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