]>
git.saurik.com Git - wxWidgets.git/blob - docs/doxygen/overviews/propgrid.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: topic overview
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
11 @page overview_propgrid wxPropertyGrid Overview
16 @li wxPropertyGridEvent
17 @li wxPropertyGridManager
18 @li wxPropertyGridPage
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.
26 As this version of wxPropertyGrid has some backward-incompatible changes
27 from version 1.4, everybody who need to maintain custom property classes
28 should carefully read final section in @ref propgrid_compat.
30 @li @ref propgrid_basics
31 @li @ref propgrid_categories
32 @li @ref propgrid_parentprops
33 @li @ref propgrid_enumandflags
34 @li @ref propgrid_advprops
35 @li @ref propgrid_processingvalues
36 @li @ref propgrid_iterating
37 @li @ref propgrid_events
38 @li @ref propgrid_validating
39 @li @ref propgrid_populating
40 @li @ref propgrid_cellrender
41 @li @ref propgrid_customizing
42 @li @ref propgrid_usage2
43 @li @ref propgrid_subclassing
44 @li @ref propgrid_misc
45 @li @ref propgrid_proplist
46 @li @ref propgrid_compat
48 @section propgrid_basics Creating and Populating wxPropertyGrid
50 As seen here, wxPropertyGrid is constructed in the same way as
51 other wxWidgets controls:
55 // Necessary header file
56 #include <wx/propgrid/propgrid.h>
60 // Assumes code is in frame/dialog constructor
62 // Construct wxPropertyGrid control
63 wxPropertyGrid* pg = new wxPropertyGrid(
66 wxDefaultPosition, // position
67 wxDefaultSize, // size
68 // Here are just some of the supported window styles
69 wxPG_AUTO_SORT | // Automatic sorting after items added
70 wxPG_SPLITTER_AUTO_CENTER | // Automatically center splitter until user manually adjusts it
74 // Window style flags are at premium, so some less often needed ones are
75 // available as extra window styles (wxPG_EX_xxx) which must be set using
76 // SetExtraStyle member function. wxPG_EX_HELP_AS_TOOLTIPS, for instance,
77 // allows displaying help strings as tool tips.
78 pg->SetExtraStyle( wxPG_EX_HELP_AS_TOOLTIPS );
82 (for complete list of new window styles, see @ref propgrid_window_styles)
84 wxPropertyGrid is usually populated with lines like this:
87 pg->Append( new wxStringProperty(wxT("Label"),wxT("Name"),wxT("Initial Value")) );
90 Naturally, wxStringProperty is a property class. Only the first function argument (label)
91 is mandatory. Second one, name, defaults to label and, third, the initial value, to
92 default value. If constant wxPG_LABEL is used as the name argument, then the label is
93 automatically used as a name as well (this is more efficient than manually defining both
94 as the same). Use of empty name is discouraged and will sometimes result in run-time error.
95 Note that all property class constructors have quite similar constructor argument list.
97 To demonstrate other common property classes, here's another code snippet:
102 pg->Append( new wxIntProperty(wxT("IntProperty"), wxPG_LABEL, 12345678) );
104 // Add float property (value type is actually double)
105 pg->Append( new wxFloatProperty(wxT("FloatProperty"), wxPG_LABEL, 12345.678) );
107 // Add a bool property
108 pg->Append( new wxBoolProperty(wxT("BoolProperty"), wxPG_LABEL, false) );
110 // A string property that can be edited in a separate editor dialog.
111 pg->Append( new wxLongStringProperty(wxT("LongStringProperty"),
113 wxT("This is much longer string than the ")
114 wxT("first one. Edit it by clicking the button.")));
116 // String editor with dir selector button.
117 pg->Append( new wxDirProperty(wxT("DirProperty"), wxPG_LABEL, ::wxGetUserHome()) );
119 // wxArrayStringProperty embeds a wxArrayString.
120 pg->Append( new wxArrayStringProperty(wxT("Label of ArrayStringProperty"),
121 wxT("NameOfArrayStringProp")));
123 // A file selector property.
124 pg->Append( new wxFileProperty(wxT("FileProperty"), wxPG_LABEL, wxEmptyString) );
126 // Extra: set wild card for file property (format same as in wxFileDialog).
127 pg->SetPropertyAttribute( wxT("FileProperty"),
129 wxT("All files (*.*)|*.*") );
133 Operations on properties are usually done by directly calling wxPGProperty's
134 or wxPropertyGridInterface's member functions. wxPropertyGridInterface is an
135 abstract base class for property containers such as wxPropertyGrid,
136 wxPropertyGridManager, and wxPropertyGridPage. Note however that wxPGProperty's
137 member functions generally do not refresh the grid.
139 wxPropertyGridInterface's property operation member functions , such as
140 SetPropertyValue() and DisableProperty(), all accept a special wxPGPropArg id
141 argument, using which you can refer to properties either by their pointer
142 (for performance) or by their name (for convenience). For instance:
145 // Add a file selector property.
146 wxPGPropety* prop = pg->Append( new wxFileProperty(wxT("FileProperty"),
150 // Valid: Set wild card by name
151 pg->SetPropertyAttribute( wxT("FileProperty"),
153 wxT("All files (*.*)|*.*") );
155 // Also Valid: Set wild card by property pointer
156 pg->SetPropertyAttribute( prop,
158 wxT("All files (*.*)|*.*") );
161 Using pointer is faster, since it doesn't require hash map lookup. Anyway,
162 you can always get property pointer (wxPGProperty*) as return value from Append()
163 or Insert(), or by calling wxPropertyGridInterface::GetPropertyByName() or
164 just plain GetProperty().
166 @section propgrid_categories Categories
168 wxPropertyGrid has a hierarchic property storage and display model, which
169 allows property categories to hold child properties and even other
170 categories. Other than that, from the programmer's point of view, categories
171 can be treated exactly the same as "other" properties. For example, despite
172 its name, GetPropertyByName() also returns a category by name. Note however
173 that sometimes the label of a property category may be referred as caption
174 (for example, there is wxPropertyGrid::SetCaptionTextColour() method
175 that sets text colour of property category labels).
177 When category is added at the top (i.e. root) level of the hierarchy,
178 it becomes a *current category*. This means that all other (non-category)
179 properties after it are automatically appended to it. You may add
180 properties to specific categories by using wxPropertyGridInterface::Insert
181 or wxPropertyGridInterface::AppendIn.
183 Category code sample:
187 // One way to add category (similar to how other properties are added)
188 pg->Append( new wxPropertyCategory(wxT("Main")) );
190 // All these are added to "Main" category
191 pg->Append( new wxStringProperty(wxT("Name")) );
192 pg->Append( new wxIntProperty(wxT("Age"),wxPG_LABEL,25) );
193 pg->Append( new wxIntProperty(wxT("Height"),wxPG_LABEL,180) );
194 pg->Append( new wxIntProperty(wxT("Weight")) );
197 pg->Append( new wxPropertyCategory(wxT("Attributes")) );
199 // All these are added to "Attributes" category
200 pg->Append( new wxIntProperty(wxT("Intelligence")) );
201 pg->Append( new wxIntProperty(wxT("Agility")) );
202 pg->Append( new wxIntProperty(wxT("Strength")) );
207 @section propgrid_parentprops Tree-like Property Structure
209 Basically any property can have children. There are few limitations, however.
212 - Names of properties with non-category, non-root parents are not stored in global
213 hash map. Instead, they can be accessed with strings like "Parent.Child".
214 For instance, in the sample below, child property named "Max. Speed (mph)"
215 can be accessed by global name "Car.Speeds.Max Speed (mph)".
216 - If you want to property's value to be a string composed of the child property values,
217 you must use wxStringProperty as parent and use magic string "<composed>" as its
219 - Events (eg. change of value) that occur in parent do not propagate to children. Events
220 that occur in children will propagate to parents, but only if they are wxStringProperties
221 with "<composed>" value.
226 wxPGProperty* carProp = pg->Append(new wxStringProperty(wxT("Car"),
230 pg->AppendIn(carProp, new wxStringProperty(wxT("Model"),
232 wxT("Lamborghini Diablo SV")));
234 pg->AppendIn(carProp, new wxIntProperty(wxT("Engine Size (cc)"),
238 wxPGProperty* speedsProp = pg->AppendIn(carProp,
239 new wxStringProperty(wxT("Speeds"),
243 pg->AppendIn( speedsProp, new wxIntProperty(wxT("Max. Speed (mph)"),
245 pg->AppendIn( speedsProp, new wxFloatProperty(wxT("0-100 mph (sec)"),
247 pg->AppendIn( speedsProp, new wxFloatProperty(wxT("1/4 mile (sec)"),
250 // This is how child property can be referred to by name
251 pg->SetPropertyValue( wxT("Car.Speeds.Max. Speed (mph)"), 300 );
253 pg->AppendIn(carProp, new wxIntProperty(wxT("Price ($)"),
257 // Displayed value of "Car" property is now very close to this:
258 // "Lamborghini Diablo SV; 5707 [300; 3.9; 8.6] 300000"
262 @section propgrid_enumandflags wxEnumProperty and wxFlagsProperty
264 wxEnumProperty is used when you want property's (integer or string) value
265 to be selected from a popup list of choices.
267 Creating wxEnumProperty is slightly more complex than those described
268 earlier. You have to provide list of constant labels, and optionally relevant
269 values (if label indexes are not sufficient).
273 - Value wxPG_INVALID_VALUE (equals INT_MAX) is not allowed as list
276 A very simple example:
281 // Using wxArrayString
283 wxArrayString arrDiet;
284 arr.Add(wxT("Herbivore"));
285 arr.Add(wxT("Carnivore"));
286 arr.Add(wxT("Omnivore"));
288 pg->Append( new wxEnumProperty(wxT("Diet"),
293 // Using wxChar* array
295 const wxChar* arrayDiet[] =
296 { wxT("Herbivore"), wxT("Carnivore"), wxT("Omnivore"), NULL };
298 pg->Append( new wxEnumProperty(wxT("Diet"),
304 Here's extended example using values as well:
309 // Using wxArrayString and wxArrayInt
311 wxArrayString arrDiet;
312 arr.Add(wxT("Herbivore"));
313 arr.Add(wxT("Carnivore"));
314 arr.Add(wxT("Omnivore"));
321 // Note that the initial value (the last argument) is the actual value,
322 // not index or anything like that. Thus, our value selects "Omnivore".
323 pg->Append( new wxEnumProperty(wxT("Diet"),
331 wxPGChoices is a class where wxEnumProperty, and other properties which
332 require storage for list of items, actually stores strings and values. It is
333 used to facilitate reference counting, and therefore recommended way of
334 adding items when multiple properties share the same set.
336 You can use wxPGChoices directly as well, filling it and then passing it
337 to the constructor. In fact, if you wish to display bitmaps next to labels,
338 your best choice is to use this approach.
343 chs.Add(wxT("Herbivore"), 40);
344 chs.Add(wxT("Carnivore"), 45);
345 chs.Add(wxT("Omnivore"), 50);
347 // Let's add an item with bitmap, too
348 chs.Add(wxT("None of the above"), wxBitmap(), 60);
350 pg->Append( new wxEnumProperty(wxT("Primary Diet"),
354 // Add same choices to another property as well - this is efficient due
355 // to reference counting
356 pg->Append( new wxEnumProperty(wxT("Secondary Diet"),
361 You can later change choices of property by using wxPGProperty::AddChoice(),
362 wxPGProperty::InsertChoice(), wxPGProperty::DeleteChoice(), and
363 wxPGProperty::SetChoices().
365 <b>wxEditEnumProperty</b> works exactly like wxEnumProperty, except
366 is uses non-read-only combo box as default editor, and value is stored as
367 string when it is not any of the choices.
369 wxFlagsProperty has similar construction:
373 const wxChar* flags_prop_labels[] = { wxT("wxICONIZE"),
374 wxT("wxCAPTION"), wxT("wxMINIMIZE_BOX"), wxT("wxMAXIMIZE_BOX"), NULL };
376 // this value array would be optional if values matched string indexes
377 long flags_prop_values[] = { wxICONIZE, wxCAPTION, wxMINIMIZE_BOX,
380 pg->Append( new wxFlagsProperty(wxT("Window Style"),
384 wxDEFAULT_FRAME_STYLE) );
388 wxFlagsProperty can use wxPGChoices just the same way as wxEnumProperty
389 <b>Note:</b> When changing "choices" (ie. flag labels) of wxFlagsProperty,
390 you will need to use wxPGProperty::SetChoices() to replace all choices
391 at once - otherwise implicit child properties will not get updated properly.
393 @section propgrid_advprops Specialized Properties
395 This section describes the use of less often needed property classes.
396 To use them, you have to include <wx/propgrid/advprops.h>.
400 // Necessary extra header file
401 #include <wx/propgrid/advprops.h>
406 pg->Append( new wxDateProperty(wxT("MyDateProperty"),
408 wxDateTime::Now()) );
410 // Image file property. Wild card is auto-generated from available
411 // image handlers, so it is not set this time.
412 pg->Append( new wxImageFileProperty(wxT("Label of ImageFileProperty"),
413 wxT("NameOfImageFileProp")) );
415 // Font property has sub-properties. Note that we give window's font as
417 pg->Append( new wxFontProperty(wxT("Font"),
421 // Colour property with arbitrary colour.
422 pg->Append( new wxColourProperty(wxT("My Colour 1"),
424 wxColour(242,109,0) ) );
426 // System colour property.
427 pg->Append( new wxSystemColourProperty(wxT("My SysColour 1"),
429 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)) );
431 // System colour property with custom colour.
432 pg->Append( new wxSystemColourProperty(wxT("My SysColour 2"),
434 wxColour(0,200,160) ) );
437 pg->Append( new wxCursorProperty(wxT("My Cursor"),
444 @section propgrid_processingvalues Processing Property Values
446 Properties store their values internally in wxVariant. You can obtain
447 this value using wxPGProperty::GetValue() or wxPropertyGridInterface::
450 If you wish to obtain property value in specific data type, you can
451 call various getter functions, such as wxPropertyGridInterface::
452 GetPropertyValueAsString(), which, as name might say, returns property
453 value's string representation. While this particular function is very
454 safe to use for any kind of property, some might display error message
455 if property value is not in compatible enough format. For instance,
456 wxPropertyGridInterface::GetPropertyValueAsLongLong() will support
457 long as well as wxLongLong, but GetPropertyValueAsArrayString() only
458 supports wxArrayString and nothing else.
460 In any case, you will need to take extra care when dealing with
461 raw wxVariant values. For instance, wxIntProperty and wxUIntProperty,
462 store value internally as wx(U)LongLong when number doesn't fit into
463 standard long type. Using << operator to get wx(U)LongLong from wxVariant
464 is customized to work quite safely with various types of variant data.
466 You may have noticed that properties store, in wxVariant, values of many
467 types which are not natively supported by it. Custom wxVariantDatas
468 are therefore implemented and << and >> operators implemented to
469 convert data from and to wxVariant.
471 Note that in some cases property value can be Null variant, which means
472 that property value is unspecified. This usually occurs only when
473 wxPG_EX_AUTO_UNSPECIFIED_VALUES extra window style is defined or when you
474 manually set property value to Null (or unspecified).
477 @section propgrid_iterating Iterating through a property container
479 You can use somewhat STL'ish iterator classes to iterate through the grid.
480 Here is a simple example of forward iterating through all individual
481 properties (not categories nor private child properties that are normally
482 'transparent' to application code):
486 wxPropertyGridIterator it;
488 for ( it = pg->GetIterator();
492 wxPGProperty* p = *it;
493 // Do something with the property
498 As expected there is also a const iterator:
502 wxPropertyGridConstIterator it;
504 for ( it = pg->GetIterator();
508 const wxPGProperty* p = *it;
509 // Do something with the property
514 You can give some arguments to GetIterator to determine which properties
515 get automatically filtered out. For complete list of options, see
516 @ref propgrid_iterator_flags. GetIterator() also accepts other arguments.
517 See wxPropertyGridInterface::GetIterator() for details.
519 This example reverse-iterates through all visible items:
523 wxPropertyGridIterator it;
525 for ( it = pg->GetIterator(wxPG_ITERATE_VISIBLE, wxBOTTOM);
529 wxPGProperty* p = *it;
530 // Do something with the property
535 <b>wxPython Note:</b> Instead of ++ operator, use Next() method, and instead of
536 * operator, use GetProperty() method.
538 GetIterator() only works with wxPropertyGrid and the individual pages
539 of wxPropertyGridManager. In order to iterate through an arbitrary
540 property container (such as entire wxPropertyGridManager), you need to use
541 wxPropertyGridInterface::GetVIterator(). Note however that this virtual
542 iterator is limited to forward iteration.
548 for ( it = manager->GetVIterator();
552 wxPGProperty* p = it.GetProperty();
553 // Do something with the property
558 @section propgrid_populating Populating wxPropertyGrid Automatically
560 @subsection propgrid_fromvariants Populating from List of wxVariants
562 Example of populating an empty wxPropertyGrid from a values stored
563 in an arbitrary list of wxVariants.
567 // This is a static method that initializes *all* built-in type handlers
568 // available, including those for wxColour and wxFont. Refers to *all*
569 // included properties, so when compiling with static library, this
570 // method may increase the executable size noticeably.
571 pg->InitAllTypeHandlers();
573 // Get contents of the grid as a wxVariant list
574 wxVariant all_values = pg->GetPropertyValues();
576 // Populate the list with values. If a property with appropriate
577 // name is not found, it is created according to the type of variant.
578 pg->SetPropertyValues( my_list_variant );
582 @subsection propgrid_fromfile Loading Population from a Text-based Storage
584 Class wxPropertyGridPopulator may be helpful when writing code that
585 loads properties from a text-source. In fact, the wxPropertyGrid xrc-handler
586 (which may not be currently included in wxWidgets, but probably will be in
587 near future) uses it.
589 @subsection editablestate Saving and Restoring User-Editable State
591 You can use wxPropertyGridInterface::SaveEditableState() and
592 wxPropertyGridInterface::RestoreEditableState() to save and restore
593 user-editable state (selected property, expanded/collapsed properties,
594 selected page, scrolled position, and splitter positions).
596 @section propgrid_events Event Handling
598 Probably the most important event is the Changed event which occurs when
599 value of any property is changed by the user. Use EVT_PG_CHANGED(id,func)
600 in your event table to use it.
602 For complete list of event types, see wxPropertyGrid class reference.
604 However, one type of event that might need focused attention is EVT_PG_CHANGING,
605 which occurs just prior property value is being changed by user. You can
606 acquire pending value using wxPropertyGridEvent::GetValue(), and if it is
607 not acceptable, call wxPropertyGridEvent::Veto() to prevent the value change
612 void MyForm::OnPropertyGridChanging( wxPropertyGridEvent& event )
614 wxPGProperty* property = event.GetProperty();
616 if ( property == m_pWatchThisProperty )
618 // GetValue() returns the pending value, but is only
619 // supported by wxEVT_PG_CHANGING.
620 if ( event.GetValue().GetString() == g_pThisTextIsNotAllowed )
630 @remarks On Child Property Event Handling
631 - For properties which have private, implicit children (wxFontProperty and
632 wxFlagsProperty), events occur for the main parent property only.
633 For other properties events occur for the children themselves. See
634 @ref propgrid_parentprops.
636 - When property's child gets changed, you can use wxPropertyGridEvent::GetMainParent()
637 to obtain its topmost non-category parent (useful, if you have deeply nested
641 @section propgrid_validating Validating Property Values
643 There are various ways to make sure user enters only correct values. First, you
644 can use wxValidators similar to as you would with ordinary controls. Use
645 wxPropertyGridInterface::SetPropertyValidator() to assign wxValidator to
648 Second, you can subclass a property and override wxPGProperty::ValidateValue(),
649 or handle wxEVT_PG_CHANGING for the same effect. Both of these ways do not
650 actually prevent user from temporarily entering invalid text, but they do give
651 you an opportunity to warn the user and block changed value from being committed
654 Various validation failure options can be controlled globally with
655 wxPropertyGrid::SetValidationFailureBehavior(), or on an event basis by
656 calling wxEvent::SetValidationFailureBehavior(). Here's a code snippet of
657 how to handle wxEVT_PG_CHANGING, and to set custom failure behaviour and
661 void MyFrame::OnPropertyGridChanging(wxPropertyGridEvent& event)
663 wxPGProperty* property = event.GetProperty();
665 // You must use wxPropertyGridEvent::GetValue() to access
666 // the value to be validated.
667 wxVariant pendingValue = event.GetValue();
669 if ( property->GetName() == wxT("Font") )
671 // Make sure value is not unspecified
672 if ( !pendingValue.IsNull() )
675 font << pendingValue;
677 // Let's just allow Arial font
678 if ( font.GetFaceName() != wxT("Arial") )
681 event.SetValidationFailureBehavior(wxPG_VFB_STAY_IN_PROPERTY |
683 wxPG_VFB_SHOW_MESSAGE);
691 @section propgrid_cellrender Customizing Individual Cell Appearance
693 You can control text colour, background colour, and attached image of
694 each cell in the property grid. Use wxPropertyGridInterface::SetPropertyCell() or
695 wxPGProperty::SetCell() for this purpose.
697 In addition, it is possible to control these characteristics for
698 wxPGChoices list items. See wxPGChoices class reference for more info.
701 @section propgrid_customizing Customizing Properties (without sub-classing)
703 In this section are presented miscellaneous ways to have custom appearance
704 and behavior for your properties without all the necessary hassle
705 of sub-classing a property class etc.
707 @subsection propgrid_customimage Setting Value Image
709 Every property can have a small value image placed in front of the
710 actual value text. Built-in example of this can be seen with
711 wxColourProperty and wxImageFileProperty, but for others it can
712 be set using wxPropertyGrid::SetPropertyImage method.
714 @subsection propgrid_customeditor Setting Property's Editor Control(s)
716 You can set editor control (or controls, in case of a control and button),
717 of any property using wxPropertyGrid::SetPropertyEditor. Editors are passed
718 as wxPGEditor_EditorName, and valid built-in EditorNames are
719 TextCtrl, Choice, ComboBox, CheckBox, TextCtrlAndButton, ChoiceAndButton,
720 SpinCtrl, and DatePickerCtrl. Two last mentioned ones require call to
721 static member function wxPropertyGrid::RegisterAdditionalEditors().
723 Following example changes wxColourProperty's editor from default Choice
724 to TextCtrlAndButton. wxColourProperty has its internal event handling set
725 up so that button click events of the button will be used to trigger
726 colour selection dialog.
730 wxPGProperty* colProp = new wxColourProperty(wxT("Text Colour"));
732 pg->SetPropertyEditor(colProp, wxPGEditor_TextCtrlAndButton);
736 Naturally, creating and setting custom editor classes is a possibility as
737 well. For more information, see wxPGEditor class reference.
739 @subsection propgrid_editorattrs Property Attributes Recognized by Editors
741 <b>SpinCtrl</b> editor can make use of property's "Min", "Max", "Step" and
744 @subsection propgrid_multiplebuttons Adding Multiple Buttons Next to an Editor
746 See wxPGMultiButton class reference.
748 @subsection propgrid_customeventhandling Handling Events Passed from Properties
750 <b>wxEVT_COMMAND_BUTTON_CLICKED </b>(corresponds to event table macro EVT_BUTTON):
751 Occurs when editor button click is not handled by the property itself
752 (as is the case, for example, if you set property's editor to TextCtrlAndButton
753 from the original TextCtrl).
755 @subsection propgrid_attributes Property Attributes
757 Miscellaneous values, often specific to a property type, can be set
758 using wxPropertyGridInterface::SetPropertyAttribute() and
759 wxPropertyGridInterface::SetPropertyAttributeAll() methods.
761 Attribute names are strings and values wxVariant. Arbitrary names are allowed
762 in order to store values that are relevant to application only and not
763 property grid. Constant equivalents of all attribute string names are
764 provided. Some of them are defined as cached strings, so using these constants
765 can provide for smaller binary size.
767 For complete list of attributes, see @ref propgrid_property_attributes.
770 @section propgrid_usage2 Using wxPropertyGridManager
772 wxPropertyGridManager is an efficient multi-page version of wxPropertyGrid,
773 which can optionally have tool bar for mode and page selection, and a help text
774 box. For more information, see wxPropertyGridManager class reference.
776 @subsection propgrid_propgridpage wxPropertyGridPage
778 wxPropertyGridPage is holder of properties for one page in manager. It is derived from
779 wxEvtHandler, so you can subclass it to process page-specific property grid events. Hand
780 over your page instance in wxPropertyGridManager::AddPage().
782 Please note that the wxPropertyGridPage itself only sports subset of wxPropertyGrid API
783 (but unlike manager, this include item iteration). Naturally it inherits from
784 wxPropertyGridInterface.
786 For more information, see wxPropertyGridPage class reference.
789 @section propgrid_subclassing Sub-classing wxPropertyGrid and wxPropertyGridManager
793 - Only a small percentage of member functions are virtual. If you need more,
794 just e-mail to wx-dev mailing list.
796 - Data manipulation is done in wxPropertyGridPageState class. So, instead of
797 overriding wxPropertyGrid::Insert(), you'll probably want to override
798 wxPropertyGridPageState::DoInsert(). See header file for details.
800 - Override wxPropertyGrid::CreateState() to instantiate your derivate
801 wxPropertyGridPageState. For wxPropertyGridManager, you'll need to subclass
802 wxPropertyGridPage instead (since it is derived from wxPropertyGridPageState),
803 and hand over instances in wxPropertyGridManager::AddPage() calls.
805 - You can use a derivate wxPropertyGrid with manager by overriding
806 wxPropertyGridManager::CreatePropertyGrid() member function.
809 @section propgrid_misc Miscellaneous Topics
811 @subsection propgrid_namescope Property Name Scope
813 All properties which parent is category or root can be accessed
814 directly by their base name (ie. name given for property in its constructor).
815 Other properties can be accessed via "ParentsName.BaseName" notation,
816 Naturally, all property names should be unique.
818 @subsection propgrid_nonuniquelabels Non-unique Labels
820 It is possible to have properties with identical label under same parent.
821 However, care must be taken to ensure that each property still has
824 @subsection propgrid_boolproperty wxBoolProperty
826 There are few points about wxBoolProperty that require further discussion:
827 - wxBoolProperty can be shown as either normal combo box or as a check box.
828 Property attribute wxPG_BOOL_USE_CHECKBOX is used to change this.
829 For example, if you have a wxFlagsProperty, you can
830 set its all items to use check box using the following:
832 pg->SetPropertyAttribute(wxT("MyFlagsProperty"),wxPG_BOOL_USE_CHECKBOX,true,wxPG_RECURSE);
835 Following will set all individual bool properties in your control to
839 pg->SetPropertyAttributeAll(wxPG_BOOL_USE_CHECKBOX, true);
842 - Default item names for wxBoolProperty are ["False", "True"]. This can be
843 changed using static function wxPropertyGrid::SetBoolChoices(trueChoice,
846 @subsection propgrid_textctrlupdates Updates from wxTextCtrl Based Editor
848 Changes from wxTextCtrl based property editors are committed (ie.
849 wxEVT_PG_CHANGED is sent etc.) *only* when (1) user presser enter, (2)
850 user moves to edit another property, or (3) when focus leaves
853 Because of this, you may find it useful, in some apps, to call
854 wxPropertyGrid::CommitChangesFromEditor() just before you need to do any
855 computations based on property grid values. Note that CommitChangesFromEditor()
856 will dispatch wxEVT_PG_CHANGED with ProcessEvent, so any of your event handlers
857 will be called immediately.
859 @subsection propgrid_splittercentering Centering the Splitter
861 If you need to center the splitter, but only once when the program starts,
862 then do <b>not</b> use the wxPG_SPLITTER_AUTO_CENTER window style, but the
863 wxPropertyGrid::CenterSplitter() method. <b>However, be sure to call it after
864 the sizer setup and SetSize calls!</b> (ie. usually at the end of the
865 frame/dialog constructor)
867 @subsection propgrid_splittersetting Setting Splitter Position When Creating Property Grid
869 Splitter position cannot exceed grid size, and therefore setting it during
870 form creation may fail as initial grid size is often smaller than desired
871 splitter position, especially when sizers are being used.
873 @subsection propgrid_colourproperty wxColourProperty and wxSystemColourProperty
875 Through sub-classing, these two property classes provide substantial customization
876 features. Subclass wxSystemColourProperty if you want to use wxColourPropertyValue
877 (which features colour type in addition to wxColour), and wxColourProperty if plain
880 Override wxSystemColourProperty::ColourToString() to redefine how colours are
883 Override wxSystemColourProperty::GetCustomColourIndex() to redefine location of
884 the item that triggers colour picker dialog (default is last).
886 Override wxSystemColourProperty::GetColour() to determine which colour matches
889 @section propgrid_proplist Property Class Descriptions
891 See @ref pgproperty_properties
893 @section propgrid_compat Changes from wxPropertyGrid 1.4
895 Version of wxPropertyGrid bundled with wxWidgets 2.9+ has various backward-
896 incompatible changes from version 1.4, which had a stable API and will remain
897 as the last separate branch.
899 Note that in general any behavior-breaking changes should not compile or run
900 without warnings or errors.
902 @subsection propgrid_compat_general General Changes
904 - Tab-traversal can no longer be used to travel between properties. Now
905 it only causes focus to move from main grid to editor of selected property.
906 Arrow keys are now your primary means of navigating between properties,
907 with keyboard. This change allowed fixing broken tab traversal on wxGTK
908 (which is open issue in wxPropertyGrid 1.4).
910 - A few member functions were removed from wxPropertyGridInterface.
911 Please use wxPGProperty's counterparts from now on.
913 - wxPGChoices now has proper Copy-On-Write behavior.
915 - wxPGChoices::SetExclusive() was renamed to AllocExclusive().
917 - wxPGProperty::SetPropertyChoicesExclusive() was removed. Instead, use
918 GetChoices().AllocExclusive().
920 - wxPGProperty::ClearModifiedStatus() is removed. Please use
921 SetModifiedStatus() instead.
923 - wxPropertyGridInterface::GetExpandedProperties() is removed. You should
924 now use wxPropertyGridInterface::GetEditableState() instead.
926 - wxPG_EX_DISABLE_TLP_TRACKING is now enabled by default. To get the old
927 behavior (recommended if you don't use a system that reparents the grid
928 on its own), use the wxPG_EX_ENABLE_TLP_TRACKING extra style.
930 - Extended window style wxPG_EX_LEGACY_VALIDATORS was removed.
932 - wxPropertyGridManager now has same Get/SetSelection() semantics as
935 - Various wxPropertyGridManager page-related functions now return pointer
936 to the page object instead of index.
938 - Instead of calling wxPropertyGrid::SetButtonShortcut(), use
939 wxPropertyGrid::SetActionTrigger(wxPG_ACTION_PRESS_BUTTON).
941 - wxPGProperty::GetCell() now returns a reference. AcquireCell() was removed.
943 - wxPGMultiButton::FinalizePosition() has been renamed to Finalize(),
944 and it has slightly different argument list.
946 - wxPropertyGridEvent::HasProperty() is removed. You can use GetProperty()
947 as immediate replacement when checking if event has a property.
949 @subsection propgrid_compat_propdev Property and Editor Sub-classing Changes
951 - Confusing custom property macros have been eliminated.
953 - Implement wxPGProperty::ValueToString() instead of GetValueAsString().
955 - wxPGProperty::ChildChanged() must now return the modified value of
956 whole property instead of writing it back into 'thisValue' argument.
958 - Removed wxPropertyGrid::PrepareValueForDialogEditing(). Use
959 wxPropertyGrid::GetPendingEditedValue() instead.
961 - wxPGProperty::GetChoiceInfo() is removed, as all properties now carry
962 wxPGChoices instance (protected wxPGProperty::m_choices).
964 - Connect() should no longer be called in implementations of
965 wxPGEditor::CreateControls(). wxPropertyGrid automatically passes all
966 events from editor to wxPGEditor::OnEvent() and wxPGProperty::OnEvent(),
969 - wxPython: Previously some of the reimplemented member functions needed a
970 'Py' prefix. This is no longer necessary. For instance, if you previously
971 implemented PyStringToValue() for your custom property, you should now
972 just implement StringToValue().