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
410 type of variant with SetValue. <b>It is mandatory to implement
411 wxVariantData class for all data types used as property values.</b>
412 You can use macros declared in wxPropertyGrid headers. For instance:
416 // (If you need to have export declaration, use version of macros
417 // with _EXPORTED postfix)
418 WX_PG_DECLARE_VARIANT_DATA(MyDataClass)
421 WX_PG_IMPLEMENT_VARIANT_DATA(MyDataClass)
423 // Or, if you don't have valid == operator:
424 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(MyDataClass)
430 class wxPGProperty
: public wxObject
433 typedef wxUint32 FlagType
;
435 /** Basic constructor.
440 Non-abstract property classes should have constructor of this style:
444 // If T is a class, then it should be a constant reference
445 // (e.g. const T& ) instead.
446 MyProperty( const wxString& label, const wxString& name, T value )
449 // Generally recommended way to set the initial value
450 // (as it should work in pretty much 100% of cases).
455 // If has private child properties then create them here. For example:
456 // AddChild( new wxStringProperty( "Subprop 1", wxPG_LABEL, value.GetSubProp1() ) );
461 wxPGProperty( const wxString
& label
, const wxString
& name
);
463 /** Virtual destructor. It is customary for derived properties to implement this. */
464 virtual ~wxPGProperty();
466 /** This virtual function is called after m_value has been set.
469 - If m_value was set to Null variant (ie. unspecified value), OnSetValue()
471 - m_value may be of any variant type. Typically properties internally support only
472 one variant type, and as such OnSetValue() provides a good opportunity to convert
473 supported values into internal type.
474 - Default implementation does nothing.
476 virtual void OnSetValue();
478 /** Override this to return something else than m_value as the value.
480 virtual wxVariant
DoGetValue() const { return m_value
; }
482 /** Implement this function in derived class to check the value.
483 Return true if it is ok. Returning false prevents property change events
487 - Default implementation always returns true.
489 virtual bool ValidateValue( wxVariant
& value
, wxPGValidationInfo
& validationInfo
) const;
491 /** Converts 'text' into proper value 'variant'. Returns true if new (different than
492 m_value) value could be interpreted from the text.
494 If wxPG_FULL_VALUE is set, returns complete, storable value instead of displayable
495 one (they may be different).
496 If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of composite
497 property string value (as generated by GetValueAsString() called with this same
501 Default implementation converts semicolon delimited tokens into child values. Only
502 works for properties with children.
504 virtual bool StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
= 0 ) const;
506 /** Converts 'number' (including choice selection) into proper value 'variant'.
507 Returns true if new (different than m_value) value could be interpreted from the integer.
509 If wxPG_FULL_VALUE is set, returns complete, storable value instead of displayable one.
512 - If property is not supposed to use choice or spinctrl or other editor
513 with int-based value, it is not necessary to implement this method.
514 - Default implementation simply assign given int to m_value.
515 - If property uses choice control, and displays a dialog on some choice items,
516 then it is preferred to display that dialog in IntToValue instead of OnEvent.
518 virtual bool IntToValue( wxVariant
& value
, int number
, int argFlags
= 0 ) const;
522 /** Returns text representation of property's value.
525 If wxPG_FULL_VALUE is set, returns complete, storable string value instead of displayable.
526 If wxPG_EDITABLE_VALUE is set, returns string value that must be editable in textctrl.
527 If wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to display
528 as a part of composite property string value.
531 Default implementation returns string composed from text representations of
534 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
536 /** Converts string to a value, and if successful, calls SetValue() on it.
537 Default behavior is to do nothing.
539 String to get the value from.
541 true if value was changed.
543 bool SetValueFromString( const wxString
& text
, int flags
= 0 );
545 /** Converts integer to a value, and if succesful, calls SetValue() on it.
546 Default behavior is to do nothing.
548 Int to get the value from.
550 If has wxPG_FULL_VALUE, then the value given is a actual value and not an index.
552 True if value was changed.
554 bool SetValueFromInt( long value
, int flags
= 0 );
556 /** Returns size of the custom painted image in front of property. This method
557 must be overridden to return non-default value if OnCustomPaint is to be
560 Normally -1, but can be an index to the property's list of items.
562 - Default behavior is to return wxSize(0,0), which means no image.
563 - Default image width or height is indicated with dimension -1.
564 - You can also return wxPG_DEFAULT_IMAGE_SIZE which equals wxSize(-1, -1).
566 virtual wxSize
OnMeasureImage( int item
= -1 ) const;
568 /** Events received by editor widgets are processed here. Note that editor class
569 usually processes most events. Some, such as button press events of
570 TextCtrlAndButton class, can be handled here. Also, if custom handling
571 for regular events is desired, then that can also be done (for example,
572 wxSystemColourProperty custom handles wxEVT_COMMAND_CHOICE_SELECTED
573 to display colour picker dialog when 'custom' selection is made).
575 If the event causes value to be changed, SetValueInEvent()
576 should be called to set the new value.
581 Should return true if any changes in value should be reported.
583 - If property uses choice control, and displays a dialog on some choice items,
584 then it is preferred to display that dialog in IntToValue instead of OnEvent.
586 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* wnd_primary
, wxEvent
& event
);
588 /** Called after value of a child property has been altered. Note that this function is
589 usually called at the time that value of this property, or given child property, is
590 still pending for change.
592 Sample pseudo-code implementation:
595 void MyProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const
597 // Acquire reference to actual type of data stored in variant
598 // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros were used to create
599 // the variant class).
600 T& data = TFromVariant(thisValue);
602 // Copy childValue into data.
603 switch ( childIndex )
606 data.SetSubProp1( childvalue.GetLong() );
609 data.SetSubProp2( childvalue.GetString() );
617 Value of this property, that should be altered.
619 Index of child changed (you can use Item(childIndex) to get).
621 Value of the child property.
623 virtual void ChildChanged( wxVariant
& thisValue
, int childIndex
, wxVariant
& childValue
) const;
625 /** Returns pointer to an instance of used editor.
627 virtual const wxPGEditor
* DoGetEditorClass() const;
629 /** Returns pointer to the wxValidator that should be used
630 with the editor of this property (NULL for no validator).
631 Setting validator explicitly via SetPropertyValidator
634 In most situations, code like this should work well
635 (macros are used to maintain one actual validator instance,
636 so on the second call the function exits within the first
641 wxValidator* wxMyPropertyClass::DoGetValidator () const
643 WX_PG_DOGETVALIDATOR_ENTRY()
645 wxMyValidator* validator = new wxMyValidator(...);
647 ... prepare validator...
649 WX_PG_DOGETVALIDATOR_EXIT(validator)
655 You can get common filename validator by returning
656 wxFileProperty::GetClassValidator(). wxDirProperty,
657 for example, uses it.
659 virtual wxValidator
* DoGetValidator () const;
661 /** Returns current value's index to the choice control. May also return,
662 through pointer arguments, strings that should be inserted to that control.
663 Irrelevant to classes which do not employ wxPGEditor_Choice or similar.
665 - If returns NULL in choiceinfo.m_choices, then this class must be
666 derived from wxBaseEnumProperty.
667 - Must be able to cope situation where property's set of choices is
670 virtual int GetChoiceInfo( wxPGChoiceInfo
* choiceinfo
);
672 /** Override to paint an image in front of the property value text or drop-down
673 list item (but only if wxPGProperty::OnMeasureImage is overridden as well).
675 If property's OnMeasureImage() returns size that has height != 0 but less than
676 row height ( < 0 has special meanings), wxPropertyGrid calls this method to
677 draw a custom image in a limited area in front of the editor control or
678 value text/graphics, and if control has drop-down list, then the image is
679 drawn there as well (even in the case OnMeasureImage() returned higher height
682 NOTE: Following applies when OnMeasureImage() returns a "flexible" height (
683 using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable height items:
684 If rect.x is < 0, then this is a measure item call, which means that
685 dc is invalid and only thing that should be done is to set paintdata.m_drawnHeight
686 to the height of the image of item at index paintdata.m_choiceItem. This call
687 may be done even as often as once every drop-down popup show.
692 Box reserved for custom graphics. Includes surrounding rectangle, if any.
693 If x is < 0, then this is a measure item call (see above).
695 wxPGPaintData structure with much useful data.
698 - You can actually exceed rect width, but if you do so then paintdata.m_drawnWidth
699 must be set to the full width drawn in pixels.
700 - Due to technical reasons, rect's height will be default even if custom height
701 was reported during measure call.
702 - Brush is guaranteed to be default background colour. It has been already used to
703 clear the background of area being painted. It can be modified.
704 - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper colour) pen for
705 drawing framing rectangle. It can be changed as well.
707 @see GetValueAsString()
709 virtual void OnCustomPaint( wxDC
& dc
, const wxRect
& rect
, wxPGPaintData
& paintdata
);
711 /** Returns used wxPGCellRenderer instance for given property column (label=0, value=1).
713 Default implementation returns editor's renderer for all columns.
715 virtual wxPGCellRenderer
* GetCellRenderer( int column
) const;
717 /** Refresh values of child properties. Automatically called after value is set.
719 virtual void RefreshChildren();
721 /** Special handling for attributes of this property.
723 If returns false, then the attribute will be automatically stored in
726 Default implementation simply returns false.
728 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
730 /** Returns value of an attribute.
732 Override if custom handling of attributes is needed.
734 Default implementation simply return NULL variant.
736 virtual wxVariant
DoGetAttribute( const wxString
& name
) const;
738 /** Returns instance of a new wxPGEditorDialogAdapter instance, which is
739 used when user presses the (optional) button next to the editor control;
741 Default implementation returns NULL (ie. no action is generated when
744 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
746 /** Adds entry to property's wxPGChoices and editor control (if it is active).
747 Returns index of item added.
749 int AppendChoice( const wxString
& label
, int value
= wxPG_INVALID_VALUE
)
751 return InsertChoice(label
,-1,value
);
754 /** Returns wxPGCell of given column, NULL if none. If valid
755 object is returned, caller will gain its ownership.
757 wxPGCell
* AcquireCell( unsigned int column
)
759 if ( column
>= m_cells
.size() )
762 wxPGCell
* cell
= (wxPGCell
*) m_cells
[column
];
763 m_cells
[column
] = NULL
;
767 /** Returns true if children of this property are component values (for instance,
768 points size, face name, and is_underlined are component values of a font).
770 bool AreChildrenComponents() const
772 if ( m_flags
& (wxPG_PROP_COMPOSED_VALUE
|wxPG_PROP_AGGREGATE
) )
778 /** Removes entry from property's wxPGChoices and editor control (if it is active).
780 If selected item is deleted, then the value is set to unspecified.
782 void DeleteChoice( int index
);
784 /** Call to enable or disable usage of common value (integer value that can be selected for
785 properties instead of their normal values) for this property.
787 Common values are disabled by the default for all properties.
789 void EnableCommonValue( bool enable
= true )
791 if ( enable
) SetFlag( wxPG_PROP_USES_COMMON_VALUE
);
792 else ClearFlag( wxPG_PROP_USES_COMMON_VALUE
);
795 /** Composes text from values of child properties. */
796 void GenerateComposedValue( wxString
& text
, int argFlags
= 0 ) const;
798 /** Returns property's label. */
799 const wxString
& GetLabel() const { return m_label
; }
801 /** Returns property's name with all (non-category, non-root) parents. */
802 wxString
GetName() const;
804 /** Returns property's base name (ie. parent's name is not added in any case) */
805 const wxString
& GetBaseName() const { return m_name
; }
807 wxPGChoices
& GetChoices();
809 const wxPGChoices
& GetChoices() const;
811 const wxPGChoiceEntry
* GetCurrentChoice() const;
813 /** Returns coordinate to the top y of the property. Note that the
814 position of scrollbars is not taken into account.
818 wxVariant
GetValue() const
823 /** Returns reference to the internal stored value. GetValue is preferred
824 way to get the actual value, since GetValueRef ignores DoGetValue,
825 which may override stored value.
827 wxVariant
& GetValueRef()
832 const wxVariant
& GetValueRef() const
837 /** Same as GetValueAsString, except takes common value into account.
839 wxString
GetValueString( int argFlags
= 0 ) const;
841 void UpdateControl( wxWindow
* primary
);
843 /** Returns wxPGCell of given column, NULL if none. wxPGProperty
844 will retain ownership of the cell object.
846 wxPGCell
* GetCell( unsigned int column
) const
848 if ( column
>= m_cells
.size() )
851 return (wxPGCell
*) m_cells
[column
];
854 unsigned int GetChoiceCount() const;
856 wxString
GetChoiceString( unsigned int index
);
858 /** Return number of displayed common values for this property.
860 int GetDisplayedCommonValueCount() const;
862 wxString
GetDisplayedString() const
864 return GetValueString(0);
867 /** Returns property grid where property lies. */
868 wxPropertyGrid
* GetGrid() const;
870 /** Returns owner wxPropertyGrid, but only if one is currently on a page
871 displaying this property. */
872 wxPropertyGrid
* GetGridIfDisplayed() const;
874 /** Returns highest level non-category, non-root parent. Useful when you
875 have nested wxCustomProperties/wxParentProperties.
877 Thus, if immediate parent is root or category, this will return the
880 wxPGProperty
* GetMainParent() const;
882 /** Return parent of property */
883 wxPGProperty
* GetParent() const { return m_parent
; }
885 /** Returns true if property has editable wxTextCtrl when selected.
888 Altough disabled properties do not displayed editor, they still
889 return True here as being disabled is considered a temporary
890 condition (unlike being read-only or having limited editing enabled).
892 bool IsTextEditable() const;
894 bool IsValueUnspecified() const
896 return m_value
.IsNull();
899 FlagType
HasFlag( FlagType flag
) const
901 return ( m_flags
& flag
);
904 /** Returns comma-delimited string of property attributes.
906 const wxPGAttributeStorage
& GetAttributes() const
911 /** Returns m_attributes as list wxVariant.
913 wxVariant
GetAttributesAsList() const;
915 FlagType
GetFlags() const
920 const wxPGEditor
* GetEditorClass() const;
922 wxString
GetValueType() const
924 return m_value
.GetType();
927 /** Returns editor used for given column. NULL for no editor.
929 const wxPGEditor
* GetColumnEditor( int column
) const
932 return GetEditorClass();
937 /** Returns common value selected for this property. -1 for none.
939 int GetCommonValue() const
941 return m_commonValue
;
944 /** Returns true if property has even one visible child.
946 bool HasVisibleChildren() const;
948 /** Adds entry to property's wxPGChoices and editor control (if it is active).
949 Returns index of item added.
951 int InsertChoice( const wxString
& label
, int index
, int value
= wxPG_INVALID_VALUE
);
953 /** Returns true if this property is actually a wxPropertyCategory.
955 bool IsCategory() const { return HasFlag(wxPG_PROP_CATEGORY
)?true:false; }
957 /** Returns true if this property is actually a wxRootProperty.
959 bool IsRoot() const { return (m_parent
== NULL
); }
961 /** Returns true if this is a sub-property. */
962 bool IsSubProperty() const
964 wxPGProperty
* parent
= (wxPGProperty
*)m_parent
;
965 if ( parent
&& !parent
->IsCategory() )
970 /** Returns last visible sub-property, recursively.
972 const wxPGProperty
* GetLastVisibleSubItem() const;
974 wxVariant
GetDefaultValue() const;
976 int GetMaxLength() const
978 return (int) m_maxLen
;
981 /** Determines, recursively, if all children are not unspecified. Takes values in given list into account.
983 bool AreAllChildrenSpecified( wxVariant
* pendingList
= NULL
) const;
985 /** Updates composed values of parent non-category properties, recursively.
986 Returns topmost property updated.
989 - Must not call SetValue() (as can be called in it).
991 wxPGProperty
* UpdateParentValues();
993 /** Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
995 FlagType
UsesAutoUnspecified() const
997 return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED
);
1000 wxBitmap
* GetValueImage() const
1002 return m_valueBitmap
;
1005 wxVariant
GetAttribute( const wxString
& name
) const;
1007 /** Returns named attribute, as string, if found. Otherwise defVal is returned.
1009 wxString
GetAttribute( const wxString
& name
, const wxString
& defVal
) const;
1011 /** Returns named attribute, as long, if found. Otherwise defVal is returned.
1013 long GetAttributeAsLong( const wxString
& name
, long defVal
) const;
1015 /** Returns named attribute, as double, if found. Otherwise defVal is returned.
1017 double GetAttributeAsDouble( const wxString
& name
, double defVal
) const;
1019 inline unsigned int GetArrIndex() const { return m_arrIndex
; }
1021 inline unsigned int GetDepth() const { return (unsigned int)m_depth
; }
1023 /** Gets flags as a'|' delimited string. Note that flag names are not
1024 prepended with 'wxPG_PROP_'.
1026 String will only be made to include flags combined by this parameter.
1028 wxString
GetFlagsAsString( FlagType flagsMask
) const;
1030 /** Returns position in parent's array. */
1031 unsigned int GetIndexInParent() const
1033 return (unsigned int)m_arrIndex
;
1036 /** Hides or reveals the property.
1038 true for hide, false for reveal.
1040 By default changes are applied recursively. Set this paramter wxPG_DONT_RECURSE to prevent this.
1042 inline bool Hide( bool hide
, int flags
= wxPG_RECURSE
);
1044 bool IsExpanded() const { return (!(m_flags
& wxPG_PROP_COLLAPSED
) && GetChildCount()); }
1046 /** Returns true if all parents expanded.
1048 bool IsVisible() const;
1050 bool IsEnabled() const
1052 return ( m_flags
& wxPG_PROP_DISABLED
) ? false : true;
1055 /** If property's editor is created this forces its recreation. Useful
1056 in SetAttribute etc. Returns true if actually did anything.
1058 bool RecreateEditor();
1060 /** If property's editor is active, then update it's value.
1062 void RefreshEditor();
1064 /** Sets an attribute for this property.
1066 Text identifier of attribute. See @ref propgrid_property_attributes.
1070 void SetAttribute( const wxString
& name
, wxVariant value
);
1072 void SetAttributes( const wxPGAttributeStorage
& attributes
);
1074 /** Sets editor for a property.
1077 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1078 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full list).
1080 For custom editors, use pointer you received from wxPropertyGrid::RegisterEditorClass().
1082 void SetEditor( const wxPGEditor
* editor
)
1084 m_customEditor
= editor
;
1087 /** Sets editor for a property.
1089 inline void SetEditor( const wxString
& editorName
);
1091 /** Sets cell information for given column.
1093 Note that the property takes ownership of given wxPGCell instance.
1095 void SetCell( int column
, wxPGCell
* cellObj
);
1097 /** Changes value of a property with choices, but only
1098 works if the value type is long or string. */
1099 void SetChoiceSelection( int newValue
, const wxPGChoiceInfo
& choiceInfo
);
1101 /** Sets common value selected for this property. -1 for none.
1103 void SetCommonValue( int commonValue
)
1105 m_commonValue
= commonValue
;
1108 /** Sets flags from a '|' delimited string. Note that flag names are not
1109 prepended with 'wxPG_PROP_'.
1111 void SetFlagsFromString( const wxString
& str
);
1113 /** Sets property's "is it modified?" flag. Affects children recursively.
1115 void SetModifiedStatus( bool modified
)
1117 SetFlagRecursively(wxPG_PROP_MODIFIED
, modified
);
1120 /** Call in OnEvent(), OnButtonClick() etc. to change the property value
1121 based on user input.
1124 This method is const since it doesn't actually modify value, but posts
1125 given variant as pending value, stored in wxPropertyGrid.
1127 void SetValueInEvent( wxVariant value
) const;
1129 /** Call this to set value of the property. Unlike methods in wxPropertyGrid,
1130 this does not automatically update the display.
1133 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run through
1134 validation process and send property change event.
1136 If you need to change property value in event, based on user input, use
1137 SetValueInEvent() instead.
1140 Pointer to list variant that contains child values. Used to indicate
1141 which children should be marked as modified.
1143 Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR).
1145 void SetValue( wxVariant value
, wxVariant
* pList
= NULL
, int flags
= 0 );
1147 /** Set wxBitmap in front of the value. This bitmap may be ignored
1148 by custom cell renderers.
1150 void SetValueImage( wxBitmap
& bmp
);
1152 /** If property has choices and they are not yet exclusive, new such copy
1153 of them will be created.
1155 void SetChoicesExclusive();
1157 void SetExpanded( bool expanded
)
1159 if ( !expanded
) m_flags
|= wxPG_PROP_COLLAPSED
;
1160 else m_flags
&= ~wxPG_PROP_COLLAPSED
;
1163 void SetFlag( FlagType flag
) { m_flags
|= flag
; }
1165 void SetFlagRecursively( FlagType flag
, bool set
);
1167 void SetHelpString( const wxString
& helpString
)
1169 m_helpString
= helpString
;
1172 /** Sets property's label.
1175 - Properties under same parent may have same labels. However,
1176 property names must still remain unique.
1178 void SetLabel( const wxString
& label
) { m_label
= label
; }
1180 inline void SetName( const wxString
& newName
);
1182 void SetValueToUnspecified()
1184 wxVariant val
; // Create NULL variant
1188 /** Sets wxValidator for a property*/
1189 void SetValidator( const wxValidator
& validator
)
1191 m_validator
= wxDynamicCast(validator
.Clone(),wxValidator
);
1194 /** Gets assignable version of property's validator. */
1195 wxValidator
* GetValidator() const
1199 return DoGetValidator();
1202 /** Updates property value in case there were last minute
1203 changes. If value was unspecified, it will be set to default.
1204 Use only for properties that have TextCtrl-based editor.
1206 If you have code similar to
1208 // Update the value in case of last minute changes
1209 if ( primary && propgrid->IsEditorsValueModified() )
1210 GetEditorClass()->CopyValueFromControl( this, primary );
1212 in wxPGProperty::OnEvent wxEVT_COMMAND_BUTTON_CLICKED handler,
1213 then replace it with call to this method.
1215 True if value changed.
1217 bool PrepareValueForDialogEditing( wxPropertyGrid
* propgrid
);
1219 /** Returns client data (void*) of a property.
1221 void* GetClientData() const
1223 return m_clientData
;
1226 /** Sets client data (void*) of a property.
1228 This untyped client data has to be deleted manually.
1230 void SetClientData( void* clientData
)
1232 m_clientData
= clientData
;
1235 /** Returns client object of a property.
1237 void SetClientObject(wxClientData
* clientObject
)
1239 delete m_clientObject
;
1240 m_clientObject
= clientObject
;
1243 /** Sets managed client object of a property.
1245 wxClientData
*GetClientObject() const { return m_clientObject
; }
1247 /** Sets new set of choices for property.
1250 This operation clears the property value.
1252 bool SetChoices( wxPGChoices
& choices
);
1254 /** Sets new set of choices for property.
1256 inline bool SetChoices( const wxArrayString
& labels
,
1257 const wxArrayInt
& values
= wxArrayInt() );
1259 /** Set max length of text in text editor.
1261 inline bool SetMaxLength( int maxLen
);
1263 /** Call with 'false' in OnSetValue to cancel value changes after all
1264 (ie. cancel 'true' returned by StringToValue() or IntToValue()).
1266 void SetWasModified( bool set
= true )
1268 if ( set
) m_flags
|= wxPG_PROP_WAS_MODIFIED
;
1269 else m_flags
&= ~wxPG_PROP_WAS_MODIFIED
;
1272 const wxString
& GetHelpString() const
1274 return m_helpString
;
1277 void ClearFlag( FlagType flag
) { m_flags
&= ~(flag
); }
1279 // Use, for example, to detect if item is inside collapsed section.
1280 bool IsSomeParent( wxPGProperty
* candidate_parent
) const;
1282 /** Adapts list variant into proper value using consequtive ChildChanged-calls.
1284 void AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const;
1286 /** This is used by properties that have fixed sub-properties. */
1287 void AddChild( wxPGProperty
* prop
);
1289 /** Returns height of children, recursively, and
1290 by taking expanded/collapsed status into account.
1292 iMax is used when finding property y-positions.
1294 int GetChildrenHeight( int lh
, int iMax
= -1 ) const;
1296 /** Returns number of child properties */
1297 unsigned int GetChildCount() const { return m_children
.GetCount(); }
1299 /** Returns sub-property at index i. */
1300 wxPGProperty
* Item( size_t i
) const { return (wxPGProperty
*)m_children
.Item(i
); }
1302 /** Returns last sub-property.
1304 wxPGProperty
* Last() const { return (wxPGProperty
*)m_children
.Last(); }
1306 /** Returns index of given sub-property. */
1307 int Index( const wxPGProperty
* p
) const { return m_children
.Index((wxPGProperty
*)p
); }
1309 /** Deletes all sub-properties. */
1312 // Puts correct indexes to children
1313 void FixIndexesOfChildren( size_t starthere
= 0 );
1315 wxPGProperty
* GetItemAtY( unsigned int y
, unsigned int lh
, unsigned int* nextItemY
) const;
1317 /** Returns (direct) child property with given name (or NULL if not found).
1319 wxPGProperty
* GetPropertyByName( const wxString
& name
) const;
1323 /** @class wxPGChoices
1325 Helper class for managing choices of wxPropertyGrid properties.
1326 Each entry can have label, value, bitmap, text colour, and background colour.
1328 @library{wxpropgrid}
1331 class WXDLLIMPEXP_PROPGRID wxPGChoices
1334 typedef long ValArrItem
;
1336 /** Default constructor. */
1342 /** Copy constructor. */
1343 wxPGChoices( const wxPGChoices
& a
)
1345 if ( a
.m_data
!= wxPGChoicesEmptyData
)
1348 m_data
->m_refCount
++;
1353 wxPGChoices( const wxChar
** labels
, const long* values
= NULL
)
1360 wxPGChoices( const wxArrayString
& labels
, const wxArrayInt
& values
= wxArrayInt() )
1366 /** Simple interface constructor. */
1367 wxPGChoices( wxPGChoicesData
* data
)
1380 /** Adds to current. If did not have own copies, creates them now. If was empty,
1381 identical to set except that creates copies.
1383 void Add( const wxChar
** labels
, const ValArrItem
* values
= NULL
);
1385 /** Version that works with wxArrayString. */
1386 void Add( const wxArrayString
& arr
, const ValArrItem
* values
= NULL
);
1388 /** Version that works with wxArrayString and wxArrayInt. */
1389 void Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
);
1391 /** Adds single item. */
1392 wxPGChoiceEntry
& Add( const wxString
& label
, int value
= wxPG_INVALID_VALUE
);
1394 /** Adds a single item, with bitmap. */
1395 wxPGChoiceEntry
& Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
= wxPG_INVALID_VALUE
);
1397 /** Adds a single item with full entry information. */
1398 wxPGChoiceEntry
& Add( const wxPGChoiceEntry
& entry
)
1400 return Insert(entry
, -1);
1403 /** Adds single item. */
1404 wxPGChoiceEntry
& AddAsSorted( const wxString
& label
, int value
= wxPG_INVALID_VALUE
);
1406 void Assign( const wxPGChoices
& a
)
1408 AssignData(a
.m_data
);
1411 void AssignData( wxPGChoicesData
* data
);
1413 /** Delete all choices. */
1416 if ( m_data
!= wxPGChoicesEmptyData
)
1422 if ( m_data
== wxPGChoicesEmptyData
)
1423 m_data
= new wxPGChoicesData();
1426 /** Gets a unsigned number identifying this list. */
1427 wxPGChoicesId
GetId() const { return (wxPGChoicesId
) m_data
; };
1429 const wxString
& GetLabel( size_t ind
) const
1431 wxASSERT( ind
>= 0 && ind
< GetCount() );
1432 return Item(ind
).GetText();
1435 size_t GetCount () const
1437 wxASSERT_MSG( m_data
,
1438 wxT("When checking if wxPGChoices is valid, use IsOk() instead of GetCount()") );
1439 return m_data
->GetCount();
1442 int GetValue( size_t ind
) const { return Item(ind
).GetValue(); }
1444 /** Returns array of values matching the given strings. Unmatching strings
1445 result in wxPG_INVALID_VALUE entry in array.
1447 wxArrayInt
GetValuesForStrings( const wxArrayString
& strings
) const;
1449 /** Returns array of indices matching given strings. Unmatching strings
1450 are added to 'unmatched', if not NULL.
1452 wxArrayInt
GetIndicesForStrings( const wxArrayString
& strings
, wxArrayString
* unmatched
= NULL
) const;
1454 /** Returns true if choices in general are likely to have values
1455 (depens on that all entries have values or none has)
1457 bool HasValues() const;
1459 bool HasValue( unsigned int i
) const { return (m_data
->GetCount() > i
&& m_data
->Item(i
)->HasValue()); }
1461 int Index( const wxString
& str
) const;
1462 int Index( int val
) const;
1464 /** Inserts single item. */
1465 wxPGChoiceEntry
& Insert( const wxString
& label
, int index
, int value
= wxPG_INVALID_VALUE
);
1467 /** Inserts a single item with full entry information. */
1468 wxPGChoiceEntry
& Insert( const wxPGChoiceEntry
& entry
, int index
);
1470 /** Returns false if this is a constant empty set of choices,
1471 which should not be modified.
1475 return ( m_data
!= wxPGChoicesEmptyData
);
1478 const wxPGChoiceEntry
& Item( unsigned int i
) const
1481 return *m_data
->Item(i
);
1484 wxPGChoiceEntry
& Item( unsigned int i
)
1487 return *m_data
->Item(i
);
1490 /** Removes count items starting at position nIndex. */
1491 void RemoveAt(size_t nIndex
, size_t count
= 1);
1493 /** Does not create copies for itself. */
1494 void Set( const wxChar
** labels
, const long* values
= NULL
)
1500 /** Version that works with wxArrayString.
1501 TODO: Deprecate this.
1503 void Set( wxArrayString
& arr
, const long* values
= (const long*) NULL
)
1509 /** Version that works with wxArrayString and wxArrayInt. */
1510 void Set( const wxArrayString
& labels
, const wxArrayInt
& values
= wxArrayInt() )
1519 // Creates exclusive copy of current choices
1522 if ( m_data
->m_refCount
!= 1 )
1524 wxPGChoicesData
* data
= new wxPGChoicesData();
1525 data
->CopyDataFrom(m_data
);
1531 // Returns data, increases refcount.
1532 wxPGChoicesData
* GetData()
1534 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
1535 m_data
->m_refCount
++;
1539 // Returns plain data ptr - no refcounting stuff is done.
1540 wxPGChoicesData
* GetDataPtr() const { return m_data
; }
1542 // Changes ownership of data to you.
1543 wxPGChoicesData
* ExtractData()
1545 wxPGChoicesData
* data
= m_data
;
1546 m_data
= wxPGChoicesEmptyData
;
1550 wxArrayString
GetLabels() const;
1552 void operator= (const wxPGChoices
& a
)
1554 AssignData(a
.m_data
);
1557 wxPGChoiceEntry
& operator[](unsigned int i
)
1562 const wxPGChoiceEntry
& operator[](unsigned int i
) const
1568 // -----------------------------------------------------------------------