]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/dirdlg.mm
guarding open combo box against AppDefined NSEvents issued by wxEventLoop::WakeUp...
[wxWidgets.git] / src / osx / cocoa / dirdlg.mm
index 7d7dc66a2193e93de42814c758c0419d49d2823a..02f92f94f834021452b8ae1fef664c9c9fce5ede 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "wx/filename.h"
 #include "wx/evtloop.h"
 
 #include "wx/filename.h"
 #include "wx/evtloop.h"
+#include "wx/modalhook.h"
 
 #include "wx/osx/private.h"
 
 
 #include "wx/osx/private.h"
 
@@ -55,12 +56,8 @@ wxDirDialog::~wxDirDialog()
     [m_sheetDelegate release];
 }
 
     [m_sheetDelegate release];
 }
 
-void wxDirDialog::ShowWindowModal()
+WX_NSOpenPanel wxDirDialog::OSXCreatePanel() const
 {
 {
-    wxCFStringRef dir( m_path );
-    
-    m_modality = wxDIALOG_MODALITY_WINDOW_MODAL;
-    
     NSOpenPanel *oPanel = [NSOpenPanel openPanel];
     [oPanel setCanChooseDirectories:YES];
     [oPanel setResolvesAliases:YES];
     NSOpenPanel *oPanel = [NSOpenPanel openPanel];
     [oPanel setCanChooseDirectories:YES];
     [oPanel setResolvesAliases:YES];
@@ -69,40 +66,40 @@ void wxDirDialog::ShowWindowModal()
     wxCFStringRef cf( m_message );
     [oPanel setMessage:cf.AsNSString()];
 
     wxCFStringRef cf( m_message );
     [oPanel setMessage:cf.AsNSString()];
 
-    if ( HasFlag(wxDD_NEW_DIR_BUTTON) )
+    if ( !HasFlag(wxDD_DIR_MUST_EXIST) )
         [oPanel setCanCreateDirectories:YES];
         [oPanel setCanCreateDirectories:YES];
-    
+
+    return oPanel;
+}
+
+void wxDirDialog::ShowWindowModal()
+{
     wxNonOwnedWindow* parentWindow = NULL;
     wxNonOwnedWindow* parentWindow = NULL;
-    
+
     if (GetParent())
         parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent()));
     if (GetParent())
         parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent()));
-    
-    wxASSERT_MSG(parentWindow, "Window modal display requires parent.");
-    
-    if (parentWindow)
-    {
-        NSWindow* nativeParent = parentWindow->GetWXWindow();
-        [oPanel beginSheetForDirectory:dir.AsNSString() file:nil types: nil
-            modalForWindow: nativeParent modalDelegate: m_sheetDelegate
-            didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
-            contextInfo: nil];
-    }
+
+    wxCHECK_RET(parentWindow, "Window modal display requires parent.");
+
+    m_modality = wxDIALOG_MODALITY_WINDOW_MODAL;
+
+    NSOpenPanel *oPanel = OSXCreatePanel();
+
+    NSWindow* nativeParent = parentWindow->GetWXWindow();
+    wxCFStringRef dir( m_path );
+    [oPanel beginSheetForDirectory:dir.AsNSString() file:nil types: nil
+        modalForWindow: nativeParent modalDelegate: m_sheetDelegate
+        didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
+        contextInfo: nil];
 }
 
 int wxDirDialog::ShowModal()
 {
 }
 
 int wxDirDialog::ShowModal()
 {
-    wxCFEventLoopPauseIdleEvents pause;
-
-    NSOpenPanel *oPanel = [NSOpenPanel openPanel];
-    [oPanel setCanChooseDirectories:YES];
-    [oPanel setResolvesAliases:YES];
-    [oPanel setCanChooseFiles:NO];
+    WX_HOOK_MODAL_DIALOG();
 
 
-    wxCFStringRef cf( m_message );
-    [oPanel setMessage:cf.AsNSString()];
+    wxCFEventLoopPauseIdleEvents pause;
 
 
-    if ( HasFlag(wxDD_NEW_DIR_BUTTON) )
-        [oPanel setCanCreateDirectories:YES];
+    NSOpenPanel *oPanel = OSXCreatePanel();
 
     wxCFStringRef dir( m_path );
 
 
     wxCFStringRef dir( m_path );
 
@@ -123,11 +120,11 @@ void wxDirDialog::ModalFinishedCallback(void* panel, int returnCode)
     if (returnCode == NSOKButton )
     {
         NSOpenPanel* oPanel = (NSOpenPanel*)panel;
     if (returnCode == NSOKButton )
     {
         NSOpenPanel* oPanel = (NSOpenPanel*)panel;
-        SetPath( wxCFStringRef::AsString([[oPanel filenames] objectAtIndex:0]));
+        SetPath( wxCFStringRef::AsStringWithNormalizationFormC([[oPanel filenames] objectAtIndex:0]));
         result = wxID_OK;
     }
     SetReturnCode(result);
         result = wxID_OK;
     }
     SetReturnCode(result);
-    
+
     if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL)
         SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED  );
 }
     if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL)
         SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED  );
 }