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