]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dirdlg.cpp
Use new function GetItemLabel
[wxWidgets.git] / src / mac / carbon / dirdlg.cpp
CommitLineData
e9576ca5 1/////////////////////////////////////////////////////////////////////////////
de6185e2 2// Name: src/mac/carbon/dirdlg.cpp
e9576ca5 3// Purpose: wxDirDialog
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
de6185e2 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878
SC
12#include "wx/wxprec.h"
13
179e085f
RN
14#if wxUSE_DIRDLG
15
e9576ca5
SC
16#include "wx/dirdlg.h"
17
de6185e2
WS
18#ifndef WX_PRECOMP
19 #include "wx/utils.h"
fdf565fe 20 #include "wx/dialog.h"
ce5d92e1 21 #include "wx/cmndata.h"
de6185e2
WS
22#endif // WX_PRECOMP
23
a4e3cdf0 24#include "wx/filename.h"
e9576ca5 25
76a5e5d2
SC
26#include "wx/mac/private.h"
27
f5c6eb5c 28#ifdef __DARWIN__
de6185e2 29 #include <Carbon/Carbon.h>
03e11df5 30#else
de6185e2 31 #include <Navigation.h>
03e11df5 32#endif
5b781a67 33
e9576ca5 34IMPLEMENT_CLASS(wxDirDialog, wxDialog)
519cb848 35
a4e3cdf0
SC
36static pascal void NavEventProc(
37 NavEventCallbackMessage inSelector,
38 NavCBRecPtr ioParams,
39 NavCallBackUserData ioUserData );
40
41static NavEventUPP sStandardNavEventFilter = NewNavEventUPP(NavEventProc);
42
43static pascal void NavEventProc(
44 NavEventCallbackMessage inSelector,
45 NavCBRecPtr ioParams,
46 NavCallBackUserData ioUserData )
47{
48 wxDirDialog * data = ( wxDirDialog *) ioUserData ;
49 if ( inSelector == kNavCBStart )
50 {
de6185e2 51 if (data && !data->GetPath().empty() )
a4e3cdf0
SC
52 {
53 // Set default location for the modern Navigation APIs
54 // Apple Technical Q&A 1151
f387b80e
SC
55 FSRef theFile;
56 wxMacPathToFSRef(data->GetPath(), &theFile);
a4e3cdf0 57 AEDesc theLocation = { typeNull, NULL };
f387b80e
SC
58 if (noErr == ::AECreateDesc(typeFSRef, &theFile, sizeof(FSRef), &theLocation))
59 ::NavCustomControl(ioParams->context, kNavCtlSetLocation, (void *) &theLocation);
a4e3cdf0
SC
60 }
61 }
62}
63
e78d4a23
VZ
64wxDirDialog::wxDirDialog(wxWindow *parent,
65 const wxString& message,
66 const wxString& defaultPath,
67 long style,
68 const wxPoint& WXUNUSED(pos),
69 const wxSize& WXUNUSED(size),
70 const wxString& WXUNUSED(name))
e9576ca5 71{
427ff662 72 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
e9576ca5 73 m_message = message;
e9576ca5 74 m_parent = parent;
e40298d5 75 m_path = defaultPath;
e9576ca5
SC
76}
77
78int wxDirDialog::ShowModal()
79{
516d38cd
SC
80 NavDialogRef dialog;
81 NavDialogCreationOptions options;
82 NavReplyRecord reply ;
83 bool disposeReply = false ;
84 OSStatus err = noErr;
de6185e2 85
516d38cd 86 err = NavGetDefaultDialogCreationOptions(&options);
de6185e2 87 if (err == noErr)
516d38cd
SC
88 {
89 wxMacCFStringHolder message(m_message, m_font.GetEncoding());
90 options.message = message;
a4e3cdf0 91 err = NavCreateChooseFolderDialog(&options, sStandardNavEventFilter , NULL, this , &dialog);
de6185e2
WS
92 if (err == noErr)
93 {
516d38cd
SC
94 err = NavDialogRun(dialog);
95 if ( err == noErr )
96 {
97 err = NavDialogGetReply(dialog, &reply);
98 disposeReply = true ;
99 }
100 }
e40298d5 101 }
de6185e2
WS
102
103 if ( err == noErr )
104 {
516d38cd
SC
105 if ( reply.validRecord )
106 {
107 FSRef folderInfo;
108 AEDesc specDesc ;
de6185e2 109
516d38cd 110 OSErr err = ::AECoerceDesc( &reply.selection , typeFSRef, &specDesc);
de6185e2 111 if ( err != noErr )
516d38cd
SC
112 {
113 m_path = wxEmptyString ;
114 }
115 else
116 {
117 folderInfo = **(FSRef**) specDesc.dataHandle;
118 m_path = wxMacFSRefToPath( &folderInfo ) ;
de6185e2 119 if (specDesc.dataHandle != nil)
516d38cd
SC
120 {
121 ::AEDisposeDesc(&specDesc);
de6185e2 122 }
516d38cd 123 }
902725ee 124 }
516d38cd
SC
125 else
126 {
127 err = paramErr ; // could be any error, only used for giving back wxID_CANCEL
e40298d5 128 }
e40298d5 129 }
de6185e2 130
516d38cd
SC
131 if ( disposeReply )
132 ::NavDisposeReply(&reply);
de6185e2 133
516d38cd
SC
134 // apparently cancelling shouldn't change m_path
135 if ( err != noErr && err != userCanceledErr )
136 m_path = wxEmptyString ;
de6185e2 137
516d38cd 138 return (err == noErr) ? wxID_OK : wxID_CANCEL ;
e9576ca5
SC
139}
140
179e085f 141#endif