]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/filepickerg.h
Add wxToolBarToolBase, missing flags, etc.
[wxWidgets.git] / include / wx / generic / filepickerg.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/filepickerg.h
3 // Purpose: wxGenericFileDirButton, wxGenericFileButton, wxGenericDirButton
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_
13 #define _WX_FILEDIRPICKER_H_
14
15 #include "wx/button.h"
16 #include "wx/filedlg.h"
17 #include "wx/dirdlg.h"
18
19
20 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COMMAND_DIRPICKER_CHANGED, wxFileDirPickerEvent );
21 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COMMAND_FILEPICKER_CHANGED, wxFileDirPickerEvent );
22
23
24 //-----------------------------------------------------------------------------
25 // wxGenericFileDirButton: a button which brings up a wx{File|Dir}Dialog
26 //-----------------------------------------------------------------------------
27
28 class WXDLLIMPEXP_CORE wxGenericFileDirButton : public wxButton,
29 public wxFileDirPickerWidgetBase
30 {
31 public:
32 wxGenericFileDirButton() { Init(); }
33 wxGenericFileDirButton(wxWindow *parent,
34 wxWindowID id,
35 const wxString& label = wxFilePickerWidgetLabel,
36 const wxString& path = wxEmptyString,
37 const wxString &message = wxFileSelectorPromptStr,
38 const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
39 const wxPoint& pos = wxDefaultPosition,
40 const wxSize& size = wxDefaultSize,
41 long style = 0,
42 const wxValidator& validator = wxDefaultValidator,
43 const wxString& name = wxFilePickerWidgetNameStr)
44 {
45 Init();
46 Create(parent, id, label, path, message, wildcard,
47 pos, size, style, validator, name);
48 }
49
50 virtual wxControl *AsControl() { return this; }
51
52 public: // overridable
53
54 virtual wxDialog *CreateDialog() = 0;
55
56 virtual wxWindow *GetDialogParent()
57 { return GetParent(); }
58
59 virtual wxEventType GetEventType() const = 0;
60
61 virtual void SetInitialDirectory(const wxString& dir);
62
63 public:
64
65 bool Create(wxWindow *parent, wxWindowID id,
66 const wxString& label = wxFilePickerWidgetLabel,
67 const wxString& path = wxEmptyString,
68 const wxString &message = wxFileSelectorPromptStr,
69 const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
70 const wxPoint& pos = wxDefaultPosition,
71 const wxSize& size = wxDefaultSize,
72 long style = 0,
73 const wxValidator& validator = wxDefaultValidator,
74 const wxString& name = wxFilePickerWidgetNameStr);
75
76 // event handler for the click
77 void OnButtonClick(wxCommandEvent &);
78
79 protected:
80 wxString m_message, m_wildcard;
81
82 // we just store the style passed to the ctor here instead of passing it to
83 // wxButton as some of our bits can conflict with wxButton styles and it
84 // just doesn't make sense to use picker styles for wxButton anyhow
85 long m_pickerStyle;
86
87 // Initial directory set by SetInitialDirectory() call or empty.
88 wxString m_initialDir;
89
90 private:
91 // common part of all ctors
92 void Init() { m_pickerStyle = -1; }
93 };
94
95
96 //-----------------------------------------------------------------------------
97 // wxGenericFileButton: a button which brings up a wxFileDialog
98 //-----------------------------------------------------------------------------
99
100 #define wxFILEBTN_DEFAULT_STYLE (wxFLP_OPEN)
101
102 class WXDLLIMPEXP_CORE wxGenericFileButton : public wxGenericFileDirButton
103 {
104 public:
105 wxGenericFileButton() {}
106 wxGenericFileButton(wxWindow *parent,
107 wxWindowID id,
108 const wxString& label = wxFilePickerWidgetLabel,
109 const wxString& path = wxEmptyString,
110 const wxString &message = wxFileSelectorPromptStr,
111 const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
112 const wxPoint& pos = wxDefaultPosition,
113 const wxSize& size = wxDefaultSize,
114 long style = wxFILEBTN_DEFAULT_STYLE,
115 const wxValidator& validator = wxDefaultValidator,
116 const wxString& name = wxFilePickerWidgetNameStr)
117 {
118 Create(parent, id, label, path, message, wildcard,
119 pos, size, style, validator, name);
120 }
121
122 public: // overridable
123
124 virtual long GetDialogStyle() const
125 {
126 // the derived class must initialize it if it doesn't use the
127 // non-default wxGenericFileDirButton ctor
128 wxASSERT_MSG( m_pickerStyle != -1,
129 "forgot to initialize m_pickerStyle?" );
130
131
132 long filedlgstyle = 0;
133
134 if ( m_pickerStyle & wxFLP_OPEN )
135 filedlgstyle |= wxFD_OPEN;
136 if ( m_pickerStyle & wxFLP_SAVE )
137 filedlgstyle |= wxFD_SAVE;
138 if ( m_pickerStyle & wxFLP_OVERWRITE_PROMPT )
139 filedlgstyle |= wxFD_OVERWRITE_PROMPT;
140 if ( m_pickerStyle & wxFLP_FILE_MUST_EXIST )
141 filedlgstyle |= wxFD_FILE_MUST_EXIST;
142 if ( m_pickerStyle & wxFLP_CHANGE_DIR )
143 filedlgstyle |= wxFD_CHANGE_DIR;
144
145 return filedlgstyle;
146 }
147
148 virtual wxDialog *CreateDialog();
149
150 wxEventType GetEventType() const
151 { return wxEVT_COMMAND_FILEPICKER_CHANGED; }
152
153 protected:
154 void UpdateDialogPath(wxDialog *p)
155 { wxStaticCast(p, wxFileDialog)->SetPath(m_path); }
156 void UpdatePathFromDialog(wxDialog *p)
157 { m_path = wxStaticCast(p, wxFileDialog)->GetPath(); }
158
159 // Set the initial directory for the dialog but without overriding the
160 // directory of the currently selected file, if any.
161 void DoSetInitialDirectory(wxFileDialog* dialog, const wxString& dir);
162
163 private:
164 DECLARE_DYNAMIC_CLASS(wxGenericFileButton)
165 };
166
167
168 //-----------------------------------------------------------------------------
169 // wxGenericDirButton: a button which brings up a wxDirDialog
170 //-----------------------------------------------------------------------------
171
172 #define wxDIRBTN_DEFAULT_STYLE 0
173
174 class WXDLLIMPEXP_CORE wxGenericDirButton : public wxGenericFileDirButton
175 {
176 public:
177 wxGenericDirButton() {}
178 wxGenericDirButton(wxWindow *parent,
179 wxWindowID id,
180 const wxString& label = wxDirPickerWidgetLabel,
181 const wxString& path = wxEmptyString,
182 const wxString &message = wxDirSelectorPromptStr,
183 const wxPoint& pos = wxDefaultPosition,
184 const wxSize& size = wxDefaultSize,
185 long style = wxDIRBTN_DEFAULT_STYLE,
186 const wxValidator& validator = wxDefaultValidator,
187 const wxString& name = wxDirPickerWidgetNameStr)
188 {
189 Create(parent, id, label, path, message, wxEmptyString,
190 pos, size, style, validator, name);
191 }
192
193 public: // overridable
194
195 virtual long GetDialogStyle() const
196 {
197 long dirdlgstyle = wxDD_DEFAULT_STYLE;
198
199 if ( m_pickerStyle & wxDIRP_DIR_MUST_EXIST )
200 dirdlgstyle |= wxDD_DIR_MUST_EXIST;
201 if ( m_pickerStyle & wxDIRP_CHANGE_DIR )
202 dirdlgstyle |= wxDD_CHANGE_DIR;
203
204 return dirdlgstyle;
205 }
206
207 virtual wxDialog *CreateDialog();
208
209 wxEventType GetEventType() const
210 { return wxEVT_COMMAND_DIRPICKER_CHANGED; }
211
212 protected:
213 void UpdateDialogPath(wxDialog *p)
214 { wxStaticCast(p, wxDirDialog)->SetPath(m_path); }
215 void UpdatePathFromDialog(wxDialog *p)
216 { m_path = wxStaticCast(p, wxDirDialog)->GetPath(); }
217
218 private:
219 DECLARE_DYNAMIC_CLASS(wxGenericDirButton)
220 };
221
222
223 #endif // _WX_FILEDIRPICKER_H_