1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Property list classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
16 (1) Optional popup-help for each item, and an optional Help button
19 (2) Align Ok, Cancel, Help buttons properly.
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.
25 (4) Deriveable types for wxPropertyValue => may need to reorganise
26 wxPropertyValue to use inheritance rather than present all-types-in-one
29 (5) Optional popup panel for value list, perhaps.
31 (6) Floating point checking routine still crashes with Floating
32 point error for zany input.
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?
39 (8) More example validators, e.g. colour selector.
46 #pragma interface "proplist.h"
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
61 #define wxPROP_BUTTON_DEFAULT wxPROP_BUTTON_OK | wxPROP_BUTTON_CANCEL | wxPROP_BUTTON_CHECK_CROSS | wxPROP_PULLDOWN
63 #define wxPROP_BUTTON_DEFAULT wxPROP_BUTTON_CHECK_CROSS | wxPROP_PULLDOWN | wxPROP_SHOWVALUES
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
73 // Mediates between a physical panel and the property sheet
74 class wxPropertyListView
: public wxPropertyView
76 DECLARE_DYNAMIC_CLASS(wxPropertyListView
)
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
85 bool detailedEditing
; // E.g. using listbox for choices
87 static wxBitmap
*tickBitmap
;
88 static wxBitmap
*crossBitmap
;
90 wxPanel
*propertyWindow
; // Panel that the controls will appear on
91 wxWindow
*managedWindow
; // Frame or dialog
93 wxButton
*windowCloseButton
; // Or OK
94 wxButton
*windowCancelButton
;
95 wxButton
*windowHelpButton
;
97 static bool dialogCancelled
;
99 wxPropertyListView(wxPanel
*propPanel
= NULL
, long flags
= wxPROP_BUTTON_DEFAULT
);
100 ~wxPropertyListView(void);
102 // Associates and shows the view
103 virtual void ShowView(wxPropertySheet
*propertySheet
, wxPanel
*panel
);
105 // Update this view of the viewed object, called e.g. by
106 // the object itself.
107 virtual bool OnUpdateView(void);
109 wxString
MakeNameValueString(wxString name
, wxString value
);
111 // Update a single line in the list of properties
112 virtual bool UpdatePropertyDisplayInList(wxProperty
*property
);
114 // Update the whole list
115 virtual bool UpdatePropertyList(bool clearEditArea
= TRUE
);
117 // Find the wxListBox index corresponding to this property
118 virtual int FindListIndexForProperty(wxProperty
*property
);
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
);
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
);
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
);
135 // Begin detailed editing (e.g. using value listbox)
136 virtual void BeginDetailedEditing(void);
138 // End detailed editing (e.g. using value listbox)
139 virtual void EndDetailedEditing(void);
141 // Called by the property listbox
142 void OnPropertySelect(wxCommandEvent
& event
);
144 // Called by the value listbox
145 void OnValueListSelect(wxCommandEvent
& event
);
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
);
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);
159 void OnCheck(wxCommandEvent
& event
);
160 void OnCross(wxCommandEvent
& event
);
161 void OnEdit(wxCommandEvent
& event
);
162 void OnText(wxCommandEvent
& event
);
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
; }
172 inline virtual void AssociatePanel(wxPanel
*win
) { propertyWindow
= win
; }
173 inline virtual wxPanel
*GetPanel(void) { return propertyWindow
; }
175 inline virtual void SetManagedWindow(wxWindow
*win
) { managedWindow
= win
; }
176 inline virtual wxWindow
*GetManagedWindow(void) { return managedWindow
; }
178 inline virtual wxButton
*GetWindowCloseButton() { return windowCloseButton
; }
179 inline virtual wxButton
*GetWindowCancelButton() { return windowCancelButton
; }
180 inline virtual wxButton
*GetHelpButton() { return windowHelpButton
; }
184 DECLARE_EVENT_TABLE()
187 class wxPropertyTextEdit
: public wxTextCtrl
189 DECLARE_CLASS(wxPropertyTextEdit
)
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);
199 #define wxPROP_ALLOW_TEXT_EDITING 1
202 * The type of validator used for property lists (Visual Basic style)
205 class wxPropertyListValidator
: public wxPropertyValidator
207 DECLARE_DYNAMIC_CLASS(wxPropertyListValidator
)
210 wxPropertyListValidator(long flags
= wxPROP_ALLOW_TEXT_EDITING
): wxPropertyValidator(flags
) { }
211 ~wxPropertyListValidator(void) {}
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
);
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(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
222 // Called when the value listbox is selected. Default behaviour is to copy
223 // string to text control, and retrieve the value into the property.
224 virtual bool OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
226 // Called when the property value is edited using standard text control
227 virtual bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
232 virtual bool OnClearControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
234 // Called when the property is edited in detail
235 virtual bool OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
240 // Called if focus lost, IF we're in a modeless property editing situation.
241 virtual bool OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
246 // Called when the edit (...) button is pressed. The default implementation
247 // calls view->BeginDetailedEditing; the filename validator (for example) overrides
248 // this function to show the file selector.
249 virtual void OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
251 // Called when TICK is pressed or focus is lost.
252 // Return FALSE if value didn't check out; signal to restore old value.
253 virtual bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
256 // Called when TICK is pressed or focus is lost or view wants to update
257 // the property list.
258 // Does the transferance from the property editing area to the property itself
259 virtual bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
261 virtual bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
265 * A default dialog box class to use.
268 class wxPropertyListDialog
: public wxDialog
270 DECLARE_CLASS(wxPropertyListDialog
)
272 wxPropertyListView
*view
;
274 wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
, const wxString
& title
,
275 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
276 long style
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= "dialogBox");
278 void OnDefaultAction(wxControl
*item
);
279 void OnCancel(wxCommandEvent
& event
);
281 // Extend event processing to search the view's event table
282 virtual bool ProcessEvent(wxEvent
& event
);
284 DECLARE_EVENT_TABLE()
288 * A default panel class to use.
291 class wxPropertyListPanel
: public wxPanel
293 DECLARE_CLASS(wxPropertyListPanel
)
295 wxPropertyListView
*view
;
297 wxPropertyListPanel(wxPropertyListView
*v
, wxWindow
*parent
, const wxPoint
& pos
= wxDefaultPosition
,
298 const wxSize
& size
= wxDefaultSize
,
299 long style
= 0, const wxString
& name
= "panel"):
300 wxPanel(parent
, -1, pos
, size
, style
, name
)
304 void OnDefaultAction(wxControl
*item
);
306 inline void SetView(wxPropertyListView
* v
) { view
= v
; }
307 inline wxPropertyListView
* GetView() const { return view
; }
309 // Extend event processing to search the view's event table
310 virtual bool ProcessEvent(wxEvent
& event
);
313 void OnSize(wxSizeEvent
& event
);
315 DECLARE_EVENT_TABLE()
319 * A default frame class to use.
322 class wxPropertyListFrame
: public wxFrame
324 DECLARE_CLASS(wxPropertyListFrame
)
326 wxPropertyListView
*view
;
327 wxPropertyListPanel
*propertyPanel
;
329 wxPropertyListFrame(wxPropertyListView
*v
, wxFrame
*parent
, const wxString
& title
,
330 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
331 long style
= wxDEFAULT_FRAME
, const wxString
& name
= "frame"):
332 wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
335 propertyPanel
= NULL
;
339 // Must call this to create panel and associate view
340 virtual bool Initialize(void);
341 virtual wxPropertyListPanel
*OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
);
342 inline virtual wxPropertyListPanel
*GetPropertyPanel(void) { return propertyPanel
; }
346 * Some default validators
349 class wxRealListValidator
: public wxPropertyListValidator
351 DECLARE_DYNAMIC_CLASS(wxRealListValidator
)
356 // 0.0, 0.0 means no range
357 wxRealListValidator(float min
= 0.0, float max
= 0.0, long flags
= wxPROP_ALLOW_TEXT_EDITING
):wxPropertyListValidator(flags
)
359 realMin
= min
; realMax
= max
;
361 ~wxRealListValidator(void) {}
363 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
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
);
369 // Called when TICK is pressed or focus is lost or view wants to update
370 // the property list.
371 // Does the transfer from the property editing area to the property itself
372 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
375 class wxIntegerListValidator
: public wxPropertyListValidator
377 DECLARE_DYNAMIC_CLASS(wxIntegerListValidator
)
382 // 0, 0 means no range
383 wxIntegerListValidator(long min
= 0, long max
= 0, long flags
= wxPROP_ALLOW_TEXT_EDITING
):wxPropertyListValidator(flags
)
385 integerMin
= min
; integerMax
= max
;
387 ~wxIntegerListValidator(void) {}
389 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
391 // Called when TICK is pressed or focus is lost.
392 // Return FALSE if value didn't check out; signal to restore old value.
393 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
395 // Called when TICK is pressed or focus is lost or view wants to update
396 // the property list.
397 // Does the transfer from the property editing area to the property itself
398 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
401 class wxBoolListValidator
: public wxPropertyListValidator
403 DECLARE_DYNAMIC_CLASS(wxBoolListValidator
)
406 wxBoolListValidator(long flags
= 0):wxPropertyListValidator(flags
)
409 ~wxBoolListValidator(void) {}
411 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
412 bool OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
413 bool OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
415 // Called when TICK is pressed or focus is lost.
416 // Return FALSE if value didn't check out; signal to restore old value.
417 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
419 // Called when TICK is pressed or focus is lost or view wants to update
420 // the property list.
421 // Does the transfer from the property editing area to the property itself
422 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
423 bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
425 // Called when the property is double clicked. Extra functionality can be provided,
426 // cycling through possible values.
427 virtual bool OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
430 class wxStringListValidator
: public wxPropertyListValidator
432 DECLARE_DYNAMIC_CLASS(wxStringListValidator
)
434 wxStringList
*strings
;
436 wxStringListValidator(wxStringList
*list
= NULL
, long flags
= 0);
438 ~wxStringListValidator(void)
444 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
445 bool OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
446 bool OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
448 // Called when TICK is pressed or focus is lost.
449 // Return FALSE if value didn't check out; signal to restore old value.
450 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
452 // Called when TICK is pressed or focus is lost or view wants to update
453 // the property list.
454 // Does the transfer from the property editing area to the property itself
455 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
456 bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
458 // Called when the property is double clicked. Extra functionality can be provided,
459 // cycling through possible values.
460 bool OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
463 class wxFilenameListValidator
: public wxPropertyListValidator
465 DECLARE_DYNAMIC_CLASS(wxFilenameListValidator
)
467 wxString filenameWildCard
;
468 wxString filenameMessage
;
471 wxFilenameListValidator(wxString message
= "Select a file", wxString wildcard
= "*.*", long flags
= 0);
473 ~wxFilenameListValidator(void);
475 // Called when TICK is pressed or focus is lost.
476 // Return FALSE if value didn't check out; signal to restore old value.
477 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
479 // Called when TICK is pressed or focus is lost or view wants to update
480 // the property list.
481 // Does the transferance from the property editing area to the property itself
482 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
483 bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
485 bool OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
487 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
489 // Called when the edit (...) button is pressed.
490 void OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
493 class wxColourListValidator
: public wxPropertyListValidator
495 DECLARE_DYNAMIC_CLASS(wxColourListValidator
)
498 wxColourListValidator(long flags
= 0);
500 ~wxColourListValidator(void);
502 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
503 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
504 bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
506 bool OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
508 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
510 // Called when the edit (...) button is pressed.
511 void OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
514 class wxListOfStringsListValidator
: public wxPropertyListValidator
516 DECLARE_DYNAMIC_CLASS(wxListOfStringsListValidator
)
519 wxListOfStringsListValidator(long flags
= 0);
521 ~wxListOfStringsListValidator(void)
525 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
527 // Called when TICK is pressed or focus is lost.
528 // Return FALSE if value didn't check out; signal to restore old value.
529 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
531 // Called when TICK is pressed or focus is lost or view wants to update
532 // the property list.
533 // Does the transfer from the property editing area to the property itself
534 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
535 bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
537 // Called when the property is double clicked.
538 bool OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
540 bool EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const char *title
= "String List Editor");
542 // Called when the edit (...) button is pressed.
543 void OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);