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"
53 #define wxPROP_BUTTON_CLOSE 1
54 #define wxPROP_BUTTON_OK 2
55 #define wxPROP_BUTTON_CANCEL 4
56 #define wxPROP_BUTTON_CHECK_CROSS 8
57 #define wxPROP_BUTTON_HELP 16
58 #define wxPROP_DYNAMIC_VALUE_FIELD 32
59 #define wxPROP_PULLDOWN 64
60 #define wxPROP_SHOWVALUES 128
62 // Show OK/Cancel buttons on X-based systems where window management is
64 #if defined(__WXMOTIF__) || defined(__WXGTK__)
65 #define wxPROP_BUTTON_DEFAULT wxPROP_BUTTON_OK | wxPROP_BUTTON_CANCEL | wxPROP_BUTTON_CHECK_CROSS | wxPROP_PULLDOWN
67 #define wxPROP_BUTTON_DEFAULT wxPROP_BUTTON_CHECK_CROSS | wxPROP_PULLDOWN | wxPROP_SHOWVALUES
70 #define wxID_PROP_CROSS 3000
71 #define wxID_PROP_CHECK 3001
72 #define wxID_PROP_EDIT 3002
73 #define wxID_PROP_TEXT 3003
74 #define wxID_PROP_SELECT 3004
75 #define wxID_PROP_VALUE_SELECT 3005
77 // Mediates between a physical panel and the property sheet
78 class WXDLLEXPORT wxPropertyListView
: public wxPropertyView
80 DECLARE_DYNAMIC_CLASS(wxPropertyListView
)
82 wxPropertyListView(wxPanel
*propPanel
= NULL
, long flags
= wxPROP_BUTTON_DEFAULT
);
83 ~wxPropertyListView(void);
85 // Associates and shows the view
86 virtual void ShowView(wxPropertySheet
*propertySheet
, wxPanel
*panel
);
88 // Update this view of the viewed object, called e.g. by
90 virtual bool OnUpdateView(void);
92 wxString
MakeNameValueString(wxString name
, wxString value
);
94 // Update a single line in the list of properties
95 virtual bool UpdatePropertyDisplayInList(wxProperty
*property
);
97 // Update the whole list
98 virtual bool UpdatePropertyList(bool clearEditArea
= TRUE
);
100 // Find the wxListBox index corresponding to this property
101 virtual int FindListIndexForProperty(wxProperty
*property
);
103 // Select and show string representation in editor the given
104 // property. NULL resets to show no property.
105 virtual bool ShowProperty(wxProperty
*property
, bool select
= TRUE
);
106 virtual bool EditProperty(wxProperty
*property
);
108 // Update the display from the property
109 virtual bool DisplayProperty(wxProperty
*property
);
110 // Update the property from the display
111 virtual bool RetrieveProperty(wxProperty
*property
);
113 // Find appropriate validator and load property into value controls
114 virtual bool BeginShowingProperty(wxProperty
*property
);
115 // Find appropriate validator and unload property from value controls
116 virtual bool EndShowingProperty(wxProperty
*property
);
118 // Begin detailed editing (e.g. using value listbox)
119 virtual void BeginDetailedEditing(void);
121 // End detailed editing (e.g. using value listbox)
122 virtual void EndDetailedEditing(void);
124 // Called by the property listbox
125 void OnPropertySelect(wxCommandEvent
& event
);
127 // Called by the value listbox
128 void OnValueListSelect(wxCommandEvent
& event
);
130 virtual bool CreateControls(void);
131 virtual void ShowTextControl(bool show
);
132 virtual void ShowListBoxControl(bool show
);
133 virtual void EnableCheck(bool show
);
134 virtual void EnableCross(bool show
);
136 void OnOk(wxCommandEvent
& event
);
137 void OnCancel(wxCommandEvent
& event
);
138 void OnHelp(wxCommandEvent
& event
);
139 void OnPropertyDoubleClick(wxCommandEvent
& event
);
140 // virtual void OnDoubleClick(void);
142 void OnCheck(wxCommandEvent
& event
);
143 void OnCross(wxCommandEvent
& event
);
144 void OnEdit(wxCommandEvent
& event
);
145 void OnText(wxCommandEvent
& event
);
147 inline virtual wxListBox
*GetPropertyScrollingList() const { return m_propertyScrollingList
; }
148 inline virtual wxListBox
*GetValueList() const { return m_valueList
; }
149 inline virtual wxTextCtrl
*GetValueText() const { return m_valueText
; }
150 inline virtual wxButton
*GetConfirmButton() const { return m_confirmButton
; }
151 inline virtual wxButton
*GetCancelButton() const { return m_cancelButton
; }
152 inline virtual wxButton
*GetEditButton() const { return m_editButton
; }
153 inline virtual bool GetDetailedEditing(void) const { return m_detailedEditing
; }
155 inline virtual void AssociatePanel(wxPanel
*win
) { m_propertyWindow
= win
; }
156 inline virtual wxPanel
*GetPanel(void) const { return m_propertyWindow
; }
158 inline virtual void SetManagedWindow(wxWindow
*win
) { m_managedWindow
= win
; }
159 inline virtual wxWindow
*GetManagedWindow(void) const { return m_managedWindow
; }
161 inline virtual wxButton
*GetWindowCloseButton() const { return m_windowCloseButton
; }
162 inline virtual wxButton
*GetWindowCancelButton() const { return m_windowCancelButton
; }
163 inline virtual wxButton
*GetHelpButton() const { return m_windowHelpButton
; }
168 static bool sm_dialogCancelled
;
171 wxListBox
* m_propertyScrollingList
;
172 wxListBox
* m_valueList
; // Should really be a combobox, but we don't have one.
173 wxTextCtrl
* m_valueText
;
174 wxButton
* m_confirmButton
; // A tick, as in VB
175 wxButton
* m_cancelButton
; // A cross, as in VB
176 wxButton
* m_editButton
; // Invokes the custom validator, if any
177 wxSizer
* m_middleSizer
;
179 bool m_detailedEditing
; // E.g. using listbox for choices
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
197 wxPropertyTextEdit(wxPropertyListView
*v
= NULL
,
198 wxWindow
*parent
= NULL
,
199 const wxWindowID id
= -1,
200 const wxString
& value
= wxEmptyString
,
201 const wxPoint
& pos
= wxDefaultPosition
,
202 const wxSize
& size
= wxDefaultSize
,
204 const wxString
& name
= _T("text"));
209 wxPropertyListView
* m_view
;
211 DECLARE_CLASS(wxPropertyTextEdit
)
214 #define wxPROP_ALLOW_TEXT_EDITING 1
217 * The type of validator used for property lists (Visual Basic style)
220 class WXDLLEXPORT wxPropertyListValidator
: public wxPropertyValidator
222 DECLARE_DYNAMIC_CLASS(wxPropertyListValidator
)
225 wxPropertyListValidator(long flags
= wxPROP_ALLOW_TEXT_EDITING
): wxPropertyValidator(flags
) { }
226 ~wxPropertyListValidator(void) {}
228 // Called when the property is selected or deselected: typically displays the value
229 // in the edit control (having chosen a suitable control to display: (non)editable text or listbox)
230 virtual bool OnSelect(bool select
, wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
232 // Called when the property is double clicked. Extra functionality can be provided, such as
233 // cycling through possible values.
234 inline virtual bool OnDoubleClick(
235 wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
) )
238 // Called when the value listbox is selected. Default behaviour is to copy
239 // string to text control, and retrieve the value into the property.
240 virtual bool OnValueListSelect(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
242 // Called when the property value is edited using standard text control
243 inline virtual bool OnPrepareControls(
244 wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
) )
247 virtual bool OnClearControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
249 // Called when the property is edited in detail
250 inline virtual bool OnPrepareDetailControls(
251 wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
) )
254 // Called if focus lost, IF we're in a modeless property editing situation.
255 inline virtual bool OnClearDetailControls(
256 wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
) )
259 // Called when the edit (...) button is pressed. The default implementation
260 // calls view->BeginDetailedEditing; the filename validator (for example) overrides
261 // this function to show the file selector.
262 virtual void OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
264 // Called when TICK is pressed or focus is lost.
265 // Return FALSE if value didn't check out; signal to restore old value.
266 inline virtual bool OnCheckValue(
267 wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
) )
270 // Called when TICK is pressed or focus is lost or view wants to update
271 // the property list.
272 // Does the transferance from the property editing area to the property itself
273 virtual bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
275 virtual bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
279 * A default dialog box class to use.
282 class WXDLLEXPORT wxPropertyListDialog
: public wxDialog
285 wxPropertyListDialog(wxPropertyListView
*v
= NULL
,
286 wxWindow
*parent
= NULL
,
287 const wxString
& title
= wxEmptyString
,
288 const wxPoint
& pos
= wxDefaultPosition
,
289 const wxSize
& size
= wxDefaultSize
,
290 long style
= wxDEFAULT_DIALOG_STYLE
,
291 const wxString
& name
= _T("dialogBox"));
293 void OnCloseWindow(wxCloseEvent
& event
);
294 void OnDefaultAction(wxControl
*item
);
295 void OnCancel(wxCommandEvent
& event
);
297 // Extend event processing to search the view's event table
298 virtual bool ProcessEvent(wxEvent
& event
);
301 wxPropertyListView
* m_view
;
303 DECLARE_CLASS(wxPropertyListDialog
)
304 DECLARE_EVENT_TABLE()
308 * A default panel class to use.
311 class WXDLLEXPORT wxPropertyListPanel
: public wxPanel
314 wxPropertyListPanel(wxPropertyListView
*v
= NULL
,
315 wxWindow
*parent
= NULL
,
316 const wxPoint
& pos
= wxDefaultPosition
,
317 const wxSize
& size
= wxDefaultSize
,
319 const wxString
& name
= _T("panel"))
320 : wxPanel(parent
, -1, pos
, size
, style
, name
)
324 ~wxPropertyListPanel();
325 void OnDefaultAction(wxControl
*item
);
327 inline void SetView(wxPropertyListView
* v
) { m_view
= v
; }
328 inline wxPropertyListView
* GetView() const { return m_view
; }
330 // Extend event processing to search the view's event table
331 virtual bool ProcessEvent(wxEvent
& event
);
334 void OnSize(wxSizeEvent
& event
);
337 wxPropertyListView
* m_view
;
339 DECLARE_EVENT_TABLE()
340 DECLARE_CLASS(wxPropertyListPanel
)
344 * A default frame class to use.
347 class WXDLLEXPORT wxPropertyListFrame
: public wxFrame
350 wxPropertyListFrame(wxPropertyListView
*v
= NULL
,
351 wxFrame
*parent
= NULL
,
352 const wxString
& title
= wxEmptyString
,
353 const wxPoint
& pos
= wxDefaultPosition
,
354 const wxSize
& size
= wxDefaultSize
,
355 long style
= wxDEFAULT_FRAME_STYLE
,
356 const wxString
& name
= _T("frame"))
357 : wxFrame(parent
, -1, title
, pos
, size
, style
, name
)
360 m_propertyPanel
= NULL
;
362 void OnCloseWindow(wxCloseEvent
& event
);
364 // Must call this to create panel and associate view
365 virtual bool Initialize(void);
366 virtual wxPropertyListPanel
*OnCreatePanel(wxFrame
*parent
, wxPropertyListView
*v
);
367 inline virtual wxPropertyListPanel
*GetPropertyPanel(void) const { return m_propertyPanel
; }
368 inline wxPropertyListView
* GetView() const { return m_view
; }
371 wxPropertyListView
* m_view
;
372 wxPropertyListPanel
* m_propertyPanel
;
374 DECLARE_EVENT_TABLE()
375 DECLARE_CLASS(wxPropertyListFrame
)
379 * Some default validators
382 class WXDLLEXPORT wxRealListValidator
: public wxPropertyListValidator
384 DECLARE_DYNAMIC_CLASS(wxRealListValidator
)
386 // 0.0, 0.0 means no range
387 wxRealListValidator(float min
= 0.0, float max
= 0.0, long flags
= wxPROP_ALLOW_TEXT_EDITING
):wxPropertyListValidator(flags
)
389 m_realMin
= min
; m_realMax
= max
;
391 ~wxRealListValidator(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 WXDLLEXPORT wxIntegerListValidator
: public wxPropertyListValidator
411 DECLARE_DYNAMIC_CLASS(wxIntegerListValidator
)
413 // 0, 0 means no range
414 wxIntegerListValidator(long min
= 0, long max
= 0, long flags
= wxPROP_ALLOW_TEXT_EDITING
):wxPropertyListValidator(flags
)
416 m_integerMin
= min
; m_integerMax
= max
;
418 ~wxIntegerListValidator(void) {}
420 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
422 // Called when TICK is pressed or focus is lost.
423 // Return FALSE if value didn't check out; signal to restore old value.
424 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
426 // Called when TICK is pressed or focus is lost or view wants to update
427 // the property list.
428 // Does the transfer from the property editing area to the property itself
429 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
436 class WXDLLEXPORT wxBoolListValidator
: public wxPropertyListValidator
438 DECLARE_DYNAMIC_CLASS(wxBoolListValidator
)
441 wxBoolListValidator(long flags
= 0):wxPropertyListValidator(flags
)
444 ~wxBoolListValidator(void) {}
446 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
447 bool OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
448 bool OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
450 // Called when TICK is pressed or focus is lost.
451 // Return FALSE if value didn't check out; signal to restore old value.
452 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
454 // Called when TICK is pressed or focus is lost or view wants to update
455 // the property list.
456 // Does the transfer from the property editing area to the property itself
457 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
458 bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
460 // Called when the property is double clicked. Extra functionality can be provided,
461 // cycling through possible values.
462 virtual bool OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
465 class WXDLLEXPORT wxStringListValidator
: public wxPropertyListValidator
467 DECLARE_DYNAMIC_CLASS(wxStringListValidator
)
469 wxStringListValidator(wxStringList
*list
= NULL
, long flags
= 0);
471 ~wxStringListValidator(void)
477 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
478 bool OnPrepareDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
479 bool OnClearDetailControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
481 // Called when TICK is pressed or focus is lost.
482 // Return FALSE if value didn't check out; signal to restore old value.
483 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
485 // Called when TICK is pressed or focus is lost or view wants to update
486 // the property list.
487 // Does the transfer from the property editing area to the property itself
488 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
489 bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
491 // Called when the property is double clicked. Extra functionality can be provided,
492 // cycling through possible values.
493 bool OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
496 wxStringList
* m_strings
;
499 class WXDLLEXPORT wxFilenameListValidator
: public wxPropertyListValidator
501 DECLARE_DYNAMIC_CLASS(wxFilenameListValidator
)
503 wxFilenameListValidator(wxString message
= "Select a file", wxString wildcard
= wxALL_FILES_PATTERN
, long flags
= 0);
505 ~wxFilenameListValidator(void);
507 // Called when TICK is pressed or focus is lost.
508 // Return FALSE if value didn't check out; signal to restore old value.
509 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
511 // Called when TICK is pressed or focus is lost or view wants to update
512 // the property list.
513 // Does the transferance from the property editing area to the property itself
514 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
515 bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
517 bool OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
519 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
521 // Called when the edit (...) button is pressed.
522 void OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
525 wxString m_filenameWildCard
;
526 wxString m_filenameMessage
;
530 class WXDLLEXPORT wxColourListValidator
: public wxPropertyListValidator
532 DECLARE_DYNAMIC_CLASS(wxColourListValidator
)
535 wxColourListValidator(long flags
= 0);
537 ~wxColourListValidator(void);
539 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
540 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
541 bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
543 bool OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
545 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
547 // Called when the edit (...) button is pressed.
548 void OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
551 class WXDLLEXPORT wxListOfStringsListValidator
: public wxPropertyListValidator
553 DECLARE_DYNAMIC_CLASS(wxListOfStringsListValidator
)
556 wxListOfStringsListValidator(long flags
= 0);
558 ~wxListOfStringsListValidator(void)
562 bool OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
564 // Called when TICK is pressed or focus is lost.
565 // Return FALSE if value didn't check out; signal to restore old value.
566 bool OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
568 // Called when TICK is pressed or focus is lost or view wants to update
569 // the property list.
570 // Does the transfer from the property editing area to the property itself
571 bool OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
572 bool OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
574 // Called when the property is double clicked.
575 bool OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);
577 bool EditStringList(wxWindow
*parent
, wxStringList
*stringList
, const wxChar
*title
= wxT("String List Editor"));
579 // Called when the edit (...) button is pressed.
580 void OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
);