1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/filepicker.h
3 // Purpose: wxFilePickerCtrl, wxDirPickerCtrl base header
4 // Author: Francesco Montorsi
7 // Copyright: (c) Francesco Montorsi
9 // Licence: wxWindows Licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_FILEDIRPICKER_H_BASE_
13 #define _WX_FILEDIRPICKER_H_BASE_
17 #if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
19 #include "wx/pickerbase.h"
21 class WXDLLIMPEXP_CORE wxDialog
;
22 class WXDLLIMPEXP_CORE wxFileDirPickerEvent
;
24 extern WXDLLEXPORT_DATA(const wxChar
) wxFilePickerWidgetLabel
[];
25 extern WXDLLEXPORT_DATA(const wxChar
) wxFilePickerWidgetNameStr
[];
26 extern WXDLLEXPORT_DATA(const wxChar
) wxFilePickerCtrlNameStr
[];
27 extern WXDLLEXPORT_DATA(const wxChar
) wxFileSelectorPromptStr
[];
29 extern WXDLLEXPORT_DATA(const wxChar
) wxDirPickerWidgetLabel
[];
30 extern WXDLLEXPORT_DATA(const wxChar
) wxDirPickerWidgetNameStr
[];
31 extern WXDLLEXPORT_DATA(const wxChar
) wxDirPickerCtrlNameStr
[];
32 extern WXDLLEXPORT_DATA(const wxChar
) wxDirSelectorPromptStr
[];
35 // ----------------------------------------------------------------------------
36 // wxFileDirPickerWidgetBase: a generic abstract interface which must be
37 // implemented by controls used by wxFileDirPickerCtrlBase
38 // ----------------------------------------------------------------------------
40 class WXDLLIMPEXP_CORE wxFileDirPickerWidgetBase
43 wxFileDirPickerWidgetBase() { }
44 virtual ~wxFileDirPickerWidgetBase() { }
46 wxString
GetPath() const { return m_path
; }
47 virtual void SetPath(const wxString
&str
) { m_path
=str
; }
49 // returns the picker widget cast to wxControl
50 virtual wxControl
*AsControl() = 0;
53 virtual void UpdateDialogPath(wxDialog
*) = 0;
54 virtual void UpdatePathFromDialog(wxDialog
*) = 0;
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
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
69 // NOTE: wxMULTIPLE is not supported !
72 #define wxDIRP_DIR_MUST_EXIST 0x0008
73 #define wxDIRP_CHANGE_DIR 0x0010
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...
81 // since GTK >= 2.6, there is GtkFileButton
82 #if defined(__WXGTK26__) && !defined(__WXUNIVERSAL__)
83 #include "wx/gtk/filepicker.h"
84 #define wxFilePickerWidget wxFileButton
85 #define wxDirPickerWidget wxDirButton
87 #include "wx/generic/filepickerg.h"
88 #define wxFilePickerWidget wxGenericFileButton
89 #define wxDirPickerWidget wxGenericDirButton
94 // ----------------------------------------------------------------------------
95 // wxFileDirPickerCtrlBase
96 // ----------------------------------------------------------------------------
98 class WXDLLIMPEXP_CORE wxFileDirPickerCtrlBase
: public wxPickerBase
101 wxFileDirPickerCtrlBase() : m_bIgnoreNextTextCtrlUpdate(false) {}
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
,
108 const wxString
& path
,
109 const wxString
&message
,
110 const wxString
&wildcard
,
114 const wxValidator
& validator
,
115 const wxString
& name
);
117 public: // public API
119 wxString
GetPath() const;
120 void SetPath(const wxString
&str
);
122 public: // internal functions
124 void UpdatePickerFromTextCtrl();
125 void UpdateTextCtrlFromPicker();
127 // event handler for our picker
128 void OnFileDirChange(wxFileDirPickerEvent
&);
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;
135 // TRUE if any textctrl change should update the current working directory
136 virtual bool IsCwdToUpdate() const = 0;
138 // Returns the event type sent by this picker
139 virtual wxEventType
GetEventType() const = 0;
141 // Returns the filtered value currently placed in the text control (if present).
142 virtual wxString
GetTextCtrlValue() const = 0;
145 // creates the picker control
147 wxFileDirPickerWidgetBase
*CreatePicker(wxWindow
*parent
,
148 const wxString
& path
,
149 const wxString
& message
,
150 const wxString
& wildcard
) = 0;
154 // true if the next UpdateTextCtrl() call is to ignore
155 bool m_bIgnoreNextTextCtrlUpdate
;
157 // m_picker object as wxFileDirPickerWidgetBase interface
158 wxFileDirPickerWidgetBase
*m_pickerIface
;
161 #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
164 #if wxUSE_FILEPICKERCTRL
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 // ----------------------------------------------------------------------------
172 #define wxFLP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
175 // GTK apps usually don't have a textctrl next to the picker
176 #define wxFLP_DEFAULT_STYLE (wxFLP_OPEN|wxFLP_FILE_MUST_EXIST)
178 #define wxFLP_DEFAULT_STYLE (wxFLP_USE_TEXTCTRL|wxFLP_OPEN|wxFLP_FILE_MUST_EXIST)
181 class WXDLLIMPEXP_CORE wxFilePickerCtrl
: public wxFileDirPickerCtrlBase
184 wxFilePickerCtrl() {}
186 wxFilePickerCtrl(wxWindow
*parent
,
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
)
197 Create(parent
, id
, path
, message
, wildcard
, pos
, size
, style
,
201 bool Create(wxWindow
*parent
,
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
)
212 return wxFileDirPickerCtrlBase::CreateBase(parent
, id
, path
,
221 // return true if the given path is valid for this control
222 bool CheckPath(const wxString
& path
) const;
224 // return the text control value in canonical form
225 wxString
GetTextCtrlValue() const;
227 bool IsCwdToUpdate() const
228 { return HasFlag(wxFLP_CHANGE_DIR
); }
230 wxEventType
GetEventType() const
231 { return wxEVT_COMMAND_FILEPICKER_CHANGED
; }
234 wxFileDirPickerWidgetBase
*CreatePicker(wxWindow
*parent
,
235 const wxString
& path
,
236 const wxString
& message
,
237 const wxString
& wildcard
)
239 return new wxFilePickerWidget(parent
, wxID_ANY
,
240 wxFilePickerWidgetLabel
,
241 path
, message
, wildcard
,
242 wxDefaultPosition
, wxDefaultSize
,
243 GetPickerStyle(GetWindowStyle()));
246 // extracts the style for our picker from wxFileDirPickerCtrlBase's style
247 long GetPickerStyle(long style
) const
249 return (style
& (wxFLP_OPEN
|wxFLP_SAVE
|wxFLP_OVERWRITE_PROMPT
|
250 wxFLP_FILE_MUST_EXIST
|wxFLP_CHANGE_DIR
));
254 DECLARE_DYNAMIC_CLASS(wxFilePickerCtrl
)
257 #endif // wxUSE_FILEPICKERCTRL
260 #if wxUSE_DIRPICKERCTRL
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 // ----------------------------------------------------------------------------
268 #define wxDIRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
271 // GTK apps usually don't have a textctrl next to the picker
272 #define wxDIRP_DEFAULT_STYLE (wxDIRP_DIR_MUST_EXIST)
274 #define wxDIRP_DEFAULT_STYLE (wxDIRP_USE_TEXTCTRL|wxDIRP_DIR_MUST_EXIST)
277 class WXDLLIMPEXP_CORE wxDirPickerCtrl
: public wxFileDirPickerCtrlBase
282 wxDirPickerCtrl(wxWindow
*parent
, wxWindowID id
,
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
)
291 Create(parent
, id
, path
, message
, pos
, size
, style
, validator
, name
);
294 bool Create(wxWindow
*parent
, wxWindowID id
,
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
)
303 return wxFileDirPickerCtrlBase::CreateBase
305 parent
, id
, path
, message
, wxEmptyString
,
306 pos
, size
, style
, validator
, name
313 bool CheckPath(const wxString
&path
) const;
315 wxString
GetTextCtrlValue() const;
317 bool IsCwdToUpdate() const
318 { return HasFlag(wxDIRP_CHANGE_DIR
); }
320 wxEventType
GetEventType() const
321 { return wxEVT_COMMAND_DIRPICKER_CHANGED
; }
324 wxFileDirPickerWidgetBase
*CreatePicker(wxWindow
*parent
,
325 const wxString
& path
,
326 const wxString
& message
,
327 const wxString
& WXUNUSED(wildcard
))
329 return new wxDirPickerWidget(parent
, wxID_ANY
, wxDirPickerWidgetLabel
,
331 wxDefaultPosition
, wxDefaultSize
,
332 GetPickerStyle(GetWindowStyle()));
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
)); }
340 DECLARE_DYNAMIC_CLASS(wxDirPickerCtrl
)
343 #endif // wxUSE_DIRPICKERCTRL
346 #if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
348 // ----------------------------------------------------------------------------
349 // wxFileDirPickerEvent: used by wxFilePickerCtrl and wxDirPickerCtrl only
350 // ----------------------------------------------------------------------------
352 BEGIN_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)
355 END_DECLARE_EVENT_TYPES()
357 class WXDLLIMPEXP_CORE wxFileDirPickerEvent
: public wxCommandEvent
360 wxFileDirPickerEvent() {}
361 wxFileDirPickerEvent(wxEventType type
, wxObject
*generator
, int id
, const wxString
&path
)
362 : wxCommandEvent(type
, id
),
365 SetEventObject(generator
);
368 wxString
GetPath() const { return m_path
; }
369 void SetPath(const wxString
&p
) { m_path
= p
; }
371 // default copy ctor, assignment operator and dtor are ok
372 virtual wxEvent
*Clone() const { return new wxFileDirPickerEvent(*this); }
377 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxFileDirPickerEvent
)
380 // ----------------------------------------------------------------------------
381 // event types and macros
382 // ----------------------------------------------------------------------------
384 typedef void (wxEvtHandler::*wxFileDirPickerEventFunction
)(wxFileDirPickerEvent
&);
386 #define wxFileDirPickerEventHandler(func) \
387 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxFileDirPickerEventFunction, &func)
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))
394 #ifdef _WX_DEFINE_DATE_EVENTS_
395 DEFINE_EVENT_TYPE(wxEVT_COMMAND_FILEPICKER_CHANGED
)
396 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DIRPICKER_CHANGED
)
398 IMPLEMENT_DYNAMIC_CLASS(wxFileDirPickerEvent
, wxCommandEvent
)
402 #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
404 #endif // _WX_FILEDIRPICKER_H_BASE_