]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/dirdlg.mm
Correct format specifiers used to show wxIPV4address.
[wxWidgets.git] / src / osx / cocoa / dirdlg.mm
index 6094f86e03751ee10a982e2b6d90316ddf5fe6b1..37e32fe813af66a6de1da23c8e292ec01844bbe9 100644 (file)
@@ -1,8 +1,8 @@
 /////////////////////////////////////////////////////////////////////////////
 // Name:        src/osx/cocoa/dirdlg.mm
-// Purpose:     wxDirDialog  
+// Purpose:     wxDirDialog
 // Author:      Stefan Csomor
-// Modified by: 
+// Modified by:
 // Created:     2008-08-30
 // RCS-ID:      $Id: dirdlg.mm 40007 2006-07-05 13:10:46Z SC $
 // Copyright:   (c) Stefan Csomor
@@ -37,8 +37,8 @@
 IMPLEMENT_CLASS(wxDirDialog, wxDialog)
 
 wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
-        const wxString& defaultPath, long style, const wxPoint& pos,
-        const wxSize& size, const wxString& name)
+        const wxString& defaultPath, long style, const wxPoint& WXUNUSED(pos),
+        const wxSize& WXUNUSED(size), const wxString& WXUNUSED(name))
 {
     m_parent = parent;
 
@@ -47,34 +47,81 @@ wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
     SetPath(defaultPath);
 }
 
-
-int wxDirDialog::ShowModal()
+void wxDirDialog::ShowWindowModal()
 {
-    int result = wxID_CANCEL;
+    wxCFStringRef dir( m_path );
+    
+    m_modality = wxDIALOG_MODALITY_WINDOW_MODAL;
     
     NSOpenPanel *oPanel = [NSOpenPanel openPanel];
     [oPanel setCanChooseDirectories:YES];
     [oPanel setResolvesAliases:YES];
     [oPanel setCanChooseFiles:NO];
+
+    wxCFStringRef cf( m_message );
+    [oPanel setMessage:cf.AsNSString()];
+
+    if ( HasFlag(wxDD_NEW_DIR_BUTTON) )
+        [oPanel setCanCreateDirectories:YES];
     
+    wxNonOwnedWindow* parentWindow = NULL;
+    
+    if (GetParent())
+        parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent()));
+    
+    wxASSERT_MSG(parentWindow, "Window modal display requires parent.");
+    
+    if (parentWindow)
+    {
+        NSWindow* nativeParent = parentWindow->GetWXWindow();
+        ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init];
+        [sheetDelegate setImplementation: this];
+        [oPanel beginSheetForDirectory:dir.AsNSString() file:nil types: nil
+            modalForWindow: nativeParent modalDelegate: sheetDelegate
+            didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
+            contextInfo: nil];
+    }
+}
+
+int wxDirDialog::ShowModal()
+{
+    NSOpenPanel *oPanel = [NSOpenPanel openPanel];
+    [oPanel setCanChooseDirectories:YES];
+    [oPanel setResolvesAliases:YES];
+    [oPanel setCanChooseFiles:NO];
+
     wxCFStringRef cf( m_message );
     [oPanel setMessage:cf.AsNSString()];
-    if ( HasFlag(wxDD_NEW_DIR_BUTTON) ) 
+
+    if ( HasFlag(wxDD_NEW_DIR_BUTTON) )
         [oPanel setCanCreateDirectories:YES];
 
     wxCFStringRef dir( m_path );
-    
+
     m_path = wxEmptyString;
-    
-    if ( [oPanel runModalForDirectory:dir.AsNSString() file:nil types:nil] == NSOKButton )
+
+    int returnCode = -1;
+
+    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 )
     {
-        wxCFStringRef resultpath( [[[oPanel filenames] objectAtIndex:0] retain] );
-        
-        SetPath( resultpath.AsString() );
+        NSOpenPanel* oPanel = (NSOpenPanel*)panel;
+        SetPath( wxCFStringRef::AsString([[oPanel filenames] objectAtIndex:0]));
         result = wxID_OK;
     }
-    return result;
+    SetReturnCode(result);
+    
+    if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL)
+        SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED  );
 }
 
 #endif // wxUSE_DIRDLG