]>
Commit | Line | Data |
---|---|---|
ec376c8f VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/filepicker.h | |
3 | // Purpose: wxFilePickerCtrl, wxDirPickerCtrl base header | |
4 | // Author: Francesco Montorsi | |
5 | // Modified by: | |
6 | // Created: 14/4/2006 | |
7 | // Copyright: (c) Francesco Montorsi | |
8 | // RCS-ID: $Id$ | |
9 | // Licence: wxWindows Licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_FILEDIRPICKER_H_BASE_ | |
13 | #define _WX_FILEDIRPICKER_H_BASE_ | |
14 | ||
15 | #include "wx/defs.h" | |
16 | ||
ec376c8f VZ |
17 | #if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL |
18 | ||
ec376c8f | 19 | #include "wx/pickerbase.h" |
ec376c8f | 20 | |
c757b5fe | 21 | class WXDLLIMPEXP_CORE wxDialog; |
ec376c8f VZ |
22 | class WXDLLIMPEXP_CORE wxFileDirPickerEvent; |
23 | ||
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[]; | |
28 | ||
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[]; | |
33 | ||
34 | ||
35 | // ---------------------------------------------------------------------------- | |
36 | // wxFileDirPickerWidgetBase: a generic abstract interface which must be | |
37 | // implemented by controls used by wxFileDirPickerCtrlBase | |
38 | // ---------------------------------------------------------------------------- | |
39 | ||
40 | class WXDLLIMPEXP_CORE wxFileDirPickerWidgetBase | |
41 | { | |
42 | public: | |
43 | wxFileDirPickerWidgetBase() { } | |
44 | virtual ~wxFileDirPickerWidgetBase() { } | |
45 | ||
46 | wxString GetPath() const { return m_path; } | |
556151f5 | 47 | virtual void SetPath(const wxString &str) { m_path=str; } |
ec376c8f VZ |
48 | |
49 | protected: | |
556151f5 MW |
50 | virtual void UpdateDialogPath(wxDialog *) = 0; |
51 | virtual void UpdatePathFromDialog(wxDialog *) = 0; | |
ec376c8f VZ |
52 | |
53 | wxString m_path; | |
54 | }; | |
55 | ||
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 | |
59 | ||
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 | |
65 | ||
66 | // NOTE: wxMULTIPLE is not supported ! | |
67 | ||
68 | ||
69 | #define wxDIRP_DIR_MUST_EXIST 0x0008 | |
70 | #define wxDIRP_CHANGE_DIR 0x0010 | |
71 | ||
72 | ||
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... | |
5b34e141 | 78 | #if defined(__WXGTK26__) // since GTK >= 2.6, there is GtkFileButton |
ec376c8f VZ |
79 | #include "wx/gtk/filepicker.h" |
80 | #define wxFilePickerWidget wxFileButton | |
81 | #define wxDirPickerWidget wxDirButton | |
82 | #else | |
83 | #include "wx/generic/filepickerg.h" | |
84 | #define wxFilePickerWidget wxGenericFileButton | |
85 | #define wxDirPickerWidget wxGenericDirButton | |
86 | #endif | |
87 | ||
88 | ||
89 | ||
90 | // ---------------------------------------------------------------------------- | |
91 | // wxFileDirPickerWidgetBase | |
92 | // ---------------------------------------------------------------------------- | |
93 | ||
94 | class WXDLLIMPEXP_CORE wxFileDirPickerCtrlBase : public wxPickerBase | |
95 | { | |
96 | public: | |
97 | wxFileDirPickerCtrlBase() : m_bIgnoreNextTextCtrlUpdate(false) {} | |
ec376c8f VZ |
98 | |
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, | |
102 | wxWindowID id, | |
103 | const wxString& path, | |
104 | const wxString &message, | |
105 | const wxString &wildcard, | |
106 | const wxPoint& pos, | |
107 | const wxSize& size, | |
108 | long style, | |
109 | const wxValidator& validator, | |
110 | const wxString& name); | |
111 | ||
112 | public: // public API | |
113 | ||
114 | wxString GetPath() const | |
115 | { return ((wxFileDirPickerWidgetBase*)m_picker)->GetPath(); } | |
116 | void SetPath(const wxString &str); | |
117 | ||
118 | public: // internal functions | |
119 | ||
120 | void UpdatePickerFromTextCtrl(); | |
121 | void UpdateTextCtrlFromPicker(); | |
122 | ||
123 | // event handler for our picker | |
124 | void OnFileDirChange(wxFileDirPickerEvent &); | |
125 | ||
126 | virtual bool CreatePicker(wxWindow *parent, const wxString& path, | |
127 | const wxString& message, const wxString& wildcard) = 0; | |
128 | ||
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; | |
133 | ||
134 | // TRUE if any textctrl change should update the current working directory | |
135 | virtual bool IsCwdToUpdate() const = 0; | |
136 | ||
137 | // Returns the event type sent by this picker | |
138 | virtual wxEventType GetEventType() const = 0; | |
139 | ||
58772e49 VZ |
140 | // Returns the filtered value currently placed in the text control (if present). |
141 | virtual wxString GetTextCtrlValue() const = 0; | |
142 | ||
ec376c8f VZ |
143 | protected: |
144 | ||
145 | // true if the next UpdateTextCtrl() call is to ignore | |
146 | bool m_bIgnoreNextTextCtrlUpdate; | |
147 | }; | |
148 | ||
149 | #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL | |
150 | ||
151 | ||
152 | #if wxUSE_FILEPICKERCTRL | |
153 | ||
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 | // ---------------------------------------------------------------------------- | |
159 | ||
556151f5 | 160 | #define wxFLP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL) |
ec376c8f VZ |
161 | |
162 | #ifdef __WXGTK__ | |
163 | // GTK apps usually don't have a textctrl next to the picker | |
58772e49 | 164 | #define wxFLP_DEFAULT_STYLE (wxFLP_OPEN|wxFLP_FILE_MUST_EXIST) |
ec376c8f | 165 | #else |
58772e49 | 166 | #define wxFLP_DEFAULT_STYLE (wxFLP_USE_TEXTCTRL|wxFLP_OPEN|wxFLP_FILE_MUST_EXIST) |
ec376c8f VZ |
167 | #endif |
168 | ||
169 | class WXDLLIMPEXP_CORE wxFilePickerCtrl : public wxFileDirPickerCtrlBase | |
170 | { | |
171 | public: | |
172 | wxFilePickerCtrl() {} | |
ec376c8f VZ |
173 | |
174 | wxFilePickerCtrl(wxWindow *parent, | |
175 | wxWindowID id, | |
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) | |
184 | { | |
185 | Create(parent, id, path, message, wildcard, pos, size, style, | |
186 | validator, name); | |
187 | } | |
188 | ||
189 | bool Create(wxWindow *parent, | |
190 | wxWindowID id, | |
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) | |
199 | { | |
200 | return wxFileDirPickerCtrlBase::CreateBase(parent, id, path, | |
201 | message, wildcard, | |
202 | pos, size, style, | |
203 | validator, name); | |
204 | } | |
205 | ||
206 | ||
207 | public: // overrides | |
208 | ||
209 | bool CreatePicker(wxWindow *parent, const wxString& path, | |
210 | const wxString& message, const wxString& wildcard) | |
211 | { | |
212 | m_picker = new wxFilePickerWidget(parent, wxID_ANY, | |
213 | wxFilePickerWidgetLabel, | |
214 | path, message, wildcard, | |
215 | wxDefaultPosition, wxDefaultSize, | |
216 | GetPickerStyle(GetWindowStyle())); | |
217 | return true; | |
218 | } | |
219 | ||
58772e49 VZ |
220 | // return true if the given path is valid for this control |
221 | bool CheckPath(const wxString& path) const; | |
222 | ||
223 | // return the text control value in canonical form | |
224 | wxString GetTextCtrlValue() const; | |
ec376c8f VZ |
225 | |
226 | bool IsCwdToUpdate() const | |
227 | { return HasFlag(wxFLP_CHANGE_DIR); } | |
228 | ||
229 | wxEventType GetEventType() const | |
230 | { return wxEVT_COMMAND_FILEPICKER_CHANGED; } | |
231 | ||
c757b5fe PC |
232 | protected: |
233 | // extracts the style for our picker from wxFileDirPickerCtrlBase's style | |
234 | long GetPickerStyle(long style) const | |
235 | { | |
236 | return (style & (wxFLP_OPEN|wxFLP_SAVE|wxFLP_OVERWRITE_PROMPT| | |
237 | wxFLP_FILE_MUST_EXIST|wxFLP_CHANGE_DIR)); | |
238 | } | |
239 | ||
ec376c8f VZ |
240 | private: |
241 | DECLARE_DYNAMIC_CLASS(wxFilePickerCtrl) | |
242 | }; | |
243 | ||
244 | #endif // wxUSE_FILEPICKERCTRL | |
245 | ||
246 | ||
247 | #if wxUSE_DIRPICKERCTRL | |
248 | ||
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 | // ---------------------------------------------------------------------------- | |
254 | ||
556151f5 | 255 | #define wxDIRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL) |
ec376c8f VZ |
256 | |
257 | #ifdef __WXGTK__ | |
258 | // GTK apps usually don't have a textctrl next to the picker | |
58772e49 | 259 | #define wxDIRP_DEFAULT_STYLE (wxDIRP_DIR_MUST_EXIST) |
ec376c8f | 260 | #else |
58772e49 | 261 | #define wxDIRP_DEFAULT_STYLE (wxDIRP_USE_TEXTCTRL|wxDIRP_DIR_MUST_EXIST) |
ec376c8f VZ |
262 | #endif |
263 | ||
264 | class WXDLLIMPEXP_CORE wxDirPickerCtrl : public wxFileDirPickerCtrlBase | |
265 | { | |
266 | public: | |
267 | wxDirPickerCtrl() {} | |
ec376c8f VZ |
268 | |
269 | wxDirPickerCtrl(wxWindow *parent, wxWindowID id, | |
58772e49 VZ |
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) | |
277 | { | |
278 | Create(parent, id, path, message, pos, size, style, validator, name); | |
279 | } | |
ec376c8f VZ |
280 | |
281 | bool Create(wxWindow *parent, wxWindowID id, | |
58772e49 VZ |
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) | |
289 | { | |
290 | return wxFileDirPickerCtrlBase::CreateBase | |
291 | ( | |
292 | parent, id, path, message, wxEmptyString, | |
293 | pos, size, style, validator, name | |
294 | ); | |
295 | } | |
ec376c8f VZ |
296 | |
297 | ||
298 | public: // overrides | |
299 | ||
300 | bool CreatePicker(wxWindow *parent, const wxString& path, | |
301 | const wxString& message, const wxString& WXUNUSED(wildcard)) | |
302 | { | |
303 | m_picker = new wxDirPickerWidget(parent, wxID_ANY, wxDirPickerWidgetLabel, | |
304 | path, message, wxDefaultPosition, wxDefaultSize, | |
305 | GetPickerStyle(GetWindowStyle())); | |
306 | return true; | |
307 | } | |
308 | ||
58772e49 VZ |
309 | bool CheckPath(const wxString &path) const; |
310 | ||
311 | wxString GetTextCtrlValue() const; | |
ec376c8f VZ |
312 | |
313 | bool IsCwdToUpdate() const | |
314 | { return HasFlag(wxDIRP_CHANGE_DIR); } | |
315 | ||
316 | wxEventType GetEventType() const | |
317 | { return wxEVT_COMMAND_DIRPICKER_CHANGED; } | |
318 | ||
c757b5fe PC |
319 | protected: |
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)); } | |
323 | ||
ec376c8f VZ |
324 | private: |
325 | DECLARE_DYNAMIC_CLASS(wxDirPickerCtrl) | |
326 | }; | |
327 | ||
328 | #endif // wxUSE_DIRPICKERCTRL | |
329 | ||
330 | ||
331 | #if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL | |
332 | ||
333 | // ---------------------------------------------------------------------------- | |
334 | // wxFileDirPickerEvent: used by wxFilePickerCtrl and wxDirPickerCtrl only | |
335 | // ---------------------------------------------------------------------------- | |
336 | ||
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() | |
341 | ||
342 | class WXDLLIMPEXP_CORE wxFileDirPickerEvent : public wxCommandEvent | |
343 | { | |
344 | public: | |
345 | wxFileDirPickerEvent() {} | |
346 | wxFileDirPickerEvent(wxEventType type, wxObject *generator, int id, const wxString &path) | |
347 | : wxCommandEvent(type, id), | |
348 | m_path(path) | |
349 | { | |
350 | SetEventObject(generator); | |
351 | } | |
352 | ||
353 | wxString GetPath() const { return m_path; } | |
354 | void SetPath(const wxString &p) { m_path = p; } | |
355 | ||
258b2ca6 RD |
356 | // default copy ctor, assignment operator and dtor are ok |
357 | virtual wxEvent *Clone() const { return new wxFileDirPickerEvent(*this); } | |
358 | ||
ec376c8f VZ |
359 | private: |
360 | wxString m_path; | |
361 | ||
258b2ca6 | 362 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxFileDirPickerEvent) |
ec376c8f VZ |
363 | }; |
364 | ||
365 | // ---------------------------------------------------------------------------- | |
366 | // event types and macros | |
367 | // ---------------------------------------------------------------------------- | |
368 | ||
369 | typedef void (wxEvtHandler::*wxFileDirPickerEventFunction)(wxFileDirPickerEvent&); | |
370 | ||
371 | #define wxFileDirPickerEventHandler(func) \ | |
372 | (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxFileDirPickerEventFunction, &func) | |
373 | ||
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)) | |
378 | ||
379 | #ifdef _WX_DEFINE_DATE_EVENTS_ | |
380 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_FILEPICKER_CHANGED) | |
381 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DIRPICKER_CHANGED) | |
382 | ||
383 | IMPLEMENT_DYNAMIC_CLASS(wxFileDirPickerEvent, wxCommandEvent) | |
384 | #endif | |
385 | ||
386 | ||
387 | #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL | |
388 | ||
389 | #endif // _WX_FILEDIRPICKER_H_BASE_ | |
390 |