]>
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 | 6 | // Created: 2008-08-30 |
a9a4f229 | 7 | // RCS-ID: $Id$ |
0f9b48d1 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 | ||
bfa92264 | 50 | void wxDirDialog::ShowWindowModal() |
0f9b48d1 | 51 | { |
bfa92264 KO |
52 | wxCFStringRef dir( m_path ); |
53 | ||
54 | m_modality = wxDIALOG_MODALITY_WINDOW_MODAL; | |
55 | ||
0f9b48d1 SC |
56 | NSOpenPanel *oPanel = [NSOpenPanel openPanel]; |
57 | [oPanel setCanChooseDirectories:YES]; | |
58 | [oPanel setResolvesAliases:YES]; | |
59 | [oPanel setCanChooseFiles:NO]; | |
03647350 | 60 | |
0f9b48d1 SC |
61 | wxCFStringRef cf( m_message ); |
62 | [oPanel setMessage:cf.AsNSString()]; | |
03647350 VZ |
63 | |
64 | if ( HasFlag(wxDD_NEW_DIR_BUTTON) ) | |
0f9b48d1 | 65 | [oPanel setCanCreateDirectories:YES]; |
bfa92264 | 66 | |
a905992c | 67 | wxNonOwnedWindow* parentWindow = NULL; |
bfa92264 | 68 | |
03647350 | 69 | if (GetParent()) |
a905992c | 70 | parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent())); |
bfa92264 KO |
71 | |
72 | wxASSERT_MSG(parentWindow, "Window modal display requires parent."); | |
73 | ||
a905992c KO |
74 | if (parentWindow) |
75 | { | |
76 | NSWindow* nativeParent = parentWindow->GetWXWindow(); | |
03647350 | 77 | ModalDialogDelegate* sheetDelegate = [[ModalDialogDelegate alloc] init]; |
bfa92264 | 78 | [sheetDelegate setImplementation: this]; |
03647350 VZ |
79 | [oPanel beginSheetForDirectory:dir.AsNSString() file:nil types: nil |
80 | modalForWindow: nativeParent modalDelegate: sheetDelegate | |
81 | didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:) | |
a905992c | 82 | contextInfo: nil]; |
a905992c | 83 | } |
bfa92264 KO |
84 | } |
85 | ||
86 | int wxDirDialog::ShowModal() | |
87 | { | |
88 | NSOpenPanel *oPanel = [NSOpenPanel openPanel]; | |
89 | [oPanel setCanChooseDirectories:YES]; | |
90 | [oPanel setResolvesAliases:YES]; | |
91 | [oPanel setCanChooseFiles:NO]; | |
92 | ||
93 | wxCFStringRef cf( m_message ); | |
94 | [oPanel setMessage:cf.AsNSString()]; | |
95 | ||
96 | if ( HasFlag(wxDD_NEW_DIR_BUTTON) ) | |
97 | [oPanel setCanCreateDirectories:YES]; | |
98 | ||
99 | wxCFStringRef dir( m_path ); | |
100 | ||
101 | m_path = wxEmptyString; | |
102 | ||
103 | int returnCode = -1; | |
104 | ||
105 | returnCode = (NSInteger)[oPanel runModalForDirectory:dir.AsNSString() file:nil types:nil]; | |
106 | ModalFinishedCallback(oPanel, returnCode); | |
107 | ||
108 | return GetReturnCode(); | |
109 | } | |
110 | ||
111 | void wxDirDialog::ModalFinishedCallback(void* panel, int returnCode) | |
112 | { | |
113 | int result = wxID_CANCEL; | |
114 | ||
a905992c | 115 | if (returnCode == NSOKButton ) |
0f9b48d1 | 116 | { |
bfa92264 | 117 | NSOpenPanel* oPanel = (NSOpenPanel*)panel; |
f66ecdc4 | 118 | SetPath( wxCFStringRef::AsString([[oPanel filenames] objectAtIndex:0])); |
0f9b48d1 SC |
119 | result = wxID_OK; |
120 | } | |
bfa92264 KO |
121 | SetReturnCode(result); |
122 | ||
123 | if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL) | |
124 | SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED ); | |
0f9b48d1 SC |
125 | } |
126 | ||
127 | #endif // wxUSE_DIRDLG |