]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/dirdlg.mm
Fix compilation with MinGW -std=c++11 option.
[wxWidgets.git] / src / cocoa / dirdlg.mm
CommitLineData
937f314d
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/cocoa/dirdlg.mm
3// Purpose: wxDirDialog for wxCocoa
4// Author: Ryan Norton
5// Modified by: Hiroyuki Nakamura(maloninc)
6// Created: 2006-01-10
7// RCS-ID: $Id$
8// Copyright: (c) Ryan Norton
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
24
1ab440bc
WS
25#include "wx/dirdlg.h"
26
937f314d
VZ
27#ifndef WX_PRECOMP
28 #include "wx/msgdlg.h"
29 #include "wx/filedlg.h"
937f314d
VZ
30 #include "wx/app.h"
31#endif
e031f1df 32
937f314d 33#include "wx/filename.h"
643e9cf9 34#include "wx/testing.h"
937f314d
VZ
35
36#include "wx/cocoa/autorelease.h"
37#include "wx/cocoa/string.h"
38
39#import <AppKit/NSOpenPanel.h>
40#import <AppKit/NSSavePanel.h>
41
42#import <Foundation/NSArray.h>
43// ============================================================================
44// implementation
45// ============================================================================
46
47IMPLEMENT_CLASS(wxCocoaDirDialog, wxDialog)
48
49// ----------------------------------------------------------------------------
50// wxDirDialog
51// ----------------------------------------------------------------------------
52
53wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
54 const wxString& defaultPath, long style, const wxPoint& pos,
55 const wxSize& size, const wxString& name)
56{
57 wxTopLevelWindows.Append(this);
e031f1df
WS
58
59 m_message = message;
747592e7
SC
60
61 SetWindowStyle(style);
937f314d
VZ
62 m_parent = parent;
63 m_path = defaultPath;
64
65 wxASSERT(CreateBase(parent,wxID_ANY,pos,wxDefaultSize,style,wxDefaultValidator,wxDialogNameStr));
66
67 if ( parent )
68 parent->AddChild(this);
69
70 m_cocoaNSWindow = nil;
71 m_cocoaNSView = nil;
72
73 //If the user requests to save - use a NSSavePanel
74 //else use a NSOpenPanel
747592e7 75 if (HasFlag(wxFD_SAVE))
937f314d
VZ
76 {
77 SetNSPanel([NSSavePanel savePanel]);
78
79 [GetNSSavePanel() setTitle:wxNSStringWithWxString(message)];
80
81 [GetNSSavePanel() setPrompt:@"Save"];
82 [GetNSSavePanel() setTreatsFilePackagesAsDirectories:YES];
83 [GetNSSavePanel() setCanSelectHiddenExtension:YES];
84 }
e031f1df 85 else //m_dialogStyle & wxFD_OPEN
937f314d
VZ
86 {
87 SetNSPanel([NSOpenPanel openPanel]);
88 [m_cocoaNSWindow setTitle:wxNSStringWithWxString(message)];
89
90 [(NSOpenPanel*)m_cocoaNSWindow setResolvesAliases:YES];
91 [(NSOpenPanel*)m_cocoaNSWindow setCanChooseFiles:NO];
92 [(NSOpenPanel*)m_cocoaNSWindow setCanChooseDirectories:YES];
93 [GetNSSavePanel() setPrompt:@"Open"];
94 }
95
747592e7 96 if (HasFlag(wxDD_NEW_DIR_BUTTON)) //m_dialogStyle & wxDD_NEW_DIR_BUTTON
e031f1df 97 {
937f314d 98 [(NSOpenPanel*)m_cocoaNSWindow setCanCreateDirectories:YES];
e031f1df 99 }
937f314d
VZ
100}
101
102wxDirDialog::~wxDirDialog()
103{
104}
105
106int wxDirDialog::ShowModal()
107{
643e9cf9
VS
108 WX_TESTING_SHOW_MODAL_HOOK();
109
937f314d
VZ
110 wxAutoNSAutoreleasePool thePool;
111
112 m_fileNames.Empty();
113
114 int nResult;
115
747592e7 116 if (HasFlag(wxFD_SAVE))
937f314d
VZ
117 {
118 nResult = [GetNSSavePanel()
119 runModalForDirectory:wxNSStringWithWxString(m_dir)
120 file:wxNSStringWithWxString(m_fileName)];
121
122 if (nResult == NSOKButton)
123 {
124 m_fileNames.Add(wxStringWithNSString([GetNSSavePanel() filename]));
125 m_path = m_fileNames[0];
126 }
127 }
e031f1df 128 else //m_dialogStyle & wxFD_OPEN
937f314d
VZ
129 {
130 nResult = [(NSOpenPanel*)m_cocoaNSWindow
131 runModalForDirectory:wxNSStringWithWxString(m_dir)
132 file:wxNSStringWithWxString(m_fileName)
133 types:NULL];
134
135 if (nResult == NSOKButton)
136 {
137 for(unsigned i = 0; i < [[(NSOpenPanel*)m_cocoaNSWindow filenames] count]; ++i)
138 {
139 m_fileNames.Add(wxStringWithNSString([[(NSOpenPanel*)m_cocoaNSWindow filenames] objectAtIndex:(i)]));
140 }
141
142 m_path = m_fileNames[0];
143 }
144 }
145
146 return nResult == NSOKButton ? wxID_OK : wxID_CANCEL;
147}
148
149#endif // wxUSE_DIRDLG