]> git.saurik.com Git - wxWidgets.git/blob - utils/dialoged/src/winprop.h
Dialog Editor bug fixes, several other small ones
[wxWidgets.git] / utils / dialoged / src / winprop.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: winprop.h
3 // Purpose: Window properties
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WINPROP_H_
13 #define _WINPROP_H_
14
15 #ifdef __GNUG__
16 #pragma interface "winprop.h"
17 #endif
18
19 #include "reseditr.h"
20
21 class wxPropertyInfo;
22
23 class wxDialogEditorPropertyListFrame: public wxPropertyListFrame
24 {
25 friend class wxPropertyInfo;
26 public:
27 wxDialogEditorPropertyListFrame(wxPropertyListView *v, wxFrame *parent, const wxString& title,
28 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
29 long style = wxDEFAULT_FRAME_STYLE, const wxString& name = "frame");
30 ~wxDialogEditorPropertyListFrame();
31
32 private:
33 wxPropertySheet* m_propSheet;
34 wxPropertyValidatorRegistry m_registry;
35 wxPropertyInfo* m_propInfo;
36 };
37
38 // A kind of property list view that intercepts OnPropertyChanged
39 // feedback.
40 class wxResourcePropertyListView: public wxPropertyListView
41 {
42 public:
43 wxResourcePropertyListView(wxPropertyInfo *info, wxPanel *propPanel = NULL, long flags = wxPROP_BUTTON_DEFAULT):
44 wxPropertyListView(propPanel, flags)
45 {
46 m_propertyInfo = info;
47 }
48 void OnPropertyChanged(wxProperty *property);
49 bool OnClose(void);
50
51 wxPropertyInfo* m_propertyInfo;
52
53 };
54
55 // Generic class for relating an object to a collection of properties.
56 // Instead of defining new functions like wxButton::GetProperty, wxButton::SetProperty,
57 // we take these functions out into of the wxWindows library and associate
58 // them with separate classes.
59 class wxPropertyInfo: public wxObject
60 {
61 friend class wxDialogEditorPropertyListFrame;
62 protected:
63 static wxWindow *sm_propertyWindow;
64 wxPropertyInfo(void)
65 {
66 }
67 ~wxPropertyInfo(void)
68 {
69 }
70 public:
71 virtual wxProperty *GetProperty(wxString& propName) = 0;
72 virtual bool SetProperty(wxString& propName, wxProperty *property) = 0;
73 virtual void GetPropertyNames(wxStringList& names) = 0;
74 virtual bool Edit(wxWindow *parent, const wxString& title);
75 };
76
77 // For all windows
78 class wxWindowPropertyInfo: public wxPropertyInfo
79 {
80 public:
81 wxWindowPropertyInfo(wxWindow *win, wxItemResource *res = NULL);
82 ~wxWindowPropertyInfo(void);
83 wxProperty *GetProperty(wxString& name);
84 bool SetProperty(wxString& name, wxProperty *property);
85 void GetPropertyNames(wxStringList& names);
86
87 inline void SetPropertyWindow(wxWindow *win) { m_propertyWindow = win; }
88
89 inline void SetResource(wxItemResource *res) { m_propertyResource = res; }
90
91 // Helper functions for font properties
92
93 wxProperty *GetFontProperty(wxString& name, wxFont *font);
94 wxFont *SetFontProperty(wxString& name, wxProperty *property, wxFont *oldFont);
95
96 // Fill in the wxItemResource members to mirror the current window settings
97 virtual bool InstantiateResource(wxItemResource *resource);
98
99 // Set the window style
100 void SetWindowStyle(wxWindow* win, long style, bool set);
101
102 protected:
103 wxWindow* m_propertyWindow;
104 wxItemResource* m_propertyResource;
105 };
106
107 // For panel items
108 class wxItemPropertyInfo: public wxWindowPropertyInfo
109 {
110 protected:
111 public:
112 wxItemPropertyInfo(wxWindow *win, wxItemResource *res = NULL):
113 wxWindowPropertyInfo(win, res) {}
114 ~wxItemPropertyInfo(void) {}
115 wxProperty *GetProperty(wxString& name);
116 bool SetProperty(wxString& name, wxProperty *property);
117 void GetPropertyNames(wxStringList& names);
118 bool InstantiateResource(wxItemResource *resource);
119 };
120
121 // For buttons
122 class wxButtonPropertyInfo: public wxItemPropertyInfo
123 {
124 protected:
125 public:
126 wxButtonPropertyInfo(wxWindow *win, wxItemResource *res = NULL):
127 wxItemPropertyInfo(win, res) { }
128 ~wxButtonPropertyInfo(void) {}
129 wxProperty *GetProperty(wxString& name);
130 bool SetProperty(wxString& name, wxProperty *property);
131 void GetPropertyNames(wxStringList& names);
132 bool InstantiateResource(wxItemResource *resource);
133 };
134
135 // For bitmap buttons
136 class wxBitmapButtonPropertyInfo: public wxButtonPropertyInfo
137 {
138 protected:
139 public:
140 wxBitmapButtonPropertyInfo(wxWindow *win, wxItemResource *res = NULL):
141 wxButtonPropertyInfo(win, res) { }
142 ~wxBitmapButtonPropertyInfo(void) {}
143 wxProperty *GetProperty(wxString& name);
144 bool SetProperty(wxString& name, wxProperty *property);
145 void GetPropertyNames(wxStringList& names);
146 bool InstantiateResource(wxItemResource *resource);
147 };
148
149 // For static text controls
150 class wxStaticTextPropertyInfo: public wxItemPropertyInfo
151 {
152 protected:
153 public:
154 wxStaticTextPropertyInfo(wxWindow *win, wxItemResource *res = NULL):
155 wxItemPropertyInfo(win, res) { }
156 ~wxStaticTextPropertyInfo(void) {}
157 wxProperty *GetProperty(wxString& name);
158 bool SetProperty(wxString& name, wxProperty *property);
159 void GetPropertyNames(wxStringList& names);
160 bool InstantiateResource(wxItemResource *resource);
161 };
162
163 // For static bitmap controls
164 class wxStaticBitmapPropertyInfo: public wxItemPropertyInfo
165 {
166 protected:
167 public:
168 wxStaticBitmapPropertyInfo(wxWindow *win, wxItemResource *res = NULL):
169 wxItemPropertyInfo(win, res) { }
170 ~wxStaticBitmapPropertyInfo(void) {}
171 wxProperty *GetProperty(wxString& name);
172 bool SetProperty(wxString& name, wxProperty *property);
173 void GetPropertyNames(wxStringList& names);
174 bool InstantiateResource(wxItemResource *resource);
175 };
176
177 // For text/multitext items
178 class wxTextPropertyInfo: public wxItemPropertyInfo
179 {
180 protected:
181 public:
182 wxTextPropertyInfo(wxWindow *win, wxItemResource *res = NULL):
183 wxItemPropertyInfo(win, res) {}
184 ~wxTextPropertyInfo(void) {}
185 wxProperty *GetProperty(wxString& name);
186 bool SetProperty(wxString& name, wxProperty *property);
187 void GetPropertyNames(wxStringList& names);
188 bool InstantiateResource(wxItemResource *resource);
189 };
190
191 // For list boxes
192 class wxListBoxPropertyInfo: public wxItemPropertyInfo
193 {
194 protected:
195 public:
196 wxListBoxPropertyInfo(wxWindow *win, wxItemResource *res = NULL):
197 wxItemPropertyInfo(win, res) {}
198 ~wxListBoxPropertyInfo(void) {}
199 wxProperty *GetProperty(wxString& name);
200 bool SetProperty(wxString& name, wxProperty *property);
201 void GetPropertyNames(wxStringList& names);
202 bool InstantiateResource(wxItemResource *resource);
203 };
204
205 // For choice items
206 class wxChoicePropertyInfo: public wxItemPropertyInfo
207 {
208 protected:
209 public:
210 wxChoicePropertyInfo(wxWindow *win, wxItemResource *res = NULL):
211 wxItemPropertyInfo(win, res) {}
212 ~wxChoicePropertyInfo(void) {}
213 wxProperty *GetProperty(wxString& name);
214 bool SetProperty(wxString& name, wxProperty *property);
215 void GetPropertyNames(wxStringList& names);
216 bool InstantiateResource(wxItemResource *resource);
217 };
218
219 // For choice items
220 class wxComboBoxPropertyInfo: public wxChoicePropertyInfo
221 {
222 protected:
223 public:
224 wxComboBoxPropertyInfo(wxWindow *win, wxItemResource *res = NULL):
225 wxChoicePropertyInfo(win, res) {}
226 ~wxComboBoxPropertyInfo(void) {}
227 wxProperty *GetProperty(wxString& name);
228 bool SetProperty(wxString& name, wxProperty *property);
229 void GetPropertyNames(wxStringList& names);
230 bool InstantiateResource(wxItemResource *resource);
231 };
232
233 // For radiobox items
234 class wxRadioBoxPropertyInfo: public wxItemPropertyInfo
235 {
236 protected:
237 public:
238 wxRadioBoxPropertyInfo(wxWindow *win, wxItemResource *res = NULL):
239 wxItemPropertyInfo(win, res) {}
240 ~wxRadioBoxPropertyInfo(void) {}
241 wxProperty *GetProperty(wxString& name);
242 bool SetProperty(wxString& name, wxProperty *property);
243 void GetPropertyNames(wxStringList& names);
244 bool InstantiateResource(wxItemResource *resource);
245 };
246
247 // For groupbox items
248 class wxGroupBoxPropertyInfo: public wxItemPropertyInfo
249 {
250 protected:
251 public:
252 wxGroupBoxPropertyInfo(wxWindow *win, wxItemResource *res = NULL):
253 wxItemPropertyInfo(win, res) {}
254 ~wxGroupBoxPropertyInfo(void) {}
255 wxProperty *GetProperty(wxString& name);
256 bool SetProperty(wxString& name, wxProperty *property);
257 void GetPropertyNames(wxStringList& names);
258 bool InstantiateResource(wxItemResource *resource);
259 };
260
261 // For checkbox items
262 class wxCheckBoxPropertyInfo: public wxItemPropertyInfo
263 {
264 protected:
265 public:
266 wxCheckBoxPropertyInfo(wxWindow *win, wxItemResource *res = NULL):
267 wxItemPropertyInfo(win, res) {}
268 ~wxCheckBoxPropertyInfo(void) {}
269 wxProperty *GetProperty(wxString& name);
270 bool SetProperty(wxString& name, wxProperty *property);
271 void GetPropertyNames(wxStringList& names);
272 bool InstantiateResource(wxItemResource *resource);
273 };
274
275 // For radiobutton items
276 class wxRadioButtonPropertyInfo: public wxItemPropertyInfo
277 {
278 protected:
279 public:
280 wxRadioButtonPropertyInfo(wxWindow *win, wxItemResource *res = NULL):
281 wxItemPropertyInfo(win, res) {}
282 ~wxRadioButtonPropertyInfo(void) {}
283 wxProperty *GetProperty(wxString& name);
284 bool SetProperty(wxString& name, wxProperty *property);
285 void GetPropertyNames(wxStringList& names);
286 bool InstantiateResource(wxItemResource *resource);
287 };
288
289 // For gauge items
290 class wxGaugePropertyInfo: public wxItemPropertyInfo
291 {
292 protected:
293 public:
294 wxGaugePropertyInfo(wxWindow *win, wxItemResource *res = NULL):
295 wxItemPropertyInfo(win, res) {}
296 ~wxGaugePropertyInfo(void) {}
297 wxProperty *GetProperty(wxString& name);
298 bool SetProperty(wxString& name, wxProperty *property);
299 void GetPropertyNames(wxStringList& names);
300 bool InstantiateResource(wxItemResource *resource);
301 };
302
303 // For scrollbar items
304 class wxScrollBarPropertyInfo: public wxItemPropertyInfo
305 {
306 protected:
307 public:
308 wxScrollBarPropertyInfo(wxWindow *win, wxItemResource *res = NULL):
309 wxItemPropertyInfo(win, res) {}
310 ~wxScrollBarPropertyInfo(void) {}
311 wxProperty *GetProperty(wxString& name);
312 bool SetProperty(wxString& name, wxProperty *property);
313 void GetPropertyNames(wxStringList& names);
314 bool InstantiateResource(wxItemResource *resource);
315 };
316
317 // For slider items
318 class wxSliderPropertyInfo: public wxItemPropertyInfo
319 {
320 protected:
321 public:
322 wxSliderPropertyInfo(wxWindow *win, wxItemResource *res = NULL):
323 wxItemPropertyInfo(win, res) {}
324 ~wxSliderPropertyInfo(void) {}
325 wxProperty *GetProperty(wxString& name);
326 bool SetProperty(wxString& name, wxProperty *property);
327 void GetPropertyNames(wxStringList& names);
328 bool InstantiateResource(wxItemResource *resource);
329 };
330
331 // For panels
332 class wxPanelPropertyInfo: public wxWindowPropertyInfo
333 {
334 protected:
335 public:
336 wxPanelPropertyInfo(wxWindow *win, wxItemResource *res = NULL):
337 wxWindowPropertyInfo(win, res) {}
338 ~wxPanelPropertyInfo(void) {}
339 wxProperty *GetProperty(wxString& name);
340 bool SetProperty(wxString& name, wxProperty *property);
341 void GetPropertyNames(wxStringList& names);
342 bool InstantiateResource(wxItemResource *resource);
343
344 // Convert this dialog, and its children, to or from dialog units
345 void ConvertDialogUnits(bool toDialogUnits);
346 };
347
348 int wxStringToFontWeight(wxString& val);
349 int wxStringToFontStyle(wxString& val);
350 int wxStringToFontFamily(wxString& val);
351
352 /*
353 * A validator to allow editing symbol/id pairs
354 */
355
356 class wxResourceSymbolValidator: public wxPropertyListValidator
357 {
358 DECLARE_DYNAMIC_CLASS(wxResourceSymbolValidator)
359 protected:
360 public:
361 wxResourceSymbolValidator(long flags = 0);
362
363 ~wxResourceSymbolValidator(void);
364
365 // Called when TICK is pressed or focus is lost.
366 // Return FALSE if value didn't check out; signal to restore old value.
367 bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
368
369 // Called when TICK is pressed or focus is lost or view wants to update
370 // the property list.
371 // Does the transferance from the property editing area to the property itself
372 bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
373 bool OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
374
375 bool OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
376
377 bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
378
379 // Called when the edit (...) button is pressed.
380 void OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
381 };
382
383 /*
384 * A dialog for editing symbol/id pairs
385 */
386
387 class wxResourceSymbolDialog: public wxDialog
388 {
389 public:
390 wxResourceSymbolDialog(wxWindow* parent, const wxWindowID id, const wxString& title,
391 const wxPoint& pos = wxDefaultPosition,
392 const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL);
393
394 void Init();
395
396 inline void SetSymbol(const wxString& symbol) { m_symbolName = symbol; }
397 inline void SetId(long id) { m_symbolId = id; }
398
399 inline wxString GetSymbol() const { return m_symbolName; }
400 inline long GetId() const { return m_symbolId; }
401
402 bool CheckValues();
403 void OnOK(wxCommandEvent& event);
404 void OnComboBoxSelect(wxCommandEvent& event);
405 void OnSymbolNameUpdate(wxCommandEvent& event);
406
407 protected:
408 wxString m_symbolName;
409 long m_symbolId;
410 wxComboBox* m_nameCtrl;
411 wxTextCtrl* m_idCtrl;
412
413 DECLARE_EVENT_TABLE()
414 };
415
416 #define ID_SYMBOLNAME_COMBOBOX 100
417 #define ID_SYMBOLID_TEXTCTRL 101
418
419 #endif
420 // _WINPROP_H_