]> git.saurik.com Git - wxWidgets.git/blame - include/wx/filepicker.h
replace changes of r49890 by defining more compatibility operators in wxCmdLineArgsAr...
[wxWidgets.git] / include / wx / filepicker.h
CommitLineData
ec376c8f
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/filepicker.h
3// Purpose: wxFilePickerCtrl, wxDirPickerCtrl base header
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_BASE_
13#define _WX_FILEDIRPICKER_H_BASE_
14
15#include "wx/defs.h"
16
ec376c8f
VZ
17#if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
18
ec376c8f 19#include "wx/pickerbase.h"
28f15a1f 20#include "wx/filename.h"
ec376c8f 21
b5dbe15d
VS
22class WXDLLIMPEXP_FWD_CORE wxDialog;
23class WXDLLIMPEXP_FWD_CORE wxFileDirPickerEvent;
ec376c8f 24
f36e602b
VZ
25extern WXDLLEXPORT_DATA(const char) wxFilePickerWidgetLabel[];
26extern WXDLLEXPORT_DATA(const char) wxFilePickerWidgetNameStr[];
27extern WXDLLEXPORT_DATA(const char) wxFilePickerCtrlNameStr[];
28extern WXDLLEXPORT_DATA(const char) wxFileSelectorPromptStr[];
29
30extern WXDLLEXPORT_DATA(const char) wxDirPickerWidgetLabel[];
31extern WXDLLEXPORT_DATA(const char) wxDirPickerWidgetNameStr[];
32extern WXDLLEXPORT_DATA(const char) wxDirPickerCtrlNameStr[];
33extern WXDLLEXPORT_DATA(const char) wxDirSelectorPromptStr[];
ec376c8f
VZ
34
35
36// ----------------------------------------------------------------------------
37// wxFileDirPickerWidgetBase: a generic abstract interface which must be
38// implemented by controls used by wxFileDirPickerCtrlBase
39// ----------------------------------------------------------------------------
40
41class WXDLLIMPEXP_CORE wxFileDirPickerWidgetBase
42{
43public:
44 wxFileDirPickerWidgetBase() { }
45 virtual ~wxFileDirPickerWidgetBase() { }
46
47 wxString GetPath() const { return m_path; }
556151f5 48 virtual void SetPath(const wxString &str) { m_path=str; }
ec376c8f 49
af6ad984
VS
50 // returns the picker widget cast to wxControl
51 virtual wxControl *AsControl() = 0;
52
ec376c8f 53protected:
556151f5
MW
54 virtual void UpdateDialogPath(wxDialog *) = 0;
55 virtual void UpdatePathFromDialog(wxDialog *) = 0;
ec376c8f
VZ
56
57 wxString m_path;
58};
59
60// Styles which must be supported by all controls implementing wxFileDirPickerWidgetBase
61// NB: these styles must be defined to carefully-chosen values to
62// avoid conflicts with wxButton's styles
63
a7a11b21
WS
64#define wxFLP_OPEN 0x0400
65#define wxFLP_SAVE 0x0800
66#define wxFLP_OVERWRITE_PROMPT 0x1000
67#define wxFLP_FILE_MUST_EXIST 0x2000
68#define wxFLP_CHANGE_DIR 0x4000
ec376c8f
VZ
69
70// NOTE: wxMULTIPLE is not supported !
71
72
73#define wxDIRP_DIR_MUST_EXIST 0x0008
74#define wxDIRP_CHANGE_DIR 0x0010
75
76
77// map platform-dependent controls which implement the wxFileDirPickerWidgetBase
78// under the name "wxFilePickerWidget" and "wxDirPickerWidget".
79// NOTE: wxFileDirPickerCtrlBase will allocate a wx{File|Dir}PickerWidget and this
80// requires that all classes being mapped as wx{File|Dir}PickerWidget have the
81// same prototype for the contructor...
82540105
MW
82// since GTK >= 2.6, there is GtkFileButton
83#if defined(__WXGTK26__) && !defined(__WXUNIVERSAL__)
ec376c8f
VZ
84 #include "wx/gtk/filepicker.h"
85 #define wxFilePickerWidget wxFileButton
86 #define wxDirPickerWidget wxDirButton
87#else
88 #include "wx/generic/filepickerg.h"
89 #define wxFilePickerWidget wxGenericFileButton
90 #define wxDirPickerWidget wxGenericDirButton
91#endif
92
93
94
95// ----------------------------------------------------------------------------
af6ad984 96// wxFileDirPickerCtrlBase
ec376c8f
VZ
97// ----------------------------------------------------------------------------
98
99class WXDLLIMPEXP_CORE wxFileDirPickerCtrlBase : public wxPickerBase
100{
101public:
102 wxFileDirPickerCtrlBase() : m_bIgnoreNextTextCtrlUpdate(false) {}
ec376c8f 103
af6ad984 104protected:
ec376c8f
VZ
105 // NB: no default values since this function will never be used
106 // directly by the user and derived classes wouldn't use them
107 bool CreateBase(wxWindow *parent,
108 wxWindowID id,
109 const wxString& path,
110 const wxString &message,
111 const wxString &wildcard,
112 const wxPoint& pos,
113 const wxSize& size,
114 long style,
115 const wxValidator& validator,
116 const wxString& name);
117
118public: // public API
119
af6ad984 120 wxString GetPath() const;
ec376c8f
VZ
121 void SetPath(const wxString &str);
122
123public: // internal functions
124
125 void UpdatePickerFromTextCtrl();
126 void UpdateTextCtrlFromPicker();
127
128 // event handler for our picker
129 void OnFileDirChange(wxFileDirPickerEvent &);
130
ec376c8f
VZ
131 // Returns TRUE if the current path is a valid one
132 // (i.e. a valid file for a wxFilePickerWidget or a valid
133 // folder for a wxDirPickerWidget).
134 virtual bool CheckPath(const wxString &str) const = 0;
135
136 // TRUE if any textctrl change should update the current working directory
137 virtual bool IsCwdToUpdate() const = 0;
138
139 // Returns the event type sent by this picker
140 virtual wxEventType GetEventType() const = 0;
141
58772e49
VZ
142 // Returns the filtered value currently placed in the text control (if present).
143 virtual wxString GetTextCtrlValue() const = 0;
144
af6ad984
VS
145protected:
146 // creates the picker control
147 virtual
148 wxFileDirPickerWidgetBase *CreatePicker(wxWindow *parent,
149 const wxString& path,
150 const wxString& message,
151 const wxString& wildcard) = 0;
152
ec376c8f
VZ
153protected:
154
155 // true if the next UpdateTextCtrl() call is to ignore
156 bool m_bIgnoreNextTextCtrlUpdate;
af6ad984
VS
157
158 // m_picker object as wxFileDirPickerWidgetBase interface
159 wxFileDirPickerWidgetBase *m_pickerIface;
ec376c8f
VZ
160};
161
162#endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
163
164
165#if wxUSE_FILEPICKERCTRL
166
167// ----------------------------------------------------------------------------
168// wxFilePickerCtrl: platform-independent class which embeds the
169// platform-dependent wxFilePickerWidget and, if wxFLP_USE_TEXTCTRL style is
170// used, a textctrl next to it.
171// ----------------------------------------------------------------------------
172
556151f5 173#define wxFLP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
ec376c8f
VZ
174
175#ifdef __WXGTK__
176 // GTK apps usually don't have a textctrl next to the picker
58772e49 177 #define wxFLP_DEFAULT_STYLE (wxFLP_OPEN|wxFLP_FILE_MUST_EXIST)
ec376c8f 178#else
58772e49 179 #define wxFLP_DEFAULT_STYLE (wxFLP_USE_TEXTCTRL|wxFLP_OPEN|wxFLP_FILE_MUST_EXIST)
ec376c8f
VZ
180#endif
181
182class WXDLLIMPEXP_CORE wxFilePickerCtrl : public wxFileDirPickerCtrlBase
183{
184public:
185 wxFilePickerCtrl() {}
ec376c8f
VZ
186
187 wxFilePickerCtrl(wxWindow *parent,
188 wxWindowID id,
189 const wxString& path = wxEmptyString,
190 const wxString& message = wxFileSelectorPromptStr,
191 const wxString& wildcard = wxFileSelectorDefaultWildcardStr,
192 const wxPoint& pos = wxDefaultPosition,
193 const wxSize& size = wxDefaultSize,
194 long style = wxFLP_DEFAULT_STYLE,
195 const wxValidator& validator = wxDefaultValidator,
196 const wxString& name = wxFilePickerCtrlNameStr)
197 {
198 Create(parent, id, path, message, wildcard, pos, size, style,
199 validator, name);
200 }
201
202 bool Create(wxWindow *parent,
203 wxWindowID id,
204 const wxString& path = wxEmptyString,
205 const wxString& message = wxFileSelectorPromptStr,
206 const wxString& wildcard = wxFileSelectorDefaultWildcardStr,
207 const wxPoint& pos = wxDefaultPosition,
208 const wxSize& size = wxDefaultSize,
209 long style = wxFLP_DEFAULT_STYLE,
210 const wxValidator& validator = wxDefaultValidator,
211 const wxString& name = wxFilePickerCtrlNameStr)
212 {
213 return wxFileDirPickerCtrlBase::CreateBase(parent, id, path,
214 message, wildcard,
215 pos, size, style,
216 validator, name);
217 }
218
28f15a1f
VZ
219 void SetFileName(const wxFileName &filename)
220 { SetPath(filename.GetFullPath()); }
221
222 wxFileName GetFileName() const
223 { return wxFileName(GetPath()); }
ec376c8f
VZ
224
225public: // overrides
226
58772e49
VZ
227 // return true if the given path is valid for this control
228 bool CheckPath(const wxString& path) const;
229
230 // return the text control value in canonical form
231 wxString GetTextCtrlValue() const;
ec376c8f
VZ
232
233 bool IsCwdToUpdate() const
234 { return HasFlag(wxFLP_CHANGE_DIR); }
235
236 wxEventType GetEventType() const
237 { return wxEVT_COMMAND_FILEPICKER_CHANGED; }
238
c757b5fe 239protected:
af6ad984
VS
240 wxFileDirPickerWidgetBase *CreatePicker(wxWindow *parent,
241 const wxString& path,
242 const wxString& message,
243 const wxString& wildcard)
244 {
245 return new wxFilePickerWidget(parent, wxID_ANY,
246 wxFilePickerWidgetLabel,
247 path, message, wildcard,
248 wxDefaultPosition, wxDefaultSize,
249 GetPickerStyle(GetWindowStyle()));
250 }
251
c757b5fe
PC
252 // extracts the style for our picker from wxFileDirPickerCtrlBase's style
253 long GetPickerStyle(long style) const
254 {
255 return (style & (wxFLP_OPEN|wxFLP_SAVE|wxFLP_OVERWRITE_PROMPT|
256 wxFLP_FILE_MUST_EXIST|wxFLP_CHANGE_DIR));
257 }
258
ec376c8f
VZ
259private:
260 DECLARE_DYNAMIC_CLASS(wxFilePickerCtrl)
261};
262
263#endif // wxUSE_FILEPICKERCTRL
264
265
266#if wxUSE_DIRPICKERCTRL
267
268// ----------------------------------------------------------------------------
269// wxDirPickerCtrl: platform-independent class which embeds the
270// platform-dependent wxDirPickerWidget and eventually a textctrl
271// (see wxDIRP_USE_TEXTCTRL) next to it.
272// ----------------------------------------------------------------------------
273
556151f5 274#define wxDIRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
ec376c8f
VZ
275
276#ifdef __WXGTK__
277 // GTK apps usually don't have a textctrl next to the picker
58772e49 278 #define wxDIRP_DEFAULT_STYLE (wxDIRP_DIR_MUST_EXIST)
ec376c8f 279#else
58772e49 280 #define wxDIRP_DEFAULT_STYLE (wxDIRP_USE_TEXTCTRL|wxDIRP_DIR_MUST_EXIST)
ec376c8f
VZ
281#endif
282
283class WXDLLIMPEXP_CORE wxDirPickerCtrl : public wxFileDirPickerCtrlBase
284{
285public:
286 wxDirPickerCtrl() {}
ec376c8f
VZ
287
288 wxDirPickerCtrl(wxWindow *parent, wxWindowID id,
58772e49
VZ
289 const wxString& path = wxEmptyString,
290 const wxString& message = wxDirSelectorPromptStr,
291 const wxPoint& pos = wxDefaultPosition,
292 const wxSize& size = wxDefaultSize,
293 long style = wxDIRP_DEFAULT_STYLE,
294 const wxValidator& validator = wxDefaultValidator,
295 const wxString& name = wxDirPickerCtrlNameStr)
296 {
297 Create(parent, id, path, message, pos, size, style, validator, name);
298 }
ec376c8f
VZ
299
300 bool Create(wxWindow *parent, wxWindowID id,
58772e49
VZ
301 const wxString& path = wxEmptyString,
302 const wxString& message = wxDirSelectorPromptStr,
303 const wxPoint& pos = wxDefaultPosition,
304 const wxSize& size = wxDefaultSize,
305 long style = wxDIRP_DEFAULT_STYLE,
306 const wxValidator& validator = wxDefaultValidator,
307 const wxString& name = wxDirPickerCtrlNameStr)
308 {
309 return wxFileDirPickerCtrlBase::CreateBase
310 (
311 parent, id, path, message, wxEmptyString,
312 pos, size, style, validator, name
313 );
314 }
ec376c8f 315
28f15a1f
VZ
316 void SetDirName(const wxFileName &dirname)
317 { SetPath(dirname.GetPath()); }
318
319 wxFileName GetDirName() const
320 { return wxFileName::DirName(GetPath()); }
ec376c8f
VZ
321
322public: // overrides
323
58772e49
VZ
324 bool CheckPath(const wxString &path) const;
325
326 wxString GetTextCtrlValue() const;
ec376c8f
VZ
327
328 bool IsCwdToUpdate() const
329 { return HasFlag(wxDIRP_CHANGE_DIR); }
330
331 wxEventType GetEventType() const
332 { return wxEVT_COMMAND_DIRPICKER_CHANGED; }
333
c757b5fe 334protected:
af6ad984
VS
335 wxFileDirPickerWidgetBase *CreatePicker(wxWindow *parent,
336 const wxString& path,
337 const wxString& message,
338 const wxString& WXUNUSED(wildcard))
339 {
340 return new wxDirPickerWidget(parent, wxID_ANY, wxDirPickerWidgetLabel,
341 path, message,
342 wxDefaultPosition, wxDefaultSize,
343 GetPickerStyle(GetWindowStyle()));
344 }
345
c757b5fe
PC
346 // extracts the style for our picker from wxFileDirPickerCtrlBase's style
347 long GetPickerStyle(long style) const
348 { return (style & (wxDIRP_DIR_MUST_EXIST|wxDIRP_CHANGE_DIR)); }
349
ec376c8f
VZ
350private:
351 DECLARE_DYNAMIC_CLASS(wxDirPickerCtrl)
352};
353
354#endif // wxUSE_DIRPICKERCTRL
355
356
357#if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
358
359// ----------------------------------------------------------------------------
360// wxFileDirPickerEvent: used by wxFilePickerCtrl and wxDirPickerCtrl only
361// ----------------------------------------------------------------------------
362
363BEGIN_DECLARE_EVENT_TYPES()
364 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE, wxEVT_COMMAND_FILEPICKER_CHANGED, 1102)
365 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE, wxEVT_COMMAND_DIRPICKER_CHANGED, 1103)
366END_DECLARE_EVENT_TYPES()
367
368class WXDLLIMPEXP_CORE wxFileDirPickerEvent : public wxCommandEvent
369{
370public:
371 wxFileDirPickerEvent() {}
372 wxFileDirPickerEvent(wxEventType type, wxObject *generator, int id, const wxString &path)
373 : wxCommandEvent(type, id),
374 m_path(path)
375 {
376 SetEventObject(generator);
377 }
378
379 wxString GetPath() const { return m_path; }
380 void SetPath(const wxString &p) { m_path = p; }
381
258b2ca6
RD
382 // default copy ctor, assignment operator and dtor are ok
383 virtual wxEvent *Clone() const { return new wxFileDirPickerEvent(*this); }
384
ec376c8f
VZ
385private:
386 wxString m_path;
387
258b2ca6 388 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxFileDirPickerEvent)
ec376c8f
VZ
389};
390
391// ----------------------------------------------------------------------------
392// event types and macros
393// ----------------------------------------------------------------------------
394
395typedef void (wxEvtHandler::*wxFileDirPickerEventFunction)(wxFileDirPickerEvent&);
396
397#define wxFileDirPickerEventHandler(func) \
398 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxFileDirPickerEventFunction, &func)
399
400#define EVT_FILEPICKER_CHANGED(id, fn) \
401 wx__DECLARE_EVT1(wxEVT_COMMAND_FILEPICKER_CHANGED, id, wxFileDirPickerEventHandler(fn))
402#define EVT_DIRPICKER_CHANGED(id, fn) \
403 wx__DECLARE_EVT1(wxEVT_COMMAND_DIRPICKER_CHANGED, id, wxFileDirPickerEventHandler(fn))
404
ec376c8f
VZ
405
406#endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
407
408#endif // _WX_FILEDIRPICKER_H_BASE_
409