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. In
573 sections below we cover few related topics.
575 @li @ref pgproperty_properties
576 @li @ref pgproperty_creating
578 @section pgproperty_properties Supplied Ready-to-use Property Classes
580 Here is a list and short description of supplied fully-functional
581 property classes. They are located in either props.h or advprops.h.
583 @li @ref wxArrayStringProperty
584 @li @ref wxBoolProperty
585 @li @ref wxColourProperty
586 @li @ref wxCursorProperty
587 @li @ref wxDateProperty
588 @li @ref wxDirProperty
589 @li @ref wxEditEnumProperty
590 @li @ref wxEnumProperty
591 @li @ref wxFileProperty
592 @li @ref wxFlagsProperty
593 @li @ref wxFloatProperty
594 @li @ref wxFontProperty
595 @li @ref wxImageFileProperty
596 @li @ref wxIntProperty
597 @li @ref wxLongStringProperty
598 @li @ref wxMultiChoiceProperty
599 @li @ref wxPropertyCategory
600 @li @ref wxStringProperty
601 @li @ref wxSystemColourProperty
602 @li @ref wxUIntProperty
604 @subsection wxPropertyCategory
606 Not an actual property per se, but a header for a group of properties.
607 Regardless inherits from wxPGProperty.
609 @subsection wxStringProperty
611 Simple string property. wxPG_STRING_PASSWORD attribute may be used
612 to echo value as asterisks and use wxTE_PASSWORD for wxTextCtrl.
615 * wxStringProperty has a special trait: if it has value of "<composed>",
616 and also has child properties, then its displayed value becomes
617 composition of child property values, similar as with wxFontProperty,
620 @subsection wxIntProperty
622 Like wxStringProperty, but converts text to a signed long integer.
623 wxIntProperty seamlessly supports 64-bit integers (ie. wxLongLong).
625 @subsection wxUIntProperty
627 Like wxIntProperty, but displays value as unsigned int. To set
628 the prefix used globally, manipulate wxPG_UINT_PREFIX string attribute.
629 To set the globally used base, manipulate wxPG_UINT_BASE int
630 attribute. Regardless of current prefix, understands (hex) values starting
631 with both "0x" and "$".
632 wxUIntProperty seamlessly supports 64-bit unsigned integers (ie.
635 @subsection wxFloatProperty
637 Like wxStringProperty, but converts text to a double-precision floating
638 point. Default float-to-text precision is 6 decimals, but this can be
639 changed by modifying wxPG_FLOAT_PRECISION attribute.
641 @subsection wxBoolProperty
643 Represents a boolean value. wxChoice is used as editor control, by the
644 default. wxPG_BOOL_USE_CHECKBOX attribute can be set to true inorder to use
647 @subsection wxLongStringProperty
649 Like wxStringProperty, but has a button that triggers a small text editor
650 dialog. Note that in long string values, tabs are represented by "\t" and
653 @subsection wxDirProperty
655 Like wxLongStringProperty, but the button triggers dir selector instead.
656 Supported properties (all with string value): wxPG_DIR_DIALOG_MESSAGE.
658 @subsection wxFileProperty
660 Like wxLongStringProperty, but the button triggers file selector instead.
661 Default wildcard is "All files..." but this can be changed by setting
662 wxPG_FILE_WILDCARD attribute (see wxFileDialog for format details).
663 Attribute wxPG_FILE_SHOW_FULL_PATH can be set to false inorder to show
664 only the filename, not the entire path.
666 @subsection wxEnumProperty
668 Represents a single selection from a list of choices -
669 wxOwnerDrawnComboBox is used to edit the value.
671 @subsection wxFlagsProperty
673 Represents a bit set that fits in a long integer. wxBoolProperty
674 sub-properties are created for editing individual bits. Textctrl is created
675 to manually edit the flags as a text; a continous sequence of spaces,
676 commas and semicolons is considered as a flag id separator.
677 <b>Note: </b> When changing "choices" (ie. flag labels) of wxFlagsProperty,
678 you will need to use SetPropertyChoices - otherwise they will not get
681 @subsection wxArrayStringProperty
683 Allows editing of a list of strings in wxTextCtrl and in a separate dialog.
685 @subsection wxDateProperty
687 wxDateTime property. Default editor is DatePickerCtrl, altough TextCtrl
688 should work as well. wxPG_DATE_FORMAT attribute can be used to change
689 string wxDateTime::Format uses (altough default is recommended as it is
690 locale-dependant), and wxPG_DATE_PICKER_STYLE allows changing window
691 style given to DatePickerCtrl (default is wxDP_DEFAULT|wxDP_SHOWCENTURY).
693 @subsection wxEditEnumProperty
695 Represents a string that can be freely edited or selected from list of
696 choices - custom combobox control is used to edit the value.
698 @subsection wxMultiChoiceProperty
700 Allows editing a multiple selection from a list of strings. This is
701 property is pretty much built around concept of wxMultiChoiceDialog.
702 It uses wxArrayString value.
704 @subsection wxImageFileProperty
706 Like wxFileProperty, but has thumbnail of the image in front of
707 the filename and autogenerates wildcard from available image handlers.
709 @subsection wxColourProperty
711 <b>Useful alternate editor:</b> Choice.
713 Represents wxColour. wxButton is used to trigger a colour picker dialog.
715 @subsection wxFontProperty
717 Represents wxFont. Various sub-properties are used to edit individual
720 @subsection wxSystemColourProperty
722 Represents wxColour and a system colour index. wxChoice is used to edit
723 the value. Drop-down list has color images. Note that value type
724 is wxColourPropertyValue instead of wxColour.
726 class wxColourPropertyValue : public wxObject
729 // An integer value relating to the colour, and which exact
730 // meaning depends on the property with which it is used.
732 // For wxSystemColourProperty:
733 // Any of wxSYS_COLOUR_XXX, or any web-colour (use
734 // wxPG_TO_WEB_COLOUR macro - (currently unsupported) ),
735 // or wxPG_COLOUR_CUSTOM.
738 // Resulting colour. Should be correct regardless of type.
743 @subsection wxCursorProperty
745 Represents a wxCursor. wxChoice is used to edit the value.
746 Drop-down list has cursor images under some (wxMSW) platforms.
749 @section pgproperty_creating Creating Custom Properties
751 New properties can be created by subclassing wxPGProperty or one
752 of the provided property classes, and (re)implementing necessary
753 member functions. Below, each virtual member function has ample
754 documentation about its purpose and any odd details which to keep
757 Here is a very simple 'template' code:
760 class MyProperty : public wxPGProperty
763 // All arguments of ctor must have a default value -
764 // use wxPG_LABEL for label and name
765 MyProperty( const wxString& label = wxPG_LABEL,
766 const wxString& name = wxPG_LABEL,
767 const wxString& value = wxEmptyString )
769 // m_value is wxVariant
773 virtual ~MyProperty() { }
775 const wxPGEditor* DoGetEditorClass() const
777 // Determines editor used by property.
778 // You can replace 'TextCtrl' below with any of these
779 // builtin-in property editor identifiers: Choice, ComboBox,
780 // TextCtrlAndButton, ChoiceAndButton, CheckBox, SpinCtrl,
782 return wxPGEditor_TextCtrl;
785 virtual wxString GetValueAsString( int argFlags ) const
787 // TODO: Return property value in string format
790 virtual bool StringToValue( wxVariant& variant,
791 const wxString& text,
794 // TODO: Adapt string to property value.
801 Since wxPGProperty derives from wxObject, you can use standard
802 DECLARE_DYNAMIC_CLASS and IMPLEMENT_DYNAMIC_CLASS macros. From the
803 above example they were omitted for sake of simplicity, and besides,
804 they are only really needed if you need to use wxRTTI with your
807 You can change the 'value type' of a property by simply assigning different
808 type of variant with SetValue. <b>It is mandatory to implement
809 wxVariantData class for all data types used as property values.</b>
810 You can use macros declared in wxPropertyGrid headers. For instance:
814 // (If you need to have export declaration, use version of macros
815 // with _EXPORTED postfix)
816 WX_PG_DECLARE_VARIANT_DATA(MyDataClass)
819 WX_PG_IMPLEMENT_VARIANT_DATA(MyDataClass)
821 // Or, if you don't have valid == operator:
822 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(MyDataClass)
828 class WXDLLIMPEXP_PROPGRID wxPGProperty
: public wxObject
830 friend class wxPropertyGrid
;
831 friend class wxPropertyGridInterface
;
832 friend class wxPropertyGridPageState
;
833 friend class wxPropertyGridPopulator
;
834 friend class wxStringProperty
; // Proper "<composed>" support requires this
836 DECLARE_ABSTRACT_CLASS(wxPGProperty
)
839 typedef wxUint32 FlagType
;
841 /** Basic constructor.
846 Non-abstract property classes should have constructor of this style:
850 // If T is a class, then it should be a constant reference
851 // (e.g. const T& ) instead.
852 MyProperty( const wxString& label, const wxString& name, T value )
855 // Generally recommended way to set the initial value
856 // (as it should work in pretty much 100% of cases).
861 // If has private child properties then create them here, e.g.:
862 // AddChild( new wxStringProperty( "Subprop 1",
864 // value.GetSubProp1() ) );
869 wxPGProperty( const wxString
& label
, const wxString
& name
);
873 It is customary for derived properties to implement this.
875 virtual ~wxPGProperty();
877 /** This virtual function is called after m_value has been set.
880 - If m_value was set to Null variant (ie. unspecified value),
881 OnSetValue() will not be called.
882 - m_value may be of any variant type. Typically properties internally
883 support only one variant type, and as such OnSetValue() provides a
884 good opportunity to convert
885 supported values into internal type.
886 - Default implementation does nothing.
888 virtual void OnSetValue();
890 /** Override this to return something else than m_value as the value.
892 virtual wxVariant
DoGetValue() const { return m_value
; }
894 #if !defined(SWIG) || defined(CREATE_VCW)
895 /** Implement this function in derived class to check the value.
896 Return true if it is ok. Returning false prevents property change events
900 - Default implementation always returns true.
902 virtual bool ValidateValue( wxVariant
& value
,
903 wxPGValidationInfo
& validationInfo
) const;
906 Converts 'text' into proper value 'variant'.
907 Returns true if new (different than m_value) value could be interpreted
910 If wxPG_FULL_VALUE is set, returns complete, storable value instead
911 of displayable one (they may be different).
912 If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of
913 composite property string value (as generated by GetValueAsString()
914 called with this same flag).
917 Default implementation converts semicolon delimited tokens into child
918 values. Only works for properties with children.
920 virtual bool StringToValue( wxVariant
& variant
,
921 const wxString
& text
,
922 int argFlags
= 0 ) const;
925 Converts 'number' (including choice selection) into proper value
928 Returns true if new (different than m_value) value could be interpreted
932 If wxPG_FULL_VALUE is set, returns complete, storable value instead
936 - If property is not supposed to use choice or spinctrl or other editor
937 with int-based value, it is not necessary to implement this method.
938 - Default implementation simply assign given int to m_value.
939 - If property uses choice control, and displays a dialog on some choice
940 items, then it is preferred to display that dialog in IntToValue
943 virtual bool IntToValue( wxVariant
& value
,
945 int argFlags
= 0 ) const;
946 #endif // !defined(SWIG) || defined(CREATE_VCW)
949 /** Returns text representation of property's value.
952 If wxPG_FULL_VALUE is set, returns complete, storable string value
953 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
954 string value that must be editable in textctrl. If
955 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
956 display as a part of composite property string value.
959 Default implementation returns string composed from text
960 representations of child properties.
962 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
964 /** Converts string to a value, and if successful, calls SetValue() on it.
965 Default behavior is to do nothing.
967 String to get the value from.
969 true if value was changed.
971 bool SetValueFromString( const wxString
& text
, int flags
= 0 );
973 /** Converts integer to a value, and if succesful, calls SetValue() on it.
974 Default behavior is to do nothing.
976 Int to get the value from.
978 If has wxPG_FULL_VALUE, then the value given is a actual value and
981 True if value was changed.
983 bool SetValueFromInt( long value
, int flags
= 0 );
986 Returns size of the custom painted image in front of property.
988 This method must be overridden to return non-default value if
989 OnCustomPaint is to be called.
991 Normally -1, but can be an index to the property's list of items.
993 - Default behavior is to return wxSize(0,0), which means no image.
994 - Default image width or height is indicated with dimension -1.
995 - You can also return wxPG_DEFAULT_IMAGE_SIZE, i.e. wxSize(-1, -1).
997 virtual wxSize
OnMeasureImage( int item
= -1 ) const;
1000 Events received by editor widgets are processed here.
1002 Note that editor class usually processes most events. Some, such as
1003 button press events of TextCtrlAndButton class, can be handled here.
1004 Also, if custom handling for regular events is desired, then that can
1005 also be done (for example, wxSystemColourProperty custom handles
1006 wxEVT_COMMAND_CHOICE_SELECTED to display colour picker dialog when
1007 'custom' selection is made).
1009 If the event causes value to be changed, SetValueInEvent()
1010 should be called to set the new value.
1015 Should return true if any changes in value should be reported.
1017 If property uses choice control, and displays a dialog on some choice
1018 items, then it is preferred to display that dialog in IntToValue
1021 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
1022 wxWindow
* wnd_primary
,
1026 Called after value of a child property has been altered.
1028 Note that this function is usually called at the time that value of
1029 this property, or given child property, is still pending for change.
1031 Sample pseudo-code implementation:
1034 void MyProperty::ChildChanged( wxVariant& thisValue,
1036 wxVariant& childValue ) const
1038 // Acquire reference to actual type of data stored in variant
1039 // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros
1040 // were used to create the variant class).
1041 T& data = TFromVariant(thisValue);
1043 // Copy childValue into data.
1044 switch ( childIndex )
1047 data.SetSubProp1( childvalue.GetLong() );
1050 data.SetSubProp2( childvalue.GetString() );
1058 Value of this property, that should be altered.
1060 Index of child changed (you can use Item(childIndex) to get).
1062 Value of the child property.
1064 virtual void ChildChanged( wxVariant
& thisValue
,
1066 wxVariant
& childValue
) const;
1068 /** Returns pointer to an instance of used editor.
1070 virtual const wxPGEditor
* DoGetEditorClass() const;
1072 /** Returns pointer to the wxValidator that should be used
1073 with the editor of this property (NULL for no validator).
1074 Setting validator explicitly via SetPropertyValidator
1077 In most situations, code like this should work well
1078 (macros are used to maintain one actual validator instance,
1079 so on the second call the function exits within the first
1084 wxValidator* wxMyPropertyClass::DoGetValidator () const
1086 WX_PG_DOGETVALIDATOR_ENTRY()
1088 wxMyValidator* validator = new wxMyValidator(...);
1090 ... prepare validator...
1092 WX_PG_DOGETVALIDATOR_EXIT(validator)
1098 You can get common filename validator by returning
1099 wxFileProperty::GetClassValidator(). wxDirProperty,
1100 for example, uses it.
1102 virtual wxValidator
* DoGetValidator () const;
1105 Returns current value's index to the choice control.
1107 May also return, through pointer arguments, strings that should be
1108 inserted to that control. Irrelevant to classes which do not employ
1109 wxPGEditor_Choice or similar.
1112 - If returns NULL in choiceinfo.m_choices, then this class must be
1113 derived from wxBaseEnumProperty.
1114 - Must be able to cope situation where property's set of choices is
1117 virtual int GetChoiceInfo( wxPGChoiceInfo
* choiceinfo
);
1120 Override to paint an image in front of the property value text or
1121 drop-down list item (but only if wxPGProperty::OnMeasureImage is
1122 overridden as well).
1124 If property's OnMeasureImage() returns size that has height != 0 but
1125 less than row height ( < 0 has special meanings), wxPropertyGrid calls
1126 this method to draw a custom image in a limited area in front of the
1127 editor control or value text/graphics, and if control has drop-down
1128 list, then the image is drawn there as well (even in the case
1129 OnMeasureImage() returned higher height than row height).
1131 NOTE: Following applies when OnMeasureImage() returns a "flexible"
1132 height ( using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable
1133 height items: If rect.x is < 0, then this is a measure item call, which
1134 means that dc is invalid and only thing that should be done is to set
1135 paintdata.m_drawnHeight to the height of the image of item at index
1136 paintdata.m_choiceItem. This call may be done even as often as once
1137 every drop-down popup show.
1142 Box reserved for custom graphics. Includes surrounding rectangle,
1143 if any. If x is < 0, then this is a measure item call (see above).
1145 wxPGPaintData structure with much useful data.
1148 - You can actually exceed rect width, but if you do so then
1149 paintdata.m_drawnWidth must be set to the full width drawn in
1151 - Due to technical reasons, rect's height will be default even if
1152 custom height was reported during measure call.
1153 - Brush is guaranteed to be default background colour. It has been
1154 already used to clear the background of area being painted. It
1156 - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper
1157 colour) pen for drawing framing rectangle. It can be changed as
1160 @see GetValueAsString()
1162 virtual void OnCustomPaint( wxDC
& dc
,
1164 wxPGPaintData
& paintdata
);
1167 Returns used wxPGCellRenderer instance for given property column
1170 Default implementation returns editor's renderer for all columns.
1172 virtual wxPGCellRenderer
* GetCellRenderer( int column
) const;
1175 Refresh values of child properties.
1177 Automatically called after value is set.
1179 virtual void RefreshChildren();
1181 /** Special handling for attributes of this property.
1183 If returns false, then the attribute will be automatically stored in
1186 Default implementation simply returns false.
1188 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
1190 /** Returns value of an attribute.
1192 Override if custom handling of attributes is needed.
1194 Default implementation simply return NULL variant.
1196 virtual wxVariant
DoGetAttribute( const wxString
& name
) const;
1198 /** Returns instance of a new wxPGEditorDialogAdapter instance, which is
1199 used when user presses the (optional) button next to the editor control;
1201 Default implementation returns NULL (ie. no action is generated when
1204 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
1207 Adds entry to property's wxPGChoices and editor control (if it is
1210 Returns index of item added.
1212 int AppendChoice( const wxString
& label
, int value
= wxPG_INVALID_VALUE
)
1214 return InsertChoice(label
,-1,value
);
1217 /** Returns wxPGCell of given column, NULL if none. If valid
1218 object is returned, caller will gain its ownership.
1220 wxPGCell
* AcquireCell( unsigned int column
)
1222 if ( column
>= m_cells
.size() )
1225 wxPGCell
* cell
= (wxPGCell
*) m_cells
[column
];
1226 m_cells
[column
] = NULL
;
1231 Returns true if children of this property are component values (for
1232 instance, points size, face name, and is_underlined are component
1235 bool AreChildrenComponents() const
1237 if ( m_flags
& (wxPG_PROP_COMPOSED_VALUE
|wxPG_PROP_AGGREGATE
) )
1244 Removes entry from property's wxPGChoices and editor control (if it is
1247 If selected item is deleted, then the value is set to unspecified.
1249 void DeleteChoice( int index
);
1252 Call to enable or disable usage of common value (integer value that can
1253 be selected for properties instead of their normal values) for this
1256 Common values are disabled by the default for all properties.
1258 void EnableCommonValue( bool enable
= true )
1260 if ( enable
) SetFlag( wxPG_PROP_USES_COMMON_VALUE
);
1261 else ClearFlag( wxPG_PROP_USES_COMMON_VALUE
);
1264 /** Composes text from values of child properties. */
1265 void GenerateComposedValue( wxString
& text
, int argFlags
= 0 ) const;
1267 /** Returns property's label. */
1268 const wxString
& GetLabel() const { return m_label
; }
1270 /** Returns property's name with all (non-category, non-root) parents. */
1271 wxString
GetName() const;
1274 Returns property's base name (ie parent's name is not added in any
1277 const wxString
& GetBaseName() const { return m_name
; }
1279 wxPGChoices
& GetChoices();
1281 const wxPGChoices
& GetChoices() const;
1283 const wxPGChoiceEntry
* GetCurrentChoice() const;
1285 /** Returns coordinate to the top y of the property. Note that the
1286 position of scrollbars is not taken into account.
1290 wxVariant
GetValue() const
1292 return DoGetValue();
1296 /** Returns reference to the internal stored value. GetValue is preferred
1297 way to get the actual value, since GetValueRef ignores DoGetValue,
1298 which may override stored value.
1300 wxVariant
& GetValueRef()
1305 const wxVariant
& GetValueRef() const
1311 /** Same as GetValueAsString, except takes common value into account.
1313 wxString
GetValueString( int argFlags
= 0 ) const;
1315 void UpdateControl( wxWindow
* primary
);
1317 /** Returns wxPGCell of given column, NULL if none. wxPGProperty
1318 will retain ownership of the cell object.
1320 wxPGCell
* GetCell( unsigned int column
) const
1322 if ( column
>= m_cells
.size() )
1325 return (wxPGCell
*) m_cells
[column
];
1328 unsigned int GetChoiceCount() const;
1330 wxString
GetChoiceString( unsigned int index
);
1332 /** Return number of displayed common values for this property.
1334 int GetDisplayedCommonValueCount() const;
1336 wxString
GetDisplayedString() const
1338 return GetValueString(0);
1341 /** Returns property grid where property lies. */
1342 wxPropertyGrid
* GetGrid() const;
1344 /** Returns owner wxPropertyGrid, but only if one is currently on a page
1345 displaying this property. */
1346 wxPropertyGrid
* GetGridIfDisplayed() const;
1348 /** Returns highest level non-category, non-root parent. Useful when you
1349 have nested wxCustomProperties/wxParentProperties.
1351 Thus, if immediate parent is root or category, this will return the
1354 wxPGProperty
* GetMainParent() const;
1356 /** Return parent of property */
1357 wxPGProperty
* GetParent() const { return m_parent
; }
1359 /** Returns true if property has editable wxTextCtrl when selected.
1362 Altough disabled properties do not displayed editor, they still
1363 return True here as being disabled is considered a temporary
1364 condition (unlike being read-only or having limited editing enabled).
1366 bool IsTextEditable() const;
1368 bool IsValueUnspecified() const
1370 return m_value
.IsNull();
1373 FlagType
HasFlag( FlagType flag
) const
1375 return ( m_flags
& flag
);
1378 /** Returns comma-delimited string of property attributes.
1380 const wxPGAttributeStorage
& GetAttributes() const
1382 return m_attributes
;
1385 /** Returns m_attributes as list wxVariant.
1387 wxVariant
GetAttributesAsList() const;
1389 FlagType
GetFlags() const
1394 const wxPGEditor
* GetEditorClass() const;
1396 wxString
GetValueType() const
1398 return m_value
.GetType();
1401 /** Returns editor used for given column. NULL for no editor.
1403 const wxPGEditor
* GetColumnEditor( int column
) const
1406 return GetEditorClass();
1411 /** Returns common value selected for this property. -1 for none.
1413 int GetCommonValue() const
1415 return m_commonValue
;
1418 /** Returns true if property has even one visible child.
1420 bool HasVisibleChildren() const;
1423 Adds entry to property's wxPGChoices and editor control (if it is
1426 Returns index of item added.
1428 int InsertChoice( const wxString
& label
,
1430 int value
= wxPG_INVALID_VALUE
);
1433 Returns true if this property is actually a wxPropertyCategory.
1435 bool IsCategory() const { return HasFlag(wxPG_PROP_CATEGORY
)?true:false; }
1437 /** Returns true if this property is actually a wxRootProperty.
1439 bool IsRoot() const { return (m_parent
== NULL
); }
1441 /** Returns true if this is a sub-property. */
1442 bool IsSubProperty() const
1444 wxPGProperty
* parent
= (wxPGProperty
*)m_parent
;
1445 if ( parent
&& !parent
->IsCategory() )
1450 /** Returns last visible sub-property, recursively.
1452 const wxPGProperty
* GetLastVisibleSubItem() const;
1454 wxVariant
GetDefaultValue() const;
1456 int GetMaxLength() const
1458 return (int) m_maxLen
;
1462 Determines, recursively, if all children are not unspecified.
1464 Takes values in given list into account.
1466 bool AreAllChildrenSpecified( wxVariant
* pendingList
= NULL
) const;
1468 /** Updates composed values of parent non-category properties, recursively.
1469 Returns topmost property updated.
1472 - Must not call SetValue() (as can be called in it).
1474 wxPGProperty
* UpdateParentValues();
1476 /** Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
1478 FlagType
UsesAutoUnspecified() const
1480 return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED
);
1483 wxBitmap
* GetValueImage() const
1485 return m_valueBitmap
;
1488 wxVariant
GetAttribute( const wxString
& name
) const;
1491 Returns named attribute, as string, if found.
1493 Otherwise defVal is returned.
1495 wxString
GetAttribute( const wxString
& name
, const wxString
& defVal
) const;
1498 Returns named attribute, as long, if found.
1500 Otherwise defVal is returned.
1502 long GetAttributeAsLong( const wxString
& name
, long defVal
) const;
1505 Returns named attribute, as double, if found.
1507 Otherwise defVal is returned.
1509 double GetAttributeAsDouble( const wxString
& name
, double defVal
) const;
1511 unsigned int GetArrIndex() const { return m_arrIndex
; }
1513 unsigned int GetDepth() const { return (unsigned int)m_depth
; }
1515 /** Gets flags as a'|' delimited string. Note that flag names are not
1516 prepended with 'wxPG_PROP_'.
1518 String will only be made to include flags combined by this parameter.
1520 wxString
GetFlagsAsString( FlagType flagsMask
) const;
1522 /** Returns position in parent's array. */
1523 unsigned int GetIndexInParent() const
1525 return (unsigned int)m_arrIndex
;
1528 /** Hides or reveals the property.
1530 true for hide, false for reveal.
1532 By default changes are applied recursively. Set this paramter
1533 wxPG_DONT_RECURSE to prevent this.
1535 inline bool Hide( bool hide
, int flags
= wxPG_RECURSE
);
1537 bool IsExpanded() const
1538 { return (!(m_flags
& wxPG_PROP_COLLAPSED
) && GetChildCount()); }
1540 /** Returns true if all parents expanded.
1542 bool IsVisible() const;
1544 bool IsEnabled() const { return !(m_flags
& wxPG_PROP_DISABLED
); }
1546 /** If property's editor is created this forces its recreation.
1547 Useful in SetAttribute etc. Returns true if actually did anything.
1549 bool RecreateEditor();
1551 /** If property's editor is active, then update it's value.
1553 void RefreshEditor();
1555 /** Sets an attribute for this property.
1557 Text identifier of attribute. See @ref propgrid_property_attributes.
1561 void SetAttribute( const wxString
& name
, wxVariant value
);
1563 void SetAttributes( const wxPGAttributeStorage
& attributes
);
1566 /** Sets editor for a property.
1569 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1570 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full
1573 For custom editors, use pointer you received from
1574 wxPropertyGrid::RegisterEditorClass().
1576 void SetEditor( const wxPGEditor
* editor
)
1578 m_customEditor
= editor
;
1582 /** Sets editor for a property.
1584 inline void SetEditor( const wxString
& editorName
);
1586 /** Sets cell information for given column.
1588 Note that the property takes ownership of given wxPGCell instance.
1590 void SetCell( int column
, wxPGCell
* cellObj
);
1592 /** Changes value of a property with choices, but only
1593 works if the value type is long or string. */
1594 void SetChoiceSelection( int newValue
, const wxPGChoiceInfo
& choiceInfo
);
1596 /** Sets common value selected for this property. -1 for none.
1598 void SetCommonValue( int commonValue
)
1600 m_commonValue
= commonValue
;
1603 /** Sets flags from a '|' delimited string. Note that flag names are not
1604 prepended with 'wxPG_PROP_'.
1606 void SetFlagsFromString( const wxString
& str
);
1608 /** Sets property's "is it modified?" flag. Affects children recursively.
1610 void SetModifiedStatus( bool modified
)
1612 SetFlagRecursively(wxPG_PROP_MODIFIED
, modified
);
1615 /** Call in OnEvent(), OnButtonClick() etc. to change the property value
1616 based on user input.
1619 This method is const since it doesn't actually modify value, but posts
1620 given variant as pending value, stored in wxPropertyGrid.
1622 void SetValueInEvent( wxVariant value
) const;
1625 Call this to set value of the property.
1627 Unlike methods in wxPropertyGrid, this does not automatically update
1631 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run
1632 through validation process and send property change event.
1634 If you need to change property value in event, based on user input, use
1635 SetValueInEvent() instead.
1638 Pointer to list variant that contains child values. Used to indicate
1639 which children should be marked as modified.
1641 Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR).
1643 void SetValue( wxVariant value
, wxVariant
* pList
= NULL
, int flags
= 0 );
1645 /** Set wxBitmap in front of the value. This bitmap may be ignored
1646 by custom cell renderers.
1648 void SetValueImage( wxBitmap
& bmp
);
1650 /** If property has choices and they are not yet exclusive, new such copy
1651 of them will be created.
1653 void SetChoicesExclusive();
1655 void SetExpanded( bool expanded
)
1657 if ( !expanded
) m_flags
|= wxPG_PROP_COLLAPSED
;
1658 else m_flags
&= ~wxPG_PROP_COLLAPSED
;
1661 void SetFlag( FlagType flag
) { m_flags
|= flag
; }
1663 void SetFlagRecursively( FlagType flag
, bool set
);
1665 void SetHelpString( const wxString
& helpString
)
1667 m_helpString
= helpString
;
1670 void SetLabel( const wxString
& label
) { m_label
= label
; }
1672 inline void SetName( const wxString
& newName
);
1674 void SetValueToUnspecified()
1676 wxVariant val
; // Create NULL variant
1680 #if wxUSE_VALIDATORS
1681 /** Sets wxValidator for a property*/
1682 void SetValidator( const wxValidator
& validator
)
1684 m_validator
= wxDynamicCast(validator
.Clone(),wxValidator
);
1687 /** Gets assignable version of property's validator. */
1688 wxValidator
* GetValidator() const
1692 return DoGetValidator();
1694 #endif // #if wxUSE_VALIDATORS
1696 /** Updates property value in case there were last minute
1697 changes. If value was unspecified, it will be set to default.
1698 Use only for properties that have TextCtrl-based editor.
1700 If you have code similar to
1702 // Update the value in case of last minute changes
1703 if ( primary && propgrid->IsEditorsValueModified() )
1704 GetEditorClass()->CopyValueFromControl( this, primary );
1706 in wxPGProperty::OnEvent wxEVT_COMMAND_BUTTON_CLICKED handler,
1707 then replace it with call to this method.
1709 True if value changed.
1711 bool PrepareValueForDialogEditing( wxPropertyGrid
* propgrid
);
1714 /** Returns client data (void*) of a property.
1716 void* GetClientData() const
1718 return m_clientData
;
1721 /** Sets client data (void*) of a property.
1723 This untyped client data has to be deleted manually.
1725 void SetClientData( void* clientData
)
1727 m_clientData
= clientData
;
1730 /** Returns client object of a property.
1732 void SetClientObject(wxClientData
* clientObject
)
1734 delete m_clientObject
;
1735 m_clientObject
= clientObject
;
1738 /** Sets managed client object of a property.
1740 wxClientData
*GetClientObject() const { return m_clientObject
; }
1743 /** Sets new set of choices for property.
1746 This operation clears the property value.
1748 bool SetChoices( wxPGChoices
& choices
);
1750 /** Sets new set of choices for property.
1752 inline bool SetChoices( const wxArrayString
& labels
,
1753 const wxArrayInt
& values
= wxArrayInt() );
1755 /** Set max length of text in text editor.
1757 inline bool SetMaxLength( int maxLen
);
1759 /** Call with 'false' in OnSetValue to cancel value changes after all
1760 (ie. cancel 'true' returned by StringToValue() or IntToValue()).
1762 void SetWasModified( bool set
= true )
1764 if ( set
) m_flags
|= wxPG_PROP_WAS_MODIFIED
;
1765 else m_flags
&= ~wxPG_PROP_WAS_MODIFIED
;
1768 const wxString
& GetHelpString() const
1770 return m_helpString
;
1773 void ClearFlag( FlagType flag
) { m_flags
&= ~(flag
); }
1775 // Use, for example, to detect if item is inside collapsed section.
1776 bool IsSomeParent( wxPGProperty
* candidate_parent
) const;
1779 Adapts list variant into proper value using consecutive
1782 void AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const;
1784 /** This is used by properties that have fixed sub-properties. */
1785 void AddChild( wxPGProperty
* prop
);
1787 /** Returns height of children, recursively, and
1788 by taking expanded/collapsed status into account.
1790 iMax is used when finding property y-positions.
1792 int GetChildrenHeight( int lh
, int iMax
= -1 ) const;
1794 /** Returns number of child properties */
1795 unsigned int GetChildCount() const { return m_children
.GetCount(); }
1797 /** Returns sub-property at index i. */
1798 wxPGProperty
* Item( size_t i
) const
1799 { return (wxPGProperty
*)m_children
.Item(i
); }
1801 /** Returns last sub-property.
1803 wxPGProperty
* Last() const { return (wxPGProperty
*)m_children
.Last(); }
1805 /** Returns index of given sub-property. */
1806 int Index( const wxPGProperty
* p
) const
1807 { return m_children
.Index((wxPGProperty
*)p
); }
1809 /** Deletes all sub-properties. */
1812 // Puts correct indexes to children
1813 void FixIndexesOfChildren( size_t starthere
= 0 );
1816 // Returns wxPropertyGridPageState in which this property resides.
1817 wxPropertyGridPageState
* GetParentState() const { return m_parentState
; }
1820 wxPGProperty
* GetItemAtY( unsigned int y
,
1822 unsigned int* nextItemY
) const;
1824 /** Returns (direct) child property with given name (or NULL if not found).
1826 wxPGProperty
* GetPropertyByName( const wxString
& name
) const;
1830 DocStr(GetClientData
,
1831 "Returns the client data object for a property", "");
1832 PyObject
* GetClientData() {
1833 wxPyClientData
* data
= (wxPyClientData
*)self
->GetClientObject();
1835 Py_INCREF(data
->m_obj
);
1843 DocStr(SetClientData
,
1844 "Associate the given client data.", "");
1845 void SetClientData(PyObject
* clientData
) {
1846 wxPyClientData
* data
= new wxPyClientData(clientData
);
1847 self
->SetClientObject(data
);
1851 GetClientObject
= GetClientData
1852 SetClientObject
= SetClientData
1858 static wxString
* sm_wxPG_LABEL
;
1860 /** This member is public so scripting language bindings
1861 wrapper code can access it freely.
1866 /** Returns text for given column.
1868 wxString
GetColumnText( unsigned int col
) const;
1870 /** Returns (direct) child property with given name (or NULL if not found),
1874 Start looking for the child at this index.
1877 Does not support scope (ie. Parent.Child notation).
1879 wxPGProperty
* GetPropertyByNameWH( const wxString
& name
,
1880 unsigned int hintIndex
) const;
1882 /** This is used by Insert etc. */
1883 void AddChild2( wxPGProperty
* prop
,
1885 bool correct_mode
= true );
1887 void DoSetName(const wxString
& str
) { m_name
= str
; }
1889 // Call for after sub-properties added with AddChild
1890 void PrepareSubProperties();
1892 void SetParentalType( int flag
)
1894 m_flags
&= ~(wxPG_PROP_PROPERTY
|wxPG_PROP_PARENTAL_FLAGS
);
1898 void SetParentState( wxPropertyGridPageState
* pstate
)
1899 { m_parentState
= pstate
; }
1901 // Call after fixed sub-properties added/removed after creation.
1902 // if oldSelInd >= 0 and < new max items, then selection is
1904 void SubPropsChanged( int oldSelInd
= -1 );
1906 int GetY2( int lh
) const;
1910 wxPGProperty
* m_parent
;
1911 wxPropertyGridPageState
* m_parentState
;
1913 wxClientData
* m_clientObject
;
1915 // Overrides editor returned by property class
1916 const wxPGEditor
* m_customEditor
;
1917 #if wxUSE_VALIDATORS
1918 // Editor is going to get this validator
1919 wxValidator
* m_validator
;
1921 // Show this in front of the value
1923 // TODO: Can bitmap be implemented with wxPGCell?
1924 wxBitmap
* m_valueBitmap
;
1927 wxPGAttributeStorage m_attributes
;
1928 wxArrayPtrVoid m_children
;
1930 // Extended cell information
1931 wxArrayPtrVoid m_cells
;
1933 // Help shown in statusbar or help box.
1934 wxString m_helpString
;
1936 // Index in parent's property array.
1937 unsigned int m_arrIndex
;
1939 // If not -1, then overrides m_value
1944 // Maximum length (mainly for string properties). Could be in some sort of
1945 // wxBaseStringProperty, but currently, for maximum flexibility and
1946 // compatibility, we'll stick it here. Anyway, we had 3 excess bytes to use
1947 // so short int will fit in just fine.
1950 // Root has 0, categories etc. at that level 1, etc.
1951 unsigned char m_depth
;
1953 // m_depthBgCol indicates width of background colour between margin and item
1954 // (essentially this is category's depth, if none then equals m_depth).
1955 unsigned char m_depthBgCol
;
1957 unsigned char m_bgColIndex
; // Background brush index.
1958 unsigned char m_fgColIndex
; // Foreground colour index.
1961 // Called in constructors.
1963 void Init( const wxString
& label
, const wxString
& name
);
1964 #endif // #ifndef SWIG
1967 // -----------------------------------------------------------------------
1970 // Property class declaration helper macros
1971 // (wxPGRootPropertyClass and wxPropertyCategory require this).
1974 #define WX_PG_DECLARE_DOGETEDITORCLASS \
1975 virtual const wxPGEditor* DoGetEditorClass() const;
1978 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
1980 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
1981 WX_PG_DECLARE_DOGETEDITORCLASS \
1984 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME)
1987 // Implements sans constructor function. Also, first arg is class name, not
1989 #define WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(PROPNAME,T,EDITOR) \
1990 const wxPGEditor* PROPNAME::DoGetEditorClass() const \
1992 return wxPGEditor_##EDITOR; \
1995 // -----------------------------------------------------------------------
1999 /** @class wxPGRootProperty
2001 Root parent property.
2003 class WXDLLIMPEXP_PROPGRID wxPGRootProperty
: public wxPGProperty
2006 WX_PG_DECLARE_PROPERTY_CLASS(wxPGRootProperty
)
2011 virtual ~wxPGRootProperty();
2013 virtual bool StringToValue( wxVariant
&, const wxString
&, int ) const
2021 // -----------------------------------------------------------------------
2023 /** @class wxPropertyCategory
2025 Category (caption) property.
2027 class WXDLLIMPEXP_PROPGRID wxPropertyCategory
: public wxPGProperty
2029 friend class wxPropertyGrid
;
2030 friend class wxPropertyGridPageState
;
2031 WX_PG_DECLARE_PROPERTY_CLASS(wxPropertyCategory
)
2034 /** Default constructor is only used in special cases. */
2035 wxPropertyCategory();
2037 wxPropertyCategory( const wxString
& label
,
2038 const wxString
& name
= wxPG_LABEL
);
2039 ~wxPropertyCategory();
2041 int GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const;
2044 virtual wxString
GetValueAsString( int argFlags
) const;
2046 void SetTextColIndex( unsigned int colInd
)
2047 { m_capFgColIndex
= (wxByte
) colInd
; }
2048 unsigned int GetTextColIndex() const
2049 { return (unsigned int) m_capFgColIndex
; }
2051 void CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
);
2053 int m_textExtent
; // pre-calculated length of text
2054 wxByte m_capFgColIndex
; // caption text colour index
2062 // -----------------------------------------------------------------------
2066 /** @class wxPGChoiceEntry
2067 Data of a single wxPGChoices choice.
2069 class WXDLLIMPEXP_PROPGRID wxPGChoiceEntry
: public wxPGCell
2073 wxPGChoiceEntry( const wxPGChoiceEntry
& entry
);
2074 wxPGChoiceEntry( const wxString
& label
,
2075 int value
= wxPG_INVALID_VALUE
)
2076 : wxPGCell(), m_value(value
)
2081 wxPGChoiceEntry( const wxString
& label
,
2083 const wxBitmap
& bitmap
,
2084 const wxColour
& fgCol
= wxNullColour
,
2085 const wxColour
& bgCol
= wxNullColour
)
2086 : wxPGCell(label
, bitmap
, fgCol
, bgCol
), m_value(value
)
2090 virtual ~wxPGChoiceEntry()
2094 void SetValue( int value
) { m_value
= value
; }
2096 int GetValue() const { return m_value
; }
2098 bool HasValue() const { return (m_value
!= wxPG_INVALID_VALUE
); }
2105 typedef void* wxPGChoicesId
;
2107 class WXDLLIMPEXP_PROPGRID wxPGChoicesData
2109 friend class wxPGChoices
;
2111 // Constructor sets m_refCount to 1.
2114 void CopyDataFrom( wxPGChoicesData
* data
);
2116 // Takes ownership of 'item'
2117 void Insert( int index
, wxPGChoiceEntry
* item
)
2119 wxArrayPtrVoid::iterator it
;
2123 index
= m_items
.size();
2127 it
= m_items
.begin() + index
;
2130 // Need to fix value?
2131 if ( item
->GetValue() == wxPG_INVALID_VALUE
)
2132 item
->SetValue(index
);
2134 m_items
.insert(it
, item
);
2137 // Delete all entries
2140 size_t GetCount() const { return m_items
.size(); }
2142 wxPGChoiceEntry
* Item( unsigned int i
) const
2144 wxCHECK_MSG( i
< GetCount(), NULL
, "invalid index" );
2146 return (wxPGChoiceEntry
*) m_items
[i
];
2152 wxASSERT( m_refCount
>= 0 );
2153 if ( m_refCount
== 0 )
2158 wxArrayPtrVoid m_items
;
2160 // So that multiple properties can use the same set
2163 virtual ~wxPGChoicesData();
2166 #define wxPGChoicesEmptyData ((wxPGChoicesData*)NULL)
2171 /** @class wxPGChoices
2173 Helper class for managing choices of wxPropertyGrid properties.
2174 Each entry can have label, value, bitmap, text colour, and background
2177 @library{wxpropgrid}
2180 class WXDLLIMPEXP_PROPGRID wxPGChoices
2183 typedef long ValArrItem
;
2185 /** Default constructor. */
2191 /** Copy constructor. */
2192 wxPGChoices( const wxPGChoices
& a
)
2194 if ( a
.m_data
!= wxPGChoicesEmptyData
)
2197 m_data
->m_refCount
++;
2202 wxPGChoices( const wxChar
** labels
, const long* values
= NULL
)
2209 wxPGChoices( const wxArrayString
& labels
,
2210 const wxArrayInt
& values
= wxArrayInt() )
2216 /** Simple interface constructor. */
2217 wxPGChoices( wxPGChoicesData
* data
)
2233 If did not have own copies, creates them now. If was empty, identical
2234 to set except that creates copies.
2236 void Add( const wxChar
** labels
, const ValArrItem
* values
= NULL
);
2238 /** Version that works with wxArrayString. */
2239 void Add( const wxArrayString
& arr
, const ValArrItem
* values
= NULL
);
2241 /** Version that works with wxArrayString and wxArrayInt. */
2242 void Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
);
2244 /** Adds single item. */
2245 wxPGChoiceEntry
& Add( const wxString
& label
,
2246 int value
= wxPG_INVALID_VALUE
);
2248 /** Adds a single item, with bitmap. */
2249 wxPGChoiceEntry
& Add( const wxString
& label
,
2250 const wxBitmap
& bitmap
,
2251 int value
= wxPG_INVALID_VALUE
);
2253 /** Adds a single item with full entry information. */
2254 wxPGChoiceEntry
& Add( const wxPGChoiceEntry
& entry
)
2256 return Insert(entry
, -1);
2259 /** Adds single item. */
2260 wxPGChoiceEntry
& AddAsSorted( const wxString
& label
,
2261 int value
= wxPG_INVALID_VALUE
);
2263 void Assign( const wxPGChoices
& a
)
2265 AssignData(a
.m_data
);
2268 void AssignData( wxPGChoicesData
* data
);
2270 /** Delete all choices. */
2273 if ( m_data
!= wxPGChoicesEmptyData
)
2279 if ( m_data
== wxPGChoicesEmptyData
)
2280 m_data
= new wxPGChoicesData();
2283 /** Gets a unsigned number identifying this list. */
2284 wxPGChoicesId
GetId() const { return (wxPGChoicesId
) m_data
; };
2286 const wxString
& GetLabel( size_t ind
) const
2288 return Item(ind
).GetText();
2291 size_t GetCount () const
2293 wxASSERT_MSG( m_data
, "When checking if wxPGChoices is valid, "
2294 "use IsOk() instead of GetCount()" );
2295 return m_data
->GetCount();
2298 int GetValue( size_t ind
) const { return Item(ind
).GetValue(); }
2300 /** Returns array of values matching the given strings. Unmatching strings
2301 result in wxPG_INVALID_VALUE entry in array.
2303 wxArrayInt
GetValuesForStrings( const wxArrayString
& strings
) const;
2305 /** Returns array of indices matching given strings. Unmatching strings
2306 are added to 'unmatched', if not NULL.
2308 wxArrayInt
GetIndicesForStrings( const wxArrayString
& strings
,
2309 wxArrayString
* unmatched
= NULL
) const;
2311 /** Returns true if choices in general are likely to have values
2312 (depens on that all entries have values or none has)
2314 bool HasValues() const;
2316 bool HasValue( unsigned int i
) const
2317 { return (i
< m_data
->GetCount()) && m_data
->Item(i
)->HasValue(); }
2319 int Index( const wxString
& str
) const;
2320 int Index( int val
) const;
2322 /** Inserts single item. */
2323 wxPGChoiceEntry
& Insert( const wxString
& label
,
2325 int value
= wxPG_INVALID_VALUE
);
2327 /** Inserts a single item with full entry information. */
2328 wxPGChoiceEntry
& Insert( const wxPGChoiceEntry
& entry
, int index
);
2330 /** Returns false if this is a constant empty set of choices,
2331 which should not be modified.
2335 return ( m_data
!= wxPGChoicesEmptyData
);
2338 const wxPGChoiceEntry
& Item( unsigned int i
) const
2341 return *m_data
->Item(i
);
2344 wxPGChoiceEntry
& Item( unsigned int i
)
2347 return *m_data
->Item(i
);
2350 /** Removes count items starting at position nIndex. */
2351 void RemoveAt(size_t nIndex
, size_t count
= 1);
2354 /** Does not create copies for itself. */
2355 void Set( const wxChar
** labels
, const long* values
= NULL
)
2361 /** Version that works with wxArrayString.
2362 TODO: Deprecate this.
2364 void Set( wxArrayString
& arr
, const long* values
= (const long*) NULL
)
2371 /** Version that works with wxArrayString and wxArrayInt. */
2372 void Set( const wxArrayString
& labels
,
2373 const wxArrayInt
& values
= wxArrayInt() )
2382 // Creates exclusive copy of current choices
2385 if ( m_data
->m_refCount
!= 1 )
2387 wxPGChoicesData
* data
= new wxPGChoicesData();
2388 data
->CopyDataFrom(m_data
);
2394 // Returns data, increases refcount.
2395 wxPGChoicesData
* GetData()
2397 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
2398 m_data
->m_refCount
++;
2402 // Returns plain data ptr - no refcounting stuff is done.
2403 wxPGChoicesData
* GetDataPtr() const { return m_data
; }
2405 // Changes ownership of data to you.
2406 wxPGChoicesData
* ExtractData()
2408 wxPGChoicesData
* data
= m_data
;
2409 m_data
= wxPGChoicesEmptyData
;
2413 wxArrayString
GetLabels() const;
2416 void operator= (const wxPGChoices
& a
)
2418 AssignData(a
.m_data
);
2421 wxPGChoiceEntry
& operator[](unsigned int i
)
2426 const wxPGChoiceEntry
& operator[](unsigned int i
) const
2432 wxPGChoicesData
* m_data
;
2439 inline bool wxPGProperty::SetChoices( const wxArrayString
& labels
,
2440 const wxArrayInt
& values
)
2442 wxPGChoices
chs(labels
, values
);
2443 return SetChoices(chs
);
2446 // -----------------------------------------------------------------------
2448 #endif // wxUSE_PROPGRID
2450 #endif // _WX_PROPGRID_PROPERTY_H_