1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgrid/property.h
3 // Purpose: wxPGProperty and related support classes
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PROPGRID_PROPERTY_H_
13 #define _WX_PROPGRID_PROPERTY_H_
17 #include "wx/propgrid/propgriddefs.h"
19 // -----------------------------------------------------------------------
21 #define wxNullProperty ((wxPGProperty*)NULL)
24 /** @class wxPGPaintData
26 Contains information relayed to property's OnCustomPaint.
30 /** wxPropertyGrid. */
31 const wxPropertyGrid
* m_parent
;
34 Normally -1, otherwise index to drop-down list item that has to be
39 /** Set to drawn width in OnCustomPaint (optional). */
43 In a measure item call, set this to the height of item at m_choiceItem
50 // Structure for relaying choice/list info.
53 wxPGChoices
* m_choices
;
60 // space between vertical sides of a custom image
61 #define wxPG_CUSTOM_IMAGE_SPACINGY 1
63 // space between caption and selection rectangle,
64 #define wxPG_CAPRECTXMARGIN 2
66 // horizontally and vertically
67 #define wxPG_CAPRECTYMARGIN 1
70 /** @class wxPGCellRenderer
72 Base class for wxPropertyGrid cell renderers.
74 class WXDLLIMPEXP_PROPGRID wxPGCellRenderer
78 wxPGCellRenderer( unsigned int refCount
= 1 )
79 : m_refCount(refCount
) { }
80 virtual ~wxPGCellRenderer() { }
85 Selected
= 0x00010000,
89 virtual void Render( wxDC
& dc
,
91 const wxPropertyGrid
* propertyGrid
,
92 wxPGProperty
* property
,
95 int flags
) const = 0;
97 /** Returns size of the image in front of the editable area.
99 If property is NULL, then this call is for a custom value. In that case
100 the item is index to wxPropertyGrid's custom values.
102 virtual wxSize
GetImageSize( const wxPGProperty
* property
,
106 /** Paints property category selection rectangle.
108 virtual void DrawCaptionSelectionRect( wxDC
& dc
,
110 int w
, int h
) const;
112 /** Utility to draw vertically centered text.
114 void DrawText( wxDC
& dc
,
117 const wxString
& text
) const;
120 Utility to draw editor's value, or vertically aligned text if editor is
123 void DrawEditorValue( wxDC
& dc
, const wxRect
& rect
,
124 int xOffset
, const wxString
& text
,
125 wxPGProperty
* property
,
126 const wxPGEditor
* editor
) const;
128 /** Utility to render cell bitmap and set text colour plus bg brush colour.
130 Returns image width that, for instance, can be passed to DrawText.
132 int PreDrawCell( wxDC
& dc
,
134 const wxPGCell
& cell
,
151 unsigned int m_refCount
;
157 Base class for simple wxPropertyGrid cell information.
159 class WXDLLIMPEXP_PROPGRID wxPGCell
163 wxPGCell( const wxString
& text
,
164 const wxBitmap
& bitmap
= wxNullBitmap
,
165 const wxColour
& fgCol
= wxNullColour
,
166 const wxColour
& bgCol
= wxNullColour
);
168 virtual ~wxPGCell() { }
170 void SetText( const wxString
& text
) { m_text
= text
; }
171 void SetBitmap( const wxBitmap
& bitmap
) { m_bitmap
= bitmap
; }
172 void SetFgCol( const wxColour
& col
) { m_fgCol
= col
; }
173 void SetBgCol( const wxColour
& col
) { m_bgCol
= col
; }
175 const wxString
& GetText() const { return m_text
; }
176 const wxBitmap
& GetBitmap() const { return m_bitmap
; }
177 const wxColour
& GetFgCol() const { return m_fgCol
; }
178 const wxColour
& GetBgCol() const { return m_bgCol
; }
188 /** @class wxPGDefaultRenderer
190 Default cell renderer, that can handles the common
193 class WXDLLIMPEXP_PROPGRID wxPGDefaultRenderer
: public wxPGCellRenderer
196 virtual void Render( wxDC
& dc
,
198 const wxPropertyGrid
* propertyGrid
,
199 wxPGProperty
* property
,
204 virtual wxSize
GetImageSize( const wxPGProperty
* property
,
211 // -----------------------------------------------------------------------
213 /** @class wxPGAttributeStorage
215 wxPGAttributeStorage is somewhat optimized storage for
216 key=variant pairs (ie. a map).
218 class WXDLLIMPEXP_PROPGRID wxPGAttributeStorage
221 wxPGAttributeStorage();
222 ~wxPGAttributeStorage();
224 void Set( const wxString
& name
, const wxVariant
& value
);
225 size_t GetCount() const { return m_map
.size(); }
226 wxVariant
FindValue( const wxString
& name
) const
228 wxPGHashMapS2P::const_iterator it
= m_map
.find(name
);
229 if ( it
!= m_map
.end() )
231 wxVariantData
* data
= (wxVariantData
*) it
->second
;
233 return wxVariant(data
, it
->first
);
238 typedef wxPGHashMapS2P::const_iterator const_iterator
;
239 const_iterator
StartIteration() const
241 return m_map
.begin();
243 bool GetNext( const_iterator
& it
, wxVariant
& variant
) const
245 if ( it
== m_map
.end() )
248 wxVariantData
* data
= (wxVariantData
*) it
->second
;
250 variant
.SetData(data
);
251 variant
.SetName(it
->first
);
257 wxPGHashMapS2P m_map
;
262 // -----------------------------------------------------------------------
264 /** @section propgrid_propflags wxPGProperty Flags
268 enum wxPG_PROPERTY_FLAGS
271 /** Indicates bold font.
273 wxPG_PROP_MODIFIED
= 0x0001,
275 /** Disables ('greyed' text and editor does not activate) property.
277 wxPG_PROP_DISABLED
= 0x0002,
279 /** Hider button will hide this property.
281 wxPG_PROP_HIDDEN
= 0x0004,
283 /** This property has custom paint image just in front of its value.
284 If property only draws custom images into a popup list, then this
285 flag should not be set.
287 wxPG_PROP_CUSTOMIMAGE
= 0x0008,
289 /** Do not create text based editor for this property (but button-triggered
290 dialog and choice are ok).
292 wxPG_PROP_NOEDITOR
= 0x0010,
294 /** Property is collapsed, ie. it's children are hidden.
296 wxPG_PROP_COLLAPSED
= 0x0020,
299 If property is selected, then indicates that validation failed for pending
302 If property is not selected, then indicates that the the actual property
303 value has failed validation (NB: this behavior is not currently supported,
304 but may be used in future).
306 wxPG_PROP_INVALID_VALUE
= 0x0040,
310 /** Switched via SetWasModified(). Temporary flag - only used when
311 setting/changing property value.
313 wxPG_PROP_WAS_MODIFIED
= 0x0200,
316 If set, then child properties (if any) are private, and should be
317 "invisible" to the application.
319 wxPG_PROP_AGGREGATE
= 0x0400,
321 /** If set, then child properties (if any) are copies and should not
324 wxPG_PROP_CHILDREN_ARE_COPIES
= 0x0800,
327 Classifies this item as a non-category.
329 Used for faster item type identification.
331 wxPG_PROP_PROPERTY
= 0x1000,
334 Classifies this item as a category.
336 Used for faster item type identification.
338 wxPG_PROP_CATEGORY
= 0x2000,
340 /** Classifies this item as a property that has children, but is not aggregate
341 (ie children are not private).
343 wxPG_PROP_MISC_PARENT
= 0x4000,
345 /** Property is read-only. Editor is still created.
347 wxPG_PROP_READONLY
= 0x8000,
350 // NB: FLAGS ABOVE 0x8000 CANNOT BE USED WITH PROPERTY ITERATORS
353 /** Property's value is composed from values of child properties.
355 This flag cannot be used with property iterators.
357 wxPG_PROP_COMPOSED_VALUE
= 0x00010000,
359 /** Common value of property is selectable in editor.
361 This flag cannot be used with property iterators.
363 wxPG_PROP_USES_COMMON_VALUE
= 0x00020000,
365 /** Property can be set to unspecified value via editor.
366 Currently, this applies to following properties:
367 - wxIntProperty, wxUIntProperty, wxFloatProperty, wxEditEnumProperty:
371 This flag cannot be used with property iterators.
373 wxPG_PROP_AUTO_UNSPECIFIED
= 0x00040000,
375 /** Indicates the bit useable by derived properties.
377 wxPG_PROP_CLASS_SPECIFIC_1
= 0x00080000,
379 /** Indicates the bit useable by derived properties.
381 wxPG_PROP_CLASS_SPECIFIC_2
= 0x00100000
387 #define wxPG_PROP_MAX wxPG_PROP_AUTO_UNSPECIFIED
389 /** Property with children must have one of these set, otherwise iterators
390 will not work correctly.
391 Code should automatically take care of this, however.
393 #define wxPG_PROP_PARENTAL_FLAGS \
394 (wxPG_PROP_AGGREGATE|wxPG_PROP_CATEGORY|wxPG_PROP_MISC_PARENT)
399 // Amalgam of flags that should be inherited by sub-properties
400 #define wxPG_INHERITED_PROPFLAGS (wxPG_PROP_HIDDEN|wxPG_PROP_NOEDITOR)
402 // Combination of flags that can be stored by GetFlagsAsString
403 #define wxPG_STRING_STORED_FLAGS \
404 (wxPG_PROP_DISABLED|wxPG_PROP_HIDDEN|wxPG_PROP_NOEDITOR|wxPG_PROP_COLLAPSED)
406 // -----------------------------------------------------------------------
411 @section propgrid_property_attributes wxPropertyGrid Property Attribute
414 wxPGProperty::SetAttribute() and
415 wxPropertyGridInterface::SetPropertyAttribute() accept one of these as
416 attribute name argument.
418 You can use strings instead of constants. However, some of these
419 constants are redefined to use cached strings which may reduce
420 your binary size by some amount.
425 /** Set default value for property.
427 #define wxPG_ATTR_DEFAULT_VALUE wxS("DefaultValue")
429 /** Universal, int or double. Minimum value for numeric properties.
431 #define wxPG_ATTR_MIN wxS("Min")
433 /** Universal, int or double. Maximum value for numeric properties.
435 #define wxPG_ATTR_MAX wxS("Max")
437 /** Universal, string. When set, will be shown as text after the displayed
438 text value. Alternatively, if third column is enabled, text will be shown
439 there (for any type of property).
441 #define wxPG_ATTR_UNITS wxS("Units")
443 /** Universal, string. When set, will be shown in property's value cell
444 when displayed value string is empty, or value is unspecified.
446 #define wxPG_ATTR_INLINE_HELP wxS("InlineHelp")
448 /** wxBoolProperty specific, int, default 0. When 1 sets bool property to
449 use checkbox instead of choice.
451 #define wxPG_BOOL_USE_CHECKBOX wxS("UseCheckbox")
453 /** wxBoolProperty specific, int, default 0. When 1 sets bool property value
454 to cycle on double click (instead of showing the popup listbox).
456 #define wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING wxS("UseDClickCycling")
459 wxFloatProperty (and similar) specific, int, default -1.
461 Sets the (max) precision used when floating point value is rendered as
462 text. The default -1 means infinite precision.
464 #define wxPG_FLOAT_PRECISION wxS("Precision")
467 The text will be echoed as asterisks (wxTE_PASSWORD will be passed to
470 #define wxPG_STRING_PASSWORD wxS("Password")
472 /** Define base used by a wxUIntProperty. Valid constants are
473 wxPG_BASE_OCT, wxPG_BASE_DEC, wxPG_BASE_HEX and wxPG_BASE_HEXL
474 (lowercase characters).
476 #define wxPG_UINT_BASE wxS("Base")
478 /** Define prefix rendered to wxUIntProperty. Accepted constants
479 wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and wxPG_PREFIX_DOLLAR_SIGN.
480 <b>Note:</b> Only wxPG_PREFIX_NONE works with Decimal and Octal
483 #define wxPG_UINT_PREFIX wxS("Prefix")
486 wxFileProperty/wxImageFileProperty specific, wxChar*, default is
488 Sets the wildcard used in the triggered wxFileDialog. Format is the same.
490 #define wxPG_FILE_WILDCARD wxS("Wildcard")
492 /** wxFileProperty/wxImageFileProperty specific, int, default 1.
493 When 0, only the file name is shown (i.e. drive and directory are hidden).
495 #define wxPG_FILE_SHOW_FULL_PATH wxS("ShowFullPath")
497 /** Specific to wxFileProperty and derived properties, wxString, default empty.
498 If set, then the filename is shown relative to the given path string.
500 #define wxPG_FILE_SHOW_RELATIVE_PATH wxS("ShowRelativePath")
503 Specific to wxFileProperty and derived properties, wxString, default is
506 Sets the initial path of where to look for files.
508 #define wxPG_FILE_INITIAL_PATH wxS("InitialPath")
510 /** Specific to wxFileProperty and derivatives, wxString, default is empty.
511 Sets a specific title for the dir dialog.
513 #define wxPG_FILE_DIALOG_TITLE wxS("DialogTitle")
515 /** Specific to wxDirProperty, wxString, default is empty.
516 Sets a specific message for the dir dialog.
518 #define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage")
520 /** Sets displayed date format for wxDateProperty.
522 #define wxPG_DATE_FORMAT wxS("DateFormat")
524 /** Sets wxDatePickerCtrl window style used with wxDateProperty. Default
525 is wxDP_DEFAULT | wxDP_SHOWCENTURY.
527 #define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
529 /** SpinCtrl editor, int or double. How much number changes when button is
530 pressed (or up/down on keybard).
532 #define wxPG_ATTR_SPINCTRL_STEP wxS("Step")
534 /** SpinCtrl editor, bool. If true, value wraps at Min/Max.
536 #define wxPG_ATTR_SPINCTRL_WRAP wxS("Wrap")
539 wxMultiChoiceProperty, int.
540 If 0, no user strings allowed. If 1, user strings appear before list
541 strings. If 2, user strings appear after list string.
543 #define wxPG_ATTR_MULTICHOICE_USERSTRINGMODE wxS("UserStringMode")
546 wxColourProperty and its kind, int, default 1.
548 Setting this attribute to 0 hides custom colour from property's list of
551 #define wxPG_COLOUR_ALLOW_CUSTOM wxS("AllowCustom")
556 // Redefine attribute macros to use cached strings
558 #define wxPG_ATTR_MIN wxPGGlobalVars->m_strMin
560 #define wxPG_ATTR_MAX wxPGGlobalVars->m_strMax
561 #undef wxPG_ATTR_UNITS
562 #define wxPG_ATTR_UNITS wxPGGlobalVars->m_strUnits
563 #undef wxPG_ATTR_INLINE_HELP
564 #define wxPG_ATTR_INLINE_HELP wxPGGlobalVars->m_strInlineHelp
568 // -----------------------------------------------------------------------
570 /** @class wxPGProperty
572 wxPGProperty is base class for all wxPropertyGrid properties.
574 NB: Full class overview is now only present in
575 interface/wx/propgrid/property.h.
580 class WXDLLIMPEXP_PROPGRID wxPGProperty
: public wxObject
582 friend class wxPropertyGrid
;
583 friend class wxPropertyGridInterface
;
584 friend class wxPropertyGridPageState
;
585 friend class wxPropertyGridPopulator
;
586 friend class wxStringProperty
; // Proper "<composed>" support requires this
588 DECLARE_ABSTRACT_CLASS(wxPGProperty
)
591 typedef wxUint32 FlagType
;
593 /** Basic constructor.
598 Non-abstract property classes should have constructor of this style:
602 // If T is a class, then it should be a constant reference
603 // (e.g. const T& ) instead.
604 MyProperty( const wxString& label, const wxString& name, T value )
607 // Generally recommended way to set the initial value
608 // (as it should work in pretty much 100% of cases).
613 // If has private child properties then create them here, e.g.:
614 // AddChild( new wxStringProperty( "Subprop 1",
616 // value.GetSubProp1() ) );
621 wxPGProperty( const wxString
& label
, const wxString
& name
);
625 It is customary for derived properties to implement this.
627 virtual ~wxPGProperty();
629 /** This virtual function is called after m_value has been set.
632 - If m_value was set to Null variant (ie. unspecified value),
633 OnSetValue() will not be called.
634 - m_value may be of any variant type. Typically properties internally
635 support only one variant type, and as such OnSetValue() provides a
636 good opportunity to convert
637 supported values into internal type.
638 - Default implementation does nothing.
640 virtual void OnSetValue();
642 /** Override this to return something else than m_value as the value.
644 virtual wxVariant
DoGetValue() const { return m_value
; }
646 #if !defined(SWIG) || defined(CREATE_VCW)
647 /** Implement this function in derived class to check the value.
648 Return true if it is ok. Returning false prevents property change events
652 - Default implementation always returns true.
654 virtual bool ValidateValue( wxVariant
& value
,
655 wxPGValidationInfo
& validationInfo
) const;
658 Converts 'text' into proper value 'variant'.
659 Returns true if new (different than m_value) value could be interpreted
662 If wxPG_FULL_VALUE is set, returns complete, storable value instead
663 of displayable one (they may be different).
664 If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of
665 composite property string value (as generated by GetValueAsString()
666 called with this same flag).
669 Default implementation converts semicolon delimited tokens into child
670 values. Only works for properties with children.
672 virtual bool StringToValue( wxVariant
& variant
,
673 const wxString
& text
,
674 int argFlags
= 0 ) const;
677 Converts 'number' (including choice selection) into proper value
680 Returns true if new (different than m_value) value could be interpreted
684 If wxPG_FULL_VALUE is set, returns complete, storable value instead
688 - If property is not supposed to use choice or spinctrl or other editor
689 with int-based value, it is not necessary to implement this method.
690 - Default implementation simply assign given int to m_value.
691 - If property uses choice control, and displays a dialog on some choice
692 items, then it is preferred to display that dialog in IntToValue
695 virtual bool IntToValue( wxVariant
& value
,
697 int argFlags
= 0 ) const;
698 #endif // !defined(SWIG) || defined(CREATE_VCW)
701 /** Returns text representation of property's value.
704 If wxPG_FULL_VALUE is set, returns complete, storable string value
705 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
706 string value that must be editable in textctrl. If
707 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
708 display as a part of composite property string value.
711 Default implementation returns string composed from text
712 representations of child properties.
714 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
716 /** Converts string to a value, and if successful, calls SetValue() on it.
717 Default behavior is to do nothing.
719 String to get the value from.
721 true if value was changed.
723 bool SetValueFromString( const wxString
& text
, int flags
= 0 );
725 /** Converts integer to a value, and if succesful, calls SetValue() on it.
726 Default behavior is to do nothing.
728 Int to get the value from.
730 If has wxPG_FULL_VALUE, then the value given is a actual value and
733 True if value was changed.
735 bool SetValueFromInt( long value
, int flags
= 0 );
738 Returns size of the custom painted image in front of property.
740 This method must be overridden to return non-default value if
741 OnCustomPaint is to be called.
743 Normally -1, but can be an index to the property's list of items.
745 - Default behavior is to return wxSize(0,0), which means no image.
746 - Default image width or height is indicated with dimension -1.
747 - You can also return wxPG_DEFAULT_IMAGE_SIZE, i.e. wxSize(-1, -1).
749 virtual wxSize
OnMeasureImage( int item
= -1 ) const;
752 Events received by editor widgets are processed here.
754 Note that editor class usually processes most events. Some, such as
755 button press events of TextCtrlAndButton class, can be handled here.
756 Also, if custom handling for regular events is desired, then that can
757 also be done (for example, wxSystemColourProperty custom handles
758 wxEVT_COMMAND_CHOICE_SELECTED to display colour picker dialog when
759 'custom' selection is made).
761 If the event causes value to be changed, SetValueInEvent()
762 should be called to set the new value.
767 Should return true if any changes in value should be reported.
769 If property uses choice control, and displays a dialog on some choice
770 items, then it is preferred to display that dialog in IntToValue
773 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
774 wxWindow
* wnd_primary
,
778 Called after value of a child property has been altered.
780 Note that this function is usually called at the time that value of
781 this property, or given child property, is still pending for change.
783 Sample pseudo-code implementation:
786 void MyProperty::ChildChanged( wxVariant& thisValue,
788 wxVariant& childValue ) const
790 // Acquire reference to actual type of data stored in variant
791 // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros
792 // were used to create the variant class).
793 T& data = TFromVariant(thisValue);
795 // Copy childValue into data.
796 switch ( childIndex )
799 data.SetSubProp1( childvalue.GetLong() );
802 data.SetSubProp2( childvalue.GetString() );
810 Value of this property, that should be altered.
812 Index of child changed (you can use Item(childIndex) to get).
814 Value of the child property.
816 virtual void ChildChanged( wxVariant
& thisValue
,
818 wxVariant
& childValue
) const;
820 /** Returns pointer to an instance of used editor.
822 virtual const wxPGEditor
* DoGetEditorClass() const;
824 /** Returns pointer to the wxValidator that should be used
825 with the editor of this property (NULL for no validator).
826 Setting validator explicitly via SetPropertyValidator
829 In most situations, code like this should work well
830 (macros are used to maintain one actual validator instance,
831 so on the second call the function exits within the first
836 wxValidator* wxMyPropertyClass::DoGetValidator () const
838 WX_PG_DOGETVALIDATOR_ENTRY()
840 wxMyValidator* validator = new wxMyValidator(...);
842 ... prepare validator...
844 WX_PG_DOGETVALIDATOR_EXIT(validator)
850 You can get common filename validator by returning
851 wxFileProperty::GetClassValidator(). wxDirProperty,
852 for example, uses it.
854 virtual wxValidator
* DoGetValidator () const;
857 Returns current value's index to the choice control.
859 May also return, through pointer arguments, strings that should be
860 inserted to that control. Irrelevant to classes which do not employ
861 wxPGEditor_Choice or similar.
864 - If returns NULL in choiceinfo.m_choices, then this class must be
865 derived from wxBaseEnumProperty.
866 - Must be able to cope situation where property's set of choices is
869 virtual int GetChoiceInfo( wxPGChoiceInfo
* choiceinfo
);
872 Override to paint an image in front of the property value text or
873 drop-down list item (but only if wxPGProperty::OnMeasureImage is
876 If property's OnMeasureImage() returns size that has height != 0 but
877 less than row height ( < 0 has special meanings), wxPropertyGrid calls
878 this method to draw a custom image in a limited area in front of the
879 editor control or value text/graphics, and if control has drop-down
880 list, then the image is drawn there as well (even in the case
881 OnMeasureImage() returned higher height than row height).
883 NOTE: Following applies when OnMeasureImage() returns a "flexible"
884 height ( using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable
885 height items: If rect.x is < 0, then this is a measure item call, which
886 means that dc is invalid and only thing that should be done is to set
887 paintdata.m_drawnHeight to the height of the image of item at index
888 paintdata.m_choiceItem. This call may be done even as often as once
889 every drop-down popup show.
894 Box reserved for custom graphics. Includes surrounding rectangle,
895 if any. If x is < 0, then this is a measure item call (see above).
897 wxPGPaintData structure with much useful data.
900 - You can actually exceed rect width, but if you do so then
901 paintdata.m_drawnWidth must be set to the full width drawn in
903 - Due to technical reasons, rect's height will be default even if
904 custom height was reported during measure call.
905 - Brush is guaranteed to be default background colour. It has been
906 already used to clear the background of area being painted. It
908 - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper
909 colour) pen for drawing framing rectangle. It can be changed as
912 @see GetValueAsString()
914 virtual void OnCustomPaint( wxDC
& dc
,
916 wxPGPaintData
& paintdata
);
919 Returns used wxPGCellRenderer instance for given property column
922 Default implementation returns editor's renderer for all columns.
924 virtual wxPGCellRenderer
* GetCellRenderer( int column
) const;
927 Refresh values of child properties.
929 Automatically called after value is set.
931 virtual void RefreshChildren();
933 /** Special handling for attributes of this property.
935 If returns false, then the attribute will be automatically stored in
938 Default implementation simply returns false.
940 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
942 /** Returns value of an attribute.
944 Override if custom handling of attributes is needed.
946 Default implementation simply return NULL variant.
948 virtual wxVariant
DoGetAttribute( const wxString
& name
) const;
950 /** Returns instance of a new wxPGEditorDialogAdapter instance, which is
951 used when user presses the (optional) button next to the editor control;
953 Default implementation returns NULL (ie. no action is generated when
956 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
959 Adds entry to property's wxPGChoices and editor control (if it is
962 Returns index of item added.
964 int AppendChoice( const wxString
& label
, int value
= wxPG_INVALID_VALUE
)
966 return InsertChoice(label
,-1,value
);
969 /** Returns wxPGCell of given column, NULL if none. If valid
970 object is returned, caller will gain its ownership.
972 wxPGCell
* AcquireCell( unsigned int column
)
974 if ( column
>= m_cells
.size() )
977 wxPGCell
* cell
= (wxPGCell
*) m_cells
[column
];
978 m_cells
[column
] = NULL
;
983 Returns true if children of this property are component values (for
984 instance, points size, face name, and is_underlined are component
987 bool AreChildrenComponents() const
989 if ( m_flags
& (wxPG_PROP_COMPOSED_VALUE
|wxPG_PROP_AGGREGATE
) )
996 Removes entry from property's wxPGChoices and editor control (if it is
999 If selected item is deleted, then the value is set to unspecified.
1001 void DeleteChoice( int index
);
1004 Call to enable or disable usage of common value (integer value that can
1005 be selected for properties instead of their normal values) for this
1008 Common values are disabled by the default for all properties.
1010 void EnableCommonValue( bool enable
= true )
1012 if ( enable
) SetFlag( wxPG_PROP_USES_COMMON_VALUE
);
1013 else ClearFlag( wxPG_PROP_USES_COMMON_VALUE
);
1016 /** Composes text from values of child properties. */
1017 void GenerateComposedValue( wxString
& text
, int argFlags
= 0 ) const;
1019 /** Returns property's label. */
1020 const wxString
& GetLabel() const { return m_label
; }
1022 /** Returns property's name with all (non-category, non-root) parents. */
1023 wxString
GetName() const;
1026 Returns property's base name (ie parent's name is not added in any
1029 const wxString
& GetBaseName() const { return m_name
; }
1031 wxPGChoices
& GetChoices();
1033 const wxPGChoices
& GetChoices() const;
1035 const wxPGChoiceEntry
* GetCurrentChoice() const;
1037 /** Returns coordinate to the top y of the property. Note that the
1038 position of scrollbars is not taken into account.
1042 wxVariant
GetValue() const
1044 return DoGetValue();
1048 /** Returns reference to the internal stored value. GetValue is preferred
1049 way to get the actual value, since GetValueRef ignores DoGetValue,
1050 which may override stored value.
1052 wxVariant
& GetValueRef()
1057 const wxVariant
& GetValueRef() const
1063 /** Same as GetValueAsString, except takes common value into account.
1065 wxString
GetValueString( int argFlags
= 0 ) const;
1067 void UpdateControl( wxWindow
* primary
);
1069 /** Returns wxPGCell of given column, NULL if none. wxPGProperty
1070 will retain ownership of the cell object.
1072 wxPGCell
* GetCell( unsigned int column
) const
1074 if ( column
>= m_cells
.size() )
1077 return (wxPGCell
*) m_cells
[column
];
1080 unsigned int GetChoiceCount() const;
1082 wxString
GetChoiceString( unsigned int index
);
1084 /** Return number of displayed common values for this property.
1086 int GetDisplayedCommonValueCount() const;
1088 wxString
GetDisplayedString() const
1090 return GetValueString(0);
1093 /** Returns property grid where property lies. */
1094 wxPropertyGrid
* GetGrid() const;
1096 /** Returns owner wxPropertyGrid, but only if one is currently on a page
1097 displaying this property. */
1098 wxPropertyGrid
* GetGridIfDisplayed() const;
1100 /** Returns highest level non-category, non-root parent. Useful when you
1101 have nested wxCustomProperties/wxParentProperties.
1103 Thus, if immediate parent is root or category, this will return the
1106 wxPGProperty
* GetMainParent() const;
1108 /** Return parent of property */
1109 wxPGProperty
* GetParent() const { return m_parent
; }
1111 /** Returns true if property has editable wxTextCtrl when selected.
1114 Altough disabled properties do not displayed editor, they still
1115 return True here as being disabled is considered a temporary
1116 condition (unlike being read-only or having limited editing enabled).
1118 bool IsTextEditable() const;
1120 bool IsValueUnspecified() const
1122 return m_value
.IsNull();
1125 FlagType
HasFlag( FlagType flag
) const
1127 return ( m_flags
& flag
);
1130 /** Returns comma-delimited string of property attributes.
1132 const wxPGAttributeStorage
& GetAttributes() const
1134 return m_attributes
;
1137 /** Returns m_attributes as list wxVariant.
1139 wxVariant
GetAttributesAsList() const;
1141 FlagType
GetFlags() const
1146 const wxPGEditor
* GetEditorClass() const;
1148 wxString
GetValueType() const
1150 return m_value
.GetType();
1153 /** Returns editor used for given column. NULL for no editor.
1155 const wxPGEditor
* GetColumnEditor( int column
) const
1158 return GetEditorClass();
1163 /** Returns common value selected for this property. -1 for none.
1165 int GetCommonValue() const
1167 return m_commonValue
;
1170 /** Returns true if property has even one visible child.
1172 bool HasVisibleChildren() const;
1175 Adds entry to property's wxPGChoices and editor control (if it is
1178 Returns index of item added.
1180 int InsertChoice( const wxString
& label
,
1182 int value
= wxPG_INVALID_VALUE
);
1185 Returns true if this property is actually a wxPropertyCategory.
1187 bool IsCategory() const { return HasFlag(wxPG_PROP_CATEGORY
)?true:false; }
1189 /** Returns true if this property is actually a wxRootProperty.
1191 bool IsRoot() const { return (m_parent
== NULL
); }
1193 /** Returns true if this is a sub-property. */
1194 bool IsSubProperty() const
1196 wxPGProperty
* parent
= (wxPGProperty
*)m_parent
;
1197 if ( parent
&& !parent
->IsCategory() )
1202 /** Returns last visible sub-property, recursively.
1204 const wxPGProperty
* GetLastVisibleSubItem() const;
1206 wxVariant
GetDefaultValue() const;
1208 int GetMaxLength() const
1210 return (int) m_maxLen
;
1214 Determines, recursively, if all children are not unspecified.
1216 Takes values in given list into account.
1218 bool AreAllChildrenSpecified( wxVariant
* pendingList
= NULL
) const;
1220 /** Updates composed values of parent non-category properties, recursively.
1221 Returns topmost property updated.
1224 - Must not call SetValue() (as can be called in it).
1226 wxPGProperty
* UpdateParentValues();
1228 /** Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
1230 FlagType
UsesAutoUnspecified() const
1232 return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED
);
1235 wxBitmap
* GetValueImage() const
1237 return m_valueBitmap
;
1240 wxVariant
GetAttribute( const wxString
& name
) const;
1243 Returns named attribute, as string, if found.
1245 Otherwise defVal is returned.
1247 wxString
GetAttribute( const wxString
& name
, const wxString
& defVal
) const;
1250 Returns named attribute, as long, if found.
1252 Otherwise defVal is returned.
1254 long GetAttributeAsLong( const wxString
& name
, long defVal
) const;
1257 Returns named attribute, as double, if found.
1259 Otherwise defVal is returned.
1261 double GetAttributeAsDouble( const wxString
& name
, double defVal
) const;
1263 unsigned int GetArrIndex() const { return m_arrIndex
; }
1265 unsigned int GetDepth() const { return (unsigned int)m_depth
; }
1267 /** Gets flags as a'|' delimited string. Note that flag names are not
1268 prepended with 'wxPG_PROP_'.
1270 String will only be made to include flags combined by this parameter.
1272 wxString
GetFlagsAsString( FlagType flagsMask
) const;
1274 /** Returns position in parent's array. */
1275 unsigned int GetIndexInParent() const
1277 return (unsigned int)m_arrIndex
;
1280 /** Hides or reveals the property.
1282 true for hide, false for reveal.
1284 By default changes are applied recursively. Set this paramter
1285 wxPG_DONT_RECURSE to prevent this.
1287 inline bool Hide( bool hide
, int flags
= wxPG_RECURSE
);
1289 bool IsExpanded() const
1290 { return (!(m_flags
& wxPG_PROP_COLLAPSED
) && GetChildCount()); }
1292 /** Returns true if all parents expanded.
1294 bool IsVisible() const;
1296 bool IsEnabled() const { return !(m_flags
& wxPG_PROP_DISABLED
); }
1298 /** If property's editor is created this forces its recreation.
1299 Useful in SetAttribute etc. Returns true if actually did anything.
1301 bool RecreateEditor();
1303 /** If property's editor is active, then update it's value.
1305 void RefreshEditor();
1307 /** Sets an attribute for this property.
1309 Text identifier of attribute. See @ref propgrid_property_attributes.
1313 void SetAttribute( const wxString
& name
, wxVariant value
);
1315 void SetAttributes( const wxPGAttributeStorage
& attributes
);
1318 /** Sets editor for a property.
1321 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1322 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full
1325 For custom editors, use pointer you received from
1326 wxPropertyGrid::RegisterEditorClass().
1328 void SetEditor( const wxPGEditor
* editor
)
1330 m_customEditor
= editor
;
1334 /** Sets editor for a property.
1336 inline void SetEditor( const wxString
& editorName
);
1338 /** Sets cell information for given column.
1340 Note that the property takes ownership of given wxPGCell instance.
1342 void SetCell( int column
, wxPGCell
* cellObj
);
1344 /** Changes value of a property with choices, but only
1345 works if the value type is long or string. */
1346 void SetChoiceSelection( int newValue
, const wxPGChoiceInfo
& choiceInfo
);
1348 /** Sets common value selected for this property. -1 for none.
1350 void SetCommonValue( int commonValue
)
1352 m_commonValue
= commonValue
;
1355 /** Sets flags from a '|' delimited string. Note that flag names are not
1356 prepended with 'wxPG_PROP_'.
1358 void SetFlagsFromString( const wxString
& str
);
1360 /** Sets property's "is it modified?" flag. Affects children recursively.
1362 void SetModifiedStatus( bool modified
)
1364 SetFlagRecursively(wxPG_PROP_MODIFIED
, modified
);
1367 /** Call in OnEvent(), OnButtonClick() etc. to change the property value
1368 based on user input.
1371 This method is const since it doesn't actually modify value, but posts
1372 given variant as pending value, stored in wxPropertyGrid.
1374 void SetValueInEvent( wxVariant value
) const;
1377 Call this to set value of the property.
1379 Unlike methods in wxPropertyGrid, this does not automatically update
1383 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run
1384 through validation process and send property change event.
1386 If you need to change property value in event, based on user input, use
1387 SetValueInEvent() instead.
1390 Pointer to list variant that contains child values. Used to indicate
1391 which children should be marked as modified.
1393 Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR).
1395 void SetValue( wxVariant value
, wxVariant
* pList
= NULL
, int flags
= 0 );
1397 /** Set wxBitmap in front of the value. This bitmap may be ignored
1398 by custom cell renderers.
1400 void SetValueImage( wxBitmap
& bmp
);
1402 /** If property has choices and they are not yet exclusive, new such copy
1403 of them will be created.
1405 void SetChoicesExclusive();
1407 void SetExpanded( bool expanded
)
1409 if ( !expanded
) m_flags
|= wxPG_PROP_COLLAPSED
;
1410 else m_flags
&= ~wxPG_PROP_COLLAPSED
;
1413 void SetFlag( FlagType flag
) { m_flags
|= flag
; }
1415 void SetFlagRecursively( FlagType flag
, bool set
);
1417 void SetHelpString( const wxString
& helpString
)
1419 m_helpString
= helpString
;
1422 void SetLabel( const wxString
& label
) { m_label
= label
; }
1424 inline void SetName( const wxString
& newName
);
1426 void SetValueToUnspecified()
1428 wxVariant val
; // Create NULL variant
1432 #if wxUSE_VALIDATORS
1433 /** Sets wxValidator for a property*/
1434 void SetValidator( const wxValidator
& validator
)
1436 m_validator
= wxDynamicCast(validator
.Clone(),wxValidator
);
1439 /** Gets assignable version of property's validator. */
1440 wxValidator
* GetValidator() const
1444 return DoGetValidator();
1446 #endif // #if wxUSE_VALIDATORS
1448 /** Updates property value in case there were last minute
1449 changes. If value was unspecified, it will be set to default.
1450 Use only for properties that have TextCtrl-based editor.
1452 If you have code similar to
1454 // Update the value in case of last minute changes
1455 if ( primary && propgrid->IsEditorsValueModified() )
1456 GetEditorClass()->CopyValueFromControl( this, primary );
1458 in wxPGProperty::OnEvent wxEVT_COMMAND_BUTTON_CLICKED handler,
1459 then replace it with call to this method.
1461 True if value changed.
1463 bool PrepareValueForDialogEditing( wxPropertyGrid
* propgrid
);
1466 /** Returns client data (void*) of a property.
1468 void* GetClientData() const
1470 return m_clientData
;
1473 /** Sets client data (void*) of a property.
1475 This untyped client data has to be deleted manually.
1477 void SetClientData( void* clientData
)
1479 m_clientData
= clientData
;
1482 /** Returns client object of a property.
1484 void SetClientObject(wxClientData
* clientObject
)
1486 delete m_clientObject
;
1487 m_clientObject
= clientObject
;
1490 /** Sets managed client object of a property.
1492 wxClientData
*GetClientObject() const { return m_clientObject
; }
1495 /** Sets new set of choices for property.
1498 This operation clears the property value.
1500 bool SetChoices( wxPGChoices
& choices
);
1502 /** Sets new set of choices for property.
1504 inline bool SetChoices( const wxArrayString
& labels
,
1505 const wxArrayInt
& values
= wxArrayInt() );
1507 /** Set max length of text in text editor.
1509 inline bool SetMaxLength( int maxLen
);
1511 /** Call with 'false' in OnSetValue to cancel value changes after all
1512 (ie. cancel 'true' returned by StringToValue() or IntToValue()).
1514 void SetWasModified( bool set
= true )
1516 if ( set
) m_flags
|= wxPG_PROP_WAS_MODIFIED
;
1517 else m_flags
&= ~wxPG_PROP_WAS_MODIFIED
;
1520 const wxString
& GetHelpString() const
1522 return m_helpString
;
1525 void ClearFlag( FlagType flag
) { m_flags
&= ~(flag
); }
1527 // Use, for example, to detect if item is inside collapsed section.
1528 bool IsSomeParent( wxPGProperty
* candidate_parent
) const;
1531 Adapts list variant into proper value using consecutive
1534 void AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const;
1536 /** This is used by properties that have fixed sub-properties. */
1537 void AddChild( wxPGProperty
* prop
);
1539 /** Returns height of children, recursively, and
1540 by taking expanded/collapsed status into account.
1542 iMax is used when finding property y-positions.
1544 int GetChildrenHeight( int lh
, int iMax
= -1 ) const;
1546 /** Returns number of child properties */
1547 unsigned int GetChildCount() const { return m_children
.GetCount(); }
1549 /** Returns sub-property at index i. */
1550 wxPGProperty
* Item( size_t i
) const
1551 { return (wxPGProperty
*)m_children
.Item(i
); }
1553 /** Returns last sub-property.
1555 wxPGProperty
* Last() const { return (wxPGProperty
*)m_children
.Last(); }
1557 /** Returns index of given sub-property. */
1558 int Index( const wxPGProperty
* p
) const
1559 { return m_children
.Index((wxPGProperty
*)p
); }
1561 /** Deletes all sub-properties. */
1564 // Puts correct indexes to children
1565 void FixIndexesOfChildren( size_t starthere
= 0 );
1568 // Returns wxPropertyGridPageState in which this property resides.
1569 wxPropertyGridPageState
* GetParentState() const { return m_parentState
; }
1572 wxPGProperty
* GetItemAtY( unsigned int y
,
1574 unsigned int* nextItemY
) const;
1576 /** Returns (direct) child property with given name (or NULL if not found).
1578 wxPGProperty
* GetPropertyByName( const wxString
& name
) const;
1582 DocStr(GetClientData
,
1583 "Returns the client data object for a property", "");
1584 PyObject
* GetClientData() {
1585 wxPyClientData
* data
= (wxPyClientData
*)self
->GetClientObject();
1587 Py_INCREF(data
->m_obj
);
1595 DocStr(SetClientData
,
1596 "Associate the given client data.", "");
1597 void SetClientData(PyObject
* clientData
) {
1598 wxPyClientData
* data
= new wxPyClientData(clientData
);
1599 self
->SetClientObject(data
);
1603 GetClientObject
= GetClientData
1604 SetClientObject
= SetClientData
1610 static wxString
* sm_wxPG_LABEL
;
1612 /** This member is public so scripting language bindings
1613 wrapper code can access it freely.
1618 /** Returns text for given column.
1620 wxString
GetColumnText( unsigned int col
) const;
1622 /** Returns (direct) child property with given name (or NULL if not found),
1626 Start looking for the child at this index.
1629 Does not support scope (ie. Parent.Child notation).
1631 wxPGProperty
* GetPropertyByNameWH( const wxString
& name
,
1632 unsigned int hintIndex
) const;
1634 /** This is used by Insert etc. */
1635 void AddChild2( wxPGProperty
* prop
,
1637 bool correct_mode
= true );
1639 void DoSetName(const wxString
& str
) { m_name
= str
; }
1641 // Call for after sub-properties added with AddChild
1642 void PrepareSubProperties();
1644 void SetParentalType( int flag
)
1646 m_flags
&= ~(wxPG_PROP_PROPERTY
|wxPG_PROP_PARENTAL_FLAGS
);
1650 void SetParentState( wxPropertyGridPageState
* pstate
)
1651 { m_parentState
= pstate
; }
1653 // Call after fixed sub-properties added/removed after creation.
1654 // if oldSelInd >= 0 and < new max items, then selection is
1656 void SubPropsChanged( int oldSelInd
= -1 );
1658 int GetY2( int lh
) const;
1662 wxPGProperty
* m_parent
;
1663 wxPropertyGridPageState
* m_parentState
;
1665 wxClientData
* m_clientObject
;
1667 // Overrides editor returned by property class
1668 const wxPGEditor
* m_customEditor
;
1669 #if wxUSE_VALIDATORS
1670 // Editor is going to get this validator
1671 wxValidator
* m_validator
;
1673 // Show this in front of the value
1675 // TODO: Can bitmap be implemented with wxPGCell?
1676 wxBitmap
* m_valueBitmap
;
1679 wxPGAttributeStorage m_attributes
;
1680 wxArrayPtrVoid m_children
;
1682 // Extended cell information
1683 wxArrayPtrVoid m_cells
;
1685 // Help shown in statusbar or help box.
1686 wxString m_helpString
;
1688 // Index in parent's property array.
1689 unsigned int m_arrIndex
;
1691 // If not -1, then overrides m_value
1696 // Maximum length (mainly for string properties). Could be in some sort of
1697 // wxBaseStringProperty, but currently, for maximum flexibility and
1698 // compatibility, we'll stick it here. Anyway, we had 3 excess bytes to use
1699 // so short int will fit in just fine.
1702 // Root has 0, categories etc. at that level 1, etc.
1703 unsigned char m_depth
;
1705 // m_depthBgCol indicates width of background colour between margin and item
1706 // (essentially this is category's depth, if none then equals m_depth).
1707 unsigned char m_depthBgCol
;
1709 unsigned char m_bgColIndex
; // Background brush index.
1710 unsigned char m_fgColIndex
; // Foreground colour index.
1713 // Called in constructors.
1715 void Init( const wxString
& label
, const wxString
& name
);
1716 #endif // #ifndef SWIG
1719 // -----------------------------------------------------------------------
1722 // Property class declaration helper macros
1723 // (wxPGRootPropertyClass and wxPropertyCategory require this).
1726 #define WX_PG_DECLARE_DOGETEDITORCLASS \
1727 virtual const wxPGEditor* DoGetEditorClass() const;
1730 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
1732 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
1733 WX_PG_DECLARE_DOGETEDITORCLASS \
1736 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME)
1739 // Implements sans constructor function. Also, first arg is class name, not
1741 #define WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(PROPNAME,T,EDITOR) \
1742 const wxPGEditor* PROPNAME::DoGetEditorClass() const \
1744 return wxPGEditor_##EDITOR; \
1747 // -----------------------------------------------------------------------
1751 /** @class wxPGRootProperty
1753 Root parent property.
1755 class WXDLLIMPEXP_PROPGRID wxPGRootProperty
: public wxPGProperty
1758 WX_PG_DECLARE_PROPERTY_CLASS(wxPGRootProperty
)
1763 virtual ~wxPGRootProperty();
1765 virtual bool StringToValue( wxVariant
&, const wxString
&, int ) const
1773 // -----------------------------------------------------------------------
1775 /** @class wxPropertyCategory
1777 Category (caption) property.
1779 class WXDLLIMPEXP_PROPGRID wxPropertyCategory
: public wxPGProperty
1781 friend class wxPropertyGrid
;
1782 friend class wxPropertyGridPageState
;
1783 WX_PG_DECLARE_PROPERTY_CLASS(wxPropertyCategory
)
1786 /** Default constructor is only used in special cases. */
1787 wxPropertyCategory();
1789 wxPropertyCategory( const wxString
& label
,
1790 const wxString
& name
= wxPG_LABEL
);
1791 ~wxPropertyCategory();
1793 int GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const;
1796 virtual wxString
GetValueAsString( int argFlags
) const;
1798 void SetTextColIndex( unsigned int colInd
)
1799 { m_capFgColIndex
= (wxByte
) colInd
; }
1800 unsigned int GetTextColIndex() const
1801 { return (unsigned int) m_capFgColIndex
; }
1803 void CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
);
1805 int m_textExtent
; // pre-calculated length of text
1806 wxByte m_capFgColIndex
; // caption text colour index
1814 // -----------------------------------------------------------------------
1818 /** @class wxPGChoiceEntry
1819 Data of a single wxPGChoices choice.
1821 class WXDLLIMPEXP_PROPGRID wxPGChoiceEntry
: public wxPGCell
1825 wxPGChoiceEntry( const wxPGChoiceEntry
& entry
);
1826 wxPGChoiceEntry( const wxString
& label
,
1827 int value
= wxPG_INVALID_VALUE
)
1828 : wxPGCell(), m_value(value
)
1833 wxPGChoiceEntry( const wxString
& label
,
1835 const wxBitmap
& bitmap
,
1836 const wxColour
& fgCol
= wxNullColour
,
1837 const wxColour
& bgCol
= wxNullColour
)
1838 : wxPGCell(label
, bitmap
, fgCol
, bgCol
), m_value(value
)
1842 virtual ~wxPGChoiceEntry()
1846 void SetValue( int value
) { m_value
= value
; }
1848 int GetValue() const { return m_value
; }
1850 bool HasValue() const { return (m_value
!= wxPG_INVALID_VALUE
); }
1857 typedef void* wxPGChoicesId
;
1859 class WXDLLIMPEXP_PROPGRID wxPGChoicesData
1861 friend class wxPGChoices
;
1863 // Constructor sets m_refCount to 1.
1866 void CopyDataFrom( wxPGChoicesData
* data
);
1868 // Takes ownership of 'item'
1869 void Insert( int index
, wxPGChoiceEntry
* item
)
1871 wxArrayPtrVoid::iterator it
;
1875 index
= m_items
.size();
1879 it
= m_items
.begin() + index
;
1882 // Need to fix value?
1883 if ( item
->GetValue() == wxPG_INVALID_VALUE
)
1884 item
->SetValue(index
);
1886 m_items
.insert(it
, item
);
1889 // Delete all entries
1892 size_t GetCount() const { return m_items
.size(); }
1894 wxPGChoiceEntry
* Item( unsigned int i
) const
1896 wxCHECK_MSG( i
< GetCount(), NULL
, "invalid index" );
1898 return (wxPGChoiceEntry
*) m_items
[i
];
1904 wxASSERT( m_refCount
>= 0 );
1905 if ( m_refCount
== 0 )
1910 wxArrayPtrVoid m_items
;
1912 // So that multiple properties can use the same set
1915 virtual ~wxPGChoicesData();
1918 #define wxPGChoicesEmptyData ((wxPGChoicesData*)NULL)
1923 /** @class wxPGChoices
1925 Helper class for managing choices of wxPropertyGrid properties.
1926 Each entry can have label, value, bitmap, text colour, and background
1929 @library{wxpropgrid}
1932 class WXDLLIMPEXP_PROPGRID wxPGChoices
1935 typedef long ValArrItem
;
1937 /** Default constructor. */
1943 /** Copy constructor. */
1944 wxPGChoices( const wxPGChoices
& a
)
1946 if ( a
.m_data
!= wxPGChoicesEmptyData
)
1949 m_data
->m_refCount
++;
1954 wxPGChoices( const wxChar
** labels
, const long* values
= NULL
)
1961 wxPGChoices( const wxArrayString
& labels
,
1962 const wxArrayInt
& values
= wxArrayInt() )
1968 /** Simple interface constructor. */
1969 wxPGChoices( wxPGChoicesData
* data
)
1985 If did not have own copies, creates them now. If was empty, identical
1986 to set except that creates copies.
1988 void Add( const wxChar
** labels
, const ValArrItem
* values
= NULL
);
1990 /** Version that works with wxArrayString. */
1991 void Add( const wxArrayString
& arr
, const ValArrItem
* values
= NULL
);
1993 /** Version that works with wxArrayString and wxArrayInt. */
1994 void Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
);
1996 /** Adds single item. */
1997 wxPGChoiceEntry
& Add( const wxString
& label
,
1998 int value
= wxPG_INVALID_VALUE
);
2000 /** Adds a single item, with bitmap. */
2001 wxPGChoiceEntry
& Add( const wxString
& label
,
2002 const wxBitmap
& bitmap
,
2003 int value
= wxPG_INVALID_VALUE
);
2005 /** Adds a single item with full entry information. */
2006 wxPGChoiceEntry
& Add( const wxPGChoiceEntry
& entry
)
2008 return Insert(entry
, -1);
2011 /** Adds single item. */
2012 wxPGChoiceEntry
& AddAsSorted( const wxString
& label
,
2013 int value
= wxPG_INVALID_VALUE
);
2015 void Assign( const wxPGChoices
& a
)
2017 AssignData(a
.m_data
);
2020 void AssignData( wxPGChoicesData
* data
);
2022 /** Delete all choices. */
2025 if ( m_data
!= wxPGChoicesEmptyData
)
2031 if ( m_data
== wxPGChoicesEmptyData
)
2032 m_data
= new wxPGChoicesData();
2035 /** Gets a unsigned number identifying this list. */
2036 wxPGChoicesId
GetId() const { return (wxPGChoicesId
) m_data
; };
2038 const wxString
& GetLabel( size_t ind
) const
2040 return Item(ind
).GetText();
2043 size_t GetCount () const
2045 wxASSERT_MSG( m_data
, "When checking if wxPGChoices is valid, "
2046 "use IsOk() instead of GetCount()" );
2047 return m_data
->GetCount();
2050 int GetValue( size_t ind
) const { return Item(ind
).GetValue(); }
2052 /** Returns array of values matching the given strings. Unmatching strings
2053 result in wxPG_INVALID_VALUE entry in array.
2055 wxArrayInt
GetValuesForStrings( const wxArrayString
& strings
) const;
2057 /** Returns array of indices matching given strings. Unmatching strings
2058 are added to 'unmatched', if not NULL.
2060 wxArrayInt
GetIndicesForStrings( const wxArrayString
& strings
,
2061 wxArrayString
* unmatched
= NULL
) const;
2063 /** Returns true if choices in general are likely to have values
2064 (depens on that all entries have values or none has)
2066 bool HasValues() const;
2068 bool HasValue( unsigned int i
) const
2069 { return (i
< m_data
->GetCount()) && m_data
->Item(i
)->HasValue(); }
2071 int Index( const wxString
& str
) const;
2072 int Index( int val
) const;
2074 /** Inserts single item. */
2075 wxPGChoiceEntry
& Insert( const wxString
& label
,
2077 int value
= wxPG_INVALID_VALUE
);
2079 /** Inserts a single item with full entry information. */
2080 wxPGChoiceEntry
& Insert( const wxPGChoiceEntry
& entry
, int index
);
2082 /** Returns false if this is a constant empty set of choices,
2083 which should not be modified.
2087 return ( m_data
!= wxPGChoicesEmptyData
);
2090 const wxPGChoiceEntry
& Item( unsigned int i
) const
2093 return *m_data
->Item(i
);
2096 wxPGChoiceEntry
& Item( unsigned int i
)
2099 return *m_data
->Item(i
);
2102 /** Removes count items starting at position nIndex. */
2103 void RemoveAt(size_t nIndex
, size_t count
= 1);
2106 /** Does not create copies for itself. */
2107 void Set( const wxChar
** labels
, const long* values
= NULL
)
2113 /** Version that works with wxArrayString.
2114 TODO: Deprecate this.
2116 void Set( wxArrayString
& arr
, const long* values
= (const long*) NULL
)
2123 /** Version that works with wxArrayString and wxArrayInt. */
2124 void Set( const wxArrayString
& labels
,
2125 const wxArrayInt
& values
= wxArrayInt() )
2134 // Creates exclusive copy of current choices
2137 if ( m_data
->m_refCount
!= 1 )
2139 wxPGChoicesData
* data
= new wxPGChoicesData();
2140 data
->CopyDataFrom(m_data
);
2146 // Returns data, increases refcount.
2147 wxPGChoicesData
* GetData()
2149 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
2150 m_data
->m_refCount
++;
2154 // Returns plain data ptr - no refcounting stuff is done.
2155 wxPGChoicesData
* GetDataPtr() const { return m_data
; }
2157 // Changes ownership of data to you.
2158 wxPGChoicesData
* ExtractData()
2160 wxPGChoicesData
* data
= m_data
;
2161 m_data
= wxPGChoicesEmptyData
;
2165 wxArrayString
GetLabels() const;
2168 void operator= (const wxPGChoices
& a
)
2170 AssignData(a
.m_data
);
2173 wxPGChoiceEntry
& operator[](unsigned int i
)
2178 const wxPGChoiceEntry
& operator[](unsigned int i
) const
2184 wxPGChoicesData
* m_data
;
2191 inline bool wxPGProperty::SetChoices( const wxArrayString
& labels
,
2192 const wxArrayInt
& values
)
2194 wxPGChoices
chs(labels
, values
);
2195 return SetChoices(chs
);
2198 // -----------------------------------------------------------------------
2200 #endif // wxUSE_PROPGRID
2202 #endif // _WX_PROPGRID_PROPERTY_H_