A lot of documentation revision. Updated doctest code in propgrid sample to reflect...
[wxWidgets.git] / docs / doxygen / overviews / propgrid.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: propgrid.h
3 // Purpose: topic overview
4 // Author: wxWidgets team
5 // RCS-ID: $Id:
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9 /**
10
11 @page overview_propgrid wxPropertyGrid Overview
12
13 Key Classes:
14 @li wxPGProperty
15 @li wxPropertyGrid
16 @li wxPropertyGridEvent
17 @li wxPropertyGridManager
18 @li wxPropertyGridPage
19
20 wxPropertyGrid is a specialized grid for editing properties - in other
21 words name = value pairs. List of ready-to-use property classes include
22 strings, numbers, flag sets, fonts, colours and many others. It is possible,
23 for example, to categorize properties, set up a complete tree-hierarchy,
24 add more than two columns, and set arbitrary per-property attributes.
25
26 @li @ref propgrid_basics
27 @li @ref propgrid_categories
28 @li @ref propgrid_parentprops
29 @li @ref propgrid_enumandflags
30 @li @ref propgrid_advprops
31 @li @ref propgrid_processingvalues
32 @li @ref propgrid_iterating
33 @li @ref propgrid_events
34 @li @ref propgrid_validating
35 @li @ref propgrid_populating
36 @li @ref propgrid_cellrender
37 @li @ref propgrid_customizing
38 @li @ref propgrid_usage2
39 @li @ref propgrid_subclassing
40 @li @ref propgrid_misc
41 @li @ref propgrid_proplist
42
43 @section propgrid_basics Creating and Populating wxPropertyGrid
44
45 As seen here, wxPropertyGrid is constructed in the same way as
46 other wxWidgets controls:
47
48 @code
49
50 // Necessary header file
51 #include <wx/propgrid/propgrid.h>
52
53 ...
54
55 // Assumes code is in frame/dialog constructor
56
57 // Construct wxPropertyGrid control
58 wxPropertyGrid* pg = new wxPropertyGrid(
59 this, // parent
60 PGID, // id
61 wxDefaultPosition, // position
62 wxDefaultSize, // size
63 // Here are just some of the supported window styles
64 wxPG_AUTO_SORT | // Automatic sorting after items added
65 wxPG_SPLITTER_AUTO_CENTER | // Automatically center splitter until user manually adjusts it
66 // Default style
67 wxPG_DEFAULT_STYLE );
68
69 // Window style flags are at premium, so some less often needed ones are
70 // available as extra window styles (wxPG_EX_xxx) which must be set using
71 // SetExtraStyle member function. wxPG_EX_HELP_AS_TOOLTIPS, for instance,
72 // allows displaying help strings as tool tips.
73 pg->SetExtraStyle( wxPG_EX_HELP_AS_TOOLTIPS );
74
75 @endcode
76
77 (for complete list of new window styles, see @ref propgrid_window_styles)
78
79 wxPropertyGrid is usually populated with lines like this:
80
81 @code
82 pg->Append( new wxStringProperty(wxT("Label"),wxT("Name"),wxT("Initial Value")) );
83 @endcode
84
85 Naturally, wxStringProperty is a property class. Only the first function argument (label)
86 is mandatory. Second one, name, defaults to label and, third, the initial value, to
87 default value. If constant wxPG_LABEL is used as the name argument, then the label is
88 automatically used as a name as well (this is more efficient than manually defining both
89 as the same). Use of empty name is discouraged and will sometimes result in run-time error.
90 Note that all property class constructors have quite similar constructor argument list.
91
92 To demonstrate other common property classes, here's another code snippet:
93
94 @code
95
96 // Add int property
97 pg->Append( new wxIntProperty(wxT("IntProperty"), wxPG_LABEL, 12345678) );
98
99 // Add float property (value type is actually double)
100 pg->Append( new wxFloatProperty(wxT("FloatProperty"), wxPG_LABEL, 12345.678) );
101
102 // Add a bool property
103 pg->Append( new wxBoolProperty(wxT("BoolProperty"), wxPG_LABEL, false) );
104
105 // A string property that can be edited in a separate editor dialog.
106 pg->Append( new wxLongStringProperty(wxT("LongStringProperty"),
107 wxPG_LABEL,
108 wxT("This is much longer string than the ")
109 wxT("first one. Edit it by clicking the button.")));
110
111 // String editor with dir selector button.
112 pg->Append( new wxDirProperty(wxT("DirProperty"), wxPG_LABEL, ::wxGetUserHome()) );
113
114 // wxArrayStringProperty embeds a wxArrayString.
115 pg->Append( new wxArrayStringProperty(wxT("Label of ArrayStringProperty"),
116 wxT("NameOfArrayStringProp")));
117
118 // A file selector property.
119 pg->Append( new wxFileProperty(wxT("FileProperty"), wxPG_LABEL, wxEmptyString) );
120
121 // Extra: set wild card for file property (format same as in wxFileDialog).
122 pg->SetPropertyAttribute( wxT("FileProperty"),
123 wxPG_FILE_WILDCARD,
124 wxT("All files (*.*)|*.*") );
125
126 @endcode
127
128 Operations on properties are usually done by directly calling wxPGProperty's
129 or wxPropertyGridInterface's member functions. wxPropertyGridInterface is an
130 abstract base class for property containers such as wxPropertyGrid,
131 wxPropertyGridManager, and wxPropertyGridPage. Note however that wxPGProperty's
132 member functions generally do not refresh the grid.
133
134 wxPropertyGridInterface's property operation member functions , such as
135 SetPropertyValue() and DisableProperty(), all accept a special wxPGPropArg id
136 argument, using which you can refer to properties either by their pointer
137 (for performance) or by their name (for convenience). For instance:
138
139 @code
140 // Add a file selector property.
141 wxPGPropety* prop = pg->Append( new wxFileProperty(wxT("FileProperty"),
142 wxPG_LABEL,
143 wxEmptyString) );
144
145 // Valid: Set wild card by name
146 pg->SetPropertyAttribute( wxT("FileProperty"),
147 wxPG_FILE_WILDCARD,
148 wxT("All files (*.*)|*.*") );
149
150 // Also Valid: Set wild card by property pointer
151 pg->SetPropertyAttribute( prop,
152 wxPG_FILE_WILDCARD,
153 wxT("All files (*.*)|*.*") );
154 @endcode
155
156 Using pointer is faster, since it doesn't require hash map lookup. Anyway,
157 you can always get property pointer (wxPGProperty*) as return value from Append()
158 or Insert(), or by calling wxPropertyGridInterface::GetPropertyByName() or
159 just plain GetProperty().
160
161 @section propgrid_categories Categories
162
163 wxPropertyGrid has a hierarchic property storage and display model, which
164 allows property categories to hold child properties and even other
165 categories. Other than that, from the programmer's point of view, categories
166 can be treated exactly the same as "other" properties. For example, despite
167 its name, GetPropertyByName() also returns a category by name. Note however
168 that sometimes the label of a property category may be referred as caption
169 (for example, there is wxPropertyGrid::SetCaptionTextColour() method
170 that sets text colour of property category labels).
171
172 When category is added at the top (i.e. root) level of the hierarchy,
173 it becomes a *current category*. This means that all other (non-category)
174 properties after it are automatically appended to it. You may add
175 properties to specific categories by using wxPropertyGridInterface::Insert
176 or wxPropertyGridInterface::AppendIn.
177
178 Category code sample:
179
180 @code
181
182 // One way to add category (similar to how other properties are added)
183 pg->Append( new wxPropertyCategory(wxT("Main")) );
184
185 // All these are added to "Main" category
186 pg->Append( new wxStringProperty(wxT("Name")) );
187 pg->Append( new wxIntProperty(wxT("Age"),wxPG_LABEL,25) );
188 pg->Append( new wxIntProperty(wxT("Height"),wxPG_LABEL,180) );
189 pg->Append( new wxIntProperty(wxT("Weight")) );
190
191 // Another one
192 pg->Append( new wxPropertyCategory(wxT("Attributes")) );
193
194 // All these are added to "Attributes" category
195 pg->Append( new wxIntProperty(wxT("Intelligence")) );
196 pg->Append( new wxIntProperty(wxT("Agility")) );
197 pg->Append( new wxIntProperty(wxT("Strength")) );
198
199 @endcode
200
201
202 @section propgrid_parentprops Tree-like Property Structure
203
204 Basically any property can have children. There are few limitations, however.
205
206 @remarks
207 - Names of properties with non-category, non-root parents are not stored in global
208 hash map. Instead, they can be accessed with strings like "Parent.Child".
209 For instance, in the sample below, child property named "Max. Speed (mph)"
210 can be accessed by global name "Car.Speeds.Max Speed (mph)".
211 - If you want to property's value to be a string composed of the child property values,
212 you must use wxStringProperty as parent and use magic string "<composed>" as its
213 value.
214 - Events (eg. change of value) that occur in parent do not propagate to children. Events
215 that occur in children will propagate to parents, but only if they are wxStringProperties
216 with "<composed>" value.
217
218 Sample:
219
220 @code
221 wxPGProperty* carProp = pg->Append(new wxStringProperty(wxT("Car"),
222 wxPG_LABEL,
223 wxT("<composed>")));
224
225 pg->AppendIn(carProp, new wxStringProperty(wxT("Model"),
226 wxPG_LABEL,
227 wxT("Lamborghini Diablo SV")));
228
229 pg->AppendIn(carProp, new wxIntProperty(wxT("Engine Size (cc)"),
230 wxPG_LABEL,
231 5707) );
232
233 wxPGProperty* speedsProp = pg->AppendIn(carProp,
234 new wxStringProperty(wxT("Speeds"),
235 wxPG_LABEL,
236 wxT("<composed>")));
237
238 pg->AppendIn( speedsProp, new wxIntProperty(wxT("Max. Speed (mph)"),
239 wxPG_LABEL,290) );
240 pg->AppendIn( speedsProp, new wxFloatProperty(wxT("0-100 mph (sec)"),
241 wxPG_LABEL,3.9) );
242 pg->AppendIn( speedsProp, new wxFloatProperty(wxT("1/4 mile (sec)"),
243 wxPG_LABEL,8.6) );
244
245 // This is how child property can be referred to by name
246 pg->SetPropertyValue( wxT("Car.Speeds.Max. Speed (mph)"), 300 );
247
248 pg->AppendIn(carProp, new wxIntProperty(wxT("Price ($)"),
249 wxPG_LABEL,
250 300000) );
251
252 // Displayed value of "Car" property is now very close to this:
253 // "Lamborghini Diablo SV; 5707 [300; 3.9; 8.6] 300000"
254
255 @endcode
256
257 @section propgrid_enumandflags wxEnumProperty and wxFlagsProperty
258
259 wxEnumProperty is used when you want property's (integer or string) value
260 to be selected from a popup list of choices.
261
262 Creating wxEnumProperty is slightly more complex than those described
263 earlier. You have to provide list of constant labels, and optionally relevant
264 values (if label indexes are not sufficient).
265
266 @remarks
267
268 - Value wxPG_INVALID_VALUE (equals INT_MAX) is not allowed as list
269 item value.
270
271 A very simple example:
272
273 @code
274
275 //
276 // Using wxArrayString
277 //
278 wxArrayString arrDiet;
279 arr.Add(wxT("Herbivore"));
280 arr.Add(wxT("Carnivore"));
281 arr.Add(wxT("Omnivore"));
282
283 pg->Append( new wxEnumProperty(wxT("Diet"),
284 wxPG_LABEL,
285 arrDiet) );
286
287 //
288 // Using wxChar* array
289 //
290 const wxChar* arrayDiet[] =
291 { wxT("Herbivore"), wxT("Carnivore"), wxT("Omnivore"), NULL };
292
293 pg->Append( new wxEnumProperty(wxT("Diet"),
294 wxPG_LABEL,
295 arrayDiet) );
296
297 @endcode
298
299 Here's extended example using values as well:
300
301 @code
302
303 //
304 // Using wxArrayString and wxArrayInt
305 //
306 wxArrayString arrDiet;
307 arr.Add(wxT("Herbivore"));
308 arr.Add(wxT("Carnivore"));
309 arr.Add(wxT("Omnivore"));
310
311 wxArrayInt arrIds;
312 arrIds.Add(40);
313 arrIds.Add(45);
314 arrIds.Add(50);
315
316 // Note that the initial value (the last argument) is the actual value,
317 // not index or anything like that. Thus, our value selects "Omnivore".
318 pg->Append( new wxEnumProperty(wxT("Diet"),
319 wxPG_LABEL,
320 arrDiet,
321 arrIds,
322 50));
323
324 @endcode
325
326 wxPGChoices is a class where wxEnumProperty, and other properties which
327 require storage for list of items, actually stores strings and values. It is
328 used to facilitate reference counting, and therefore recommended way of
329 adding items when multiple properties share the same set.
330
331 You can use wxPGChoices directly as well, filling it and then passing it
332 to the constructor. In fact, if you wish to display bitmaps next to labels,
333 your best choice is to use this approach.
334
335 @code
336
337 wxPGChoices chs;
338 chs.Add(wxT("Herbivore"), 40);
339 chs.Add(wxT("Carnivore"), 45);
340 chs.Add(wxT("Omnivore"), 50);
341
342 // Let's add an item with bitmap, too
343 chs.Add(wxT("None of the above"), wxBitmap(), 60);
344
345 pg->Append( new wxEnumProperty(wxT("Primary Diet"),
346 wxPG_LABEL,
347 chs) );
348
349 // Add same choices to another property as well - this is efficient due
350 // to reference counting
351 pg->Append( new wxEnumProperty(wxT("Secondary Diet"),
352 wxPG_LABEL,
353 chs) );
354 @endcode
355
356 You can later change choices of property by using wxPGProperty::AddChoice(),
357 wxPGProperty::InsertChoice(), wxPGProperty::DeleteChoice(), and
358 wxPGProperty::SetChoices().
359
360 <b>wxEditEnumProperty</b> works exactly like wxEnumProperty, except
361 is uses non-read-only combo box as default editor, and value is stored as
362 string when it is not any of the choices.
363
364 wxFlagsProperty has similar construction:
365
366 @code
367
368 const wxChar* flags_prop_labels[] = { wxT("wxICONIZE"),
369 wxT("wxCAPTION"), wxT("wxMINIMIZE_BOX"), wxT("wxMAXIMIZE_BOX"), NULL };
370
371 // this value array would be optional if values matched string indexes
372 long flags_prop_values[] = { wxICONIZE, wxCAPTION, wxMINIMIZE_BOX,
373 wxMAXIMIZE_BOX };
374
375 pg->Append( new wxFlagsProperty(wxT("Window Style"),
376 wxPG_LABEL,
377 flags_prop_labels,
378 flags_prop_values,
379 wxDEFAULT_FRAME_STYLE) );
380
381 @endcode
382
383 wxFlagsProperty can use wxPGChoices just the same way as wxEnumProperty
384 <b>Note:</b> When changing "choices" (ie. flag labels) of wxFlagsProperty,
385 you will need to use wxPGProperty::SetChoices() to replace all choices
386 at once - otherwise implicit child properties will not get updated properly.
387
388 @section propgrid_advprops Specialized Properties
389
390 This section describes the use of less often needed property classes.
391 To use them, you have to include <wx/propgrid/advprops.h>.
392
393 @code
394
395 // Necessary extra header file
396 #include <wx/propgrid/advprops.h>
397
398 ...
399
400 // Date property.
401 pg->Append( new wxDateProperty(wxT("MyDateProperty"),
402 wxPG_LABEL,
403 wxDateTime::Now()) );
404
405 // Image file property. Wild card is auto-generated from available
406 // image handlers, so it is not set this time.
407 pg->Append( new wxImageFileProperty(wxT("Label of ImageFileProperty"),
408 wxT("NameOfImageFileProp")) );
409
410 // Font property has sub-properties. Note that we give window's font as
411 // initial value.
412 pg->Append( new wxFontProperty(wxT("Font"),
413 wxPG_LABEL,
414 GetFont()) );
415
416 // Colour property with arbitrary colour.
417 pg->Append( new wxColourProperty(wxT("My Colour 1"),
418 wxPG_LABEL,
419 wxColour(242,109,0) ) );
420
421 // System colour property.
422 pg->Append( new wxSystemColourProperty(wxT("My SysColour 1"),
423 wxPG_LABEL,
424 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)) );
425
426 // System colour property with custom colour.
427 pg->Append( new wxSystemColourProperty(wxT("My SysColour 2"),
428 wxPG_LABEL,
429 wxColour(0,200,160) ) );
430
431 // Cursor property
432 pg->Append( new wxCursorProperty(wxT("My Cursor"),
433 wxPG_LABEL,
434 wxCURSOR_ARROW));
435
436 @endcode
437
438
439 @section propgrid_processingvalues Processing Property Values
440
441 Properties store their values internally in wxVariant. You can obtain
442 this value using wxPGProperty::GetValue() or wxPropertyGridInterface::
443 GetPropertyValue().
444
445 If you wish to obtain property value in specific data type, you can
446 call various getter functions, such as wxPropertyGridInterface::
447 GetPropertyValueAsString(), which, as name might say, returns property
448 value's string representation. While this particular function is very
449 safe to use for any kind of property, some might display error message
450 if property value is not in compatible enough format. For instance,
451 wxPropertyGridInterface::GetPropertyValueAsLongLong() will support
452 long as well as wxLongLong, but GetPropertyValueAsArrayString() only
453 supports wxArrayString and nothing else.
454
455 In any case, you will need to take extra care when dealing with
456 raw wxVariant values. For instance, wxIntProperty and wxUIntProperty,
457 store value internally as wx(U)LongLong when number doesn't fit into
458 standard long type.
459
460 You may have noticed that properties store, in wxVariant, values of many
461 types which are not natively supported by it. Custom wxVariantDatas
462 are therefore implemented and << and >> operators implemented to
463 convert data from and to wxVariant.
464
465 Note that in some cases property value can be Null variant, which means
466 that property value is unspecified. This usually occurs only when
467 wxPG_EX_AUTO_UNSPECIFIED_VALUES extra window style is defined or when you
468 manually set property value to Null (or unspecified).
469
470
471 @section propgrid_iterating Iterating through a property container
472
473 You can use somewhat STL'ish iterator classes to iterate through the grid.
474 Here is a simple example of forward iterating through all individual
475 properties (not categories nor private child properties that are normally
476 'transparent' to application code):
477
478 @code
479
480 wxPropertyGridIterator it;
481
482 for ( it = pg->GetIterator();
483 !it.AtEnd();
484 it++ )
485 {
486 wxPGProperty* p = *it;
487 // Do something with the property
488 }
489
490 @endcode
491
492 As expected there is also a const iterator:
493
494 @code
495
496 wxPropertyGridConstIterator it;
497
498 for ( it = pg->GetIterator();
499 !it.AtEnd();
500 it++ )
501 {
502 const wxPGProperty* p = *it;
503 // Do something with the property
504 }
505
506 @endcode
507
508 You can give some arguments to GetIterator to determine which properties
509 get automatically filtered out. For complete list of options, see
510 @ref propgrid_iterator_flags. GetIterator() also accepts other arguments.
511 See wxPropertyGridInterface::GetIterator() for details.
512
513 This example reverse-iterates through all visible items:
514
515 @code
516
517 wxPropertyGridIterator it;
518
519 for ( it = pg->GetIterator(wxPG_ITERATE_VISIBLE, wxBOTTOM);
520 !it.AtEnd();
521 it-- )
522 {
523 wxPGProperty* p = *it;
524 // Do something with the property
525 }
526
527 @endcode
528
529 <b>wxPython Note:</b> Instead of ++ operator, use Next() method, and instead of
530 * operator, use GetProperty() method.
531
532 GetIterator() only works with wxPropertyGrid and the individual pages
533 of wxPropertyGridManager. In order to iterate through an arbitrary
534 property container (such as entire wxPropertyGridManager), you need to use
535 wxPropertyGridInterface::GetVIterator(). Note however that this virtual
536 iterator is limited to forward iteration.
537
538 @code
539
540 wxPGVIterator it;
541
542 for ( it = manager->GetVIterator();
543 !it.AtEnd();
544 it.Next() )
545 {
546 wxPGProperty* p = it.GetProperty();
547 // Do something with the property
548 }
549
550 @endcode
551
552 @section propgrid_populating Populating wxPropertyGrid Automatically
553
554 @subsection propgrid_fromvariants Populating from List of wxVariants
555
556 Example of populating an empty wxPropertyGrid from a values stored
557 in an arbitrary list of wxVariants.
558
559 @code
560
561 // This is a static method that initializes *all* built-in type handlers
562 // available, including those for wxColour and wxFont. Refers to *all*
563 // included properties, so when compiling with static library, this
564 // method may increase the executable size noticeably.
565 pg->InitAllTypeHandlers();
566
567 // Get contents of the grid as a wxVariant list
568 wxVariant all_values = pg->GetPropertyValues();
569
570 // Populate the list with values. If a property with appropriate
571 // name is not found, it is created according to the type of variant.
572 pg->SetPropertyValues( my_list_variant );
573
574 @endcode
575
576 @subsection propgrid_fromfile Loading Population from a Text-based Storage
577
578 Class wxPropertyGridPopulator may be helpful when writing code that
579 loads properties from a text-source. In fact, the wxPropertyGrid xrc-handler
580 (which may not be currently included in wxWidgets, but probably will be in
581 near future) uses it.
582
583 @subsection editablestate Saving and Restoring User-Editable State
584
585 You can use wxPropertyGridInterface::SaveEditableState() and
586 wxPropertyGridInterface::RestoreEditableState() to save and restore
587 user-editable state (selected property, expanded/collapsed properties,
588 selected page, scrolled position, and splitter positions).
589
590 @section propgrid_events Event Handling
591
592 Probably the most important event is the Changed event which occurs when
593 value of any property is changed by the user. Use EVT_PG_CHANGED(id,func)
594 in your event table to use it.
595
596 For complete list of event types, see wxPropertyGrid class reference.
597
598 However, one type of event that might need focused attention is EVT_PG_CHANGING,
599 which occurs just prior property value is being changed by user. You can
600 acquire pending value using wxPropertyGridEvent::GetValue(), and if it is
601 not acceptable, call wxPropertyGridEvent::Veto() to prevent the value change
602 from taking place.
603
604 @code
605
606 void MyForm::OnPropertyGridChanging( wxPropertyGridEvent& event )
607 {
608 wxPGProperty* property = event.GetProperty();
609
610 if ( property == m_pWatchThisProperty )
611 {
612 // GetValue() returns the pending value, but is only
613 // supported by wxEVT_PG_CHANGING.
614 if ( event.GetValue().GetString() == g_pThisTextIsNotAllowed )
615 {
616 event.Veto();
617 return;
618 }
619 }
620 }
621
622 @endcode
623
624 @remarks On Child Property Event Handling
625 - For properties which have private, implicit children (wxFontProperty and
626 wxFlagsProperty), events occur for the main parent property only.
627 For other properties events occur for the children themselves. See
628 @ref propgrid_parentprops.
629
630 - When property's child gets changed, you can use wxPropertyGridEvent::GetMainParent()
631 to obtain its topmost non-category parent (useful, if you have deeply nested
632 properties).
633
634
635 @section propgrid_validating Validating Property Values
636
637 There are various ways to make sure user enters only correct values. First, you
638 can use wxValidators similar to as you would with ordinary controls. Use
639 wxPropertyGridInterface::SetPropertyValidator() to assign wxValidator to
640 property.
641
642 Second, you can subclass a property and override wxPGProperty::ValidateValue(),
643 or handle wxEVT_PG_CHANGING for the same effect. Both of these ways do not
644 actually prevent user from temporarily entering invalid text, but they do give
645 you an opportunity to warn the user and block changed value from being committed
646 in a property.
647
648 Various validation failure options can be controlled globally with
649 wxPropertyGrid::SetValidationFailureBehavior(), or on an event basis by
650 calling wxEvent::SetValidationFailureBehavior(). Here's a code snippet of
651 how to handle wxEVT_PG_CHANGING, and to set custom failure behaviour and
652 message.
653
654 @code
655 void MyFrame::OnPropertyGridChanging(wxPropertyGridEvent& event)
656 {
657 wxPGProperty* property = event.GetProperty();
658
659 // You must use wxPropertyGridEvent::GetValue() to access
660 // the value to be validated.
661 wxVariant pendingValue = event.GetValue();
662
663 if ( property->GetName() == wxT("Font") )
664 {
665 // Make sure value is not unspecified
666 if ( !pendingValue.IsNull() )
667 {
668 wxFont font;
669 font << pendingValue;
670
671 // Let's just allow Arial font
672 if ( font.GetFaceName() != wxT("Arial") )
673 {
674 event.Veto();
675 event.SetValidationFailureBehavior(wxPG_VFB_STAY_IN_PROPERTY |
676 wxPG_VFB_BEEP |
677 wxPG_VFB_SHOW_MESSAGE);
678 }
679 }
680 }
681 }
682 @endcode
683
684
685 @section propgrid_cellrender Customizing Individual Cell Appearance
686
687 You can control text colour, background colour, and attached image of
688 each cell in the property grid. Use wxPropertyGridInterface::SetPropertyCell() or
689 wxPGProperty::SetCell() for this purpose.
690
691 In addition, it is possible to control these characteristics for
692 wxPGChoices list items. See wxPGChoices class reference for more info.
693
694
695 @section propgrid_customizing Customizing Properties (without sub-classing)
696
697 In this section are presented miscellaneous ways to have custom appearance
698 and behavior for your properties without all the necessary hassle
699 of sub-classing a property class etc.
700
701 @subsection propgrid_customimage Setting Value Image
702
703 Every property can have a small value image placed in front of the
704 actual value text. Built-in example of this can be seen with
705 wxColourProperty and wxImageFileProperty, but for others it can
706 be set using wxPropertyGrid::SetPropertyImage method.
707
708 @subsection propgrid_customeditor Setting Property's Editor Control(s)
709
710 You can set editor control (or controls, in case of a control and button),
711 of any property using wxPropertyGrid::SetPropertyEditor. Editors are passed
712 as wxPGEditor_EditorName, and valid built-in EditorNames are
713 TextCtrl, Choice, ComboBox, CheckBox, TextCtrlAndButton, ChoiceAndButton,
714 SpinCtrl, and DatePickerCtrl. Two last mentioned ones require call to
715 static member function wxPropertyGrid::RegisterAdditionalEditors().
716
717 Following example changes wxColourProperty's editor from default Choice
718 to TextCtrlAndButton. wxColourProperty has its internal event handling set
719 up so that button click events of the button will be used to trigger
720 colour selection dialog.
721
722 @code
723
724 wxPGProperty* colProp = new wxColourProperty(wxT("Text Colour"));
725 pg->Append(colProp);
726 pg->SetPropertyEditor(colProp, wxPGEditor_TextCtrlAndButton);
727
728 @endcode
729
730 Naturally, creating and setting custom editor classes is a possibility as
731 well. For more information, see wxPGEditor class reference.
732
733 @subsection propgrid_editorattrs Property Attributes Recognized by Editors
734
735 <b>SpinCtrl</b> editor can make use of property's "Min", "Max", "Step" and
736 "Wrap" attributes.
737
738 @subsection propgrid_multiplebuttons Adding Multiple Buttons Next to an Editor
739
740 See wxPGMultiButton class reference.
741
742 @subsection propgrid_customeventhandling Handling Events Passed from Properties
743
744 <b>wxEVT_COMMAND_BUTTON_CLICKED </b>(corresponds to event table macro EVT_BUTTON):
745 Occurs when editor button click is not handled by the property itself
746 (as is the case, for example, if you set property's editor to TextCtrlAndButton
747 from the original TextCtrl).
748
749 @subsection propgrid_attributes Property Attributes
750
751 Miscellaneous values, often specific to a property type, can be set
752 using wxPropertyGridInterface::SetPropertyAttribute() and
753 wxPropertyGridInterface::SetPropertyAttributeAll() methods.
754
755 Attribute names are strings and values wxVariant. Arbitrary names are allowed
756 in order to store values that are relevant to application only and not
757 property grid. Constant equivalents of all attribute string names are
758 provided. Some of them are defined as cached strings, so using these constants
759 can provide for smaller binary size.
760
761 For complete list of attributes, see @ref propgrid_property_attributes.
762
763
764 @section propgrid_usage2 Using wxPropertyGridManager
765
766 wxPropertyGridManager is an efficient multi-page version of wxPropertyGrid,
767 which can optionally have tool bar for mode and page selection, and a help text
768 box. For more information, see wxPropertyGridManager class reference.
769
770 @subsection propgrid_propgridpage wxPropertyGridPage
771
772 wxPropertyGridPage is holder of properties for one page in manager. It is derived from
773 wxEvtHandler, so you can subclass it to process page-specific property grid events. Hand
774 over your page instance in wxPropertyGridManager::AddPage().
775
776 Please note that the wxPropertyGridPage itself only sports subset of wxPropertyGrid API
777 (but unlike manager, this include item iteration). Naturally it inherits from
778 wxPropertyGridInterface.
779
780 For more information, see wxPropertyGridPage class reference.
781
782
783 @section propgrid_subclassing Sub-classing wxPropertyGrid and wxPropertyGridManager
784
785 Few things to note:
786
787 - Only a small percentage of member functions are virtual. If you need more,
788 just e-mail to wx-dev mailing list.
789
790 - Data manipulation is done in wxPropertyGridPageState class. So, instead of
791 overriding wxPropertyGrid::Insert(), you'll probably want to override
792 wxPropertyGridPageState::DoInsert(). See header file for details.
793
794 - Override wxPropertyGrid::CreateState() to instantiate your derivate
795 wxPropertyGridPageState. For wxPropertyGridManager, you'll need to subclass
796 wxPropertyGridPage instead (since it is derived from wxPropertyGridPageState),
797 and hand over instances in wxPropertyGridManager::AddPage() calls.
798
799 - You can use a derivate wxPropertyGrid with manager by overriding
800 wxPropertyGridManager::CreatePropertyGrid() member function.
801
802
803 @section propgrid_misc Miscellaneous Topics
804
805 @subsection propgrid_namescope Property Name Scope
806
807 All properties which parent is category or root can be accessed
808 directly by their base name (ie. name given for property in its constructor).
809 Other properties can be accessed via "ParentsName.BaseName" notation,
810 Naturally, all property names should be unique.
811
812 @subsection propgrid_nonuniquelabels Non-unique Labels
813
814 It is possible to have properties with identical label under same parent.
815 However, care must be taken to ensure that each property still has
816 unique (base) name.
817
818 @subsection propgrid_boolproperty wxBoolProperty
819
820 There are few points about wxBoolProperty that require further discussion:
821 - wxBoolProperty can be shown as either normal combo box or as a check box.
822 Property attribute wxPG_BOOL_USE_CHECKBOX is used to change this.
823 For example, if you have a wxFlagsProperty, you can
824 set its all items to use check box using the following:
825 @code
826 pg->SetPropertyAttribute(wxT("MyFlagsProperty"),wxPG_BOOL_USE_CHECKBOX,true,wxPG_RECURSE);
827 @endcode
828
829 Following will set all individual bool properties in your control to
830 use check box:
831
832 @code
833 pg->SetPropertyAttributeAll(wxPG_BOOL_USE_CHECKBOX, true);
834 @endcode
835
836 - Default item names for wxBoolProperty are ["False", "True"]. This can be
837 changed using static function wxPropertyGrid::SetBoolChoices(trueChoice,
838 falseChoice).
839
840 @subsection propgrid_textctrlupdates Updates from wxTextCtrl Based Editor
841
842 Changes from wxTextCtrl based property editors are committed (ie.
843 wxEVT_PG_CHANGED is sent etc.) *only* when (1) user presser enter, (2)
844 user moves to edit another property, or (3) when focus leaves
845 the grid.
846
847 Because of this, you may find it useful, in some apps, to call
848 wxPropertyGrid::CommitChangesFromEditor() just before you need to do any
849 computations based on property grid values. Note that CommitChangesFromEditor()
850 will dispatch wxEVT_PG_CHANGED with ProcessEvent, so any of your event handlers
851 will be called immediately.
852
853 @subsection propgrid_splittercentering Centering the Splitter
854
855 If you need to center the splitter, but only once when the program starts,
856 then do <b>not</b> use the wxPG_SPLITTER_AUTO_CENTER window style, but the
857 wxPropertyGrid::CenterSplitter() method. <b>However, be sure to call it after
858 the sizer setup and SetSize calls!</b> (ie. usually at the end of the
859 frame/dialog constructor)
860
861 @subsection propgrid_splittersetting Setting Splitter Position When Creating Property Grid
862
863 Splitter position cannot exceed grid size, and therefore setting it during
864 form creation may fail as initial grid size is often smaller than desired
865 splitter position, especially when sizers are being used.
866
867 @subsection propgrid_colourproperty wxColourProperty and wxSystemColourProperty
868
869 Through sub-classing, these two property classes provide substantial customization
870 features. Subclass wxSystemColourProperty if you want to use wxColourPropertyValue
871 (which features colour type in addition to wxColour), and wxColourProperty if plain
872 wxColour is enough.
873
874 Override wxSystemColourProperty::ColourToString() to redefine how colours are
875 printed as strings.
876
877 Override wxSystemColourProperty::GetCustomColourIndex() to redefine location of
878 the item that triggers colour picker dialog (default is last).
879
880 Override wxSystemColourProperty::GetColour() to determine which colour matches
881 which choice entry.
882
883 @section propgrid_proplist Property Class Descriptions
884
885 See @ref pgproperty_properties
886
887 */
888