+ dialogCreateOptions.windowTitle = titleRef;
+#if wxUSE_UNICODE
+ CFStringRef defaultFileNameRef = ::CFStringCreateWithCString(NULL,
+ m_fileName.wc_str(),
+ kCFStringEncodingUnicode);
+#else
+ CFStringRef defaultFileNameRef = ::CFStringCreateWithCString(NULL,
+ m_fileName.c_str(),
+ CFStringGetSystemEncoding());
+#endif
+ dialogCreateOptions.saveFileName = defaultFileNameRef;
+ NavDialogRef dialog;
+ NavObjectFilterUPP navFilterUPP = NULL;
+ CFArrayRef cfArray = NULL; // for popupExtension
+ OpenUserDataRec myData;
+ myData.defaultLocation = m_dir;
+
+ if (m_dialogStyle & wxSAVE)
+ {
+ dialogCreateOptions.optionFlags |= kNavNoTypePopup;
+ dialogCreateOptions.optionFlags |= kNavDontAutoTranslate;
+ dialogCreateOptions.optionFlags |= kNavDontAddTranslateItems;
+
+ // The extension is important
+ dialogCreateOptions.optionFlags |= kNavPreserveSaveFileExtension;
+
+
+ err = ::NavCreatePutFileDialog(&dialogCreateOptions,
+ 'TEXT',
+ 'TEXT',
+ sStandardNavEventFilter,
+ &myData, // for defaultLocation
+ &dialog);
+ }
+ else
+ {
+ MakeUserDataRec(&myData , m_wildCard);
+ int numfilters = myData.extensions.GetCount();
+ if (numfilters > 0){
+ CFMutableArrayRef popup = CFArrayCreateMutable( kCFAllocatorDefault ,
+ numfilters , &kCFTypeArrayCallBacks ) ;
+ dialogCreateOptions.popupExtension = popup ;
+ myData.menuitems = dialogCreateOptions.popupExtension ;
+ for ( size_t i = 0 ; i < numfilters ; ++i )
+ {
+ CFArrayAppendValue( popup , (CFStringRef) wxMacCFStringHolder( myData.name[i] ) ) ;
+ }
+ }
+ navFilterUPP = NewNavObjectFilterUPP(CrossPlatformFilterCallback);
+ err = ::NavCreateGetFileDialog(&dialogCreateOptions,
+ NULL, // NavTypeListHandle
+ sStandardNavEventFilter,
+ NULL, // NavPreviewUPP
+ navFilterUPP,
+ (void *) &myData, // inClientData
+ &dialog);
+ }
+
+ if (err == noErr)
+ err = ::NavDialogRun(dialog);
+
+ // 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;
+ char thePath[FILENAME_MAX];
+
+ 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;
+
+ if (m_dialogStyle & wxSAVE)
+ {
+ thePath[0] = '\0';
+ CFURLRef parentURLRef = ::CFURLCreateFromFSRef(NULL, &theFSRef);
+
+ if (parentURLRef)
+ {
+ CFURLRef fullURLRef =
+ ::CFURLCreateCopyAppendingPathComponent(NULL,
+ parentURLRef,
+ navReply.saveFileName,
+ false);
+ ::CFRelease(parentURLRef);
+ if (fullURLRef)
+ {
+ CFStringRef cfString = ::CFURLCopyPath(fullURLRef);
+ ::CFRelease(fullURLRef);
+
+ if (cfString)
+ {
+ // unescape the URL for
+ // "file name" instead of "file%20name"
+ CFStringRef cfStringUnescaped =
+ ::CFURLCreateStringByReplacingPercentEscapes(NULL,
+ cfString,
+ CFSTR(""));
+ ::CFRelease(cfString);
+
+ if (cfStringUnescaped)
+ {
+#if wxUSE_UNICODE
+ ::CFStringGetCString(cfStringUnescaped,
+ thePath,
+ FILENAME_MAX,
+ kCFStringEncodingUnicode);
+#else
+ ::CFStringGetCString(cfStringUnescaped,
+ thePath,
+ FILENAME_MAX,
+ CFStringGetSystemEncoding());
+#endif
+ ::CFRelease(cfStringUnescaped);
+ }
+ }
+ }
+ }
+ if (!thePath[0])
+ {
+ ::NavDisposeReply(&navReply);
+ return wxID_CANCEL;
+ }
+ }
+ else
+ {
+ err = ::FSRefMakePath(&theFSRef,
+ (UInt8 *)thePath, sizeof(thePath));
+ if (err != noErr)
+ break;
+ }
+ 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;