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_
18 #if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
20 #include "wx/control.h"
21 #include "wx/pickerbase.h"
22 #include "wx/filedlg.h"
23 #include "wx/filename.h"
26 class WXDLLIMPEXP_CORE wxFileDirPickerEvent
;
28 extern WXDLLEXPORT_DATA(const wxChar
) wxFilePickerWidgetLabel
[];
29 extern WXDLLEXPORT_DATA(const wxChar
) wxFilePickerWidgetNameStr
[];
30 extern WXDLLEXPORT_DATA(const wxChar
) wxFilePickerCtrlNameStr
[];
31 extern WXDLLEXPORT_DATA(const wxChar
) wxFileSelectorPromptStr
[];
33 extern WXDLLEXPORT_DATA(const wxChar
) wxDirPickerWidgetLabel
[];
34 extern WXDLLEXPORT_DATA(const wxChar
) wxDirPickerWidgetNameStr
[];
35 extern WXDLLEXPORT_DATA(const wxChar
) wxDirPickerCtrlNameStr
[];
36 extern WXDLLEXPORT_DATA(const wxChar
) wxDirSelectorPromptStr
[];
39 // ----------------------------------------------------------------------------
40 // wxFileDirPickerWidgetBase: a generic abstract interface which must be
41 // implemented by controls used by wxFileDirPickerCtrlBase
42 // ----------------------------------------------------------------------------
44 class WXDLLIMPEXP_CORE wxFileDirPickerWidgetBase
47 wxFileDirPickerWidgetBase() { }
48 virtual ~wxFileDirPickerWidgetBase() { }
50 wxString
GetPath() const { return m_path
; }
51 void SetPath(const wxString
&str
) { m_path
=str
; UpdateDialogPath(); }
54 virtual void UpdateDialogPath() = 0;
55 virtual void UpdatePathFromDialog() = 0;
60 // Styles which must be supported by all controls implementing wxFileDirPickerWidgetBase
61 // NB: these styles must be defined to carefully-chosen values to
62 // avoid conflicts with wxButton's styles
64 #define wxFLP_OPEN 0x0200
65 #define wxFLP_SAVE 0x0400
66 #define wxFLP_OVERWRITE_PROMPT 0x0800
67 #define wxFLP_FILE_MUST_EXIST 0x1000
68 #define wxFLP_CHANGE_DIR 0x2000
70 // NOTE: wxMULTIPLE is not supported !
73 #define wxDIRP_DIR_MUST_EXIST 0x0008
74 #define wxDIRP_CHANGE_DIR 0x0010
77 // map platform-dependent controls which implement the wxFileDirPickerWidgetBase
78 // under the name "wxFilePickerWidget" and "wxDirPickerWidget".
79 // NOTE: wxFileDirPickerCtrlBase will allocate a wx{File|Dir}PickerWidget and this
80 // requires that all classes being mapped as wx{File|Dir}PickerWidget have the
81 // same prototype for the contructor...
82 #if defined(__WXGTK26__) // since GTK >= 2.6, there is GtkFileButton
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 // wxFileDirPickerWidgetBase
96 // ----------------------------------------------------------------------------
98 class WXDLLIMPEXP_CORE wxFileDirPickerCtrlBase
: public wxPickerBase
101 wxFileDirPickerCtrlBase() : m_bIgnoreNextTextCtrlUpdate(false) {}
102 virtual ~wxFileDirPickerCtrlBase() {}
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 { return ((wxFileDirPickerWidgetBase
*)m_picker
)->GetPath(); }
121 void SetPath(const wxString
&str
);
123 public: // internal functions
125 void UpdatePickerFromTextCtrl();
126 void UpdateTextCtrlFromPicker();
128 // event handler for our picker
129 void OnFileDirChange(wxFileDirPickerEvent
&);
131 virtual bool CreatePicker(wxWindow
*parent
, const wxString
& path
,
132 const wxString
& message
, const wxString
& wildcard
) = 0;
134 // Returns TRUE if the current path is a valid one
135 // (i.e. a valid file for a wxFilePickerWidget or a valid
136 // folder for a wxDirPickerWidget).
137 virtual bool CheckPath(const wxString
&str
) const = 0;
139 // TRUE if any textctrl change should update the current working directory
140 virtual bool IsCwdToUpdate() const = 0;
142 // Returns the event type sent by this picker
143 virtual wxEventType
GetEventType() const = 0;
147 // true if the next UpdateTextCtrl() call is to ignore
148 bool m_bIgnoreNextTextCtrlUpdate
;
151 #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
154 #if wxUSE_FILEPICKERCTRL
156 // ----------------------------------------------------------------------------
157 // wxFilePickerCtrl: platform-independent class which embeds the
158 // platform-dependent wxFilePickerWidget and, if wxFLP_USE_TEXTCTRL style is
159 // used, a textctrl next to it.
160 // ----------------------------------------------------------------------------
162 #define wxFLP_USE_TEXTCTRL wxPB_USE_TEXTCTRL
165 // GTK apps usually don't have a textctrl next to the picker
166 #define wxFLP_DEFAULT_STYLE wxFLP_OPEN
168 #define wxFLP_DEFAULT_STYLE wxFLP_USE_TEXTCTRL|wxFLP_OPEN
171 class WXDLLIMPEXP_CORE wxFilePickerCtrl
: public wxFileDirPickerCtrlBase
174 wxFilePickerCtrl() {}
175 virtual ~wxFilePickerCtrl() {}
177 wxFilePickerCtrl(wxWindow
*parent
,
179 const wxString
& path
= wxEmptyString
,
180 const wxString
& message
= wxFileSelectorPromptStr
,
181 const wxString
& wildcard
= wxFileSelectorDefaultWildcardStr
,
182 const wxPoint
& pos
= wxDefaultPosition
,
183 const wxSize
& size
= wxDefaultSize
,
184 long style
= wxFLP_DEFAULT_STYLE
,
185 const wxValidator
& validator
= wxDefaultValidator
,
186 const wxString
& name
= wxFilePickerCtrlNameStr
)
188 Create(parent
, id
, path
, message
, wildcard
, pos
, size
, style
,
192 bool Create(wxWindow
*parent
,
194 const wxString
& path
= wxEmptyString
,
195 const wxString
& message
= wxFileSelectorPromptStr
,
196 const wxString
& wildcard
= wxFileSelectorDefaultWildcardStr
,
197 const wxPoint
& pos
= wxDefaultPosition
,
198 const wxSize
& size
= wxDefaultSize
,
199 long style
= wxFLP_DEFAULT_STYLE
,
200 const wxValidator
& validator
= wxDefaultValidator
,
201 const wxString
& name
= wxFilePickerCtrlNameStr
)
203 return wxFileDirPickerCtrlBase::CreateBase(parent
, id
, path
,
212 bool CreatePicker(wxWindow
*parent
, const wxString
& path
,
213 const wxString
& message
, const wxString
& wildcard
)
215 m_picker
= new wxFilePickerWidget(parent
, wxID_ANY
,
216 wxFilePickerWidgetLabel
,
217 path
, message
, wildcard
,
218 wxDefaultPosition
, wxDefaultSize
,
219 GetPickerStyle(GetWindowStyle()));
223 // extracts the style for our picker from wxFileDirPickerCtrlBase's style
224 long GetPickerStyle(long style
) const
226 return (style
& (wxFLP_OPEN
|wxFLP_SAVE
|wxFLP_OVERWRITE_PROMPT
|
227 wxFLP_FILE_MUST_EXIST
|wxFLP_CHANGE_DIR
));
230 bool CheckPath(const wxString
&path
) const
232 return HasFlag(wxFLP_SAVE
) || wxFileName::FileExists(path
);
235 bool IsCwdToUpdate() const
236 { return HasFlag(wxFLP_CHANGE_DIR
); }
238 wxEventType
GetEventType() const
239 { return wxEVT_COMMAND_FILEPICKER_CHANGED
; }
242 DECLARE_DYNAMIC_CLASS(wxFilePickerCtrl
)
245 #endif // wxUSE_FILEPICKERCTRL
248 #if wxUSE_DIRPICKERCTRL
250 // ----------------------------------------------------------------------------
251 // wxDirPickerCtrl: platform-independent class which embeds the
252 // platform-dependent wxDirPickerWidget and eventually a textctrl
253 // (see wxDIRP_USE_TEXTCTRL) next to it.
254 // ----------------------------------------------------------------------------
256 #define wxDIRP_USE_TEXTCTRL wxPB_USE_TEXTCTRL
259 // GTK apps usually don't have a textctrl next to the picker
260 #define wxDIRP_DEFAULT_STYLE 0
262 #define wxDIRP_DEFAULT_STYLE wxDIRP_USE_TEXTCTRL
265 class WXDLLIMPEXP_CORE wxDirPickerCtrl
: public wxFileDirPickerCtrlBase
269 virtual ~wxDirPickerCtrl() {}
271 wxDirPickerCtrl(wxWindow
*parent
, wxWindowID id
,
272 const wxString
& path
= wxEmptyString
,
273 const wxString
& message
= wxDirSelectorPromptStr
,
274 const wxPoint
& pos
= wxDefaultPosition
,
275 const wxSize
& size
= wxDefaultSize
, long style
= wxDIRP_DEFAULT_STYLE
,
276 const wxValidator
& validator
= wxDefaultValidator
,
277 const wxString
& name
= wxDirPickerCtrlNameStr
)
278 { Create(parent
, id
, path
, message
, pos
, size
, style
, validator
, name
); }
280 bool Create(wxWindow
*parent
, wxWindowID id
,
281 const wxString
& path
= wxEmptyString
,
282 const wxString
& message
= wxDirSelectorPromptStr
,
283 const wxPoint
& pos
= wxDefaultPosition
,
284 const wxSize
& size
= wxDefaultSize
, long style
= wxDIRP_DEFAULT_STYLE
,
285 const wxValidator
& validator
= wxDefaultValidator
,
286 const wxString
& name
= wxDirPickerCtrlNameStr
)
287 { return wxFileDirPickerCtrlBase::CreateBase(parent
, id
, path
, message
, wxEmptyString
,
288 pos
, size
, style
, validator
, name
); }
293 bool CreatePicker(wxWindow
*parent
, const wxString
& path
,
294 const wxString
& message
, const wxString
& WXUNUSED(wildcard
))
296 m_picker
= new wxDirPickerWidget(parent
, wxID_ANY
, wxDirPickerWidgetLabel
,
297 path
, message
, wxDefaultPosition
, wxDefaultSize
,
298 GetPickerStyle(GetWindowStyle()));
302 // extracts the style for our picker from wxFileDirPickerCtrlBase's style
303 long GetPickerStyle(long style
) const
304 { return (style
& (wxDIRP_DIR_MUST_EXIST
|wxDIRP_CHANGE_DIR
)); }
306 bool CheckPath(const wxString
&path
) const
307 { if (HasFlag(wxDIRP_DIR_MUST_EXIST
)) return wxFileName::DirExists(path
); else return true; }
309 bool IsCwdToUpdate() const
310 { return HasFlag(wxDIRP_CHANGE_DIR
); }
312 wxEventType
GetEventType() const
313 { return wxEVT_COMMAND_DIRPICKER_CHANGED
; }
316 DECLARE_DYNAMIC_CLASS(wxDirPickerCtrl
)
319 #endif // wxUSE_DIRPICKERCTRL
322 #if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
324 // ----------------------------------------------------------------------------
325 // wxFileDirPickerEvent: used by wxFilePickerCtrl and wxDirPickerCtrl only
326 // ----------------------------------------------------------------------------
328 BEGIN_DECLARE_EVENT_TYPES()
329 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE
, wxEVT_COMMAND_FILEPICKER_CHANGED
, 1102)
330 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE
, wxEVT_COMMAND_DIRPICKER_CHANGED
, 1103)
331 END_DECLARE_EVENT_TYPES()
333 class WXDLLIMPEXP_CORE wxFileDirPickerEvent
: public wxCommandEvent
336 wxFileDirPickerEvent() {}
337 wxFileDirPickerEvent(wxEventType type
, wxObject
*generator
, int id
, const wxString
&path
)
338 : wxCommandEvent(type
, id
),
341 SetEventObject(generator
);
344 wxString
GetPath() const { return m_path
; }
345 void SetPath(const wxString
&p
) { m_path
= p
; }
350 DECLARE_DYNAMIC_CLASS_NO_COPY(wxFileDirPickerEvent
)
353 // ----------------------------------------------------------------------------
354 // event types and macros
355 // ----------------------------------------------------------------------------
357 typedef void (wxEvtHandler::*wxFileDirPickerEventFunction
)(wxFileDirPickerEvent
&);
359 #define wxFileDirPickerEventHandler(func) \
360 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxFileDirPickerEventFunction, &func)
362 #define EVT_FILEPICKER_CHANGED(id, fn) \
363 wx__DECLARE_EVT1(wxEVT_COMMAND_FILEPICKER_CHANGED, id, wxFileDirPickerEventHandler(fn))
364 #define EVT_DIRPICKER_CHANGED(id, fn) \
365 wx__DECLARE_EVT1(wxEVT_COMMAND_DIRPICKER_CHANGED, id, wxFileDirPickerEventHandler(fn))
367 #ifdef _WX_DEFINE_DATE_EVENTS_
368 DEFINE_EVENT_TYPE(wxEVT_COMMAND_FILEPICKER_CHANGED
)
369 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DIRPICKER_CHANGED
)
371 IMPLEMENT_DYNAMIC_CLASS(wxFileDirPickerEvent
, wxCommandEvent
)
375 #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
377 #endif // _WX_FILEDIRPICKER_H_BASE_