]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/dirdlg.mm
Add wxTimer::StartOnce().
[wxWidgets.git] / src / osx / cocoa / dirdlg.mm
index 9ab49d86ec3e12ddd5f96a504069c32924563b63..02f92f94f834021452b8ae1fef664c9c9fce5ede 100644 (file)
@@ -1,10 +1,10 @@
 /////////////////////////////////////////////////////////////////////////////
 // Name:        src/osx/cocoa/dirdlg.mm
 /////////////////////////////////////////////////////////////////////////////
 // Name:        src/osx/cocoa/dirdlg.mm
-// Purpose:     wxDirDialog  
+// Purpose:     wxDirDialog
 // Author:      Stefan Csomor
 // Author:      Stefan Csomor
-// Modified by: 
+// Modified by:
 // Created:     2008-08-30
 // Created:     2008-08-30
-// RCS-ID:      $Id: dirdlg.mm 40007 2006-07-05 13:10:46Z SC $
+// RCS-ID:      $Id$
 // Copyright:   (c) Stefan Csomor
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 // Copyright:   (c) Stefan Csomor
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
@@ -31,6 +31,8 @@
 #endif
 
 #include "wx/filename.h"
 #endif
 
 #include "wx/filename.h"
+#include "wx/evtloop.h"
+#include "wx/modalhook.h"
 
 #include "wx/osx/private.h"
 
 
 #include "wx/osx/private.h"
 
@@ -45,64 +47,86 @@ wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
     SetMessage( message );
     SetWindowStyle(style);
     SetPath(defaultPath);
     SetMessage( message );
     SetWindowStyle(style);
     SetPath(defaultPath);
+    m_sheetDelegate = [[ModalDialogDelegate alloc] init];
+    [(ModalDialogDelegate*)m_sheetDelegate setImplementation: this];
 }
 
 }
 
+wxDirDialog::~wxDirDialog()
+{
+    [m_sheetDelegate release];
+}
 
 
-int wxDirDialog::ShowModal()
+WX_NSOpenPanel wxDirDialog::OSXCreatePanel() const
 {
 {
-    int result = wxID_CANCEL;
-    
     NSOpenPanel *oPanel = [NSOpenPanel openPanel];
     [oPanel setCanChooseDirectories:YES];
     [oPanel setResolvesAliases:YES];
     [oPanel setCanChooseFiles:NO];
     NSOpenPanel *oPanel = [NSOpenPanel openPanel];
     [oPanel setCanChooseDirectories:YES];
     [oPanel setResolvesAliases:YES];
     [oPanel setCanChooseFiles:NO];
-    
+
     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;
+
+    if (GetParent())
+        parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent()));
+
+    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()
+{
+    WX_HOOK_MODAL_DIALOG();
+
+    wxCFEventLoopPauseIdleEvents pause;
+
+    NSOpenPanel *oPanel = OSXCreatePanel();
+
     wxCFStringRef dir( m_path );
     wxCFStringRef dir( m_path );
-    
+
     m_path = wxEmptyString;
 
     m_path = wxEmptyString;
 
-    wxNonOwnedWindow* parentWindow = NULL;
     int returnCode = -1;
     int returnCode = -1;
-    
-    if (GetParent()) 
-    {
-        parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent()));
-    }
-    else
-    {
-        fprintf(stderr, "No parent!\n");
-    }
 
 
-/*    
-    if (parentWindow)
-    {
-        NSWindow* nativeParent = parentWindow->GetWXWindow();
-        ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init]; 
-        [oPanel beginSheetForDirectory:dir.AsNSString() file:nil types: nil 
-            modalForWindow: nativeParent modalDelegate: sheetDelegate 
-            didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:) 
-            contextInfo: nil];
-        [sheetDelegate waitForSheetToFinish];
-        returnCode = [sheetDelegate code];
-        [sheetDelegate release];
-    }
-    else
-*/
-    {
-        returnCode = (NSInteger)[oPanel runModalForDirectory:dir.AsNSString() file:nil types:nil];
-    }
+    returnCode = (NSInteger)[oPanel runModalForDirectory:dir.AsNSString() file:nil types:nil];
+    ModalFinishedCallback(oPanel, returnCode);
+
+    return GetReturnCode();
+}
+
+void wxDirDialog::ModalFinishedCallback(void* panel, int returnCode)
+{
+    int result = wxID_CANCEL;
+
     if (returnCode == NSOKButton )
     {
     if (returnCode == NSOKButton )
     {
-        SetPath( wxCFStringRef::AsString([[oPanel filenames] objectAtIndex:0]));
+        NSOpenPanel* oPanel = (NSOpenPanel*)panel;
+        SetPath( wxCFStringRef::AsStringWithNormalizationFormC([[oPanel filenames] objectAtIndex:0]));
         result = wxID_OK;
     }
         result = wxID_OK;
     }
-    return result;
+    SetReturnCode(result);
+
+    if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL)
+        SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED  );
 }
 
 #endif // wxUSE_DIRDLG
 }
 
 #endif // wxUSE_DIRDLG