]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/filedlg.cpp
* In _GSocket_Get_Mac_Socket(), do not call CFSocketSetSocketFlags to turn
[wxWidgets.git] / src / mac / carbon / filedlg.cpp
index b82a45ee47c736a535b118e2f215a215e60887a9..f2cb493f4a84eff4ea571978f045c928cd052af3 100644 (file)
@@ -360,9 +360,9 @@ int wxFileDialog::ShowModal()
     // 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);
+    CFStringRef titleRef = ::CFStringCreateWithCharacters( kCFAllocatorDefault,
+                                (const unsigned short*)m_message.wc_str(), 
+                                m_message.Len() );
 #else
     CFStringRef titleRef = ::CFStringCreateWithCString(NULL,
                                                        m_message.c_str(),
@@ -370,9 +370,9 @@ int wxFileDialog::ShowModal()
 #endif
     dialogCreateOptions.windowTitle = titleRef;
 #if wxUSE_UNICODE
-    CFStringRef defaultFileNameRef = ::CFStringCreateWithCString(NULL,
-                                                                 m_fileName.wc_str(),
-                                                                 kCFStringEncodingUnicode);
+    CFStringRef defaultFileNameRef = ::CFStringCreateWithCharacters( kCFAllocatorDefault,
+                                        (const unsigned short*)m_fileName.wc_str(), 
+                                        m_fileName.Len() );
 #else
     CFStringRef defaultFileNameRef = ::CFStringCreateWithCString(NULL,
                                                                  m_fileName.c_str(),
@@ -459,8 +459,7 @@ 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)
@@ -470,64 +469,36 @@ int wxFileDialog::ShowModal()
             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();
+            if (!thePath)
+            {
+                ::NavDisposeReply(&navReply);
+                return wxID_CANCEL;
             }
             m_path = thePath;
             m_paths.Add(m_path);