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);
51 int wxDirDialog::ShowModal()
53 int result = wxID_CANCEL;
55 NSOpenPanel *oPanel = [NSOpenPanel openPanel];
56 [oPanel setCanChooseDirectories:YES];
57 [oPanel setResolvesAliases:YES];
58 [oPanel setCanChooseFiles:NO];
60 wxCFStringRef cf( m_message );
61 [oPanel setMessage:cf.AsNSString()];
63 if ( HasFlag(wxDD_NEW_DIR_BUTTON) )
64 [oPanel setCanCreateDirectories:YES];
66 wxCFStringRef dir( m_path );
68 m_path = wxEmptyString;
70 wxNonOwnedWindow* parentWindow = NULL;
75 parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent()));
79 fprintf(stderr, "No parent!\n");
85 NSWindow* nativeParent = parentWindow->GetWXWindow();
86 ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init];
87 [oPanel beginSheetForDirectory:dir.AsNSString() file:nil types: nil
88 modalForWindow: nativeParent modalDelegate: sheetDelegate
89 didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
91 [sheetDelegate waitForSheetToFinish];
92 returnCode = [sheetDelegate code];
93 [sheetDelegate release];
98 returnCode = (NSInteger)[oPanel runModalForDirectory:dir.AsNSString() file:nil types:nil];
100 if (returnCode == NSOKButton )
102 wxCFStringRef resultpath( [[[oPanel filenames] objectAtIndex:0] retain] );
104 SetPath( resultpath.AsString() );
110 #endif // wxUSE_DIRDLG