]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dirdlg.cpp
Missing #includes to allow wx/mac/carbon/tooltip.h be included first by user.
[wxWidgets.git] / src / mac / carbon / dirdlg.cpp
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_parent = parent;
76 m_path = defaultPath;
77 }
78
79 int wxDirDialog::ShowModal()
80 {
81 NavDialogRef dialog;
82 NavDialogCreationOptions options;
83 NavReplyRecord reply ;
84 bool disposeReply = false ;
85 OSStatus err = noErr;
86
87 err = NavGetDefaultDialogCreationOptions(&options);
88 if (err == noErr)
89 {
90 wxMacCFStringHolder message(m_message, m_font.GetEncoding());
91 options.message = message;
92 err = NavCreateChooseFolderDialog(&options, sStandardNavEventFilter , NULL, this , &dialog);
93 if (err == noErr)
94 {
95 err = NavDialogRun(dialog);
96 if ( err == noErr )
97 {
98 err = NavDialogGetReply(dialog, &reply);
99 disposeReply = true ;
100 }
101 }
102 }
103
104 if ( err == noErr )
105 {
106 if ( reply.validRecord )
107 {
108 FSRef folderInfo;
109 AEDesc specDesc ;
110
111 OSErr err = ::AECoerceDesc( &reply.selection , typeFSRef, &specDesc);
112 if ( err != noErr )
113 {
114 m_path = wxEmptyString ;
115 }
116 else
117 {
118 folderInfo = **(FSRef**) specDesc.dataHandle;
119 m_path = wxMacFSRefToPath( &folderInfo ) ;
120 if (specDesc.dataHandle != nil)
121 {
122 ::AEDisposeDesc(&specDesc);
123 }
124 }
125 }
126 else
127 {
128 err = paramErr ; // could be any error, only used for giving back wxID_CANCEL
129 }
130 }
131
132 if ( disposeReply )
133 ::NavDisposeReply(&reply);
134
135 // apparently cancelling shouldn't change m_path
136 if ( err != noErr && err != userCanceledErr )
137 m_path = wxEmptyString ;
138
139 return (err == noErr) ? wxID_OK : wxID_CANCEL ;
140 }
141
142 #endif