1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Property list classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
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.
42 #ifndef _WX_PROPLIST_H_
43 #define _WX_PROPLIST_H_
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 wxPropertyListView(wxPanel
*propPanel
= NULL
, long flags
= wxPROP_BUTTON_DEFAULT
);
79 ~wxPropertyListView(void);
81 // Associates and shows the view
82 virtual void ShowView(wxPropertySheet
*propertySheet
, wxPanel
*panel
);
84 // Update this view of the viewed object, called e.g. by
86 virtual bool OnUpdateView(void);
88 wxString
MakeNameValueString(wxString name
, wxString value
);
90 // Update a single line in the list of properties
91 virtual bool UpdatePropertyDisplayInList(wxProperty
*property
);
93 // Update the whole list
94 virtual bool UpdatePropertyList(bool clearEditArea
= TRUE
);
96 // Find the wxListBox index corresponding to this property
97 virtual int FindListIndexForProperty(wxProperty
*property
);
99 // Select and show string representation in editor the given
100 // property. NULL resets to show no property.
101 virtual bool ShowProperty(wxProperty
*property
, bool select
= TRUE
);
102 virtual bool EditProperty(wxProperty
*property
);
104 // Update the display from the property
105 virtual bool DisplayProperty(wxProperty
*property
);
106 // Update the property from the display
107 virtual bool RetrieveProperty(wxProperty
*property
);
109 // Find appropriate validator and load property into value controls
110 virtual bool BeginShowingProperty(wxProperty
*property
);
111 // Find appropriate validator and unload property from value controls
112 virtual bool EndShowingProperty(wxProperty
*property
);
114 // Begin detailed editing (e.g. using value listbox)
115 virtual void BeginDetailedEditing(void);
117 // End detailed editing (e.g. using value listbox)
118 virtual void EndDetailedEditing(void);
120 // Called by the property listbox
121 void OnPropertySelect(wxCommandEvent
& event
);
123 // Called by the value listbox
124 void OnValueListSelect(wxCommandEvent
& event
);
126 virtual bool CreateControls(void);
127 virtual void ShowTextControl(bool show
);
128 virtual void ShowListBoxControl(bool show
);
129 virtual void EnableCheck(bool show
);
130 virtual void EnableCross(bool show
);
132 void OnOk(wxCommandEvent
& event
);
133 void OnCancel(wxCommandEvent
& event
);
134 void OnHelp(wxCommandEvent
& event
);
135 void OnPropertyDoubleClick(wxCommandEvent
& event
);
136 // virtual void OnDoubleClick(void);
138 void OnCheck(wxCommandEvent
& event
);
139 void OnCross(wxCommandEvent
& event
);
140 void OnEdit(wxCommandEvent
& event
);
141 void OnText(wxCommandEvent
& event
);
143 inline virtual wxListBox
*GetPropertyScrollingList() const { return m_propertyScrollingList
; }
144 inline virtual wxListBox
*GetValueList() const { return m_valueList
; }
145 inline virtual wxTextCtrl
*GetValueText() const { return m_valueText
; }
146 inline virtual wxButton
*GetConfirmButton() const { return m_confirmButton
; }
147 inline virtual wxButton
*GetCancelButton() const { return m_cancelButton
; }
148 inline virtual wxButton
*GetEditButton() const { return m_editButton
; }
149 inline virtual bool GetDetailedEditing(void) const { return m_detailedEditing
; }
151 inline virtual void AssociatePanel(wxPanel
*win
) { m_propertyWindow
= win
; }
152 inline virtual wxPanel
*GetPanel(void) const { return m_propertyWindow
; }
154 inline virtual void SetManagedWindow(wxWindow
*win
) { m_managedWindow
= win
; }
155 inline virtual wxWindow
*GetManagedWindow(void) const { return m_managedWindow
; }
157 inline virtual wxButton
*GetWindowCloseButton() const { return m_windowCloseButton
; }
158 inline virtual wxButton
*GetWindowCancelButton() const { return m_windowCancelButton
; }
159 inline virtual wxButton
*GetHelpButton() const { return m_windowHelpButton
; }
164 static bool sm_dialogCancelled
;
167 wxListBox
* m_propertyScrollingList
;
168 wxListBox
* m_valueList
; // Should really be a combobox, but we don't have one.
169 wxTextCtrl
* m_valueText
;
170 wxButton
* m_confirmButton
; // A tick, as in VB
171 wxButton
* m_cancelButton
; // A cross, as in VB
172 wxButton
* m_editButton
; // Invokes the custom validator, if any
174 bool m_detailedEditing
; // E.g. using listbox for choices
176 static wxBitmap
* sm_tickBitmap
;
177 static wxBitmap
* sm_crossBitmap
;
179 wxPanel
* m_propertyWindow
; // Panel that the controls will appear on
180 wxWindow
* m_managedWindow
; // Frame or dialog
182 wxButton
* m_windowCloseButton
; // Or OK
183 wxButton
* m_windowCancelButton
;
184 wxButton
* m_windowHelpButton
;
186 DECLARE_EVENT_TABLE()
189 class wxPropertyTextEdit
: public wxTextCtrl
191 DECLARE_CLASS(wxPropertyTextEdit
)
193 wxPropertyTextEdit(wxPropertyListView
*v
, wxWindow
*parent
, const wxWindowID id
,
194 const wxString
& value
, const wxPoint
& pos
= wxDefaultPosition
,
195 const wxSize
& size
= wxDefaultSize
, long style
= 0, const wxString
& name
= "text");
196 void OnSetFocus(void);
197 void OnKillFocus(void);
199 wxPropertyListView
* m_view
;
202 #define wxPROP_ALLOW_TEXT_EDITING 1
205 * The type of validator used for property lists (Visual Basic style)
208 class wxPropertyListValidator
: public wxPropertyValidator
210 DECLARE_DYNAMIC_CLASS(wxPropertyListValidator
)
213 wxPropertyListValidator(long flags
= wxPROP_ALLOW_TEXT_EDITING
): wxPropertyValidator(flags
) { }
214 ~wxPropertyListValidator(void) {}
216 // Called when the property is selected or deselected: typically displays the value
217 // in the edit control (having chosen a suitable control to display: (non)editable text or listbox)
218 virtual bool OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
220 // Called when the property is double clicked. Extra functionality can be provided, such as
221 // cycling through possible values.
222 inline virtual bool OnDoubleClick(
223 wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
) )
226 // Called when the value listbox is selected. Default behaviour is to copy
227 // string to text control, and retrieve the value into the property.
228 virtual bool OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
230 // Called when the property value is edited using standard text control
231 inline virtual bool OnPrepareControls(
232 wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
) )
235 virtual bool OnClearControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
237 // Called when the property is edited in detail
238 inline virtual bool OnPrepareDetailControls(
239 wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
) )
242 // Called if focus lost, IF we're in a modeless property editing situation.
243 inline virtual bool OnClearDetailControls(
244 wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
) )
247 // Called when the edit (...) button is pressed. The default implementation
248 // calls view->BeginDetailedEditing; the filename validator (for example) overrides
249 // this function to show the file selector.
250 virtual void OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
252 // Called when TICK is pressed or focus is lost.
253 // Return FALSE if value didn't check out; signal to restore old value.
254 inline virtual bool OnCheckValue(
255 wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
) )
258 // Called when TICK is pressed or focus is lost or view wants to update
259 // the property list.
260 // Does the transferance from the property editing area to the property itself
261 virtual bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
263 virtual bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
267 * A default dialog box class to use.
270 class wxPropertyListDialog
: public wxDialog
272 DECLARE_CLASS(wxPropertyListDialog
)
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
);
285 wxPropertyListView
* m_view
;
287 DECLARE_EVENT_TABLE()
291 * A default panel class to use.
294 class wxPropertyListPanel
: public wxPanel
296 DECLARE_CLASS(wxPropertyListPanel
)
298 wxPropertyListPanel(wxPropertyListView
*v
, wxWindow
*parent
, const wxPoint
& pos
= wxDefaultPosition
,
299 const wxSize
& size
= wxDefaultSize
,
300 long style
= 0, const wxString
& name
= "panel"):
301 wxPanel(parent
, -1, pos
, size
, style
, name
)
305 ~wxPropertyListPanel();
306 void OnDefaultAction(wxControl
*item
);
308 inline void SetView(wxPropertyListView
* v
) { m_view
= v
; }
309 inline wxPropertyListView
* GetView() const { return m_view
; }
311 // Extend event processing to search the view's event table
312 virtual bool ProcessEvent(wxEvent
& event
);
315 void OnSize(wxSizeEvent
& event
);
318 wxPropertyListView
* m_view
;
320 DECLARE_EVENT_TABLE()
324 * A default frame class to use.
327 class wxPropertyListFrame
: public wxFrame
329 DECLARE_CLASS(wxPropertyListFrame
)
331 wxPropertyListFrame(wxPropertyListView
*v
, wxFrame
*parent
, const wxString
& title
,
332 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
333 long style
= wxDEFAULT_FRAME
, const wxString
& name
= "frame"):
334 wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
337 m_propertyPanel
= NULL
;
341 // Must call this to create panel and associate view
342 virtual bool Initialize(void);
343 virtual wxPropertyListPanel
*OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
);
344 inline virtual wxPropertyListPanel
*GetPropertyPanel(void) const { return m_propertyPanel
; }
347 wxPropertyListView
* m_view
;
348 wxPropertyListPanel
* m_propertyPanel
;
352 * Some default validators
355 class wxRealListValidator
: public wxPropertyListValidator
357 DECLARE_DYNAMIC_CLASS(wxRealListValidator
)
359 // 0.0, 0.0 means no range
360 wxRealListValidator(float min
= 0.0, float max
= 0.0, long flags
= wxPROP_ALLOW_TEXT_EDITING
):wxPropertyListValidator(flags
)
362 m_realMin
= min
; m_realMax
= max
;
364 ~wxRealListValidator(void) {}
366 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
368 // Called when TICK is pressed or focus is lost.
369 // Return FALSE if value didn't check out; signal to restore old value.
370 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
372 // Called when TICK is pressed or focus is lost or view wants to update
373 // the property list.
374 // Does the transfer from the property editing area to the property itself
375 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
382 class wxIntegerListValidator
: public wxPropertyListValidator
384 DECLARE_DYNAMIC_CLASS(wxIntegerListValidator
)
386 // 0, 0 means no range
387 wxIntegerListValidator(long min
= 0, long max
= 0, long flags
= wxPROP_ALLOW_TEXT_EDITING
):wxPropertyListValidator(flags
)
389 m_integerMin
= min
; m_integerMax
= max
;
391 ~wxIntegerListValidator(void) {}
393 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
395 // Called when TICK is pressed or focus is lost.
396 // Return FALSE if value didn't check out; signal to restore old value.
397 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
399 // Called when TICK is pressed or focus is lost or view wants to update
400 // the property list.
401 // Does the transfer from the property editing area to the property itself
402 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
409 class wxBoolListValidator
: public wxPropertyListValidator
411 DECLARE_DYNAMIC_CLASS(wxBoolListValidator
)
414 wxBoolListValidator(long flags
= 0):wxPropertyListValidator(flags
)
417 ~wxBoolListValidator(void) {}
419 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
420 bool OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
421 bool OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
423 // Called when TICK is pressed or focus is lost.
424 // Return FALSE if value didn't check out; signal to restore old value.
425 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
427 // Called when TICK is pressed or focus is lost or view wants to update
428 // the property list.
429 // Does the transfer from the property editing area to the property itself
430 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
431 bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
433 // Called when the property is double clicked. Extra functionality can be provided,
434 // cycling through possible values.
435 virtual bool OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
438 class wxStringListValidator
: public wxPropertyListValidator
440 DECLARE_DYNAMIC_CLASS(wxStringListValidator
)
442 wxStringListValidator(wxStringList
*list
= NULL
, long flags
= 0);
444 ~wxStringListValidator(void)
450 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
451 bool OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
452 bool OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
454 // Called when TICK is pressed or focus is lost.
455 // Return FALSE if value didn't check out; signal to restore old value.
456 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
458 // Called when TICK is pressed or focus is lost or view wants to update
459 // the property list.
460 // Does the transfer from the property editing area to the property itself
461 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
462 bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
464 // Called when the property is double clicked. Extra functionality can be provided,
465 // cycling through possible values.
466 bool OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
469 wxStringList
* m_strings
;
472 class wxFilenameListValidator
: public wxPropertyListValidator
474 DECLARE_DYNAMIC_CLASS(wxFilenameListValidator
)
476 wxFilenameListValidator(wxString message
= "Select a file", wxString wildcard
= "*.*", long flags
= 0);
478 ~wxFilenameListValidator(void);
480 // Called when TICK is pressed or focus is lost.
481 // Return FALSE if value didn't check out; signal to restore old value.
482 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
484 // Called when TICK is pressed or focus is lost or view wants to update
485 // the property list.
486 // Does the transferance from the property editing area to the property itself
487 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
488 bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
490 bool OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
492 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
494 // Called when the edit (...) button is pressed.
495 void OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
498 wxString m_filenameWildCard
;
499 wxString m_filenameMessage
;
503 class wxColourListValidator
: public wxPropertyListValidator
505 DECLARE_DYNAMIC_CLASS(wxColourListValidator
)
508 wxColourListValidator(long flags
= 0);
510 ~wxColourListValidator(void);
512 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
513 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
514 bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
516 bool OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
518 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
520 // Called when the edit (...) button is pressed.
521 void OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
524 class wxListOfStringsListValidator
: public wxPropertyListValidator
526 DECLARE_DYNAMIC_CLASS(wxListOfStringsListValidator
)
529 wxListOfStringsListValidator(long flags
= 0);
531 ~wxListOfStringsListValidator(void)
535 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
537 // Called when TICK is pressed or focus is lost.
538 // Return FALSE if value didn't check out; signal to restore old value.
539 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
541 // Called when TICK is pressed or focus is lost or view wants to update
542 // the property list.
543 // Does the transfer from the property editing area to the property itself
544 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
545 bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
547 // Called when the property is double clicked.
548 bool OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
550 bool EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const char *title
= "String List Editor");
552 // Called when the edit (...) button is pressed.
553 void OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);