]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/filedlg.cpp
applied patch 923858 (fixes crash in zlib streams)
[wxWidgets.git] / src / mac / carbon / filedlg.cpp
index e70ffbdf4cc66b09eb22e5f144dba27437141289..59807f398d9aba4bd8e2b450ee9bfee982ddf04d 100644 (file)
@@ -141,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 ) ;
@@ -322,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
@@ -346,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 = ::CFStringCreateWithCharacters( kCFAllocatorDefault,
-                                (const unsigned short*)m_message.wc_str(), 
-                                m_message.Len() );
-#else
-    CFStringRef titleRef = ::CFStringCreateWithCString(NULL,
-                                                       m_message.c_str(),
-                                                       CFStringGetSystemEncoding());
-#endif
-    dialogCreateOptions.windowTitle = titleRef;
-#if wxUSE_UNICODE
-    CFStringRef defaultFileNameRef = ::CFStringCreateWithCharacters( kCFAllocatorDefault,
-                                        (const unsigned short*)m_fileName.wc_str(), 
-                                        m_fileName.Len() );
-#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
@@ -403,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() ) ) ;
             }
         }
 
@@ -424,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;
 
@@ -454,7 +436,7 @@ int wxFileDialog::ShowModal()
         ::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;
@@ -484,7 +466,7 @@ int wxFileDialog::ShowModal()
             CFURLPathStyle pathstyle = kCFURLHFSPathStyle;
 #endif
             CFStringRef cfString = CFURLCopyFileSystemPath(fullURLRef, pathstyle);
-            thePath = wxMacCFStringHolder(cfString).AsString();
+            thePath = wxMacCFStringHolder(cfString).AsString(m_font.GetEncoding());
             if (!thePath)
             {
                 ::NavDisposeReply(&navReply);