1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxPGProperty
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 #define wxNullProperty ((wxPGProperty*)NULL)
15 Contains information relayed to property's OnCustomPaint.
19 /** wxPropertyGrid. */
20 const wxPropertyGrid
* m_parent
;
22 /** Normally -1, otherwise index to drop-down list item that has to be drawn. */
25 /** Set to drawn width in OnCustomPaint (optional). */
28 /** In a measure item call, set this to the height of item at m_choiceItem index. */
33 // Structure for relaying choice/list info.
36 wxPGChoices
* m_choices
;
40 /** @section propgrid_property_attributes wxPropertyGrid Property Attribute Identifiers
42 wxPGProperty::SetAttribute() and wxPropertyGridInterfaces::SetPropertyAttribute()
43 accept one of these as attribute name argument .
45 You can use strings instead of constants. However, some of these
46 constants are redefined to use cached strings which may reduce
47 your binary size by some amount.
52 /** Set default value for property.
54 #define wxPG_ATTR_DEFAULT_VALUE wxS("DefaultValue")
56 /** Universal, int or double. Minimum value for numeric properties.
58 #define wxPG_ATTR_MIN wxS("Min")
60 /** Universal, int or double. Maximum value for numeric properties.
62 #define wxPG_ATTR_MAX wxS("Max")
64 /** Universal, string. When set, will be shown as text after the displayed
65 text value. Alternatively, if third column is enabled, text will be shown
66 there (for any type of property).
68 #define wxPG_ATTR_UNITS wxS("Units")
70 /** Universal, string. When set, will be shown in property's value cell
71 when displayed value string is empty, or value is unspecified.
73 #define wxPG_ATTR_INLINE_HELP wxS("InlineHelp")
75 /** wxBoolProperty specific, int, default 0. When 1 sets bool property to
76 use checkbox instead of choice.
78 #define wxPG_BOOL_USE_CHECKBOX wxS("UseCheckbox")
80 /** wxBoolProperty specific, int, default 0. When 1 sets bool property value
81 to cycle on double click (instead of showing the popup listbox).
83 #define wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING wxS("UseDClickCycling")
85 /** wxFloatProperty (and similar) specific, int, default -1. Sets the (max) precision
86 used when floating point value is rendered as text. The default -1 means infinite
89 #define wxPG_FLOAT_PRECISION wxS("Precision")
91 /** The text will be echoed as asterisks (wxTE_PASSWORD will be passed to textctrl etc).
93 #define wxPG_STRING_PASSWORD wxS("Password")
95 /** Define base used by a wxUIntProperty. Valid constants are
96 wxPG_BASE_OCT, wxPG_BASE_DEC, wxPG_BASE_HEX and wxPG_BASE_HEXL
97 (lowercase characters).
99 #define wxPG_UINT_BASE wxS("Base")
101 /** Define prefix rendered to wxUIntProperty. Accepted constants
102 wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and wxPG_PREFIX_DOLLAR_SIGN.
103 <b>Note:</b> Only wxPG_PREFIX_NONE works with Decimal and Octal
106 #define wxPG_UINT_PREFIX wxS("Prefix")
108 /** wxFileProperty/wxImageFileProperty specific, wxChar*, default is detected/varies.
109 Sets the wildcard used in the triggered wxFileDialog. Format is the
112 #define wxPG_FILE_WILDCARD wxS("Wildcard")
114 /** wxFileProperty/wxImageFileProperty specific, int, default 1.
115 When 0, only the file name is shown (i.e. drive and directory are hidden).
117 #define wxPG_FILE_SHOW_FULL_PATH wxS("ShowFullPath")
119 /** Specific to wxFileProperty and derived properties, wxString, default empty.
120 If set, then the filename is shown relative to the given path string.
122 #define wxPG_FILE_SHOW_RELATIVE_PATH wxS("ShowRelativePath")
124 /** Specific to wxFileProperty and derived properties, wxString, default is empty.
125 Sets the initial path of where to look for files.
127 #define wxPG_FILE_INITIAL_PATH wxS("InitialPath")
129 /** Specific to wxFileProperty and derivatives, wxString, default is empty.
130 Sets a specific title for the dir dialog.
132 #define wxPG_FILE_DIALOG_TITLE wxS("DialogTitle")
134 /** Specific to wxDirProperty, wxString, default is empty.
135 Sets a specific message for the dir dialog.
137 #define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage")
139 /** Sets displayed date format for wxDateProperty.
141 #define wxPG_DATE_FORMAT wxS("DateFormat")
143 /** Sets wxDatePickerCtrl window style used with wxDateProperty. Default
144 is wxDP_DEFAULT | wxDP_SHOWCENTURY.
146 #define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
148 /** SpinCtrl editor, int or double. How much number changes when button is
149 pressed (or up/down on keybard).
151 #define wxPG_ATTR_SPINCTRL_STEP wxS("Step")
153 /** SpinCtrl editor, bool. If true, value wraps at Min/Max.
155 #define wxPG_ATTR_SPINCTRL_WRAP wxS("Wrap")
157 /** wxMultiChoiceProperty, int. If 0, no user strings allowed. If 1, user strings
158 appear before list strings. If 2, user strings appear after list string.
160 #define wxPG_ATTR_MULTICHOICE_USERSTRINGMODE wxS("UserStringMode")
162 /** wxColourProperty and its kind, int, default 1. Setting this attribute to 0 hides custom
163 colour from property's list of choices.
165 #define wxPG_COLOUR_ALLOW_CUSTOM wxS("AllowCustom")
167 /** First attribute id that is guaranteed not to be used built-in
170 //#define wxPG_USER_ATTRIBUTE 192
175 // -----------------------------------------------------------------------
177 /** @class wxPGProperty
179 wxPGProperty is base class for all wxPropertyGrid properties. In
180 sections below we cover few related topics.
182 @li @ref pgproperty_properties
183 @li @ref pgproperty_creating
185 @section pgproperty_properties Supplied Ready-to-use Property Classes
187 Here is a list and short description of supplied fully-functional
188 property classes. They are located in either props.h or advprops.h.
190 @li @ref wxArrayStringProperty
191 @li @ref wxBoolProperty
192 @li @ref wxColourProperty
193 @li @ref wxCursorProperty
194 @li @ref wxDateProperty
195 @li @ref wxDirProperty
196 @li @ref wxEditEnumProperty
197 @li @ref wxEnumProperty
198 @li @ref wxFileProperty
199 @li @ref wxFlagsProperty
200 @li @ref wxFloatProperty
201 @li @ref wxFontProperty
202 @li @ref wxImageFileProperty
203 @li @ref wxIntProperty
204 @li @ref wxLongStringProperty
205 @li @ref wxMultiChoiceProperty
206 @li @ref wxPropertyCategory
207 @li @ref wxStringProperty
208 @li @ref wxSystemColourProperty
209 @li @ref wxUIntProperty
211 @subsection wxPropertyCategory
213 Not an actual property per se, but a header for a group of properties.
214 Regardless inherits from wxPGProperty.
216 @subsection wxStringProperty
218 Simple string property. wxPG_STRING_PASSWORD attribute may be used
219 to echo value as asterisks and use wxTE_PASSWORD for wxTextCtrl.
222 * wxStringProperty has a special trait: if it has value of "<composed>",
223 and also has child properties, then its displayed value becomes
224 composition of child property values, similar as with wxFontProperty,
227 @subsection wxIntProperty
229 Like wxStringProperty, but converts text to a signed long integer.
230 wxIntProperty seamlessly supports 64-bit integers (ie. wxLongLong).
232 @subsection wxUIntProperty
234 Like wxIntProperty, but displays value as unsigned int. To set
235 the prefix used globally, manipulate wxPG_UINT_PREFIX string attribute.
236 To set the globally used base, manipulate wxPG_UINT_BASE int
237 attribute. Regardless of current prefix, understands (hex) values starting
238 with both "0x" and "$".
239 wxUIntProperty seamlessly supports 64-bit unsigned integers (ie. wxULongLong).
241 @subsection wxFloatProperty
243 Like wxStringProperty, but converts text to a double-precision floating point.
244 Default float-to-text precision is 6 decimals, but this can be changed
245 by modifying wxPG_FLOAT_PRECISION attribute.
247 @subsection wxBoolProperty
249 Represents a boolean value. wxChoice is used as editor control, by the
250 default. wxPG_BOOL_USE_CHECKBOX attribute can be set to true inorder to use
253 @subsection wxLongStringProperty
255 Like wxStringProperty, but has a button that triggers a small text editor
256 dialog. Note that in long string values, tabs are represented by "\t" and
259 @subsection wxDirProperty
261 Like wxLongStringProperty, but the button triggers dir selector instead.
262 Supported properties (all with string value): wxPG_DIR_DIALOG_MESSAGE.
264 @subsection wxFileProperty
266 Like wxLongStringProperty, but the button triggers file selector instead.
267 Default wildcard is "All files..." but this can be changed by setting
268 wxPG_FILE_WILDCARD attribute (see wxFileDialog for format details).
269 Attribute wxPG_FILE_SHOW_FULL_PATH can be set to false inorder to show
270 only the filename, not the entire path.
272 @subsection wxEnumProperty
274 Represents a single selection from a list of choices -
275 wxOwnerDrawnComboBox is used to edit the value.
277 @subsection wxFlagsProperty
279 Represents a bit set that fits in a long integer. wxBoolProperty sub-properties
280 are created for editing individual bits. Textctrl is created to manually edit
281 the flags as a text; a continous sequence of spaces, commas and semicolons
282 is considered as a flag id separator.
283 <b>Note: </b> When changing "choices" (ie. flag labels) of wxFlagsProperty, you
284 will need to use SetPropertyChoices - otherwise they will not get updated properly.
286 @subsection wxArrayStringProperty
288 Allows editing of a list of strings in wxTextCtrl and in a separate dialog.
290 @subsection wxDateProperty
292 wxDateTime property. Default editor is DatePickerCtrl, altough TextCtrl
293 should work as well. wxPG_DATE_FORMAT attribute can be used to change
294 string wxDateTime::Format uses (altough default is recommended as it is
295 locale-dependant), and wxPG_DATE_PICKER_STYLE allows changing window
296 style given to DatePickerCtrl (default is wxDP_DEFAULT|wxDP_SHOWCENTURY).
298 @subsection wxEditEnumProperty
300 Represents a string that can be freely edited or selected from list of choices -
301 custom combobox control is used to edit the value.
303 @subsection wxMultiChoiceProperty
305 Allows editing a multiple selection from a list of strings. This is
306 property is pretty much built around concept of wxMultiChoiceDialog.
307 It uses wxArrayString value.
309 @subsection wxImageFileProperty
311 Like wxFileProperty, but has thumbnail of the image in front of
312 the filename and autogenerates wildcard from available image handlers.
314 @subsection wxColourProperty
316 <b>Useful alternate editor:</b> Choice.
318 Represents wxColour. wxButton is used to trigger a colour picker dialog.
320 @subsection wxFontProperty
322 Represents wxFont. Various sub-properties are used to edit individual
325 @subsection wxSystemColourProperty
327 Represents wxColour and a system colour index. wxChoice is used to edit
328 the value. Drop-down list has color images. Note that value type
329 is wxColourPropertyValue instead of wxColour.
331 class wxColourPropertyValue : public wxObject
334 // An integer value relating to the colour, and which exact
335 // meaning depends on the property with which it is used.
337 // For wxSystemColourProperty:
338 // Any of wxSYS_COLOUR_XXX, or any web-colour ( use wxPG_TO_WEB_COLOUR
339 // macro - (currently unsupported) ), or wxPG_COLOUR_CUSTOM.
342 // Resulting colour. Should be correct regardless of type.
347 @subsection wxCursorProperty
349 Represents a wxCursor. wxChoice is used to edit the value.
350 Drop-down list has cursor images under some (wxMSW) platforms.
353 @section pgproperty_creating Creating Custom Properties
355 New properties can be created by subclassing wxPGProperty or one
356 of the provided property classes, and (re)implementing necessary
357 member functions. Below, each virtual member function has ample
358 documentation about its purpose and any odd details which to keep
361 Here is a very simple 'template' code:
364 class MyProperty : public wxPGProperty
367 // All arguments of ctor must have a default value -
368 // use wxPG_LABEL for label and name
369 MyProperty( const wxString& label = wxPG_LABEL,
370 const wxString& name = wxPG_LABEL,
371 const wxString& value = wxEmptyString )
373 // m_value is wxVariant
377 virtual ~MyProperty() { }
379 const wxPGEditor* DoGetEditorClass() const
381 // Determines editor used by property.
382 // You can replace 'TextCtrl' below with any of these
383 // builtin-in property editor identifiers: Choice, ComboBox,
384 // TextCtrlAndButton, ChoiceAndButton, CheckBox, SpinCtrl,
386 return wxPGEditor_TextCtrl;
389 virtual wxString GetValueAsString( int argFlags ) const
391 // TODO: Return property value in string format
394 virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags )
396 // TODO: Adapt string to property value.
403 Since wxPGProperty derives from wxObject, you can use standard
404 DECLARE_DYNAMIC_CLASS and IMPLEMENT_DYNAMIC_CLASS macros. From the
405 above example they were omitted for sake of simplicity, and besides,
406 they are only really needed if you need to use wxRTTI with your
409 You can change the 'value type' of a property by simply assigning different type
410 of variant with SetValue. <b>It is mandatory to implement wxVariantData class
411 for all data types used as property values.</b> Also, it is further recommended
412 to derive your class from wxPGVariantData, like this:
416 // (replace DECL with required data declaration, wxEMPTY_PARAMETER_VALUE if none)
417 WX_PG_DECLARE_VARIANT_DATA(wxPGVariantMyDataClass, MyDataClass, DECL)
420 WX_PG_IMPLEMENT_VARIANT_DATA(wxPGVariantMyDataClass, MyDataClass)
426 class wxPGProperty
: public wxObject
429 typedef wxUint32 FlagType
;
431 /** Basic constructor.
436 Non-abstract property classes should have constructor of this style:
440 // If T is a class, then it should be a constant reference
441 // (e.g. const T& ) instead.
442 MyProperty( const wxString& label, const wxString& name, T value )
445 // Generally recommended way to set the initial value
446 // (as it should work in pretty much 100% of cases).
451 // If has private child properties then create them here. For example:
452 // AddChild( new wxStringProperty( "Subprop 1", wxPG_LABEL, value.GetSubProp1() ) );
457 wxPGProperty( const wxString
& label
, const wxString
& name
);
459 /** Virtual destructor. It is customary for derived properties to implement this. */
460 virtual ~wxPGProperty();
462 /** This virtual function is called after m_value has been set.
465 - If m_value was set to Null variant (ie. unspecified value), OnSetValue()
467 - m_value may be of any variant type. Typically properties internally support only
468 one variant type, and as such OnSetValue() provides a good opportunity to convert
469 supported values into internal type.
470 - Default implementation does nothing.
472 virtual void OnSetValue();
474 /** Override this to return something else than m_value as the value.
476 virtual wxVariant
DoGetValue() const { return m_value
; }
478 /** Implement this function in derived class to check the value.
479 Return true if it is ok. Returning false prevents property change events
483 - Default implementation always returns true.
485 virtual bool ValidateValue( wxVariant
& value
, wxPGValidationInfo
& validationInfo
) const;
487 /** Converts 'text' into proper value 'variant'. Returns true if new (different than
488 m_value) value could be interpreted from the text.
490 If wxPG_FULL_VALUE is set, returns complete, storable value instead of displayable
491 one (they may be different).
492 If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of composite
493 property string value (as generated by GetValueAsString() called with this same
497 Default implementation converts semicolon delimited tokens into child values. Only
498 works for properties with children.
500 virtual bool StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
= 0 ) const;
502 /** Converts 'number' (including choice selection) into proper value 'variant'.
503 Returns true if new (different than m_value) value could be interpreted from the integer.
505 If wxPG_FULL_VALUE is set, returns complete, storable value instead of displayable one.
508 - If property is not supposed to use choice or spinctrl or other editor
509 with int-based value, it is not necessary to implement this method.
510 - Default implementation simply assign given int to m_value.
511 - If property uses choice control, and displays a dialog on some choice items,
512 then it is preferred to display that dialog in IntToValue instead of OnEvent.
514 virtual bool IntToValue( wxVariant
& value
, int number
, int argFlags
= 0 ) const;
518 /** Returns text representation of property's value.
521 If wxPG_FULL_VALUE is set, returns complete, storable string value instead of displayable.
522 If wxPG_EDITABLE_VALUE is set, returns string value that must be editable in textctrl.
523 If wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to display
524 as a part of composite property string value.
527 Default implementation returns string composed from text representations of
530 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
532 /** Converts string to a value, and if successful, calls SetValue() on it.
533 Default behavior is to do nothing.
535 String to get the value from.
537 true if value was changed.
539 bool SetValueFromString( const wxString
& text
, int flags
= 0 );
541 /** Converts integer to a value, and if succesful, calls SetValue() on it.
542 Default behavior is to do nothing.
544 Int to get the value from.
546 If has wxPG_FULL_VALUE, then the value given is a actual value and not an index.
548 True if value was changed.
550 bool SetValueFromInt( long value
, int flags
= 0 );
552 /** Returns size of the custom painted image in front of property. This method
553 must be overridden to return non-default value if OnCustomPaint is to be
556 Normally -1, but can be an index to the property's list of items.
558 - Default behavior is to return wxSize(0,0), which means no image.
559 - Default image width or height is indicated with dimension -1.
560 - You can also return wxPG_DEFAULT_IMAGE_SIZE which equals wxSize(-1, -1).
562 virtual wxSize
OnMeasureImage( int item
= -1 ) const;
564 /** Events received by editor widgets are processed here. Note that editor class
565 usually processes most events. Some, such as button press events of
566 TextCtrlAndButton class, can be handled here. Also, if custom handling
567 for regular events is desired, then that can also be done (for example,
568 wxSystemColourProperty custom handles wxEVT_COMMAND_CHOICE_SELECTED
569 to display colour picker dialog when 'custom' selection is made).
571 If the event causes value to be changed, SetValueInEvent()
572 should be called to set the new value.
577 Should return true if any changes in value should be reported.
579 - If property uses choice control, and displays a dialog on some choice items,
580 then it is preferred to display that dialog in IntToValue instead of OnEvent.
582 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* wnd_primary
, wxEvent
& event
);
584 /** Called after value of a child property has been altered. Note that this function is
585 usually called at the time that value of this property, or given child property, is
586 still pending for change.
588 Sample pseudo-code implementation:
591 void MyProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const
593 // Acquire reference to actual type of data stored in variant
594 // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros were used to create
595 // the variant class).
596 T& data = TFromVariant(thisValue);
598 // Copy childValue into data.
599 switch ( childIndex )
602 data.SetSubProp1( childvalue.GetLong() );
605 data.SetSubProp2( childvalue.GetString() );
613 Value of this property, that should be altered.
615 Index of child changed (you can use Item(childIndex) to get).
617 Value of the child property.
619 virtual void ChildChanged( wxVariant
& thisValue
, int childIndex
, wxVariant
& childValue
) const;
621 /** Returns pointer to an instance of used editor.
623 virtual const wxPGEditor
* DoGetEditorClass() const;
625 /** Returns pointer to the wxValidator that should be used
626 with the editor of this property (NULL for no validator).
627 Setting validator explicitly via SetPropertyValidator
630 In most situations, code like this should work well
631 (macros are used to maintain one actual validator instance,
632 so on the second call the function exits within the first
637 wxValidator* wxMyPropertyClass::DoGetValidator () const
639 WX_PG_DOGETVALIDATOR_ENTRY()
641 wxMyValidator* validator = new wxMyValidator(...);
643 ... prepare validator...
645 WX_PG_DOGETVALIDATOR_EXIT(validator)
651 You can get common filename validator by returning
652 wxFileProperty::GetClassValidator(). wxDirProperty,
653 for example, uses it.
655 virtual wxValidator
* DoGetValidator () const;
657 /** Returns current value's index to the choice control. May also return,
658 through pointer arguments, strings that should be inserted to that control.
659 Irrelevant to classes which do not employ wxPGEditor_Choice or similar.
661 - If returns NULL in choiceinfo.m_choices, then this class must be
662 derived from wxBaseEnumProperty.
663 - Must be able to cope situation where property's set of choices is
666 virtual int GetChoiceInfo( wxPGChoiceInfo
* choiceinfo
);
668 /** Override to paint an image in front of the property value text or drop-down
669 list item (but only if wxPGProperty::OnMeasureImage is overridden as well).
671 If property's OnMeasureImage() returns size that has height != 0 but less than
672 row height ( < 0 has special meanings), wxPropertyGrid calls this method to
673 draw a custom image in a limited area in front of the editor control or
674 value text/graphics, and if control has drop-down list, then the image is
675 drawn there as well (even in the case OnMeasureImage() returned higher height
678 NOTE: Following applies when OnMeasureImage() returns a "flexible" height (
679 using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable height items:
680 If rect.x is < 0, then this is a measure item call, which means that
681 dc is invalid and only thing that should be done is to set paintdata.m_drawnHeight
682 to the height of the image of item at index paintdata.m_choiceItem. This call
683 may be done even as often as once every drop-down popup show.
688 Box reserved for custom graphics. Includes surrounding rectangle, if any.
689 If x is < 0, then this is a measure item call (see above).
691 wxPGPaintData structure with much useful data.
694 - You can actually exceed rect width, but if you do so then paintdata.m_drawnWidth
695 must be set to the full width drawn in pixels.
696 - Due to technical reasons, rect's height will be default even if custom height
697 was reported during measure call.
698 - Brush is guaranteed to be default background colour. It has been already used to
699 clear the background of area being painted. It can be modified.
700 - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper colour) pen for
701 drawing framing rectangle. It can be changed as well.
703 @see GetValueAsString()
705 virtual void OnCustomPaint( wxDC
& dc
, const wxRect
& rect
, wxPGPaintData
& paintdata
);
707 /** Returns used wxPGCellRenderer instance for given property column (label=0, value=1).
709 Default implementation returns editor's renderer for all columns.
711 virtual wxPGCellRenderer
* GetCellRenderer( int column
) const;
713 /** Refresh values of child properties. Automatically called after value is set.
715 virtual void RefreshChildren();
717 /** Special handling for attributes of this property.
719 If returns false, then the attribute will be automatically stored in
722 Default implementation simply returns false.
724 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
726 /** Returns value of an attribute.
728 Override if custom handling of attributes is needed.
730 Default implementation simply return NULL variant.
732 virtual wxVariant
DoGetAttribute( const wxString
& name
) const;
734 /** Returns instance of a new wxPGEditorDialogAdapter instance, which is
735 used when user presses the (optional) button next to the editor control;
737 Default implementation returns NULL (ie. no action is generated when
740 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
742 /** Adds entry to property's wxPGChoices and editor control (if it is active).
743 Returns index of item added.
745 int AppendChoice( const wxString
& label
, int value
= wxPG_INVALID_VALUE
)
747 return InsertChoice(label
,-1,value
);
750 /** Returns wxPGCell of given column, NULL if none. If valid
751 object is returned, caller will gain its ownership.
753 wxPGCell
* AcquireCell( unsigned int column
)
755 if ( column
>= m_cells
.size() )
758 wxPGCell
* cell
= (wxPGCell
*) m_cells
[column
];
759 m_cells
[column
] = NULL
;
763 /** Returns true if children of this property are component values (for instance,
764 points size, face name, and is_underlined are component values of a font).
766 bool AreChildrenComponents() const
768 if ( m_flags
& (wxPG_PROP_COMPOSED_VALUE
|wxPG_PROP_AGGREGATE
) )
774 /** Removes entry from property's wxPGChoices and editor control (if it is active).
776 If selected item is deleted, then the value is set to unspecified.
778 void DeleteChoice( int index
);
780 /** Call to enable or disable usage of common value (integer value that can be selected for
781 properties instead of their normal values) for this property.
783 Common values are disabled by the default for all properties.
785 void EnableCommonValue( bool enable
= true )
787 if ( enable
) SetFlag( wxPG_PROP_USES_COMMON_VALUE
);
788 else ClearFlag( wxPG_PROP_USES_COMMON_VALUE
);
791 /** Composes text from values of child properties. */
792 void GenerateComposedValue( wxString
& text
, int argFlags
= 0 ) const;
794 /** Returns property's label. */
795 const wxString
& GetLabel() const { return m_label
; }
797 /** Returns property's name with all (non-category, non-root) parents. */
798 wxString
GetName() const;
800 /** Returns property's base name (ie. parent's name is not added in any case) */
801 const wxString
& GetBaseName() const { return m_name
; }
803 wxPGChoices
& GetChoices();
805 const wxPGChoices
& GetChoices() const;
807 const wxPGChoiceEntry
* GetCurrentChoice() const;
809 /** Returns coordinate to the top y of the property. Note that the
810 position of scrollbars is not taken into account.
814 wxVariant
GetValue() const
819 /** Returns reference to the internal stored value. GetValue is preferred
820 way to get the actual value, since GetValueRef ignores DoGetValue,
821 which may override stored value.
823 wxVariant
& GetValueRef()
828 const wxVariant
& GetValueRef() const
833 /** Same as GetValueAsString, except takes common value into account.
835 wxString
GetValueString( int argFlags
= 0 ) const;
837 void UpdateControl( wxWindow
* primary
);
839 /** Returns wxPGCell of given column, NULL if none. wxPGProperty
840 will retain ownership of the cell object.
842 wxPGCell
* GetCell( unsigned int column
) const
844 if ( column
>= m_cells
.size() )
847 return (wxPGCell
*) m_cells
[column
];
850 unsigned int GetChoiceCount() const;
852 wxString
GetChoiceString( unsigned int index
);
854 /** Return number of displayed common values for this property.
856 int GetDisplayedCommonValueCount() const;
858 wxString
GetDisplayedString() const
860 return GetValueString(0);
863 /** Returns property grid where property lies. */
864 wxPropertyGrid
* GetGrid() const;
866 /** Returns owner wxPropertyGrid, but only if one is currently on a page
867 displaying this property. */
868 wxPropertyGrid
* GetGridIfDisplayed() const;
870 /** Returns highest level non-category, non-root parent. Useful when you
871 have nested wxCustomProperties/wxParentProperties.
873 Thus, if immediate parent is root or category, this will return the
876 wxPGProperty
* GetMainParent() const;
878 /** Return parent of property */
879 wxPGProperty
* GetParent() const { return m_parent
; }
881 /** Returns true if property has editable wxTextCtrl when selected.
884 Altough disabled properties do not displayed editor, they still
885 return True here as being disabled is considered a temporary
886 condition (unlike being read-only or having limited editing enabled).
888 bool IsTextEditable() const;
890 bool IsValueUnspecified() const
892 return m_value
.IsNull();
895 FlagType
HasFlag( FlagType flag
) const
897 return ( m_flags
& flag
);
900 /** Returns comma-delimited string of property attributes.
902 const wxPGAttributeStorage
& GetAttributes() const
907 /** Returns m_attributes as list wxVariant.
909 wxVariant
GetAttributesAsList() const;
911 FlagType
GetFlags() const
916 const wxPGEditor
* GetEditorClass() const;
918 wxString
GetValueType() const
920 return m_value
.GetType();
923 /** Returns editor used for given column. NULL for no editor.
925 const wxPGEditor
* GetColumnEditor( int column
) const
928 return GetEditorClass();
933 /** Returns common value selected for this property. -1 for none.
935 int GetCommonValue() const
937 return m_commonValue
;
940 /** Returns true if property has even one visible child.
942 bool HasVisibleChildren() const;
944 /** Adds entry to property's wxPGChoices and editor control (if it is active).
945 Returns index of item added.
947 int InsertChoice( const wxString
& label
, int index
, int value
= wxPG_INVALID_VALUE
);
949 /** Returns true if this property is actually a wxPropertyCategory.
951 bool IsCategory() const { return HasFlag(wxPG_PROP_CATEGORY
)?true:false; }
953 /** Returns true if this property is actually a wxRootProperty.
955 bool IsRoot() const { return (m_parent
== NULL
); }
957 /** Returns true if this is a sub-property. */
958 bool IsSubProperty() const
960 wxPGProperty
* parent
= (wxPGProperty
*)m_parent
;
961 if ( parent
&& !parent
->IsCategory() )
966 /** Returns last visible sub-property, recursively.
968 const wxPGProperty
* GetLastVisibleSubItem() const;
970 wxVariant
GetDefaultValue() const;
972 int GetMaxLength() const
974 return (int) m_maxLen
;
977 /** Determines, recursively, if all children are not unspecified. Takes values in given list into account.
979 bool AreAllChildrenSpecified( wxVariant
* pendingList
= NULL
) const;
981 /** Updates composed values of parent non-category properties, recursively.
982 Returns topmost property updated.
985 - Must not call SetValue() (as can be called in it).
987 wxPGProperty
* UpdateParentValues();
989 /** Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
991 FlagType
UsesAutoUnspecified() const
993 return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED
);
996 wxBitmap
* GetValueImage() const
998 return m_valueBitmap
;
1001 wxVariant
GetAttribute( const wxString
& name
) const;
1003 /** Returns named attribute, as string, if found. Otherwise defVal is returned.
1005 wxString
GetAttribute( const wxString
& name
, const wxString
& defVal
) const;
1007 /** Returns named attribute, as long, if found. Otherwise defVal is returned.
1009 long GetAttributeAsLong( const wxString
& name
, long defVal
) const;
1011 /** Returns named attribute, as double, if found. Otherwise defVal is returned.
1013 double GetAttributeAsDouble( const wxString
& name
, double defVal
) const;
1015 inline unsigned int GetArrIndex() const { return m_arrIndex
; }
1017 inline unsigned int GetDepth() const { return (unsigned int)m_depth
; }
1019 /** Gets flags as a'|' delimited string. Note that flag names are not
1020 prepended with 'wxPG_PROP_'.
1022 String will only be made to include flags combined by this parameter.
1024 wxString
GetFlagsAsString( FlagType flagsMask
) const;
1026 /** Returns position in parent's array. */
1027 unsigned int GetIndexInParent() const
1029 return (unsigned int)m_arrIndex
;
1032 /** Hides or reveals the property.
1034 true for hide, false for reveal.
1036 By default changes are applied recursively. Set this paramter wxPG_DONT_RECURSE to prevent this.
1038 inline bool Hide( bool hide
, int flags
= wxPG_RECURSE
);
1040 bool IsExpanded() const { return (!(m_flags
& wxPG_PROP_COLLAPSED
) && GetChildCount()); }
1042 /** Returns true if all parents expanded.
1044 bool IsVisible() const;
1046 bool IsEnabled() const
1048 return ( m_flags
& wxPG_PROP_DISABLED
) ? false : true;
1051 /** If property's editor is created this forces its recreation. Useful
1052 in SetAttribute etc. Returns true if actually did anything.
1054 bool RecreateEditor();
1056 /** If property's editor is active, then update it's value.
1058 void RefreshEditor();
1060 /** Sets an attribute for this property.
1062 Text identifier of attribute. See @ref propgrid_property_attributes.
1066 void SetAttribute( const wxString
& name
, wxVariant value
);
1068 void SetAttributes( const wxPGAttributeStorage
& attributes
);
1070 /** Sets editor for a property.
1073 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1074 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full list).
1076 For custom editors, use pointer you received from wxPropertyGrid::RegisterEditorClass().
1078 void SetEditor( const wxPGEditor
* editor
)
1080 m_customEditor
= editor
;
1083 /** Sets editor for a property.
1085 inline void SetEditor( const wxString
& editorName
);
1087 /** Sets cell information for given column.
1089 Note that the property takes ownership of given wxPGCell instance.
1091 void SetCell( int column
, wxPGCell
* cellObj
);
1093 /** Changes value of a property with choices, but only
1094 works if the value type is long or string. */
1095 void SetChoiceSelection( int newValue
, const wxPGChoiceInfo
& choiceInfo
);
1097 /** Sets common value selected for this property. -1 for none.
1099 void SetCommonValue( int commonValue
)
1101 m_commonValue
= commonValue
;
1104 /** Sets flags from a '|' delimited string. Note that flag names are not
1105 prepended with 'wxPG_PROP_'.
1107 void SetFlagsFromString( const wxString
& str
);
1109 /** Sets property's "is it modified?" flag. Affects children recursively.
1111 void SetModifiedStatus( bool modified
)
1113 SetFlagRecursively(wxPG_PROP_MODIFIED
, modified
);
1116 /** Call in OnEvent(), OnButtonClick() etc. to change the property value
1117 based on user input.
1120 This method is const since it doesn't actually modify value, but posts
1121 given variant as pending value, stored in wxPropertyGrid.
1123 void SetValueInEvent( wxVariant value
) const;
1125 /** Call this to set value of the property. Unlike methods in wxPropertyGrid,
1126 this does not automatically update the display.
1129 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run through
1130 validation process and send property change event.
1132 If you need to change property value in event, based on user input, use
1133 SetValueInEvent() instead.
1136 Pointer to list variant that contains child values. Used to indicate
1137 which children should be marked as modified.
1139 Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR).
1141 void SetValue( wxVariant value
, wxVariant
* pList
= NULL
, int flags
= 0 );
1143 /** Set wxBitmap in front of the value. This bitmap may be ignored
1144 by custom cell renderers.
1146 void SetValueImage( wxBitmap
& bmp
);
1148 /** If property has choices and they are not yet exclusive, new such copy
1149 of them will be created.
1151 void SetChoicesExclusive();
1153 void SetExpanded( bool expanded
)
1155 if ( !expanded
) m_flags
|= wxPG_PROP_COLLAPSED
;
1156 else m_flags
&= ~wxPG_PROP_COLLAPSED
;
1159 void SetFlag( FlagType flag
) { m_flags
|= flag
; }
1161 void SetFlagRecursively( FlagType flag
, bool set
);
1163 void SetHelpString( const wxString
& helpString
)
1165 m_helpString
= helpString
;
1168 /** Sets property's label.
1171 - Properties under same parent may have same labels. However,
1172 property names must still remain unique.
1174 void SetLabel( const wxString
& label
) { m_label
= label
; }
1176 inline void SetName( const wxString
& newName
);
1178 void SetValueToUnspecified()
1180 wxVariant val
; // Create NULL variant
1184 /** Sets wxValidator for a property*/
1185 void SetValidator( const wxValidator
& validator
)
1187 m_validator
= wxDynamicCast(validator
.Clone(),wxValidator
);
1190 /** Gets assignable version of property's validator. */
1191 wxValidator
* GetValidator() const
1195 return DoGetValidator();
1198 /** Updates property value in case there were last minute
1199 changes. If value was unspecified, it will be set to default.
1200 Use only for properties that have TextCtrl-based editor.
1202 If you have code similar to
1204 // Update the value in case of last minute changes
1205 if ( primary && propgrid->IsEditorsValueModified() )
1206 GetEditorClass()->CopyValueFromControl( this, primary );
1208 in wxPGProperty::OnEvent wxEVT_COMMAND_BUTTON_CLICKED handler,
1209 then replace it with call to this method.
1211 True if value changed.
1213 bool PrepareValueForDialogEditing( wxPropertyGrid
* propgrid
);
1215 /** Returns client data (void*) of a property.
1217 void* GetClientData() const
1219 return m_clientData
;
1222 /** Sets client data (void*) of a property.
1224 This untyped client data has to be deleted manually.
1226 void SetClientData( void* clientData
)
1228 m_clientData
= clientData
;
1231 /** Returns client object of a property.
1233 void SetClientObject(wxClientData
* clientObject
)
1235 delete m_clientObject
;
1236 m_clientObject
= clientObject
;
1239 /** Sets managed client object of a property.
1241 wxClientData
*GetClientObject() const { return m_clientObject
; }
1243 /** Sets new set of choices for property.
1246 This operation clears the property value.
1248 bool SetChoices( wxPGChoices
& choices
);
1250 /** Sets new set of choices for property.
1252 inline bool SetChoices( const wxArrayString
& labels
,
1253 const wxArrayInt
& values
= wxArrayInt() );
1255 /** Set max length of text in text editor.
1257 inline bool SetMaxLength( int maxLen
);
1259 /** Call with 'false' in OnSetValue to cancel value changes after all
1260 (ie. cancel 'true' returned by StringToValue() or IntToValue()).
1262 void SetWasModified( bool set
= true )
1264 if ( set
) m_flags
|= wxPG_PROP_WAS_MODIFIED
;
1265 else m_flags
&= ~wxPG_PROP_WAS_MODIFIED
;
1268 const wxString
& GetHelpString() const
1270 return m_helpString
;
1273 void ClearFlag( FlagType flag
) { m_flags
&= ~(flag
); }
1275 // Use, for example, to detect if item is inside collapsed section.
1276 bool IsSomeParent( wxPGProperty
* candidate_parent
) const;
1278 /** Adapts list variant into proper value using consequtive ChildChanged-calls.
1280 void AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const;
1282 /** This is used by properties that have fixed sub-properties. */
1283 void AddChild( wxPGProperty
* prop
);
1285 /** Returns height of children, recursively, and
1286 by taking expanded/collapsed status into account.
1288 iMax is used when finding property y-positions.
1290 int GetChildrenHeight( int lh
, int iMax
= -1 ) const;
1292 /** Returns number of child properties */
1293 unsigned int GetChildCount() const { return m_children
.GetCount(); }
1295 /** Returns sub-property at index i. */
1296 wxPGProperty
* Item( size_t i
) const { return (wxPGProperty
*)m_children
.Item(i
); }
1298 /** Returns last sub-property.
1300 wxPGProperty
* Last() const { return (wxPGProperty
*)m_children
.Last(); }
1302 /** Returns index of given sub-property. */
1303 int Index( const wxPGProperty
* p
) const { return m_children
.Index((wxPGProperty
*)p
); }
1305 /** Deletes all sub-properties. */
1308 // Puts correct indexes to children
1309 void FixIndexesOfChildren( size_t starthere
= 0 );
1311 wxPGProperty
* GetItemAtY( unsigned int y
, unsigned int lh
, unsigned int* nextItemY
) const;
1313 /** Returns (direct) child property with given name (or NULL if not found).
1315 wxPGProperty
* GetPropertyByName( const wxString
& name
) const;
1319 /** @class wxPGChoices
1321 Helper class for managing choices of wxPropertyGrid properties.
1322 Each entry can have label, value, bitmap, text colour, and background colour.
1324 @library{wxpropgrid}
1327 class WXDLLIMPEXP_PROPGRID wxPGChoices
1330 typedef long ValArrItem
;
1332 /** Default constructor. */
1338 /** Copy constructor. */
1339 wxPGChoices( const wxPGChoices
& a
)
1341 if ( a
.m_data
!= wxPGChoicesEmptyData
)
1344 m_data
->m_refCount
++;
1349 wxPGChoices( const wxChar
** labels
, const long* values
= NULL
)
1356 wxPGChoices( const wxArrayString
& labels
, const wxArrayInt
& values
= wxArrayInt() )
1362 /** Simple interface constructor. */
1363 wxPGChoices( wxPGChoicesData
* data
)
1376 /** Adds to current. If did not have own copies, creates them now. If was empty,
1377 identical to set except that creates copies.
1379 void Add( const wxChar
** labels
, const ValArrItem
* values
= NULL
);
1381 /** Version that works with wxArrayString. */
1382 void Add( const wxArrayString
& arr
, const ValArrItem
* values
= NULL
);
1384 /** Version that works with wxArrayString and wxArrayInt. */
1385 void Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
);
1387 /** Adds single item. */
1388 wxPGChoiceEntry
& Add( const wxString
& label
, int value
= wxPG_INVALID_VALUE
);
1390 /** Adds a single item, with bitmap. */
1391 wxPGChoiceEntry
& Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
= wxPG_INVALID_VALUE
);
1393 /** Adds a single item with full entry information. */
1394 wxPGChoiceEntry
& Add( const wxPGChoiceEntry
& entry
)
1396 return Insert(entry
, -1);
1399 /** Adds single item. */
1400 wxPGChoiceEntry
& AddAsSorted( const wxString
& label
, int value
= wxPG_INVALID_VALUE
);
1402 void Assign( const wxPGChoices
& a
)
1404 AssignData(a
.m_data
);
1407 void AssignData( wxPGChoicesData
* data
);
1409 /** Delete all choices. */
1412 if ( m_data
!= wxPGChoicesEmptyData
)
1418 if ( m_data
== wxPGChoicesEmptyData
)
1419 m_data
= new wxPGChoicesData();
1422 /** Gets a unsigned number identifying this list. */
1423 wxPGChoicesId
GetId() const { return (wxPGChoicesId
) m_data
; };
1425 const wxString
& GetLabel( size_t ind
) const
1427 wxASSERT( ind
>= 0 && ind
< GetCount() );
1428 return Item(ind
).GetText();
1431 size_t GetCount () const
1433 wxASSERT_MSG( m_data
,
1434 wxT("When checking if wxPGChoices is valid, use IsOk() instead of GetCount()") );
1435 return m_data
->GetCount();
1438 int GetValue( size_t ind
) const { return Item(ind
).GetValue(); }
1440 /** Returns array of values matching the given strings. Unmatching strings
1441 result in wxPG_INVALID_VALUE entry in array.
1443 wxArrayInt
GetValuesForStrings( const wxArrayString
& strings
) const;
1445 /** Returns array of indices matching given strings. Unmatching strings
1446 are added to 'unmatched', if not NULL.
1448 wxArrayInt
GetIndicesForStrings( const wxArrayString
& strings
, wxArrayString
* unmatched
= NULL
) const;
1450 /** Returns true if choices in general are likely to have values
1451 (depens on that all entries have values or none has)
1453 bool HasValues() const;
1455 bool HasValue( unsigned int i
) const { return (m_data
->GetCount() > i
&& m_data
->Item(i
)->HasValue()); }
1457 int Index( const wxString
& str
) const;
1458 int Index( int val
) const;
1460 /** Inserts single item. */
1461 wxPGChoiceEntry
& Insert( const wxString
& label
, int index
, int value
= wxPG_INVALID_VALUE
);
1463 /** Inserts a single item with full entry information. */
1464 wxPGChoiceEntry
& Insert( const wxPGChoiceEntry
& entry
, int index
);
1466 /** Returns false if this is a constant empty set of choices,
1467 which should not be modified.
1471 return ( m_data
!= wxPGChoicesEmptyData
);
1474 const wxPGChoiceEntry
& Item( unsigned int i
) const
1477 return *m_data
->Item(i
);
1480 wxPGChoiceEntry
& Item( unsigned int i
)
1483 return *m_data
->Item(i
);
1486 /** Removes count items starting at position nIndex. */
1487 void RemoveAt(size_t nIndex
, size_t count
= 1);
1489 /** Does not create copies for itself. */
1490 void Set( const wxChar
** labels
, const long* values
= NULL
)
1496 /** Version that works with wxArrayString.
1497 TODO: Deprecate this.
1499 void Set( wxArrayString
& arr
, const long* values
= (const long*) NULL
)
1505 /** Version that works with wxArrayString and wxArrayInt. */
1506 void Set( const wxArrayString
& labels
, const wxArrayInt
& values
= wxArrayInt() )
1515 // Creates exclusive copy of current choices
1518 if ( m_data
->m_refCount
!= 1 )
1520 wxPGChoicesData
* data
= new wxPGChoicesData();
1521 data
->CopyDataFrom(m_data
);
1527 // Returns data, increases refcount.
1528 wxPGChoicesData
* GetData()
1530 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
1531 m_data
->m_refCount
++;
1535 // Returns plain data ptr - no refcounting stuff is done.
1536 wxPGChoicesData
* GetDataPtr() const { return m_data
; }
1538 // Changes ownership of data to you.
1539 wxPGChoicesData
* ExtractData()
1541 wxPGChoicesData
* data
= m_data
;
1542 m_data
= wxPGChoicesEmptyData
;
1546 wxArrayString
GetLabels() const;
1548 void operator= (const wxPGChoices
& a
)
1550 AssignData(a
.m_data
);
1553 wxPGChoiceEntry
& operator[](unsigned int i
)
1558 const wxPGChoiceEntry
& operator[](unsigned int i
) const
1564 // -----------------------------------------------------------------------