1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/filepicker.h
3 // Purpose: wxFilePickerCtrl, wxDirPickerCtrl base header
4 // Author: Francesco Montorsi
7 // Copyright: (c) Francesco Montorsi
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_FILEDIRPICKER_H_BASE_
12 #define _WX_FILEDIRPICKER_H_BASE_
16 #if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
18 #include "wx/pickerbase.h"
19 #include "wx/filename.h"
21 class WXDLLIMPEXP_FWD_CORE wxDialog
;
22 class WXDLLIMPEXP_FWD_CORE wxFileDirPickerEvent
;
24 extern WXDLLIMPEXP_DATA_CORE(const char) wxFilePickerWidgetLabel
[];
25 extern WXDLLIMPEXP_DATA_CORE(const char) wxFilePickerWidgetNameStr
[];
26 extern WXDLLIMPEXP_DATA_CORE(const char) wxFilePickerCtrlNameStr
[];
27 extern WXDLLIMPEXP_DATA_CORE(const char) wxFileSelectorPromptStr
[];
29 extern WXDLLIMPEXP_DATA_CORE(const char) wxDirPickerWidgetLabel
[];
30 extern WXDLLIMPEXP_DATA_CORE(const char) wxDirPickerWidgetNameStr
[];
31 extern WXDLLIMPEXP_DATA_CORE(const char) wxDirPickerCtrlNameStr
[];
32 extern WXDLLIMPEXP_DATA_CORE(const char) wxDirSelectorPromptStr
[];
34 // ----------------------------------------------------------------------------
35 // wxFileDirPickerEvent: used by wxFilePickerCtrl and wxDirPickerCtrl only
36 // ----------------------------------------------------------------------------
38 class WXDLLIMPEXP_CORE wxFileDirPickerEvent
: public wxCommandEvent
41 wxFileDirPickerEvent() {}
42 wxFileDirPickerEvent(wxEventType type
, wxObject
*generator
, int id
, const wxString
&path
)
43 : wxCommandEvent(type
, id
),
46 SetEventObject(generator
);
49 wxString
GetPath() const { return m_path
; }
50 void SetPath(const wxString
&p
) { m_path
= p
; }
52 // default copy ctor, assignment operator and dtor are ok
53 virtual wxEvent
*Clone() const { return new wxFileDirPickerEvent(*this); }
58 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxFileDirPickerEvent
)
61 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_FILEPICKER_CHANGED
, wxFileDirPickerEvent
);
62 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE
, wxEVT_DIRPICKER_CHANGED
, wxFileDirPickerEvent
);
64 // ----------------------------------------------------------------------------
65 // event types and macros
66 // ----------------------------------------------------------------------------
68 typedef void (wxEvtHandler::*wxFileDirPickerEventFunction
)(wxFileDirPickerEvent
&);
70 #define wxFileDirPickerEventHandler(func) \
71 wxEVENT_HANDLER_CAST(wxFileDirPickerEventFunction, func)
73 #define EVT_FILEPICKER_CHANGED(id, fn) \
74 wx__DECLARE_EVT1(wxEVT_FILEPICKER_CHANGED, id, wxFileDirPickerEventHandler(fn))
75 #define EVT_DIRPICKER_CHANGED(id, fn) \
76 wx__DECLARE_EVT1(wxEVT_DIRPICKER_CHANGED, id, wxFileDirPickerEventHandler(fn))
78 // ----------------------------------------------------------------------------
79 // wxFileDirPickerWidgetBase: a generic abstract interface which must be
80 // implemented by controls used by wxFileDirPickerCtrlBase
81 // ----------------------------------------------------------------------------
83 class WXDLLIMPEXP_CORE wxFileDirPickerWidgetBase
86 wxFileDirPickerWidgetBase() { }
87 virtual ~wxFileDirPickerWidgetBase() { }
89 // Path here is the name of the selected file or directory.
90 wxString
GetPath() const { return m_path
; }
91 virtual void SetPath(const wxString
&str
) { m_path
=str
; }
93 // Set the directory to open the file browse dialog at initially.
94 virtual void SetInitialDirectory(const wxString
& dir
) = 0;
96 // returns the picker widget cast to wxControl
97 virtual wxControl
*AsControl() = 0;
100 virtual void UpdateDialogPath(wxDialog
*) = 0;
101 virtual void UpdatePathFromDialog(wxDialog
*) = 0;
106 // Styles which must be supported by all controls implementing wxFileDirPickerWidgetBase
107 // NB: these styles must be defined to carefully-chosen values to
108 // avoid conflicts with wxButton's styles
110 #define wxFLP_OPEN 0x0400
111 #define wxFLP_SAVE 0x0800
112 #define wxFLP_OVERWRITE_PROMPT 0x1000
113 #define wxFLP_FILE_MUST_EXIST 0x2000
114 #define wxFLP_CHANGE_DIR 0x4000
115 #define wxFLP_SMALL wxPB_SMALL
117 // NOTE: wxMULTIPLE is not supported !
120 #define wxDIRP_DIR_MUST_EXIST 0x0008
121 #define wxDIRP_CHANGE_DIR 0x0010
122 #define wxDIRP_SMALL wxPB_SMALL
125 // map platform-dependent controls which implement the wxFileDirPickerWidgetBase
126 // under the name "wxFilePickerWidget" and "wxDirPickerWidget".
127 // NOTE: wxFileDirPickerCtrlBase will allocate a wx{File|Dir}PickerWidget and this
128 // requires that all classes being mapped as wx{File|Dir}PickerWidget have the
129 // same prototype for the contructor...
130 // since GTK >= 2.6, there is GtkFileButton
131 #if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
132 #include "wx/gtk/filepicker.h"
133 #define wxFilePickerWidget wxFileButton
134 #define wxDirPickerWidget wxDirButton
136 #include "wx/generic/filepickerg.h"
137 #define wxFilePickerWidget wxGenericFileButton
138 #define wxDirPickerWidget wxGenericDirButton
143 // ----------------------------------------------------------------------------
144 // wxFileDirPickerCtrlBase
145 // ----------------------------------------------------------------------------
147 class WXDLLIMPEXP_CORE wxFileDirPickerCtrlBase
: public wxPickerBase
150 wxFileDirPickerCtrlBase() {}
153 // NB: no default values since this function will never be used
154 // directly by the user and derived classes wouldn't use them
155 bool CreateBase(wxWindow
*parent
,
157 const wxString
& path
,
158 const wxString
&message
,
159 const wxString
&wildcard
,
163 const wxValidator
& validator
,
164 const wxString
& name
);
166 public: // public API
168 wxString
GetPath() const;
169 void SetPath(const wxString
&str
);
171 // Set the directory to open the file browse dialog at initially.
172 void SetInitialDirectory(const wxString
& dir
)
174 m_pickerIface
->SetInitialDirectory(dir
);
177 public: // internal functions
179 void UpdatePickerFromTextCtrl();
180 void UpdateTextCtrlFromPicker();
182 // event handler for our picker
183 void OnFileDirChange(wxFileDirPickerEvent
&);
185 // TRUE if any textctrl change should update the current working directory
186 virtual bool IsCwdToUpdate() const = 0;
188 // Returns the event type sent by this picker
189 virtual wxEventType
GetEventType() const = 0;
191 virtual void DoConnect( wxControl
*sender
, wxFileDirPickerCtrlBase
*eventSink
) = 0;
193 // Returns the filtered value currently placed in the text control (if present).
194 virtual wxString
GetTextCtrlValue() const = 0;
197 // creates the picker control
199 wxFileDirPickerWidgetBase
*CreatePicker(wxWindow
*parent
,
200 const wxString
& path
,
201 const wxString
& message
,
202 const wxString
& wildcard
) = 0;
206 // m_picker object as wxFileDirPickerWidgetBase interface
207 wxFileDirPickerWidgetBase
*m_pickerIface
;
210 #endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
213 #if wxUSE_FILEPICKERCTRL
215 // ----------------------------------------------------------------------------
216 // wxFilePickerCtrl: platform-independent class which embeds the
217 // platform-dependent wxFilePickerWidget and, if wxFLP_USE_TEXTCTRL style is
218 // used, a textctrl next to it.
219 // ----------------------------------------------------------------------------
221 #define wxFLP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
224 // GTK apps usually don't have a textctrl next to the picker
225 #define wxFLP_DEFAULT_STYLE (wxFLP_OPEN|wxFLP_FILE_MUST_EXIST)
227 #define wxFLP_DEFAULT_STYLE (wxFLP_USE_TEXTCTRL|wxFLP_OPEN|wxFLP_FILE_MUST_EXIST)
230 class WXDLLIMPEXP_CORE wxFilePickerCtrl
: public wxFileDirPickerCtrlBase
233 wxFilePickerCtrl() {}
235 wxFilePickerCtrl(wxWindow
*parent
,
237 const wxString
& path
= wxEmptyString
,
238 const wxString
& message
= wxFileSelectorPromptStr
,
239 const wxString
& wildcard
= wxFileSelectorDefaultWildcardStr
,
240 const wxPoint
& pos
= wxDefaultPosition
,
241 const wxSize
& size
= wxDefaultSize
,
242 long style
= wxFLP_DEFAULT_STYLE
,
243 const wxValidator
& validator
= wxDefaultValidator
,
244 const wxString
& name
= wxFilePickerCtrlNameStr
)
246 Create(parent
, id
, path
, message
, wildcard
, pos
, size
, style
,
250 bool Create(wxWindow
*parent
,
252 const wxString
& path
= wxEmptyString
,
253 const wxString
& message
= wxFileSelectorPromptStr
,
254 const wxString
& wildcard
= wxFileSelectorDefaultWildcardStr
,
255 const wxPoint
& pos
= wxDefaultPosition
,
256 const wxSize
& size
= wxDefaultSize
,
257 long style
= wxFLP_DEFAULT_STYLE
,
258 const wxValidator
& validator
= wxDefaultValidator
,
259 const wxString
& name
= wxFilePickerCtrlNameStr
);
261 void SetFileName(const wxFileName
&filename
)
262 { SetPath(filename
.GetFullPath()); }
264 wxFileName
GetFileName() const
265 { return wxFileName(GetPath()); }
269 // return the text control value in canonical form
270 wxString
GetTextCtrlValue() const;
272 bool IsCwdToUpdate() const
273 { return HasFlag(wxFLP_CHANGE_DIR
); }
275 wxEventType
GetEventType() const
276 { return wxEVT_FILEPICKER_CHANGED
; }
278 virtual void DoConnect( wxControl
*sender
, wxFileDirPickerCtrlBase
*eventSink
)
280 sender
->Connect( wxEVT_FILEPICKER_CHANGED
,
281 wxFileDirPickerEventHandler( wxFileDirPickerCtrlBase::OnFileDirChange
),
288 wxFileDirPickerWidgetBase
*CreatePicker(wxWindow
*parent
,
289 const wxString
& path
,
290 const wxString
& message
,
291 const wxString
& wildcard
)
293 return new wxFilePickerWidget(parent
, wxID_ANY
,
294 wxGetTranslation(wxFilePickerWidgetLabel
),
295 path
, message
, wildcard
,
296 wxDefaultPosition
, wxDefaultSize
,
297 GetPickerStyle(GetWindowStyle()));
300 // extracts the style for our picker from wxFileDirPickerCtrlBase's style
301 long GetPickerStyle(long style
) const
303 return style
& (wxFLP_OPEN
|
305 wxFLP_OVERWRITE_PROMPT
|
306 wxFLP_FILE_MUST_EXIST
|
313 DECLARE_DYNAMIC_CLASS(wxFilePickerCtrl
)
316 #endif // wxUSE_FILEPICKERCTRL
319 #if wxUSE_DIRPICKERCTRL
321 // ----------------------------------------------------------------------------
322 // wxDirPickerCtrl: platform-independent class which embeds the
323 // platform-dependent wxDirPickerWidget and eventually a textctrl
324 // (see wxDIRP_USE_TEXTCTRL) next to it.
325 // ----------------------------------------------------------------------------
327 #define wxDIRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
330 // GTK apps usually don't have a textctrl next to the picker
331 #define wxDIRP_DEFAULT_STYLE (wxDIRP_DIR_MUST_EXIST)
333 #define wxDIRP_DEFAULT_STYLE (wxDIRP_USE_TEXTCTRL|wxDIRP_DIR_MUST_EXIST)
336 class WXDLLIMPEXP_CORE wxDirPickerCtrl
: public wxFileDirPickerCtrlBase
341 wxDirPickerCtrl(wxWindow
*parent
, wxWindowID id
,
342 const wxString
& path
= wxEmptyString
,
343 const wxString
& message
= wxDirSelectorPromptStr
,
344 const wxPoint
& pos
= wxDefaultPosition
,
345 const wxSize
& size
= wxDefaultSize
,
346 long style
= wxDIRP_DEFAULT_STYLE
,
347 const wxValidator
& validator
= wxDefaultValidator
,
348 const wxString
& name
= wxDirPickerCtrlNameStr
)
350 Create(parent
, id
, path
, message
, pos
, size
, style
, validator
, name
);
353 bool Create(wxWindow
*parent
, wxWindowID id
,
354 const wxString
& path
= wxEmptyString
,
355 const wxString
& message
= wxDirSelectorPromptStr
,
356 const wxPoint
& pos
= wxDefaultPosition
,
357 const wxSize
& size
= wxDefaultSize
,
358 long style
= wxDIRP_DEFAULT_STYLE
,
359 const wxValidator
& validator
= wxDefaultValidator
,
360 const wxString
& name
= wxDirPickerCtrlNameStr
);
362 void SetDirName(const wxFileName
&dirname
)
363 { SetPath(dirname
.GetPath()); }
365 wxFileName
GetDirName() const
366 { return wxFileName::DirName(GetPath()); }
370 wxString
GetTextCtrlValue() const;
372 bool IsCwdToUpdate() const
373 { return HasFlag(wxDIRP_CHANGE_DIR
); }
375 wxEventType
GetEventType() const
376 { return wxEVT_DIRPICKER_CHANGED
; }
378 virtual void DoConnect( wxControl
*sender
, wxFileDirPickerCtrlBase
*eventSink
)
380 sender
->Connect( wxEVT_DIRPICKER_CHANGED
,
381 wxFileDirPickerEventHandler( wxFileDirPickerCtrlBase::OnFileDirChange
),
388 wxFileDirPickerWidgetBase
*CreatePicker(wxWindow
*parent
,
389 const wxString
& path
,
390 const wxString
& message
,
391 const wxString
& WXUNUSED(wildcard
))
393 return new wxDirPickerWidget(parent
, wxID_ANY
,
394 wxGetTranslation(wxDirPickerWidgetLabel
),
396 wxDefaultPosition
, wxDefaultSize
,
397 GetPickerStyle(GetWindowStyle()));
400 // extracts the style for our picker from wxFileDirPickerCtrlBase's style
401 long GetPickerStyle(long style
) const
403 return style
& (wxDIRP_DIR_MUST_EXIST
|
405 wxDIRP_USE_TEXTCTRL
|
410 DECLARE_DYNAMIC_CLASS(wxDirPickerCtrl
)
413 #endif // wxUSE_DIRPICKERCTRL
415 // old wxEVT_COMMAND_* constants
416 #define wxEVT_COMMAND_FILEPICKER_CHANGED wxEVT_FILEPICKER_CHANGED
417 #define wxEVT_COMMAND_DIRPICKER_CHANGED wxEVT_DIRPICKER_CHANGED
419 #endif // _WX_FILEDIRPICKER_H_BASE_