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