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