]>
Commit | Line | Data |
---|---|---|
0f9b48d1 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/osx/cocoa/dirdlg.mm | |
03647350 | 3 | // Purpose: wxDirDialog |
0f9b48d1 | 4 | // Author: Stefan Csomor |
03647350 | 5 | // Modified by: |
0f9b48d1 SC |
6 | // Created: 2008-08-30 |
7 | // RCS-ID: $Id: dirdlg.mm 40007 2006-07-05 13:10:46Z SC $ | |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // For compilers that support precompilation, includes "wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #if wxUSE_DIRDLG && !defined(__WXUNIVERSAL__) | |
24 | ||
25 | #include "wx/dirdlg.h" | |
26 | ||
27 | #ifndef WX_PRECOMP | |
28 | #include "wx/msgdlg.h" | |
29 | #include "wx/filedlg.h" | |
30 | #include "wx/app.h" | |
31 | #endif | |
32 | ||
33 | #include "wx/filename.h" | |
34 | ||
35 | #include "wx/osx/private.h" | |
36 | ||
37 | IMPLEMENT_CLASS(wxDirDialog, wxDialog) | |
38 | ||
39 | wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message, | |
d8207702 SC |
40 | const wxString& defaultPath, long style, const wxPoint& WXUNUSED(pos), |
41 | const wxSize& WXUNUSED(size), const wxString& WXUNUSED(name)) | |
0f9b48d1 SC |
42 | { |
43 | m_parent = parent; | |
44 | ||
45 | SetMessage( message ); | |
46 | SetWindowStyle(style); | |
47 | SetPath(defaultPath); | |
48 | } | |
49 | ||
50 | ||
51 | int wxDirDialog::ShowModal() | |
52 | { | |
53 | int result = wxID_CANCEL; | |
03647350 | 54 | |
0f9b48d1 SC |
55 | NSOpenPanel *oPanel = [NSOpenPanel openPanel]; |
56 | [oPanel setCanChooseDirectories:YES]; | |
57 | [oPanel setResolvesAliases:YES]; | |
58 | [oPanel setCanChooseFiles:NO]; | |
03647350 | 59 | |
0f9b48d1 SC |
60 | wxCFStringRef cf( m_message ); |
61 | [oPanel setMessage:cf.AsNSString()]; | |
03647350 VZ |
62 | |
63 | if ( HasFlag(wxDD_NEW_DIR_BUTTON) ) | |
0f9b48d1 SC |
64 | [oPanel setCanCreateDirectories:YES]; |
65 | ||
66 | wxCFStringRef dir( m_path ); | |
03647350 | 67 | |
0f9b48d1 | 68 | m_path = wxEmptyString; |
a905992c KO |
69 | |
70 | wxNonOwnedWindow* parentWindow = NULL; | |
71 | int returnCode = -1; | |
03647350 VZ |
72 | |
73 | if (GetParent()) | |
a905992c KO |
74 | { |
75 | parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent())); | |
76 | } | |
77 | else | |
78 | { | |
79 | fprintf(stderr, "No parent!\n"); | |
80 | } | |
440e5cb2 | 81 | |
03647350 | 82 | /* |
a905992c KO |
83 | if (parentWindow) |
84 | { | |
85 | NSWindow* nativeParent = parentWindow->GetWXWindow(); | |
03647350 VZ |
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:) | |
a905992c KO |
90 | contextInfo: nil]; |
91 | [sheetDelegate waitForSheetToFinish]; | |
92 | returnCode = [sheetDelegate code]; | |
93 | [sheetDelegate release]; | |
94 | } | |
95 | else | |
440e5cb2 | 96 | */ |
a905992c KO |
97 | { |
98 | returnCode = (NSInteger)[oPanel runModalForDirectory:dir.AsNSString() file:nil types:nil]; | |
99 | } | |
100 | if (returnCode == NSOKButton ) | |
0f9b48d1 | 101 | { |
f66ecdc4 | 102 | SetPath( wxCFStringRef::AsString([[oPanel filenames] objectAtIndex:0])); |
0f9b48d1 SC |
103 | result = wxID_OK; |
104 | } | |
105 | return result; | |
106 | } | |
107 | ||
108 | #endif // wxUSE_DIRDLG |