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