1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/dirdlg.mm
3 // Purpose: wxDirDialog
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: dirdlg.mm 40007 2006-07-05 13:10:46Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
23 #if wxUSE_DIRDLG && !defined(__WXUNIVERSAL__)
25 #include "wx/dirdlg.h"
28 #include "wx/msgdlg.h"
29 #include "wx/filedlg.h"
33 #include "wx/filename.h"
35 #include "wx/osx/private.h"
37 IMPLEMENT_CLASS(wxDirDialog, wxDialog)
39 wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
40 const wxString& defaultPath, long style, const wxPoint& WXUNUSED(pos),
41 const wxSize& WXUNUSED(size), const wxString& WXUNUSED(name))
45 SetMessage( message );
46 SetWindowStyle(style);
50 void wxDirDialog::ShowWindowModal()
52 wxCFStringRef dir( m_path );
54 m_modality = wxDIALOG_MODALITY_WINDOW_MODAL;
56 NSOpenPanel *oPanel = [NSOpenPanel openPanel];
57 [oPanel setCanChooseDirectories:YES];
58 [oPanel setResolvesAliases:YES];
59 [oPanel setCanChooseFiles:NO];
61 wxCFStringRef cf( m_message );
62 [oPanel setMessage:cf.AsNSString()];
64 if ( HasFlag(wxDD_NEW_DIR_BUTTON) )
65 [oPanel setCanCreateDirectories:YES];
67 wxNonOwnedWindow* parentWindow = NULL;
70 parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent()));
72 wxASSERT_MSG(parentWindow, "Window modal display requires parent.");
76 NSWindow* nativeParent = parentWindow->GetWXWindow();
77 ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init];
78 [sheetDelegate setImplementation: this];
79 [oPanel beginSheetForDirectory:dir.AsNSString() file:nil types: nil
80 modalForWindow: nativeParent modalDelegate: sheetDelegate
81 didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
86 int wxDirDialog::ShowModal()
88 NSOpenPanel *oPanel = [NSOpenPanel openPanel];
89 [oPanel setCanChooseDirectories:YES];
90 [oPanel setResolvesAliases:YES];
91 [oPanel setCanChooseFiles:NO];
93 wxCFStringRef cf( m_message );
94 [oPanel setMessage:cf.AsNSString()];
96 if ( HasFlag(wxDD_NEW_DIR_BUTTON) )
97 [oPanel setCanCreateDirectories:YES];
99 wxCFStringRef dir( m_path );
101 m_path = wxEmptyString;
105 returnCode = (NSInteger)[oPanel runModalForDirectory:dir.AsNSString() file:nil types:nil];
106 ModalFinishedCallback(oPanel, returnCode);
108 return GetReturnCode();
111 void wxDirDialog::ModalFinishedCallback(void* panel, int returnCode)
113 int result = wxID_CANCEL;
115 if (returnCode == NSOKButton )
117 NSOpenPanel* oPanel = (NSOpenPanel*)panel;
118 SetPath( wxCFStringRef::AsString([[oPanel filenames] objectAtIndex:0]));
121 SetReturnCode(result);
123 if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL)
124 SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED );
127 #endif // wxUSE_DIRDLG