Debian Codegraph @

wxcrafter/src/custom_pg_properties.h

raw
1 #ifndef CUSTOM_PG_PROPS_H
2 #define CUSTOM_PG_PROPS_H
3
4 #include "BitmapSelectorDlg.h"
5 #include "BmpTextSelectorDlg.h"
6 #include "FontPickerDlg.h"
7 #include "VirtualDirectorySelectorDlg.h"
8 #include "enter_strings_dlg.h"
9 #include "wxgui_defs.h"
10 #include "wxgui_helpers.h"
11 #include <workspace.h>
12 #include <wx/app.h>
13 #include <wx/dirdlg.h>
14 #include <wx/filedlg.h>
15 #include <wx/propgrid/advprops.h>
16 #include <wx/propgrid/editors.h>
17 #include <wx/propgrid/propgrid.h>
18
19 ///////////////////////////////////////////////////////////////////////
20 // Custom editors
21 ///////////////////////////////////////////////////////////////////////
22
23 ///////////////////////////////////////////////////////////////////////
24 // Multi string editor
25 ///////////////////////////////////////////////////////////////////////
26
27 class EnterStringsDlgAdapter : public wxPGEditorDialogAdapter
28 {
29 public:
30 EnterStringsDlgAdapter()
31 : wxPGEditorDialogAdapter()
32 {
33 }
34
35 virtual ~EnterStringsDlgAdapter() {}
36
37 virtual bool DoShowDialog(wxPropertyGrid* propGrid, wxPGProperty* property)
38 {
39 wxUnusedVar(propGrid);
40 wxString delim = ";";
41 wxString str;
42
43 wxString origlbl = property->GetLabel();
44 wxString lbl = origlbl;
45 if(lbl.EndsWith(":") == false) { lbl << ":"; }
46
47 if(lbl == PROP_TOOLTIP || lbl == PROP_LABEL || lbl == PROP_MESSAGE || lbl == PROP_TITLE ||
48 lbl == PROP_CB_CHOICES) {
49 delim = "\\n";
50 }
51
52 bool wordsSplit = false;
53 if(origlbl == PROP_KEYWORDS_SET_1 || origlbl == PROP_KEYWORDS_SET_2 || origlbl == PROP_KEYWORDS_SET_3 ||
54 origlbl == PROP_KEYWORDS_SET_4 || origlbl == PROP_KEYWORDS_SET_5) {
55 wordsSplit = true;
56 delim = " ";
57 }
58
59 wxArrayString arr = wxCrafter::SplitByString(property->GetValueAsString(), delim, true);
60
61 for(size_t i = 0; i < arr.GetCount(); i++) {
62 str << arr.Item(i) << wxT("\n");
63 }
64
65 if(str.IsEmpty() == false) { str.RemoveLast(); }
66
67 EnterStringsDlg dlg(wxCrafter::TopFrame(), str);
68 dlg.SetMessage(wxT(""));
69 if(dlg.ShowModal() == wxID_OK) {
70
71 wxString value = dlg.GetValue();
72
73 if(wordsSplit) {
74 wxArrayString strings = wxCrafter::Split(value, wxT("\n\r; \t"), wxTOKEN_STRTOK);
75 value = wxCrafter::Join(strings, delim);
76
77 } else {
78 wxArrayString strings = wxCrafter::Split(value, wxT("\n\r"), wxTOKEN_RET_EMPTY_ALL);
79 value = wxCrafter::Join(strings, delim);
80 }
81
82 SetValue(wxVariant(value));
83 return true;
84 }
85 return false;
86 }
87 };
88
89 ///////////////////////////////////////////////////////////////////////
90 // Font picker
91 ///////////////////////////////////////////////////////////////////////
92
93 class FontPickerDlgAdapter : public wxPGEditorDialogAdapter
94 {
95 public:
96 FontPickerDlgAdapter()
97 : wxPGEditorDialogAdapter()
98 {
99 }
100
101 virtual ~FontPickerDlgAdapter() {}
102
103 virtual bool DoShowDialog(wxPropertyGrid* propGrid, wxPGProperty* property)
104 {
105 FontPickerDlg dlg(wxCrafter::TopFrame(), property->GetValueAsString());
106 if(dlg.ShowModal() == wxID_OK) {
107 wxString fontName = dlg.GetFontName();
108 SetValue(fontName);
109 return true;
110 }
111 return false;
112 }
113 };
114
115 ///////////////////////////////////////////////////////////////////////
116 // Bitmap picker
117 ///////////////////////////////////////////////////////////////////////
118
119 class BitmapPickerDlgAdapter : public wxPGEditorDialogAdapter
120 {
121 public:
122 BitmapPickerDlgAdapter()
123 : wxPGEditorDialogAdapter()
124 {
125 }
126
127 virtual ~BitmapPickerDlgAdapter() {}
128
129 virtual bool DoShowDialog(wxPropertyGrid* propGrid, wxPGProperty* property)
130 {
131 BitmapSelectorDlg dlg(wxCrafter::TopFrame(), property->GetValueAsString());
132 if(dlg.ShowModal() == wxID_OK) {
133 wxString bmpname = dlg.GetBitmapFile();
134 SetValue(bmpname);
135 return true;
136 }
137 return false;
138 }
139 };
140
141 class wxPG_MultiStringProperty : public wxStringProperty
142 {
143 wxString m_value;
144
145 public:
146 wxPG_MultiStringProperty(const wxString& label, const wxString& name = wxPG_LABEL, const wxString& value = "")
147 : wxStringProperty(label, name, value)
148 {
149 }
150
151 virtual ~wxPG_MultiStringProperty() {}
152
153 // Set editor to have button
154 virtual const wxPGEditor* DoGetEditorClass() const { return wxPGEditor_TextCtrlAndButton; }
155
156 // Set what happens on button click
157 virtual wxPGEditorDialogAdapter* GetEditorDialog() const { return new EnterStringsDlgAdapter(); }
158 };
159
160 class wxPG_FontProperty : public wxStringProperty
161 {
162 wxString m_value;
163
164 public:
165 wxPG_FontProperty(const wxString& label, const wxString& name = wxPG_LABEL, const wxString& value = "")
166 : wxStringProperty(label, name, value)
167 {
168 }
169
170 virtual ~wxPG_FontProperty() {}
171
172 // Set editor to have button
173 virtual const wxPGEditor* DoGetEditorClass() const { return wxPGEditor_TextCtrlAndButton; }
174
175 // Set what happens on button click
176 virtual wxPGEditorDialogAdapter* GetEditorDialog() const { return new FontPickerDlgAdapter(); }
177 };
178
179 ///////////////////////////////////////////////////////////////////////
180 // Bitmap picker
181 ///////////////////////////////////////////////////////////////////////
182
183 class wxPG_BitmapProperty : public wxStringProperty
184 {
185 wxString m_value;
186
187 public:
188 wxPG_BitmapProperty(const wxString& label, const wxString& name = wxPG_LABEL, const wxString& value = "")
189 : wxStringProperty(label, name, value)
190 {
191 }
192
193 virtual ~wxPG_BitmapProperty() {}
194
195 // Set editor to have button
196 virtual const wxPGEditor* DoGetEditorClass() const { return wxPGEditor_TextCtrlAndButton; }
197
198 // Set what happens on button click
199 virtual wxPGEditorDialogAdapter* GetEditorDialog() const { return new BitmapPickerDlgAdapter(); }
200 };
201
202 ///////////////////////////////////////////////////////////////////////
203 // File Picker
204 ///////////////////////////////////////////////////////////////////////
205
206 class FilePickerDlgAdapter : public wxPGEditorDialogAdapter
207 {
208 protected:
209 wxString m_projectPath;
210
211 public:
212 FilePickerDlgAdapter(const wxString& projectPath)
213 : wxPGEditorDialogAdapter()
214 , m_projectPath(projectPath)
215 {
216 }
217
218 virtual ~FilePickerDlgAdapter() {}
219
220 virtual bool DoShowDialog(wxPropertyGrid* propGrid, wxPGProperty* property)
221 {
222
223 wxString wildcard =
224 wxT("PNG files (*.png)|*.png|BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif|All files (*)|*");
225 wxString newPath = ::wxFileSelector(_("Select bitmap"), wxT(""), wxT(""), wxEmptyString, wildcard, wxFD_OPEN,
226 wxCrafter::TopFrame());
227 if(newPath.IsEmpty() == false) {
228 wxFileName newFilePath(newPath);
229 if(m_projectPath.IsEmpty() == false) { newFilePath.MakeRelativeTo(m_projectPath); }
230 SetValue(newFilePath.GetFullPath(wxPATH_UNIX));
231 return true;
232 }
233 return false;
234 }
235 };
236
237 ///////////////////////////////////////////////////////////////////////
238 // File Picker
239 ///////////////////////////////////////////////////////////////////////
240
241 class DirPickerDlgAdapter : public wxPGEditorDialogAdapter
242 {
243 protected:
244 wxString m_projectPath;
245
246 public:
247 DirPickerDlgAdapter(const wxString& projectPath)
248 : wxPGEditorDialogAdapter()
249 , m_projectPath(projectPath)
250 {
251 }
252
253 virtual ~DirPickerDlgAdapter() {}
254
255 virtual bool DoShowDialog(wxPropertyGrid* propGrid, wxPGProperty* property)
256 {
257 wxString newPath = ::wxDirSelector("Select a folder", wxEmptyString, wxDD_DEFAULT_STYLE, wxDefaultPosition,
258 wxCrafter::TopFrame());
259 if(newPath.IsEmpty() == false) {
260 wxFileName newFilePath(newPath, "");
261 if(m_projectPath.IsEmpty() == false) { newFilePath.MakeRelativeTo(m_projectPath); }
262 wxString new_path = newFilePath.GetFullPath(wxPATH_UNIX);
263 if(new_path.IsEmpty()) new_path = ".";
264 SetValue(new_path);
265 return true;
266 }
267 return false;
268 }
269 };
270
271 class wxPG_DirPickerProperty : public wxStringProperty
272 {
273 wxString m_value;
274 wxString m_projectPath;
275
276 public:
277 wxPG_DirPickerProperty(const wxString& label, const wxString& projectPath, const wxString& name = wxPG_LABEL,
278 const wxString& value = "")
279 : wxStringProperty(label, name, value)
280 , m_projectPath(projectPath)
281 {
282 }
283
284 virtual ~wxPG_DirPickerProperty() {}
285
286 // Set editor to have button
287 virtual const wxPGEditor* DoGetEditorClass() const { return wxPGEditor_TextCtrlAndButton; }
288
289 // Set what happens on button click
290 virtual wxPGEditorDialogAdapter* GetEditorDialog() const { return new DirPickerDlgAdapter(m_projectPath); }
291 };
292
293 class wxPG_FilePickerProperty : public wxStringProperty
294 {
295 wxString m_value;
296 wxString m_projectPath;
297
298 public:
299 wxPG_FilePickerProperty(const wxString& label, const wxString& projectPath, const wxString& name = wxPG_LABEL,
300 const wxString& value = "")
301 : wxStringProperty(label, name, value)
302 , m_projectPath(projectPath)
303 {
304 }
305
306 virtual ~wxPG_FilePickerProperty() {}
307
308 // Set editor to have button
309 virtual const wxPGEditor* DoGetEditorClass() const { return wxPGEditor_TextCtrlAndButton; }
310
311 // Set what happens on button click
312 virtual wxPGEditorDialogAdapter* GetEditorDialog() const { return new FilePickerDlgAdapter(m_projectPath); }
313 };
314
315 ///////////////////////////////////////////////////////////////////////
316 // Virtual Folder Picker
317 ///////////////////////////////////////////////////////////////////////
318
319 class VDPickerDlgAdapter : public wxPGEditorDialogAdapter
320 {
321 protected:
322 wxString m_vdPath;
323
324 public:
325 VDPickerDlgAdapter(const wxString& vdPath)
326 : wxPGEditorDialogAdapter()
327 , m_vdPath(vdPath)
328 {
329 }
330
331 virtual ~VDPickerDlgAdapter() {}
332
333 virtual bool DoShowDialog(wxPropertyGrid* propGrid, wxPGProperty* property)
334 {
335
336 VirtualDirectorySelectorDlg selector(wxCrafter::TopFrame(), clCxxWorkspaceST::Get(), m_vdPath);
337 if(selector.ShowModal() == wxID_OK) {
338 m_vdPath = selector.GetVirtualDirectoryPath();
339 SetValue(m_vdPath);
340 return true;
341 }
342 return false;
343 }
344 };
345
346 class wxPG_VDPickerProperty : public wxStringProperty
347 {
348 public:
349 wxPG_VDPickerProperty(const wxString& label, const wxString& name = wxPG_LABEL, const wxString& value = "")
350 : wxStringProperty(label, name, value)
351 {
352 }
353
354 virtual ~wxPG_VDPickerProperty() {}
355
356 // Set editor to have button
357 virtual const wxPGEditor* DoGetEditorClass() const { return wxPGEditor_TextCtrlAndButton; }
358
359 // Set what happens on button click
360 virtual wxPGEditorDialogAdapter* GetEditorDialog() const { return new VDPickerDlgAdapter(GetValueAsString()); }
361 };
362
363 ///////////////////////////////////////////////////////////////////////
364 // Bitmap and Text pairs selectors
365 ///////////////////////////////////////////////////////////////////////
366
367 class BmpTextDialogAdapter : public wxPGEditorDialogAdapter
368 {
369 protected:
370 wxString m_initialValue;
371
372 public:
373 BmpTextDialogAdapter(const wxString& value)
374 : wxPGEditorDialogAdapter()
375 , m_initialValue(value)
376 {
377 }
378
379 virtual ~BmpTextDialogAdapter() {}
380
381 virtual bool DoShowDialog(wxPropertyGrid* propGrid, wxPGProperty* property)
382 {
383 BmpTextSelectorDlg selector(wxCrafter::TopFrame(), m_initialValue);
384 if(selector.ShowModal() == wxID_OK) {
385 m_initialValue = selector.GetValue();
386 SetValue(m_initialValue);
387 return true;
388 }
389 return false;
390 }
391 };
392
393 class wxPG_BmpTextProperty : public wxStringProperty
394 {
395 public:
396 wxPG_BmpTextProperty(const wxString& label, const wxString& name = wxPG_LABEL, const wxString& value = "")
397 : wxStringProperty(label, name, value)
398 {
399 }
400
401 virtual ~wxPG_BmpTextProperty() {}
402
403 // Set editor to have button
404 virtual const wxPGEditor* DoGetEditorClass() const { return wxPGEditor_TextCtrlAndButton; }
405
406 // Set what happens on button click
407 virtual wxPGEditorDialogAdapter* GetEditorDialog() const { return new BmpTextDialogAdapter(GetValueAsString()); }
408 };
409
410 class wxPG_Colour : public wxSystemColourProperty
411 {
412 public:
413 wxPG_Colour(const wxString& label = wxPG_LABEL, const wxString& name = wxPG_LABEL,
414 const wxColourPropertyValue& value = wxColourPropertyValue())
415 : wxSystemColourProperty(label, name, value)
416 {
417 }
418 virtual ~wxPG_Colour() {}
419 virtual bool OnEvent(wxPropertyGrid* propgrid, wxWindow* primary, wxEvent& event);
420 };
421
422 //////////////////////////////////////////////////////////////////
423 class wxcPGChoiceAndButtonEditor : public wxPGChoiceEditor
424 {
425 public:
426 wxcPGChoiceAndButtonEditor() {}
427 virtual ~wxcPGChoiceAndButtonEditor();
428 virtual wxString GetName() const;
429
430 virtual wxPGWindowList CreateControls(wxPropertyGrid* propgrid, wxPGProperty* property, const wxPoint& pos,
431 const wxSize& size) const;
432 };
433
434 #endif // CUSTOM_PG_PROPS_H