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