]> git.saurik.com Git - wxWidgets.git/blame - src/osx/cocoa/dirdlg.mm
Avoid double destruction of wxTipWindow under wxOSX.
[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
bfa92264 58void wxDirDialog::ShowWindowModal()
0f9b48d1 59{
bfa92264
KO
60 wxCFStringRef dir( m_path );
61
62 m_modality = wxDIALOG_MODALITY_WINDOW_MODAL;
63
0f9b48d1
SC
64 NSOpenPanel *oPanel = [NSOpenPanel openPanel];
65 [oPanel setCanChooseDirectories:YES];
66 [oPanel setResolvesAliases:YES];
67 [oPanel setCanChooseFiles:NO];
03647350 68
0f9b48d1
SC
69 wxCFStringRef cf( m_message );
70 [oPanel setMessage:cf.AsNSString()];
03647350
VZ
71
72 if ( HasFlag(wxDD_NEW_DIR_BUTTON) )
0f9b48d1 73 [oPanel setCanCreateDirectories:YES];
bfa92264 74
a905992c 75 wxNonOwnedWindow* parentWindow = NULL;
bfa92264 76
03647350 77 if (GetParent())
a905992c 78 parentWindow = dynamic_cast<wxNonOwnedWindow*>(wxGetTopLevelParent(GetParent()));
bfa92264
KO
79
80 wxASSERT_MSG(parentWindow, "Window modal display requires parent.");
81
a905992c
KO
82 if (parentWindow)
83 {
84 NSWindow* nativeParent = parentWindow->GetWXWindow();
03647350 85 [oPanel beginSheetForDirectory:dir.AsNSString() file:nil types: nil
4d3e2dc9 86 modalForWindow: nativeParent modalDelegate: m_sheetDelegate
03647350 87 didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:)
a905992c 88 contextInfo: nil];
a905992c 89 }
bfa92264
KO
90}
91
92int wxDirDialog::ShowModal()
93{
1bfba4a0
SC
94 wxCFEventLoopPauseIdleEvents pause;
95
bfa92264
KO
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
119void wxDirDialog::ModalFinishedCallback(void* panel, int returnCode)
120{
121 int result = wxID_CANCEL;
122
a905992c 123 if (returnCode == NSOKButton )
0f9b48d1 124 {
bfa92264 125 NSOpenPanel* oPanel = (NSOpenPanel*)panel;
f66ecdc4 126 SetPath( wxCFStringRef::AsString([[oPanel filenames] objectAtIndex:0]));
0f9b48d1
SC
127 result = wxID_OK;
128 }
bfa92264
KO
129 SetReturnCode(result);
130
131 if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL)
132 SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED );
0f9b48d1
SC
133}
134
135#endif // wxUSE_DIRDLG