]>
Commit | Line | Data |
---|---|---|
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 | #include "wx/cmndata.h" | |
22 | #endif // WX_PRECOMP | |
23 | ||
24 | #include "wx/filename.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 | wxDirDialog::wxDirDialog(wxWindow *parent, | |
59 | const wxString& message, | |
60 | const wxString& defaultPath, | |
61 | long style, | |
62 | const wxPoint& WXUNUSED(pos), | |
63 | const wxSize& WXUNUSED(size), | |
64 | const wxString& WXUNUSED(name)) | |
65 | { | |
66 | wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ; | |
67 | m_parent = parent; | |
68 | ||
69 | SetMessage( message ); | |
70 | SetWindowStyle(style); | |
71 | SetPath(defaultPath); | |
72 | } | |
73 | ||
74 | int wxDirDialog::ShowModal() | |
75 | { | |
76 | NavDialogRef dialog = NULL; | |
77 | NavDialogCreationOptions options; | |
78 | NavReplyRecord reply ; | |
79 | bool disposeReply = false ; | |
80 | OSStatus err = noErr; | |
81 | ||
82 | err = NavGetDefaultDialogCreationOptions(&options); | |
83 | options.optionFlags &= ~kNavAllowMultipleFiles; | |
84 | if (err == noErr) | |
85 | { | |
86 | wxCFStringRef message(m_message, GetFont().GetEncoding()); | |
87 | options.message = message; | |
88 | err = NavCreateChooseFolderDialog(&options, sStandardNavEventFilter , NULL, this , &dialog); | |
89 | if (err == noErr) | |
90 | { | |
91 | wxDialog::OSXBeginModalDialog(); | |
92 | err = NavDialogRun(dialog); | |
93 | wxDialog::OSXEndModalDialog(); | |
94 | if ( err == noErr ) | |
95 | { | |
96 | err = NavDialogGetReply(dialog, &reply); | |
97 | disposeReply = true ; | |
98 | } | |
99 | } | |
100 | } | |
101 | ||
102 | if ( err == noErr ) | |
103 | { | |
104 | if ( reply.validRecord ) | |
105 | { | |
106 | FSRef folderInfo; | |
107 | AEDesc specDesc ; | |
108 | ||
109 | OSErr err = ::AECoerceDesc( &reply.selection , typeFSRef, &specDesc); | |
110 | if ( err != noErr ) | |
111 | { | |
112 | m_path = wxEmptyString ; | |
113 | } | |
114 | else | |
115 | { | |
116 | folderInfo = **(FSRef**) specDesc.dataHandle; | |
117 | m_path = wxMacFSRefToPath( &folderInfo ) ; | |
118 | if (specDesc.dataHandle != nil) | |
119 | { | |
120 | ::AEDisposeDesc(&specDesc); | |
121 | } | |
122 | } | |
123 | } | |
124 | else | |
125 | { | |
126 | err = paramErr ; // could be any error, only used for giving back wxID_CANCEL | |
127 | } | |
128 | } | |
129 | ||
130 | if ( disposeReply ) | |
131 | ::NavDisposeReply(&reply); | |
132 | ||
133 | // apparently cancelling shouldn't change m_path | |
134 | if ( err != noErr && err != userCanceledErr ) | |
135 | m_path = wxEmptyString ; | |
136 | ||
137 | if ( dialog ) | |
138 | ::NavDialogDispose(dialog); | |
139 | ||
140 | return (err == noErr) ? wxID_OK : wxID_CANCEL ; | |
141 | } | |
142 | ||
143 | #endif |