]> git.saurik.com Git - wxWidgets.git/blame - include/wx/filepicker.h
Add new components to wxOS2 builds.
[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
17
18#if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
19
20#include "wx/control.h"
21#include "wx/pickerbase.h"
22#include "wx/filedlg.h"
23#include "wx/filename.h"
24
25
26class WXDLLIMPEXP_CORE wxFileDirPickerEvent;
27
28extern WXDLLEXPORT_DATA(const wxChar) wxFilePickerWidgetLabel[];
29extern WXDLLEXPORT_DATA(const wxChar) wxFilePickerWidgetNameStr[];
30extern WXDLLEXPORT_DATA(const wxChar) wxFilePickerCtrlNameStr[];
31extern WXDLLEXPORT_DATA(const wxChar) wxFileSelectorPromptStr[];
32
33extern WXDLLEXPORT_DATA(const wxChar) wxDirPickerWidgetLabel[];
34extern WXDLLEXPORT_DATA(const wxChar) wxDirPickerWidgetNameStr[];
35extern WXDLLEXPORT_DATA(const wxChar) wxDirPickerCtrlNameStr[];
36extern WXDLLEXPORT_DATA(const wxChar) wxDirSelectorPromptStr[];
37
38
39// ----------------------------------------------------------------------------
40// wxFileDirPickerWidgetBase: a generic abstract interface which must be
41// implemented by controls used by wxFileDirPickerCtrlBase
42// ----------------------------------------------------------------------------
43
44class WXDLLIMPEXP_CORE wxFileDirPickerWidgetBase
45{
46public:
47 wxFileDirPickerWidgetBase() { }
48 virtual ~wxFileDirPickerWidgetBase() { }
49
50 wxString GetPath() const { return m_path; }
51 void SetPath(const wxString &str) { m_path=str; UpdateDialogPath(); }
52
53protected:
54 virtual void UpdateDialogPath() = 0;
55 virtual void UpdatePathFromDialog() = 0;
56
57 wxString m_path;
58};
59
60// Styles which must be supported by all controls implementing wxFileDirPickerWidgetBase
61// NB: these styles must be defined to carefully-chosen values to
62// avoid conflicts with wxButton's styles
63
64#define wxFLP_OPEN 0x0200
65#define wxFLP_SAVE 0x0400
66#define wxFLP_OVERWRITE_PROMPT 0x0800
67#define wxFLP_FILE_MUST_EXIST 0x1000
68#define wxFLP_CHANGE_DIR 0x2000
69
70// NOTE: wxMULTIPLE is not supported !
71
72
73#define wxDIRP_DIR_MUST_EXIST 0x0008
74#define wxDIRP_CHANGE_DIR 0x0010
75
76
77// map platform-dependent controls which implement the wxFileDirPickerWidgetBase
78// under the name "wxFilePickerWidget" and "wxDirPickerWidget".
79// NOTE: wxFileDirPickerCtrlBase will allocate a wx{File|Dir}PickerWidget and this
80// requires that all classes being mapped as wx{File|Dir}PickerWidget have the
81// same prototype for the contructor...
5b34e141 82#if defined(__WXGTK26__) // since GTK >= 2.6, there is GtkFileButton
ec376c8f
VZ
83 #include "wx/gtk/filepicker.h"
84 #define wxFilePickerWidget wxFileButton
85 #define wxDirPickerWidget wxDirButton
86#else
87 #include "wx/generic/filepickerg.h"
88 #define wxFilePickerWidget wxGenericFileButton
89 #define wxDirPickerWidget wxGenericDirButton
90#endif
91
92
93
94// ----------------------------------------------------------------------------
95// wxFileDirPickerWidgetBase
96// ----------------------------------------------------------------------------
97
98class WXDLLIMPEXP_CORE wxFileDirPickerCtrlBase : public wxPickerBase
99{
100public:
101 wxFileDirPickerCtrlBase() : m_bIgnoreNextTextCtrlUpdate(false) {}
102 virtual ~wxFileDirPickerCtrlBase() {}
103
104 // NB: no default values since this function will never be used
105 // directly by the user and derived classes wouldn't use them
106 bool CreateBase(wxWindow *parent,
107 wxWindowID id,
108 const wxString& path,
109 const wxString &message,
110 const wxString &wildcard,
111 const wxPoint& pos,
112 const wxSize& size,
113 long style,
114 const wxValidator& validator,
115 const wxString& name);
116
117public: // public API
118
119 wxString GetPath() const
120 { return ((wxFileDirPickerWidgetBase*)m_picker)->GetPath(); }
121 void SetPath(const wxString &str);
122
123public: // internal functions
124
125 void UpdatePickerFromTextCtrl();
126 void UpdateTextCtrlFromPicker();
127
128 // event handler for our picker
129 void OnFileDirChange(wxFileDirPickerEvent &);
130
131 virtual bool CreatePicker(wxWindow *parent, const wxString& path,
132 const wxString& message, const wxString& wildcard) = 0;
133
134 // Returns TRUE if the current path is a valid one
135 // (i.e. a valid file for a wxFilePickerWidget or a valid
136 // folder for a wxDirPickerWidget).
137 virtual bool CheckPath(const wxString &str) const = 0;
138
139 // TRUE if any textctrl change should update the current working directory
140 virtual bool IsCwdToUpdate() const = 0;
141
142 // Returns the event type sent by this picker
143 virtual wxEventType GetEventType() const = 0;
144
145protected:
146
147 // true if the next UpdateTextCtrl() call is to ignore
148 bool m_bIgnoreNextTextCtrlUpdate;
149};
150
151#endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
152
153
154#if wxUSE_FILEPICKERCTRL
155
156// ----------------------------------------------------------------------------
157// wxFilePickerCtrl: platform-independent class which embeds the
158// platform-dependent wxFilePickerWidget and, if wxFLP_USE_TEXTCTRL style is
159// used, a textctrl next to it.
160// ----------------------------------------------------------------------------
161
162#define wxFLP_USE_TEXTCTRL wxPB_USE_TEXTCTRL
163
164#ifdef __WXGTK__
165 // GTK apps usually don't have a textctrl next to the picker
166 #define wxFLP_DEFAULT_STYLE wxFLP_OPEN
167#else
168 #define wxFLP_DEFAULT_STYLE wxFLP_USE_TEXTCTRL|wxFLP_OPEN
169#endif
170
171class WXDLLIMPEXP_CORE wxFilePickerCtrl : public wxFileDirPickerCtrlBase
172{
173public:
174 wxFilePickerCtrl() {}
175 virtual ~wxFilePickerCtrl() {}
176
177 wxFilePickerCtrl(wxWindow *parent,
178 wxWindowID id,
179 const wxString& path = wxEmptyString,
180 const wxString& message = wxFileSelectorPromptStr,
181 const wxString& wildcard = wxFileSelectorDefaultWildcardStr,
182 const wxPoint& pos = wxDefaultPosition,
183 const wxSize& size = wxDefaultSize,
184 long style = wxFLP_DEFAULT_STYLE,
185 const wxValidator& validator = wxDefaultValidator,
186 const wxString& name = wxFilePickerCtrlNameStr)
187 {
188 Create(parent, id, path, message, wildcard, pos, size, style,
189 validator, name);
190 }
191
192 bool Create(wxWindow *parent,
193 wxWindowID id,
194 const wxString& path = wxEmptyString,
195 const wxString& message = wxFileSelectorPromptStr,
196 const wxString& wildcard = wxFileSelectorDefaultWildcardStr,
197 const wxPoint& pos = wxDefaultPosition,
198 const wxSize& size = wxDefaultSize,
199 long style = wxFLP_DEFAULT_STYLE,
200 const wxValidator& validator = wxDefaultValidator,
201 const wxString& name = wxFilePickerCtrlNameStr)
202 {
203 return wxFileDirPickerCtrlBase::CreateBase(parent, id, path,
204 message, wildcard,
205 pos, size, style,
206 validator, name);
207 }
208
209
210public: // overrides
211
212 bool CreatePicker(wxWindow *parent, const wxString& path,
213 const wxString& message, const wxString& wildcard)
214 {
215 m_picker = new wxFilePickerWidget(parent, wxID_ANY,
216 wxFilePickerWidgetLabel,
217 path, message, wildcard,
218 wxDefaultPosition, wxDefaultSize,
219 GetPickerStyle(GetWindowStyle()));
220 return true;
221 }
222
223 // extracts the style for our picker from wxFileDirPickerCtrlBase's style
224 long GetPickerStyle(long style) const
225 {
226 return (style & (wxFLP_OPEN|wxFLP_SAVE|wxFLP_OVERWRITE_PROMPT|
227 wxFLP_FILE_MUST_EXIST|wxFLP_CHANGE_DIR));
228 }
229
230 bool CheckPath(const wxString &path) const
231 {
232 return HasFlag(wxFLP_SAVE) || wxFileName::FileExists(path);
233 }
234
235 bool IsCwdToUpdate() const
236 { return HasFlag(wxFLP_CHANGE_DIR); }
237
238 wxEventType GetEventType() const
239 { return wxEVT_COMMAND_FILEPICKER_CHANGED; }
240
241private:
242 DECLARE_DYNAMIC_CLASS(wxFilePickerCtrl)
243};
244
245#endif // wxUSE_FILEPICKERCTRL
246
247
248#if wxUSE_DIRPICKERCTRL
249
250// ----------------------------------------------------------------------------
251// wxDirPickerCtrl: platform-independent class which embeds the
252// platform-dependent wxDirPickerWidget and eventually a textctrl
253// (see wxDIRP_USE_TEXTCTRL) next to it.
254// ----------------------------------------------------------------------------
255
256#define wxDIRP_USE_TEXTCTRL wxPB_USE_TEXTCTRL
257
258#ifdef __WXGTK__
259 // GTK apps usually don't have a textctrl next to the picker
260 #define wxDIRP_DEFAULT_STYLE 0
261#else
262 #define wxDIRP_DEFAULT_STYLE wxDIRP_USE_TEXTCTRL
263#endif
264
265class WXDLLIMPEXP_CORE wxDirPickerCtrl : public wxFileDirPickerCtrlBase
266{
267public:
268 wxDirPickerCtrl() {}
269 virtual ~wxDirPickerCtrl() {}
270
271 wxDirPickerCtrl(wxWindow *parent, wxWindowID id,
272 const wxString& path = wxEmptyString,
273 const wxString& message = wxDirSelectorPromptStr,
274 const wxPoint& pos = wxDefaultPosition,
275 const wxSize& size = wxDefaultSize, long style = wxDIRP_DEFAULT_STYLE,
276 const wxValidator& validator = wxDefaultValidator,
277 const wxString& name = wxDirPickerCtrlNameStr)
278 { Create(parent, id, path, message, pos, size, style, validator, name); }
279
280 bool Create(wxWindow *parent, wxWindowID id,
281 const wxString& path = wxEmptyString,
282 const wxString& message = wxDirSelectorPromptStr,
283 const wxPoint& pos = wxDefaultPosition,
284 const wxSize& size = wxDefaultSize, long style = wxDIRP_DEFAULT_STYLE,
285 const wxValidator& validator = wxDefaultValidator,
286 const wxString& name = wxDirPickerCtrlNameStr)
287 { return wxFileDirPickerCtrlBase::CreateBase(parent, id, path, message, wxEmptyString,
288 pos, size, style, validator, name); }
289
290
291public: // overrides
292
293 bool CreatePicker(wxWindow *parent, const wxString& path,
294 const wxString& message, const wxString& WXUNUSED(wildcard))
295 {
296 m_picker = new wxDirPickerWidget(parent, wxID_ANY, wxDirPickerWidgetLabel,
297 path, message, wxDefaultPosition, wxDefaultSize,
298 GetPickerStyle(GetWindowStyle()));
299 return true;
300 }
301
302 // extracts the style for our picker from wxFileDirPickerCtrlBase's style
303 long GetPickerStyle(long style) const
304 { return (style & (wxDIRP_DIR_MUST_EXIST|wxDIRP_CHANGE_DIR)); }
305
306 bool CheckPath(const wxString &path) const
307 { if (HasFlag(wxDIRP_DIR_MUST_EXIST)) return wxFileName::DirExists(path); else return true; }
308
309 bool IsCwdToUpdate() const
310 { return HasFlag(wxDIRP_CHANGE_DIR); }
311
312 wxEventType GetEventType() const
313 { return wxEVT_COMMAND_DIRPICKER_CHANGED; }
314
315private:
316 DECLARE_DYNAMIC_CLASS(wxDirPickerCtrl)
317};
318
319#endif // wxUSE_DIRPICKERCTRL
320
321
322#if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
323
324// ----------------------------------------------------------------------------
325// wxFileDirPickerEvent: used by wxFilePickerCtrl and wxDirPickerCtrl only
326// ----------------------------------------------------------------------------
327
328BEGIN_DECLARE_EVENT_TYPES()
329 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE, wxEVT_COMMAND_FILEPICKER_CHANGED, 1102)
330 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE, wxEVT_COMMAND_DIRPICKER_CHANGED, 1103)
331END_DECLARE_EVENT_TYPES()
332
333class WXDLLIMPEXP_CORE wxFileDirPickerEvent : public wxCommandEvent
334{
335public:
336 wxFileDirPickerEvent() {}
337 wxFileDirPickerEvent(wxEventType type, wxObject *generator, int id, const wxString &path)
338 : wxCommandEvent(type, id),
339 m_path(path)
340 {
341 SetEventObject(generator);
342 }
343
344 wxString GetPath() const { return m_path; }
345 void SetPath(const wxString &p) { m_path = p; }
346
347private:
348 wxString m_path;
349
350 DECLARE_DYNAMIC_CLASS_NO_COPY(wxFileDirPickerEvent)
351};
352
353// ----------------------------------------------------------------------------
354// event types and macros
355// ----------------------------------------------------------------------------
356
357typedef void (wxEvtHandler::*wxFileDirPickerEventFunction)(wxFileDirPickerEvent&);
358
359#define wxFileDirPickerEventHandler(func) \
360 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxFileDirPickerEventFunction, &func)
361
362#define EVT_FILEPICKER_CHANGED(id, fn) \
363 wx__DECLARE_EVT1(wxEVT_COMMAND_FILEPICKER_CHANGED, id, wxFileDirPickerEventHandler(fn))
364#define EVT_DIRPICKER_CHANGED(id, fn) \
365 wx__DECLARE_EVT1(wxEVT_COMMAND_DIRPICKER_CHANGED, id, wxFileDirPickerEventHandler(fn))
366
367#ifdef _WX_DEFINE_DATE_EVENTS_
368 DEFINE_EVENT_TYPE(wxEVT_COMMAND_FILEPICKER_CHANGED)
369 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DIRPICKER_CHANGED)
370
371 IMPLEMENT_DYNAMIC_CLASS(wxFileDirPickerEvent, wxCommandEvent)
372#endif
373
374
375#endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
376
377#endif // _WX_FILEDIRPICKER_H_BASE_
378