1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxPGProperty
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 #define wxNullProperty ((wxPGProperty*)NULL)
14 @section propgrid_property_attributes wxPropertyGrid Property Attribute Identifiers
16 wxPGProperty::SetAttribute() and wxPropertyGridInterface::SetPropertyAttribute()
17 accept one of these as attribute name argument.
19 You can use strings instead of constants.
20 However, some of these constants are redefined to use cached strings which
21 may reduce 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. Using wxDP_ALLOWNONE will enable
119 better unspecified value support in the editor.
121 #define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
123 /** SpinCtrl editor, int or double. How much number changes when button is
124 pressed (or up/down on keybard).
126 #define wxPG_ATTR_SPINCTRL_STEP wxS("Step")
128 /** SpinCtrl editor, bool. If @true, value wraps at Min/Max.
130 #define wxPG_ATTR_SPINCTRL_WRAP wxS("Wrap")
132 /** SpinCtrl editor, bool. If @true, value can also by changed by moving
133 mouse when left mouse button is being pressed.
135 #define wxPG_ATTR_SPINCTRL_MOTIONSPIN wxS("MotionSpin")
137 /** wxMultiChoiceProperty, int. If 0, no user strings allowed. If 1, user strings
138 appear before list strings. If 2, user strings appear after list string.
140 #define wxPG_ATTR_MULTICHOICE_USERSTRINGMODE wxS("UserStringMode")
142 /** wxColourProperty and its kind, int, default 1. Setting this attribute to 0 hides custom
143 colour from property's list of choices.
145 #define wxPG_COLOUR_ALLOW_CUSTOM wxS("AllowCustom")
155 wxPGProperty is base class for all wxPropertyGrid properties. In
156 sections below we cover few related topics.
158 @li @ref pgproperty_properties
159 @li @ref pgproperty_creating
161 @section pgproperty_properties Supplied Ready-to-use Property Classes
163 Here is a list and short description of supplied fully-functional
164 property classes. They are located in either props.h or advprops.h.
166 @li @ref wxArrayStringProperty
167 @li @ref wxBoolProperty
168 @li @ref wxColourProperty
169 @li @ref wxCursorProperty
170 @li @ref wxDateProperty
171 @li @ref wxDirProperty
172 @li @ref wxEditEnumProperty
173 @li @ref wxEnumProperty
174 @li @ref wxFileProperty
175 @li @ref wxFlagsProperty
176 @li @ref wxFloatProperty
177 @li @ref wxFontProperty
178 @li @ref wxImageFileProperty
179 @li @ref wxIntProperty
180 @li @ref wxLongStringProperty
181 @li @ref wxMultiChoiceProperty
182 @li @ref wxPropertyCategory
183 @li @ref wxStringProperty
184 @li @ref wxSystemColourProperty
185 @li @ref wxUIntProperty
187 @subsection wxPropertyCategory
189 Not an actual property per se, but a header for a group of properties.
190 Regardless inherits from wxPGProperty.
192 @subsection wxStringProperty
194 Simple string property. wxPG_STRING_PASSWORD attribute may be used
195 to echo value as asterisks and use wxTE_PASSWORD for wxTextCtrl.
197 @remarks wxStringProperty has a special trait: if it has value of
198 "<composed>", and also has child properties, then its displayed
199 value becomes composition of child property values, similar as
200 with wxFontProperty, for instance.
202 @subsection wxIntProperty
204 Like wxStringProperty, but converts text to a signed long integer.
205 wxIntProperty seamlessly supports 64-bit integers (ie. wxLongLong).
206 To safely convert variant to integer, use code like this:
210 ll << property->GetValue();
213 wxLongLong ll = propertyGrid->GetPropertyValueAsLong(property);
216 @subsection wxUIntProperty
218 Like wxIntProperty, but displays value as unsigned int. To set
219 the prefix used globally, manipulate wxPG_UINT_PREFIX string attribute.
220 To set the globally used base, manipulate wxPG_UINT_BASE int
221 attribute. Regardless of current prefix, understands (hex) values starting
222 with both "0x" and "$".
223 Like wxIntProperty, wxUIntProperty seamlessly supports 64-bit unsigned
224 integers (ie. wxULongLong). Same wxVariant safety rules apply.
226 @subsection wxFloatProperty
228 Like wxStringProperty, but converts text to a double-precision floating point.
229 Default float-to-text precision is 6 decimals, but this can be changed
230 by modifying wxPG_FLOAT_PRECISION attribute.
232 @subsection wxBoolProperty
234 Represents a boolean value. wxChoice is used as editor control, by the
235 default. wxPG_BOOL_USE_CHECKBOX attribute can be set to true inorder to use
238 @subsection wxLongStringProperty
240 Like wxStringProperty, but has a button that triggers a small text editor
241 dialog. Note that in long string values, tabs are represented by "\t" and
244 To display custom dialog on button press, you can subclass
245 wxLongStringProperty and implement OnButtonClick, like this:
248 virtual bool OnButtonClick( wxPropertyGrid* propGrid, wxString& value )
250 wxSize dialogSize(...size of your dialog...);
252 wxPoint dlgPos = propGrid->GetGoodEditorDialogPosition(this,
255 // Create dialog dlg at dlgPos. Use value as initial string
259 if ( dlg.ShowModal() == wxID_OK )
261 value = dlg.GetStringValue);
268 Also, if you wish not to have line breaks and tabs translated to
269 escape sequences, then do following in constructor of your subclass:
272 m_flags |= wxPG_PROP_NO_ESCAPE;
275 @subsection wxDirProperty
277 Like wxLongStringProperty, but the button triggers dir selector instead.
278 Supported properties (all with string value): wxPG_DIR_DIALOG_MESSAGE.
280 @subsection wxFileProperty
282 Like wxLongStringProperty, but the button triggers file selector instead.
283 Default wildcard is "All files..." but this can be changed by setting
284 wxPG_FILE_WILDCARD attribute (see wxFileDialog for format details).
285 Attribute wxPG_FILE_SHOW_FULL_PATH can be set to @false inorder to show
286 only the filename, not the entire path.
288 @subsection wxEnumProperty
290 Represents a single selection from a list of choices -
291 wxOwnerDrawnComboBox is used to edit the value.
293 @subsection wxFlagsProperty
295 Represents a bit set that fits in a long integer. wxBoolProperty sub-properties
296 are created for editing individual bits. Textctrl is created to manually edit
297 the flags as a text; a continous sequence of spaces, commas and semicolons
298 is considered as a flag id separator.
299 <b>Note: </b> When changing "choices" (ie. flag labels) of wxFlagsProperty, you
300 will need to use wxPGProperty::SetChoices() - otherwise they will not get updated
303 @subsection wxArrayStringProperty
305 Allows editing of a list of strings in wxTextCtrl and in a separate dialog.
307 @subsection wxDateProperty
309 wxDateTime property. Default editor is DatePickerCtrl, altough TextCtrl
310 should work as well. wxPG_DATE_FORMAT attribute can be used to change
311 string wxDateTime::Format uses (altough default is recommended as it is
312 locale-dependant), and wxPG_DATE_PICKER_STYLE allows changing window
313 style given to DatePickerCtrl (default is wxDP_DEFAULT|wxDP_SHOWCENTURY).
314 Using wxDP_ALLOWNONE will enable better unspecified value support.
316 @subsection wxEditEnumProperty
318 Represents a string that can be freely edited or selected from list of choices -
319 custom combobox control is used to edit the value.
321 @subsection wxMultiChoiceProperty
323 Allows editing a multiple selection from a list of strings. This is
324 property is pretty much built around concept of wxMultiChoiceDialog.
325 It uses wxArrayString value.
327 @subsection wxImageFileProperty
329 Like wxFileProperty, but has thumbnail of the image in front of
330 the filename and autogenerates wildcard from available image handlers.
332 @subsection wxColourProperty
334 <b>Useful alternate editor:</b> Choice.
336 Represents wxColour. wxButton is used to trigger a colour picker dialog.
337 There are various sub-classing opportunities with this class. See
338 below in wxSystemColourProperty section for details.
340 @subsection wxFontProperty
342 Represents wxFont. Various sub-properties are used to edit individual
345 @subsection wxSystemColourProperty
347 Represents wxColour and a system colour index. wxChoice is used to edit
348 the value. Drop-down list has color images. Note that value type
349 is wxColourPropertyValue instead of wxColour (which wxColourProperty
353 class wxColourPropertyValue : public wxObject
356 // An integer value relating to the colour, and which exact
357 // meaning depends on the property with which it is used.
359 // For wxSystemColourProperty:
360 // Any of wxSYS_COLOUR_XXX, or any web-colour ( use wxPG_TO_WEB_COLOUR
361 // macro - (currently unsupported) ), or wxPG_COLOUR_CUSTOM.
364 // Resulting colour. Should be correct regardless of type.
369 in wxSystemColourProperty, and its derived class wxColourProperty, there
370 are various sub-classing features. To set basic list list of colour
371 names, call wxPGProperty::SetChoices().
374 // Override in derived class to customize how colours are translated
376 virtual wxString ColourToString( const wxColour& col, int index ) const;
378 // Returns index of entry that triggers colour picker dialog
379 // (default is last).
380 virtual int GetCustomColourIndex() const;
382 // Helper function to show the colour dialog
383 bool QueryColourFromUser( wxVariant& variant ) const;
385 // Returns colour for given choice.
386 // Default function returns wxSystemSettings::GetColour(index).
387 virtual wxColour GetColour( int index ) const;
390 @subsection wxCursorProperty
392 Represents a wxCursor. wxChoice is used to edit the value.
393 Drop-down list has cursor images under some (wxMSW) platforms.
396 @section pgproperty_creating Creating Custom Properties
398 New properties can be created by subclassing wxPGProperty or one
399 of the provided property classes, and (re)implementing necessary
400 member functions. Below, each virtual member function has ample
401 documentation about its purpose and any odd details which to keep
404 Here is a very simple 'template' code:
407 class MyProperty : public wxPGProperty
410 // All arguments of ctor must have a default value -
411 // use wxPG_LABEL for label and name
412 MyProperty( const wxString& label = wxPG_LABEL,
413 const wxString& name = wxPG_LABEL,
414 const wxString& value = wxEmptyString )
416 // m_value is wxVariant
420 virtual ~MyProperty() { }
422 const wxPGEditor* DoGetEditorClass() const
424 // Determines editor used by property.
425 // You can replace 'TextCtrl' below with any of these
426 // builtin-in property editor identifiers: Choice, ComboBox,
427 // TextCtrlAndButton, ChoiceAndButton, CheckBox, SpinCtrl,
429 return wxPGEditor_TextCtrl;
432 virtual wxString ValueToString( wxVariant& value,
435 // TODO: Convert given property value to a string
438 virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags )
440 // TODO: Adapt string to property value.
447 Since wxPGProperty derives from wxObject, you can use standard
448 DECLARE_DYNAMIC_CLASS and IMPLEMENT_DYNAMIC_CLASS macros. From the
449 above example they were omitted for sake of simplicity, and besides,
450 they are only really needed if you need to use wxRTTI with your
453 You can change the 'value type' of a property by simply assigning different
454 type of variant with SetValue. <b>It is mandatory to implement
455 wxVariantData class for all data types used as property values.</b>
456 You can use macros declared in wxPropertyGrid headers. For instance:
460 // (If you need to have export declaration, use version of macros
461 // with _EXPORTED postfix)
462 WX_PG_DECLARE_VARIANT_DATA(MyDataClass)
465 WX_PG_IMPLEMENT_VARIANT_DATA(MyDataClass)
467 // Or, if you don't have valid == operator:
468 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(MyDataClass)
474 class wxPGProperty
: public wxObject
477 typedef wxUint32 FlagType
;
486 Non-abstract property classes should have constructor of this style:
490 MyProperty( const wxString& label, const wxString& name, const T& value )
493 // Generally recommended way to set the initial value
494 // (as it should work in pretty much 100% of cases).
499 // If has private child properties then create them here. For example:
500 // AddChild( new wxStringProperty( "Subprop 1", wxPG_LABEL, value.GetSubProp1() ) );
505 wxPGProperty( const wxString
& label
, const wxString
& name
);
508 Virtual destructor. It is customary for derived properties to implement this.
510 virtual ~wxPGProperty();
513 This virtual function is called after m_value has been set.
516 - If m_value was set to Null variant (ie. unspecified value), OnSetValue()
518 - m_value may be of any variant type. Typically properties internally support only
519 one variant type, and as such OnSetValue() provides a good opportunity to convert
520 supported values into internal type.
521 - Default implementation does nothing.
523 virtual void OnSetValue();
526 Override this to return something else than m_value as the value.
528 virtual wxVariant
DoGetValue() const;
531 Implement this function in derived class to check the value.
532 Return @true if it is ok. Returning @false prevents property change events
536 - Default implementation always returns @true.
538 virtual bool ValidateValue( wxVariant
& value
, wxPGValidationInfo
& validationInfo
) const;
541 Converts text into wxVariant value appropriate for this property.
544 On function entry this is the old value (should not be wxNullVariant
545 in normal cases). Translated value must be assigned back to it.
548 Text to be translated into variant.
551 If wxPG_FULL_VALUE is set, returns complete, storable value instead
552 of displayable one (they may be different).
553 If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of
554 composite property string value (as generated by ValueToString()
555 called with this same flag).
557 @return Returns @true if resulting wxVariant value was different.
559 @remarks Default implementation converts semicolon delimited tokens into
560 child values. Only works for properties with children.
562 You might want to take into account that m_value is Null variant
563 if property value is unspecified (which is usually only case if
564 you explicitly enabled that sort behavior).
566 virtual bool StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
= 0 ) const;
569 Converts integer (possibly a choice selection) into wxVariant value
570 appropriate for this property.
573 On function entry this is the old value (should not be wxNullVariant
574 in normal cases). Translated value must be assigned back to it.
576 Integer to be translated into variant.
578 If wxPG_FULL_VALUE is set, returns complete, storable value instead
581 @return Returns @true if resulting wxVariant value was different.
584 - If property is not supposed to use choice or spinctrl or other editor
585 with int-based value, it is not necessary to implement this method.
586 - Default implementation simply assign given int to m_value.
587 - If property uses choice control, and displays a dialog on some choice
588 items, then it is preferred to display that dialog in IntToValue
590 - You might want to take into account that m_value is Mull variant if
591 property value is unspecified (which is usually only case if you
592 explicitly enabled that sort behavior).
594 virtual bool IntToValue( wxVariant
& variant
, int number
, int argFlags
= 0 ) const;
597 Converts property value into a text representation.
600 Value to be converted.
602 If 0 (default value), then displayed string is returned.
603 If wxPG_FULL_VALUE is set, returns complete, storable string value
604 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
605 string value that must be editable in textctrl.
606 If wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
607 display as a part of string property's composite text representation.
609 @remarks Default implementation calls GenerateComposedValue().
611 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
614 Converts string to a value, and if successful, calls SetValue() on it.
615 Default behavior is to do nothing.
618 String to get the value from.
622 @return @true if value was changed.
624 bool SetValueFromString( const wxString
& text
, int flags
= 0 );
627 Converts integer to a value, and if succesful, calls SetValue() on it.
628 Default behavior is to do nothing.
631 Int to get the value from.
633 If has wxPG_FULL_VALUE, then the value given is a actual value and not an index.
635 @return @true if value was changed.
637 bool SetValueFromInt( long value
, int flags
= 0 );
640 Returns size of the custom painted image in front of property. This method
641 must be overridden to return non-default value if OnCustomPaint is to be
645 Normally -1, but can be an index to the property's list of items.
648 - Default behavior is to return wxSize(0,0), which means no image.
649 - Default image width or height is indicated with dimension -1.
650 - You can also return wxPG_DEFAULT_IMAGE_SIZE which equals wxSize(-1, -1).
652 virtual wxSize
OnMeasureImage( int item
= -1 ) const;
655 Events received by editor widgets are processed here. Note that editor class
656 usually processes most events. Some, such as button press events of
657 TextCtrlAndButton class, can be handled here. Also, if custom handling
658 for regular events is desired, then that can also be done (for example,
659 wxSystemColourProperty custom handles wxEVT_COMMAND_CHOICE_SELECTED
660 to display colour picker dialog when 'custom' selection is made).
662 If the event causes value to be changed, SetValueInEvent() should be called
663 to set the new value.
665 The parameter @a event is the associated wxEvent.
668 Should return @true if any changes in value should be reported.
671 - If property uses choice control, and displays a dialog on some choice items,
672 then it is preferred to display that dialog in IntToValue instead of OnEvent.
674 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* wnd_primary
, wxEvent
& event
);
677 Called after value of a child property has been altered. Note that this function is
678 usually called at the time that value of this property, or given child property, is
679 still pending for change.
681 Sample pseudo-code implementation:
684 void MyProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const
686 // Acquire reference to actual type of data stored in variant
687 // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros were used to create
688 // the variant class).
689 T& data = TFromVariant(thisValue);
691 // Copy childValue into data.
692 switch ( childIndex )
695 data.SetSubProp1( childvalue.GetLong() );
698 data.SetSubProp2( childvalue.GetString() );
706 Value of this property, that should be altered.
708 Index of child changed (you can use Item(childIndex) to get).
710 Value of the child property.
712 virtual void ChildChanged( wxVariant
& thisValue
, int childIndex
, wxVariant
& childValue
) const;
715 Returns pointer to an instance of used editor.
717 virtual const wxPGEditor
* DoGetEditorClass() const;
720 Returns pointer to the wxValidator that should be used
721 with the editor of this property (@NULL for no validator).
722 Setting validator explicitly via SetPropertyValidator
725 In most situations, code like this should work well
726 (macros are used to maintain one actual validator instance,
727 so on the second call the function exits within the first
732 wxValidator* wxMyPropertyClass::DoGetValidator () const
734 WX_PG_DOGETVALIDATOR_ENTRY()
736 wxMyValidator* validator = new wxMyValidator(...);
738 ... prepare validator...
740 WX_PG_DOGETVALIDATOR_EXIT(validator)
746 You can get common filename validator by returning
747 wxFileProperty::GetClassValidator(). wxDirProperty,
748 for example, uses it.
750 virtual wxValidator
* DoGetValidator () const;
753 Override to paint an image in front of the property value text or drop-down
754 list item (but only if wxPGProperty::OnMeasureImage is overridden as well).
756 If property's OnMeasureImage() returns size that has height != 0 but less than
757 row height ( < 0 has special meanings), wxPropertyGrid calls this method to
758 draw a custom image in a limited area in front of the editor control or
759 value text/graphics, and if control has drop-down list, then the image is
760 drawn there as well (even in the case OnMeasureImage() returned higher height
763 NOTE: Following applies when OnMeasureImage() returns a "flexible" height (
764 using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable height items:
765 If rect.x is < 0, then this is a measure item call, which means that
766 dc is invalid and only thing that should be done is to set paintdata.m_drawnHeight
767 to the height of the image of item at index paintdata.m_choiceItem. This call
768 may be done even as often as once every drop-down popup show.
773 Box reserved for custom graphics. Includes surrounding rectangle, if any.
774 If x is < 0, then this is a measure item call (see above).
776 wxPGPaintData structure with much useful data about painted item.
781 const wxPropertyGrid* m_parent;
783 // Normally -1, otherwise index to drop-down list item that has to be drawn.
786 // Set to drawn width in OnCustomPaint (optional).
789 // In a measure item call, set this to the height of item at m_choiceItem index
795 - You can actually exceed rect width, but if you do so then paintdata.m_drawnWidth
796 must be set to the full width drawn in pixels.
797 - Due to technical reasons, rect's height will be default even if custom height
798 was reported during measure call.
799 - Brush is guaranteed to be default background colour. It has been already used to
800 clear the background of area being painted. It can be modified.
801 - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper colour) pen for
802 drawing framing rectangle. It can be changed as well.
806 virtual void OnCustomPaint( wxDC
& dc
, const wxRect
& rect
, wxPGPaintData
& paintdata
);
809 Returns used wxPGCellRenderer instance for given property column (label=0, value=1).
811 Default implementation returns editor's renderer for all columns.
813 virtual wxPGCellRenderer
* GetCellRenderer( int column
) const;
816 Returns which choice is currently selected. Only applies to properties
819 Needs to reimplemented in derived class if property value does not
820 map directly to a choice. Integer as index, bool, and string usually do.
822 virtual int GetChoiceSelection() const;
825 Refresh values of child properties. Automatically called after value is set.
827 virtual void RefreshChildren();
830 Special handling for attributes of this property.
832 If returns @false, then the attribute will be automatically stored in
835 Default implementation simply returns @false.
837 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
840 Returns value of an attribute.
842 Override if custom handling of attributes is needed.
844 Default implementation simply return @NULL variant.
846 virtual wxVariant
DoGetAttribute( const wxString
& name
) const;
849 Returns instance of a new wxPGEditorDialogAdapter instance, which is
850 used when user presses the (optional) button next to the editor control;
852 Default implementation returns @NULL (ie. no action is generated when
855 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
858 Called whenever validation has failed with given pending value.
860 @remarks If you implement this in your custom property class, please
861 remember to call the baser implementation as well, since they
862 may use it to revert property into pre-change state.
864 virtual void OnValidationFailure( wxVariant
& pendingValue
);
867 Append a new choice to property's list of choices.
870 Label for added choice.
873 Value for new choice. Do not specify if you wish this
874 to equal choice index.
877 Index to added choice.
879 int AddChoice( const wxString
& label
, int value
= wxPG_INVALID_VALUE
);
882 Adds a child property. If you use this instead of
883 wxPropertyGridInterface::Insert() or
884 wxPropertyGridInterface::AppendIn(), then you must set up
885 property's parental type before making the call. To do this,
886 call property's SetParentalType() function with either
887 wxPG_PROP_MISC_PARENT (normal, public children) or with
888 wxPG_PROP_AGGREGATE (private children for subclassed property).
892 wxPGProperty* prop = new wxStringProperty(wxS("Property"));
893 prop->SetParentalType(wxPG_PROP_MISC_PARENT);
894 wxPGProperty* prop2 = new wxStringProperty(wxS("Property2"));
895 prop->AddChild(prop2);
898 void AddChild( wxPGProperty
* property
);
901 Adapts list variant into proper value using consecutive
902 ChildChanged() calls.
904 void AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const;
907 Determines, recursively, if all children are not unspecified.
910 Assumes members in this wxVariant list as pending
913 bool AreAllChildrenSpecified( wxVariant
* pendingList
= NULL
) const;
916 Returns @true if children of this property are component values (for instance,
917 points size, face name, and is_underlined are component values of a font).
919 bool AreChildrenComponents() const;
922 Deletes children of the property.
924 void DeleteChildren();
927 Removes entry from property's wxPGChoices and editor control (if it is active).
929 If selected item is deleted, then the value is set to unspecified.
931 void DeleteChoice( int index
);
933 /** Deletes all child properties. */
937 Composes text from values of child properties.
939 wxString
GenerateComposedValue() const;
942 Returns property attribute value, null variant if not found.
944 wxVariant
GetAttribute( const wxString
& name
) const;
946 /** Returns named attribute, as string, if found. Otherwise defVal is returned.
948 wxString
GetAttribute( const wxString
& name
, const wxString
& defVal
) const;
950 /** Returns named attribute, as long, if found. Otherwise defVal is returned.
952 long GetAttributeAsLong( const wxString
& name
, long defVal
) const;
954 /** Returns named attribute, as double, if found. Otherwise defVal is returned.
956 double GetAttributeAsDouble( const wxString
& name
, double defVal
) const;
959 Returns attributes as list wxVariant.
961 wxVariant
GetAttributesAsList() const;
964 Returns editor used for given column. @NULL for no editor.
966 const wxPGEditor
* GetColumnEditor( int column
) const;
968 /** Returns property's base name (ie. parent's name is not added in any case) */
969 const wxString
& GetBaseName() const;
972 Returns wxPGCell of given column.
974 const wxPGCell
& GetCell( unsigned int column
) const;
977 Returns number of child properties.
979 unsigned int GetChildCount() const;
982 Returns height of children, recursively, and
983 by taking expanded/collapsed status into account.
986 Line height. Pass result of GetGrid()->GetRowHeight() here.
989 Only used (internally) when finding property y-positions.
991 int GetChildrenHeight( int lh
, int iMax
= -1 ) const;
994 Returns read-only reference to property's list of choices.
996 const wxPGChoices
& GetChoices() const;
999 Returns client data (void*) of a property.
1001 void* GetClientData() const;
1003 /** Sets managed client object of a property.
1005 wxClientData
*GetClientObject() const;
1008 Returns property's default value. If property's value type is not
1009 a built-in one, and "DefaultValue" attribute is not defined, then
1010 this function usually returns Null variant.
1012 wxVariant
GetDefaultValue() const;
1014 /** Returns property's displayed text.
1016 wxString
GetDisplayedString() const;
1019 Returns wxPGEditor that will be used and created when
1020 property becomes selected. Returns more accurate value
1021 than DoGetEditorClass().
1023 const wxPGEditor
* GetEditorClass() const;
1025 /** Returns property grid where property lies. */
1026 wxPropertyGrid
* GetGrid() const;
1029 Returns owner wxPropertyGrid, but only if one is currently on a page
1030 displaying this property.
1032 wxPropertyGrid
* GetGridIfDisplayed() const;
1035 Returns property's help or description text.
1037 @see SetHelpString()
1039 const wxString
& GetHelpString() const;
1042 Returns position in parent's array.
1044 unsigned int GetIndexInParent() const;
1046 /** Returns property's label. */
1047 const wxString
& GetLabel() const;
1050 Returns last visible child property, recursively.
1052 const wxPGProperty
* GetLastVisibleSubItem() const;
1055 Returns highest level non-category, non-root parent. Useful when you
1056 have nested properties with children.
1058 @remarks If immediate parent is root or category, this will return the
1061 wxPGProperty
* GetMainParent() const;
1063 /** Returns maximum allowed length of property's text value.
1065 int GetMaxLength() const;
1067 /** Returns property's name with all (non-category, non-root) parents. */
1068 wxString
GetName() const;
1070 /** Return parent of property */
1071 wxPGProperty
* GetParent() const;
1074 Returns (direct) child property with given name (or @NULL if not found).
1076 wxPGProperty
* GetPropertyByName( const wxString
& name
) const;
1078 /** Gets assignable version of property's validator. */
1079 wxValidator
* GetValidator() const;
1082 Returns property's value.
1084 wxVariant
GetValue() const;
1087 Returns bitmap that appears next to value text. Only returns non-@NULL
1088 bitmap if one was set with SetValueImage().
1090 wxBitmap
* GetValueImage() const;
1092 /** Returns text representation of property's value.
1095 If 0 (default value), then displayed string is returned.
1096 If wxPG_FULL_VALUE is set, returns complete, storable string value
1097 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
1098 string value that must be editable in textctrl. If
1099 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
1100 display as a part of string property's composite text
1103 @remarks In older versions, this function used to be overridden to convert
1104 property's value into a string representation. This function is
1105 now handled by ValueToString(), and overriding this function now
1106 will result in run-time assertion failure.
1108 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
1110 /** Synonymous to GetValueAsString().
1112 @deprecated Use GetValueAsString() instead.
1114 @see GetValueAsString()
1116 wxDEPRECATED( wxString
GetValueString( int argFlags
= 0 ) const );
1119 Returns value type used by this property.
1121 wxString
GetValueType() const;
1124 Returns coordinate to the top y of the property. Note that the
1125 position of scrollbars is not taken into account.
1130 Returns @true if property has even one visible child.
1132 bool HasVisibleChildren() const;
1135 Hides or reveals the property.
1138 @true for hide, @false for reveal.
1141 By default changes are applied recursively. Set this parameter wxPG_DONT_RECURSE to prevent this.
1143 bool Hide( bool hide
, int flags
= wxPG_RECURSE
);
1146 Returns index of given child property. wxNOT_FOUND if
1147 given property is not child of this.
1149 int Index( const wxPGProperty
* p
) const;
1152 Inserts a new choice to property's list of choices.
1158 Insertion position. Use wxNOT_FOUND to append.
1161 Value for new choice. Do not specify if you wish this
1162 to equal choice index.
1164 int InsertChoice( const wxString
& label
, int index
, int value
= wxPG_INVALID_VALUE
);
1167 Returns @true if this property is actually a wxPropertyCategory.
1169 bool IsCategory() const;
1172 Returns @true if property is enabled.
1174 bool IsEnabled() const;
1177 Returns @true if property has visible children.
1179 bool IsExpanded() const;
1182 Returns @true if this property is actually a wxRootProperty.
1184 bool IsRoot() const;
1187 Returns @true if candidateParent is some parent of this property.
1189 bool IsSomeParent( wxPGProperty
* candidateParent
) const;
1192 Returns true if property has editable wxTextCtrl when selected.
1194 @remarks Altough disabled properties do not displayed editor, they still
1195 return @true here as being disabled is considered a temporary
1196 condition (unlike being read-only or having limited editing enabled).
1198 bool IsTextEditable() const;
1201 Returns @true if property's value is considered unspecified. This
1202 usually means that value is Null variant.
1204 bool IsValueUnspecified() const;
1207 Returns true if all parents expanded.
1209 bool IsVisible() const;
1212 Returns child property at index i.
1214 wxPGProperty
* Item( unsigned int i
) const;
1217 If property's editor is active, then update it's value.
1219 void RefreshEditor();
1222 Sets an attribute for this property.
1225 Text identifier of attribute. See @ref propgrid_property_attributes.
1230 @remarks Setting attribute's value to Null variant will simply remove it
1231 from property's set of attributes.
1233 void SetAttribute( const wxString
& name
, wxVariant value
);
1236 Sets property's background colour.
1239 Background colour to use.
1242 If @true, children are affected recursively, and any categories
1245 void SetBackgroundColour( const wxColour
& colour
,
1246 bool recursively
= false );
1249 Sets editor for a property.
1252 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1253 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full list).
1255 For custom editors, use pointer you received from wxPropertyGrid::RegisterEditorClass().
1257 void SetEditor( const wxPGEditor
* editor
);
1260 Sets editor for a property, by editor name.
1262 void SetEditor( const wxString
& editorName
);
1265 Sets cell information for given column.
1267 void SetCell( int column
, const wxPGCell
& cell
);
1270 Sets new set of choices for property.
1272 @remarks This operation clears the property value.
1274 bool SetChoices( wxPGChoices
& choices
);
1277 If property has choices and they are not yet exclusive, new such copy
1278 of them will be created.
1280 void SetChoicesExclusive();
1283 Sets client data (void*) of a property.
1285 @remarks This untyped client data has to be deleted manually.
1287 void SetClientData( void* clientData
);
1289 /** Returns client object of a property.
1291 void SetClientObject(wxClientData
* clientObject
);
1294 Sets selected choice and changes property value.
1296 Tries to retain value type, although currently if it is not string,
1297 then it is forced to integer.
1299 void SetChoiceSelection( int newValue
);
1302 Sets property's help string, which is shown, for example, in
1303 wxPropertyGridManager's description text box.
1305 void SetHelpString( const wxString
& helpString
);
1308 Sets property's label.
1310 @remarks Properties under same parent may have same labels. However,
1311 property names must still remain unique.
1313 void SetLabel( const wxString
& label
);
1316 Set max length of text in text editor.
1318 bool SetMaxLength( int maxLen
);
1321 Sets property's "is it modified?" flag. Affects children recursively.
1323 void SetModifiedStatus( bool modified
);
1326 Sets new (base) name for property.
1328 void SetName( const wxString
& newName
);
1331 Changes what sort of parent this property is for its children.
1334 Use one of the following values: wxPG_PROP_MISC_PARENT (for generic
1335 parents), wxPG_PROP_CATEGORY (for categories), or
1336 wxPG_PROP_AGGREGATE (for derived property classes with private
1339 @remarks You only need to call this if you use AddChild() to add
1340 child properties. Adding properties with
1341 wxPropertyGridInterface::Insert() or
1342 wxPropertyGridInterface::AppendIn() will automatically set
1343 property to use wxPG_PROP_MISC_PARENT style.
1345 void SetParentalType( int flag
);
1348 Sets property's text colour.
1354 If @true, children are affected recursively, and any categories
1357 void SetTextColour( const wxColour
& colour
,
1358 bool recursively
= false );
1360 /** Sets wxValidator for a property */
1361 void SetValidator( const wxValidator
& validator
);
1364 Call this to set value of the property. Unlike methods in wxPropertyGrid,
1365 this does not automatically update the display.
1368 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run through
1369 validation process and send property change event.
1371 If you need to change property value in event, based on user input, use
1372 SetValueInEvent() instead.
1377 Pointer to list variant that contains child values. Used to indicate
1378 which children should be marked as modified. Usually you just use @NULL.
1380 Use wxPG_SETVAL_REFRESH_EDITOR to update editor control, if it
1383 void SetValue( wxVariant value
, wxVariant
* pList
= NULL
, int flags
= 0 );
1386 Set wxBitmap in front of the value. This bitmap may be ignored
1387 by custom cell renderers.
1389 void SetValueImage( wxBitmap
& bmp
);
1392 Call this function in OnEvent(), OnButtonClick() etc. to change the
1393 property value based on user input.
1395 @remarks This method is const since it doesn't actually modify value, but posts
1396 given variant as pending value, stored in wxPropertyGrid.
1398 void SetValueInEvent( wxVariant value
) const;
1401 Sets property's value to unspecified (ie. Null variant).
1403 void SetValueToUnspecified();
1406 Call with @false in OnSetValue() to cancel value changes after all
1407 (ie. cancel @true returned by StringToValue() or IntToValue()).
1409 void SetWasModified( bool set
= true );
1412 Updates composed values of parent non-category properties, recursively.
1413 Returns topmost property updated.
1415 wxPGProperty
* UpdateParentValues();
1418 Returns @true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
1420 bool UsesAutoUnspecified() const;
1427 Helper class for managing choices of wxPropertyGrid properties.
1428 Each entry can have label, value, bitmap, text colour, and background colour.
1430 @library{wxpropgrid}
1433 class WXDLLIMPEXP_PROPGRID wxPGChoices
1436 typedef long ValArrItem
;
1439 Default constructor.
1443 /** Copy constructor. */
1444 wxPGChoices( const wxPGChoices
& a
);
1447 wxPGChoices( const wxChar
** labels
, const long* values
= NULL
);
1450 wxPGChoices( const wxArrayString
& labels
, const wxArrayInt
& values
= wxArrayInt() );
1453 wxPGChoices( wxPGChoicesData
* data
);
1459 Adds to current. If did not have own copies, creates them now. If was empty,
1460 identical to set except that creates copies.
1462 void Add( const wxChar
** labels
, const ValArrItem
* values
= NULL
);
1464 /** Version that works with wxArrayString. */
1465 void Add( const wxArrayString
& arr
, const ValArrItem
* values
= NULL
);
1467 /** Version that works with wxArrayString and wxArrayInt. */
1468 void Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
);
1470 /** Adds single item. */
1471 wxPGChoiceEntry
& Add( const wxString
& label
, int value
= wxPG_INVALID_VALUE
);
1473 /** Adds a single item, with bitmap. */
1474 wxPGChoiceEntry
& Add( const wxString
& label
, const wxBitmap
& bitmap
,
1475 int value
= wxPG_INVALID_VALUE
);
1477 /** Adds a single item with full entry information. */
1478 wxPGChoiceEntry
& Add( const wxPGChoiceEntry
& entry
);
1480 /** Adds single item, sorted. */
1481 wxPGChoiceEntry
& AddAsSorted( const wxString
& label
, int value
= wxPG_INVALID_VALUE
);
1484 Assigns data from another set of choices.
1486 void Assign( const wxPGChoices
& a
);
1489 Assigns data from another set of choices.
1491 void AssignData( wxPGChoicesData
* data
);
1499 Returns labe of item.
1501 const wxString
& GetLabel( unsigned int ind
) const;
1504 Returns number of items.
1506 unsigned int GetCount() const;
1509 Returns value of item;
1511 int GetValue( unsigned int ind
) const;
1514 Returns array of values matching the given strings. Unmatching strings
1515 result in wxPG_INVALID_VALUE entry in array.
1517 wxArrayInt
GetValuesForStrings( const wxArrayString
& strings
) const;
1520 Returns array of indices matching given strings. Unmatching strings
1521 are added to 'unmatched', if not @NULL.
1523 wxArrayInt
GetIndicesForStrings( const wxArrayString
& strings
,
1524 wxArrayString
* unmatched
= NULL
) const;
1527 Returns @true if item at given index has a valid value;
1529 bool HasValue( unsigned int i
) const;
1532 Returns index of item with given label.
1534 int Index( const wxString
& label
) const;
1537 Returns index of item with given value.
1539 int Index( int val
) const;
1542 Inserts single item.
1544 wxPGChoiceEntry
& Insert( const wxString
& label
, int index
, int value
= wxPG_INVALID_VALUE
);
1547 Inserts a single item with full entry information.
1549 wxPGChoiceEntry
& Insert( const wxPGChoiceEntry
& entry
, int index
);
1552 Returns @false if this is a constant empty set of choices,
1553 which should not be modified.
1558 Returns item at given index.
1560 const wxPGChoiceEntry
& Item( unsigned int i
) const;
1563 Returns item at given index.
1565 wxPGChoiceEntry
& Item( unsigned int i
);
1568 Removes count items starting at position nIndex.
1570 void RemoveAt(size_t nIndex
, size_t count
= 1);
1573 Sets contents from lists of strings and values.
1575 void Set( const wxChar
** labels
, const long* values
= NULL
);
1578 Sets contents from lists of strings and values.
1580 void Set( const wxArrayString
& labels
, const wxArrayInt
& values
= wxArrayInt() );
1583 Creates exclusive copy of current choices.
1585 void SetExclusive();
1588 Returns array of choice labels.
1590 wxArrayString
GetLabels() const;
1592 void operator= (const wxPGChoices
& a
);
1594 wxPGChoiceEntry
& operator[](unsigned int i
);
1595 const wxPGChoiceEntry
& operator[](unsigned int i
) const;
1598 // -----------------------------------------------------------------------