+ // clean up filter related data, etc.
+ if (navFilterUPP)
+ ::DisposeNavObjectFilterUPP(navFilterUPP);
+ if (cfArray)
+ {
+ CFIndex n = ::CFArrayGetCount(cfArray);
+ for (CFIndex i = 0; i < n; i++)
+ {
+ CFStringRef str = (CFStringRef) ::CFArrayGetValueAtIndex(cfArray, i);
+ if (str)
+ ::CFRelease(str);
+ }
+ ::CFRelease(cfArray);
+ }
+ if (titleRef)
+ ::CFRelease(titleRef);
+ if (defaultFileNameRef)
+ ::CFRelease(defaultFileNameRef);
+ if (err != noErr)
+ return wxID_CANCEL;
+
+ NavReplyRecord navReply;
+ err = ::NavDialogGetReply(dialog, &navReply);
+ if (err == noErr && navReply.validRecord)
+ {
+ AEKeyword theKeyword;
+ DescType actualType;
+ Size actualSize;
+ FSRef theFSRef;
+ wxString thePath ;
+ long count;
+ ::AECountItems(&navReply.selection , &count);
+ for (long i = 1; i <= count; ++i)
+ {
+ err = ::AEGetNthPtr(&(navReply.selection), 1, typeFSRef, &theKeyword, &actualType,
+ &theFSRef, sizeof(theFSRef), &actualSize);
+ if (err != noErr)
+ break;
+
+ CFURLRef fullURLRef;
+ if (m_dialogStyle & wxSAVE)
+ {
+ CFURLRef parentURLRef = ::CFURLCreateFromFSRef(NULL, &theFSRef);
+
+ if (parentURLRef)
+ {
+ fullURLRef =
+ ::CFURLCreateCopyAppendingPathComponent(NULL,
+ parentURLRef,
+ navReply.saveFileName,
+ false);
+ ::CFRelease(parentURLRef);
+ }
+ }
+ else
+ {
+ fullURLRef = ::CFURLCreateFromFSRef(NULL, &theFSRef);
+ }
+#ifdef __UNIX__
+ CFURLPathStyle pathstyle = kCFURLPOSIXPathStyle;
+#else
+ CFURLPathStyle pathstyle = kCFURLHFSPathStyle;
+#endif
+ CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, pathstyle);
+ thePath = wxMacCFStringHolder(cfString).AsString();
+ if (!thePath)
+ {
+ ::NavDisposeReply(&navReply);
+ return wxID_CANCEL;
+ }
+ m_path = thePath;
+ m_paths.Add(m_path);
+ m_fileName = wxFileNameFromPath(m_path);
+ m_fileNames.Add(m_fileName);
+ }
+ // set these to the first hit
+ m_path = m_paths[0];
+ m_fileName = wxFileNameFromPath(m_path);
+ m_dir = wxPathOnly(m_path);
+ }
+ ::NavDisposeReply(&navReply);
+
+ return (err == noErr) ? wxID_OK : wxID_CANCEL;
+#else // TARGET_CARBON
+
+ NavDialogOptions mNavOptions;
+ NavObjectFilterUPP mNavFilterUPP = NULL;
+ NavPreviewUPP mNavPreviewUPP = NULL ;
+ NavReplyRecord mNavReply;
+ AEDesc mDefaultLocation ;
+ bool mSelectDefault = false ;
+ OSStatus err = noErr ;
+ // setup dialog
+
+ mNavFilterUPP = nil;
+ mNavPreviewUPP = nil;
+ mSelectDefault = false;
+ mDefaultLocation.descriptorType = typeNull;
+ mDefaultLocation.dataHandle = nil;
+
+ NavGetDefaultDialogOptions(&mNavOptions);
+ wxMacStringToPascal( m_message , (StringPtr)mNavOptions.message ) ;
+ wxMacStringToPascal( m_fileName , (StringPtr)mNavOptions.savedFileName ) ;
+
+ // Set default location, the location
+ // that's displayed when the dialog
+ // first appears
+
+ FSSpec location ;
+ wxMacFilename2FSSpec( m_dir , &location ) ;
+
+ err = ::AECreateDesc(typeFSS, &location, sizeof(FSSpec), &mDefaultLocation );
+
+ if ( mDefaultLocation.dataHandle )
+ {
+ if (mSelectDefault)
+ {
+ mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
+ } else {
+ mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation;
+ }
+ }
+
+ memset( &mNavReply , 0 , sizeof( mNavReply ) ) ;
+ mNavReply.validRecord = false;
+ mNavReply.replacing = false;
+ mNavReply.isStationery = false;
+ mNavReply.translationNeeded = false;
+ mNavReply.selection.descriptorType = typeNull;
+ mNavReply.selection.dataHandle = nil;
+ mNavReply.keyScript = smSystemScript;
+ mNavReply.fileTranslation = nil;
+ mNavReply.version = kNavReplyRecordVersion ;
+
+ // zero all data
+
+ m_path = wxEmptyString ;
+ m_fileName = wxEmptyString ;
+ m_paths.Empty();
+ m_fileNames.Empty();
+
+ OpenUserDataRec myData;
+ MakeUserDataRec( &myData , m_wildCard ) ;
+ myData.currentfilter = m_filterIndex ;
+ if ( myData.extensions.GetCount() > 0 )
+ {
+ mNavOptions.popupExtension = (NavMenuItemSpecArrayHandle) NewHandle( sizeof( NavMenuItemSpec ) * myData.extensions.GetCount() ) ;
+ myData.menuitems = mNavOptions.popupExtension ;
+ for ( size_t i = 0 ; i < myData.extensions.GetCount() ; ++i )
+ {
+ (*mNavOptions.popupExtension)[i].version = kNavMenuItemSpecVersion ;
+ (*mNavOptions.popupExtension)[i].menuCreator = 'WXNG' ;
+ // TODO : according to the new docs -1 to 10 are reserved for the OS
+ (*mNavOptions.popupExtension)[i].menuType = i ;
+ wxMacStringToPascal( myData.name[i] , (StringPtr)(*mNavOptions.popupExtension)[i].menuItemName ) ;
+ }
+ }
+ if ( m_dialogStyle & wxSAVE )
+ {
+ myData.saveMode = true ;
+
+ mNavOptions.dialogOptionFlags |= kNavDontAutoTranslate ;
+ mNavOptions.dialogOptionFlags |= kNavDontAddTranslateItems ;
+
+ err = ::NavPutFile(
+ &mDefaultLocation,
+ &mNavReply,
+ &mNavOptions,
+ sStandardNavEventFilter ,
+ NULL,
+ kNavGenericSignature,
+ &myData); // User Data
+ m_filterIndex = myData.currentfilter ;
+ }
+ else
+ {
+ myData.saveMode = false ;
+
+ mNavFilterUPP = NewNavObjectFilterUPP( CrossPlatformFilterCallback ) ;
+ if ( m_dialogStyle & wxMULTIPLE )
+ mNavOptions.dialogOptionFlags |= kNavAllowMultipleFiles ;
+ else
+ mNavOptions.dialogOptionFlags &= ~kNavAllowMultipleFiles ;
+
+ err = ::NavGetFile(
+ &mDefaultLocation,
+ &mNavReply,
+ &mNavOptions,
+ sStandardNavEventFilter ,
+ mNavPreviewUPP,
+ mNavFilterUPP,
+ NULL ,
+ &myData);
+ m_filterIndex = myData.currentfilter ;
+ }
+
+ DisposeNavObjectFilterUPP(mNavFilterUPP);
+ if ( mDefaultLocation.dataHandle != nil )
+ {
+ ::AEDisposeDesc(&mDefaultLocation);
+ }
+
+ if ( (err != noErr) && (err != userCanceledErr) ) {
+ return wxID_CANCEL ;
+ }