]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/filepickerg.h
Implement GetPageText for the OSX WebKit implementation.
[wxWidgets.git] / include / wx / generic / filepickerg.h
CommitLineData
ec376c8f
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/generic/filepickerg.h
3// Purpose: wxGenericFileDirButton, wxGenericFileButton, wxGenericDirButton
4// Author: Francesco Montorsi
5// Modified by:
6// Created: 14/4/2006
7// Copyright: (c) Francesco Montorsi
8// RCS-ID: $Id$
9// Licence: wxWindows Licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_FILEDIRPICKER_H_
13#define _WX_FILEDIRPICKER_H_
14
45f9b662 15#include "wx/button.h"
ec376c8f
VZ
16#include "wx/filedlg.h"
17#include "wx/dirdlg.h"
18
19
9b11752c
VZ
20wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COMMAND_DIRPICKER_CHANGED, wxFileDirPickerEvent );
21wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COMMAND_FILEPICKER_CHANGED, wxFileDirPickerEvent );
ec376c8f
VZ
22
23
24//-----------------------------------------------------------------------------
25// wxGenericFileDirButton: a button which brings up a wx{File|Dir}Dialog
26//-----------------------------------------------------------------------------
27
28class WXDLLIMPEXP_CORE wxGenericFileDirButton : public wxButton,
29 public wxFileDirPickerWidgetBase
30{
31public:
459128ac 32 wxGenericFileDirButton() { Init(); }
ec376c8f
VZ
33 wxGenericFileDirButton(wxWindow *parent,
34 wxWindowID id,
35 const wxString& label = wxFilePickerWidgetLabel,
36 const wxString& path = wxEmptyString,
37 const wxString &message = wxFileSelectorPromptStr,
38 const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
39 const wxPoint& pos = wxDefaultPosition,
40 const wxSize& size = wxDefaultSize,
41 long style = 0,
42 const wxValidator& validator = wxDefaultValidator,
43 const wxString& name = wxFilePickerWidgetNameStr)
44 {
459128ac 45 Init();
ec376c8f
VZ
46 Create(parent, id, label, path, message, wildcard,
47 pos, size, style, validator, name);
48 }
49
af6ad984
VS
50 virtual wxControl *AsControl() { return this; }
51
d13b34d3 52public: // overridable
ec376c8f 53
556151f5 54 virtual wxDialog *CreateDialog() = 0;
ec376c8f 55
ec376c8f 56 virtual wxWindow *GetDialogParent()
556151f5 57 { return GetParent(); }
ec376c8f
VZ
58
59 virtual wxEventType GetEventType() const = 0;
60
61public:
62
ec376c8f
VZ
63 bool Create(wxWindow *parent, wxWindowID id,
64 const wxString& label = wxFilePickerWidgetLabel,
65 const wxString& path = wxEmptyString,
66 const wxString &message = wxFileSelectorPromptStr,
67 const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
68 const wxPoint& pos = wxDefaultPosition,
69 const wxSize& size = wxDefaultSize,
70 long style = 0,
71 const wxValidator& validator = wxDefaultValidator,
72 const wxString& name = wxFilePickerWidgetNameStr);
73
74 // event handler for the click
75 void OnButtonClick(wxCommandEvent &);
76
556151f5
MW
77protected:
78 wxString m_message, m_wildcard;
8eca1205
VZ
79
80 // we just store the style passed to the ctor here instead of passing it to
81 // wxButton as some of our bits can conflict with wxButton styles and it
82 // just doesn't make sense to use picker styles for wxButton anyhow
83 long m_pickerStyle;
459128ac
VZ
84
85private:
86 // common part of all ctors
87 void Init() { m_pickerStyle = -1; }
ec376c8f
VZ
88};
89
90
91//-----------------------------------------------------------------------------
92// wxGenericFileButton: a button which brings up a wxFileDialog
93//-----------------------------------------------------------------------------
94
556151f5 95#define wxFILEBTN_DEFAULT_STYLE (wxFLP_OPEN)
ec376c8f
VZ
96
97class WXDLLIMPEXP_CORE wxGenericFileButton : public wxGenericFileDirButton
98{
99public:
100 wxGenericFileButton() {}
101 wxGenericFileButton(wxWindow *parent,
102 wxWindowID id,
103 const wxString& label = wxFilePickerWidgetLabel,
104 const wxString& path = wxEmptyString,
105 const wxString &message = wxFileSelectorPromptStr,
106 const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
107 const wxPoint& pos = wxDefaultPosition,
108 const wxSize& size = wxDefaultSize,
109 long style = wxFILEBTN_DEFAULT_STYLE,
110 const wxValidator& validator = wxDefaultValidator,
111 const wxString& name = wxFilePickerWidgetNameStr)
112 {
113 Create(parent, id, label, path, message, wildcard,
114 pos, size, style, validator, name);
115 }
116
d13b34d3 117public: // overridable
ec376c8f
VZ
118
119 virtual long GetDialogStyle() const
120 {
459128ac
VZ
121 // the derived class must initialize it if it doesn't use the
122 // non-default wxGenericFileDirButton ctor
123 wxASSERT_MSG( m_pickerStyle != -1,
124 "forgot to initialize m_pickerStyle?" );
125
126
ec376c8f
VZ
127 long filedlgstyle = 0;
128
8eca1205 129 if ( m_pickerStyle & wxFLP_OPEN )
ec376c8f 130 filedlgstyle |= wxFD_OPEN;
8eca1205 131 if ( m_pickerStyle & wxFLP_SAVE )
ec376c8f 132 filedlgstyle |= wxFD_SAVE;
8eca1205 133 if ( m_pickerStyle & wxFLP_OVERWRITE_PROMPT )
ec376c8f 134 filedlgstyle |= wxFD_OVERWRITE_PROMPT;
8eca1205 135 if ( m_pickerStyle & wxFLP_FILE_MUST_EXIST )
ec376c8f 136 filedlgstyle |= wxFD_FILE_MUST_EXIST;
8eca1205 137 if ( m_pickerStyle & wxFLP_CHANGE_DIR )
ec376c8f
VZ
138 filedlgstyle |= wxFD_CHANGE_DIR;
139
140 return filedlgstyle;
141 }
142
556151f5 143 virtual wxDialog *CreateDialog()
ec376c8f 144 {
556151f5 145 wxFileDialog *p = new wxFileDialog(GetDialogParent(), m_message,
ec376c8f 146 wxEmptyString, wxEmptyString,
556151f5 147 m_wildcard, GetDialogStyle());
ec376c8f
VZ
148
149 // this sets both the default folder and the default file of the dialog
556151f5
MW
150 p->SetPath(m_path);
151 return p;
ec376c8f
VZ
152 }
153
c757b5fe
PC
154 wxEventType GetEventType() const
155 { return wxEVT_COMMAND_FILEPICKER_CHANGED; }
156
157protected:
556151f5
MW
158 void UpdateDialogPath(wxDialog *p)
159 { wxStaticCast(p, wxFileDialog)->SetPath(m_path); }
160 void UpdatePathFromDialog(wxDialog *p)
161 { m_path = wxStaticCast(p, wxFileDialog)->GetPath(); }
ec376c8f
VZ
162
163private:
164 DECLARE_DYNAMIC_CLASS(wxGenericFileButton)
165};
166
167
168//-----------------------------------------------------------------------------
169// wxGenericDirButton: a button which brings up a wxDirDialog
170//-----------------------------------------------------------------------------
171
172#define wxDIRBTN_DEFAULT_STYLE 0
173
174class WXDLLIMPEXP_CORE wxGenericDirButton : public wxGenericFileDirButton
175{
176public:
177 wxGenericDirButton() {}
178 wxGenericDirButton(wxWindow *parent,
179 wxWindowID id,
180 const wxString& label = wxDirPickerWidgetLabel,
181 const wxString& path = wxEmptyString,
182 const wxString &message = wxDirSelectorPromptStr,
183 const wxPoint& pos = wxDefaultPosition,
184 const wxSize& size = wxDefaultSize,
185 long style = wxDIRBTN_DEFAULT_STYLE,
186 const wxValidator& validator = wxDefaultValidator,
187 const wxString& name = wxDirPickerWidgetNameStr)
188 {
189 Create(parent, id, label, path, message, wxEmptyString,
190 pos, size, style, validator, name);
191 }
192
d13b34d3 193public: // overridable
ec376c8f
VZ
194
195 virtual long GetDialogStyle() const
196 {
b5c4d59e 197 long dirdlgstyle = wxDD_DEFAULT_STYLE;
ec376c8f 198
8eca1205 199 if ( m_pickerStyle & wxDIRP_DIR_MUST_EXIST )
ec376c8f 200 dirdlgstyle |= wxDD_DIR_MUST_EXIST;
8eca1205 201 if ( m_pickerStyle & wxDIRP_CHANGE_DIR )
ec376c8f
VZ
202 dirdlgstyle |= wxDD_CHANGE_DIR;
203
204 return dirdlgstyle;
205 }
206
556151f5 207 virtual wxDialog *CreateDialog()
ec376c8f 208 {
556151f5 209 return new wxDirDialog(GetDialogParent(), m_message, m_path,
ec376c8f 210 GetDialogStyle());
ec376c8f
VZ
211 }
212
c757b5fe
PC
213 wxEventType GetEventType() const
214 { return wxEVT_COMMAND_DIRPICKER_CHANGED; }
215
216protected:
556151f5
MW
217 void UpdateDialogPath(wxDialog *p)
218 { wxStaticCast(p, wxDirDialog)->SetPath(m_path); }
219 void UpdatePathFromDialog(wxDialog *p)
220 { m_path = wxStaticCast(p, wxDirDialog)->GetPath(); }
ec376c8f
VZ
221
222private:
223 DECLARE_DYNAMIC_CLASS(wxGenericDirButton)
224};
225
226
227#endif // _WX_FILEDIRPICKER_H_