]> git.saurik.com Git - wxWidgets.git/blob - utils/wxprop/src/proplist.h
wxFileConfig ctor now (again) uses the files in the correct locations if the
[wxWidgets.git] / utils / wxprop / src / proplist.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: proplist.h
3 // Purpose: Property list classes
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 /*
13
14 TO DO:
15
16 (1) Optional popup-help for each item, and an optional Help button
17 for dialog.
18
19 (2) Align Ok, Cancel, Help buttons properly.
20
21 (3) Consider retrieving the rectangle on the panel that can be
22 drawn into (where the value listbox is) and giving an example
23 of editing graphically. May be too fancy.
24
25 (4) Deriveable types for wxPropertyValue => may need to reorganise
26 wxPropertyValue to use inheritance rather than present all-types-in-one
27 scheme.
28
29 (5) Optional popup panel for value list, perhaps.
30
31 (6) Floating point checking routine still crashes with Floating
32 point error for zany input.
33
34 (7) Property sheet with choice (or listbox) to select alternative
35 sheets... multiple views per panel, only one active. For this
36 we really need a wxChoice that can be dynamically set: XView
37 may be a problem; Motif?
38
39 (8) More example validators, e.g. colour selector.
40 */
41
42 #ifndef _PROPLIST_H_
43 #define _PROPLIST_H_
44
45 #ifdef __GNUG__
46 #pragma interface "proplist.h"
47 #endif
48
49 #include "prop.h"
50
51 #define wxPROP_BUTTON_CLOSE 1
52 #define wxPROP_BUTTON_OK 2
53 #define wxPROP_BUTTON_CANCEL 4
54 #define wxPROP_BUTTON_CHECK_CROSS 8
55 #define wxPROP_BUTTON_HELP 16
56 #define wxPROP_DYNAMIC_VALUE_FIELD 32
57 #define wxPROP_PULLDOWN 64
58 #define wxPROP_SHOWVALUES 128
59
60 #ifdef __XVIEW__
61 #define wxPROP_BUTTON_DEFAULT wxPROP_BUTTON_OK | wxPROP_BUTTON_CANCEL | wxPROP_BUTTON_CHECK_CROSS | wxPROP_PULLDOWN
62 #else
63 #define wxPROP_BUTTON_DEFAULT wxPROP_BUTTON_CHECK_CROSS | wxPROP_PULLDOWN | wxPROP_SHOWVALUES
64 #endif
65
66 #define wxID_PROP_CROSS 3000
67 #define wxID_PROP_CHECK 3001
68 #define wxID_PROP_EDIT 3002
69 #define wxID_PROP_TEXT 3003
70 #define wxID_PROP_SELECT 3004
71 #define wxID_PROP_VALUE_SELECT 3005
72
73 // Mediates between a physical panel and the property sheet
74 class wxPropertyListView: public wxPropertyView
75 {
76 DECLARE_DYNAMIC_CLASS(wxPropertyListView)
77 protected:
78 wxListBox *propertyScrollingList;
79 wxListBox *valueList; // Should really be a combobox, but we don't have one.
80 wxTextCtrl *valueText;
81 wxButton *confirmButton; // A tick, as in VB
82 wxButton *cancelButton; // A cross, as in VB
83 wxButton *editButton; // Invokes the custom validator, if any
84
85 bool detailedEditing; // E.g. using listbox for choices
86
87 static wxBitmap *tickBitmap;
88 static wxBitmap *crossBitmap;
89
90 wxPanel *propertyWindow; // Panel that the controls will appear on
91 wxWindow *managedWindow; // Frame or dialog
92
93 wxButton *windowCloseButton; // Or OK
94 wxButton *windowCancelButton;
95 wxButton *windowHelpButton;
96 public:
97 static bool dialogCancelled;
98
99 wxPropertyListView(wxPanel *propPanel = NULL, long flags = wxPROP_BUTTON_DEFAULT);
100 ~wxPropertyListView(void);
101
102 // Associates and shows the view
103 virtual void ShowView(wxPropertySheet *propertySheet, wxPanel *panel);
104
105 // Update this view of the viewed object, called e.g. by
106 // the object itself.
107 virtual bool OnUpdateView(void);
108
109 wxString MakeNameValueString(wxString name, wxString value);
110
111 // Update a single line in the list of properties
112 virtual bool UpdatePropertyDisplayInList(wxProperty *property);
113
114 // Update the whole list
115 virtual bool UpdatePropertyList(bool clearEditArea = TRUE);
116
117 // Find the wxListBox index corresponding to this property
118 virtual int FindListIndexForProperty(wxProperty *property);
119
120 // Select and show string representation in editor the given
121 // property. NULL resets to show no property.
122 virtual bool ShowProperty(wxProperty *property, bool select = TRUE);
123 virtual bool EditProperty(wxProperty *property);
124
125 // Update the display from the property
126 virtual bool DisplayProperty(wxProperty *property);
127 // Update the property from the display
128 virtual bool RetrieveProperty(wxProperty *property);
129
130 // Find appropriate validator and load property into value controls
131 virtual bool BeginShowingProperty(wxProperty *property);
132 // Find appropriate validator and unload property from value controls
133 virtual bool EndShowingProperty(wxProperty *property);
134
135 // Begin detailed editing (e.g. using value listbox)
136 virtual void BeginDetailedEditing(void);
137
138 // End detailed editing (e.g. using value listbox)
139 virtual void EndDetailedEditing(void);
140
141 // Called by the property listbox
142 void OnPropertySelect(wxCommandEvent& event);
143
144 // Called by the value listbox
145 void OnValueListSelect(wxCommandEvent& event);
146
147 virtual bool CreateControls(void);
148 virtual void ShowTextControl(bool show);
149 virtual void ShowListBoxControl(bool show);
150 virtual void EnableCheck(bool show);
151 virtual void EnableCross(bool show);
152
153 void OnOk(wxCommandEvent& event);
154 void OnCancel(wxCommandEvent& event);
155 void OnHelp(wxCommandEvent& event);
156 void OnPropertyDoubleClick(wxCommandEvent& event);
157 // virtual void OnDoubleClick(void);
158
159 void OnCheck(wxCommandEvent& event);
160 void OnCross(wxCommandEvent& event);
161 void OnEdit(wxCommandEvent& event);
162 void OnText(wxCommandEvent& event);
163
164 inline virtual wxListBox *GetPropertyScrollingList() { return propertyScrollingList; }
165 inline virtual wxListBox *GetValueList() { return valueList; }
166 inline virtual wxTextCtrl *GetValueText() { return valueText; }
167 inline virtual wxButton *GetConfirmButton() { return confirmButton; }
168 inline virtual wxButton *GetCancelButton() { return cancelButton; }
169 inline virtual wxButton *GetEditButton() { return editButton; }
170 inline virtual bool GetDetailedEditing(void) { return detailedEditing; }
171
172 inline virtual void AssociatePanel(wxPanel *win) { propertyWindow = win; }
173 inline virtual wxPanel *GetPanel(void) { return propertyWindow; }
174
175 inline virtual void SetManagedWindow(wxWindow *win) { managedWindow = win; }
176 inline virtual wxWindow *GetManagedWindow(void) { return managedWindow; }
177
178 inline virtual wxButton *GetWindowCloseButton() { return windowCloseButton; }
179 inline virtual wxButton *GetWindowCancelButton() { return windowCancelButton; }
180 inline virtual wxButton *GetHelpButton() { return windowHelpButton; }
181
182 bool OnClose(void);
183
184 DECLARE_EVENT_TABLE()
185 };
186
187 class wxPropertyTextEdit: public wxTextCtrl
188 {
189 DECLARE_CLASS(wxPropertyTextEdit)
190 public:
191 wxPropertyListView *view;
192 wxPropertyTextEdit(wxPropertyListView *v, wxWindow *parent, const wxWindowID id,
193 const wxString& value, const wxPoint& pos = wxDefaultPosition,
194 const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = "text");
195 void OnSetFocus(void);
196 void OnKillFocus(void);
197 };
198
199 #define wxPROP_ALLOW_TEXT_EDITING 1
200
201 /*
202 * The type of validator used for property lists (Visual Basic style)
203 */
204
205 class wxPropertyListValidator: public wxPropertyValidator
206 {
207 DECLARE_DYNAMIC_CLASS(wxPropertyListValidator)
208 protected:
209 public:
210 wxPropertyListValidator(long flags = wxPROP_ALLOW_TEXT_EDITING): wxPropertyValidator(flags) { }
211 ~wxPropertyListValidator(void) {}
212
213 // Called when the property is selected or deselected: typically displays the value
214 // in the edit control (having chosen a suitable control to display: (non)editable text or listbox)
215 virtual bool OnSelect(bool select, wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
216
217 // Called when the property is double clicked. Extra functionality can be provided, such as
218 // cycling through possible values.
219 inline virtual bool OnDoubleClick(
220 wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow) )
221 { return TRUE; }
222
223 // Called when the value listbox is selected. Default behaviour is to copy
224 // string to text control, and retrieve the value into the property.
225 virtual bool OnValueListSelect(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
226
227 // Called when the property value is edited using standard text control
228 inline virtual bool OnPrepareControls(
229 wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow) )
230 { return TRUE; }
231
232 virtual bool OnClearControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
233
234 // Called when the property is edited in detail
235 inline virtual bool OnPrepareDetailControls(
236 wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow) )
237 { return TRUE; }
238
239 // Called if focus lost, IF we're in a modeless property editing situation.
240 inline virtual bool OnClearDetailControls(
241 wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow) )
242 { return TRUE; }
243
244 // Called when the edit (...) button is pressed. The default implementation
245 // calls view->BeginDetailedEditing; the filename validator (for example) overrides
246 // this function to show the file selector.
247 virtual void OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
248
249 // Called when TICK is pressed or focus is lost.
250 // Return FALSE if value didn't check out; signal to restore old value.
251 inline virtual bool OnCheckValue(
252 wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow) )
253 { return TRUE; }
254
255 // Called when TICK is pressed or focus is lost or view wants to update
256 // the property list.
257 // Does the transferance from the property editing area to the property itself
258 virtual bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
259
260 virtual bool OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
261 };
262
263 /*
264 * A default dialog box class to use.
265 */
266
267 class wxPropertyListDialog: public wxDialog
268 {
269 DECLARE_CLASS(wxPropertyListDialog)
270 private:
271 wxPropertyListView *view;
272 public:
273 wxPropertyListDialog(wxPropertyListView *v, wxWindow *parent, const wxString& title,
274 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
275 long style = wxDEFAULT_DIALOG_STYLE, const wxString& name = "dialogBox");
276 bool OnClose(void);
277 void OnDefaultAction(wxControl *item);
278 void OnCancel(wxCommandEvent& event);
279
280 // Extend event processing to search the view's event table
281 virtual bool ProcessEvent(wxEvent& event);
282
283 DECLARE_EVENT_TABLE()
284 };
285
286 /*
287 * A default panel class to use.
288 */
289
290 class wxPropertyListPanel: public wxPanel
291 {
292 DECLARE_CLASS(wxPropertyListPanel)
293 private:
294 wxPropertyListView *view;
295 public:
296 wxPropertyListPanel(wxPropertyListView *v, wxWindow *parent, const wxPoint& pos = wxDefaultPosition,
297 const wxSize& size = wxDefaultSize,
298 long style = 0, const wxString& name = "panel"):
299 wxPanel(parent, -1, pos, size, style, name)
300 {
301 view = v;
302 }
303 void OnDefaultAction(wxControl *item);
304
305 inline void SetView(wxPropertyListView* v) { view = v; }
306 inline wxPropertyListView* GetView() const { return view; }
307
308 // Extend event processing to search the view's event table
309 virtual bool ProcessEvent(wxEvent& event);
310
311 // Call Layout()
312 void OnSize(wxSizeEvent& event);
313
314 DECLARE_EVENT_TABLE()
315 };
316
317 /*
318 * A default frame class to use.
319 */
320
321 class wxPropertyListFrame: public wxFrame
322 {
323 DECLARE_CLASS(wxPropertyListFrame)
324 private:
325 wxPropertyListView *view;
326 wxPropertyListPanel *propertyPanel;
327 public:
328 wxPropertyListFrame(wxPropertyListView *v, wxFrame *parent, const wxString& title,
329 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
330 long style = wxDEFAULT_FRAME, const wxString& name = "frame"):
331 wxFrame(parent, -1, title, pos, size, style, name)
332 {
333 view = v;
334 propertyPanel = NULL;
335 }
336 bool OnClose(void);
337
338 // Must call this to create panel and associate view
339 virtual bool Initialize(void);
340 virtual wxPropertyListPanel *OnCreatePanel(wxFrame *parent, wxPropertyListView *v);
341 inline virtual wxPropertyListPanel *GetPropertyPanel(void) { return propertyPanel; }
342 };
343
344 /*
345 * Some default validators
346 */
347
348 class wxRealListValidator: public wxPropertyListValidator
349 {
350 DECLARE_DYNAMIC_CLASS(wxRealListValidator)
351 protected:
352 float realMin;
353 float realMax;
354 public:
355 // 0.0, 0.0 means no range
356 wxRealListValidator(float min = 0.0, float max = 0.0, long flags = wxPROP_ALLOW_TEXT_EDITING):wxPropertyListValidator(flags)
357 {
358 realMin = min; realMax = max;
359 }
360 ~wxRealListValidator(void) {}
361
362 bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
363
364 // Called when TICK is pressed or focus is lost.
365 // Return FALSE if value didn't check out; signal to restore old value.
366 bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
367
368 // Called when TICK is pressed or focus is lost or view wants to update
369 // the property list.
370 // Does the transfer from the property editing area to the property itself
371 bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
372 };
373
374 class wxIntegerListValidator: public wxPropertyListValidator
375 {
376 DECLARE_DYNAMIC_CLASS(wxIntegerListValidator)
377 protected:
378 long integerMin;
379 long integerMax;
380 public:
381 // 0, 0 means no range
382 wxIntegerListValidator(long min = 0, long max = 0, long flags = wxPROP_ALLOW_TEXT_EDITING):wxPropertyListValidator(flags)
383 {
384 integerMin = min; integerMax = max;
385 }
386 ~wxIntegerListValidator(void) {}
387
388 bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
389
390 // Called when TICK is pressed or focus is lost.
391 // Return FALSE if value didn't check out; signal to restore old value.
392 bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
393
394 // Called when TICK is pressed or focus is lost or view wants to update
395 // the property list.
396 // Does the transfer from the property editing area to the property itself
397 bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
398 };
399
400 class wxBoolListValidator: public wxPropertyListValidator
401 {
402 DECLARE_DYNAMIC_CLASS(wxBoolListValidator)
403 protected:
404 public:
405 wxBoolListValidator(long flags = 0):wxPropertyListValidator(flags)
406 {
407 }
408 ~wxBoolListValidator(void) {}
409
410 bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
411 bool OnPrepareDetailControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
412 bool OnClearDetailControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
413
414 // Called when TICK is pressed or focus is lost.
415 // Return FALSE if value didn't check out; signal to restore old value.
416 bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
417
418 // Called when TICK is pressed or focus is lost or view wants to update
419 // the property list.
420 // Does the transfer from the property editing area to the property itself
421 bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
422 bool OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
423
424 // Called when the property is double clicked. Extra functionality can be provided,
425 // cycling through possible values.
426 virtual bool OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
427 };
428
429 class wxStringListValidator: public wxPropertyListValidator
430 {
431 DECLARE_DYNAMIC_CLASS(wxStringListValidator)
432 protected:
433 wxStringList *strings;
434 public:
435 wxStringListValidator(wxStringList *list = NULL, long flags = 0);
436
437 ~wxStringListValidator(void)
438 {
439 if (strings)
440 delete strings;
441 }
442
443 bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
444 bool OnPrepareDetailControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
445 bool OnClearDetailControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
446
447 // Called when TICK is pressed or focus is lost.
448 // Return FALSE if value didn't check out; signal to restore old value.
449 bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
450
451 // Called when TICK is pressed or focus is lost or view wants to update
452 // the property list.
453 // Does the transfer from the property editing area to the property itself
454 bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
455 bool OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
456
457 // Called when the property is double clicked. Extra functionality can be provided,
458 // cycling through possible values.
459 bool OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
460 };
461
462 class wxFilenameListValidator: public wxPropertyListValidator
463 {
464 DECLARE_DYNAMIC_CLASS(wxFilenameListValidator)
465 protected:
466 wxString filenameWildCard;
467 wxString filenameMessage;
468
469 public:
470 wxFilenameListValidator(wxString message = "Select a file", wxString wildcard = "*.*", long flags = 0);
471
472 ~wxFilenameListValidator(void);
473
474 // Called when TICK is pressed or focus is lost.
475 // Return FALSE if value didn't check out; signal to restore old value.
476 bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
477
478 // Called when TICK is pressed or focus is lost or view wants to update
479 // the property list.
480 // Does the transferance from the property editing area to the property itself
481 bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
482 bool OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
483
484 bool OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
485
486 bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
487
488 // Called when the edit (...) button is pressed.
489 void OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
490 };
491
492 class wxColourListValidator: public wxPropertyListValidator
493 {
494 DECLARE_DYNAMIC_CLASS(wxColourListValidator)
495 protected:
496 public:
497 wxColourListValidator(long flags = 0);
498
499 ~wxColourListValidator(void);
500
501 bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
502 bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
503 bool OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
504
505 bool OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
506
507 bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
508
509 // Called when the edit (...) button is pressed.
510 void OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
511 };
512
513 class wxListOfStringsListValidator: public wxPropertyListValidator
514 {
515 DECLARE_DYNAMIC_CLASS(wxListOfStringsListValidator)
516 protected:
517 public:
518 wxListOfStringsListValidator(long flags = 0);
519
520 ~wxListOfStringsListValidator(void)
521 {
522 }
523
524 bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
525
526 // Called when TICK is pressed or focus is lost.
527 // Return FALSE if value didn't check out; signal to restore old value.
528 bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
529
530 // Called when TICK is pressed or focus is lost or view wants to update
531 // the property list.
532 // Does the transfer from the property editing area to the property itself
533 bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
534 bool OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
535
536 // Called when the property is double clicked.
537 bool OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
538
539 bool EditStringList(wxWindow *parent, wxStringList *stringList, const char *title = "String List Editor");
540
541 // Called when the edit (...) button is pressed.
542 void OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
543 };
544
545 #endif
546