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 #if defined(__WXGTK26__) // since GTK >= 2.6, there is GtkFileButton
82 #include "wx/gtk/filepicker.h"
83 #define wxFilePickerWidget wxFileButton
84 #define wxDirPickerWidget wxDirButton
86 #include "wx/generic/filepickerg.h"
87 #define wxFilePickerWidget wxGenericFileButton
88 #define wxDirPickerWidget wxGenericDirButton
93 // ----------------------------------------------------------------------------
94 // wxFileDirPickerCtrlBase
95 // ----------------------------------------------------------------------------
97 class WXDLLIMPEXP_CORE wxFileDirPickerCtrlBase
: public wxPickerBase
100 wxFileDirPickerCtrlBase() : m_bIgnoreNextTextCtrlUpdate(false) {}
103 // NB: no default values since this function will never be used
104 // directly by the user and derived classes wouldn't use them
105 bool CreateBase(wxWindow
*parent
,
107 const wxString
& path
,
108 const wxString
&message
,
109 const wxString
&wildcard
,
113 const wxValidator
& validator
,
114 const wxString
& name
);
116 public: // public API
118 wxString
GetPath() const;
119 void SetPath(const wxString
&str
);
121 public: // internal functions
123 void UpdatePickerFromTextCtrl();
124 void UpdateTextCtrlFromPicker();
126 // event handler for our picker
127 void OnFileDirChange(wxFileDirPickerEvent
&);
129 // Returns TRUE if the current path is a valid one
130 // (i.e. a valid file for a wxFilePickerWidget or a valid
131 // folder for a wxDirPickerWidget).
132 virtual bool CheckPath(const wxString
&str
) const = 0;
134 // TRUE if any textctrl change should update the current working directory
135 virtual bool IsCwdToUpdate() const = 0;
137 // Returns the event type sent by this picker
138 virtual wxEventType
GetEventType() const = 0;
140 // Returns the filtered value currently placed in the text control (if present).
141 virtual wxString
GetTextCtrlValue() const = 0;
144 // creates the picker control
146 wxFileDirPickerWidgetBase
*CreatePicker(wxWindow
*parent
,
147 const wxString
& path
,
148 const wxString
& message
,
149 const wxString
& wildcard
) = 0;
153 // true if the next UpdateTextCtrl() call is to ignore
154 bool m_bIgnoreNextTextCtrlUpdate
;
156 // m_picker object as wxFileDirPickerWidgetBase interface
157 wxFileDirPickerWidgetBase
*m_pickerIface
;
160 #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
163 #if wxUSE_FILEPICKERCTRL
165 // ----------------------------------------------------------------------------
166 // wxFilePickerCtrl: platform-independent class which embeds the
167 // platform-dependent wxFilePickerWidget and, if wxFLP_USE_TEXTCTRL style is
168 // used, a textctrl next to it.
169 // ----------------------------------------------------------------------------
171 #define wxFLP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
174 // GTK apps usually don't have a textctrl next to the picker
175 #define wxFLP_DEFAULT_STYLE (wxFLP_OPEN|wxFLP_FILE_MUST_EXIST)
177 #define wxFLP_DEFAULT_STYLE (wxFLP_USE_TEXTCTRL|wxFLP_OPEN|wxFLP_FILE_MUST_EXIST)
180 class WXDLLIMPEXP_CORE wxFilePickerCtrl
: public wxFileDirPickerCtrlBase
183 wxFilePickerCtrl() {}
185 wxFilePickerCtrl(wxWindow
*parent
,
187 const wxString
& path
= wxEmptyString
,
188 const wxString
& message
= wxFileSelectorPromptStr
,
189 const wxString
& wildcard
= wxFileSelectorDefaultWildcardStr
,
190 const wxPoint
& pos
= wxDefaultPosition
,
191 const wxSize
& size
= wxDefaultSize
,
192 long style
= wxFLP_DEFAULT_STYLE
,
193 const wxValidator
& validator
= wxDefaultValidator
,
194 const wxString
& name
= wxFilePickerCtrlNameStr
)
196 Create(parent
, id
, path
, message
, wildcard
, pos
, size
, style
,
200 bool Create(wxWindow
*parent
,
202 const wxString
& path
= wxEmptyString
,
203 const wxString
& message
= wxFileSelectorPromptStr
,
204 const wxString
& wildcard
= wxFileSelectorDefaultWildcardStr
,
205 const wxPoint
& pos
= wxDefaultPosition
,
206 const wxSize
& size
= wxDefaultSize
,
207 long style
= wxFLP_DEFAULT_STYLE
,
208 const wxValidator
& validator
= wxDefaultValidator
,
209 const wxString
& name
= wxFilePickerCtrlNameStr
)
211 return wxFileDirPickerCtrlBase::CreateBase(parent
, id
, path
,
220 // return true if the given path is valid for this control
221 bool CheckPath(const wxString
& path
) const;
223 // return the text control value in canonical form
224 wxString
GetTextCtrlValue() const;
226 bool IsCwdToUpdate() const
227 { return HasFlag(wxFLP_CHANGE_DIR
); }
229 wxEventType
GetEventType() const
230 { return wxEVT_COMMAND_FILEPICKER_CHANGED
; }
233 wxFileDirPickerWidgetBase
*CreatePicker(wxWindow
*parent
,
234 const wxString
& path
,
235 const wxString
& message
,
236 const wxString
& wildcard
)
238 return new wxFilePickerWidget(parent
, wxID_ANY
,
239 wxFilePickerWidgetLabel
,
240 path
, message
, wildcard
,
241 wxDefaultPosition
, wxDefaultSize
,
242 GetPickerStyle(GetWindowStyle()));
245 // extracts the style for our picker from wxFileDirPickerCtrlBase's style
246 long GetPickerStyle(long style
) const
248 return (style
& (wxFLP_OPEN
|wxFLP_SAVE
|wxFLP_OVERWRITE_PROMPT
|
249 wxFLP_FILE_MUST_EXIST
|wxFLP_CHANGE_DIR
));
253 DECLARE_DYNAMIC_CLASS(wxFilePickerCtrl
)
256 #endif // wxUSE_FILEPICKERCTRL
259 #if wxUSE_DIRPICKERCTRL
261 // ----------------------------------------------------------------------------
262 // wxDirPickerCtrl: platform-independent class which embeds the
263 // platform-dependent wxDirPickerWidget and eventually a textctrl
264 // (see wxDIRP_USE_TEXTCTRL) next to it.
265 // ----------------------------------------------------------------------------
267 #define wxDIRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
270 // GTK apps usually don't have a textctrl next to the picker
271 #define wxDIRP_DEFAULT_STYLE (wxDIRP_DIR_MUST_EXIST)
273 #define wxDIRP_DEFAULT_STYLE (wxDIRP_USE_TEXTCTRL|wxDIRP_DIR_MUST_EXIST)
276 class WXDLLIMPEXP_CORE wxDirPickerCtrl
: public wxFileDirPickerCtrlBase
281 wxDirPickerCtrl(wxWindow
*parent
, wxWindowID id
,
282 const wxString
& path
= wxEmptyString
,
283 const wxString
& message
= wxDirSelectorPromptStr
,
284 const wxPoint
& pos
= wxDefaultPosition
,
285 const wxSize
& size
= wxDefaultSize
,
286 long style
= wxDIRP_DEFAULT_STYLE
,
287 const wxValidator
& validator
= wxDefaultValidator
,
288 const wxString
& name
= wxDirPickerCtrlNameStr
)
290 Create(parent
, id
, path
, message
, pos
, size
, style
, validator
, name
);
293 bool Create(wxWindow
*parent
, wxWindowID id
,
294 const wxString
& path
= wxEmptyString
,
295 const wxString
& message
= wxDirSelectorPromptStr
,
296 const wxPoint
& pos
= wxDefaultPosition
,
297 const wxSize
& size
= wxDefaultSize
,
298 long style
= wxDIRP_DEFAULT_STYLE
,
299 const wxValidator
& validator
= wxDefaultValidator
,
300 const wxString
& name
= wxDirPickerCtrlNameStr
)
302 return wxFileDirPickerCtrlBase::CreateBase
304 parent
, id
, path
, message
, wxEmptyString
,
305 pos
, size
, style
, validator
, name
312 bool CheckPath(const wxString
&path
) const;
314 wxString
GetTextCtrlValue() const;
316 bool IsCwdToUpdate() const
317 { return HasFlag(wxDIRP_CHANGE_DIR
); }
319 wxEventType
GetEventType() const
320 { return wxEVT_COMMAND_DIRPICKER_CHANGED
; }
323 wxFileDirPickerWidgetBase
*CreatePicker(wxWindow
*parent
,
324 const wxString
& path
,
325 const wxString
& message
,
326 const wxString
& WXUNUSED(wildcard
))
328 return new wxDirPickerWidget(parent
, wxID_ANY
, wxDirPickerWidgetLabel
,
330 wxDefaultPosition
, wxDefaultSize
,
331 GetPickerStyle(GetWindowStyle()));
334 // extracts the style for our picker from wxFileDirPickerCtrlBase's style
335 long GetPickerStyle(long style
) const
336 { return (style
& (wxDIRP_DIR_MUST_EXIST
|wxDIRP_CHANGE_DIR
)); }
339 DECLARE_DYNAMIC_CLASS(wxDirPickerCtrl
)
342 #endif // wxUSE_DIRPICKERCTRL
345 #if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
347 // ----------------------------------------------------------------------------
348 // wxFileDirPickerEvent: used by wxFilePickerCtrl and wxDirPickerCtrl only
349 // ----------------------------------------------------------------------------
351 BEGIN_DECLARE_EVENT_TYPES()
352 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE
, wxEVT_COMMAND_FILEPICKER_CHANGED
, 1102)
353 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE
, wxEVT_COMMAND_DIRPICKER_CHANGED
, 1103)
354 END_DECLARE_EVENT_TYPES()
356 class WXDLLIMPEXP_CORE wxFileDirPickerEvent
: public wxCommandEvent
359 wxFileDirPickerEvent() {}
360 wxFileDirPickerEvent(wxEventType type
, wxObject
*generator
, int id
, const wxString
&path
)
361 : wxCommandEvent(type
, id
),
364 SetEventObject(generator
);
367 wxString
GetPath() const { return m_path
; }
368 void SetPath(const wxString
&p
) { m_path
= p
; }
370 // default copy ctor, assignment operator and dtor are ok
371 virtual wxEvent
*Clone() const { return new wxFileDirPickerEvent(*this); }
376 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxFileDirPickerEvent
)
379 // ----------------------------------------------------------------------------
380 // event types and macros
381 // ----------------------------------------------------------------------------
383 typedef void (wxEvtHandler::*wxFileDirPickerEventFunction
)(wxFileDirPickerEvent
&);
385 #define wxFileDirPickerEventHandler(func) \
386 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxFileDirPickerEventFunction, &func)
388 #define EVT_FILEPICKER_CHANGED(id, fn) \
389 wx__DECLARE_EVT1(wxEVT_COMMAND_FILEPICKER_CHANGED, id, wxFileDirPickerEventHandler(fn))
390 #define EVT_DIRPICKER_CHANGED(id, fn) \
391 wx__DECLARE_EVT1(wxEVT_COMMAND_DIRPICKER_CHANGED, id, wxFileDirPickerEventHandler(fn))
393 #ifdef _WX_DEFINE_DATE_EVENTS_
394 DEFINE_EVENT_TYPE(wxEVT_COMMAND_FILEPICKER_CHANGED
)
395 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DIRPICKER_CHANGED
)
397 IMPLEMENT_DYNAMIC_CLASS(wxFileDirPickerEvent
, wxCommandEvent
)
401 #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
403 #endif // _WX_FILEDIRPICKER_H_BASE_