]>
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" |
28f15a1f | 20 | #include "wx/filename.h" |
ec376c8f | 21 | |
b5dbe15d VS |
22 | class WXDLLIMPEXP_FWD_CORE wxDialog; |
23 | class WXDLLIMPEXP_FWD_CORE wxFileDirPickerEvent; | |
ec376c8f | 24 | |
53a2db12 FM |
25 | extern WXDLLIMPEXP_DATA_CORE(const char) wxFilePickerWidgetLabel[]; |
26 | extern WXDLLIMPEXP_DATA_CORE(const char) wxFilePickerWidgetNameStr[]; | |
27 | extern WXDLLIMPEXP_DATA_CORE(const char) wxFilePickerCtrlNameStr[]; | |
28 | extern WXDLLIMPEXP_DATA_CORE(const char) wxFileSelectorPromptStr[]; | |
29 | ||
30 | extern WXDLLIMPEXP_DATA_CORE(const char) wxDirPickerWidgetLabel[]; | |
31 | extern WXDLLIMPEXP_DATA_CORE(const char) wxDirPickerWidgetNameStr[]; | |
32 | extern WXDLLIMPEXP_DATA_CORE(const char) wxDirPickerCtrlNameStr[]; | |
33 | extern WXDLLIMPEXP_DATA_CORE(const char) wxDirSelectorPromptStr[]; | |
ec376c8f | 34 | |
3c778901 VZ |
35 | // ---------------------------------------------------------------------------- |
36 | // wxFileDirPickerEvent: used by wxFilePickerCtrl and wxDirPickerCtrl only | |
37 | // ---------------------------------------------------------------------------- | |
38 | ||
39 | class WXDLLIMPEXP_CORE wxFileDirPickerEvent : public wxCommandEvent | |
40 | { | |
41 | public: | |
42 | wxFileDirPickerEvent() {} | |
43 | wxFileDirPickerEvent(wxEventType type, wxObject *generator, int id, const wxString &path) | |
44 | : wxCommandEvent(type, id), | |
45 | m_path(path) | |
46 | { | |
47 | SetEventObject(generator); | |
48 | } | |
49 | ||
50 | wxString GetPath() const { return m_path; } | |
51 | void SetPath(const wxString &p) { m_path = p; } | |
52 | ||
53 | // default copy ctor, assignment operator and dtor are ok | |
54 | virtual wxEvent *Clone() const { return new wxFileDirPickerEvent(*this); } | |
55 | ||
56 | private: | |
57 | wxString m_path; | |
58 | ||
59 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxFileDirPickerEvent) | |
60 | }; | |
61 | ||
ce7fe42e VZ |
62 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_FILEPICKER_CHANGED, wxFileDirPickerEvent ); |
63 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_DIRPICKER_CHANGED, wxFileDirPickerEvent ); | |
3c778901 VZ |
64 | |
65 | // ---------------------------------------------------------------------------- | |
66 | // event types and macros | |
67 | // ---------------------------------------------------------------------------- | |
68 | ||
69 | typedef void (wxEvtHandler::*wxFileDirPickerEventFunction)(wxFileDirPickerEvent&); | |
70 | ||
71 | #define wxFileDirPickerEventHandler(func) \ | |
72 | wxEVENT_HANDLER_CAST(wxFileDirPickerEventFunction, func) | |
73 | ||
74 | #define EVT_FILEPICKER_CHANGED(id, fn) \ | |
ce7fe42e | 75 | wx__DECLARE_EVT1(wxEVT_FILEPICKER_CHANGED, id, wxFileDirPickerEventHandler(fn)) |
3c778901 | 76 | #define EVT_DIRPICKER_CHANGED(id, fn) \ |
ce7fe42e | 77 | wx__DECLARE_EVT1(wxEVT_DIRPICKER_CHANGED, id, wxFileDirPickerEventHandler(fn)) |
ec376c8f VZ |
78 | |
79 | // ---------------------------------------------------------------------------- | |
80 | // wxFileDirPickerWidgetBase: a generic abstract interface which must be | |
81 | // implemented by controls used by wxFileDirPickerCtrlBase | |
82 | // ---------------------------------------------------------------------------- | |
83 | ||
84 | class WXDLLIMPEXP_CORE wxFileDirPickerWidgetBase | |
85 | { | |
86 | public: | |
87 | wxFileDirPickerWidgetBase() { } | |
88 | virtual ~wxFileDirPickerWidgetBase() { } | |
89 | ||
75cb911c | 90 | // Path here is the name of the selected file or directory. |
ec376c8f | 91 | wxString GetPath() const { return m_path; } |
556151f5 | 92 | virtual void SetPath(const wxString &str) { m_path=str; } |
ec376c8f | 93 | |
75cb911c VZ |
94 | // Set the directory to open the file browse dialog at initially. |
95 | virtual void SetInitialDirectory(const wxString& dir) = 0; | |
96 | ||
af6ad984 VS |
97 | // returns the picker widget cast to wxControl |
98 | virtual wxControl *AsControl() = 0; | |
99 | ||
ec376c8f | 100 | protected: |
556151f5 MW |
101 | virtual void UpdateDialogPath(wxDialog *) = 0; |
102 | virtual void UpdatePathFromDialog(wxDialog *) = 0; | |
ec376c8f VZ |
103 | |
104 | wxString m_path; | |
105 | }; | |
106 | ||
107 | // Styles which must be supported by all controls implementing wxFileDirPickerWidgetBase | |
108 | // NB: these styles must be defined to carefully-chosen values to | |
109 | // avoid conflicts with wxButton's styles | |
110 | ||
a7a11b21 WS |
111 | #define wxFLP_OPEN 0x0400 |
112 | #define wxFLP_SAVE 0x0800 | |
113 | #define wxFLP_OVERWRITE_PROMPT 0x1000 | |
114 | #define wxFLP_FILE_MUST_EXIST 0x2000 | |
115 | #define wxFLP_CHANGE_DIR 0x4000 | |
75bc8b34 | 116 | #define wxFLP_SMALL wxPB_SMALL |
ec376c8f VZ |
117 | |
118 | // NOTE: wxMULTIPLE is not supported ! | |
119 | ||
120 | ||
121 | #define wxDIRP_DIR_MUST_EXIST 0x0008 | |
122 | #define wxDIRP_CHANGE_DIR 0x0010 | |
75bc8b34 | 123 | #define wxDIRP_SMALL wxPB_SMALL |
ec376c8f VZ |
124 | |
125 | ||
126 | // map platform-dependent controls which implement the wxFileDirPickerWidgetBase | |
127 | // under the name "wxFilePickerWidget" and "wxDirPickerWidget". | |
128 | // NOTE: wxFileDirPickerCtrlBase will allocate a wx{File|Dir}PickerWidget and this | |
129 | // requires that all classes being mapped as wx{File|Dir}PickerWidget have the | |
130 | // same prototype for the contructor... | |
82540105 | 131 | // since GTK >= 2.6, there is GtkFileButton |
4e621d24 | 132 | #if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__) |
ec376c8f VZ |
133 | #include "wx/gtk/filepicker.h" |
134 | #define wxFilePickerWidget wxFileButton | |
135 | #define wxDirPickerWidget wxDirButton | |
136 | #else | |
137 | #include "wx/generic/filepickerg.h" | |
138 | #define wxFilePickerWidget wxGenericFileButton | |
139 | #define wxDirPickerWidget wxGenericDirButton | |
140 | #endif | |
141 | ||
142 | ||
143 | ||
144 | // ---------------------------------------------------------------------------- | |
af6ad984 | 145 | // wxFileDirPickerCtrlBase |
ec376c8f VZ |
146 | // ---------------------------------------------------------------------------- |
147 | ||
148 | class WXDLLIMPEXP_CORE wxFileDirPickerCtrlBase : public wxPickerBase | |
149 | { | |
150 | public: | |
44b72116 | 151 | wxFileDirPickerCtrlBase() {} |
ec376c8f | 152 | |
af6ad984 | 153 | protected: |
ec376c8f VZ |
154 | // NB: no default values since this function will never be used |
155 | // directly by the user and derived classes wouldn't use them | |
156 | bool CreateBase(wxWindow *parent, | |
157 | wxWindowID id, | |
158 | const wxString& path, | |
159 | const wxString &message, | |
160 | const wxString &wildcard, | |
161 | const wxPoint& pos, | |
162 | const wxSize& size, | |
163 | long style, | |
164 | const wxValidator& validator, | |
165 | const wxString& name); | |
166 | ||
167 | public: // public API | |
168 | ||
af6ad984 | 169 | wxString GetPath() const; |
ec376c8f VZ |
170 | void SetPath(const wxString &str); |
171 | ||
75cb911c VZ |
172 | // Set the directory to open the file browse dialog at initially. |
173 | void SetInitialDirectory(const wxString& dir) | |
174 | { | |
175 | m_pickerIface->SetInitialDirectory(dir); | |
176 | } | |
177 | ||
ec376c8f VZ |
178 | public: // internal functions |
179 | ||
180 | void UpdatePickerFromTextCtrl(); | |
181 | void UpdateTextCtrlFromPicker(); | |
182 | ||
183 | // event handler for our picker | |
184 | void OnFileDirChange(wxFileDirPickerEvent &); | |
185 | ||
ec376c8f VZ |
186 | // TRUE if any textctrl change should update the current working directory |
187 | virtual bool IsCwdToUpdate() const = 0; | |
188 | ||
189 | // Returns the event type sent by this picker | |
190 | virtual wxEventType GetEventType() const = 0; | |
191 | ||
3c778901 VZ |
192 | virtual void DoConnect( wxControl *sender, wxFileDirPickerCtrlBase *eventSink ) = 0; |
193 | ||
58772e49 VZ |
194 | // Returns the filtered value currently placed in the text control (if present). |
195 | virtual wxString GetTextCtrlValue() const = 0; | |
196 | ||
af6ad984 VS |
197 | protected: |
198 | // creates the picker control | |
199 | virtual | |
200 | wxFileDirPickerWidgetBase *CreatePicker(wxWindow *parent, | |
201 | const wxString& path, | |
202 | const wxString& message, | |
203 | const wxString& wildcard) = 0; | |
204 | ||
ec376c8f VZ |
205 | protected: |
206 | ||
af6ad984 VS |
207 | // m_picker object as wxFileDirPickerWidgetBase interface |
208 | wxFileDirPickerWidgetBase *m_pickerIface; | |
ec376c8f VZ |
209 | }; |
210 | ||
211 | #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL | |
212 | ||
213 | ||
214 | #if wxUSE_FILEPICKERCTRL | |
215 | ||
216 | // ---------------------------------------------------------------------------- | |
217 | // wxFilePickerCtrl: platform-independent class which embeds the | |
218 | // platform-dependent wxFilePickerWidget and, if wxFLP_USE_TEXTCTRL style is | |
219 | // used, a textctrl next to it. | |
220 | // ---------------------------------------------------------------------------- | |
221 | ||
556151f5 | 222 | #define wxFLP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL) |
ec376c8f VZ |
223 | |
224 | #ifdef __WXGTK__ | |
225 | // GTK apps usually don't have a textctrl next to the picker | |
58772e49 | 226 | #define wxFLP_DEFAULT_STYLE (wxFLP_OPEN|wxFLP_FILE_MUST_EXIST) |
ec376c8f | 227 | #else |
58772e49 | 228 | #define wxFLP_DEFAULT_STYLE (wxFLP_USE_TEXTCTRL|wxFLP_OPEN|wxFLP_FILE_MUST_EXIST) |
ec376c8f VZ |
229 | #endif |
230 | ||
231 | class WXDLLIMPEXP_CORE wxFilePickerCtrl : public wxFileDirPickerCtrlBase | |
232 | { | |
233 | public: | |
234 | wxFilePickerCtrl() {} | |
ec376c8f VZ |
235 | |
236 | wxFilePickerCtrl(wxWindow *parent, | |
237 | wxWindowID id, | |
238 | const wxString& path = wxEmptyString, | |
239 | const wxString& message = wxFileSelectorPromptStr, | |
240 | const wxString& wildcard = wxFileSelectorDefaultWildcardStr, | |
241 | const wxPoint& pos = wxDefaultPosition, | |
242 | const wxSize& size = wxDefaultSize, | |
243 | long style = wxFLP_DEFAULT_STYLE, | |
244 | const wxValidator& validator = wxDefaultValidator, | |
245 | const wxString& name = wxFilePickerCtrlNameStr) | |
246 | { | |
247 | Create(parent, id, path, message, wildcard, pos, size, style, | |
248 | validator, name); | |
249 | } | |
250 | ||
251 | bool Create(wxWindow *parent, | |
252 | wxWindowID id, | |
253 | const wxString& path = wxEmptyString, | |
254 | const wxString& message = wxFileSelectorPromptStr, | |
255 | const wxString& wildcard = wxFileSelectorDefaultWildcardStr, | |
256 | const wxPoint& pos = wxDefaultPosition, | |
257 | const wxSize& size = wxDefaultSize, | |
258 | long style = wxFLP_DEFAULT_STYLE, | |
259 | const wxValidator& validator = wxDefaultValidator, | |
ea7ff9ad | 260 | const wxString& name = wxFilePickerCtrlNameStr); |
ec376c8f | 261 | |
28f15a1f VZ |
262 | void SetFileName(const wxFileName &filename) |
263 | { SetPath(filename.GetFullPath()); } | |
264 | ||
265 | wxFileName GetFileName() const | |
266 | { return wxFileName(GetPath()); } | |
ec376c8f VZ |
267 | |
268 | public: // overrides | |
269 | ||
58772e49 VZ |
270 | // return the text control value in canonical form |
271 | wxString GetTextCtrlValue() const; | |
ec376c8f VZ |
272 | |
273 | bool IsCwdToUpdate() const | |
274 | { return HasFlag(wxFLP_CHANGE_DIR); } | |
275 | ||
276 | wxEventType GetEventType() const | |
ce7fe42e | 277 | { return wxEVT_FILEPICKER_CHANGED; } |
ec376c8f | 278 | |
3c778901 VZ |
279 | virtual void DoConnect( wxControl *sender, wxFileDirPickerCtrlBase *eventSink ) |
280 | { | |
ce7fe42e | 281 | sender->Connect( wxEVT_FILEPICKER_CHANGED, |
3c778901 VZ |
282 | wxFileDirPickerEventHandler( wxFileDirPickerCtrlBase::OnFileDirChange ), |
283 | NULL, eventSink ); | |
284 | } | |
285 | ||
286 | ||
c757b5fe | 287 | protected: |
5ffd2ea0 | 288 | virtual |
af6ad984 VS |
289 | wxFileDirPickerWidgetBase *CreatePicker(wxWindow *parent, |
290 | const wxString& path, | |
291 | const wxString& message, | |
292 | const wxString& wildcard) | |
293 | { | |
294 | return new wxFilePickerWidget(parent, wxID_ANY, | |
174e8f45 | 295 | wxGetTranslation(wxFilePickerWidgetLabel), |
af6ad984 VS |
296 | path, message, wildcard, |
297 | wxDefaultPosition, wxDefaultSize, | |
298 | GetPickerStyle(GetWindowStyle())); | |
299 | } | |
300 | ||
c757b5fe PC |
301 | // extracts the style for our picker from wxFileDirPickerCtrlBase's style |
302 | long GetPickerStyle(long style) const | |
303 | { | |
75bc8b34 VZ |
304 | return style & (wxFLP_OPEN | |
305 | wxFLP_SAVE | | |
306 | wxFLP_OVERWRITE_PROMPT | | |
307 | wxFLP_FILE_MUST_EXIST | | |
308 | wxFLP_CHANGE_DIR | | |
309 | wxFLP_USE_TEXTCTRL | | |
310 | wxFLP_SMALL); | |
c757b5fe PC |
311 | } |
312 | ||
ec376c8f VZ |
313 | private: |
314 | DECLARE_DYNAMIC_CLASS(wxFilePickerCtrl) | |
315 | }; | |
316 | ||
317 | #endif // wxUSE_FILEPICKERCTRL | |
318 | ||
319 | ||
320 | #if wxUSE_DIRPICKERCTRL | |
321 | ||
322 | // ---------------------------------------------------------------------------- | |
323 | // wxDirPickerCtrl: platform-independent class which embeds the | |
324 | // platform-dependent wxDirPickerWidget and eventually a textctrl | |
325 | // (see wxDIRP_USE_TEXTCTRL) next to it. | |
326 | // ---------------------------------------------------------------------------- | |
327 | ||
556151f5 | 328 | #define wxDIRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL) |
ec376c8f VZ |
329 | |
330 | #ifdef __WXGTK__ | |
331 | // GTK apps usually don't have a textctrl next to the picker | |
58772e49 | 332 | #define wxDIRP_DEFAULT_STYLE (wxDIRP_DIR_MUST_EXIST) |
ec376c8f | 333 | #else |
58772e49 | 334 | #define wxDIRP_DEFAULT_STYLE (wxDIRP_USE_TEXTCTRL|wxDIRP_DIR_MUST_EXIST) |
ec376c8f VZ |
335 | #endif |
336 | ||
337 | class WXDLLIMPEXP_CORE wxDirPickerCtrl : public wxFileDirPickerCtrlBase | |
338 | { | |
339 | public: | |
340 | wxDirPickerCtrl() {} | |
ec376c8f VZ |
341 | |
342 | wxDirPickerCtrl(wxWindow *parent, wxWindowID id, | |
58772e49 VZ |
343 | const wxString& path = wxEmptyString, |
344 | const wxString& message = wxDirSelectorPromptStr, | |
345 | const wxPoint& pos = wxDefaultPosition, | |
346 | const wxSize& size = wxDefaultSize, | |
347 | long style = wxDIRP_DEFAULT_STYLE, | |
348 | const wxValidator& validator = wxDefaultValidator, | |
349 | const wxString& name = wxDirPickerCtrlNameStr) | |
350 | { | |
351 | Create(parent, id, path, message, pos, size, style, validator, name); | |
352 | } | |
ec376c8f VZ |
353 | |
354 | bool Create(wxWindow *parent, wxWindowID id, | |
58772e49 VZ |
355 | const wxString& path = wxEmptyString, |
356 | const wxString& message = wxDirSelectorPromptStr, | |
357 | const wxPoint& pos = wxDefaultPosition, | |
358 | const wxSize& size = wxDefaultSize, | |
359 | long style = wxDIRP_DEFAULT_STYLE, | |
360 | const wxValidator& validator = wxDefaultValidator, | |
ea7ff9ad | 361 | const wxString& name = wxDirPickerCtrlNameStr); |
ec376c8f | 362 | |
28f15a1f VZ |
363 | void SetDirName(const wxFileName &dirname) |
364 | { SetPath(dirname.GetPath()); } | |
365 | ||
366 | wxFileName GetDirName() const | |
367 | { return wxFileName::DirName(GetPath()); } | |
ec376c8f VZ |
368 | |
369 | public: // overrides | |
370 | ||
58772e49 | 371 | wxString GetTextCtrlValue() const; |
ec376c8f VZ |
372 | |
373 | bool IsCwdToUpdate() const | |
374 | { return HasFlag(wxDIRP_CHANGE_DIR); } | |
375 | ||
376 | wxEventType GetEventType() const | |
ce7fe42e | 377 | { return wxEVT_DIRPICKER_CHANGED; } |
ec376c8f | 378 | |
3c778901 VZ |
379 | virtual void DoConnect( wxControl *sender, wxFileDirPickerCtrlBase *eventSink ) |
380 | { | |
ce7fe42e | 381 | sender->Connect( wxEVT_DIRPICKER_CHANGED, |
3c778901 VZ |
382 | wxFileDirPickerEventHandler( wxFileDirPickerCtrlBase::OnFileDirChange ), |
383 | NULL, eventSink ); | |
384 | } | |
385 | ||
386 | ||
c757b5fe | 387 | protected: |
5ffd2ea0 | 388 | virtual |
af6ad984 VS |
389 | wxFileDirPickerWidgetBase *CreatePicker(wxWindow *parent, |
390 | const wxString& path, | |
391 | const wxString& message, | |
392 | const wxString& WXUNUSED(wildcard)) | |
393 | { | |
174e8f45 VZ |
394 | return new wxDirPickerWidget(parent, wxID_ANY, |
395 | wxGetTranslation(wxDirPickerWidgetLabel), | |
af6ad984 VS |
396 | path, message, |
397 | wxDefaultPosition, wxDefaultSize, | |
398 | GetPickerStyle(GetWindowStyle())); | |
399 | } | |
400 | ||
c757b5fe PC |
401 | // extracts the style for our picker from wxFileDirPickerCtrlBase's style |
402 | long GetPickerStyle(long style) const | |
75bc8b34 VZ |
403 | { |
404 | return style & (wxDIRP_DIR_MUST_EXIST | | |
405 | wxDIRP_CHANGE_DIR | | |
406 | wxDIRP_USE_TEXTCTRL | | |
407 | wxDIRP_SMALL); | |
408 | } | |
c757b5fe | 409 | |
ec376c8f VZ |
410 | private: |
411 | DECLARE_DYNAMIC_CLASS(wxDirPickerCtrl) | |
412 | }; | |
413 | ||
414 | #endif // wxUSE_DIRPICKERCTRL | |
415 | ||
ce7fe42e VZ |
416 | // old wxEVT_COMMAND_* constants |
417 | #define wxEVT_COMMAND_FILEPICKER_CHANGED wxEVT_FILEPICKER_CHANGED | |
418 | #define wxEVT_COMMAND_DIRPICKER_CHANGED wxEVT_DIRPICKER_CHANGED | |
419 | ||
ec376c8f VZ |
420 | #endif // _WX_FILEDIRPICKER_H_BASE_ |
421 |