X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/685a634c8daac07785cef430d80b2d0489546038..7688f0a1f784b6f2f551e63d4eeff7bab3ea46ff:/src/mac/carbon/filedlg.cpp diff --git a/src/mac/carbon/filedlg.cpp b/src/mac/carbon/filedlg.cpp index b82a45ee47..59807f398d 100644 --- a/src/mac/carbon/filedlg.cpp +++ b/src/mac/carbon/filedlg.cpp @@ -20,6 +20,7 @@ #include "wx/filedlg.h" #include "wx/intl.h" #include "wx/tokenzr.h" +#include "wx/filename.h" #ifndef __DARWIN__ #include "PLStringFuncs.h" @@ -140,7 +141,7 @@ NavEventProc( { sfilename = sfilename.Left(pos+1)+extension ; #if TARGET_CARBON - cfString = sfilename ; + cfString.Assign( sfilename , wxFONTENCODING_DEFAULT ) ; NavDialogSetSaveFileName( ioParams->context , cfString ) ; #else wxMacStringToPascal( sfilename , filename ) ; @@ -152,24 +153,6 @@ NavEventProc( } } -const wxChar * gfilters[] = -{ - wxT("*.TXT") , - wxT("*.TIF") , - wxT("*.JPG") , - - NULL -} ; - -OSType gfiltersmac[] = -{ - 'TEXT' , - 'TIFF' , - 'JPEG' , - - '****' -} ; - void MakeUserDataRec(OpenUserDataRec *myData , const wxString& filter ) { @@ -218,19 +201,26 @@ void MakeUserDataRec(OpenUserDataRec *myData , const wxString& filter ) const size_t extCount = myData->extensions.GetCount(); for ( size_t i = 0 ; i < extCount; i++ ) { - int j ; - for ( j = 0 ; gfilters[j] ; j++ ) + wxUint32 fileType; + wxUint32 creator; + wxString extension = myData->extensions[i]; + + if (extension.GetChar(0) == '*') + extension = extension.Mid(1); // Remove leading * + + if (extension.GetChar(0) == '.') { - if ( myData->extensions[i] == gfilters[j] ) - { - myData->filtermactypes.Add( gfiltersmac[j] ) ; - break ; - } + extension = extension.Mid(1); // Remove leading . } - if( gfilters[j] == NULL ) + + if (wxFileName::MacFindDefaultTypeAndCreator( extension, &fileType, &creator )) { - myData->filtermactypes.Add( '****' ) ; + myData->filtermactypes.Add( (OSType)fileType ); } + else + { + myData->filtermactypes.Add( '****' ) ; // We'll fail safe if it's not recognized + } } } } @@ -332,10 +322,20 @@ pascal Boolean CrossPlatformFilterCallback ( { FSRef fsref ; memcpy( &fsref , *theItem->dataHandle , sizeof(FSRef) ) ; - wxString file ; - const short maxpath = 1024 ; - FSRefMakePath( &fsref , (UInt8*) file.GetWriteBuf(maxpath+1),maxpath) ; - file.UngetWriteBuf() ; + + + + CFURLRef fullURLRef; + fullURLRef = ::CFURLCreateFromFSRef(NULL, &fsref); +#ifdef __UNIX__ + CFURLPathStyle pathstyle = kCFURLPOSIXPathStyle; +#else + CFURLPathStyle pathstyle = kCFURLHFSPathStyle; +#endif + CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, pathstyle); + ::CFRelease( fullURLRef ) ; + wxString file = wxMacCFStringHolder(cfString).AsString(wxFont::GetDefaultEncoding()); + display = CheckFile( file , theInfo->fileAndFolder.fileInfo.finderInfo.fdType , data ) ; } #endif @@ -356,29 +356,13 @@ int wxFileDialog::ShowModal() // this was always unset in the old code dialogCreateOptions.optionFlags &= ~kNavSelectDefaultLocation; -#if wxUSE_UNICODE - // tried using wxMacCFStringHolder in the code below, but it seems - // the CFStrings were being released before the save dialog was called, - // causing a crash - open dialog works fine with or without wxMacCFStringHolder - CFStringRef titleRef = ::CFStringCreateWithCString(NULL, - m_message.wc_str(), - kCFStringEncodingUnicode); -#else - CFStringRef titleRef = ::CFStringCreateWithCString(NULL, - m_message.c_str(), - CFStringGetSystemEncoding()); -#endif - 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; + wxMacCFStringHolder message(m_message, m_font.GetEncoding()); + dialogCreateOptions.windowTitle = message; + + wxMacCFStringHolder defaultFileName(m_fileName, m_font.GetEncoding()); + dialogCreateOptions.saveFileName = defaultFileName; + + NavDialogRef dialog; NavObjectFilterUPP navFilterUPP = NULL; CFArrayRef cfArray = NULL; // for popupExtension @@ -413,7 +397,7 @@ int wxFileDialog::ShowModal() myData.menuitems = dialogCreateOptions.popupExtension ; for ( size_t i = 0 ; i < numfilters ; ++i ) { - CFArrayAppendValue( popup , (CFStringRef) wxMacCFStringHolder( myData.name[i] ) ) ; + CFArrayAppendValue( popup , (CFStringRef) wxMacCFStringHolder( myData.name[i] , m_font.GetEncoding() ) ) ; } } @@ -434,20 +418,8 @@ int wxFileDialog::ShowModal() 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; @@ -459,75 +431,46 @@ int wxFileDialog::ShowModal() DescType actualType; Size actualSize; FSRef theFSRef; - char thePath[FILENAME_MAX]; - + wxString thePath ; long count; ::AECountItems(&navReply.selection , &count); for (long i = 1; i <= count; ++i) { - err = ::AEGetNthPtr(&(navReply.selection), 1, typeFSRef, &theKeyword, &actualType, + err = ::AEGetNthPtr(&(navReply.selection), i, typeFSRef, &theKeyword, &actualType, &theFSRef, sizeof(theFSRef), &actualSize); if (err != noErr) break; + CFURLRef fullURLRef; if (m_dialogStyle & wxSAVE) { - thePath[0] = '\0'; CFURLRef parentURLRef = ::CFURLCreateFromFSRef(NULL, &theFSRef); if (parentURLRef) { - CFURLRef fullURLRef = + 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; + fullURLRef = ::CFURLCreateFromFSRef(NULL, &theFSRef); + } +#ifdef __UNIX__ + CFURLPathStyle pathstyle = kCFURLPOSIXPathStyle; +#else + CFURLPathStyle pathstyle = kCFURLHFSPathStyle; +#endif + CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, pathstyle); + thePath = wxMacCFStringHolder(cfString).AsString(m_font.GetEncoding()); + if (!thePath) + { + ::NavDisposeReply(&navReply); + return wxID_CANCEL; } m_path = thePath; m_paths.Add(m_path);