1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxPGProperty
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 #define wxNullProperty ((wxPGProperty*)NULL)
13 /** @section propgrid_property_attributes wxPropertyGrid Property Attribute Identifiers
15 wxPGProperty::SetAttribute() and
16 wxPropertyGridInterface::SetPropertyAttribute()
17 accept one of these as attribute name argument .
19 You can use strings instead of constants. However, some of these
20 constants are redefined to use cached strings which may reduce
21 your binary size by some amount.
26 /** Set default value for property.
28 #define wxPG_ATTR_DEFAULT_VALUE wxS("DefaultValue")
30 /** Universal, int or double. Minimum value for numeric properties.
32 #define wxPG_ATTR_MIN wxS("Min")
34 /** Universal, int or double. Maximum value for numeric properties.
36 #define wxPG_ATTR_MAX wxS("Max")
38 /** Universal, string. When set, will be shown as text after the displayed
39 text value. Alternatively, if third column is enabled, text will be shown
40 there (for any type of property).
42 #define wxPG_ATTR_UNITS wxS("Units")
44 /** Universal, string. When set, will be shown in property's value cell
45 when displayed value string is empty, or value is unspecified.
47 #define wxPG_ATTR_INLINE_HELP wxS("InlineHelp")
49 /** wxBoolProperty specific, int, default 0. When 1 sets bool property to
50 use checkbox instead of choice.
52 #define wxPG_BOOL_USE_CHECKBOX wxS("UseCheckbox")
54 /** wxBoolProperty specific, int, default 0. When 1 sets bool property value
55 to cycle on double click (instead of showing the popup listbox).
57 #define wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING wxS("UseDClickCycling")
59 /** wxFloatProperty (and similar) specific, int, default -1. Sets the (max) precision
60 used when floating point value is rendered as text. The default -1 means infinite
63 #define wxPG_FLOAT_PRECISION wxS("Precision")
65 /** The text will be echoed as asterisks (wxTE_PASSWORD will be passed to textctrl etc).
67 #define wxPG_STRING_PASSWORD wxS("Password")
69 /** Define base used by a wxUIntProperty. Valid constants are
70 wxPG_BASE_OCT, wxPG_BASE_DEC, wxPG_BASE_HEX and wxPG_BASE_HEXL
71 (lowercase characters).
73 #define wxPG_UINT_BASE wxS("Base")
75 /** Define prefix rendered to wxUIntProperty. Accepted constants
76 wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and wxPG_PREFIX_DOLLAR_SIGN.
77 <b>Note:</b> Only wxPG_PREFIX_NONE works with Decimal and Octal
80 #define wxPG_UINT_PREFIX wxS("Prefix")
82 /** wxFileProperty/wxImageFileProperty specific, wxChar*, default is detected/varies.
83 Sets the wildcard used in the triggered wxFileDialog. Format is the
86 #define wxPG_FILE_WILDCARD wxS("Wildcard")
88 /** wxFileProperty/wxImageFileProperty specific, int, default 1.
89 When 0, only the file name is shown (i.e. drive and directory are hidden).
91 #define wxPG_FILE_SHOW_FULL_PATH wxS("ShowFullPath")
93 /** Specific to wxFileProperty and derived properties, wxString, default empty.
94 If set, then the filename is shown relative to the given path string.
96 #define wxPG_FILE_SHOW_RELATIVE_PATH wxS("ShowRelativePath")
98 /** Specific to wxFileProperty and derived properties, wxString, default is empty.
99 Sets the initial path of where to look for files.
101 #define wxPG_FILE_INITIAL_PATH wxS("InitialPath")
103 /** Specific to wxFileProperty and derivatives, wxString, default is empty.
104 Sets a specific title for the dir dialog.
106 #define wxPG_FILE_DIALOG_TITLE wxS("DialogTitle")
108 /** Specific to wxDirProperty, wxString, default is empty.
109 Sets a specific message for the dir dialog.
111 #define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage")
113 /** Sets displayed date format for wxDateProperty.
115 #define wxPG_DATE_FORMAT wxS("DateFormat")
117 /** Sets wxDatePickerCtrl window style used with wxDateProperty. Default
118 is wxDP_DEFAULT | wxDP_SHOWCENTURY.
120 #define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
122 /** SpinCtrl editor, int or double. How much number changes when button is
123 pressed (or up/down on keybard).
125 #define wxPG_ATTR_SPINCTRL_STEP wxS("Step")
127 /** SpinCtrl editor, bool. If true, value wraps at Min/Max.
129 #define wxPG_ATTR_SPINCTRL_WRAP wxS("Wrap")
131 /** wxMultiChoiceProperty, int. If 0, no user strings allowed. If 1, user strings
132 appear before list strings. If 2, user strings appear after list string.
134 #define wxPG_ATTR_MULTICHOICE_USERSTRINGMODE wxS("UserStringMode")
136 /** wxColourProperty and its kind, int, default 1. Setting this attribute to 0 hides custom
137 colour from property's list of choices.
139 #define wxPG_COLOUR_ALLOW_CUSTOM wxS("AllowCustom")
144 // -----------------------------------------------------------------------
146 /** @class wxPGProperty
148 wxPGProperty is base class for all wxPropertyGrid properties. In
149 sections below we cover few related topics.
151 @li @ref pgproperty_properties
152 @li @ref pgproperty_creating
154 @section pgproperty_properties Supplied Ready-to-use Property Classes
156 Here is a list and short description of supplied fully-functional
157 property classes. They are located in either props.h or advprops.h.
159 @li @ref wxArrayStringProperty
160 @li @ref wxBoolProperty
161 @li @ref wxColourProperty
162 @li @ref wxCursorProperty
163 @li @ref wxDateProperty
164 @li @ref wxDirProperty
165 @li @ref wxEditEnumProperty
166 @li @ref wxEnumProperty
167 @li @ref wxFileProperty
168 @li @ref wxFlagsProperty
169 @li @ref wxFloatProperty
170 @li @ref wxFontProperty
171 @li @ref wxImageFileProperty
172 @li @ref wxIntProperty
173 @li @ref wxLongStringProperty
174 @li @ref wxMultiChoiceProperty
175 @li @ref wxPropertyCategory
176 @li @ref wxStringProperty
177 @li @ref wxSystemColourProperty
178 @li @ref wxUIntProperty
180 @subsection wxPropertyCategory
182 Not an actual property per se, but a header for a group of properties.
183 Regardless inherits from wxPGProperty.
185 @subsection wxStringProperty
187 Simple string property. wxPG_STRING_PASSWORD attribute may be used
188 to echo value as asterisks and use wxTE_PASSWORD for wxTextCtrl.
190 @remarks wxStringProperty has a special trait: if it has value of
191 "<composed>", and also has child properties, then its displayed
192 value becomes composition of child property values, similar as
193 with wxFontProperty, for instance.
195 @subsection wxIntProperty
197 Like wxStringProperty, but converts text to a signed long integer.
198 wxIntProperty seamlessly supports 64-bit integers (ie. wxLongLong).
199 To safely convert variant to integer, use code like this:
203 ll << property->GetValue();
206 wxLongLong ll = propertyGrid->GetPropertyValueAsLong(property);
209 @subsection wxUIntProperty
211 Like wxIntProperty, but displays value as unsigned int. To set
212 the prefix used globally, manipulate wxPG_UINT_PREFIX string attribute.
213 To set the globally used base, manipulate wxPG_UINT_BASE int
214 attribute. Regardless of current prefix, understands (hex) values starting
215 with both "0x" and "$".
216 Like wxIntProperty, wxUIntProperty seamlessly supports 64-bit unsigned
217 integers (ie. wxULongLong). Same wxVariant safety rules apply.
219 @subsection wxFloatProperty
221 Like wxStringProperty, but converts text to a double-precision floating point.
222 Default float-to-text precision is 6 decimals, but this can be changed
223 by modifying wxPG_FLOAT_PRECISION attribute.
225 @subsection wxBoolProperty
227 Represents a boolean value. wxChoice is used as editor control, by the
228 default. wxPG_BOOL_USE_CHECKBOX attribute can be set to true inorder to use
231 @subsection wxLongStringProperty
233 Like wxStringProperty, but has a button that triggers a small text editor
234 dialog. Note that in long string values, tabs are represented by "\t" and
237 To display custom dialog on button press, you can subclass
238 wxLongStringProperty and implement OnButtonClick, like this:
241 virtual bool OnButtonClick( wxPropertyGrid* propGrid, wxString& value )
243 wxSize dialogSize(...size of your dialog...);
245 wxPoint dlgPos = propGrid->GetGoodEditorDialogPosition(this,
248 // Create dialog dlg at dlgPos. Use value as initial string
252 if ( dlg.ShowModal() == wxID_OK )
254 value = dlg.GetStringValue);
261 Also, if you wish not to have line breaks and tabs translated to
262 escape sequences, then do following in constructor of your subclass:
265 m_flags |= wxPG_PROP_NO_ESCAPE;
268 @subsection wxDirProperty
270 Like wxLongStringProperty, but the button triggers dir selector instead.
271 Supported properties (all with string value): wxPG_DIR_DIALOG_MESSAGE.
273 @subsection wxFileProperty
275 Like wxLongStringProperty, but the button triggers file selector instead.
276 Default wildcard is "All files..." but this can be changed by setting
277 wxPG_FILE_WILDCARD attribute (see wxFileDialog for format details).
278 Attribute wxPG_FILE_SHOW_FULL_PATH can be set to false inorder to show
279 only the filename, not the entire path.
281 @subsection wxEnumProperty
283 Represents a single selection from a list of choices -
284 wxOwnerDrawnComboBox is used to edit the value.
286 @subsection wxFlagsProperty
288 Represents a bit set that fits in a long integer. wxBoolProperty sub-properties
289 are created for editing individual bits. Textctrl is created to manually edit
290 the flags as a text; a continous sequence of spaces, commas and semicolons
291 is considered as a flag id separator.
292 <b>Note: </b> When changing "choices" (ie. flag labels) of wxFlagsProperty, you
293 will need to use wxPGProperty::SetChoices() - otherwise they will not get updated
296 @subsection wxArrayStringProperty
298 Allows editing of a list of strings in wxTextCtrl and in a separate dialog.
300 @subsection wxDateProperty
302 wxDateTime property. Default editor is DatePickerCtrl, altough TextCtrl
303 should work as well. wxPG_DATE_FORMAT attribute can be used to change
304 string wxDateTime::Format uses (altough default is recommended as it is
305 locale-dependant), and wxPG_DATE_PICKER_STYLE allows changing window
306 style given to DatePickerCtrl (default is wxDP_DEFAULT|wxDP_SHOWCENTURY).
308 @subsection wxEditEnumProperty
310 Represents a string that can be freely edited or selected from list of choices -
311 custom combobox control is used to edit the value.
313 @subsection wxMultiChoiceProperty
315 Allows editing a multiple selection from a list of strings. This is
316 property is pretty much built around concept of wxMultiChoiceDialog.
317 It uses wxArrayString value.
319 @subsection wxImageFileProperty
321 Like wxFileProperty, but has thumbnail of the image in front of
322 the filename and autogenerates wildcard from available image handlers.
324 @subsection wxColourProperty
326 <b>Useful alternate editor:</b> Choice.
328 Represents wxColour. wxButton is used to trigger a colour picker dialog.
329 There are various sub-classing opportunities with this class. See
330 below in wxSystemColourProperty section for details.
332 @subsection wxFontProperty
334 Represents wxFont. Various sub-properties are used to edit individual
337 @subsection wxSystemColourProperty
339 Represents wxColour and a system colour index. wxChoice is used to edit
340 the value. Drop-down list has color images. Note that value type
341 is wxColourPropertyValue instead of wxColour (which wxColourProperty
345 class wxColourPropertyValue : public wxObject
348 // An integer value relating to the colour, and which exact
349 // meaning depends on the property with which it is used.
351 // For wxSystemColourProperty:
352 // Any of wxSYS_COLOUR_XXX, or any web-colour ( use wxPG_TO_WEB_COLOUR
353 // macro - (currently unsupported) ), or wxPG_COLOUR_CUSTOM.
356 // Resulting colour. Should be correct regardless of type.
361 in wxSystemColourProperty, and its derived class wxColourProperty, there
362 are various sub-classing features. To set basic list list of colour
363 names, call wxPGProperty::SetChoices().
366 // Override in derived class to customize how colours are translated
368 virtual wxString ColourToString( const wxColour& col, int index ) const;
370 // Returns index of entry that triggers colour picker dialog
371 // (default is last).
372 virtual int GetCustomColourIndex() const;
374 // Helper function to show the colour dialog
375 bool QueryColourFromUser( wxVariant& variant ) const;
377 // Returns colour for given choice.
378 // Default function returns wxSystemSettings::GetColour(index).
379 virtual wxColour GetColour( int index ) const;
382 @subsection wxCursorProperty
384 Represents a wxCursor. wxChoice is used to edit the value.
385 Drop-down list has cursor images under some (wxMSW) platforms.
388 @section pgproperty_creating Creating Custom Properties
390 New properties can be created by subclassing wxPGProperty or one
391 of the provided property classes, and (re)implementing necessary
392 member functions. Below, each virtual member function has ample
393 documentation about its purpose and any odd details which to keep
396 Here is a very simple 'template' code:
399 class MyProperty : public wxPGProperty
402 // All arguments of ctor must have a default value -
403 // use wxPG_LABEL for label and name
404 MyProperty( const wxString& label = wxPG_LABEL,
405 const wxString& name = wxPG_LABEL,
406 const wxString& value = wxEmptyString )
408 // m_value is wxVariant
412 virtual ~MyProperty() { }
414 const wxPGEditor* DoGetEditorClass() const
416 // Determines editor used by property.
417 // You can replace 'TextCtrl' below with any of these
418 // builtin-in property editor identifiers: Choice, ComboBox,
419 // TextCtrlAndButton, ChoiceAndButton, CheckBox, SpinCtrl,
421 return wxPGEditor_TextCtrl;
424 virtual wxString GetValueAsString( int argFlags ) const
426 // TODO: Return property value in string format
429 virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags )
431 // TODO: Adapt string to property value.
438 Since wxPGProperty derives from wxObject, you can use standard
439 DECLARE_DYNAMIC_CLASS and IMPLEMENT_DYNAMIC_CLASS macros. From the
440 above example they were omitted for sake of simplicity, and besides,
441 they are only really needed if you need to use wxRTTI with your
444 You can change the 'value type' of a property by simply assigning different
445 type of variant with SetValue. <b>It is mandatory to implement
446 wxVariantData class for all data types used as property values.</b>
447 You can use macros declared in wxPropertyGrid headers. For instance:
451 // (If you need to have export declaration, use version of macros
452 // with _EXPORTED postfix)
453 WX_PG_DECLARE_VARIANT_DATA(MyDataClass)
456 WX_PG_IMPLEMENT_VARIANT_DATA(MyDataClass)
458 // Or, if you don't have valid == operator:
459 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(MyDataClass)
465 class wxPGProperty
: public wxObject
468 typedef wxUint32 FlagType
;
477 Non-abstract property classes should have constructor of this style:
481 MyProperty( const wxString& label, const wxString& name, const T& value )
484 // Generally recommended way to set the initial value
485 // (as it should work in pretty much 100% of cases).
490 // If has private child properties then create them here. For example:
491 // AddChild( new wxStringProperty( "Subprop 1", wxPG_LABEL, value.GetSubProp1() ) );
496 wxPGProperty( const wxString
& label
, const wxString
& name
);
499 Virtual destructor. It is customary for derived properties to implement this.
501 virtual ~wxPGProperty();
504 This virtual function is called after m_value has been set.
507 - If m_value was set to Null variant (ie. unspecified value), OnSetValue()
509 - m_value may be of any variant type. Typically properties internally support only
510 one variant type, and as such OnSetValue() provides a good opportunity to convert
511 supported values into internal type.
512 - Default implementation does nothing.
514 virtual void OnSetValue();
517 Override this to return something else than m_value as the value.
519 virtual wxVariant
DoGetValue() const { return m_value
; }
522 Implement this function in derived class to check the value.
523 Return true if it is ok. Returning false prevents property change events
527 - Default implementation always returns true.
529 virtual bool ValidateValue( wxVariant
& value
, wxPGValidationInfo
& validationInfo
) const;
532 Converts text into wxVariant value appropriate for this property.
535 On function entry this is the old value (should not be wxNullVariant
536 in normal cases). Translated value must be assigned back to it.
539 Text to be translated into variant.
542 If wxPG_FULL_VALUE is set, returns complete, storable value instead
543 of displayable one (they may be different).
544 If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of
545 composite property string value (as generated by GetValueAsString()
546 called with this same flag).
548 @return Returns @true if resulting wxVariant value was different.
550 @remarks Default implementation converts semicolon delimited tokens into
551 child values. Only works for properties with children.
553 You might want to take into account that m_value is Null variant
554 if property value is unspecified (which is usually only case if
555 you explicitly enabled that sort behavior).
557 virtual bool StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
= 0 ) const;
560 Converts integer (possibly a choice selection) into wxVariant value
561 appropriate for this property.
564 On function entry this is the old value (should not be wxNullVariant
565 in normal cases). Translated value must be assigned back to it.
568 Integer to be translated into variant.
571 If wxPG_FULL_VALUE is set, returns complete, storable value instead
574 @return Returns @true if resulting wxVariant value was different.
577 - If property is not supposed to use choice or spinctrl or other editor
578 with int-based value, it is not necessary to implement this method.
579 - Default implementation simply assign given int to m_value.
580 - If property uses choice control, and displays a dialog on some choice
581 items, then it is preferred to display that dialog in IntToValue
583 - You might want to take into account that m_value is Null variant if
584 property value is unspecified (which is usually only case if you
585 explicitly enabled that sort behavior).
587 virtual bool IntToValue( wxVariant
& value
, int number
, int argFlags
= 0 ) const;
590 Returns text representation of property's value.
593 If wxPG_FULL_VALUE is set, returns complete, storable string value instead of displayable.
594 If wxPG_EDITABLE_VALUE is set, returns string value that must be editable in textctrl.
595 If wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to display
596 as a part of composite property string value.
599 Default implementation returns string composed from text representations of
602 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
605 Converts string to a value, and if successful, calls SetValue() on it.
606 Default behavior is to do nothing.
608 String to get the value from.
610 true if value was changed.
612 bool SetValueFromString( const wxString
& text
, int flags
= 0 );
615 Converts integer to a value, and if succesful, calls SetValue() on it.
616 Default behavior is to do nothing.
618 Int to get the value from.
620 If has wxPG_FULL_VALUE, then the value given is a actual value and not an index.
622 True if value was changed.
624 bool SetValueFromInt( long value
, int flags
= 0 );
627 Returns size of the custom painted image in front of property. This method
628 must be overridden to return non-default value if OnCustomPaint is to be
631 Normally -1, but can be an index to the property's list of items.
633 - Default behavior is to return wxSize(0,0), which means no image.
634 - Default image width or height is indicated with dimension -1.
635 - You can also return wxPG_DEFAULT_IMAGE_SIZE which equals wxSize(-1, -1).
637 virtual wxSize
OnMeasureImage( int item
= -1 ) const;
640 Events received by editor widgets are processed here. Note that editor class
641 usually processes most events. Some, such as button press events of
642 TextCtrlAndButton class, can be handled here. Also, if custom handling
643 for regular events is desired, then that can also be done (for example,
644 wxSystemColourProperty custom handles wxEVT_COMMAND_CHOICE_SELECTED
645 to display colour picker dialog when 'custom' selection is made).
647 If the event causes value to be changed, SetValueInEvent()
648 should be called to set the new value.
653 Should return true if any changes in value should be reported.
655 - If property uses choice control, and displays a dialog on some choice items,
656 then it is preferred to display that dialog in IntToValue instead of OnEvent.
658 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* wnd_primary
, wxEvent
& event
);
661 Called after value of a child property has been altered. Note that this function is
662 usually called at the time that value of this property, or given child property, is
663 still pending for change.
665 Sample pseudo-code implementation:
668 void MyProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const
670 // Acquire reference to actual type of data stored in variant
671 // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros were used to create
672 // the variant class).
673 T& data = TFromVariant(thisValue);
675 // Copy childValue into data.
676 switch ( childIndex )
679 data.SetSubProp1( childvalue.GetLong() );
682 data.SetSubProp2( childvalue.GetString() );
690 Value of this property, that should be altered.
692 Index of child changed (you can use Item(childIndex) to get).
694 Value of the child property.
696 virtual void ChildChanged( wxVariant
& thisValue
, int childIndex
, wxVariant
& childValue
) const;
699 Returns pointer to an instance of used editor.
701 virtual const wxPGEditor
* DoGetEditorClass() const;
704 Returns pointer to the wxValidator that should be used
705 with the editor of this property (NULL for no validator).
706 Setting validator explicitly via SetPropertyValidator
709 In most situations, code like this should work well
710 (macros are used to maintain one actual validator instance,
711 so on the second call the function exits within the first
716 wxValidator* wxMyPropertyClass::DoGetValidator () const
718 WX_PG_DOGETVALIDATOR_ENTRY()
720 wxMyValidator* validator = new wxMyValidator(...);
722 ... prepare validator...
724 WX_PG_DOGETVALIDATOR_EXIT(validator)
730 You can get common filename validator by returning
731 wxFileProperty::GetClassValidator(). wxDirProperty,
732 for example, uses it.
734 virtual wxValidator
* DoGetValidator () const;
737 Override to paint an image in front of the property value text or drop-down
738 list item (but only if wxPGProperty::OnMeasureImage is overridden as well).
740 If property's OnMeasureImage() returns size that has height != 0 but less than
741 row height ( < 0 has special meanings), wxPropertyGrid calls this method to
742 draw a custom image in a limited area in front of the editor control or
743 value text/graphics, and if control has drop-down list, then the image is
744 drawn there as well (even in the case OnMeasureImage() returned higher height
747 NOTE: Following applies when OnMeasureImage() returns a "flexible" height (
748 using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable height items:
749 If rect.x is < 0, then this is a measure item call, which means that
750 dc is invalid and only thing that should be done is to set paintdata.m_drawnHeight
751 to the height of the image of item at index paintdata.m_choiceItem. This call
752 may be done even as often as once every drop-down popup show.
757 Box reserved for custom graphics. Includes surrounding rectangle, if any.
758 If x is < 0, then this is a measure item call (see above).
760 wxPGPaintData structure with much useful data about painted item.
765 const wxPropertyGrid* m_parent;
767 // Normally -1, otherwise index to drop-down list item that has to be drawn.
770 // Set to drawn width in OnCustomPaint (optional).
773 // In a measure item call, set this to the height of item at m_choiceItem index
779 - You can actually exceed rect width, but if you do so then paintdata.m_drawnWidth
780 must be set to the full width drawn in pixels.
781 - Due to technical reasons, rect's height will be default even if custom height
782 was reported during measure call.
783 - Brush is guaranteed to be default background colour. It has been already used to
784 clear the background of area being painted. It can be modified.
785 - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper colour) pen for
786 drawing framing rectangle. It can be changed as well.
788 @see GetValueAsString()
790 virtual void OnCustomPaint( wxDC
& dc
, const wxRect
& rect
, wxPGPaintData
& paintdata
);
793 Returns used wxPGCellRenderer instance for given property column (label=0, value=1).
795 Default implementation returns editor's renderer for all columns.
797 virtual wxPGCellRenderer
* GetCellRenderer( int column
) const;
800 Returns which choice is currently selected. Only applies to properties
803 Needs to reimplemented in derived class if property value does not
804 map directly to a choice. Integer as index, bool, and string usually do.
806 virtual int GetChoiceSelection() const;
809 Refresh values of child properties. Automatically called after value is set.
811 virtual void RefreshChildren();
814 Special handling for attributes of this property.
816 If returns false, then the attribute will be automatically stored in
819 Default implementation simply returns false.
821 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
824 Returns value of an attribute.
826 Override if custom handling of attributes is needed.
828 Default implementation simply return NULL variant.
830 virtual wxVariant
DoGetAttribute( const wxString
& name
) const;
833 Returns instance of a new wxPGEditorDialogAdapter instance, which is
834 used when user presses the (optional) button next to the editor control;
836 Default implementation returns NULL (ie. no action is generated when
839 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
842 Returns wxPGCell of given column, NULL if none. If valid
843 object is returned, caller will gain its ownership.
845 wxPGCell
* AcquireCell( unsigned int column
)
847 if ( column
>= m_cells
.size() )
850 wxPGCell
* cell
= (wxPGCell
*) m_cells
[column
];
851 m_cells
[column
] = NULL
;
856 Append a new choice to property's list of choices.
859 Label for added choice.
862 Value for new choice. Do not specify if you wish this
863 to equal choice index.
866 Index to added choice.
868 int AddChoice( const wxString
& label
, int value
= wxPG_INVALID_VALUE
);
871 Properties which have private child properties should add them
872 with this function, called in their constructor.
874 void AddChild( wxPGProperty
* property
);
877 Adapts list variant into proper value using consecutive
878 ChildChanged() calls.
880 void AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const;
883 Determines, recursively, if all children are not unspecified.
886 Assumes members in this wxVariant list as pending
889 bool AreAllChildrenSpecified( wxVariant
* pendingList
= NULL
) const;
892 Returns true if children of this property are component values (for instance,
893 points size, face name, and is_underlined are component values of a font).
895 bool AreChildrenComponents() const
897 if ( m_flags
& (wxPG_PROP_COMPOSED_VALUE
|wxPG_PROP_AGGREGATE
) )
904 Removes entry from property's wxPGChoices and editor control (if it is active).
906 If selected item is deleted, then the value is set to unspecified.
908 void DeleteChoice( int index
);
910 /** Deletes all child properties. */
913 /** Composes text from values of child properties. */
914 void GenerateComposedValue( wxString
& text
, int argFlags
= 0 ) const;
917 Returns property attribute value, null variant if not found.
919 wxVariant
GetAttribute( const wxString
& name
) const;
921 /** Returns named attribute, as string, if found. Otherwise defVal is returned.
923 wxString
GetAttribute( const wxString
& name
, const wxString
& defVal
) const;
925 /** Returns named attribute, as long, if found. Otherwise defVal is returned.
927 long GetAttributeAsLong( const wxString
& name
, long defVal
) const;
929 /** Returns named attribute, as double, if found. Otherwise defVal is returned.
931 double GetAttributeAsDouble( const wxString
& name
, double defVal
) const;
934 Returns attributes as list wxVariant.
936 wxVariant
GetAttributesAsList() const;
939 Returns editor used for given column. NULL for no editor.
941 const wxPGEditor
* GetColumnEditor( int column
) const
944 return GetEditorClass();
949 /** Returns property's base name (ie. parent's name is not added in any case) */
950 const wxString
& GetBaseName() const { return m_name
; }
953 Returns wxPGCell of given column, NULL if none. wxPGProperty
954 will retain ownership of the cell object.
956 wxPGCell
* GetCell( unsigned int column
) const
958 if ( column
>= m_cells
.size() )
961 return (wxPGCell
*) m_cells
[column
];
965 Returns number of child properties.
967 unsigned int GetChildCount() const;
970 Returns height of children, recursively, and
971 by taking expanded/collapsed status into account.
974 Line height. Pass result of GetGrid()->GetRowHeight() here.
977 Only used (internally) when finding property y-positions.
979 int GetChildrenHeight( int lh
, int iMax
= -1 ) const;
982 Returns read-only reference to property's list of choices.
984 const wxPGChoices
& GetChoices() const;
987 Returns client data (void*) of a property.
989 void* GetClientData() const;
991 /** Sets managed client object of a property.
993 wxClientData
*GetClientObject() const;
996 Returns property's default value. If property's value type is not
997 a built-in one, and "DefaultValue" attribute is not defined, then
998 this function usually returns Null variant.
1000 wxVariant
GetDefaultValue() const;
1002 /** Returns property's displayed text.
1004 wxString
GetDisplayedString() const
1006 return GetValueString(0);
1010 Returns wxPGEditor that will be used and created when
1011 property becomes selected. Returns more accurate value
1012 than DoGetEditorClass().
1014 const wxPGEditor
* GetEditorClass() const;
1016 /** Returns property grid where property lies. */
1017 wxPropertyGrid
* GetGrid() const;
1020 Returns owner wxPropertyGrid, but only if one is currently on a page
1021 displaying this property.
1023 wxPropertyGrid
* GetGridIfDisplayed() const;
1026 Returns property's help or description text.
1028 @see SetHelpString()
1030 const wxString
& GetHelpString() const;
1033 Returns position in parent's array.
1035 unsigned int GetIndexInParent() const;
1037 /** Returns property's label. */
1038 const wxString
& GetLabel() const { return m_label
; }
1041 Returns last visible child property, recursively.
1043 const wxPGProperty
* GetLastVisibleSubItem() const;
1046 Returns highest level non-category, non-root parent. Useful when you
1047 have nested properties with children.
1049 @remarks If immediate parent is root or category, this will return the
1052 wxPGProperty
* GetMainParent() const;
1054 /** Returns maximum allowed length of property's text value.
1056 int GetMaxLength() const
1058 return (int) m_maxLen
;
1061 /** Returns property's name with all (non-category, non-root) parents. */
1062 wxString
GetName() const;
1064 /** Return parent of property */
1065 wxPGProperty
* GetParent() const { return m_parent
; }
1068 Returns (direct) child property with given name (or NULL if not found).
1070 wxPGProperty
* GetPropertyByName( const wxString
& name
) const;
1072 /** Gets assignable version of property's validator. */
1073 wxValidator
* GetValidator() const;
1076 Returns property's value.
1078 wxVariant
GetValue() const
1080 return DoGetValue();
1084 Returns bitmap that appears next to value text. Only returns non-NULL
1085 bitmap if one was set with SetValueImage().
1087 wxBitmap
* GetValueImage() const;
1090 To acquire property's value as string, you should use this
1091 function (instead of GetValueAsString()), as it may produce
1092 more accurate value in future versions.
1094 @see GetValueAsString()
1096 wxString
GetValueString( int argFlags
= 0 ) const;
1099 Returns value type used by this property.
1101 wxString
GetValueType() const
1103 return m_value
.GetType();
1107 Returns coordinate to the top y of the property. Note that the
1108 position of scrollbars is not taken into account.
1113 Returns true if property has even one visible child.
1115 bool HasVisibleChildren() const;
1118 Hides or reveals the property.
1121 @true for hide, @false for reveal.
1124 By default changes are applied recursively. Set this parameter wxPG_DONT_RECURSE to prevent this.
1126 bool Hide( bool hide
, int flags
= wxPG_RECURSE
);
1129 Returns index of given child property. wxNOT_FOUND if
1130 given property is not child of this.
1132 int Index( const wxPGProperty
* p
) const;
1135 Inserts a new choice to property's list of choices.
1141 Insertion position. Use wxNOT_FOUND to append.
1144 Value for new choice. Do not specify if you wish this
1145 to equal choice index.
1147 int InsertChoice( const wxString
& label
, int index
, int value
= wxPG_INVALID_VALUE
);
1150 Returns @true if this property is actually a wxPropertyCategory.
1152 bool IsCategory() const;
1155 Returns @true if property is enabled.
1157 bool IsEnabled() const;
1160 Returns @true if property has visible children.
1162 bool IsExpanded() const;
1165 Returns @true if this property is actually a wxRootProperty.
1167 bool IsRoot() const { return (m_parent
== NULL
); }
1170 Returns @true if candidateParent is some parent of this property.
1172 bool IsSomeParent( wxPGProperty
* candidateParent
) const;
1175 Returns true if property has editable wxTextCtrl when selected.
1177 @remarks Altough disabled properties do not displayed editor, they still
1178 return @true here as being disabled is considered a temporary
1179 condition (unlike being read-only or having limited editing enabled).
1181 bool IsTextEditable() const;
1184 Returns @true if property's value is considered unspecified. This
1185 usually means that value is Null variant.
1187 bool IsValueUnspecified() const;
1190 Returns true if all parents expanded.
1192 bool IsVisible() const;
1195 Returns child property at index i.
1197 wxPGProperty
* Item( size_t i
) const;
1200 If property's editor is active, then update it's value.
1202 void RefreshEditor();
1205 Sets an attribute for this property.
1208 Text identifier of attribute. See @ref propgrid_property_attributes.
1213 @remarks Setting attribute's value to Null variant will simply remove it
1214 from property's set of attributes.
1216 void SetAttribute( const wxString
& name
, wxVariant value
);
1219 Sets editor for a property.
1222 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1223 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full list).
1225 For custom editors, use pointer you received from wxPropertyGrid::RegisterEditorClass().
1227 void SetEditor( const wxPGEditor
* editor
);
1230 Sets editor for a property, by editor name.
1232 void SetEditor( const wxString
& editorName
);
1235 Sets cell information for given column.
1237 Note that the property takes ownership of given wxPGCell instance.
1239 void SetCell( int column
, wxPGCell
* cellObj
);
1242 Sets new set of choices for property.
1244 @remarks This operation clears the property value.
1246 bool SetChoices( wxPGChoices
& choices
);
1249 If property has choices and they are not yet exclusive, new such copy
1250 of them will be created.
1252 void SetChoicesExclusive();
1255 Sets client data (void*) of a property.
1257 @remarks This untyped client data has to be deleted manually.
1259 void SetClientData( void* clientData
);
1261 /** Returns client object of a property.
1263 void SetClientObject(wxClientData
* clientObject
);
1266 Sets selected choice and changes property value.
1268 Tries to retain value type, although currently if it is not string,
1269 then it is forced to integer.
1271 void SetChoiceSelection( int newValue
);
1274 Sets property's help string, which is shown, for example, in
1275 wxPropertyGridManager's description text box.
1277 void SetHelpString( const wxString
& helpString
);
1280 Sets property's label.
1282 @remarks Properties under same parent may have same labels. However,
1283 property names must still remain unique.
1285 void SetLabel( const wxString
& label
) { m_label
= label
; }
1288 Set max length of text in text editor.
1290 bool SetMaxLength( int maxLen
);
1293 Sets property's "is it modified?" flag. Affects children recursively.
1295 void SetModifiedStatus( bool modified
);
1298 Sets new (base) name for property.
1300 void SetName( const wxString
& newName
);
1302 /** Sets wxValidator for a property */
1303 void SetValidator( const wxValidator
& validator
);
1306 Call this to set value of the property. Unlike methods in wxPropertyGrid,
1307 this does not automatically update the display.
1310 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run through
1311 validation process and send property change event.
1313 If you need to change property value in event, based on user input, use
1314 SetValueInEvent() instead.
1317 Pointer to list variant that contains child values. Used to indicate
1318 which children should be marked as modified. Usually you just use NULL.
1321 Use wxPG_SETVAL_REFRESH_EDITOR to update editor control, if it
1324 void SetValue( wxVariant value
, wxVariant
* pList
= NULL
, int flags
= 0 );
1327 Set wxBitmap in front of the value. This bitmap may be ignored
1328 by custom cell renderers.
1330 void SetValueImage( wxBitmap
& bmp
);
1333 Call this function in OnEvent(), OnButtonClick() etc. to change the
1334 property value based on user input.
1336 @remarks This method is const since it doesn't actually modify value, but posts
1337 given variant as pending value, stored in wxPropertyGrid.
1339 void SetValueInEvent( wxVariant value
) const;
1342 Sets property's value to unspecified (ie. Null variant).
1344 void SetValueToUnspecified();
1347 Call with @false in OnSetValue() to cancel value changes after all
1348 (ie. cancel @true returned by StringToValue() or IntToValue()).
1350 void SetWasModified( bool set
= true );
1353 Updates composed values of parent non-category properties, recursively.
1354 Returns topmost property updated.
1356 wxPGProperty
* UpdateParentValues();
1359 Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
1361 bool UsesAutoUnspecified() const;
1365 /** @class wxPGChoices
1367 Helper class for managing choices of wxPropertyGrid properties.
1368 Each entry can have label, value, bitmap, text colour, and background colour.
1370 @library{wxpropgrid}
1373 class WXDLLIMPEXP_PROPGRID wxPGChoices
1376 typedef long ValArrItem
;
1379 Default constructor.
1383 /** Copy constructor. */
1384 wxPGChoices( const wxPGChoices
& a
);
1387 wxPGChoices( const wxChar
** labels
, const long* values
= NULL
);
1390 wxPGChoices( const wxArrayString
& labels
, const wxArrayInt
& values
= wxArrayInt() );
1393 wxPGChoices( wxPGChoicesData
* data
);
1399 Adds to current. If did not have own copies, creates them now. If was empty,
1400 identical to set except that creates copies.
1402 void Add( const wxChar
** labels
, const ValArrItem
* values
= NULL
);
1404 /** Version that works with wxArrayString. */
1405 void Add( const wxArrayString
& arr
, const ValArrItem
* values
= NULL
);
1407 /** Version that works with wxArrayString and wxArrayInt. */
1408 void Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
);
1410 /** Adds single item. */
1411 wxPGChoiceEntry
& Add( const wxString
& label
, int value
= wxPG_INVALID_VALUE
);
1413 /** Adds a single item, with bitmap. */
1414 wxPGChoiceEntry
& Add( const wxString
& label
, const wxBitmap
& bitmap
,
1415 int value
= wxPG_INVALID_VALUE
);
1417 /** Adds a single item with full entry information. */
1418 wxPGChoiceEntry
& Add( const wxPGChoiceEntry
& entry
)
1420 return Insert(entry
, -1);
1423 /** Adds single item, sorted. */
1424 wxPGChoiceEntry
& AddAsSorted( const wxString
& label
, int value
= wxPG_INVALID_VALUE
);
1427 Assigns data from another set of choices.
1429 void Assign( const wxPGChoices
& a
)
1431 AssignData(a
.m_data
);
1435 Assigns data from another set of choices.
1437 void AssignData( wxPGChoicesData
* data
);
1444 if ( m_data
!= wxPGChoicesEmptyData
)
1449 Returns labe of item.
1451 const wxString
& GetLabel( size_t ind
) const;
1454 Returns number of items.
1456 size_t GetCount () const;
1459 Returns value of item;
1461 int GetValue( size_t ind
) const;
1464 Returns array of values matching the given strings. Unmatching strings
1465 result in wxPG_INVALID_VALUE entry in array.
1467 wxArrayInt
GetValuesForStrings( const wxArrayString
& strings
) const;
1470 Returns array of indices matching given strings. Unmatching strings
1471 are added to 'unmatched', if not NULL.
1473 wxArrayInt
GetIndicesForStrings( const wxArrayString
& strings
,
1474 wxArrayString
* unmatched
= NULL
) const;
1477 Returns @true if item at given index has a valid value;
1479 bool HasValue( unsigned int i
) const;
1482 Returns index of item with given label.
1484 int Index( const wxString
& label
) const;
1487 Returns index of item with given value.
1489 int Index( int val
) const;
1492 Inserts single item.
1494 wxPGChoiceEntry
& Insert( const wxString
& label
, int index
, int value
= wxPG_INVALID_VALUE
);
1497 Inserts a single item with full entry information.
1499 wxPGChoiceEntry
& Insert( const wxPGChoiceEntry
& entry
, int index
);
1502 Returns false if this is a constant empty set of choices,
1503 which should not be modified.
1507 return ( m_data
!= wxPGChoicesEmptyData
);
1511 Returns item at given index.
1513 const wxPGChoiceEntry
& Item( unsigned int i
) const
1516 return *m_data
->Item(i
);
1520 Returns item at given index.
1522 wxPGChoiceEntry
& Item( unsigned int i
)
1525 return *m_data
->Item(i
);
1529 Removes count items starting at position nIndex.
1531 void RemoveAt(size_t nIndex
, size_t count
= 1);
1534 Sets contents from lists of strings and values.
1536 void Set( const wxChar
** labels
, const long* values
= NULL
);
1539 Sets contents from lists of strings and values.
1541 void Set( const wxArrayString
& labels
, const wxArrayInt
& values
= wxArrayInt() );
1544 Creates exclusive copy of current choices.
1546 void SetExclusive();
1549 Returns array of choice labels.
1551 wxArrayString
GetLabels() const;
1553 void operator= (const wxPGChoices
& a
)
1555 AssignData(a
.m_data
);
1558 wxPGChoiceEntry
& operator[](unsigned int i
)
1563 const wxPGChoiceEntry
& operator[](unsigned int i
) const
1569 // -----------------------------------------------------------------------