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