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