]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: filedlg.cpp | |
685a634c | 3 | // Purpose: wxFileDialog |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
e9576ca5 SC |
9 | // Licence: wxWindows licence |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "filedlg.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/defs.h" | |
5fde6fcc | 17 | #include "wx/app.h" |
e9576ca5 SC |
18 | #include "wx/utils.h" |
19 | #include "wx/dialog.h" | |
20 | #include "wx/filedlg.h" | |
21 | #include "wx/intl.h" | |
fe35d097 | 22 | #include "wx/tokenzr.h" |
5974c3cf | 23 | #include "wx/filename.h" |
e9576ca5 | 24 | |
f11bdd03 | 25 | #ifndef __DARWIN__ |
03e11df5 GD |
26 | #include "PLStringFuncs.h" |
27 | #endif | |
5b781a67 | 28 | |
2f1ae414 | 29 | #if !USE_SHARED_LIBRARY |
f74172ab | 30 | IMPLEMENT_CLASS(wxFileDialog, wxFileDialogBase) |
2f1ae414 | 31 | #endif |
e9576ca5 | 32 | |
519cb848 SC |
33 | // begin wxmac |
34 | ||
76a5e5d2 SC |
35 | #include "wx/mac/private.h" |
36 | ||
bb378910 | 37 | #include <Navigation.h> |
5b781a67 | 38 | |
2d4e4f80 GD |
39 | #ifdef __DARWIN__ |
40 | # include "MoreFilesX.h" | |
41 | #else | |
42 | # include "MoreFiles.h" | |
43 | # include "MoreFilesExtras.h" | |
44 | #endif | |
685a634c | 45 | |
5b781a67 SC |
46 | extern bool gUseNavServices ; |
47 | ||
4d4d8bbf SC |
48 | // the data we need to pass to our standard file hook routine |
49 | // includes a pointer to the dialog, a pointer to the standard | |
50 | // file reply record (so we can inspect the current selection) | |
51 | // and a copy of the "previous" file spec of the reply record | |
52 | // so we can see if the selection has changed | |
53 | ||
4d4d8bbf | 54 | struct OpenUserDataRec { |
a4f5b9b9 GD |
55 | int currentfilter ; |
56 | bool saveMode ; | |
2b5f62a0 VZ |
57 | wxArrayString name ; |
58 | wxArrayString extensions ; | |
e40298d5 | 59 | wxArrayLong filtermactypes ; |
685a634c | 60 | wxString defaultLocation; |
f65d4b83 | 61 | #if TARGET_CARBON |
a4f5b9b9 | 62 | CFArrayRef menuitems ; |
f65d4b83 | 63 | #else |
2b5f62a0 | 64 | NavMenuItemSpecArrayHandle menuitems ; |
f65d4b83 | 65 | #endif |
4d4d8bbf | 66 | }; |
2b5f62a0 | 67 | |
4d4d8bbf | 68 | typedef struct OpenUserDataRec |
a4f5b9b9 | 69 | OpenUserDataRec, *OpenUserDataRecPtr; |
4d4d8bbf | 70 | |
e40298d5 JS |
71 | static pascal void NavEventProc( |
72 | NavEventCallbackMessage inSelector, | |
73 | NavCBRecPtr ioParams, | |
74 | NavCallBackUserData ioUserData); | |
5b781a67 SC |
75 | |
76 | #if TARGET_CARBON | |
e40298d5 | 77 | static NavEventUPP sStandardNavEventFilter = NewNavEventUPP(NavEventProc); |
5b781a67 | 78 | #else |
e40298d5 | 79 | static NavEventUPP sStandardNavEventFilter = NewNavEventProc(NavEventProc); |
5b781a67 SC |
80 | #endif |
81 | ||
82 | static pascal void | |
83 | NavEventProc( | |
e40298d5 JS |
84 | NavEventCallbackMessage inSelector, |
85 | NavCBRecPtr ioParams, | |
86 | NavCallBackUserData ioUserData ) | |
5b781a67 | 87 | { |
e40298d5 | 88 | OpenUserDataRec * data = ( OpenUserDataRec *) ioUserData ; |
a4f5b9b9 | 89 | if (inSelector == kNavCBEvent) { |
f65d4b83 | 90 | #if TARGET_CARBON |
685a634c | 91 | #else |
a4f5b9b9 | 92 | wxTheApp->MacHandleOneEvent(ioParams->eventData.eventDataParms.event); |
ac9b5f98 | 93 | #endif |
685a634c | 94 | } |
e40298d5 JS |
95 | else if ( inSelector == kNavCBStart ) |
96 | { | |
f65d4b83 | 97 | #if TARGET_CARBON |
a4f5b9b9 GD |
98 | if (data && !(data->defaultLocation).IsEmpty()) |
99 | { | |
100 | // Set default location for the modern Navigation APIs | |
101 | // Apple Technical Q&A 1151 | |
102 | FSSpec theFSSpec; | |
103 | wxMacFilename2FSSpec(data->defaultLocation, &theFSSpec); | |
104 | AEDesc theLocation = {typeNull, NULL}; | |
105 | if (noErr == ::AECreateDesc(typeFSS, &theFSSpec, sizeof(FSSpec), &theLocation)) | |
106 | ::NavCustomControl(ioParams->context, kNavCtlSetLocation, (void *) &theLocation); | |
107 | } | |
108 | #else | |
e40298d5 JS |
109 | if ( data->menuitems ) |
110 | NavCustomControl(ioParams->context, kNavCtlSelectCustomType, &(*data->menuitems)[data->currentfilter]); | |
f65d4b83 | 111 | #endif |
e40298d5 JS |
112 | } |
113 | else if ( inSelector == kNavCBPopupMenuSelect ) | |
114 | { | |
115 | NavMenuItemSpec * menu = (NavMenuItemSpec *) ioParams->eventData.eventDataParms.param ; | |
f65d4b83 SC |
116 | #if TARGET_CARBON |
117 | #else | |
e40298d5 | 118 | if ( menu->menuCreator == 'WXNG' ) |
f65d4b83 | 119 | #endif |
e40298d5 JS |
120 | { |
121 | data->currentfilter = menu->menuType ; | |
122 | if ( data->saveMode ) | |
123 | { | |
124 | int i = menu->menuType ; | |
125 | wxString extension = data->extensions[i].AfterLast('.') ; | |
126 | extension.MakeLower() ; | |
f65d4b83 | 127 | wxString sfilename ; |
685a634c | 128 | |
f65d4b83 | 129 | #if TARGET_CARBON |
4891a3d5 | 130 | wxMacCFStringHolder cfString( NavDialogGetSaveFileName( ioParams->context ) , false ); |
f65d4b83 SC |
131 | sfilename = cfString.AsString() ; |
132 | #else | |
e40298d5 JS |
133 | Str255 filename ; |
134 | // get the current filename | |
135 | NavCustomControl(ioParams->context, kNavCtlGetEditFileName, &filename); | |
f65d4b83 SC |
136 | sfilename = wxMacMakeStringFromPascal( filename ) ; |
137 | #endif | |
138 | ||
685a634c | 139 | int pos = sfilename.Find('.', true) ; |
e40298d5 JS |
140 | if ( pos != wxNOT_FOUND ) |
141 | { | |
142 | sfilename = sfilename.Left(pos+1)+extension ; | |
f65d4b83 | 143 | #if TARGET_CARBON |
a9412f8f | 144 | cfString.Assign( sfilename , wxFONTENCODING_DEFAULT ) ; |
f65d4b83 SC |
145 | NavDialogSetSaveFileName( ioParams->context , cfString ) ; |
146 | #else | |
427ff662 | 147 | wxMacStringToPascal( sfilename , filename ) ; |
e40298d5 | 148 | NavCustomControl(ioParams->context, kNavCtlSetEditFileName, &filename); |
f65d4b83 | 149 | #endif |
e40298d5 JS |
150 | } |
151 | } | |
f65d4b83 | 152 | } |
e40298d5 | 153 | } |
5b781a67 SC |
154 | } |
155 | ||
2f1ae414 | 156 | |
e40298d5 | 157 | void MakeUserDataRec(OpenUserDataRec *myData , const wxString& filter ) |
4d4d8bbf | 158 | { |
e40298d5 JS |
159 | myData->menuitems = NULL ; |
160 | myData->currentfilter = 0 ; | |
685a634c DS |
161 | myData->saveMode = false ; |
162 | ||
e40298d5 | 163 | if ( filter && filter[0] ) |
4d4d8bbf | 164 | { |
e40298d5 JS |
165 | wxString filter2(filter) ; |
166 | int filterIndex = 0; | |
167 | bool isName = true ; | |
168 | wxString current ; | |
169 | for( unsigned int i = 0; i < filter2.Len() ; i++ ) | |
170 | { | |
171 | if( filter2.GetChar(i) == wxT('|') ) | |
172 | { | |
173 | if( isName ) { | |
174 | myData->name.Add( current ) ; | |
175 | } | |
176 | else { | |
177 | myData->extensions.Add( current.MakeUpper() ) ; | |
178 | ++filterIndex ; | |
179 | } | |
180 | isName = !isName ; | |
427ff662 | 181 | current = wxEmptyString ; |
e40298d5 JS |
182 | } |
183 | else | |
184 | { | |
185 | current += filter2.GetChar(i) ; | |
186 | } | |
4d4d8bbf | 187 | } |
e40298d5 JS |
188 | // we allow for compatibility reason to have a single filter expression (like *.*) without |
189 | // an explanatory text, in that case the first part is name and extension at the same time | |
685a634c | 190 | |
427ff662 | 191 | wxASSERT_MSG( filterIndex == 0 || !isName , wxT("incorrect format of format string") ) ; |
e40298d5 JS |
192 | if ( current.IsEmpty() ) |
193 | myData->extensions.Add( myData->name[filterIndex] ) ; | |
194 | else | |
195 | myData->extensions.Add( current.MakeUpper() ) ; | |
196 | if ( filterIndex == 0 || isName ) | |
197 | myData->name.Add( current.MakeUpper() ) ; | |
685a634c | 198 | |
e40298d5 | 199 | ++filterIndex ; |
685a634c | 200 | |
2b5f62a0 | 201 | const size_t extCount = myData->extensions.GetCount(); |
e40298d5 JS |
202 | for ( size_t i = 0 ; i < extCount; i++ ) |
203 | { | |
5974c3cf SC |
204 | wxUint32 fileType; |
205 | wxUint32 creator; | |
206 | wxString extension = myData->extensions[i]; | |
207 | ||
208 | if (extension.GetChar(0) == '*') | |
209 | extension = extension.Mid(1); // Remove leading * | |
210 | ||
211 | if (extension.GetChar(0) == '.') | |
e40298d5 | 212 | { |
5974c3cf | 213 | extension = extension.Mid(1); // Remove leading . |
e40298d5 | 214 | } |
5974c3cf SC |
215 | |
216 | if (wxFileName::MacFindDefaultTypeAndCreator( extension, &fileType, &creator )) | |
e40298d5 | 217 | { |
5974c3cf | 218 | myData->filtermactypes.Add( (OSType)fileType ); |
e40298d5 | 219 | } |
5974c3cf SC |
220 | else |
221 | { | |
222 | myData->filtermactypes.Add( '****' ) ; // We'll fail safe if it's not recognized | |
223 | } | |
e40298d5 JS |
224 | } |
225 | } | |
4d4d8bbf | 226 | } |
bb378910 | 227 | |
f65d4b83 | 228 | static Boolean CheckFile( const wxString &filename , OSType type , OpenUserDataRecPtr data) |
4d4d8bbf | 229 | { |
a4f5b9b9 | 230 | wxString file(filename) ; |
9f92f6fb | 231 | file.MakeUpper() ; |
685a634c | 232 | |
2b5f62a0 | 233 | if ( data->extensions.GetCount() > 0 ) |
da2b4b7a | 234 | { |
e40298d5 JS |
235 | //for ( int i = 0 ; i < data->numfilters ; ++i ) |
236 | int i = data->currentfilter ; | |
427ff662 | 237 | if ( data->extensions[i].Right(2) == wxT(".*") ) |
e40298d5 | 238 | return true ; |
685a634c | 239 | |
e40298d5 JS |
240 | { |
241 | if ( type == (OSType)data->filtermactypes[i] ) | |
242 | return true ; | |
685a634c | 243 | |
427ff662 | 244 | wxStringTokenizer tokenizer( data->extensions[i] , wxT(";") ) ; |
e40298d5 JS |
245 | while( tokenizer.HasMoreTokens() ) |
246 | { | |
247 | wxString extension = tokenizer.GetNextToken() ; | |
248 | if ( extension.GetChar(0) == '*' ) | |
249 | extension = extension.Mid(1) ; | |
685a634c | 250 | |
e40298d5 JS |
251 | if ( file.Len() >= extension.Len() && extension == file.Right(extension.Len() ) ) |
252 | return true ; | |
253 | } | |
254 | } | |
255 | return false ; | |
da2b4b7a GD |
256 | } |
257 | return true ; | |
4d4d8bbf SC |
258 | } |
259 | ||
bb378910 | 260 | #ifndef __DARWIN__ |
5fde6fcc | 261 | static pascal Boolean CrossPlatformFileFilter(CInfoPBPtr myCInfoPBPtr, void *dataPtr) |
a4f5b9b9 | 262 | { |
e40298d5 JS |
263 | OpenUserDataRecPtr data = (OpenUserDataRecPtr) dataPtr ; |
264 | // return true if this item is invisible or a file | |
265 | ||
266 | Boolean visibleFlag; | |
267 | Boolean folderFlag; | |
685a634c | 268 | |
e40298d5 JS |
269 | visibleFlag = ! (myCInfoPBPtr->hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible); |
270 | folderFlag = (myCInfoPBPtr->hFileInfo.ioFlAttrib & 0x10); | |
685a634c | 271 | |
e40298d5 JS |
272 | // because the semantics of the filter proc are "true means don't show |
273 | // it" we need to invert the result that we return | |
685a634c | 274 | |
e40298d5 JS |
275 | if ( !visibleFlag ) |
276 | return true ; | |
685a634c | 277 | |
e40298d5 JS |
278 | if ( !folderFlag ) |
279 | { | |
a4f5b9b9 | 280 | wxString file = wxMacMakeStringFromPascal( myCInfoPBPtr->hFileInfo.ioNamePtr ) ; |
f65d4b83 | 281 | return !CheckFile( file , myCInfoPBPtr->hFileInfo.ioFlFndrInfo.fdType , data ) ; |
a4f5b9b9 | 282 | } |
685a634c | 283 | |
e40298d5 | 284 | return false ; |
519cb848 | 285 | } |
bb378910 | 286 | #endif |
519cb848 SC |
287 | |
288 | // end wxmac | |
289 | ||
e9576ca5 SC |
290 | wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, |
291 | const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard, | |
292 | long style, const wxPoint& pos) | |
f74172ab | 293 | :wxFileDialogBase(parent, message, defaultDir, defaultFileName, wildCard, style, pos) |
e9576ca5 | 294 | { |
427ff662 | 295 | wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ; |
e9576ca5 SC |
296 | } |
297 | ||
f11bdd03 | 298 | pascal Boolean CrossPlatformFilterCallback ( |
685a634c DS |
299 | AEDesc *theItem, |
300 | void *info, | |
301 | void *callBackUD, | |
4d4d8bbf SC |
302 | NavFilterModes filterMode |
303 | ) | |
304 | { | |
2d4e4f80 GD |
305 | bool display = true; |
306 | OpenUserDataRecPtr data = (OpenUserDataRecPtr) callBackUD ; | |
685a634c | 307 | |
2d4e4f80 GD |
308 | if (filterMode == kNavFilteringBrowserList) |
309 | { | |
310 | NavFileOrFolderInfo* theInfo = (NavFileOrFolderInfo*) info ; | |
f65d4b83 | 311 | if ( !theInfo->isFolder ) |
2d4e4f80 | 312 | { |
f65d4b83 SC |
313 | if (theItem->descriptorType == typeFSS ) |
314 | { | |
315 | FSSpec spec; | |
316 | memcpy( &spec , *theItem->dataHandle , sizeof(FSSpec) ) ; | |
a4f5b9b9 | 317 | wxString file = wxMacMakeStringFromPascal( spec.name ) ; |
f65d4b83 | 318 | display = CheckFile( file , theInfo->fileAndFolder.fileInfo.finderInfo.fdType , data ) ; |
685a634c | 319 | } |
613b6bb9 | 320 | #if TARGET_CARBON |
f65d4b83 SC |
321 | else if ( theItem->descriptorType == typeFSRef ) |
322 | { | |
323 | FSRef fsref ; | |
324 | memcpy( &fsref , *theItem->dataHandle , sizeof(FSRef) ) ; | |
305a0f60 SC |
325 | |
326 | ||
327 | ||
328 | CFURLRef fullURLRef; | |
329 | fullURLRef = ::CFURLCreateFromFSRef(NULL, &fsref); | |
330 | #ifdef __UNIX__ | |
331 | CFURLPathStyle pathstyle = kCFURLPOSIXPathStyle; | |
332 | #else | |
333 | CFURLPathStyle pathstyle = kCFURLHFSPathStyle; | |
334 | #endif | |
335 | CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, pathstyle); | |
336 | wxString file = wxMacCFStringHolder(cfString).AsString(wxFont::GetDefaultEncoding()); | |
337 | ||
f65d4b83 SC |
338 | display = CheckFile( file , theInfo->fileAndFolder.fileInfo.finderInfo.fdType , data ) ; |
339 | } | |
613b6bb9 | 340 | #endif |
2d4e4f80 GD |
341 | } |
342 | } | |
685a634c | 343 | |
2d4e4f80 | 344 | return display; |
4d4d8bbf SC |
345 | } |
346 | ||
e9576ca5 SC |
347 | int wxFileDialog::ShowModal() |
348 | { | |
f65d4b83 | 349 | #if TARGET_CARBON |
a4f5b9b9 GD |
350 | OSErr err; |
351 | NavDialogCreationOptions dialogCreateOptions; | |
352 | // set default options | |
353 | ::NavGetDefaultDialogCreationOptions(&dialogCreateOptions); | |
685a634c | 354 | |
a4f5b9b9 GD |
355 | // this was always unset in the old code |
356 | dialogCreateOptions.optionFlags &= ~kNavSelectDefaultLocation; | |
685a634c | 357 | |
a4f5b9b9 | 358 | #if wxUSE_UNICODE |
685a634c DS |
359 | // tried using wxMacCFStringHolder in the code below, but it seems |
360 | // the CFStrings were being released before the save dialog was called, | |
a4f5b9b9 | 361 | // causing a crash - open dialog works fine with or without wxMacCFStringHolder |
878973f1 GD |
362 | CFStringRef titleRef = ::CFStringCreateWithCharacters( kCFAllocatorDefault, |
363 | (const unsigned short*)m_message.wc_str(), | |
364 | m_message.Len() ); | |
f65d4b83 | 365 | #else |
685a634c | 366 | CFStringRef titleRef = ::CFStringCreateWithCString(NULL, |
a4f5b9b9 | 367 | m_message.c_str(), |
a9412f8f | 368 | m_font.GetEncoding() ); |
f65d4b83 | 369 | #endif |
a4f5b9b9 GD |
370 | dialogCreateOptions.windowTitle = titleRef; |
371 | #if wxUSE_UNICODE | |
878973f1 GD |
372 | CFStringRef defaultFileNameRef = ::CFStringCreateWithCharacters( kCFAllocatorDefault, |
373 | (const unsigned short*)m_fileName.wc_str(), | |
374 | m_fileName.Len() ); | |
a4f5b9b9 | 375 | #else |
685a634c DS |
376 | CFStringRef defaultFileNameRef = ::CFStringCreateWithCString(NULL, |
377 | m_fileName.c_str(), | |
a9412f8f | 378 | m_font.GetEncoding()); |
a4f5b9b9 GD |
379 | #endif |
380 | dialogCreateOptions.saveFileName = defaultFileNameRef; | |
381 | NavDialogRef dialog; | |
382 | NavObjectFilterUPP navFilterUPP = NULL; | |
685a634c | 383 | CFArrayRef cfArray = NULL; // for popupExtension |
a4f5b9b9 GD |
384 | OpenUserDataRec myData; |
385 | myData.defaultLocation = m_dir; | |
386 | ||
387 | if (m_dialogStyle & wxSAVE) | |
388 | { | |
685a634c DS |
389 | dialogCreateOptions.optionFlags |= kNavNoTypePopup; |
390 | dialogCreateOptions.optionFlags |= kNavDontAutoTranslate; | |
391 | dialogCreateOptions.optionFlags |= kNavDontAddTranslateItems; | |
392 | ||
393 | // The extension is important | |
394 | dialogCreateOptions.optionFlags |= kNavPreserveSaveFileExtension; | |
395 | ||
a4f5b9b9 | 396 | err = ::NavCreatePutFileDialog(&dialogCreateOptions, |
685a634c DS |
397 | 'TEXT', |
398 | 'TEXT', | |
399 | sStandardNavEventFilter, | |
400 | &myData, // for defaultLocation | |
401 | &dialog); | |
a4f5b9b9 GD |
402 | } |
403 | else | |
404 | { | |
405 | MakeUserDataRec(&myData , m_wildCard); | |
685a634c DS |
406 | size_t numfilters = myData.extensions.GetCount(); |
407 | if (numfilters > 0) | |
a4f5b9b9 | 408 | { |
685a634c DS |
409 | CFMutableArrayRef popup = CFArrayCreateMutable( kCFAllocatorDefault , |
410 | numfilters , &kCFTypeArrayCallBacks ) ; | |
411 | dialogCreateOptions.popupExtension = popup ; | |
412 | myData.menuitems = dialogCreateOptions.popupExtension ; | |
413 | for ( size_t i = 0 ; i < numfilters ; ++i ) | |
414 | { | |
a9412f8f | 415 | CFArrayAppendValue( popup , (CFStringRef) wxMacCFStringHolder( myData.name[i] , m_font.GetEncoding() ) ) ; |
685a634c DS |
416 | } |
417 | } | |
418 | ||
a4f5b9b9 GD |
419 | navFilterUPP = NewNavObjectFilterUPP(CrossPlatformFilterCallback); |
420 | err = ::NavCreateGetFileDialog(&dialogCreateOptions, | |
421 | NULL, // NavTypeListHandle | |
422 | sStandardNavEventFilter, | |
423 | NULL, // NavPreviewUPP | |
424 | navFilterUPP, | |
425 | (void *) &myData, // inClientData | |
426 | &dialog); | |
427 | } | |
428 | ||
429 | if (err == noErr) | |
430 | err = ::NavDialogRun(dialog); | |
685a634c | 431 | |
a4f5b9b9 GD |
432 | // clean up filter related data, etc. |
433 | if (navFilterUPP) | |
434 | ::DisposeNavObjectFilterUPP(navFilterUPP); | |
435 | if (cfArray) | |
436 | { | |
437 | CFIndex n = ::CFArrayGetCount(cfArray); | |
438 | for (CFIndex i = 0; i < n; i++) | |
439 | { | |
440 | CFStringRef str = (CFStringRef) ::CFArrayGetValueAtIndex(cfArray, i); | |
441 | if (str) | |
442 | ::CFRelease(str); | |
443 | } | |
444 | ::CFRelease(cfArray); | |
445 | } | |
446 | if (titleRef) | |
447 | ::CFRelease(titleRef); | |
448 | if (defaultFileNameRef) | |
449 | ::CFRelease(defaultFileNameRef); | |
685a634c | 450 | if (err != noErr) |
a4f5b9b9 GD |
451 | return wxID_CANCEL; |
452 | ||
453 | NavReplyRecord navReply; | |
454 | err = ::NavDialogGetReply(dialog, &navReply); | |
685a634c | 455 | if (err == noErr && navReply.validRecord) |
a4f5b9b9 GD |
456 | { |
457 | AEKeyword theKeyword; | |
458 | DescType actualType; | |
459 | Size actualSize; | |
460 | FSRef theFSRef; | |
878973f1 | 461 | wxString thePath ; |
a4f5b9b9 GD |
462 | long count; |
463 | ::AECountItems(&navReply.selection , &count); | |
464 | for (long i = 1; i <= count; ++i) | |
465 | { | |
466 | err = ::AEGetNthPtr(&(navReply.selection), 1, typeFSRef, &theKeyword, &actualType, | |
467 | &theFSRef, sizeof(theFSRef), &actualSize); | |
685a634c | 468 | if (err != noErr) |
a4f5b9b9 GD |
469 | break; |
470 | ||
a449f840 | 471 | CFURLRef fullURLRef; |
a4f5b9b9 GD |
472 | if (m_dialogStyle & wxSAVE) |
473 | { | |
a4f5b9b9 | 474 | CFURLRef parentURLRef = ::CFURLCreateFromFSRef(NULL, &theFSRef); |
685a634c | 475 | |
a4f5b9b9 GD |
476 | if (parentURLRef) |
477 | { | |
a449f840 | 478 | fullURLRef = |
a4f5b9b9 | 479 | ::CFURLCreateCopyAppendingPathComponent(NULL, |
685a634c DS |
480 | parentURLRef, |
481 | navReply.saveFileName, | |
a4f5b9b9 GD |
482 | false); |
483 | ::CFRelease(parentURLRef); | |
a4f5b9b9 GD |
484 | } |
485 | } | |
685a634c | 486 | else |
a4f5b9b9 | 487 | { |
a449f840 DS |
488 | fullURLRef = ::CFURLCreateFromFSRef(NULL, &theFSRef); |
489 | } | |
490 | #ifdef __UNIX__ | |
491 | CFURLPathStyle pathstyle = kCFURLPOSIXPathStyle; | |
492 | #else | |
493 | CFURLPathStyle pathstyle = kCFURLHFSPathStyle; | |
494 | #endif | |
495 | CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, pathstyle); | |
a9412f8f | 496 | thePath = wxMacCFStringHolder(cfString).AsString(m_font.GetEncoding()); |
a449f840 DS |
497 | if (!thePath) |
498 | { | |
499 | ::NavDisposeReply(&navReply); | |
500 | return wxID_CANCEL; | |
a4f5b9b9 GD |
501 | } |
502 | m_path = thePath; | |
503 | m_paths.Add(m_path); | |
504 | m_fileName = wxFileNameFromPath(m_path); | |
505 | m_fileNames.Add(m_fileName); | |
506 | } | |
507 | // set these to the first hit | |
508 | m_path = m_paths[0]; | |
509 | m_fileName = wxFileNameFromPath(m_path); | |
510 | m_dir = wxPathOnly(m_path); | |
511 | } | |
512 | ::NavDisposeReply(&navReply); | |
685a634c | 513 | |
a4f5b9b9 GD |
514 | return (err == noErr) ? wxID_OK : wxID_CANCEL; |
515 | #else // TARGET_CARBON | |
516 | ||
517 | NavDialogOptions mNavOptions; | |
e40298d5 JS |
518 | NavObjectFilterUPP mNavFilterUPP = NULL; |
519 | NavPreviewUPP mNavPreviewUPP = NULL ; | |
520 | NavReplyRecord mNavReply; | |
521 | AEDesc mDefaultLocation ; | |
522 | bool mSelectDefault = false ; | |
f65d4b83 | 523 | OSStatus err = noErr ; |
e40298d5 | 524 | // setup dialog |
685a634c | 525 | |
e40298d5 JS |
526 | mNavFilterUPP = nil; |
527 | mNavPreviewUPP = nil; | |
528 | mSelectDefault = false; | |
f65d4b83 SC |
529 | mDefaultLocation.descriptorType = typeNull; |
530 | mDefaultLocation.dataHandle = nil; | |
531 | ||
f65d4b83 SC |
532 | NavGetDefaultDialogOptions(&mNavOptions); |
533 | wxMacStringToPascal( m_message , (StringPtr)mNavOptions.message ) ; | |
534 | wxMacStringToPascal( m_fileName , (StringPtr)mNavOptions.savedFileName ) ; | |
535 | ||
2d4e4f80 GD |
536 | // Set default location, the location |
537 | // that's displayed when the dialog | |
538 | // first appears | |
685a634c | 539 | |
2d4e4f80 GD |
540 | FSSpec location ; |
541 | wxMacFilename2FSSpec( m_dir , &location ) ; | |
685a634c | 542 | |
2d4e4f80 | 543 | err = ::AECreateDesc(typeFSS, &location, sizeof(FSSpec), &mDefaultLocation ); |
5b781a67 | 544 | |
685a634c DS |
545 | if ( mDefaultLocation.dataHandle ) |
546 | { | |
547 | if (mSelectDefault) | |
548 | { | |
2d4e4f80 GD |
549 | mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation; |
550 | } else { | |
551 | mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation; | |
552 | } | |
553 | } | |
5b781a67 | 554 | |
f65d4b83 SC |
555 | memset( &mNavReply , 0 , sizeof( mNavReply ) ) ; |
556 | mNavReply.validRecord = false; | |
557 | mNavReply.replacing = false; | |
558 | mNavReply.isStationery = false; | |
559 | mNavReply.translationNeeded = false; | |
560 | mNavReply.selection.descriptorType = typeNull; | |
561 | mNavReply.selection.dataHandle = nil; | |
562 | mNavReply.keyScript = smSystemScript; | |
563 | mNavReply.fileTranslation = nil; | |
564 | mNavReply.version = kNavReplyRecordVersion ; | |
685a634c | 565 | |
7ed2b47b | 566 | // zero all data |
685a634c | 567 | |
7ed2b47b SC |
568 | m_path = wxEmptyString ; |
569 | m_fileName = wxEmptyString ; | |
570 | m_paths.Empty(); | |
571 | m_fileNames.Empty(); | |
572 | ||
e40298d5 | 573 | OpenUserDataRec myData; |
2d4e4f80 GD |
574 | MakeUserDataRec( &myData , m_wildCard ) ; |
575 | myData.currentfilter = m_filterIndex ; | |
576 | if ( myData.extensions.GetCount() > 0 ) | |
577 | { | |
578 | mNavOptions.popupExtension = (NavMenuItemSpecArrayHandle) NewHandle( sizeof( NavMenuItemSpec ) * myData.extensions.GetCount() ) ; | |
579 | myData.menuitems = mNavOptions.popupExtension ; | |
685a634c | 580 | for ( size_t i = 0 ; i < myData.extensions.GetCount() ; ++i ) |
2d4e4f80 GD |
581 | { |
582 | (*mNavOptions.popupExtension)[i].version = kNavMenuItemSpecVersion ; | |
583 | (*mNavOptions.popupExtension)[i].menuCreator = 'WXNG' ; | |
f65d4b83 | 584 | // TODO : according to the new docs -1 to 10 are reserved for the OS |
2d4e4f80 | 585 | (*mNavOptions.popupExtension)[i].menuType = i ; |
427ff662 | 586 | wxMacStringToPascal( myData.name[i] , (StringPtr)(*mNavOptions.popupExtension)[i].menuItemName ) ; |
2d4e4f80 GD |
587 | } |
588 | } | |
589 | if ( m_dialogStyle & wxSAVE ) | |
590 | { | |
591 | myData.saveMode = true ; | |
2b5f62a0 | 592 | |
2d4e4f80 GD |
593 | mNavOptions.dialogOptionFlags |= kNavDontAutoTranslate ; |
594 | mNavOptions.dialogOptionFlags |= kNavDontAddTranslateItems ; | |
685a634c | 595 | |
2d4e4f80 GD |
596 | err = ::NavPutFile( |
597 | &mDefaultLocation, | |
598 | &mNavReply, | |
599 | &mNavOptions, | |
600 | sStandardNavEventFilter , | |
601 | NULL, | |
602 | kNavGenericSignature, | |
e40298d5 | 603 | &myData); // User Data |
2d4e4f80 GD |
604 | m_filterIndex = myData.currentfilter ; |
605 | } | |
606 | else | |
607 | { | |
608 | myData.saveMode = false ; | |
4d4d8bbf | 609 | |
2d4e4f80 GD |
610 | mNavFilterUPP = NewNavObjectFilterUPP( CrossPlatformFilterCallback ) ; |
611 | if ( m_dialogStyle & wxMULTIPLE ) | |
612 | mNavOptions.dialogOptionFlags |= kNavAllowMultipleFiles ; | |
613 | else | |
614 | mNavOptions.dialogOptionFlags &= ~kNavAllowMultipleFiles ; | |
685a634c | 615 | |
2d4e4f80 GD |
616 | err = ::NavGetFile( |
617 | &mDefaultLocation, | |
618 | &mNavReply, | |
619 | &mNavOptions, | |
620 | sStandardNavEventFilter , | |
621 | mNavPreviewUPP, | |
622 | mNavFilterUPP, | |
623 | NULL , | |
624 | &myData); | |
625 | m_filterIndex = myData.currentfilter ; | |
626 | } | |
685a634c | 627 | |
2d4e4f80 GD |
628 | DisposeNavObjectFilterUPP(mNavFilterUPP); |
629 | if ( mDefaultLocation.dataHandle != nil ) | |
630 | { | |
631 | ::AEDisposeDesc(&mDefaultLocation); | |
632 | } | |
685a634c | 633 | |
2d4e4f80 | 634 | if ( (err != noErr) && (err != userCanceledErr) ) { |
2d4e4f80 GD |
635 | return wxID_CANCEL ; |
636 | } | |
5b781a67 | 637 | |
685a634c DS |
638 | if (mNavReply.validRecord) |
639 | { | |
2d4e4f80 GD |
640 | FSSpec outFileSpec ; |
641 | AEDesc specDesc ; | |
642 | AEKeyword keyWord ; | |
685a634c | 643 | |
2d4e4f80 GD |
644 | long count ; |
645 | ::AECountItems( &mNavReply.selection , &count ) ; | |
646 | for ( long i = 1 ; i <= count ; ++i ) | |
647 | { | |
648 | OSErr err = ::AEGetNthDesc( &mNavReply.selection , i , typeFSS, &keyWord , &specDesc); | |
685a634c DS |
649 | if ( err != noErr ) |
650 | { | |
427ff662 | 651 | m_path = wxT("") ; |
2d4e4f80 | 652 | return wxID_CANCEL ; |
685a634c | 653 | } |
2d4e4f80 GD |
654 | outFileSpec = **(FSSpec**) specDesc.dataHandle; |
655 | if (specDesc.dataHandle != nil) { | |
656 | ::AEDisposeDesc(&specDesc); | |
657 | } | |
658 | m_path = wxMacFSSpec2MacFilename( &outFileSpec ) ; | |
a4f5b9b9 | 659 | |
2d4e4f80 | 660 | m_paths.Add( m_path ) ; |
24fe8dc7 | 661 | m_fileName = wxFileNameFromPath(m_path); |
2d4e4f80 GD |
662 | m_fileNames.Add(m_fileName); |
663 | } | |
664 | // set these to the first hit | |
665 | m_path = m_paths[ 0 ] ; | |
666 | m_fileName = wxFileNameFromPath(m_path); | |
667 | m_dir = wxPathOnly(m_path); | |
668 | NavDisposeReply( &mNavReply ) ; | |
669 | return wxID_OK ; | |
670 | } | |
671 | return wxID_CANCEL; | |
a4f5b9b9 | 672 | #endif // TARGET_CARBON |
5b781a67 | 673 | } |
e9576ca5 | 674 |