]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/proplist.h
Various small fixes
[wxWidgets.git] / include / wx / proplist.h
... / ...
CommitLineData
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 licence
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 _WX_PROPLIST_H_
43#define _WX_PROPLIST_H_
44
45#ifdef __GNUG__
46#pragma interface "proplist.h"
47#endif
48
49#include "wx/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// Show OK/Cancel buttons on X-based systems where window management is
61// more awkward
62#if defined(__WXMOTIF__) || defined(__WXGTK__)
63#define wxPROP_BUTTON_DEFAULT wxPROP_BUTTON_OK | wxPROP_BUTTON_CANCEL | wxPROP_BUTTON_CHECK_CROSS | wxPROP_PULLDOWN
64#else
65#define wxPROP_BUTTON_DEFAULT wxPROP_BUTTON_CHECK_CROSS | wxPROP_PULLDOWN | wxPROP_SHOWVALUES
66#endif
67
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
74
75// Mediates between a physical panel and the property sheet
76class WXDLLEXPORT wxPropertyListView: public wxPropertyView
77{
78 DECLARE_DYNAMIC_CLASS(wxPropertyListView)
79 public:
80 wxPropertyListView(wxPanel *propPanel = NULL, long flags = wxPROP_BUTTON_DEFAULT);
81 ~wxPropertyListView(void);
82
83 // Associates and shows the view
84 virtual void ShowView(wxPropertySheet *propertySheet, wxPanel *panel);
85
86 // Update this view of the viewed object, called e.g. by
87 // the object itself.
88 virtual bool OnUpdateView(void);
89
90 wxString MakeNameValueString(wxString name, wxString value);
91
92 // Update a single line in the list of properties
93 virtual bool UpdatePropertyDisplayInList(wxProperty *property);
94
95 // Update the whole list
96 virtual bool UpdatePropertyList(bool clearEditArea = TRUE);
97
98 // Find the wxListBox index corresponding to this property
99 virtual int FindListIndexForProperty(wxProperty *property);
100
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);
105
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);
110
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);
115
116 // Begin detailed editing (e.g. using value listbox)
117 virtual void BeginDetailedEditing(void);
118
119 // End detailed editing (e.g. using value listbox)
120 virtual void EndDetailedEditing(void);
121
122 // Called by the property listbox
123 void OnPropertySelect(wxCommandEvent& event);
124
125 // Called by the value listbox
126 void OnValueListSelect(wxCommandEvent& event);
127
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);
133
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);
139
140 void OnCheck(wxCommandEvent& event);
141 void OnCross(wxCommandEvent& event);
142 void OnEdit(wxCommandEvent& event);
143 void OnText(wxCommandEvent& event);
144
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; }
152
153 inline virtual void AssociatePanel(wxPanel *win) { m_propertyWindow = win; }
154 inline virtual wxPanel *GetPanel(void) const { return m_propertyWindow; }
155
156 inline virtual void SetManagedWindow(wxWindow *win) { m_managedWindow = win; }
157 inline virtual wxWindow *GetManagedWindow(void) const { return m_managedWindow; }
158
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; }
162
163 bool OnClose(void);
164
165public:
166 static bool sm_dialogCancelled;
167
168 protected:
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
175
176 bool m_detailedEditing; // E.g. using listbox for choices
177
178 static wxBitmap* sm_tickBitmap;
179 static wxBitmap* sm_crossBitmap;
180
181 wxPanel* m_propertyWindow; // Panel that the controls will appear on
182 wxWindow* m_managedWindow; // Frame or dialog
183
184 wxButton* m_windowCloseButton; // Or OK
185 wxButton* m_windowCancelButton;
186 wxButton* m_windowHelpButton;
187
188DECLARE_EVENT_TABLE()
189};
190
191class WXDLLEXPORT wxPropertyTextEdit: public wxTextCtrl
192{
193 DECLARE_CLASS(wxPropertyTextEdit)
194 public:
195 wxPropertyTextEdit(wxPropertyListView *v, wxWindow *parent, const wxWindowID id,
196 const wxString& value, const wxPoint& pos = wxDefaultPosition,
197 const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = "text");
198 void OnSetFocus(void);
199 void OnKillFocus(void);
200
201 wxPropertyListView* m_view;
202};
203
204#define wxPROP_ALLOW_TEXT_EDITING 1
205
206/*
207 * The type of validator used for property lists (Visual Basic style)
208 */
209
210class WXDLLEXPORT wxPropertyListValidator: public wxPropertyValidator
211{
212 DECLARE_DYNAMIC_CLASS(wxPropertyListValidator)
213 protected:
214 public:
215 wxPropertyListValidator(long flags = wxPROP_ALLOW_TEXT_EDITING): wxPropertyValidator(flags) { }
216 ~wxPropertyListValidator(void) {}
217
218 // Called when the property is selected or deselected: typically displays the value
219 // in the edit control (having chosen a suitable control to display: (non)editable text or listbox)
220 virtual bool OnSelect(bool select, wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
221
222 // Called when the property is double clicked. Extra functionality can be provided, such as
223 // cycling through possible values.
224 inline virtual bool OnDoubleClick(
225 wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow) )
226 { return TRUE; }
227
228 // Called when the value listbox is selected. Default behaviour is to copy
229 // string to text control, and retrieve the value into the property.
230 virtual bool OnValueListSelect(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
231
232 // Called when the property value is edited using standard text control
233 inline virtual bool OnPrepareControls(
234 wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow) )
235 { return TRUE; }
236
237 virtual bool OnClearControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
238
239 // Called when the property is edited in detail
240 inline virtual bool OnPrepareDetailControls(
241 wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow) )
242 { return TRUE; }
243
244 // Called if focus lost, IF we're in a modeless property editing situation.
245 inline virtual bool OnClearDetailControls(
246 wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow) )
247 { return TRUE; }
248
249 // Called when the edit (...) button is pressed. The default implementation
250 // calls view->BeginDetailedEditing; the filename validator (for example) overrides
251 // this function to show the file selector.
252 virtual void OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
253
254 // Called when TICK is pressed or focus is lost.
255 // Return FALSE if value didn't check out; signal to restore old value.
256 inline virtual bool OnCheckValue(
257 wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow) )
258 { return TRUE; }
259
260 // Called when TICK is pressed or focus is lost or view wants to update
261 // the property list.
262 // Does the transferance from the property editing area to the property itself
263 virtual bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
264
265 virtual bool OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
266};
267
268/*
269 * A default dialog box class to use.
270 */
271
272class WXDLLEXPORT wxPropertyListDialog: public wxDialog
273{
274 DECLARE_CLASS(wxPropertyListDialog)
275 public:
276 wxPropertyListDialog(wxPropertyListView *v, wxWindow *parent, const wxString& title,
277 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
278 long style = wxDEFAULT_DIALOG_STYLE, const wxString& name = "dialogBox");
279 bool OnClose(void);
280 void OnDefaultAction(wxControl *item);
281 void OnCancel(wxCommandEvent& event);
282
283 // Extend event processing to search the view's event table
284 virtual bool ProcessEvent(wxEvent& event);
285
286 private:
287 wxPropertyListView* m_view;
288
289DECLARE_EVENT_TABLE()
290};
291
292/*
293 * A default panel class to use.
294 */
295
296class WXDLLEXPORT wxPropertyListPanel: public wxPanel
297{
298 DECLARE_CLASS(wxPropertyListPanel)
299 public:
300 wxPropertyListPanel(wxPropertyListView *v, wxWindow *parent, const wxPoint& pos = wxDefaultPosition,
301 const wxSize& size = wxDefaultSize,
302 long style = 0, const wxString& name = "panel"):
303 wxPanel(parent, -1, pos, size, style, name)
304 {
305 m_view = v;
306 }
307 ~wxPropertyListPanel();
308 void OnDefaultAction(wxControl *item);
309
310 inline void SetView(wxPropertyListView* v) { m_view = v; }
311 inline wxPropertyListView* GetView() const { return m_view; }
312
313 // Extend event processing to search the view's event table
314 virtual bool ProcessEvent(wxEvent& event);
315
316 // Call Layout()
317 void OnSize(wxSizeEvent& event);
318
319 private:
320 wxPropertyListView* m_view;
321
322DECLARE_EVENT_TABLE()
323};
324
325/*
326 * A default frame class to use.
327 */
328
329class WXDLLEXPORT wxPropertyListFrame: public wxFrame
330{
331 DECLARE_CLASS(wxPropertyListFrame)
332 public:
333 wxPropertyListFrame(wxPropertyListView *v, wxFrame *parent, const wxString& title,
334 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
335 long style = wxDEFAULT_FRAME_STYLE, const wxString& name = "frame"):
336 wxFrame(parent, -1, title, pos, size, style, name)
337 {
338 m_view = v;
339 m_propertyPanel = NULL;
340 }
341 bool OnClose(void);
342
343 // Must call this to create panel and associate view
344 virtual bool Initialize(void);
345 virtual wxPropertyListPanel *OnCreatePanel(wxFrame *parent, wxPropertyListView *v);
346 inline virtual wxPropertyListPanel *GetPropertyPanel(void) const { return m_propertyPanel; }
347
348 private:
349 wxPropertyListView* m_view;
350 wxPropertyListPanel* m_propertyPanel;
351};
352
353/*
354 * Some default validators
355 */
356
357class WXDLLEXPORT wxRealListValidator: public wxPropertyListValidator
358{
359 DECLARE_DYNAMIC_CLASS(wxRealListValidator)
360 public:
361 // 0.0, 0.0 means no range
362 wxRealListValidator(float min = 0.0, float max = 0.0, long flags = wxPROP_ALLOW_TEXT_EDITING):wxPropertyListValidator(flags)
363 {
364 m_realMin = min; m_realMax = max;
365 }
366 ~wxRealListValidator(void) {}
367
368 bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
369
370 // Called when TICK is pressed or focus is lost.
371 // Return FALSE if value didn't check out; signal to restore old value.
372 bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
373
374 // Called when TICK is pressed or focus is lost or view wants to update
375 // the property list.
376 // Does the transfer from the property editing area to the property itself
377 bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
378
379 protected:
380 float m_realMin;
381 float m_realMax;
382};
383
384class WXDLLEXPORT wxIntegerListValidator: public wxPropertyListValidator
385{
386 DECLARE_DYNAMIC_CLASS(wxIntegerListValidator)
387 public:
388 // 0, 0 means no range
389 wxIntegerListValidator(long min = 0, long max = 0, long flags = wxPROP_ALLOW_TEXT_EDITING):wxPropertyListValidator(flags)
390 {
391 m_integerMin = min; m_integerMax = max;
392 }
393 ~wxIntegerListValidator(void) {}
394
395 bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
396
397 // Called when TICK is pressed or focus is lost.
398 // Return FALSE if value didn't check out; signal to restore old value.
399 bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
400
401 // Called when TICK is pressed or focus is lost or view wants to update
402 // the property list.
403 // Does the transfer from the property editing area to the property itself
404 bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
405
406 protected:
407 long m_integerMin;
408 long m_integerMax;
409};
410
411class WXDLLEXPORT wxBoolListValidator: public wxPropertyListValidator
412{
413 DECLARE_DYNAMIC_CLASS(wxBoolListValidator)
414 protected:
415 public:
416 wxBoolListValidator(long flags = 0):wxPropertyListValidator(flags)
417 {
418 }
419 ~wxBoolListValidator(void) {}
420
421 bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
422 bool OnPrepareDetailControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
423 bool OnClearDetailControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
424
425 // Called when TICK is pressed or focus is lost.
426 // Return FALSE if value didn't check out; signal to restore old value.
427 bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
428
429 // Called when TICK is pressed or focus is lost or view wants to update
430 // the property list.
431 // Does the transfer from the property editing area to the property itself
432 bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
433 bool OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
434
435 // Called when the property is double clicked. Extra functionality can be provided,
436 // cycling through possible values.
437 virtual bool OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
438};
439
440class WXDLLEXPORT wxStringListValidator: public wxPropertyListValidator
441{
442 DECLARE_DYNAMIC_CLASS(wxStringListValidator)
443 public:
444 wxStringListValidator(wxStringList *list = NULL, long flags = 0);
445
446 ~wxStringListValidator(void)
447 {
448 if (m_strings)
449 delete m_strings;
450 }
451
452 bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
453 bool OnPrepareDetailControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
454 bool OnClearDetailControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
455
456 // Called when TICK is pressed or focus is lost.
457 // Return FALSE if value didn't check out; signal to restore old value.
458 bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
459
460 // Called when TICK is pressed or focus is lost or view wants to update
461 // the property list.
462 // Does the transfer from the property editing area to the property itself
463 bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
464 bool OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
465
466 // Called when the property is double clicked. Extra functionality can be provided,
467 // cycling through possible values.
468 bool OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
469
470 protected:
471 wxStringList* m_strings;
472};
473
474class WXDLLEXPORT wxFilenameListValidator: public wxPropertyListValidator
475{
476 DECLARE_DYNAMIC_CLASS(wxFilenameListValidator)
477 public:
478 wxFilenameListValidator(wxString message = "Select a file", wxString wildcard = "*.*", long flags = 0);
479
480 ~wxFilenameListValidator(void);
481
482 // Called when TICK is pressed or focus is lost.
483 // Return FALSE if value didn't check out; signal to restore old value.
484 bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
485
486 // Called when TICK is pressed or focus is lost or view wants to update
487 // the property list.
488 // Does the transferance from the property editing area to the property itself
489 bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
490 bool OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
491
492 bool OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
493
494 bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
495
496 // Called when the edit (...) button is pressed.
497 void OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
498
499 protected:
500 wxString m_filenameWildCard;
501 wxString m_filenameMessage;
502
503};
504
505class WXDLLEXPORT wxColourListValidator: public wxPropertyListValidator
506{
507 DECLARE_DYNAMIC_CLASS(wxColourListValidator)
508 protected:
509 public:
510 wxColourListValidator(long flags = 0);
511
512 ~wxColourListValidator(void);
513
514 bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
515 bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
516 bool OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
517
518 bool OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
519
520 bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
521
522 // Called when the edit (...) button is pressed.
523 void OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
524};
525
526class WXDLLEXPORT wxListOfStringsListValidator: public wxPropertyListValidator
527{
528 DECLARE_DYNAMIC_CLASS(wxListOfStringsListValidator)
529 protected:
530 public:
531 wxListOfStringsListValidator(long flags = 0);
532
533 ~wxListOfStringsListValidator(void)
534 {
535 }
536
537 bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
538
539 // Called when TICK is pressed or focus is lost.
540 // Return FALSE if value didn't check out; signal to restore old value.
541 bool OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
542
543 // Called when TICK is pressed or focus is lost or view wants to update
544 // the property list.
545 // Does the transfer from the property editing area to the property itself
546 bool OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
547 bool OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
548
549 // Called when the property is double clicked.
550 bool OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
551
552 bool EditStringList(wxWindow *parent, wxStringList *stringList, const char *title = "String List Editor");
553
554 // Called when the edit (...) button is pressed.
555 void OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
556};
557
558#endif
559 // _WX_PROPLIST_H_