]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/filedlg.mm
Fix install_name_tool calls in OS X "make install".
[wxWidgets.git] / src / osx / cocoa / filedlg.mm
index 0ab62f5bfad811ecb13139f44c7e0f450c89a42f..67f58554c456e1fe06f1a0e1a81a23fb7fb2189f 100644 (file)
@@ -4,7 +4,6 @@
 // Author:      Ryan Norton
 // Modified by:
 // Created:     2004-10-02
-// RCS-ID:      $Id$
 // Copyright:   (c) Ryan Norton
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 #include "wx/filename.h"
 #include "wx/tokenzr.h"
+#include "wx/evtloop.h"
 
 #include "wx/osx/private.h"
 #include "wx/sysopt.h"
+#include "wx/modalhook.h"
 
 #include <mach-o/dyld.h>
 
@@ -70,10 +71,8 @@ bool HasAppKit_10_6()
         // case above.
         version = NSVersionOfRunTimeLibrary("AppKit");
     }
-    if (version == -1)
-    {
-        return false;
-    }
+
+    // Notice that this still works correctly even if version is -1.
     return version >= 0x40e2400 /* version of 10.6 AppKit */;
 }
 
@@ -187,13 +186,20 @@ bool HasAppKit_10_6()
 
 IMPLEMENT_CLASS(wxFileDialog, wxFileDialogBase)
 
-wxFileDialog::wxFileDialog(
+void wxFileDialog::Init()
+{
+    m_filterIndex = -1;
+    m_delegate = nil;
+    m_sheetDelegate = nil;
+}
+
+void wxFileDialog::Create(
     wxWindow *parent, const wxString& message,
     const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard,
     long style, const wxPoint& pos, const wxSize& sz, const wxString& name)
-    : wxFileDialogBase(parent, message, defaultDir, defaultFileName, wildCard, style, pos, sz, name)
 {
-    m_filterIndex = -1;
+    wxFileDialogBase::Create(parent, message, defaultDir, defaultFileName, wildCard, style, pos, sz, name);
+
     m_sheetDelegate = [[ModalDialogDelegate alloc] init];
     [(ModalDialogDelegate*)m_sheetDelegate setImplementation: this];
 }
@@ -397,7 +403,7 @@ wxWindow* wxFileDialog::CreateFilterPanel(wxWindow *extracontrol)
             if ( m_firstFileTypeFilter >= 0 )
                 m_filterChoice->SetSelection(m_firstFileTypeFilter);
         }
-        m_filterChoice->Connect(wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler(wxFileDialog::OnFilterSelected), NULL, this);
+        m_filterChoice->Connect(wxEVT_CHOICE, wxCommandEventHandler(wxFileDialog::OnFilterSelected), NULL, this);
     }
         
     if(extracontrol)
@@ -448,6 +454,11 @@ bool wxFileDialog::CheckFile( const wxString& filename )
 void wxFileDialog::SetupExtraControls(WXWindow nativeWindow)
 {
     NSSavePanel* panel = (NSSavePanel*) nativeWindow;
+    // for sandboxed app we cannot access the outer structures
+    // this leads to problems with extra controls, so as a temporary
+    // workaround for crashes we don't support those yet
+    if ( [panel contentView] == nil )
+        return;
     
     wxNonOwnedWindow::Create( GetParent(), nativeWindow );
     wxWindow* extracontrol = NULL;
@@ -458,7 +469,6 @@ void wxFileDialog::SetupExtraControls(WXWindow nativeWindow)
     }
 
     NSView* accView = nil;
-    m_delegate = nil;
 
     if ( m_useFileTypeFilter )
     {
@@ -496,6 +506,10 @@ void wxFileDialog::SetupExtraControls(WXWindow nativeWindow)
 
 int wxFileDialog::ShowModal()
 {
+    WX_HOOK_MODAL_DIALOG();
+
+    wxCFEventLoopPauseIdleEvents pause;
+
     wxMacAutoreleasePool autoreleasepool;
     
     wxCFStringRef cf( m_message );
@@ -647,7 +661,7 @@ void wxFileDialog::ModalFinishedCallback(void* panel, int returnCode)
             NSSavePanel* sPanel = (NSSavePanel*)panel;
             result = wxID_OK;
 
-            m_path = wxCFStringRef::AsString([sPanel filename]);
+            m_path = wxCFStringRef::AsStringWithNormalizationFormC([sPanel filename]);
             m_fileName = wxFileNameFromPath(m_path);
             m_dir = wxPathOnly( m_path );
             if (m_filterChoice)
@@ -666,7 +680,7 @@ void wxFileDialog::ModalFinishedCallback(void* panel, int returnCode)
             NSArray* filenames = [oPanel filenames];
             for ( size_t i = 0 ; i < [filenames count] ; ++ i )
             {
-                wxString fnstr = wxCFStringRef::AsString([filenames objectAtIndex:i]);
+                wxString fnstr = wxCFStringRef::AsStringWithNormalizationFormC([filenames objectAtIndex:i]);
                 m_paths.Add( fnstr );
                 m_fileNames.Add( wxFileNameFromPath(fnstr) );
                 if ( i == 0 )
@@ -689,7 +703,9 @@ void wxFileDialog::ModalFinishedCallback(void* panel, int returnCode)
     if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL)
         SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED  );
     
-    UnsubclassWin();
+    // workaround for sandboxed app, see above
+    if ( m_isNativeWindowWrapper )
+        UnsubclassWin();
     [(NSSavePanel*) panel setAccessoryView:nil];
 }