X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bfa92264c07d094c05e5a07a17fd7f5bcee8e81f..0afeb753e0a6a3fdba290bf3612bb2f012d44d95:/src/osx/cocoa/dirdlg.mm diff --git a/src/osx/cocoa/dirdlg.mm b/src/osx/cocoa/dirdlg.mm index 37e32fe813..02f92f94f8 100644 --- a/src/osx/cocoa/dirdlg.mm +++ b/src/osx/cocoa/dirdlg.mm @@ -4,7 +4,7 @@ // Author: Stefan Csomor // Modified by: // 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 ///////////////////////////////////////////////////////////////////////////// @@ -31,6 +31,8 @@ #endif #include "wx/filename.h" +#include "wx/evtloop.h" +#include "wx/modalhook.h" #include "wx/osx/private.h" @@ -45,14 +47,17 @@ wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message, SetMessage( message ); SetWindowStyle(style); SetPath(defaultPath); + m_sheetDelegate = [[ModalDialogDelegate alloc] init]; + [(ModalDialogDelegate*)m_sheetDelegate setImplementation: this]; } -void wxDirDialog::ShowWindowModal() +wxDirDialog::~wxDirDialog() +{ + [m_sheetDelegate release]; +} + +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]; @@ -61,40 +66,40 @@ void wxDirDialog::ShowWindowModal() wxCFStringRef cf( m_message ); [oPanel setMessage:cf.AsNSString()]; - if ( HasFlag(wxDD_NEW_DIR_BUTTON) ) + if ( !HasFlag(wxDD_DIR_MUST_EXIST) ) [oPanel setCanCreateDirectories:YES]; - + + return oPanel; +} + +void wxDirDialog::ShowWindowModal() +{ wxNonOwnedWindow* parentWindow = NULL; - + if (GetParent()) parentWindow = dynamic_cast(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]; - } + + 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() { - 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 ); @@ -115,11 +120,11 @@ void wxDirDialog::ModalFinishedCallback(void* panel, int returnCode) 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); - + if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL) SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED ); }