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