1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxPGProperty
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 #define wxNullProperty ((wxPGProperty*)NULL)
13 // Structure for relaying choice/list info.
16 wxPGChoices
* m_choices
;
20 /** @section propgrid_property_attributes wxPropertyGrid Property Attribute Identifiers
22 wxPGProperty::SetAttribute() and
23 wxPropertyGridInterface::SetPropertyAttribute()
24 accept one of these as attribute name argument .
26 You can use strings instead of constants. However, some of these
27 constants are redefined to use cached strings which may reduce
28 your binary size by some amount.
33 /** Set default value for property.
35 #define wxPG_ATTR_DEFAULT_VALUE wxS("DefaultValue")
37 /** Universal, int or double. Minimum value for numeric properties.
39 #define wxPG_ATTR_MIN wxS("Min")
41 /** Universal, int or double. Maximum value for numeric properties.
43 #define wxPG_ATTR_MAX wxS("Max")
45 /** Universal, string. When set, will be shown as text after the displayed
46 text value. Alternatively, if third column is enabled, text will be shown
47 there (for any type of property).
49 #define wxPG_ATTR_UNITS wxS("Units")
51 /** Universal, string. When set, will be shown in property's value cell
52 when displayed value string is empty, or value is unspecified.
54 #define wxPG_ATTR_INLINE_HELP wxS("InlineHelp")
56 /** wxBoolProperty specific, int, default 0. When 1 sets bool property to
57 use checkbox instead of choice.
59 #define wxPG_BOOL_USE_CHECKBOX wxS("UseCheckbox")
61 /** wxBoolProperty specific, int, default 0. When 1 sets bool property value
62 to cycle on double click (instead of showing the popup listbox).
64 #define wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING wxS("UseDClickCycling")
66 /** wxFloatProperty (and similar) specific, int, default -1. Sets the (max) precision
67 used when floating point value is rendered as text. The default -1 means infinite
70 #define wxPG_FLOAT_PRECISION wxS("Precision")
72 /** The text will be echoed as asterisks (wxTE_PASSWORD will be passed to textctrl etc).
74 #define wxPG_STRING_PASSWORD wxS("Password")
76 /** Define base used by a wxUIntProperty. Valid constants are
77 wxPG_BASE_OCT, wxPG_BASE_DEC, wxPG_BASE_HEX and wxPG_BASE_HEXL
78 (lowercase characters).
80 #define wxPG_UINT_BASE wxS("Base")
82 /** Define prefix rendered to wxUIntProperty. Accepted constants
83 wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and wxPG_PREFIX_DOLLAR_SIGN.
84 <b>Note:</b> Only wxPG_PREFIX_NONE works with Decimal and Octal
87 #define wxPG_UINT_PREFIX wxS("Prefix")
89 /** wxFileProperty/wxImageFileProperty specific, wxChar*, default is detected/varies.
90 Sets the wildcard used in the triggered wxFileDialog. Format is the
93 #define wxPG_FILE_WILDCARD wxS("Wildcard")
95 /** wxFileProperty/wxImageFileProperty specific, int, default 1.
96 When 0, only the file name is shown (i.e. drive and directory are hidden).
98 #define wxPG_FILE_SHOW_FULL_PATH wxS("ShowFullPath")
100 /** Specific to wxFileProperty and derived properties, wxString, default empty.
101 If set, then the filename is shown relative to the given path string.
103 #define wxPG_FILE_SHOW_RELATIVE_PATH wxS("ShowRelativePath")
105 /** Specific to wxFileProperty and derived properties, wxString, default is empty.
106 Sets the initial path of where to look for files.
108 #define wxPG_FILE_INITIAL_PATH wxS("InitialPath")
110 /** Specific to wxFileProperty and derivatives, wxString, default is empty.
111 Sets a specific title for the dir dialog.
113 #define wxPG_FILE_DIALOG_TITLE wxS("DialogTitle")
115 /** Specific to wxDirProperty, wxString, default is empty.
116 Sets a specific message for the dir dialog.
118 #define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage")
120 /** Sets displayed date format for wxDateProperty.
122 #define wxPG_DATE_FORMAT wxS("DateFormat")
124 /** Sets wxDatePickerCtrl window style used with wxDateProperty. Default
125 is wxDP_DEFAULT | wxDP_SHOWCENTURY.
127 #define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
129 /** SpinCtrl editor, int or double. How much number changes when button is
130 pressed (or up/down on keybard).
132 #define wxPG_ATTR_SPINCTRL_STEP wxS("Step")
134 /** SpinCtrl editor, bool. If true, value wraps at Min/Max.
136 #define wxPG_ATTR_SPINCTRL_WRAP wxS("Wrap")
138 /** wxMultiChoiceProperty, int. If 0, no user strings allowed. If 1, user strings
139 appear before list strings. If 2, user strings appear after list string.
141 #define wxPG_ATTR_MULTICHOICE_USERSTRINGMODE wxS("UserStringMode")
143 /** wxColourProperty and its kind, int, default 1. Setting this attribute to 0 hides custom
144 colour from property's list of choices.
146 #define wxPG_COLOUR_ALLOW_CUSTOM wxS("AllowCustom")
151 // -----------------------------------------------------------------------
153 /** @class wxPGProperty
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.
198 * wxStringProperty has a special trait: if it has value of "<composed>",
199 and also has child properties, then its displayed value becomes
200 composition of child property values, similar as with wxFontProperty,
203 @subsection wxIntProperty
205 Like wxStringProperty, but converts text to a signed long integer.
206 wxIntProperty seamlessly supports 64-bit integers (ie. wxLongLong).
208 @subsection wxUIntProperty
210 Like wxIntProperty, but displays value as unsigned int. To set
211 the prefix used globally, manipulate wxPG_UINT_PREFIX string attribute.
212 To set the globally used base, manipulate wxPG_UINT_BASE int
213 attribute. Regardless of current prefix, understands (hex) values starting
214 with both "0x" and "$".
215 wxUIntProperty seamlessly supports 64-bit unsigned integers (ie. wxULongLong).
217 @subsection wxFloatProperty
219 Like wxStringProperty, but converts text to a double-precision floating point.
220 Default float-to-text precision is 6 decimals, but this can be changed
221 by modifying wxPG_FLOAT_PRECISION attribute.
223 @subsection wxBoolProperty
225 Represents a boolean value. wxChoice is used as editor control, by the
226 default. wxPG_BOOL_USE_CHECKBOX attribute can be set to true inorder to use
229 @subsection wxLongStringProperty
231 Like wxStringProperty, but has a button that triggers a small text editor
232 dialog. Note that in long string values, tabs are represented by "\t" and
235 @subsection wxDirProperty
237 Like wxLongStringProperty, but the button triggers dir selector instead.
238 Supported properties (all with string value): wxPG_DIR_DIALOG_MESSAGE.
240 @subsection wxFileProperty
242 Like wxLongStringProperty, but the button triggers file selector instead.
243 Default wildcard is "All files..." but this can be changed by setting
244 wxPG_FILE_WILDCARD attribute (see wxFileDialog for format details).
245 Attribute wxPG_FILE_SHOW_FULL_PATH can be set to false inorder to show
246 only the filename, not the entire path.
248 @subsection wxEnumProperty
250 Represents a single selection from a list of choices -
251 wxOwnerDrawnComboBox is used to edit the value.
253 @subsection wxFlagsProperty
255 Represents a bit set that fits in a long integer. wxBoolProperty sub-properties
256 are created for editing individual bits. Textctrl is created to manually edit
257 the flags as a text; a continous sequence of spaces, commas and semicolons
258 is considered as a flag id separator.
259 <b>Note: </b> When changing "choices" (ie. flag labels) of wxFlagsProperty, you
260 will need to use SetPropertyChoices - otherwise they will not get updated properly.
262 @subsection wxArrayStringProperty
264 Allows editing of a list of strings in wxTextCtrl and in a separate dialog.
266 @subsection wxDateProperty
268 wxDateTime property. Default editor is DatePickerCtrl, altough TextCtrl
269 should work as well. wxPG_DATE_FORMAT attribute can be used to change
270 string wxDateTime::Format uses (altough default is recommended as it is
271 locale-dependant), and wxPG_DATE_PICKER_STYLE allows changing window
272 style given to DatePickerCtrl (default is wxDP_DEFAULT|wxDP_SHOWCENTURY).
274 @subsection wxEditEnumProperty
276 Represents a string that can be freely edited or selected from list of choices -
277 custom combobox control is used to edit the value.
279 @subsection wxMultiChoiceProperty
281 Allows editing a multiple selection from a list of strings. This is
282 property is pretty much built around concept of wxMultiChoiceDialog.
283 It uses wxArrayString value.
285 @subsection wxImageFileProperty
287 Like wxFileProperty, but has thumbnail of the image in front of
288 the filename and autogenerates wildcard from available image handlers.
290 @subsection wxColourProperty
292 <b>Useful alternate editor:</b> Choice.
294 Represents wxColour. wxButton is used to trigger a colour picker dialog.
296 @subsection wxFontProperty
298 Represents wxFont. Various sub-properties are used to edit individual
301 @subsection wxSystemColourProperty
303 Represents wxColour and a system colour index. wxChoice is used to edit
304 the value. Drop-down list has color images. Note that value type
305 is wxColourPropertyValue instead of wxColour.
307 class wxColourPropertyValue : public wxObject
310 // An integer value relating to the colour, and which exact
311 // meaning depends on the property with which it is used.
313 // For wxSystemColourProperty:
314 // Any of wxSYS_COLOUR_XXX, or any web-colour ( use wxPG_TO_WEB_COLOUR
315 // macro - (currently unsupported) ), or wxPG_COLOUR_CUSTOM.
318 // Resulting colour. Should be correct regardless of type.
323 @subsection wxCursorProperty
325 Represents a wxCursor. wxChoice is used to edit the value.
326 Drop-down list has cursor images under some (wxMSW) platforms.
329 @section pgproperty_creating Creating Custom Properties
331 New properties can be created by subclassing wxPGProperty or one
332 of the provided property classes, and (re)implementing necessary
333 member functions. Below, each virtual member function has ample
334 documentation about its purpose and any odd details which to keep
337 Here is a very simple 'template' code:
340 class MyProperty : public wxPGProperty
343 // All arguments of ctor must have a default value -
344 // use wxPG_LABEL for label and name
345 MyProperty( const wxString& label = wxPG_LABEL,
346 const wxString& name = wxPG_LABEL,
347 const wxString& value = wxEmptyString )
349 // m_value is wxVariant
353 virtual ~MyProperty() { }
355 const wxPGEditor* DoGetEditorClass() const
357 // Determines editor used by property.
358 // You can replace 'TextCtrl' below with any of these
359 // builtin-in property editor identifiers: Choice, ComboBox,
360 // TextCtrlAndButton, ChoiceAndButton, CheckBox, SpinCtrl,
362 return wxPGEditor_TextCtrl;
365 virtual wxString GetValueAsString( int argFlags ) const
367 // TODO: Return property value in string format
370 virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags )
372 // TODO: Adapt string to property value.
379 Since wxPGProperty derives from wxObject, you can use standard
380 DECLARE_DYNAMIC_CLASS and IMPLEMENT_DYNAMIC_CLASS macros. From the
381 above example they were omitted for sake of simplicity, and besides,
382 they are only really needed if you need to use wxRTTI with your
385 You can change the 'value type' of a property by simply assigning different
386 type of variant with SetValue. <b>It is mandatory to implement
387 wxVariantData class for all data types used as property values.</b>
388 You can use macros declared in wxPropertyGrid headers. For instance:
392 // (If you need to have export declaration, use version of macros
393 // with _EXPORTED postfix)
394 WX_PG_DECLARE_VARIANT_DATA(MyDataClass)
397 WX_PG_IMPLEMENT_VARIANT_DATA(MyDataClass)
399 // Or, if you don't have valid == operator:
400 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(MyDataClass)
406 class wxPGProperty
: public wxObject
409 typedef wxUint32 FlagType
;
411 /** Basic constructor.
416 Non-abstract property classes should have constructor of this style:
420 // If T is a class, then it should be a constant reference
421 // (e.g. const T& ) instead.
422 MyProperty( const wxString& label, const wxString& name, T value )
425 // Generally recommended way to set the initial value
426 // (as it should work in pretty much 100% of cases).
431 // If has private child properties then create them here. For example:
432 // AddChild( new wxStringProperty( "Subprop 1", wxPG_LABEL, value.GetSubProp1() ) );
437 wxPGProperty( const wxString
& label
, const wxString
& name
);
439 /** Virtual destructor. It is customary for derived properties to implement this. */
440 virtual ~wxPGProperty();
442 /** This virtual function is called after m_value has been set.
445 - If m_value was set to Null variant (ie. unspecified value), OnSetValue()
447 - m_value may be of any variant type. Typically properties internally support only
448 one variant type, and as such OnSetValue() provides a good opportunity to convert
449 supported values into internal type.
450 - Default implementation does nothing.
452 virtual void OnSetValue();
454 /** Override this to return something else than m_value as the value.
456 virtual wxVariant
DoGetValue() const { return m_value
; }
458 /** Implement this function in derived class to check the value.
459 Return true if it is ok. Returning false prevents property change events
463 - Default implementation always returns true.
465 virtual bool ValidateValue( wxVariant
& value
, wxPGValidationInfo
& validationInfo
) const;
467 /** Converts 'text' into proper value 'variant'. Returns true if new (different than
468 m_value) value could be interpreted from the text.
470 If wxPG_FULL_VALUE is set, returns complete, storable value instead of displayable
471 one (they may be different).
472 If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of composite
473 property string value (as generated by GetValueAsString() called with this same
477 Default implementation converts semicolon delimited tokens into child values. Only
478 works for properties with children.
480 virtual bool StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
= 0 ) const;
482 /** Converts 'number' (including choice selection) into proper value 'variant'.
483 Returns true if new (different than m_value) value could be interpreted from the integer.
485 If wxPG_FULL_VALUE is set, returns complete, storable value instead of displayable one.
488 - If property is not supposed to use choice or spinctrl or other editor
489 with int-based value, it is not necessary to implement this method.
490 - Default implementation simply assign given int to m_value.
491 - If property uses choice control, and displays a dialog on some choice items,
492 then it is preferred to display that dialog in IntToValue instead of OnEvent.
494 virtual bool IntToValue( wxVariant
& value
, int number
, int argFlags
= 0 ) const;
498 /** Returns text representation of property's value.
501 If wxPG_FULL_VALUE is set, returns complete, storable string value instead of displayable.
502 If wxPG_EDITABLE_VALUE is set, returns string value that must be editable in textctrl.
503 If wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to display
504 as a part of composite property string value.
507 Default implementation returns string composed from text representations of
510 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
512 /** Converts string to a value, and if successful, calls SetValue() on it.
513 Default behavior is to do nothing.
515 String to get the value from.
517 true if value was changed.
519 bool SetValueFromString( const wxString
& text
, int flags
= 0 );
521 /** Converts integer to a value, and if succesful, calls SetValue() on it.
522 Default behavior is to do nothing.
524 Int to get the value from.
526 If has wxPG_FULL_VALUE, then the value given is a actual value and not an index.
528 True if value was changed.
530 bool SetValueFromInt( long value
, int flags
= 0 );
532 /** Returns size of the custom painted image in front of property. This method
533 must be overridden to return non-default value if OnCustomPaint is to be
536 Normally -1, but can be an index to the property's list of items.
538 - Default behavior is to return wxSize(0,0), which means no image.
539 - Default image width or height is indicated with dimension -1.
540 - You can also return wxPG_DEFAULT_IMAGE_SIZE which equals wxSize(-1, -1).
542 virtual wxSize
OnMeasureImage( int item
= -1 ) const;
544 /** Events received by editor widgets are processed here. Note that editor class
545 usually processes most events. Some, such as button press events of
546 TextCtrlAndButton class, can be handled here. Also, if custom handling
547 for regular events is desired, then that can also be done (for example,
548 wxSystemColourProperty custom handles wxEVT_COMMAND_CHOICE_SELECTED
549 to display colour picker dialog when 'custom' selection is made).
551 If the event causes value to be changed, SetValueInEvent()
552 should be called to set the new value.
557 Should return true if any changes in value should be reported.
559 - If property uses choice control, and displays a dialog on some choice items,
560 then it is preferred to display that dialog in IntToValue instead of OnEvent.
562 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* wnd_primary
, wxEvent
& event
);
564 /** Called after value of a child property has been altered. Note that this function is
565 usually called at the time that value of this property, or given child property, is
566 still pending for change.
568 Sample pseudo-code implementation:
571 void MyProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const
573 // Acquire reference to actual type of data stored in variant
574 // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros were used to create
575 // the variant class).
576 T& data = TFromVariant(thisValue);
578 // Copy childValue into data.
579 switch ( childIndex )
582 data.SetSubProp1( childvalue.GetLong() );
585 data.SetSubProp2( childvalue.GetString() );
593 Value of this property, that should be altered.
595 Index of child changed (you can use Item(childIndex) to get).
597 Value of the child property.
599 virtual void ChildChanged( wxVariant
& thisValue
, int childIndex
, wxVariant
& childValue
) const;
601 /** Returns pointer to an instance of used editor.
603 virtual const wxPGEditor
* DoGetEditorClass() const;
605 /** Returns pointer to the wxValidator that should be used
606 with the editor of this property (NULL for no validator).
607 Setting validator explicitly via SetPropertyValidator
610 In most situations, code like this should work well
611 (macros are used to maintain one actual validator instance,
612 so on the second call the function exits within the first
617 wxValidator* wxMyPropertyClass::DoGetValidator () const
619 WX_PG_DOGETVALIDATOR_ENTRY()
621 wxMyValidator* validator = new wxMyValidator(...);
623 ... prepare validator...
625 WX_PG_DOGETVALIDATOR_EXIT(validator)
631 You can get common filename validator by returning
632 wxFileProperty::GetClassValidator(). wxDirProperty,
633 for example, uses it.
635 virtual wxValidator
* DoGetValidator () const;
637 /** Returns current value's index to the choice control. May also return,
638 through pointer arguments, strings that should be inserted to that control.
639 Irrelevant to classes which do not employ wxPGEditor_Choice or similar.
641 - If returns NULL in choiceinfo.m_choices, then this class must be
642 derived from wxBaseEnumProperty.
643 - Must be able to cope situation where property's set of choices is
646 virtual int GetChoiceInfo( wxPGChoiceInfo
* choiceinfo
);
648 /** Override to paint an image in front of the property value text or drop-down
649 list item (but only if wxPGProperty::OnMeasureImage is overridden as well).
651 If property's OnMeasureImage() returns size that has height != 0 but less than
652 row height ( < 0 has special meanings), wxPropertyGrid calls this method to
653 draw a custom image in a limited area in front of the editor control or
654 value text/graphics, and if control has drop-down list, then the image is
655 drawn there as well (even in the case OnMeasureImage() returned higher height
658 NOTE: Following applies when OnMeasureImage() returns a "flexible" height (
659 using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable height items:
660 If rect.x is < 0, then this is a measure item call, which means that
661 dc is invalid and only thing that should be done is to set paintdata.m_drawnHeight
662 to the height of the image of item at index paintdata.m_choiceItem. This call
663 may be done even as often as once every drop-down popup show.
668 Box reserved for custom graphics. Includes surrounding rectangle, if any.
669 If x is < 0, then this is a measure item call (see above).
671 wxPGPaintData structure with much useful data about painted item.
676 const wxPropertyGrid* m_parent;
678 // Normally -1, otherwise index to drop-down list item that has to be drawn.
681 // Set to drawn width in OnCustomPaint (optional).
684 // In a measure item call, set this to the height of item at m_choiceItem index
690 - You can actually exceed rect width, but if you do so then paintdata.m_drawnWidth
691 must be set to the full width drawn in pixels.
692 - Due to technical reasons, rect's height will be default even if custom height
693 was reported during measure call.
694 - Brush is guaranteed to be default background colour. It has been already used to
695 clear the background of area being painted. It can be modified.
696 - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper colour) pen for
697 drawing framing rectangle. It can be changed as well.
699 @see GetValueAsString()
701 virtual void OnCustomPaint( wxDC
& dc
, const wxRect
& rect
, wxPGPaintData
& paintdata
);
703 /** Returns used wxPGCellRenderer instance for given property column (label=0, value=1).
705 Default implementation returns editor's renderer for all columns.
707 virtual wxPGCellRenderer
* GetCellRenderer( int column
) const;
709 /** Refresh values of child properties. Automatically called after value is set.
711 virtual void RefreshChildren();
713 /** Special handling for attributes of this property.
715 If returns false, then the attribute will be automatically stored in
718 Default implementation simply returns false.
720 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
722 /** Returns value of an attribute.
724 Override if custom handling of attributes is needed.
726 Default implementation simply return NULL variant.
728 virtual wxVariant
DoGetAttribute( const wxString
& name
) const;
730 /** Returns instance of a new wxPGEditorDialogAdapter instance, which is
731 used when user presses the (optional) button next to the editor control;
733 Default implementation returns NULL (ie. no action is generated when
736 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
738 /** Adds entry to property's wxPGChoices and editor control (if it is active).
739 Returns index of item added.
741 int AppendChoice( const wxString
& label
, int value
= wxPG_INVALID_VALUE
)
743 return InsertChoice(label
,-1,value
);
746 /** Returns wxPGCell of given column, NULL if none. If valid
747 object is returned, caller will gain its ownership.
749 wxPGCell
* AcquireCell( unsigned int column
)
751 if ( column
>= m_cells
.size() )
754 wxPGCell
* cell
= (wxPGCell
*) m_cells
[column
];
755 m_cells
[column
] = NULL
;
759 /** Returns true if children of this property are component values (for instance,
760 points size, face name, and is_underlined are component values of a font).
762 bool AreChildrenComponents() const
764 if ( m_flags
& (wxPG_PROP_COMPOSED_VALUE
|wxPG_PROP_AGGREGATE
) )
770 /** Removes entry from property's wxPGChoices and editor control (if it is active).
772 If selected item is deleted, then the value is set to unspecified.
774 void DeleteChoice( int index
);
776 /** Call to enable or disable usage of common value (integer value that can be selected for
777 properties instead of their normal values) for this property.
779 Common values are disabled by the default for all properties.
781 void EnableCommonValue( bool enable
= true )
783 if ( enable
) SetFlag( wxPG_PROP_USES_COMMON_VALUE
);
784 else ClearFlag( wxPG_PROP_USES_COMMON_VALUE
);
787 /** Composes text from values of child properties. */
788 void GenerateComposedValue( wxString
& text
, int argFlags
= 0 ) const;
790 /** Returns property's label. */
791 const wxString
& GetLabel() const { return m_label
; }
793 /** Returns property's name with all (non-category, non-root) parents. */
794 wxString
GetName() const;
796 /** Returns property's base name (ie. parent's name is not added in any case) */
797 const wxString
& GetBaseName() const { return m_name
; }
799 wxPGChoices
& GetChoices();
801 const wxPGChoices
& GetChoices() const;
803 const wxPGChoiceEntry
* GetCurrentChoice() const;
805 /** Returns coordinate to the top y of the property. Note that the
806 position of scrollbars is not taken into account.
810 wxVariant
GetValue() const
815 /** Returns reference to the internal stored value. GetValue is preferred
816 way to get the actual value, since GetValueRef ignores DoGetValue,
817 which may override stored value.
819 wxVariant
& GetValueRef()
824 const wxVariant
& GetValueRef() const
829 /** Same as GetValueAsString, except takes common value into account.
831 wxString
GetValueString( int argFlags
= 0 ) const;
833 void UpdateControl( wxWindow
* primary
);
835 /** Returns wxPGCell of given column, NULL if none. wxPGProperty
836 will retain ownership of the cell object.
838 wxPGCell
* GetCell( unsigned int column
) const
840 if ( column
>= m_cells
.size() )
843 return (wxPGCell
*) m_cells
[column
];
846 unsigned int GetChoiceCount() const;
848 wxString
GetChoiceString( unsigned int index
);
850 /** Return number of displayed common values for this property.
852 int GetDisplayedCommonValueCount() const;
854 wxString
GetDisplayedString() const
856 return GetValueString(0);
859 /** Returns property grid where property lies. */
860 wxPropertyGrid
* GetGrid() const;
862 /** Returns owner wxPropertyGrid, but only if one is currently on a page
863 displaying this property. */
864 wxPropertyGrid
* GetGridIfDisplayed() const;
866 /** Returns highest level non-category, non-root parent. Useful when you
867 have nested wxCustomProperties/wxParentProperties.
869 Thus, if immediate parent is root or category, this will return the
872 wxPGProperty
* GetMainParent() const;
874 /** Return parent of property */
875 wxPGProperty
* GetParent() const { return m_parent
; }
877 /** Returns true if property has editable wxTextCtrl when selected.
880 Altough disabled properties do not displayed editor, they still
881 return True here as being disabled is considered a temporary
882 condition (unlike being read-only or having limited editing enabled).
884 bool IsTextEditable() const;
886 bool IsValueUnspecified() const
888 return m_value
.IsNull();
891 FlagType
HasFlag( FlagType flag
) const
893 return ( m_flags
& flag
);
896 /** Returns comma-delimited string of property attributes.
898 const wxPGAttributeStorage
& GetAttributes() const
903 /** Returns m_attributes as list wxVariant.
905 wxVariant
GetAttributesAsList() const;
907 FlagType
GetFlags() const
912 const wxPGEditor
* GetEditorClass() const;
914 wxString
GetValueType() const
916 return m_value
.GetType();
919 /** Returns editor used for given column. NULL for no editor.
921 const wxPGEditor
* GetColumnEditor( int column
) const
924 return GetEditorClass();
929 /** Returns common value selected for this property. -1 for none.
931 int GetCommonValue() const
933 return m_commonValue
;
936 /** Returns true if property has even one visible child.
938 bool HasVisibleChildren() const;
940 /** Adds entry to property's wxPGChoices and editor control (if it is active).
941 Returns index of item added.
943 int InsertChoice( const wxString
& label
, int index
, int value
= wxPG_INVALID_VALUE
);
945 /** Returns true if this property is actually a wxPropertyCategory.
947 bool IsCategory() const { return HasFlag(wxPG_PROP_CATEGORY
)?true:false; }
949 /** Returns true if this property is actually a wxRootProperty.
951 bool IsRoot() const { return (m_parent
== NULL
); }
953 /** Returns true if this is a sub-property. */
954 bool IsSubProperty() const
956 wxPGProperty
* parent
= (wxPGProperty
*)m_parent
;
957 if ( parent
&& !parent
->IsCategory() )
962 /** Returns last visible sub-property, recursively.
964 const wxPGProperty
* GetLastVisibleSubItem() const;
966 wxVariant
GetDefaultValue() const;
968 int GetMaxLength() const
970 return (int) m_maxLen
;
973 /** Determines, recursively, if all children are not unspecified. Takes values in given list into account.
975 bool AreAllChildrenSpecified( wxVariant
* pendingList
= NULL
) const;
977 /** Updates composed values of parent non-category properties, recursively.
978 Returns topmost property updated.
981 - Must not call SetValue() (as can be called in it).
983 wxPGProperty
* UpdateParentValues();
985 /** Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
987 FlagType
UsesAutoUnspecified() const
989 return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED
);
992 wxBitmap
* GetValueImage() const
994 return m_valueBitmap
;
997 wxVariant
GetAttribute( const wxString
& name
) const;
999 /** Returns named attribute, as string, if found. Otherwise defVal is returned.
1001 wxString
GetAttribute( const wxString
& name
, const wxString
& defVal
) const;
1003 /** Returns named attribute, as long, if found. Otherwise defVal is returned.
1005 long GetAttributeAsLong( const wxString
& name
, long defVal
) const;
1007 /** Returns named attribute, as double, if found. Otherwise defVal is returned.
1009 double GetAttributeAsDouble( const wxString
& name
, double defVal
) const;
1011 inline unsigned int GetArrIndex() const { return m_arrIndex
; }
1013 inline unsigned int GetDepth() const { return (unsigned int)m_depth
; }
1015 /** Gets flags as a'|' delimited string. Note that flag names are not
1016 prepended with 'wxPG_PROP_'.
1018 String will only be made to include flags combined by this parameter.
1020 wxString
GetFlagsAsString( FlagType flagsMask
) const;
1022 /** Returns position in parent's array. */
1023 unsigned int GetIndexInParent() const
1025 return (unsigned int)m_arrIndex
;
1028 /** Hides or reveals the property.
1030 true for hide, false for reveal.
1032 By default changes are applied recursively. Set this paramter wxPG_DONT_RECURSE to prevent this.
1034 inline bool Hide( bool hide
, int flags
= wxPG_RECURSE
);
1036 bool IsExpanded() const { return (!(m_flags
& wxPG_PROP_COLLAPSED
) && GetChildCount()); }
1038 /** Returns true if all parents expanded.
1040 bool IsVisible() const;
1042 bool IsEnabled() const
1044 return ( m_flags
& wxPG_PROP_DISABLED
) ? false : true;
1047 /** If property's editor is created this forces its recreation. Useful
1048 in SetAttribute etc. Returns true if actually did anything.
1050 bool RecreateEditor();
1052 /** If property's editor is active, then update it's value.
1054 void RefreshEditor();
1056 /** Sets an attribute for this property.
1058 Text identifier of attribute. See @ref propgrid_property_attributes.
1062 void SetAttribute( const wxString
& name
, wxVariant value
);
1064 void SetAttributes( const wxPGAttributeStorage
& attributes
);
1066 /** Sets editor for a property.
1069 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1070 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full list).
1072 For custom editors, use pointer you received from wxPropertyGrid::RegisterEditorClass().
1074 void SetEditor( const wxPGEditor
* editor
)
1076 m_customEditor
= editor
;
1079 /** Sets editor for a property.
1081 inline void SetEditor( const wxString
& editorName
);
1083 /** Sets cell information for given column.
1085 Note that the property takes ownership of given wxPGCell instance.
1087 void SetCell( int column
, wxPGCell
* cellObj
);
1089 /** Changes value of a property with choices, but only
1090 works if the value type is long or string. */
1091 void SetChoiceSelection( int newValue
, const wxPGChoiceInfo
& choiceInfo
);
1093 /** Sets common value selected for this property. -1 for none.
1095 void SetCommonValue( int commonValue
)
1097 m_commonValue
= commonValue
;
1100 /** Sets flags from a '|' delimited string. Note that flag names are not
1101 prepended with 'wxPG_PROP_'.
1103 void SetFlagsFromString( const wxString
& str
);
1105 /** Sets property's "is it modified?" flag. Affects children recursively.
1107 void SetModifiedStatus( bool modified
)
1109 SetFlagRecursively(wxPG_PROP_MODIFIED
, modified
);
1112 /** Call in OnEvent(), OnButtonClick() etc. to change the property value
1113 based on user input.
1116 This method is const since it doesn't actually modify value, but posts
1117 given variant as pending value, stored in wxPropertyGrid.
1119 void SetValueInEvent( wxVariant value
) const;
1121 /** Call this to set value of the property. Unlike methods in wxPropertyGrid,
1122 this does not automatically update the display.
1125 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run through
1126 validation process and send property change event.
1128 If you need to change property value in event, based on user input, use
1129 SetValueInEvent() instead.
1132 Pointer to list variant that contains child values. Used to indicate
1133 which children should be marked as modified.
1135 Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR).
1137 void SetValue( wxVariant value
, wxVariant
* pList
= NULL
, int flags
= 0 );
1139 /** Set wxBitmap in front of the value. This bitmap may be ignored
1140 by custom cell renderers.
1142 void SetValueImage( wxBitmap
& bmp
);
1144 /** If property has choices and they are not yet exclusive, new such copy
1145 of them will be created.
1147 void SetChoicesExclusive();
1149 void SetExpanded( bool expanded
)
1151 if ( !expanded
) m_flags
|= wxPG_PROP_COLLAPSED
;
1152 else m_flags
&= ~wxPG_PROP_COLLAPSED
;
1155 void SetFlag( FlagType flag
) { m_flags
|= flag
; }
1157 void SetFlagRecursively( FlagType flag
, bool set
);
1159 void SetHelpString( const wxString
& helpString
)
1161 m_helpString
= helpString
;
1164 /** Sets property's label.
1167 - Properties under same parent may have same labels. However,
1168 property names must still remain unique.
1170 void SetLabel( const wxString
& label
) { m_label
= label
; }
1172 inline void SetName( const wxString
& newName
);
1174 void SetValueToUnspecified()
1176 wxVariant val
; // Create NULL variant
1180 /** Sets wxValidator for a property*/
1181 void SetValidator( const wxValidator
& validator
)
1183 m_validator
= wxDynamicCast(validator
.Clone(),wxValidator
);
1186 /** Gets assignable version of property's validator. */
1187 wxValidator
* GetValidator() const
1191 return DoGetValidator();
1194 /** Updates property value in case there were last minute
1195 changes. If value was unspecified, it will be set to default.
1196 Use only for properties that have TextCtrl-based editor.
1198 If you have code similar to
1200 // Update the value in case of last minute changes
1201 if ( primary && propgrid->IsEditorsValueModified() )
1202 GetEditorClass()->CopyValueFromControl( this, primary );
1204 in wxPGProperty::OnEvent wxEVT_COMMAND_BUTTON_CLICKED handler,
1205 then replace it with call to this method.
1207 True if value changed.
1209 bool PrepareValueForDialogEditing( wxPropertyGrid
* propgrid
);
1211 /** Returns client data (void*) of a property.
1213 void* GetClientData() const
1215 return m_clientData
;
1218 /** Sets client data (void*) of a property.
1220 This untyped client data has to be deleted manually.
1222 void SetClientData( void* clientData
)
1224 m_clientData
= clientData
;
1227 /** Returns client object of a property.
1229 void SetClientObject(wxClientData
* clientObject
)
1231 delete m_clientObject
;
1232 m_clientObject
= clientObject
;
1235 /** Sets managed client object of a property.
1237 wxClientData
*GetClientObject() const { return m_clientObject
; }
1239 /** Sets new set of choices for property.
1242 This operation clears the property value.
1244 bool SetChoices( wxPGChoices
& choices
);
1246 /** Sets new set of choices for property.
1248 inline bool SetChoices( const wxArrayString
& labels
,
1249 const wxArrayInt
& values
= wxArrayInt() );
1251 /** Set max length of text in text editor.
1253 inline bool SetMaxLength( int maxLen
);
1255 /** Call with 'false' in OnSetValue to cancel value changes after all
1256 (ie. cancel 'true' returned by StringToValue() or IntToValue()).
1258 void SetWasModified( bool set
= true )
1260 if ( set
) m_flags
|= wxPG_PROP_WAS_MODIFIED
;
1261 else m_flags
&= ~wxPG_PROP_WAS_MODIFIED
;
1264 const wxString
& GetHelpString() const
1266 return m_helpString
;
1269 void ClearFlag( FlagType flag
) { m_flags
&= ~(flag
); }
1271 // Use, for example, to detect if item is inside collapsed section.
1272 bool IsSomeParent( wxPGProperty
* candidate_parent
) const;
1274 /** Adapts list variant into proper value using consequtive ChildChanged-calls.
1276 void AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const;
1278 /** This is used by properties that have fixed sub-properties. */
1279 void AddChild( wxPGProperty
* prop
);
1281 /** Returns height of children, recursively, and
1282 by taking expanded/collapsed status into account.
1284 iMax is used when finding property y-positions.
1286 int GetChildrenHeight( int lh
, int iMax
= -1 ) const;
1288 /** Returns number of child properties */
1289 unsigned int GetChildCount() const { return m_children
.GetCount(); }
1291 /** Returns sub-property at index i. */
1292 wxPGProperty
* Item( size_t i
) const { return (wxPGProperty
*)m_children
.Item(i
); }
1294 /** Returns last sub-property.
1296 wxPGProperty
* Last() const { return (wxPGProperty
*)m_children
.Last(); }
1298 /** Returns index of given sub-property. */
1299 int Index( const wxPGProperty
* p
) const { return m_children
.Index((wxPGProperty
*)p
); }
1301 /** Deletes all sub-properties. */
1304 // Puts correct indexes to children
1305 void FixIndexesOfChildren( size_t starthere
= 0 );
1307 wxPGProperty
* GetItemAtY( unsigned int y
, unsigned int lh
, unsigned int* nextItemY
) const;
1309 /** Returns (direct) child property with given name (or NULL if not found).
1311 wxPGProperty
* GetPropertyByName( const wxString
& name
) const;
1315 /** @class wxPGChoices
1317 Helper class for managing choices of wxPropertyGrid properties.
1318 Each entry can have label, value, bitmap, text colour, and background colour.
1320 @library{wxpropgrid}
1323 class WXDLLIMPEXP_PROPGRID wxPGChoices
1326 typedef long ValArrItem
;
1328 /** Default constructor. */
1334 /** Copy constructor. */
1335 wxPGChoices( const wxPGChoices
& a
)
1337 if ( a
.m_data
!= wxPGChoicesEmptyData
)
1340 m_data
->m_refCount
++;
1345 wxPGChoices( const wxChar
** labels
, const long* values
= NULL
)
1352 wxPGChoices( const wxArrayString
& labels
, const wxArrayInt
& values
= wxArrayInt() )
1358 /** Simple interface constructor. */
1359 wxPGChoices( wxPGChoicesData
* data
)
1372 /** Adds to current. If did not have own copies, creates them now. If was empty,
1373 identical to set except that creates copies.
1375 void Add( const wxChar
** labels
, const ValArrItem
* values
= NULL
);
1377 /** Version that works with wxArrayString. */
1378 void Add( const wxArrayString
& arr
, const ValArrItem
* values
= NULL
);
1380 /** Version that works with wxArrayString and wxArrayInt. */
1381 void Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
);
1383 /** Adds single item. */
1384 wxPGChoiceEntry
& Add( const wxString
& label
, int value
= wxPG_INVALID_VALUE
);
1386 /** Adds a single item, with bitmap. */
1387 wxPGChoiceEntry
& Add( const wxString
& label
, const wxBitmap
& bitmap
, int value
= wxPG_INVALID_VALUE
);
1389 /** Adds a single item with full entry information. */
1390 wxPGChoiceEntry
& Add( const wxPGChoiceEntry
& entry
)
1392 return Insert(entry
, -1);
1395 /** Adds single item. */
1396 wxPGChoiceEntry
& AddAsSorted( const wxString
& label
, int value
= wxPG_INVALID_VALUE
);
1398 void Assign( const wxPGChoices
& a
)
1400 AssignData(a
.m_data
);
1403 void AssignData( wxPGChoicesData
* data
);
1405 /** Delete all choices. */
1408 if ( m_data
!= wxPGChoicesEmptyData
)
1414 if ( m_data
== wxPGChoicesEmptyData
)
1415 m_data
= new wxPGChoicesData();
1418 /** Gets a unsigned number identifying this list. */
1419 wxPGChoicesId
GetId() const { return (wxPGChoicesId
) m_data
; };
1421 const wxString
& GetLabel( size_t ind
) const
1423 wxASSERT( ind
>= 0 && ind
< GetCount() );
1424 return Item(ind
).GetText();
1427 size_t GetCount () const
1429 wxASSERT_MSG( m_data
,
1430 wxT("When checking if wxPGChoices is valid, use IsOk() instead of GetCount()") );
1431 return m_data
->GetCount();
1434 int GetValue( size_t ind
) const { return Item(ind
).GetValue(); }
1436 /** Returns array of values matching the given strings. Unmatching strings
1437 result in wxPG_INVALID_VALUE entry in array.
1439 wxArrayInt
GetValuesForStrings( const wxArrayString
& strings
) const;
1441 /** Returns array of indices matching given strings. Unmatching strings
1442 are added to 'unmatched', if not NULL.
1444 wxArrayInt
GetIndicesForStrings( const wxArrayString
& strings
, wxArrayString
* unmatched
= NULL
) const;
1446 /** Returns true if choices in general are likely to have values
1447 (depens on that all entries have values or none has)
1449 bool HasValues() const;
1451 bool HasValue( unsigned int i
) const { return (m_data
->GetCount() > i
&& m_data
->Item(i
)->HasValue()); }
1453 int Index( const wxString
& str
) const;
1454 int Index( int val
) const;
1456 /** Inserts single item. */
1457 wxPGChoiceEntry
& Insert( const wxString
& label
, int index
, int value
= wxPG_INVALID_VALUE
);
1459 /** Inserts a single item with full entry information. */
1460 wxPGChoiceEntry
& Insert( const wxPGChoiceEntry
& entry
, int index
);
1462 /** Returns false if this is a constant empty set of choices,
1463 which should not be modified.
1467 return ( m_data
!= wxPGChoicesEmptyData
);
1470 const wxPGChoiceEntry
& Item( unsigned int i
) const
1473 return *m_data
->Item(i
);
1476 wxPGChoiceEntry
& Item( unsigned int i
)
1479 return *m_data
->Item(i
);
1482 /** Removes count items starting at position nIndex. */
1483 void RemoveAt(size_t nIndex
, size_t count
= 1);
1485 /** Does not create copies for itself. */
1486 void Set( const wxChar
** labels
, const long* values
= NULL
)
1492 /** Version that works with wxArrayString.
1493 TODO: Deprecate this.
1495 void Set( wxArrayString
& arr
, const long* values
= (const long*) NULL
)
1501 /** Version that works with wxArrayString and wxArrayInt. */
1502 void Set( const wxArrayString
& labels
, const wxArrayInt
& values
= wxArrayInt() )
1511 // Creates exclusive copy of current choices
1514 if ( m_data
->m_refCount
!= 1 )
1516 wxPGChoicesData
* data
= new wxPGChoicesData();
1517 data
->CopyDataFrom(m_data
);
1523 // Returns data, increases refcount.
1524 wxPGChoicesData
* GetData()
1526 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
1527 m_data
->m_refCount
++;
1531 // Returns plain data ptr - no refcounting stuff is done.
1532 wxPGChoicesData
* GetDataPtr() const { return m_data
; }
1534 // Changes ownership of data to you.
1535 wxPGChoicesData
* ExtractData()
1537 wxPGChoicesData
* data
= m_data
;
1538 m_data
= wxPGChoicesEmptyData
;
1542 wxArrayString
GetLabels() const;
1544 void operator= (const wxPGChoices
& a
)
1546 AssignData(a
.m_data
);
1549 wxPGChoiceEntry
& operator[](unsigned int i
)
1554 const wxPGChoiceEntry
& operator[](unsigned int i
) const
1560 // -----------------------------------------------------------------------