]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/dirdlg.cpp
Fix uninitialized variable warning in wxMSW wxFileSystemWatcher code.
[wxWidgets.git] / src / osx / carbon / dirdlg.cpp
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 #endif // WX_PRECOMP
22
23 #include "wx/filename.h"
24
25 #include "wx/osx/private.h"
26
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
57 wxDirDialog::wxDirDialog(wxWindow *parent,
58 const wxString& message,
59 const wxString& defaultPath,
60 long style,
61 const wxPoint& WXUNUSED(pos),
62 const wxSize& WXUNUSED(size),
63 const wxString& WXUNUSED(name))
64 {
65 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
66 m_parent = parent;
67
68 SetMessage( message );
69 SetWindowStyle(style);
70 SetPath(defaultPath);
71 }
72
73 int wxDirDialog::ShowModal()
74 {
75 NavDialogRef dialog = NULL;
76 NavDialogCreationOptions options;
77 NavReplyRecord reply ;
78 bool disposeReply = false ;
79 OSStatus err = noErr;
80
81 err = NavGetDefaultDialogCreationOptions(&options);
82 options.optionFlags &= ~kNavAllowMultipleFiles;
83 if (err == noErr)
84 {
85 wxCFStringRef message(m_message, GetFont().GetEncoding());
86 options.message = message;
87 err = NavCreateChooseFolderDialog(&options, sStandardNavEventFilter , NULL, this , &dialog);
88 if (err == noErr)
89 {
90 wxDialog::OSXBeginModalDialog();
91 err = NavDialogRun(dialog);
92 wxDialog::OSXEndModalDialog();
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 if ( dialog )
137 ::NavDialogDispose(dialog);
138
139 return (err == noErr) ? wxID_OK : wxID_CANCEL ;
140 }
141
142 #endif