]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/dirdlg.mm
fixing usage of load states, set controller visible correctly
[wxWidgets.git] / src / osx / cocoa / dirdlg.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/dirdlg.mm
3 // Purpose: wxDirDialog
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 2008-08-30
7 // RCS-ID: $Id$
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 #include "wx/evtloop.h"
35
36 #include "wx/osx/private.h"
37
38 IMPLEMENT_CLASS(wxDirDialog, wxDialog)
39
40 wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
41 const wxString& defaultPath, long style, const wxPoint& WXUNUSED(pos),
42 const wxSize& WXUNUSED(size), const wxString& WXUNUSED(name))
43 {
44 m_parent = parent;
45
46 SetMessage( message );
47 SetWindowStyle(style);
48 SetPath(defaultPath);
49 m_sheetDelegate = [[ModalDialogDelegate alloc] init];
50 [(ModalDialogDelegate*)m_sheetDelegate setImplementation: this];
51 }
52
53 wxDirDialog::~wxDirDialog()
54 {
55 [m_sheetDelegate release];
56 }
57
58 void wxDirDialog::ShowWindowModal()
59 {
60 wxCFStringRef dir( m_path );
61
62 m_modality = wxDIALOG_MODALITY_WINDOW_MODAL;
63
64 NSOpenPanel *oPanel = [NSOpenPanel openPanel];
65 [oPanel setCanChooseDirectories:YES];
66 [oPanel setResolvesAliases:YES];
67 [oPanel setCanChooseFiles:NO];
68
69 wxCFStringRef cf( m_message );
70 [oPanel setMessage:cf.AsNSString()];
71
72 if ( HasFlag(wxDD_NEW_DIR_BUTTON) )
73 [oPanel setCanCreateDirectories:YES];
74
75 wxNonOwnedWindow* parentWindow = NULL;
76
77 if (GetParent())
78 parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent()));
79
80 wxASSERT_MSG(parentWindow, "Window modal display requires parent.");
81
82 if (parentWindow)
83 {
84 NSWindow* nativeParent = parentWindow->GetWXWindow();
85 [oPanel beginSheetForDirectory:dir.AsNSString() file:nil types: nil
86 modalForWindow: nativeParent modalDelegate: m_sheetDelegate
87 didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
88 contextInfo: nil];
89 }
90 }
91
92 int wxDirDialog::ShowModal()
93 {
94 wxCFEventLoopPauseIdleEvents pause;
95
96 NSOpenPanel *oPanel = [NSOpenPanel openPanel];
97 [oPanel setCanChooseDirectories:YES];
98 [oPanel setResolvesAliases:YES];
99 [oPanel setCanChooseFiles:NO];
100
101 wxCFStringRef cf( m_message );
102 [oPanel setMessage:cf.AsNSString()];
103
104 if ( HasFlag(wxDD_NEW_DIR_BUTTON) )
105 [oPanel setCanCreateDirectories:YES];
106
107 wxCFStringRef dir( m_path );
108
109 m_path = wxEmptyString;
110
111 int returnCode = -1;
112
113 returnCode = (NSInteger)[oPanel runModalForDirectory:dir.AsNSString() file:nil types:nil];
114 ModalFinishedCallback(oPanel, returnCode);
115
116 return GetReturnCode();
117 }
118
119 void wxDirDialog::ModalFinishedCallback(void* panel, int returnCode)
120 {
121 int result = wxID_CANCEL;
122
123 if (returnCode == NSOKButton )
124 {
125 NSOpenPanel* oPanel = (NSOpenPanel*)panel;
126 SetPath( wxCFStringRef::AsString([[oPanel filenames] objectAtIndex:0]));
127 result = wxID_OK;
128 }
129 SetReturnCode(result);
130
131 if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL)
132 SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED );
133 }
134
135 #endif // wxUSE_DIRDLG