2008-09-12 16:57:41 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: propgrid.h
|
|
|
|
// Purpose: topic overview
|
|
|
|
// Author: wxWidgets team
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2008-09-12 16:57:41 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
@page overview_propgrid wxPropertyGrid Overview
|
|
|
|
|
2012-11-03 14:34:10 -04:00
|
|
|
@tableofcontents
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2012-11-03 14:34:10 -04:00
|
|
|
wxPropertyGrid is a specialized grid for editing properties - in other words
|
|
|
|
name = value pairs. List of ready-to-use property classes include strings,
|
|
|
|
numbers, flag sets, fonts, colours and many others. It is possible, for
|
|
|
|
example, to categorize properties, set up a complete tree-hierarchy, add more
|
|
|
|
than two columns, and set arbitrary per-property attributes.
|
|
|
|
|
|
|
|
As this version of wxPropertyGrid has some backward-incompatible changes from
|
|
|
|
version 1.4, everybody who need to maintain custom property classes should
|
|
|
|
carefully read final section in @ref propgrid_compat.
|
|
|
|
|
|
|
|
@see wxPropertyGrid, wxPropertyGridEvent, wxPropertyGridManager,
|
|
|
|
wxPropertyGridPage, wxPGProperty
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2009-06-07 05:02:35 -04:00
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
|
|
|
|
@section propgrid_basics Creating and Populating wxPropertyGrid
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
As seen here, wxPropertyGrid is constructed in the same way as
|
|
|
|
other wxWidgets controls:
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
|
|
|
// Necessary header file
|
|
|
|
#include <wx/propgrid/propgrid.h>
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
// Assumes code is in frame/dialog constructor
|
|
|
|
|
|
|
|
// Construct wxPropertyGrid control
|
|
|
|
wxPropertyGrid* pg = new wxPropertyGrid(
|
|
|
|
this, // parent
|
|
|
|
PGID, // id
|
|
|
|
wxDefaultPosition, // position
|
|
|
|
wxDefaultSize, // size
|
|
|
|
// Here are just some of the supported window styles
|
|
|
|
wxPG_AUTO_SORT | // Automatic sorting after items added
|
|
|
|
wxPG_SPLITTER_AUTO_CENTER | // Automatically center splitter until user manually adjusts it
|
|
|
|
// Default style
|
|
|
|
wxPG_DEFAULT_STYLE );
|
|
|
|
|
|
|
|
// Window style flags are at premium, so some less often needed ones are
|
|
|
|
// available as extra window styles (wxPG_EX_xxx) which must be set using
|
|
|
|
// SetExtraStyle member function. wxPG_EX_HELP_AS_TOOLTIPS, for instance,
|
2008-09-21 10:13:32 -04:00
|
|
|
// allows displaying help strings as tool tips.
|
2008-09-12 16:57:41 -04:00
|
|
|
pg->SetExtraStyle( wxPG_EX_HELP_AS_TOOLTIPS );
|
|
|
|
|
|
|
|
@endcode
|
|
|
|
|
2008-09-18 13:14:13 -04:00
|
|
|
(for complete list of new window styles, see @ref propgrid_window_styles)
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
wxPropertyGrid is usually populated with lines like this:
|
|
|
|
|
|
|
|
@code
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxStringProperty("Label", "Name", "Initial Value") );
|
2008-09-12 16:57:41 -04:00
|
|
|
@endcode
|
|
|
|
|
|
|
|
Naturally, wxStringProperty is a property class. Only the first function argument (label)
|
|
|
|
is mandatory. Second one, name, defaults to label and, third, the initial value, to
|
|
|
|
default value. If constant wxPG_LABEL is used as the name argument, then the label is
|
2008-09-14 09:14:32 -04:00
|
|
|
automatically used as a name as well (this is more efficient than manually defining both
|
|
|
|
as the same). Use of empty name is discouraged and will sometimes result in run-time error.
|
|
|
|
Note that all property class constructors have quite similar constructor argument list.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
To demonstrate other common property classes, here's another code snippet:
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
|
|
|
// Add int property
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxIntProperty("IntProperty", wxPG_LABEL, 12345678) );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
// Add float property (value type is actually double)
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxFloatProperty("FloatProperty", wxPG_LABEL, 12345.678) );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
// Add a bool property
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxBoolProperty("BoolProperty", wxPG_LABEL, false) );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
// A string property that can be edited in a separate editor dialog.
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxLongStringProperty("LongStringProperty",
|
2008-09-12 16:57:41 -04:00
|
|
|
wxPG_LABEL,
|
2009-12-26 05:51:39 -05:00
|
|
|
"This is much longer string than the "
|
|
|
|
"first one. Edit it by clicking the button."));
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
// String editor with dir selector button.
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxDirProperty("DirProperty", wxPG_LABEL, ::wxGetUserHome()) );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
// wxArrayStringProperty embeds a wxArrayString.
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxArrayStringProperty("Label of ArrayStringProperty",
|
|
|
|
"NameOfArrayStringProp"));
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
// A file selector property.
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxFileProperty("FileProperty", wxPG_LABEL, wxEmptyString) );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
// Extra: set wild card for file property (format same as in wxFileDialog).
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->SetPropertyAttribute( "FileProperty",
|
2008-09-12 16:57:41 -04:00
|
|
|
wxPG_FILE_WILDCARD,
|
2009-12-26 05:51:39 -05:00
|
|
|
"All files (*.*)|*.*" );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
@endcode
|
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
Operations on properties are usually done by directly calling wxPGProperty's
|
|
|
|
or wxPropertyGridInterface's member functions. wxPropertyGridInterface is an
|
|
|
|
abstract base class for property containers such as wxPropertyGrid,
|
|
|
|
wxPropertyGridManager, and wxPropertyGridPage. Note however that wxPGProperty's
|
|
|
|
member functions generally do not refresh the grid.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
wxPropertyGridInterface's property operation member functions , such as
|
|
|
|
SetPropertyValue() and DisableProperty(), all accept a special wxPGPropArg id
|
|
|
|
argument, using which you can refer to properties either by their pointer
|
|
|
|
(for performance) or by their name (for convenience). For instance:
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
@code
|
2008-09-21 10:13:32 -04:00
|
|
|
// Add a file selector property.
|
2011-09-18 16:28:37 -04:00
|
|
|
wxPGProperty* prop = pg->Append( new wxFileProperty("FileProperty",
|
|
|
|
wxPG_LABEL,
|
|
|
|
wxEmptyString) );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
// Valid: Set wild card by name
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->SetPropertyAttribute( "FileProperty",
|
2008-09-12 16:57:41 -04:00
|
|
|
wxPG_FILE_WILDCARD,
|
2009-12-26 05:51:39 -05:00
|
|
|
"All files (*.*)|*.*" );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
// Also Valid: Set wild card by property pointer
|
|
|
|
pg->SetPropertyAttribute( prop,
|
2008-09-12 16:57:41 -04:00
|
|
|
wxPG_FILE_WILDCARD,
|
2009-12-26 05:51:39 -05:00
|
|
|
"All files (*.*)|*.*" );
|
2008-09-12 16:57:41 -04:00
|
|
|
@endcode
|
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
Using pointer is faster, since it doesn't require hash map lookup. Anyway,
|
|
|
|
you can always get property pointer (wxPGProperty*) as return value from Append()
|
|
|
|
or Insert(), or by calling wxPropertyGridInterface::GetPropertyByName() or
|
|
|
|
just plain GetProperty().
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@section propgrid_categories Categories
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
wxPropertyGrid has a hierarchic property storage and display model, which
|
2008-09-12 16:57:41 -04:00
|
|
|
allows property categories to hold child properties and even other
|
|
|
|
categories. Other than that, from the programmer's point of view, categories
|
|
|
|
can be treated exactly the same as "other" properties. For example, despite
|
2008-09-21 10:13:32 -04:00
|
|
|
its name, GetPropertyByName() also returns a category by name. Note however
|
|
|
|
that sometimes the label of a property category may be referred as caption
|
|
|
|
(for example, there is wxPropertyGrid::SetCaptionTextColour() method
|
|
|
|
that sets text colour of property category labels).
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
When category is added at the top (i.e. root) level of the hierarchy,
|
|
|
|
it becomes a *current category*. This means that all other (non-category)
|
2008-09-21 10:13:32 -04:00
|
|
|
properties after it are automatically appended to it. You may add
|
|
|
|
properties to specific categories by using wxPropertyGridInterface::Insert
|
|
|
|
or wxPropertyGridInterface::AppendIn.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
Category code sample:
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
|
|
|
// One way to add category (similar to how other properties are added)
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxPropertyCategory("Main") );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
// All these are added to "Main" category
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxStringProperty("Name") );
|
|
|
|
pg->Append( new wxIntProperty("Age",wxPG_LABEL,25) );
|
|
|
|
pg->Append( new wxIntProperty("Height",wxPG_LABEL,180) );
|
|
|
|
pg->Append( new wxIntProperty("Weight") );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
// Another one
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxPropertyCategory("Attributes") );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
// All these are added to "Attributes" category
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxIntProperty("Intelligence") );
|
|
|
|
pg->Append( new wxIntProperty("Agility") );
|
|
|
|
pg->Append( new wxIntProperty("Strength") );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@section propgrid_parentprops Tree-like Property Structure
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
Basically any property can have children. There are few limitations, however.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
@remarks
|
2008-09-21 10:13:32 -04:00
|
|
|
- Names of properties with non-category, non-root parents are not stored in global
|
|
|
|
hash map. Instead, they can be accessed with strings like "Parent.Child".
|
|
|
|
For instance, in the sample below, child property named "Max. Speed (mph)"
|
|
|
|
can be accessed by global name "Car.Speeds.Max Speed (mph)".
|
|
|
|
- If you want to property's value to be a string composed of the child property values,
|
|
|
|
you must use wxStringProperty as parent and use magic string "<composed>" as its
|
|
|
|
value.
|
2008-09-12 16:57:41 -04:00
|
|
|
- Events (eg. change of value) that occur in parent do not propagate to children. Events
|
|
|
|
that occur in children will propagate to parents, but only if they are wxStringProperties
|
|
|
|
with "<composed>" value.
|
|
|
|
|
|
|
|
Sample:
|
|
|
|
|
|
|
|
@code
|
2009-12-26 05:51:39 -05:00
|
|
|
wxPGProperty* carProp = pg->Append(new wxStringProperty("Car",
|
2008-09-21 10:13:32 -04:00
|
|
|
wxPG_LABEL,
|
2009-12-26 05:51:39 -05:00
|
|
|
"<composed>"));
|
2008-09-21 10:13:32 -04:00
|
|
|
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->AppendIn(carProp, new wxStringProperty("Model",
|
2008-09-21 10:13:32 -04:00
|
|
|
wxPG_LABEL,
|
2009-12-26 05:51:39 -05:00
|
|
|
"Lamborghini Diablo SV"));
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->AppendIn(carProp, new wxIntProperty("Engine Size (cc)",
|
2008-09-12 16:57:41 -04:00
|
|
|
wxPG_LABEL,
|
2008-09-21 10:13:32 -04:00
|
|
|
5707) );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
wxPGProperty* speedsProp = pg->AppendIn(carProp,
|
2009-12-26 05:51:39 -05:00
|
|
|
new wxStringProperty("Speeds",
|
2008-09-21 10:13:32 -04:00
|
|
|
wxPG_LABEL,
|
2009-12-26 05:51:39 -05:00
|
|
|
"<composed>"));
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->AppendIn( speedsProp, new wxIntProperty("Max. Speed (mph)",
|
2008-09-21 10:13:32 -04:00
|
|
|
wxPG_LABEL,290) );
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->AppendIn( speedsProp, new wxFloatProperty("0-100 mph (sec)",
|
2008-09-21 10:13:32 -04:00
|
|
|
wxPG_LABEL,3.9) );
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->AppendIn( speedsProp, new wxFloatProperty("1/4 mile (sec)",
|
2008-09-21 10:13:32 -04:00
|
|
|
wxPG_LABEL,8.6) );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
// This is how child property can be referred to by name
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->SetPropertyValue( "Car.Speeds.Max. Speed (mph)", 300 );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->AppendIn(carProp, new wxIntProperty("Price ($)",
|
2008-09-21 10:13:32 -04:00
|
|
|
wxPG_LABEL,
|
|
|
|
300000) );
|
|
|
|
|
|
|
|
// Displayed value of "Car" property is now very close to this:
|
|
|
|
// "Lamborghini Diablo SV; 5707 [300; 3.9; 8.6] 300000"
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
@endcode
|
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@section propgrid_enumandflags wxEnumProperty and wxFlagsProperty
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
wxEnumProperty is used when you want property's (integer or string) value
|
|
|
|
to be selected from a popup list of choices.
|
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
Creating wxEnumProperty is slightly more complex than those described
|
|
|
|
earlier. You have to provide list of constant labels, and optionally relevant
|
|
|
|
values (if label indexes are not sufficient).
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
@remarks
|
|
|
|
|
2008-09-19 12:57:33 -04:00
|
|
|
- Value wxPG_INVALID_VALUE (equals INT_MAX) is not allowed as list
|
|
|
|
item value.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
A very simple example:
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
|
|
|
//
|
|
|
|
// Using wxArrayString
|
|
|
|
//
|
|
|
|
wxArrayString arrDiet;
|
2017-03-22 04:55:07 -04:00
|
|
|
arrDiet.Add("Herbivore");
|
|
|
|
arrDiet.Add("Carnivore");
|
|
|
|
arrDiet.Add("Omnivore");
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxEnumProperty("Diet",
|
2008-09-12 16:57:41 -04:00
|
|
|
wxPG_LABEL,
|
|
|
|
arrDiet) );
|
|
|
|
|
|
|
|
//
|
|
|
|
// Using wxChar* array
|
|
|
|
//
|
|
|
|
const wxChar* arrayDiet[] =
|
|
|
|
{ wxT("Herbivore"), wxT("Carnivore"), wxT("Omnivore"), NULL };
|
|
|
|
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxEnumProperty("Diet",
|
2008-09-12 16:57:41 -04:00
|
|
|
wxPG_LABEL,
|
|
|
|
arrayDiet) );
|
|
|
|
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
Here's extended example using values as well:
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
|
|
|
//
|
|
|
|
// Using wxArrayString and wxArrayInt
|
|
|
|
//
|
|
|
|
wxArrayString arrDiet;
|
2017-03-22 04:55:07 -04:00
|
|
|
arrDiet.Add("Herbivore");
|
|
|
|
arrDiet.Add("Carnivore");
|
|
|
|
arrDiet.Add("Omnivore");
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
wxArrayInt arrIds;
|
|
|
|
arrIds.Add(40);
|
|
|
|
arrIds.Add(45);
|
|
|
|
arrIds.Add(50);
|
|
|
|
|
|
|
|
// Note that the initial value (the last argument) is the actual value,
|
|
|
|
// not index or anything like that. Thus, our value selects "Omnivore".
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxEnumProperty("Diet",
|
2008-09-12 16:57:41 -04:00
|
|
|
wxPG_LABEL,
|
|
|
|
arrDiet,
|
|
|
|
arrIds,
|
|
|
|
50));
|
|
|
|
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
wxPGChoices is a class where wxEnumProperty, and other properties which
|
2008-09-21 10:13:32 -04:00
|
|
|
require storage for list of items, actually stores strings and values. It is
|
|
|
|
used to facilitate reference counting, and therefore recommended way of
|
2008-09-12 16:57:41 -04:00
|
|
|
adding items when multiple properties share the same set.
|
|
|
|
|
|
|
|
You can use wxPGChoices directly as well, filling it and then passing it
|
2008-09-21 10:13:32 -04:00
|
|
|
to the constructor. In fact, if you wish to display bitmaps next to labels,
|
2008-09-12 16:57:41 -04:00
|
|
|
your best choice is to use this approach.
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
|
|
|
wxPGChoices chs;
|
2009-12-26 05:51:39 -05:00
|
|
|
chs.Add("Herbivore", 40);
|
|
|
|
chs.Add("Carnivore", 45);
|
|
|
|
chs.Add("Omnivore", 50);
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
// Let's add an item with bitmap, too
|
2009-12-26 05:51:39 -05:00
|
|
|
chs.Add("None of the above", wxBitmap(), 60);
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxEnumProperty("Primary Diet",
|
2008-09-12 16:57:41 -04:00
|
|
|
wxPG_LABEL,
|
|
|
|
chs) );
|
|
|
|
|
|
|
|
// Add same choices to another property as well - this is efficient due
|
|
|
|
// to reference counting
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxEnumProperty("Secondary Diet",
|
2008-09-12 16:57:41 -04:00
|
|
|
wxPG_LABEL,
|
|
|
|
chs) );
|
|
|
|
@endcode
|
|
|
|
|
2008-09-19 13:39:09 -04:00
|
|
|
You can later change choices of property by using wxPGProperty::AddChoice(),
|
|
|
|
wxPGProperty::InsertChoice(), wxPGProperty::DeleteChoice(), and
|
|
|
|
wxPGProperty::SetChoices().
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
<b>wxEditEnumProperty</b> works exactly like wxEnumProperty, except
|
|
|
|
is uses non-read-only combo box as default editor, and value is stored as
|
2008-09-12 16:57:41 -04:00
|
|
|
string when it is not any of the choices.
|
|
|
|
|
2008-09-19 12:57:33 -04:00
|
|
|
wxFlagsProperty has similar construction:
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
@code
|
|
|
|
|
|
|
|
const wxChar* flags_prop_labels[] = { wxT("wxICONIZE"),
|
|
|
|
wxT("wxCAPTION"), wxT("wxMINIMIZE_BOX"), wxT("wxMAXIMIZE_BOX"), NULL };
|
|
|
|
|
|
|
|
// this value array would be optional if values matched string indexes
|
|
|
|
long flags_prop_values[] = { wxICONIZE, wxCAPTION, wxMINIMIZE_BOX,
|
|
|
|
wxMAXIMIZE_BOX };
|
|
|
|
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxFlagsProperty("Window Style",
|
2008-09-12 16:57:41 -04:00
|
|
|
wxPG_LABEL,
|
|
|
|
flags_prop_labels,
|
|
|
|
flags_prop_values,
|
|
|
|
wxDEFAULT_FRAME_STYLE) );
|
|
|
|
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
wxFlagsProperty can use wxPGChoices just the same way as wxEnumProperty
|
2008-09-21 10:13:32 -04:00
|
|
|
<b>Note:</b> When changing "choices" (ie. flag labels) of wxFlagsProperty,
|
2008-09-19 12:57:33 -04:00
|
|
|
you will need to use wxPGProperty::SetChoices() to replace all choices
|
2008-09-21 10:13:32 -04:00
|
|
|
at once - otherwise implicit child properties will not get updated properly.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@section propgrid_advprops Specialized Properties
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
This section describes the use of less often needed property classes.
|
|
|
|
To use them, you have to include <wx/propgrid/advprops.h>.
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
|
|
|
// Necessary extra header file
|
|
|
|
#include <wx/propgrid/advprops.h>
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
// Date property.
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxDateProperty("MyDateProperty",
|
2008-09-12 16:57:41 -04:00
|
|
|
wxPG_LABEL,
|
|
|
|
wxDateTime::Now()) );
|
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
// Image file property. Wild card is auto-generated from available
|
2008-09-12 16:57:41 -04:00
|
|
|
// image handlers, so it is not set this time.
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxImageFileProperty("Label of ImageFileProperty",
|
|
|
|
"NameOfImageFileProp") );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
// Font property has sub-properties. Note that we give window's font as
|
|
|
|
// initial value.
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxFontProperty("Font",
|
2008-09-12 16:57:41 -04:00
|
|
|
wxPG_LABEL,
|
|
|
|
GetFont()) );
|
|
|
|
|
|
|
|
// Colour property with arbitrary colour.
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxColourProperty("My Colour 1",
|
2008-09-12 16:57:41 -04:00
|
|
|
wxPG_LABEL,
|
|
|
|
wxColour(242,109,0) ) );
|
|
|
|
|
|
|
|
// System colour property.
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxSystemColourProperty("My SysColour 1",
|
2008-09-12 16:57:41 -04:00
|
|
|
wxPG_LABEL,
|
|
|
|
wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)) );
|
|
|
|
|
|
|
|
// System colour property with custom colour.
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxSystemColourProperty("My SysColour 2",
|
2008-09-12 16:57:41 -04:00
|
|
|
wxPG_LABEL,
|
|
|
|
wxColour(0,200,160) ) );
|
|
|
|
|
|
|
|
// Cursor property
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->Append( new wxCursorProperty("My Cursor",
|
2008-09-12 16:57:41 -04:00
|
|
|
wxPG_LABEL,
|
|
|
|
wxCURSOR_ARROW));
|
|
|
|
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
@section propgrid_processingvalues Processing Property Values
|
|
|
|
|
2010-04-16 10:36:32 -04:00
|
|
|
Properties store their values internally as wxVariant, but is also possible to
|
|
|
|
obtain them as wxAny, using implicit conversion. You can get property
|
|
|
|
values with wxPGProperty::GetValue() and
|
|
|
|
wxPropertyGridInterface::GetPropertyValue().
|
|
|
|
|
|
|
|
Below is a code example which handles wxEVT_PG_CHANGED event:
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
|
|
|
void MyWindowClass::OnPropertyGridChanged(wxPropertyGridEvent& event)
|
|
|
|
{
|
|
|
|
wxPGProperty* property = event.GetProperty();
|
|
|
|
|
|
|
|
// Do nothing if event did not have associated property
|
|
|
|
if ( !property )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// GetValue() returns wxVariant, but it is converted transparently to
|
|
|
|
// wxAny
|
|
|
|
wxAny value = property->GetValue();
|
|
|
|
|
|
|
|
// Also, handle the case where property value is unspecified
|
|
|
|
if ( value.IsNull() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Handle changes in values, as needed
|
2012-10-16 10:01:54 -04:00
|
|
|
if ( property->GetName() == "MyStringProperty" )
|
2010-04-16 10:36:32 -04:00
|
|
|
OnMyStringPropertyChanged(value.As<wxString>());
|
2012-10-16 10:01:54 -04:00
|
|
|
else if ( property->GetName() == "MyColourProperty" )
|
2010-04-16 10:36:32 -04:00
|
|
|
OnMyColourPropertyChanged(value.As<wxColour>());
|
|
|
|
}
|
|
|
|
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
You can get a string-representation of property's value using
|
|
|
|
wxPGProperty::GetValueAsString() or
|
|
|
|
wxPropertyGridInterface::GetPropertyValueAsString(). This particular function
|
|
|
|
is very safe to use with any kind of property.
|
|
|
|
|
|
|
|
@note There is a one case in which you may want to take extra care when
|
|
|
|
dealing with raw wxVariant values. That is, integer-type properties,
|
|
|
|
such as wxIntProperty and wxUIntProperty, store value internally as
|
|
|
|
wx(U)LongLong when number doesn't fit into standard long type. Using
|
|
|
|
<< operator to get wx(U)LongLong from wxVariant is customized to work
|
|
|
|
quite safely with various types of variant data. However, you can also
|
|
|
|
bypass this problem by using wxAny in your code instead of wxVariant.
|
2008-09-21 10:13:32 -04:00
|
|
|
|
|
|
|
Note that in some cases property value can be Null variant, which means
|
|
|
|
that property value is unspecified. This usually occurs only when
|
|
|
|
wxPG_EX_AUTO_UNSPECIFIED_VALUES extra window style is defined or when you
|
|
|
|
manually set property value to Null (or unspecified).
|
|
|
|
|
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@section propgrid_iterating Iterating through a property container
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
You can use somewhat STL'ish iterator classes to iterate through the grid.
|
|
|
|
Here is a simple example of forward iterating through all individual
|
2008-09-21 10:13:32 -04:00
|
|
|
properties (not categories nor private child properties that are normally
|
|
|
|
'transparent' to application code):
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
@code
|
|
|
|
|
|
|
|
wxPropertyGridIterator it;
|
|
|
|
|
|
|
|
for ( it = pg->GetIterator();
|
|
|
|
!it.AtEnd();
|
|
|
|
it++ )
|
|
|
|
{
|
|
|
|
wxPGProperty* p = *it;
|
|
|
|
// Do something with the property
|
|
|
|
}
|
|
|
|
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
As expected there is also a const iterator:
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
|
|
|
wxPropertyGridConstIterator it;
|
|
|
|
|
|
|
|
for ( it = pg->GetIterator();
|
|
|
|
!it.AtEnd();
|
|
|
|
it++ )
|
|
|
|
{
|
|
|
|
const wxPGProperty* p = *it;
|
|
|
|
// Do something with the property
|
|
|
|
}
|
|
|
|
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
You can give some arguments to GetIterator to determine which properties
|
|
|
|
get automatically filtered out. For complete list of options, see
|
2008-09-18 13:14:13 -04:00
|
|
|
@ref propgrid_iterator_flags. GetIterator() also accepts other arguments.
|
|
|
|
See wxPropertyGridInterface::GetIterator() for details.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
This example reverse-iterates through all visible items:
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
|
|
|
wxPropertyGridIterator it;
|
|
|
|
|
|
|
|
for ( it = pg->GetIterator(wxPG_ITERATE_VISIBLE, wxBOTTOM);
|
|
|
|
!it.AtEnd();
|
|
|
|
it-- )
|
|
|
|
{
|
|
|
|
wxPGProperty* p = *it;
|
|
|
|
// Do something with the property
|
|
|
|
}
|
|
|
|
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
GetIterator() only works with wxPropertyGrid and the individual pages
|
|
|
|
of wxPropertyGridManager. In order to iterate through an arbitrary
|
2008-09-21 10:13:32 -04:00
|
|
|
property container (such as entire wxPropertyGridManager), you need to use
|
|
|
|
wxPropertyGridInterface::GetVIterator(). Note however that this virtual
|
|
|
|
iterator is limited to forward iteration.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
@code
|
|
|
|
|
|
|
|
wxPGVIterator it;
|
|
|
|
|
2011-09-18 16:28:37 -04:00
|
|
|
for ( it = manager->GetVIterator(wxPG_ITERATE_ALL);
|
2008-09-12 16:57:41 -04:00
|
|
|
!it.AtEnd();
|
|
|
|
it.Next() )
|
|
|
|
{
|
|
|
|
wxPGProperty* p = it.GetProperty();
|
|
|
|
// Do something with the property
|
|
|
|
}
|
|
|
|
|
|
|
|
@endcode
|
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@section propgrid_populating Populating wxPropertyGrid Automatically
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@subsection propgrid_fromvariants Populating from List of wxVariants
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
Example of populating an empty wxPropertyGrid from a values stored
|
|
|
|
in an arbitrary list of wxVariants.
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
// This is a static method that initializes *all* built-in type handlers
|
2008-09-12 16:57:41 -04:00
|
|
|
// available, including those for wxColour and wxFont. Refers to *all*
|
|
|
|
// included properties, so when compiling with static library, this
|
2008-09-21 10:13:32 -04:00
|
|
|
// method may increase the executable size noticeably.
|
2008-09-12 16:57:41 -04:00
|
|
|
pg->InitAllTypeHandlers();
|
|
|
|
|
|
|
|
// Get contents of the grid as a wxVariant list
|
|
|
|
wxVariant all_values = pg->GetPropertyValues();
|
|
|
|
|
|
|
|
// Populate the list with values. If a property with appropriate
|
|
|
|
// name is not found, it is created according to the type of variant.
|
|
|
|
pg->SetPropertyValues( my_list_variant );
|
|
|
|
|
|
|
|
@endcode
|
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@subsection propgrid_fromfile Loading Population from a Text-based Storage
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
Class wxPropertyGridPopulator may be helpful when writing code that
|
2008-09-21 10:13:32 -04:00
|
|
|
loads properties from a text-source. In fact, the wxPropertyGrid xrc-handler
|
|
|
|
(which may not be currently included in wxWidgets, but probably will be in
|
|
|
|
near future) uses it.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
@subsection editablestate Saving and Restoring User-Editable State
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
You can use wxPropertyGridInterface::SaveEditableState() and
|
|
|
|
wxPropertyGridInterface::RestoreEditableState() to save and restore
|
|
|
|
user-editable state (selected property, expanded/collapsed properties,
|
|
|
|
selected page, scrolled position, and splitter positions).
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@section propgrid_events Event Handling
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
Probably the most important event is the Changed event which occurs when
|
|
|
|
value of any property is changed by the user. Use EVT_PG_CHANGED(id,func)
|
|
|
|
in your event table to use it.
|
|
|
|
|
|
|
|
For complete list of event types, see wxPropertyGrid class reference.
|
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
However, one type of event that might need focused attention is EVT_PG_CHANGING,
|
|
|
|
which occurs just prior property value is being changed by user. You can
|
|
|
|
acquire pending value using wxPropertyGridEvent::GetValue(), and if it is
|
|
|
|
not acceptable, call wxPropertyGridEvent::Veto() to prevent the value change
|
|
|
|
from taking place.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
@code
|
|
|
|
|
|
|
|
void MyForm::OnPropertyGridChanging( wxPropertyGridEvent& event )
|
|
|
|
{
|
|
|
|
wxPGProperty* property = event.GetProperty();
|
|
|
|
|
|
|
|
if ( property == m_pWatchThisProperty )
|
|
|
|
{
|
|
|
|
// GetValue() returns the pending value, but is only
|
|
|
|
// supported by wxEVT_PG_CHANGING.
|
|
|
|
if ( event.GetValue().GetString() == g_pThisTextIsNotAllowed )
|
|
|
|
{
|
|
|
|
event.Veto();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@endcode
|
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
@remarks On Child Property Event Handling
|
|
|
|
- For properties which have private, implicit children (wxFontProperty and
|
|
|
|
wxFlagsProperty), events occur for the main parent property only.
|
|
|
|
For other properties events occur for the children themselves. See
|
|
|
|
@ref propgrid_parentprops.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
- When property's child gets changed, you can use wxPropertyGridEvent::GetMainParent()
|
2008-09-12 16:57:41 -04:00
|
|
|
to obtain its topmost non-category parent (useful, if you have deeply nested
|
|
|
|
properties).
|
|
|
|
|
2009-12-26 05:45:04 -05:00
|
|
|
@section propgrid_tooltipandhint Help String, Hint and Tool Tips
|
|
|
|
|
|
|
|
For each property you can specify two different types of help text. First,
|
|
|
|
you can use wxPropertyGridInterface::SetPropertyHelpString() or
|
|
|
|
wxPGProperty::SetHelpString() to set property's help text. Second, you
|
|
|
|
can use wxPGProperty::SetAttribute() to set property's "Hint" attribute.
|
|
|
|
|
|
|
|
Difference between hint and help string is that the hint is shown in an empty
|
|
|
|
property value cell, while help string is shown either in the description text
|
|
|
|
box, as a tool tip, or on the status bar, whichever of these is available.
|
|
|
|
|
|
|
|
To enable display of help string as tool tips, you must explicitly use
|
|
|
|
the wxPG_EX_HELP_AS_TOOLTIPS extra window style.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@section propgrid_validating Validating Property Values
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
There are various ways to make sure user enters only correct values. First, you
|
|
|
|
can use wxValidators similar to as you would with ordinary controls. Use
|
2009-06-07 05:02:35 -04:00
|
|
|
wxPropertyGridInterface::SetPropertyValidator() to assign wxValidator to
|
2008-09-12 16:57:41 -04:00
|
|
|
property.
|
|
|
|
|
|
|
|
Second, you can subclass a property and override wxPGProperty::ValidateValue(),
|
2008-09-21 10:13:32 -04:00
|
|
|
or handle wxEVT_PG_CHANGING for the same effect. Both of these ways do not
|
2008-09-12 16:57:41 -04:00
|
|
|
actually prevent user from temporarily entering invalid text, but they do give
|
|
|
|
you an opportunity to warn the user and block changed value from being committed
|
|
|
|
in a property.
|
|
|
|
|
|
|
|
Various validation failure options can be controlled globally with
|
|
|
|
wxPropertyGrid::SetValidationFailureBehavior(), or on an event basis by
|
|
|
|
calling wxEvent::SetValidationFailureBehavior(). Here's a code snippet of
|
|
|
|
how to handle wxEVT_PG_CHANGING, and to set custom failure behaviour and
|
|
|
|
message.
|
|
|
|
|
|
|
|
@code
|
|
|
|
void MyFrame::OnPropertyGridChanging(wxPropertyGridEvent& event)
|
|
|
|
{
|
|
|
|
wxPGProperty* property = event.GetProperty();
|
|
|
|
|
|
|
|
// You must use wxPropertyGridEvent::GetValue() to access
|
|
|
|
// the value to be validated.
|
|
|
|
wxVariant pendingValue = event.GetValue();
|
|
|
|
|
2009-12-26 05:51:39 -05:00
|
|
|
if ( property->GetName() == "Font" )
|
2008-09-12 16:57:41 -04:00
|
|
|
{
|
|
|
|
// Make sure value is not unspecified
|
|
|
|
if ( !pendingValue.IsNull() )
|
|
|
|
{
|
2008-09-21 10:13:32 -04:00
|
|
|
wxFont font;
|
|
|
|
font << pendingValue;
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
// Let's just allow Arial font
|
2009-12-26 05:51:39 -05:00
|
|
|
if ( font.GetFaceName() != "Arial" )
|
2008-09-12 16:57:41 -04:00
|
|
|
{
|
|
|
|
event.Veto();
|
|
|
|
event.SetValidationFailureBehavior(wxPG_VFB_STAY_IN_PROPERTY |
|
|
|
|
wxPG_VFB_BEEP |
|
2010-07-04 04:53:07 -04:00
|
|
|
wxPG_VFB_SHOW_MESSAGEBOX);
|
2008-09-12 16:57:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@section propgrid_cellrender Customizing Individual Cell Appearance
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
You can control text colour, background colour, and attached image of
|
|
|
|
each cell in the property grid. Use wxPropertyGridInterface::SetPropertyCell() or
|
|
|
|
wxPGProperty::SetCell() for this purpose.
|
|
|
|
|
|
|
|
In addition, it is possible to control these characteristics for
|
2008-09-21 10:13:32 -04:00
|
|
|
wxPGChoices list items. See wxPGChoices class reference for more info.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2010-12-22 13:44:42 -05:00
|
|
|
@section propgrid_keyhandling Customizing Keyboard Handling
|
|
|
|
|
|
|
|
There is probably one preference for keyboard handling for every developer
|
|
|
|
out there, and as a conveniency control wxPropertyGrid tries to cater for
|
|
|
|
that. By the default arrow keys are used for navigating between properties,
|
|
|
|
and TAB key is used to move focus between the property editor and the
|
|
|
|
first column. When the focus is in the editor, arrow keys usually no longer
|
|
|
|
work for navigation since they are consumed by the editor.
|
|
|
|
|
|
|
|
There are mainly two functions which you can use this customize things,
|
|
|
|
wxPropertyGrid::AddActionTrigger() and wxPropertyGrid::DedicateKey().
|
|
|
|
First one can be used to set a navigation event to occur on a specific key
|
|
|
|
press and the second is used to divert a key from property editors, making it
|
|
|
|
possible for the grid to use keys normally consumed by the focused editors.
|
|
|
|
|
|
|
|
For example, let's say you want to have an ENTER-based editing scheme. That
|
|
|
|
is, editor is focused on ENTER press and the next property is selected when
|
|
|
|
the user finishes editing and presses ENTER again. Code like this would
|
|
|
|
accomplish the task:
|
|
|
|
|
|
|
|
@code
|
|
|
|
// Have property editor focus on Enter
|
|
|
|
propgrid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_RETURN );
|
|
|
|
|
|
|
|
// Have Enter work as action trigger even when editor is focused
|
|
|
|
propgrid->DedicateKey( WXK_RETURN );
|
|
|
|
|
|
|
|
// Let Enter also navigate to the next property
|
|
|
|
propgrid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN );
|
|
|
|
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
wxPG_ACTION_EDIT is prioritized above wxPG_ACTION_NEXT_PROPERTY so that the
|
|
|
|
above code can work without conflicts. For a complete list of available
|
|
|
|
actions, see @ref propgrid_keyboard_actions.
|
|
|
|
|
|
|
|
Here's another trick. Normally the up and down cursor keys are consumed by
|
|
|
|
the focused wxTextCtrl editor and as such can't be used for navigating between
|
|
|
|
properties when that editor is focused. However, using DedicateKey() we can
|
|
|
|
change this so that instead of the cursor keys moving the caret inside the
|
|
|
|
wxTextCtrl, they navigate between adjacent properties. As such:
|
|
|
|
|
|
|
|
@code
|
|
|
|
propgrid->DedicateKey(WXK_UP);
|
|
|
|
propgrid->DedicateKey(WXK_DOWN);
|
|
|
|
@endcode
|
|
|
|
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@section propgrid_customizing Customizing Properties (without sub-classing)
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
In this section are presented miscellaneous ways to have custom appearance
|
2011-03-22 10:17:38 -04:00
|
|
|
and behaviour for your properties without all the necessary hassle
|
2008-09-12 16:57:41 -04:00
|
|
|
of sub-classing a property class etc.
|
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@subsection propgrid_customimage Setting Value Image
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
Every property can have a small value image placed in front of the
|
|
|
|
actual value text. Built-in example of this can be seen with
|
|
|
|
wxColourProperty and wxImageFileProperty, but for others it can
|
|
|
|
be set using wxPropertyGrid::SetPropertyImage method.
|
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@subsection propgrid_customeditor Setting Property's Editor Control(s)
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
You can set editor control (or controls, in case of a control and button),
|
|
|
|
of any property using wxPropertyGrid::SetPropertyEditor. Editors are passed
|
2008-09-21 10:13:32 -04:00
|
|
|
as wxPGEditor_EditorName, and valid built-in EditorNames are
|
2008-09-12 16:57:41 -04:00
|
|
|
TextCtrl, Choice, ComboBox, CheckBox, TextCtrlAndButton, ChoiceAndButton,
|
|
|
|
SpinCtrl, and DatePickerCtrl. Two last mentioned ones require call to
|
|
|
|
static member function wxPropertyGrid::RegisterAdditionalEditors().
|
|
|
|
|
|
|
|
Following example changes wxColourProperty's editor from default Choice
|
|
|
|
to TextCtrlAndButton. wxColourProperty has its internal event handling set
|
|
|
|
up so that button click events of the button will be used to trigger
|
|
|
|
colour selection dialog.
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
2009-12-26 05:51:39 -05:00
|
|
|
wxPGProperty* colProp = new wxColourProperty("Text Colour");
|
2008-09-21 10:13:32 -04:00
|
|
|
pg->Append(colProp);
|
|
|
|
pg->SetPropertyEditor(colProp, wxPGEditor_TextCtrlAndButton);
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
Naturally, creating and setting custom editor classes is a possibility as
|
|
|
|
well. For more information, see wxPGEditor class reference.
|
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@subsection propgrid_editorattrs Property Attributes Recognized by Editors
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
<b>SpinCtrl</b> editor can make use of property's "Min", "Max", "Step" and
|
|
|
|
"Wrap" attributes.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@subsection propgrid_multiplebuttons Adding Multiple Buttons Next to an Editor
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
See wxPGMultiButton class reference.
|
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@subsection propgrid_customeventhandling Handling Events Passed from Properties
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
<b>wxEVT_COMMAND_BUTTON_CLICKED </b>(corresponds to event table macro EVT_BUTTON):
|
|
|
|
Occurs when editor button click is not handled by the property itself
|
|
|
|
(as is the case, for example, if you set property's editor to TextCtrlAndButton
|
|
|
|
from the original TextCtrl).
|
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@subsection propgrid_attributes Property Attributes
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
Miscellaneous values, often specific to a property type, can be set
|
2008-09-21 10:13:32 -04:00
|
|
|
using wxPropertyGridInterface::SetPropertyAttribute() and
|
|
|
|
wxPropertyGridInterface::SetPropertyAttributeAll() methods.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
Attribute names are strings and values wxVariant. Arbitrary names are allowed
|
2008-09-21 10:13:32 -04:00
|
|
|
in order to store values that are relevant to application only and not
|
|
|
|
property grid. Constant equivalents of all attribute string names are
|
|
|
|
provided. Some of them are defined as cached strings, so using these constants
|
|
|
|
can provide for smaller binary size.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-18 13:14:13 -04:00
|
|
|
For complete list of attributes, see @ref propgrid_property_attributes.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@section propgrid_usage2 Using wxPropertyGridManager
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
wxPropertyGridManager is an efficient multi-page version of wxPropertyGrid,
|
2008-09-21 10:13:32 -04:00
|
|
|
which can optionally have tool bar for mode and page selection, and a help text
|
|
|
|
box. For more information, see wxPropertyGridManager class reference.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@subsection propgrid_propgridpage wxPropertyGridPage
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
wxPropertyGridPage is holder of properties for one page in manager. It is derived from
|
|
|
|
wxEvtHandler, so you can subclass it to process page-specific property grid events. Hand
|
2008-09-21 10:13:32 -04:00
|
|
|
over your page instance in wxPropertyGridManager::AddPage().
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
Please note that the wxPropertyGridPage itself only sports subset of wxPropertyGrid API
|
|
|
|
(but unlike manager, this include item iteration). Naturally it inherits from
|
2008-09-21 10:13:32 -04:00
|
|
|
wxPropertyGridInterface.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
For more information, see wxPropertyGridPage class reference.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
|
|
|
|
@section propgrid_subclassing Sub-classing wxPropertyGrid and wxPropertyGridManager
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
Few things to note:
|
|
|
|
|
|
|
|
- Only a small percentage of member functions are virtual. If you need more,
|
|
|
|
just e-mail to wx-dev mailing list.
|
|
|
|
|
|
|
|
- Data manipulation is done in wxPropertyGridPageState class. So, instead of
|
2008-09-21 10:13:32 -04:00
|
|
|
overriding wxPropertyGrid::Insert(), you'll probably want to override
|
|
|
|
wxPropertyGridPageState::DoInsert(). See header file for details.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
- Override wxPropertyGrid::CreateState() to instantiate your derivate
|
|
|
|
wxPropertyGridPageState. For wxPropertyGridManager, you'll need to subclass
|
|
|
|
wxPropertyGridPage instead (since it is derived from wxPropertyGridPageState),
|
|
|
|
and hand over instances in wxPropertyGridManager::AddPage() calls.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
- You can use a derivate wxPropertyGrid with manager by overriding
|
|
|
|
wxPropertyGridManager::CreatePropertyGrid() member function.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@section propgrid_misc Miscellaneous Topics
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@subsection propgrid_namescope Property Name Scope
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-14 09:53:21 -04:00
|
|
|
All properties which parent is category or root can be accessed
|
|
|
|
directly by their base name (ie. name given for property in its constructor).
|
|
|
|
Other properties can be accessed via "ParentsName.BaseName" notation,
|
|
|
|
Naturally, all property names should be unique.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@subsection propgrid_nonuniquelabels Non-unique Labels
|
2008-09-14 09:53:21 -04:00
|
|
|
|
|
|
|
It is possible to have properties with identical label under same parent.
|
|
|
|
However, care must be taken to ensure that each property still has
|
|
|
|
unique (base) name.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@subsection propgrid_boolproperty wxBoolProperty
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
There are few points about wxBoolProperty that require further discussion:
|
|
|
|
- wxBoolProperty can be shown as either normal combo box or as a check box.
|
2008-09-12 16:57:41 -04:00
|
|
|
Property attribute wxPG_BOOL_USE_CHECKBOX is used to change this.
|
|
|
|
For example, if you have a wxFlagsProperty, you can
|
|
|
|
set its all items to use check box using the following:
|
|
|
|
@code
|
2009-12-26 05:51:39 -05:00
|
|
|
pg->SetPropertyAttribute("MyFlagsProperty", wxPG_BOOL_USE_CHECKBOX, true, wxPG_RECURSE);
|
2008-09-12 16:57:41 -04:00
|
|
|
@endcode
|
2009-06-07 05:02:35 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
Following will set all individual bool properties in your control to
|
|
|
|
use check box:
|
2009-06-07 05:02:35 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
@code
|
|
|
|
pg->SetPropertyAttributeAll(wxPG_BOOL_USE_CHECKBOX, true);
|
|
|
|
@endcode
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-19 12:57:33 -04:00
|
|
|
- Default item names for wxBoolProperty are ["False", "True"]. This can be
|
2008-09-21 10:13:32 -04:00
|
|
|
changed using static function wxPropertyGrid::SetBoolChoices(trueChoice,
|
|
|
|
falseChoice).
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@subsection propgrid_textctrlupdates Updates from wxTextCtrl Based Editor
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
Changes from wxTextCtrl based property editors are committed (ie.
|
|
|
|
wxEVT_PG_CHANGED is sent etc.) *only* when (1) user presser enter, (2)
|
|
|
|
user moves to edit another property, or (3) when focus leaves
|
|
|
|
the grid.
|
|
|
|
|
|
|
|
Because of this, you may find it useful, in some apps, to call
|
|
|
|
wxPropertyGrid::CommitChangesFromEditor() just before you need to do any
|
|
|
|
computations based on property grid values. Note that CommitChangesFromEditor()
|
|
|
|
will dispatch wxEVT_PG_CHANGED with ProcessEvent, so any of your event handlers
|
|
|
|
will be called immediately.
|
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@subsection propgrid_splittercentering Centering the Splitter
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
If you need to center the splitter, but only once when the program starts,
|
|
|
|
then do <b>not</b> use the wxPG_SPLITTER_AUTO_CENTER window style, but the
|
|
|
|
wxPropertyGrid::CenterSplitter() method. <b>However, be sure to call it after
|
|
|
|
the sizer setup and SetSize calls!</b> (ie. usually at the end of the
|
|
|
|
frame/dialog constructor)
|
|
|
|
|
2011-03-22 10:17:38 -04:00
|
|
|
Splitter centering behaviour can be customized using
|
2010-02-14 09:09:06 -05:00
|
|
|
wxPropertyGridInterface::SetColumnProportion(). Usually it is used to set
|
|
|
|
non-equal column proportions, which in essence stops the splitter(s) from
|
|
|
|
being 'centered' as such, and instead just auto-resized.
|
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@subsection propgrid_splittersetting Setting Splitter Position When Creating Property Grid
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
Splitter position cannot exceed grid size, and therefore setting it during
|
|
|
|
form creation may fail as initial grid size is often smaller than desired
|
|
|
|
splitter position, especially when sizers are being used.
|
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@subsection propgrid_colourproperty wxColourProperty and wxSystemColourProperty
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-21 10:13:32 -04:00
|
|
|
Through sub-classing, these two property classes provide substantial customization
|
2008-09-12 16:57:41 -04:00
|
|
|
features. Subclass wxSystemColourProperty if you want to use wxColourPropertyValue
|
|
|
|
(which features colour type in addition to wxColour), and wxColourProperty if plain
|
|
|
|
wxColour is enough.
|
|
|
|
|
|
|
|
Override wxSystemColourProperty::ColourToString() to redefine how colours are
|
|
|
|
printed as strings.
|
|
|
|
|
|
|
|
Override wxSystemColourProperty::GetCustomColourIndex() to redefine location of
|
|
|
|
the item that triggers colour picker dialog (default is last).
|
|
|
|
|
|
|
|
Override wxSystemColourProperty::GetColour() to determine which colour matches
|
|
|
|
which choice entry.
|
|
|
|
|
2008-09-18 12:53:47 -04:00
|
|
|
@section propgrid_proplist Property Class Descriptions
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
See @ref pgproperty_properties
|
|
|
|
|
2009-06-07 05:02:35 -04:00
|
|
|
@section propgrid_compat Changes from wxPropertyGrid 1.4
|
|
|
|
|
|
|
|
Version of wxPropertyGrid bundled with wxWidgets 2.9+ has various backward-
|
|
|
|
incompatible changes from version 1.4, which had a stable API and will remain
|
|
|
|
as the last separate branch.
|
|
|
|
|
2011-03-22 10:17:38 -04:00
|
|
|
Note that in general any behaviour-breaking changes should not compile or run
|
2009-06-07 05:02:35 -04:00
|
|
|
without warnings or errors.
|
|
|
|
|
|
|
|
@subsection propgrid_compat_general General Changes
|
|
|
|
|
|
|
|
- Tab-traversal can no longer be used to travel between properties. Now
|
|
|
|
it only causes focus to move from main grid to editor of selected property.
|
|
|
|
Arrow keys are now your primary means of navigating between properties,
|
|
|
|
with keyboard. This change allowed fixing broken tab traversal on wxGTK
|
|
|
|
(which is open issue in wxPropertyGrid 1.4).
|
|
|
|
|
2011-03-22 10:17:38 -04:00
|
|
|
- wxPG_EX_UNFOCUS_ON_ENTER style is removed and is now default behaviour.
|
2010-07-04 06:39:10 -04:00
|
|
|
That is, when enter is pressed, editing is considered done and focus
|
|
|
|
moves back to the property grid from the editor control.
|
|
|
|
|
2009-06-07 05:02:35 -04:00
|
|
|
- A few member functions were removed from wxPropertyGridInterface.
|
|
|
|
Please use wxPGProperty's counterparts from now on.
|
|
|
|
|
2011-03-22 10:17:38 -04:00
|
|
|
- wxPGChoices now has proper Copy-On-Write behaviour.
|
2009-06-07 05:02:35 -04:00
|
|
|
|
|
|
|
- wxPGChoices::SetExclusive() was renamed to AllocExclusive().
|
|
|
|
|
|
|
|
- wxPGProperty::SetPropertyChoicesExclusive() was removed. Instead, use
|
|
|
|
GetChoices().AllocExclusive().
|
|
|
|
|
|
|
|
- wxPGProperty::ClearModifiedStatus() is removed. Please use
|
|
|
|
SetModifiedStatus() instead.
|
|
|
|
|
|
|
|
- wxPropertyGridInterface::GetExpandedProperties() is removed. You should
|
|
|
|
now use wxPropertyGridInterface::GetEditableState() instead.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2009-08-29 04:09:45 -04:00
|
|
|
- wxPG_EX_DISABLE_TLP_TRACKING is now enabled by default. To get the old
|
2011-03-22 10:17:38 -04:00
|
|
|
behaviour (recommended if you don't use a system that reparents the grid
|
2009-08-29 04:09:45 -04:00
|
|
|
on its own), use the wxPG_EX_ENABLE_TLP_TRACKING extra style.
|
|
|
|
|
2009-06-07 05:02:35 -04:00
|
|
|
- Extended window style wxPG_EX_LEGACY_VALIDATORS was removed.
|
|
|
|
|
2011-03-22 10:17:38 -04:00
|
|
|
- Default property validation failure behaviour has been changed to
|
2010-07-04 04:53:07 -04:00
|
|
|
(wxPG_VFB_MARK_CELL | wxPG_VFB_SHOW_MESSAGEBOX), which means that the
|
|
|
|
cell is marked red and wxMessageBox is shown. This is more user-friendly
|
2011-03-22 10:17:38 -04:00
|
|
|
than the old behaviour, which simply beeped and prevented leaving the
|
2010-07-04 04:53:07 -04:00
|
|
|
property editor until a valid value was entered.
|
|
|
|
|
2009-06-07 05:02:35 -04:00
|
|
|
- wxPropertyGridManager now has same Get/SetSelection() semantics as
|
|
|
|
wxPropertyGrid.
|
|
|
|
|
|
|
|
- Various wxPropertyGridManager page-related functions now return pointer
|
|
|
|
to the page object instead of index.
|
|
|
|
|
2010-07-10 11:30:35 -04:00
|
|
|
- wxArrayEditorDialog used by wxArrayStringProperty and some sample
|
|
|
|
properties has been renamed to wxPGArrayEditorDialog. Also, it now uses
|
|
|
|
wxEditableListBox for editing.
|
|
|
|
|
2009-06-07 05:02:35 -04:00
|
|
|
- Instead of calling wxPropertyGrid::SetButtonShortcut(), use
|
|
|
|
wxPropertyGrid::SetActionTrigger(wxPG_ACTION_PRESS_BUTTON).
|
|
|
|
|
|
|
|
- wxPGProperty::GetCell() now returns a reference. AcquireCell() was removed.
|
|
|
|
|
|
|
|
- wxPGMultiButton::FinalizePosition() has been renamed to Finalize(),
|
|
|
|
and it has slightly different argument list.
|
|
|
|
|
|
|
|
- wxPropertyGridEvent::HasProperty() is removed. You can use GetProperty()
|
|
|
|
as immediate replacement when checking if event has a property.
|
|
|
|
|
2009-12-26 05:45:04 -05:00
|
|
|
- "InlineHelp" property has been replaced with "Hint".
|
|
|
|
|
2010-02-14 09:37:56 -05:00
|
|
|
- wxPropertyGrid::CanClose() has been removed. Call
|
|
|
|
wxPropertyGridInterface::EditorValidate() instead.
|
|
|
|
|
2010-08-08 08:22:08 -04:00
|
|
|
- wxPGProperty::SetFlag() has been moved to private API. This was done to
|
|
|
|
underline the fact that it was not the preferred method to change a
|
|
|
|
property's state since it never had any desired side-effects. ChangeFlag()
|
|
|
|
still exists for those who really need to achieve the same effect.
|
|
|
|
|
2010-08-26 09:51:45 -04:00
|
|
|
- wxArrayStringProperty default delimiter is now comma (','), and it can
|
|
|
|
be changed by setting the new "Delimiter" attribute.
|
|
|
|
|
2009-06-07 05:02:35 -04:00
|
|
|
@subsection propgrid_compat_propdev Property and Editor Sub-classing Changes
|
|
|
|
|
|
|
|
- Confusing custom property macros have been eliminated.
|
|
|
|
|
|
|
|
- Implement wxPGProperty::ValueToString() instead of GetValueAsString().
|
|
|
|
|
|
|
|
- wxPGProperty::ChildChanged() must now return the modified value of
|
|
|
|
whole property instead of writing it back into 'thisValue' argument.
|
|
|
|
|
|
|
|
- Removed wxPropertyGrid::PrepareValueForDialogEditing(). Use
|
|
|
|
wxPropertyGrid::GetPendingEditedValue() instead.
|
|
|
|
|
|
|
|
- wxPGProperty::GetChoiceInfo() is removed, as all properties now carry
|
|
|
|
wxPGChoices instance (protected wxPGProperty::m_choices).
|
|
|
|
|
|
|
|
- Connect() should no longer be called in implementations of
|
|
|
|
wxPGEditor::CreateControls(). wxPropertyGrid automatically passes all
|
|
|
|
events from editor to wxPGEditor::OnEvent() and wxPGProperty::OnEvent(),
|
|
|
|
as appropriate.
|
2009-06-10 16:51:25 -04:00
|
|
|
|
|
|
|
- wxPython: Previously some of the reimplemented member functions needed a
|
|
|
|
'Py' prefix. This is no longer necessary. For instance, if you previously
|
|
|
|
implemented PyStringToValue() for your custom property, you should now
|
|
|
|
just implement StringToValue().
|
2009-06-07 05:02:35 -04:00
|
|
|
*/
|