]>
Commit | Line | Data |
---|---|---|
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 | ||
17 | #if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL | |
18 | ||
19 | #include "wx/pickerbase.h" | |
20 | #include "wx/filename.h" | |
21 | ||
22 | class WXDLLIMPEXP_CORE wxDialog; | |
23 | class WXDLLIMPEXP_CORE wxFileDirPickerEvent; | |
24 | ||
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[]; | |
29 | ||
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[]; | |
34 | ||
35 | ||
36 | // ---------------------------------------------------------------------------- | |
37 | // wxFileDirPickerWidgetBase: a generic abstract interface which must be | |
38 | // implemented by controls used by wxFileDirPickerCtrlBase | |
39 | // ---------------------------------------------------------------------------- | |
40 | ||
41 | class WXDLLIMPEXP_CORE wxFileDirPickerWidgetBase | |
42 | { | |
43 | public: | |
44 | wxFileDirPickerWidgetBase() { } | |
45 | virtual ~wxFileDirPickerWidgetBase() { } | |
46 | ||
47 | wxString GetPath() const { return m_path; } | |
48 | virtual void SetPath(const wxString &str) { m_path=str; } | |
49 | ||
50 | protected: | |
51 | virtual void UpdateDialogPath(wxDialog *) = 0; | |
52 | virtual void UpdatePathFromDialog(wxDialog *) = 0; | |
53 | ||
54 | wxString m_path; | |
55 | }; | |
56 | ||
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 | |
60 | ||
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 | |
66 | ||
67 | // NOTE: wxMULTIPLE is not supported ! | |
68 | ||
69 | ||
70 | #define wxDIRP_DIR_MUST_EXIST 0x0008 | |
71 | #define wxDIRP_CHANGE_DIR 0x0010 | |
72 | ||
73 | ||
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 | |
83 | #else | |
84 | #include "wx/generic/filepickerg.h" | |
85 | #define wxFilePickerWidget wxGenericFileButton | |
86 | #define wxDirPickerWidget wxGenericDirButton | |
87 | #endif | |
88 | ||
89 | ||
90 | ||
91 | // ---------------------------------------------------------------------------- | |
92 | // wxFileDirPickerWidgetBase | |
93 | // ---------------------------------------------------------------------------- | |
94 | ||
95 | class WXDLLIMPEXP_CORE wxFileDirPickerCtrlBase : public wxPickerBase | |
96 | { | |
97 | public: | |
98 | wxFileDirPickerCtrlBase() : m_bIgnoreNextTextCtrlUpdate(false) {} | |
99 | virtual ~wxFileDirPickerCtrlBase() {} | |
100 | ||
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, | |
104 | wxWindowID id, | |
105 | const wxString& path, | |
106 | const wxString &message, | |
107 | const wxString &wildcard, | |
108 | const wxPoint& pos, | |
109 | const wxSize& size, | |
110 | long style, | |
111 | const wxValidator& validator, | |
112 | const wxString& name); | |
113 | ||
114 | public: // public API | |
115 | ||
116 | wxString GetPath() const | |
117 | { return ((wxFileDirPickerWidgetBase*)m_picker)->GetPath(); } | |
118 | void SetPath(const wxString &str); | |
119 | ||
120 | public: // internal functions | |
121 | ||
122 | void UpdatePickerFromTextCtrl(); | |
123 | void UpdateTextCtrlFromPicker(); | |
124 | ||
125 | // event handler for our picker | |
126 | void OnFileDirChange(wxFileDirPickerEvent &); | |
127 | ||
128 | virtual bool CreatePicker(wxWindow *parent, const wxString& path, | |
129 | const wxString& message, const wxString& wildcard) = 0; | |
130 | ||
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; | |
135 | ||
136 | // TRUE if any textctrl change should update the current working directory | |
137 | virtual bool IsCwdToUpdate() const = 0; | |
138 | ||
139 | // Returns the event type sent by this picker | |
140 | virtual wxEventType GetEventType() const = 0; | |
141 | ||
142 | protected: | |
143 | ||
144 | // true if the next UpdateTextCtrl() call is to ignore | |
145 | bool m_bIgnoreNextTextCtrlUpdate; | |
146 | }; | |
147 | ||
148 | #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL | |
149 | ||
150 | ||
151 | #if wxUSE_FILEPICKERCTRL | |
152 | ||
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 | // ---------------------------------------------------------------------------- | |
158 | ||
159 | #define wxFLP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL) | |
160 | ||
161 | #ifdef __WXGTK__ | |
162 | // GTK apps usually don't have a textctrl next to the picker | |
163 | #define wxFLP_DEFAULT_STYLE (wxFLP_OPEN) | |
164 | #else | |
165 | #define wxFLP_DEFAULT_STYLE (wxFLP_USE_TEXTCTRL|wxFLP_OPEN) | |
166 | #endif | |
167 | ||
168 | class WXDLLIMPEXP_CORE wxFilePickerCtrl : public wxFileDirPickerCtrlBase | |
169 | { | |
170 | public: | |
171 | wxFilePickerCtrl() {} | |
172 | virtual ~wxFilePickerCtrl() {} | |
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 | ||
220 | bool CheckPath(const wxString &path) const | |
221 | { | |
222 | return HasFlag(wxFLP_SAVE) || wxFileName::FileExists(path); | |
223 | } | |
224 | ||
225 | bool IsCwdToUpdate() const | |
226 | { return HasFlag(wxFLP_CHANGE_DIR); } | |
227 | ||
228 | wxEventType GetEventType() const | |
229 | { return wxEVT_COMMAND_FILEPICKER_CHANGED; } | |
230 | ||
231 | protected: | |
232 | // extracts the style for our picker from wxFileDirPickerCtrlBase's style | |
233 | long GetPickerStyle(long style) const | |
234 | { | |
235 | return (style & (wxFLP_OPEN|wxFLP_SAVE|wxFLP_OVERWRITE_PROMPT| | |
236 | wxFLP_FILE_MUST_EXIST|wxFLP_CHANGE_DIR)); | |
237 | } | |
238 | ||
239 | private: | |
240 | DECLARE_DYNAMIC_CLASS(wxFilePickerCtrl) | |
241 | }; | |
242 | ||
243 | #endif // wxUSE_FILEPICKERCTRL | |
244 | ||
245 | ||
246 | #if wxUSE_DIRPICKERCTRL | |
247 | ||
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 | // ---------------------------------------------------------------------------- | |
253 | ||
254 | #define wxDIRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL) | |
255 | ||
256 | #ifdef __WXGTK__ | |
257 | // GTK apps usually don't have a textctrl next to the picker | |
258 | #define wxDIRP_DEFAULT_STYLE 0 | |
259 | #else | |
260 | #define wxDIRP_DEFAULT_STYLE (wxDIRP_USE_TEXTCTRL) | |
261 | #endif | |
262 | ||
263 | class WXDLLIMPEXP_CORE wxDirPickerCtrl : public wxFileDirPickerCtrlBase | |
264 | { | |
265 | public: | |
266 | wxDirPickerCtrl() {} | |
267 | virtual ~wxDirPickerCtrl() {} | |
268 | ||
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); } | |
277 | ||
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); } | |
287 | ||
288 | ||
289 | public: // overrides | |
290 | ||
291 | bool CreatePicker(wxWindow *parent, const wxString& path, | |
292 | const wxString& message, const wxString& WXUNUSED(wildcard)) | |
293 | { | |
294 | m_picker = new wxDirPickerWidget(parent, wxID_ANY, wxDirPickerWidgetLabel, | |
295 | path, message, wxDefaultPosition, wxDefaultSize, | |
296 | GetPickerStyle(GetWindowStyle())); | |
297 | return true; | |
298 | } | |
299 | ||
300 | bool CheckPath(const wxString &path) const | |
301 | { if (HasFlag(wxDIRP_DIR_MUST_EXIST)) return wxFileName::DirExists(path); else return true; } | |
302 | ||
303 | bool IsCwdToUpdate() const | |
304 | { return HasFlag(wxDIRP_CHANGE_DIR); } | |
305 | ||
306 | wxEventType GetEventType() const | |
307 | { return wxEVT_COMMAND_DIRPICKER_CHANGED; } | |
308 | ||
309 | protected: | |
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)); } | |
313 | ||
314 | private: | |
315 | DECLARE_DYNAMIC_CLASS(wxDirPickerCtrl) | |
316 | }; | |
317 | ||
318 | #endif // wxUSE_DIRPICKERCTRL | |
319 | ||
320 | ||
321 | #if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL | |
322 | ||
323 | // ---------------------------------------------------------------------------- | |
324 | // wxFileDirPickerEvent: used by wxFilePickerCtrl and wxDirPickerCtrl only | |
325 | // ---------------------------------------------------------------------------- | |
326 | ||
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() | |
331 | ||
332 | class WXDLLIMPEXP_CORE wxFileDirPickerEvent : public wxCommandEvent | |
333 | { | |
334 | public: | |
335 | wxFileDirPickerEvent() {} | |
336 | wxFileDirPickerEvent(wxEventType type, wxObject *generator, int id, const wxString &path) | |
337 | : wxCommandEvent(type, id), | |
338 | m_path(path) | |
339 | { | |
340 | SetEventObject(generator); | |
341 | } | |
342 | ||
343 | wxString GetPath() const { return m_path; } | |
344 | void SetPath(const wxString &p) { m_path = p; } | |
345 | ||
346 | private: | |
347 | wxString m_path; | |
348 | ||
349 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxFileDirPickerEvent) | |
350 | }; | |
351 | ||
352 | // ---------------------------------------------------------------------------- | |
353 | // event types and macros | |
354 | // ---------------------------------------------------------------------------- | |
355 | ||
356 | typedef void (wxEvtHandler::*wxFileDirPickerEventFunction)(wxFileDirPickerEvent&); | |
357 | ||
358 | #define wxFileDirPickerEventHandler(func) \ | |
359 | (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxFileDirPickerEventFunction, &func) | |
360 | ||
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)) | |
365 | ||
366 | #ifdef _WX_DEFINE_DATE_EVENTS_ | |
367 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_FILEPICKER_CHANGED) | |
368 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DIRPICKER_CHANGED) | |
369 | ||
370 | IMPLEMENT_DYNAMIC_CLASS(wxFileDirPickerEvent, wxCommandEvent) | |
371 | #endif | |
372 | ||
373 | ||
374 | #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL | |
375 | ||
376 | #endif // _WX_FILEDIRPICKER_H_BASE_ | |
377 |