]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/mac/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 | |
15 | ||
16 | #include "wx/dirdlg.h" | |
17 | ||
18 | #ifndef WX_PRECOMP | |
19 | #include "wx/utils.h" | |
20 | #endif // WX_PRECOMP | |
21 | ||
22 | #include "wx/dialog.h" | |
23 | ||
24 | #include "wx/cmndata.h" | |
25 | #include "wx/filename.h" | |
26 | ||
27 | #include "wx/mac/private.h" | |
28 | ||
29 | #ifdef __DARWIN__ | |
30 | #include <Carbon/Carbon.h> | |
31 | #else | |
32 | #include <Navigation.h> | |
33 | #endif | |
34 | ||
35 | IMPLEMENT_CLASS(wxDirDialog, wxDialog) | |
36 | ||
37 | static pascal void NavEventProc( | |
38 | NavEventCallbackMessage inSelector, | |
39 | NavCBRecPtr ioParams, | |
40 | NavCallBackUserData ioUserData ); | |
41 | ||
42 | static NavEventUPP sStandardNavEventFilter = NewNavEventUPP(NavEventProc); | |
43 | ||
44 | static pascal void NavEventProc( | |
45 | NavEventCallbackMessage inSelector, | |
46 | NavCBRecPtr ioParams, | |
47 | NavCallBackUserData ioUserData ) | |
48 | { | |
49 | wxDirDialog * data = ( wxDirDialog *) ioUserData ; | |
50 | if ( inSelector == kNavCBStart ) | |
51 | { | |
52 | if (data && !data->GetPath().empty() ) | |
53 | { | |
54 | // Set default location for the modern Navigation APIs | |
55 | // Apple Technical Q&A 1151 | |
56 | FSSpec theFSSpec; | |
57 | wxMacFilename2FSSpec(data->GetPath(), &theFSSpec); | |
58 | AEDesc theLocation = { typeNull, NULL }; | |
59 | if (noErr == ::AECreateDesc(typeFSS, &theFSSpec, sizeof(FSSpec), &theLocation)) | |
60 | ::NavCustomControl(ioParams->context, kNavCtlSetLocation, (void *) &theLocation); | |
61 | } | |
62 | } | |
63 | } | |
64 | ||
65 | wxDirDialog::wxDirDialog(wxWindow *parent, | |
66 | const wxString& message, | |
67 | const wxString& defaultPath, | |
68 | long style, | |
69 | const wxPoint& WXUNUSED(pos), | |
70 | const wxSize& WXUNUSED(size), | |
71 | const wxString& WXUNUSED(name)) | |
72 | { | |
73 | wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ; | |
74 | m_message = message; | |
75 | m_dialogStyle = style; | |
76 | m_parent = parent; | |
77 | m_path = defaultPath; | |
78 | } | |
79 | ||
80 | int wxDirDialog::ShowModal() | |
81 | { | |
82 | NavDialogRef dialog; | |
83 | NavDialogCreationOptions options; | |
84 | NavReplyRecord reply ; | |
85 | bool disposeReply = false ; | |
86 | OSStatus err = noErr; | |
87 | ||
88 | err = NavGetDefaultDialogCreationOptions(&options); | |
89 | if (err == noErr) | |
90 | { | |
91 | wxMacCFStringHolder message(m_message, m_font.GetEncoding()); | |
92 | options.message = message; | |
93 | err = NavCreateChooseFolderDialog(&options, sStandardNavEventFilter , NULL, this , &dialog); | |
94 | if (err == noErr) | |
95 | { | |
96 | err = NavDialogRun(dialog); | |
97 | if ( err == noErr ) | |
98 | { | |
99 | err = NavDialogGetReply(dialog, &reply); | |
100 | disposeReply = true ; | |
101 | } | |
102 | } | |
103 | } | |
104 | ||
105 | if ( err == noErr ) | |
106 | { | |
107 | if ( reply.validRecord ) | |
108 | { | |
109 | FSRef folderInfo; | |
110 | AEDesc specDesc ; | |
111 | ||
112 | OSErr err = ::AECoerceDesc( &reply.selection , typeFSRef, &specDesc); | |
113 | if ( err != noErr ) | |
114 | { | |
115 | m_path = wxEmptyString ; | |
116 | } | |
117 | else | |
118 | { | |
119 | folderInfo = **(FSRef**) specDesc.dataHandle; | |
120 | m_path = wxMacFSRefToPath( &folderInfo ) ; | |
121 | if (specDesc.dataHandle != nil) | |
122 | { | |
123 | ::AEDisposeDesc(&specDesc); | |
124 | } | |
125 | } | |
126 | } | |
127 | else | |
128 | { | |
129 | err = paramErr ; // could be any error, only used for giving back wxID_CANCEL | |
130 | } | |
131 | } | |
132 | ||
133 | if ( disposeReply ) | |
134 | ::NavDisposeReply(&reply); | |
135 | ||
136 | // apparently cancelling shouldn't change m_path | |
137 | if ( err != noErr && err != userCanceledErr ) | |
138 | m_path = wxEmptyString ; | |
139 | ||
140 | return (err == noErr) ? wxID_OK : wxID_CANCEL ; | |
141 | } | |
142 | ||
143 | #endif |