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
60 // Show OK/Cancel buttons on X-based systems where window management is
62 #if defined(__WXMOTIF__) || defined(__WXGTK__)
63 #define wxPROP_BUTTON_DEFAULT wxPROP_BUTTON_OK | wxPROP_BUTTON_CANCEL | wxPROP_BUTTON_CHECK_CROSS | wxPROP_PULLDOWN
65 #define wxPROP_BUTTON_DEFAULT wxPROP_BUTTON_CHECK_CROSS | wxPROP_PULLDOWN | wxPROP_SHOWVALUES
68 #define wxID_PROP_CROSS 3000
69 #define wxID_PROP_CHECK 3001
70 #define wxID_PROP_EDIT 3002
71 #define wxID_PROP_TEXT 3003
72 #define wxID_PROP_SELECT 3004
73 #define wxID_PROP_VALUE_SELECT 3005
75 // Mediates between a physical panel and the property sheet
76 class WXDLLEXPORT wxPropertyListView
: public wxPropertyView
78 DECLARE_DYNAMIC_CLASS(wxPropertyListView
)
80 wxPropertyListView(wxPanel
*propPanel
= NULL
, long flags
= wxPROP_BUTTON_DEFAULT
);
81 ~wxPropertyListView(void);
83 // Associates and shows the view
84 virtual void ShowView(wxPropertySheet
*propertySheet
, wxPanel
*panel
);
86 // Update this view of the viewed object, called e.g. by
88 virtual bool OnUpdateView(void);
90 wxString
MakeNameValueString(wxString name
, wxString value
);
92 // Update a single line in the list of properties
93 virtual bool UpdatePropertyDisplayInList(wxProperty
*property
);
95 // Update the whole list
96 virtual bool UpdatePropertyList(bool clearEditArea
= TRUE
);
98 // Find the wxListBox index corresponding to this property
99 virtual int FindListIndexForProperty(wxProperty
*property
);
101 // Select and show string representation in editor the given
102 // property. NULL resets to show no property.
103 virtual bool ShowProperty(wxProperty
*property
, bool select
= TRUE
);
104 virtual bool EditProperty(wxProperty
*property
);
106 // Update the display from the property
107 virtual bool DisplayProperty(wxProperty
*property
);
108 // Update the property from the display
109 virtual bool RetrieveProperty(wxProperty
*property
);
111 // Find appropriate validator and load property into value controls
112 virtual bool BeginShowingProperty(wxProperty
*property
);
113 // Find appropriate validator and unload property from value controls
114 virtual bool EndShowingProperty(wxProperty
*property
);
116 // Begin detailed editing (e.g. using value listbox)
117 virtual void BeginDetailedEditing(void);
119 // End detailed editing (e.g. using value listbox)
120 virtual void EndDetailedEditing(void);
122 // Called by the property listbox
123 void OnPropertySelect(wxCommandEvent
& event
);
125 // Called by the value listbox
126 void OnValueListSelect(wxCommandEvent
& event
);
128 virtual bool CreateControls(void);
129 virtual void ShowTextControl(bool show
);
130 virtual void ShowListBoxControl(bool show
);
131 virtual void EnableCheck(bool show
);
132 virtual void EnableCross(bool show
);
134 void OnOk(wxCommandEvent
& event
);
135 void OnCancel(wxCommandEvent
& event
);
136 void OnHelp(wxCommandEvent
& event
);
137 void OnPropertyDoubleClick(wxCommandEvent
& event
);
138 // virtual void OnDoubleClick(void);
140 void OnCheck(wxCommandEvent
& event
);
141 void OnCross(wxCommandEvent
& event
);
142 void OnEdit(wxCommandEvent
& event
);
143 void OnText(wxCommandEvent
& event
);
145 inline virtual wxListBox
*GetPropertyScrollingList() const { return m_propertyScrollingList
; }
146 inline virtual wxListBox
*GetValueList() const { return m_valueList
; }
147 inline virtual wxTextCtrl
*GetValueText() const { return m_valueText
; }
148 inline virtual wxButton
*GetConfirmButton() const { return m_confirmButton
; }
149 inline virtual wxButton
*GetCancelButton() const { return m_cancelButton
; }
150 inline virtual wxButton
*GetEditButton() const { return m_editButton
; }
151 inline virtual bool GetDetailedEditing(void) const { return m_detailedEditing
; }
153 inline virtual void AssociatePanel(wxPanel
*win
) { m_propertyWindow
= win
; }
154 inline virtual wxPanel
*GetPanel(void) const { return m_propertyWindow
; }
156 inline virtual void SetManagedWindow(wxWindow
*win
) { m_managedWindow
= win
; }
157 inline virtual wxWindow
*GetManagedWindow(void) const { return m_managedWindow
; }
159 inline virtual wxButton
*GetWindowCloseButton() const { return m_windowCloseButton
; }
160 inline virtual wxButton
*GetWindowCancelButton() const { return m_windowCancelButton
; }
161 inline virtual wxButton
*GetHelpButton() const { return m_windowHelpButton
; }
166 static bool sm_dialogCancelled
;
169 wxListBox
* m_propertyScrollingList
;
170 wxListBox
* m_valueList
; // Should really be a combobox, but we don't have one.
171 wxTextCtrl
* m_valueText
;
172 wxButton
* m_confirmButton
; // A tick, as in VB
173 wxButton
* m_cancelButton
; // A cross, as in VB
174 wxButton
* m_editButton
; // Invokes the custom validator, if any
176 bool m_detailedEditing
; // E.g. using listbox for choices
178 static wxBitmap
* sm_tickBitmap
;
179 static wxBitmap
* sm_crossBitmap
;
181 wxPanel
* m_propertyWindow
; // Panel that the controls will appear on
182 wxWindow
* m_managedWindow
; // Frame or dialog
184 wxButton
* m_windowCloseButton
; // Or OK
185 wxButton
* m_windowCancelButton
;
186 wxButton
* m_windowHelpButton
;
188 DECLARE_EVENT_TABLE()
190 virtual void ShowView(wxPropertySheet
*propertySheet
, wxWindow
*window
)
191 { wxPropertyView::ShowView(propertySheet
, window
); };
194 class WXDLLEXPORT wxPropertyTextEdit
: public wxTextCtrl
196 DECLARE_CLASS(wxPropertyTextEdit
)
198 wxPropertyTextEdit(wxPropertyListView
*v
, wxWindow
*parent
, const wxWindowID id
,
199 const wxString
& value
, const wxPoint
& pos
= wxDefaultPosition
,
200 const wxSize
& size
= wxDefaultSize
, long style
= 0, const wxString
& name
= "text");
201 void OnSetFocus(void);
202 void OnKillFocus(void);
204 wxPropertyListView
* m_view
;
207 #define wxPROP_ALLOW_TEXT_EDITING 1
210 * The type of validator used for property lists (Visual Basic style)
213 class WXDLLEXPORT wxPropertyListValidator
: public wxPropertyValidator
215 DECLARE_DYNAMIC_CLASS(wxPropertyListValidator
)
218 wxPropertyListValidator(long flags
= wxPROP_ALLOW_TEXT_EDITING
): wxPropertyValidator(flags
) { }
219 ~wxPropertyListValidator(void) {}
221 // Called when the property is selected or deselected: typically displays the value
222 // in the edit control (having chosen a suitable control to display: (non)editable text or listbox)
223 virtual bool OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
225 // Called when the property is double clicked. Extra functionality can be provided, such as
226 // cycling through possible values.
227 inline virtual bool OnDoubleClick(
228 wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
) )
231 // Called when the value listbox is selected. Default behaviour is to copy
232 // string to text control, and retrieve the value into the property.
233 virtual bool OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
235 // Called when the property value is edited using standard text control
236 inline virtual bool OnPrepareControls(
237 wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
) )
240 virtual bool OnClearControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
242 // Called when the property is edited in detail
243 inline virtual bool OnPrepareDetailControls(
244 wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
) )
247 // Called if focus lost, IF we're in a modeless property editing situation.
248 inline virtual bool OnClearDetailControls(
249 wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
) )
252 // Called when the edit (...) button is pressed. The default implementation
253 // calls view->BeginDetailedEditing; the filename validator (for example) overrides
254 // this function to show the file selector.
255 virtual void OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
257 // Called when TICK is pressed or focus is lost.
258 // Return FALSE if value didn't check out; signal to restore old value.
259 inline virtual bool OnCheckValue(
260 wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
) )
263 // Called when TICK is pressed or focus is lost or view wants to update
264 // the property list.
265 // Does the transferance from the property editing area to the property itself
266 virtual bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
268 virtual bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
272 * A default dialog box class to use.
275 class WXDLLEXPORT wxPropertyListDialog
: public wxDialog
277 DECLARE_CLASS(wxPropertyListDialog
)
279 wxPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
, const wxString
& title
,
280 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
281 long style
= wxDEFAULT_DIALOG_STYLE
, const wxString
& name
= "dialogBox");
282 void OnCloseWindow(wxCloseEvent
& event
);
283 void OnDefaultAction(wxControl
*item
);
284 void OnCancel(wxCommandEvent
& event
);
286 // Extend event processing to search the view's event table
287 virtual bool ProcessEvent(wxEvent
& event
);
290 wxPropertyListView
* m_view
;
292 DECLARE_EVENT_TABLE()
296 * A default panel class to use.
299 class WXDLLEXPORT wxPropertyListPanel
: public wxPanel
301 DECLARE_CLASS(wxPropertyListPanel
)
303 wxPropertyListPanel(wxPropertyListView
*v
, wxWindow
*parent
, const wxPoint
& pos
= wxDefaultPosition
,
304 const wxSize
& size
= wxDefaultSize
,
305 long style
= 0, const wxString
& name
= "panel"):
306 wxPanel(parent
, -1, pos
, size
, style
, name
)
310 ~wxPropertyListPanel();
311 void OnDefaultAction(wxControl
*item
);
313 inline void SetView(wxPropertyListView
* v
) { m_view
= v
; }
314 inline wxPropertyListView
* GetView() const { return m_view
; }
316 // Extend event processing to search the view's event table
317 virtual bool ProcessEvent(wxEvent
& event
);
320 void OnSize(wxSizeEvent
& event
);
323 wxPropertyListView
* m_view
;
325 DECLARE_EVENT_TABLE()
329 * A default frame class to use.
332 class WXDLLEXPORT wxPropertyListFrame
: public wxFrame
334 DECLARE_CLASS(wxPropertyListFrame
)
336 wxPropertyListFrame(wxPropertyListView
*v
, wxFrame
*parent
, const wxString
& title
,
337 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
,
338 long style
= wxDEFAULT_FRAME_STYLE
, const wxString
& name
= "frame"):
339 wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
342 m_propertyPanel
= NULL
;
344 void OnCloseWindow(wxCloseEvent
& event
);
346 // Must call this to create panel and associate view
347 virtual bool Initialize(void);
348 virtual wxPropertyListPanel
*OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
);
349 inline virtual wxPropertyListPanel
*GetPropertyPanel(void) const { return m_propertyPanel
; }
352 wxPropertyListView
* m_view
;
353 wxPropertyListPanel
* m_propertyPanel
;
355 DECLARE_EVENT_TABLE()
359 * Some default validators
362 class WXDLLEXPORT wxRealListValidator
: public wxPropertyListValidator
364 DECLARE_DYNAMIC_CLASS(wxRealListValidator
)
366 // 0.0, 0.0 means no range
367 wxRealListValidator(float min
= 0.0, float max
= 0.0, long flags
= wxPROP_ALLOW_TEXT_EDITING
):wxPropertyListValidator(flags
)
369 m_realMin
= min
; m_realMax
= max
;
371 ~wxRealListValidator(void) {}
373 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
375 // Called when TICK is pressed or focus is lost.
376 // Return FALSE if value didn't check out; signal to restore old value.
377 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
379 // Called when TICK is pressed or focus is lost or view wants to update
380 // the property list.
381 // Does the transfer from the property editing area to the property itself
382 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
389 class WXDLLEXPORT wxIntegerListValidator
: public wxPropertyListValidator
391 DECLARE_DYNAMIC_CLASS(wxIntegerListValidator
)
393 // 0, 0 means no range
394 wxIntegerListValidator(long min
= 0, long max
= 0, long flags
= wxPROP_ALLOW_TEXT_EDITING
):wxPropertyListValidator(flags
)
396 m_integerMin
= min
; m_integerMax
= max
;
398 ~wxIntegerListValidator(void) {}
400 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
402 // Called when TICK is pressed or focus is lost.
403 // Return FALSE if value didn't check out; signal to restore old value.
404 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
406 // Called when TICK is pressed or focus is lost or view wants to update
407 // the property list.
408 // Does the transfer from the property editing area to the property itself
409 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
416 class WXDLLEXPORT wxBoolListValidator
: public wxPropertyListValidator
418 DECLARE_DYNAMIC_CLASS(wxBoolListValidator
)
421 wxBoolListValidator(long flags
= 0):wxPropertyListValidator(flags
)
424 ~wxBoolListValidator(void) {}
426 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
427 bool OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
428 bool OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
430 // Called when TICK is pressed or focus is lost.
431 // Return FALSE if value didn't check out; signal to restore old value.
432 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
434 // Called when TICK is pressed or focus is lost or view wants to update
435 // the property list.
436 // Does the transfer from the property editing area to the property itself
437 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
438 bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
440 // Called when the property is double clicked. Extra functionality can be provided,
441 // cycling through possible values.
442 virtual bool OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
445 class WXDLLEXPORT wxStringListValidator
: public wxPropertyListValidator
447 DECLARE_DYNAMIC_CLASS(wxStringListValidator
)
449 wxStringListValidator(wxStringList
*list
= NULL
, long flags
= 0);
451 ~wxStringListValidator(void)
457 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
458 bool OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
459 bool OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
461 // Called when TICK is pressed or focus is lost.
462 // Return FALSE if value didn't check out; signal to restore old value.
463 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
465 // Called when TICK is pressed or focus is lost or view wants to update
466 // the property list.
467 // Does the transfer from the property editing area to the property itself
468 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
469 bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
471 // Called when the property is double clicked. Extra functionality can be provided,
472 // cycling through possible values.
473 bool OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
476 wxStringList
* m_strings
;
479 class WXDLLEXPORT wxFilenameListValidator
: public wxPropertyListValidator
481 DECLARE_DYNAMIC_CLASS(wxFilenameListValidator
)
483 wxFilenameListValidator(wxString message
= "Select a file", wxString wildcard
= "*.*", long flags
= 0);
485 ~wxFilenameListValidator(void);
487 // Called when TICK is pressed or focus is lost.
488 // Return FALSE if value didn't check out; signal to restore old value.
489 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
491 // Called when TICK is pressed or focus is lost or view wants to update
492 // the property list.
493 // Does the transferance from the property editing area to the property itself
494 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
495 bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
497 bool OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
499 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
501 // Called when the edit (...) button is pressed.
502 void OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
505 wxString m_filenameWildCard
;
506 wxString m_filenameMessage
;
510 class WXDLLEXPORT wxColourListValidator
: public wxPropertyListValidator
512 DECLARE_DYNAMIC_CLASS(wxColourListValidator
)
515 wxColourListValidator(long flags
= 0);
517 ~wxColourListValidator(void);
519 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
520 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
521 bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
523 bool OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
525 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
527 // Called when the edit (...) button is pressed.
528 void OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
531 class WXDLLEXPORT wxListOfStringsListValidator
: public wxPropertyListValidator
533 DECLARE_DYNAMIC_CLASS(wxListOfStringsListValidator
)
536 wxListOfStringsListValidator(long flags
= 0);
538 ~wxListOfStringsListValidator(void)
542 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
544 // Called when TICK is pressed or focus is lost.
545 // Return FALSE if value didn't check out; signal to restore old value.
546 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
548 // Called when TICK is pressed or focus is lost or view wants to update
549 // the property list.
550 // Does the transfer from the property editing area to the property itself
551 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
552 bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
554 // Called when the property is double clicked.
555 bool OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
557 bool EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const wxChar
*title
= _T("String List Editor"));
559 // Called when the edit (...) button is pressed.
560 void OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);