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
; }
50 virtual void UpdateDialogPath(wxDialog
*) = 0;
51 virtual void UpdatePathFromDialog(wxDialog
*) = 0;
56 // Styles which must be supported by all controls implementing wxFileDirPickerWidgetBase
57 // NB: these styles must be defined to carefully-chosen values to
58 // avoid conflicts with wxButton's styles
60 #define wxFLP_OPEN 0x0200
61 #define wxFLP_SAVE 0x0400
62 #define wxFLP_OVERWRITE_PROMPT 0x0800
63 #define wxFLP_FILE_MUST_EXIST 0x1000
64 #define wxFLP_CHANGE_DIR 0x2000
66 // NOTE: wxMULTIPLE is not supported !
69 #define wxDIRP_DIR_MUST_EXIST 0x0008
70 #define wxDIRP_CHANGE_DIR 0x0010
73 // map platform-dependent controls which implement the wxFileDirPickerWidgetBase
74 // under the name "wxFilePickerWidget" and "wxDirPickerWidget".
75 // NOTE: wxFileDirPickerCtrlBase will allocate a wx{File|Dir}PickerWidget and this
76 // requires that all classes being mapped as wx{File|Dir}PickerWidget have the
77 // same prototype for the contructor...
78 #if defined(__WXGTK26__) // since GTK >= 2.6, there is GtkFileButton
79 #include "wx/gtk/filepicker.h"
80 #define wxFilePickerWidget wxFileButton
81 #define wxDirPickerWidget wxDirButton
83 #include "wx/generic/filepickerg.h"
84 #define wxFilePickerWidget wxGenericFileButton
85 #define wxDirPickerWidget wxGenericDirButton
90 // ----------------------------------------------------------------------------
91 // wxFileDirPickerWidgetBase
92 // ----------------------------------------------------------------------------
94 class WXDLLIMPEXP_CORE wxFileDirPickerCtrlBase
: public wxPickerBase
97 wxFileDirPickerCtrlBase() : m_bIgnoreNextTextCtrlUpdate(false) {}
99 // NB: no default values since this function will never be used
100 // directly by the user and derived classes wouldn't use them
101 bool CreateBase(wxWindow
*parent
,
103 const wxString
& path
,
104 const wxString
&message
,
105 const wxString
&wildcard
,
109 const wxValidator
& validator
,
110 const wxString
& name
);
112 public: // public API
114 wxString
GetPath() const
115 { return ((wxFileDirPickerWidgetBase
*)m_picker
)->GetPath(); }
116 void SetPath(const wxString
&str
);
118 public: // internal functions
120 void UpdatePickerFromTextCtrl();
121 void UpdateTextCtrlFromPicker();
123 // event handler for our picker
124 void OnFileDirChange(wxFileDirPickerEvent
&);
126 virtual bool CreatePicker(wxWindow
*parent
, const wxString
& path
,
127 const wxString
& message
, const wxString
& wildcard
) = 0;
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;
145 // true if the next UpdateTextCtrl() call is to ignore
146 bool m_bIgnoreNextTextCtrlUpdate
;
149 #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
152 #if wxUSE_FILEPICKERCTRL
154 // ----------------------------------------------------------------------------
155 // wxFilePickerCtrl: platform-independent class which embeds the
156 // platform-dependent wxFilePickerWidget and, if wxFLP_USE_TEXTCTRL style is
157 // used, a textctrl next to it.
158 // ----------------------------------------------------------------------------
160 #define wxFLP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
163 // GTK apps usually don't have a textctrl next to the picker
164 #define wxFLP_DEFAULT_STYLE (wxFLP_OPEN|wxFLP_FILE_MUST_EXIST)
166 #define wxFLP_DEFAULT_STYLE (wxFLP_USE_TEXTCTRL|wxFLP_OPEN|wxFLP_FILE_MUST_EXIST)
169 class WXDLLIMPEXP_CORE wxFilePickerCtrl
: public wxFileDirPickerCtrlBase
172 wxFilePickerCtrl() {}
174 wxFilePickerCtrl(wxWindow
*parent
,
176 const wxString
& path
= wxEmptyString
,
177 const wxString
& message
= wxFileSelectorPromptStr
,
178 const wxString
& wildcard
= wxFileSelectorDefaultWildcardStr
,
179 const wxPoint
& pos
= wxDefaultPosition
,
180 const wxSize
& size
= wxDefaultSize
,
181 long style
= wxFLP_DEFAULT_STYLE
,
182 const wxValidator
& validator
= wxDefaultValidator
,
183 const wxString
& name
= wxFilePickerCtrlNameStr
)
185 Create(parent
, id
, path
, message
, wildcard
, pos
, size
, style
,
189 bool Create(wxWindow
*parent
,
191 const wxString
& path
= wxEmptyString
,
192 const wxString
& message
= wxFileSelectorPromptStr
,
193 const wxString
& wildcard
= wxFileSelectorDefaultWildcardStr
,
194 const wxPoint
& pos
= wxDefaultPosition
,
195 const wxSize
& size
= wxDefaultSize
,
196 long style
= wxFLP_DEFAULT_STYLE
,
197 const wxValidator
& validator
= wxDefaultValidator
,
198 const wxString
& name
= wxFilePickerCtrlNameStr
)
200 return wxFileDirPickerCtrlBase::CreateBase(parent
, id
, path
,
209 bool CreatePicker(wxWindow
*parent
, const wxString
& path
,
210 const wxString
& message
, const wxString
& wildcard
)
212 m_picker
= new wxFilePickerWidget(parent
, wxID_ANY
,
213 wxFilePickerWidgetLabel
,
214 path
, message
, wildcard
,
215 wxDefaultPosition
, wxDefaultSize
,
216 GetPickerStyle(GetWindowStyle()));
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 // extracts the style for our picker from wxFileDirPickerCtrlBase's style
234 long GetPickerStyle(long style
) const
236 return (style
& (wxFLP_OPEN
|wxFLP_SAVE
|wxFLP_OVERWRITE_PROMPT
|
237 wxFLP_FILE_MUST_EXIST
|wxFLP_CHANGE_DIR
));
241 DECLARE_DYNAMIC_CLASS(wxFilePickerCtrl
)
244 #endif // wxUSE_FILEPICKERCTRL
247 #if wxUSE_DIRPICKERCTRL
249 // ----------------------------------------------------------------------------
250 // wxDirPickerCtrl: platform-independent class which embeds the
251 // platform-dependent wxDirPickerWidget and eventually a textctrl
252 // (see wxDIRP_USE_TEXTCTRL) next to it.
253 // ----------------------------------------------------------------------------
255 #define wxDIRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
258 // GTK apps usually don't have a textctrl next to the picker
259 #define wxDIRP_DEFAULT_STYLE (wxDIRP_DIR_MUST_EXIST)
261 #define wxDIRP_DEFAULT_STYLE (wxDIRP_USE_TEXTCTRL|wxDIRP_DIR_MUST_EXIST)
264 class WXDLLIMPEXP_CORE wxDirPickerCtrl
: public wxFileDirPickerCtrlBase
269 wxDirPickerCtrl(wxWindow
*parent
, wxWindowID id
,
270 const wxString
& path
= wxEmptyString
,
271 const wxString
& message
= wxDirSelectorPromptStr
,
272 const wxPoint
& pos
= wxDefaultPosition
,
273 const wxSize
& size
= wxDefaultSize
,
274 long style
= wxDIRP_DEFAULT_STYLE
,
275 const wxValidator
& validator
= wxDefaultValidator
,
276 const wxString
& name
= wxDirPickerCtrlNameStr
)
278 Create(parent
, id
, path
, message
, pos
, size
, style
, validator
, name
);
281 bool Create(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 return wxFileDirPickerCtrlBase::CreateBase
292 parent
, id
, path
, message
, wxEmptyString
,
293 pos
, size
, style
, validator
, name
300 bool CreatePicker(wxWindow
*parent
, const wxString
& path
,
301 const wxString
& message
, const wxString
& WXUNUSED(wildcard
))
303 m_picker
= new wxDirPickerWidget(parent
, wxID_ANY
, wxDirPickerWidgetLabel
,
304 path
, message
, wxDefaultPosition
, wxDefaultSize
,
305 GetPickerStyle(GetWindowStyle()));
309 bool CheckPath(const wxString
&path
) const;
311 wxString
GetTextCtrlValue() const;
313 bool IsCwdToUpdate() const
314 { return HasFlag(wxDIRP_CHANGE_DIR
); }
316 wxEventType
GetEventType() const
317 { return wxEVT_COMMAND_DIRPICKER_CHANGED
; }
320 // extracts the style for our picker from wxFileDirPickerCtrlBase's style
321 long GetPickerStyle(long style
) const
322 { return (style
& (wxDIRP_DIR_MUST_EXIST
|wxDIRP_CHANGE_DIR
)); }
325 DECLARE_DYNAMIC_CLASS(wxDirPickerCtrl
)
328 #endif // wxUSE_DIRPICKERCTRL
331 #if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
333 // ----------------------------------------------------------------------------
334 // wxFileDirPickerEvent: used by wxFilePickerCtrl and wxDirPickerCtrl only
335 // ----------------------------------------------------------------------------
337 BEGIN_DECLARE_EVENT_TYPES()
338 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE
, wxEVT_COMMAND_FILEPICKER_CHANGED
, 1102)
339 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE
, wxEVT_COMMAND_DIRPICKER_CHANGED
, 1103)
340 END_DECLARE_EVENT_TYPES()
342 class WXDLLIMPEXP_CORE wxFileDirPickerEvent
: public wxCommandEvent
345 wxFileDirPickerEvent() {}
346 wxFileDirPickerEvent(wxEventType type
, wxObject
*generator
, int id
, const wxString
&path
)
347 : wxCommandEvent(type
, id
),
350 SetEventObject(generator
);
353 wxString
GetPath() const { return m_path
; }
354 void SetPath(const wxString
&p
) { m_path
= p
; }
356 // default copy ctor, assignment operator and dtor are ok
357 virtual wxEvent
*Clone() const { return new wxFileDirPickerEvent(*this); }
362 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxFileDirPickerEvent
)
365 // ----------------------------------------------------------------------------
366 // event types and macros
367 // ----------------------------------------------------------------------------
369 typedef void (wxEvtHandler::*wxFileDirPickerEventFunction
)(wxFileDirPickerEvent
&);
371 #define wxFileDirPickerEventHandler(func) \
372 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxFileDirPickerEventFunction, &func)
374 #define EVT_FILEPICKER_CHANGED(id, fn) \
375 wx__DECLARE_EVT1(wxEVT_COMMAND_FILEPICKER_CHANGED, id, wxFileDirPickerEventHandler(fn))
376 #define EVT_DIRPICKER_CHANGED(id, fn) \
377 wx__DECLARE_EVT1(wxEVT_COMMAND_DIRPICKER_CHANGED, id, wxFileDirPickerEventHandler(fn))
379 #ifdef _WX_DEFINE_DATE_EVENTS_
380 DEFINE_EVENT_TYPE(wxEVT_COMMAND_FILEPICKER_CHANGED
)
381 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DIRPICKER_CHANGED
)
383 IMPLEMENT_DYNAMIC_CLASS(wxFileDirPickerEvent
, wxCommandEvent
)
387 #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
389 #endif // _WX_FILEDIRPICKER_H_BASE_