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