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"
20 #include "wx/filename.h"
22 class WXDLLIMPEXP_CORE wxDialog
;
23 class WXDLLIMPEXP_CORE wxFileDirPickerEvent
;
25 extern WXDLLEXPORT_DATA(const wxChar
) wxFilePickerWidgetLabel
[];
26 extern WXDLLEXPORT_DATA(const wxChar
) wxFilePickerWidgetNameStr
[];
27 extern WXDLLEXPORT_DATA(const wxChar
) wxFilePickerCtrlNameStr
[];
28 extern WXDLLEXPORT_DATA(const wxChar
) wxFileSelectorPromptStr
[];
30 extern WXDLLEXPORT_DATA(const wxChar
) wxDirPickerWidgetLabel
[];
31 extern WXDLLEXPORT_DATA(const wxChar
) wxDirPickerWidgetNameStr
[];
32 extern WXDLLEXPORT_DATA(const wxChar
) wxDirPickerCtrlNameStr
[];
33 extern WXDLLEXPORT_DATA(const wxChar
) wxDirSelectorPromptStr
[];
36 // ----------------------------------------------------------------------------
37 // wxFileDirPickerWidgetBase: a generic abstract interface which must be
38 // implemented by controls used by wxFileDirPickerCtrlBase
39 // ----------------------------------------------------------------------------
41 class WXDLLIMPEXP_CORE wxFileDirPickerWidgetBase
44 wxFileDirPickerWidgetBase() { }
45 virtual ~wxFileDirPickerWidgetBase() { }
47 wxString
GetPath() const { return m_path
; }
48 virtual void SetPath(const wxString
&str
) { m_path
=str
; }
51 virtual void UpdateDialogPath(wxDialog
*) = 0;
52 virtual void UpdatePathFromDialog(wxDialog
*) = 0;
57 // Styles which must be supported by all controls implementing wxFileDirPickerWidgetBase
58 // NB: these styles must be defined to carefully-chosen values to
59 // avoid conflicts with wxButton's styles
61 #define wxFLP_OPEN 0x0200
62 #define wxFLP_SAVE 0x0400
63 #define wxFLP_OVERWRITE_PROMPT 0x0800
64 #define wxFLP_FILE_MUST_EXIST 0x1000
65 #define wxFLP_CHANGE_DIR 0x2000
67 // NOTE: wxMULTIPLE is not supported !
70 #define wxDIRP_DIR_MUST_EXIST 0x0008
71 #define wxDIRP_CHANGE_DIR 0x0010
74 // map platform-dependent controls which implement the wxFileDirPickerWidgetBase
75 // under the name "wxFilePickerWidget" and "wxDirPickerWidget".
76 // NOTE: wxFileDirPickerCtrlBase will allocate a wx{File|Dir}PickerWidget and this
77 // requires that all classes being mapped as wx{File|Dir}PickerWidget have the
78 // same prototype for the contructor...
79 #if defined(__WXGTK26__) // since GTK >= 2.6, there is GtkFileButton
80 #include "wx/gtk/filepicker.h"
81 #define wxFilePickerWidget wxFileButton
82 #define wxDirPickerWidget wxDirButton
84 #include "wx/generic/filepickerg.h"
85 #define wxFilePickerWidget wxGenericFileButton
86 #define wxDirPickerWidget wxGenericDirButton
91 // ----------------------------------------------------------------------------
92 // wxFileDirPickerWidgetBase
93 // ----------------------------------------------------------------------------
95 class WXDLLIMPEXP_CORE wxFileDirPickerCtrlBase
: public wxPickerBase
98 wxFileDirPickerCtrlBase() : m_bIgnoreNextTextCtrlUpdate(false) {}
99 virtual ~wxFileDirPickerCtrlBase() {}
101 // NB: no default values since this function will never be used
102 // directly by the user and derived classes wouldn't use them
103 bool CreateBase(wxWindow
*parent
,
105 const wxString
& path
,
106 const wxString
&message
,
107 const wxString
&wildcard
,
111 const wxValidator
& validator
,
112 const wxString
& name
);
114 public: // public API
116 wxString
GetPath() const
117 { return ((wxFileDirPickerWidgetBase
*)m_picker
)->GetPath(); }
118 void SetPath(const wxString
&str
);
120 public: // internal functions
122 void UpdatePickerFromTextCtrl();
123 void UpdateTextCtrlFromPicker();
125 // event handler for our picker
126 void OnFileDirChange(wxFileDirPickerEvent
&);
128 virtual bool CreatePicker(wxWindow
*parent
, const wxString
& path
,
129 const wxString
& message
, const wxString
& wildcard
) = 0;
131 // Returns TRUE if the current path is a valid one
132 // (i.e. a valid file for a wxFilePickerWidget or a valid
133 // folder for a wxDirPickerWidget).
134 virtual bool CheckPath(const wxString
&str
) const = 0;
136 // TRUE if any textctrl change should update the current working directory
137 virtual bool IsCwdToUpdate() const = 0;
139 // Returns the event type sent by this picker
140 virtual wxEventType
GetEventType() const = 0;
144 // true if the next UpdateTextCtrl() call is to ignore
145 bool m_bIgnoreNextTextCtrlUpdate
;
148 #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
151 #if wxUSE_FILEPICKERCTRL
153 // ----------------------------------------------------------------------------
154 // wxFilePickerCtrl: platform-independent class which embeds the
155 // platform-dependent wxFilePickerWidget and, if wxFLP_USE_TEXTCTRL style is
156 // used, a textctrl next to it.
157 // ----------------------------------------------------------------------------
159 #define wxFLP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
162 // GTK apps usually don't have a textctrl next to the picker
163 #define wxFLP_DEFAULT_STYLE (wxFLP_OPEN)
165 #define wxFLP_DEFAULT_STYLE (wxFLP_USE_TEXTCTRL|wxFLP_OPEN)
168 class WXDLLIMPEXP_CORE wxFilePickerCtrl
: public wxFileDirPickerCtrlBase
171 wxFilePickerCtrl() {}
172 virtual ~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 bool CheckPath(const wxString
&path
) const
222 return HasFlag(wxFLP_SAVE
) || wxFileName::FileExists(path
);
225 bool IsCwdToUpdate() const
226 { return HasFlag(wxFLP_CHANGE_DIR
); }
228 wxEventType
GetEventType() const
229 { return wxEVT_COMMAND_FILEPICKER_CHANGED
; }
232 // extracts the style for our picker from wxFileDirPickerCtrlBase's style
233 long GetPickerStyle(long style
) const
235 return (style
& (wxFLP_OPEN
|wxFLP_SAVE
|wxFLP_OVERWRITE_PROMPT
|
236 wxFLP_FILE_MUST_EXIST
|wxFLP_CHANGE_DIR
));
240 DECLARE_DYNAMIC_CLASS(wxFilePickerCtrl
)
243 #endif // wxUSE_FILEPICKERCTRL
246 #if wxUSE_DIRPICKERCTRL
248 // ----------------------------------------------------------------------------
249 // wxDirPickerCtrl: platform-independent class which embeds the
250 // platform-dependent wxDirPickerWidget and eventually a textctrl
251 // (see wxDIRP_USE_TEXTCTRL) next to it.
252 // ----------------------------------------------------------------------------
254 #define wxDIRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
257 // GTK apps usually don't have a textctrl next to the picker
258 #define wxDIRP_DEFAULT_STYLE 0
260 #define wxDIRP_DEFAULT_STYLE (wxDIRP_USE_TEXTCTRL)
263 class WXDLLIMPEXP_CORE wxDirPickerCtrl
: public wxFileDirPickerCtrlBase
267 virtual ~wxDirPickerCtrl() {}
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
, long style
= wxDIRP_DEFAULT_STYLE
,
274 const wxValidator
& validator
= wxDefaultValidator
,
275 const wxString
& name
= wxDirPickerCtrlNameStr
)
276 { Create(parent
, id
, path
, message
, pos
, size
, style
, validator
, name
); }
278 bool Create(wxWindow
*parent
, wxWindowID id
,
279 const wxString
& path
= wxEmptyString
,
280 const wxString
& message
= wxDirSelectorPromptStr
,
281 const wxPoint
& pos
= wxDefaultPosition
,
282 const wxSize
& size
= wxDefaultSize
, long style
= wxDIRP_DEFAULT_STYLE
,
283 const wxValidator
& validator
= wxDefaultValidator
,
284 const wxString
& name
= wxDirPickerCtrlNameStr
)
285 { return wxFileDirPickerCtrlBase::CreateBase(parent
, id
, path
, message
, wxEmptyString
,
286 pos
, size
, style
, validator
, name
); }
291 bool CreatePicker(wxWindow
*parent
, const wxString
& path
,
292 const wxString
& message
, const wxString
& WXUNUSED(wildcard
))
294 m_picker
= new wxDirPickerWidget(parent
, wxID_ANY
, wxDirPickerWidgetLabel
,
295 path
, message
, wxDefaultPosition
, wxDefaultSize
,
296 GetPickerStyle(GetWindowStyle()));
300 bool CheckPath(const wxString
&path
) const
301 { if (HasFlag(wxDIRP_DIR_MUST_EXIST
)) return wxFileName::DirExists(path
); else return true; }
303 bool IsCwdToUpdate() const
304 { return HasFlag(wxDIRP_CHANGE_DIR
); }
306 wxEventType
GetEventType() const
307 { return wxEVT_COMMAND_DIRPICKER_CHANGED
; }
310 // extracts the style for our picker from wxFileDirPickerCtrlBase's style
311 long GetPickerStyle(long style
) const
312 { return (style
& (wxDIRP_DIR_MUST_EXIST
|wxDIRP_CHANGE_DIR
)); }
315 DECLARE_DYNAMIC_CLASS(wxDirPickerCtrl
)
318 #endif // wxUSE_DIRPICKERCTRL
321 #if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
323 // ----------------------------------------------------------------------------
324 // wxFileDirPickerEvent: used by wxFilePickerCtrl and wxDirPickerCtrl only
325 // ----------------------------------------------------------------------------
327 BEGIN_DECLARE_EVENT_TYPES()
328 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE
, wxEVT_COMMAND_FILEPICKER_CHANGED
, 1102)
329 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE
, wxEVT_COMMAND_DIRPICKER_CHANGED
, 1103)
330 END_DECLARE_EVENT_TYPES()
332 class WXDLLIMPEXP_CORE wxFileDirPickerEvent
: public wxCommandEvent
335 wxFileDirPickerEvent() {}
336 wxFileDirPickerEvent(wxEventType type
, wxObject
*generator
, int id
, const wxString
&path
)
337 : wxCommandEvent(type
, id
),
340 SetEventObject(generator
);
343 wxString
GetPath() const { return m_path
; }
344 void SetPath(const wxString
&p
) { m_path
= p
; }
349 DECLARE_DYNAMIC_CLASS_NO_COPY(wxFileDirPickerEvent
)
352 // ----------------------------------------------------------------------------
353 // event types and macros
354 // ----------------------------------------------------------------------------
356 typedef void (wxEvtHandler::*wxFileDirPickerEventFunction
)(wxFileDirPickerEvent
&);
358 #define wxFileDirPickerEventHandler(func) \
359 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxFileDirPickerEventFunction, &func)
361 #define EVT_FILEPICKER_CHANGED(id, fn) \
362 wx__DECLARE_EVT1(wxEVT_COMMAND_FILEPICKER_CHANGED, id, wxFileDirPickerEventHandler(fn))
363 #define EVT_DIRPICKER_CHANGED(id, fn) \
364 wx__DECLARE_EVT1(wxEVT_COMMAND_DIRPICKER_CHANGED, id, wxFileDirPickerEventHandler(fn))
366 #ifdef _WX_DEFINE_DATE_EVENTS_
367 DEFINE_EVENT_TYPE(wxEVT_COMMAND_FILEPICKER_CHANGED
)
368 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DIRPICKER_CHANGED
)
370 IMPLEMENT_DYNAMIC_CLASS(wxFileDirPickerEvent
, wxCommandEvent
)
374 #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
376 #endif // _WX_FILEDIRPICKER_H_BASE_