]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/dirdlg.mm
wxNB_HITTEST_* flags renamed to wxBK_HITTEST_* to serve all book controls.
[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
VZ
33#include "wx/filename.h"
34
35#include "wx/cocoa/autorelease.h"
36#include "wx/cocoa/string.h"
37
38#import <AppKit/NSOpenPanel.h>
39#import <AppKit/NSSavePanel.h>
40
41#import <Foundation/NSArray.h>
42// ============================================================================
43// implementation
44// ============================================================================
45
46IMPLEMENT_CLASS(wxCocoaDirDialog, wxDialog)
47
48// ----------------------------------------------------------------------------
49// wxDirDialog
50// ----------------------------------------------------------------------------
51
52wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
53 const wxString& defaultPath, long style, const wxPoint& pos,
54 const wxSize& size, const wxString& name)
55{
56 wxTopLevelWindows.Append(this);
e031f1df
WS
57
58 m_message = message;
937f314d
VZ
59 m_dialogStyle = style;
60 m_parent = parent;
61 m_path = defaultPath;
62
63 wxASSERT(CreateBase(parent,wxID_ANY,pos,wxDefaultSize,style,wxDefaultValidator,wxDialogNameStr));
64
65 if ( parent )
66 parent->AddChild(this);
67
68 m_cocoaNSWindow = nil;
69 m_cocoaNSView = nil;
70
71 //If the user requests to save - use a NSSavePanel
72 //else use a NSOpenPanel
e031f1df 73 if (m_dialogStyle & wxFD_SAVE)
937f314d
VZ
74 {
75 SetNSPanel([NSSavePanel savePanel]);
76
77 [GetNSSavePanel() setTitle:wxNSStringWithWxString(message)];
78
79 [GetNSSavePanel() setPrompt:@"Save"];
80 [GetNSSavePanel() setTreatsFilePackagesAsDirectories:YES];
81 [GetNSSavePanel() setCanSelectHiddenExtension:YES];
82 }
e031f1df 83 else //m_dialogStyle & wxFD_OPEN
937f314d
VZ
84 {
85 SetNSPanel([NSOpenPanel openPanel]);
86 [m_cocoaNSWindow setTitle:wxNSStringWithWxString(message)];
87
88 [(NSOpenPanel*)m_cocoaNSWindow setResolvesAliases:YES];
89 [(NSOpenPanel*)m_cocoaNSWindow setCanChooseFiles:NO];
90 [(NSOpenPanel*)m_cocoaNSWindow setCanChooseDirectories:YES];
91 [GetNSSavePanel() setPrompt:@"Open"];
92 }
93
e031f1df
WS
94 if (m_dialogStyle & wxDD_NEW_DIR_BUTTON) //m_dialogStyle & wxDD_NEW_DIR_BUTTON
95 {
937f314d 96 [(NSOpenPanel*)m_cocoaNSWindow setCanCreateDirectories:YES];
e031f1df 97 }
937f314d
VZ
98}
99
100wxDirDialog::~wxDirDialog()
101{
102}
103
104int wxDirDialog::ShowModal()
105{
106 wxAutoNSAutoreleasePool thePool;
107
108 m_fileNames.Empty();
109
110 int nResult;
111
e031f1df 112 if (m_dialogStyle & wxFD_SAVE)
937f314d
VZ
113 {
114 nResult = [GetNSSavePanel()
115 runModalForDirectory:wxNSStringWithWxString(m_dir)
116 file:wxNSStringWithWxString(m_fileName)];
117
118 if (nResult == NSOKButton)
119 {
120 m_fileNames.Add(wxStringWithNSString([GetNSSavePanel() filename]));
121 m_path = m_fileNames[0];
122 }
123 }
e031f1df 124 else //m_dialogStyle & wxFD_OPEN
937f314d
VZ
125 {
126 nResult = [(NSOpenPanel*)m_cocoaNSWindow
127 runModalForDirectory:wxNSStringWithWxString(m_dir)
128 file:wxNSStringWithWxString(m_fileName)
129 types:NULL];
130
131 if (nResult == NSOKButton)
132 {
133 for(unsigned i = 0; i < [[(NSOpenPanel*)m_cocoaNSWindow filenames] count]; ++i)
134 {
135 m_fileNames.Add(wxStringWithNSString([[(NSOpenPanel*)m_cocoaNSWindow filenames] objectAtIndex:(i)]));
136 }
137
138 m_path = m_fileNames[0];
139 }
140 }
141
142 return nResult == NSOKButton ? wxID_OK : wxID_CANCEL;
143}
144
145#endif // wxUSE_DIRDLG