]> git.saurik.com Git - wxWidgets.git/blame - include/wx/proplist.h
Lots of wxMotif fixes
[wxWidgets.git] / include / wx / proplist.h
CommitLineData
e3a43801
JS
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#ifdef __XVIEW__
61#define wxPROP_BUTTON_DEFAULT wxPROP_BUTTON_OK | wxPROP_BUTTON_CANCEL | wxPROP_BUTTON_CHECK_CROSS | wxPROP_PULLDOWN
62#else
63#define wxPROP_BUTTON_DEFAULT wxPROP_BUTTON_CHECK_CROSS | wxPROP_PULLDOWN | wxPROP_SHOWVALUES
64#endif
65
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
72
73// Mediates between a physical panel and the property sheet
74class wxPropertyListView: public wxPropertyView
75{
76 DECLARE_DYNAMIC_CLASS(wxPropertyListView)
77 public:
78 wxPropertyListView(wxPanel *propPanel = NULL, long flags = wxPROP_BUTTON_DEFAULT);
79 ~wxPropertyListView(void);
80
81 // Associates and shows the view
82 virtual void ShowView(wxPropertySheet *propertySheet, wxPanel *panel);
83
84 // Update this view of the viewed object, called e.g. by
85 // the object itself.
86 virtual bool OnUpdateView(void);
87
88 wxString MakeNameValueString(wxString name, wxString value);
89
90 // Update a single line in the list of properties
91 virtual bool UpdatePropertyDisplayInList(wxProperty *property);
92
93 // Update the whole list
94 virtual bool UpdatePropertyList(bool clearEditArea = TRUE);
95
96 // Find the wxListBox index corresponding to this property
97 virtual int FindListIndexForProperty(wxProperty *property);
98
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);
103
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);
108
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);
113
114 // Begin detailed editing (e.g. using value listbox)
115 virtual void BeginDetailedEditing(void);
116
117 // End detailed editing (e.g. using value listbox)
118 virtual void EndDetailedEditing(void);
119
120 // Called by the property listbox
121 void OnPropertySelect(wxCommandEvent& event);
122
123 // Called by the value listbox
124 void OnValueListSelect(wxCommandEvent& event);
125
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);
131
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);
137
138 void OnCheck(wxCommandEvent& event);
139 void OnCross(wxCommandEvent& event);
140 void OnEdit(wxCommandEvent& event);
141 void OnText(wxCommandEvent& event);
142
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; }
150
151 inline virtual void AssociatePanel(wxPanel *win) { m_propertyWindow = win; }
152 inline virtual wxPanel *GetPanel(void) const { return m_propertyWindow; }
153
154 inline virtual void SetManagedWindow(wxWindow *win) { m_managedWindow = win; }
155 inline virtual wxWindow *GetManagedWindow(void) const { return m_managedWindow; }
156
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; }
160
161 bool OnClose(void);
162
163public:
164 static bool sm_dialogCancelled;
165
166 protected:
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
173
174 bool m_detailedEditing; // E.g. using listbox for choices
175
176 static wxBitmap* sm_tickBitmap;
177 static wxBitmap* sm_crossBitmap;
178
179 wxPanel* m_propertyWindow; // Panel that the controls will appear on
180 wxWindow* m_managedWindow; // Frame or dialog
181
182 wxButton* m_windowCloseButton; // Or OK
183 wxButton* m_windowCancelButton;
184 wxButton* m_windowHelpButton;
185
186DECLARE_EVENT_TABLE()
187};
188
189class wxPropertyTextEdit: public wxTextCtrl
190{
191 DECLARE_CLASS(wxPropertyTextEdit)
192 public:
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);
198
199 wxPropertyListView* m_view;
200};
201
202#define wxPROP_ALLOW_TEXT_EDITING 1
203
204/*
205 * The type of validator used for property lists (Visual Basic style)
206 */
207
208class wxPropertyListValidator: public wxPropertyValidator
209{
210 DECLARE_DYNAMIC_CLASS(wxPropertyListValidator)
211 protected:
212 public:
213 wxPropertyListValidator(long flags = wxPROP_ALLOW_TEXT_EDITING): wxPropertyValidator(flags) { }
214 ~wxPropertyListValidator(void) {}
215
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);
219
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) )
224 { return TRUE; }
225
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);
229
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) )
233 { return TRUE; }
234
235 virtual bool OnClearControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
236
237 // Called when the property is edited in detail
238 inline virtual bool OnPrepareDetailControls(
239 wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow) )
240 { return TRUE; }
241
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) )
245 { return TRUE; }
246
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);
251
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) )
256 { return TRUE; }
257
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);
262
263 virtual bool OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
264};
265
266/*
267 * A default dialog box class to use.
268 */
269
270class wxPropertyListDialog: public wxDialog
271{
272 DECLARE_CLASS(wxPropertyListDialog)
273 public:
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");
277 bool OnClose(void);
278 void OnDefaultAction(wxControl *item);
279 void OnCancel(wxCommandEvent& event);
280
281 // Extend event processing to search the view's event table
282 virtual bool ProcessEvent(wxEvent& event);
283
284 private:
285 wxPropertyListView* m_view;
286
287DECLARE_EVENT_TABLE()
288};
289
290/*
291 * A default panel class to use.
292 */
293
294class wxPropertyListPanel: public wxPanel
295{
296 DECLARE_CLASS(wxPropertyListPanel)
297 public:
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)
302 {
303 m_view = v;
304 }
305 ~wxPropertyListPanel();
306 void OnDefaultAction(wxControl *item);
307
308 inline void SetView(wxPropertyListView* v) { m_view = v; }
309 inline wxPropertyListView* GetView() const { return m_view; }
310
311 // Extend event processing to search the view's event table
312 virtual bool ProcessEvent(wxEvent& event);
313
314 // Call Layout()
315 void OnSize(wxSizeEvent& event);
316
317 private:
318 wxPropertyListView* m_view;
319
320DECLARE_EVENT_TABLE()
321};
322
323/*
324 * A default frame class to use.
325 */
326
327class wxPropertyListFrame: public wxFrame
328{
329 DECLARE_CLASS(wxPropertyListFrame)
330 public:
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)
335 {
336 m_view = v;
337 m_propertyPanel = NULL;
338 }
339 bool OnClose(void);
340
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; }
345
346 private:
347 wxPropertyListView* m_view;
348 wxPropertyListPanel* m_propertyPanel;
349};
350
351/*
352 * Some default validators
353 */
354
355class wxRealListValidator: public wxPropertyListValidator
356{
357 DECLARE_DYNAMIC_CLASS(wxRealListValidator)
358 public:
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)
361 {
362 m_realMin = min; m_realMax = max;
363 }
364 ~wxRealListValidator(void) {}
365
366 bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
367
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);
371
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);
376
377 protected:
378 float m_realMin;
379 float m_realMax;
380};
381
382class wxIntegerListValidator: public wxPropertyListValidator
383{
384 DECLARE_DYNAMIC_CLASS(wxIntegerListValidator)
385 public:
386 // 0, 0 means no range
387 wxIntegerListValidator(long min = 0, long max = 0, long flags = wxPROP_ALLOW_TEXT_EDITING):wxPropertyListValidator(flags)
388 {
389 m_integerMin = min; m_integerMax = max;
390 }
391 ~wxIntegerListValidator(void) {}
392
393 bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
394
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);
398
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);
403
404 protected:
405 long m_integerMin;
406 long m_integerMax;
407};
408
409class wxBoolListValidator: public wxPropertyListValidator
410{
411 DECLARE_DYNAMIC_CLASS(wxBoolListValidator)
412 protected:
413 public:
414 wxBoolListValidator(long flags = 0):wxPropertyListValidator(flags)
415 {
416 }
417 ~wxBoolListValidator(void) {}
418
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);
422
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);
426
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);
432
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);
436};
437
438class wxStringListValidator: public wxPropertyListValidator
439{
440 DECLARE_DYNAMIC_CLASS(wxStringListValidator)
441 public:
442 wxStringListValidator(wxStringList *list = NULL, long flags = 0);
443
444 ~wxStringListValidator(void)
445 {
446 if (m_strings)
447 delete m_strings;
448 }
449
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);
453
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);
457
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);
463
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);
467
468 protected:
469 wxStringList* m_strings;
470};
471
472class wxFilenameListValidator: public wxPropertyListValidator
473{
474 DECLARE_DYNAMIC_CLASS(wxFilenameListValidator)
475 public:
476 wxFilenameListValidator(wxString message = "Select a file", wxString wildcard = "*.*", long flags = 0);
477
478 ~wxFilenameListValidator(void);
479
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);
483
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);
489
490 bool OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
491
492 bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
493
494 // Called when the edit (...) button is pressed.
495 void OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
496
497 protected:
498 wxString m_filenameWildCard;
499 wxString m_filenameMessage;
500
501};
502
503class wxColourListValidator: public wxPropertyListValidator
504{
505 DECLARE_DYNAMIC_CLASS(wxColourListValidator)
506 protected:
507 public:
508 wxColourListValidator(long flags = 0);
509
510 ~wxColourListValidator(void);
511
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);
515
516 bool OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
517
518 bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
519
520 // Called when the edit (...) button is pressed.
521 void OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
522};
523
524class wxListOfStringsListValidator: public wxPropertyListValidator
525{
526 DECLARE_DYNAMIC_CLASS(wxListOfStringsListValidator)
527 protected:
528 public:
529 wxListOfStringsListValidator(long flags = 0);
530
531 ~wxListOfStringsListValidator(void)
532 {
533 }
534
535 bool OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
536
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);
540
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);
546
547 // Called when the property is double clicked.
548 bool OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
549
550 bool EditStringList(wxWindow *parent, wxStringList *stringList, const char *title = "String List Editor");
551
552 // Called when the edit (...) button is pressed.
553 void OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow);
554};
555
556#endif
557 // _WX_PROPLIST_H_