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