]>
Commit | Line | Data |
---|---|---|
ec376c8f VZ |
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 | ||
45f9b662 | 15 | #include "wx/button.h" |
ec376c8f VZ |
16 | #include "wx/filename.h" |
17 | #include "wx/filedlg.h" | |
18 | #include "wx/dirdlg.h" | |
19 | ||
20 | ||
21 | extern const wxEventType wxEVT_COMMAND_DIRPICKER_CHANGED; | |
22 | extern const wxEventType wxEVT_COMMAND_FILEPICKER_CHANGED; | |
23 | ||
24 | ||
25 | //----------------------------------------------------------------------------- | |
26 | // wxGenericFileDirButton: a button which brings up a wx{File|Dir}Dialog | |
27 | //----------------------------------------------------------------------------- | |
28 | ||
29 | class WXDLLIMPEXP_CORE wxGenericFileDirButton : public wxButton, | |
30 | public wxFileDirPickerWidgetBase | |
31 | { | |
32 | public: | |
33 | wxGenericFileDirButton() { m_dialog = NULL; } | |
34 | wxGenericFileDirButton(wxWindow *parent, | |
35 | wxWindowID id, | |
36 | const wxString& label = wxFilePickerWidgetLabel, | |
37 | const wxString& path = wxEmptyString, | |
38 | const wxString &message = wxFileSelectorPromptStr, | |
39 | const wxString &wildcard = wxFileSelectorDefaultWildcardStr, | |
40 | const wxPoint& pos = wxDefaultPosition, | |
41 | const wxSize& size = wxDefaultSize, | |
42 | long style = 0, | |
43 | const wxValidator& validator = wxDefaultValidator, | |
44 | const wxString& name = wxFilePickerWidgetNameStr) | |
45 | { | |
46 | m_dialog = NULL; | |
47 | Create(parent, id, label, path, message, wildcard, | |
48 | pos, size, style, validator, name); | |
49 | } | |
50 | ||
51 | virtual ~wxGenericFileDirButton() {} | |
52 | ||
53 | public: // overrideable | |
54 | ||
55 | virtual bool CreateDialog(const wxString &message, | |
56 | const wxString &wildcard) = 0; | |
57 | ||
58 | // NULL is because of a problem with destruction order in both generic & GTK code | |
59 | virtual wxWindow *GetDialogParent() | |
60 | { return NULL; } | |
61 | ||
62 | virtual wxEventType GetEventType() const = 0; | |
63 | ||
64 | public: | |
65 | ||
66 | bool Destroy() | |
67 | { | |
68 | m_dialog->Destroy(); | |
69 | return wxButton::Destroy(); | |
70 | } | |
71 | ||
72 | bool Create(wxWindow *parent, wxWindowID id, | |
73 | const wxString& label = wxFilePickerWidgetLabel, | |
74 | const wxString& path = wxEmptyString, | |
75 | const wxString &message = wxFileSelectorPromptStr, | |
76 | const wxString &wildcard = wxFileSelectorDefaultWildcardStr, | |
77 | const wxPoint& pos = wxDefaultPosition, | |
78 | const wxSize& size = wxDefaultSize, | |
79 | long style = 0, | |
80 | const wxValidator& validator = wxDefaultValidator, | |
81 | const wxString& name = wxFilePickerWidgetNameStr); | |
82 | ||
83 | // event handler for the click | |
84 | void OnButtonClick(wxCommandEvent &); | |
85 | ||
86 | wxDialog *m_dialog; | |
87 | }; | |
88 | ||
89 | ||
90 | //----------------------------------------------------------------------------- | |
91 | // wxGenericFileButton: a button which brings up a wxFileDialog | |
92 | //----------------------------------------------------------------------------- | |
93 | ||
94 | #define wxFILEBTN_DEFAULT_STYLE wxFLP_OPEN | |
95 | ||
96 | class WXDLLIMPEXP_CORE wxGenericFileButton : public wxGenericFileDirButton | |
97 | { | |
98 | public: | |
99 | wxGenericFileButton() {} | |
100 | wxGenericFileButton(wxWindow *parent, | |
101 | wxWindowID id, | |
102 | const wxString& label = wxFilePickerWidgetLabel, | |
103 | const wxString& path = wxEmptyString, | |
104 | const wxString &message = wxFileSelectorPromptStr, | |
105 | const wxString &wildcard = wxFileSelectorDefaultWildcardStr, | |
106 | const wxPoint& pos = wxDefaultPosition, | |
107 | const wxSize& size = wxDefaultSize, | |
108 | long style = wxFILEBTN_DEFAULT_STYLE, | |
109 | const wxValidator& validator = wxDefaultValidator, | |
110 | const wxString& name = wxFilePickerWidgetNameStr) | |
111 | { | |
112 | Create(parent, id, label, path, message, wildcard, | |
113 | pos, size, style, validator, name); | |
114 | } | |
115 | ||
116 | public: // overrideable | |
117 | ||
118 | virtual long GetDialogStyle() const | |
119 | { | |
120 | long filedlgstyle = 0; | |
121 | ||
122 | if (this->HasFlag(wxFLP_OPEN)) | |
123 | filedlgstyle |= wxFD_OPEN; | |
124 | if (this->HasFlag(wxFLP_SAVE)) | |
125 | filedlgstyle |= wxFD_SAVE; | |
126 | if (this->HasFlag(wxFLP_OVERWRITE_PROMPT)) | |
127 | filedlgstyle |= wxFD_OVERWRITE_PROMPT; | |
128 | if (this->HasFlag(wxFLP_FILE_MUST_EXIST)) | |
129 | filedlgstyle |= wxFD_FILE_MUST_EXIST; | |
130 | if (this->HasFlag(wxFLP_CHANGE_DIR)) | |
131 | filedlgstyle |= wxFD_CHANGE_DIR; | |
132 | ||
133 | return filedlgstyle; | |
134 | } | |
135 | ||
136 | virtual bool CreateDialog(const wxString &message, const wxString &wildcard) | |
137 | { | |
138 | m_dialog = new wxFileDialog(GetDialogParent(), message, | |
139 | wxEmptyString, wxEmptyString, | |
140 | wildcard, GetDialogStyle()); | |
141 | ||
142 | // this sets both the default folder and the default file of the dialog | |
143 | GetDialog()->SetPath(m_path); | |
144 | ||
145 | return true; | |
146 | } | |
147 | ||
148 | wxFileDialog *GetDialog() | |
149 | { return wxStaticCast(m_dialog, wxFileDialog); } | |
150 | void UpdateDialogPath() | |
151 | { GetDialog()->SetPath(m_path); } | |
152 | void UpdatePathFromDialog() | |
153 | { m_path = GetDialog()->GetPath(); } | |
154 | wxEventType GetEventType() const | |
155 | { return wxEVT_COMMAND_FILEPICKER_CHANGED; } | |
156 | ||
157 | private: | |
158 | DECLARE_DYNAMIC_CLASS(wxGenericFileButton) | |
159 | }; | |
160 | ||
161 | ||
162 | //----------------------------------------------------------------------------- | |
163 | // wxGenericDirButton: a button which brings up a wxDirDialog | |
164 | //----------------------------------------------------------------------------- | |
165 | ||
166 | #define wxDIRBTN_DEFAULT_STYLE 0 | |
167 | ||
168 | class WXDLLIMPEXP_CORE wxGenericDirButton : public wxGenericFileDirButton | |
169 | { | |
170 | public: | |
171 | wxGenericDirButton() {} | |
172 | wxGenericDirButton(wxWindow *parent, | |
173 | wxWindowID id, | |
174 | const wxString& label = wxDirPickerWidgetLabel, | |
175 | const wxString& path = wxEmptyString, | |
176 | const wxString &message = wxDirSelectorPromptStr, | |
177 | const wxPoint& pos = wxDefaultPosition, | |
178 | const wxSize& size = wxDefaultSize, | |
179 | long style = wxDIRBTN_DEFAULT_STYLE, | |
180 | const wxValidator& validator = wxDefaultValidator, | |
181 | const wxString& name = wxDirPickerWidgetNameStr) | |
182 | { | |
183 | Create(parent, id, label, path, message, wxEmptyString, | |
184 | pos, size, style, validator, name); | |
185 | } | |
186 | ||
187 | public: // overrideable | |
188 | ||
189 | virtual long GetDialogStyle() const | |
190 | { | |
191 | long dirdlgstyle = 0; | |
192 | ||
193 | if (this->HasFlag(wxDIRP_DIR_MUST_EXIST)) | |
194 | dirdlgstyle |= wxDD_DIR_MUST_EXIST; | |
195 | if (this->HasFlag(wxDIRP_CHANGE_DIR)) | |
196 | dirdlgstyle |= wxDD_CHANGE_DIR; | |
197 | ||
198 | return dirdlgstyle; | |
199 | } | |
200 | ||
201 | virtual bool CreateDialog(const wxString &message, const wxString &WXUNUSED(wildcard)) | |
202 | { | |
203 | m_dialog = new wxDirDialog(GetDialogParent(), message, m_path, | |
204 | GetDialogStyle()); | |
205 | return true; | |
206 | } | |
207 | ||
208 | wxDirDialog *GetDialog() | |
209 | { return wxStaticCast(m_dialog, wxDirDialog); } | |
210 | void UpdateDialogPath() | |
211 | { GetDialog()->SetPath(m_path); } | |
212 | void UpdatePathFromDialog() | |
213 | { m_path = GetDialog()->GetPath(); } | |
214 | wxEventType GetEventType() const | |
215 | { return wxEVT_COMMAND_DIRPICKER_CHANGED; } | |
216 | ||
217 | private: | |
218 | DECLARE_DYNAMIC_CLASS(wxGenericDirButton) | |
219 | }; | |
220 | ||
221 | ||
222 | #endif // _WX_FILEDIRPICKER_H_ |