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
53 // space between vertical sides of a custom image
54 #define wxPG_CUSTOM_IMAGE_SPACINGY 1
56 // space between caption and selection rectangle,
57 #define wxPG_CAPRECTXMARGIN 2
59 // horizontally and vertically
60 #define wxPG_CAPRECTYMARGIN 1
63 /** @class wxPGCellRenderer
65 Base class for wxPropertyGrid cell renderers.
67 class WXDLLIMPEXP_PROPGRID wxPGCellRenderer
71 wxPGCellRenderer( unsigned int refCount
= 1 )
72 : m_refCount(refCount
) { }
73 virtual ~wxPGCellRenderer() { }
78 // We are painting selected item
79 Selected
= 0x00010000,
81 // We are painting item in choice popup
82 ChoicePopup
= 0x00020000,
84 // We are rendering wxOwnerDrawnComboBox control
85 // (or other owner drawn control, but that is only
86 // officially supported one ATM).
89 // We are painting a disable property
90 Disabled
= 0x00080000,
92 // We are painting selected, disabled, or similar
93 // item that dictates fore- and background colours,
94 // overriding any cell values.
95 DontUseCellFgCol
= 0x00100000,
96 DontUseCellBgCol
= 0x00200000,
97 DontUseCellColours
= DontUseCellFgCol
|
101 virtual void Render( wxDC
& dc
,
103 const wxPropertyGrid
* propertyGrid
,
104 wxPGProperty
* property
,
107 int flags
) const = 0;
109 /** Returns size of the image in front of the editable area.
111 If property is NULL, then this call is for a custom value. In that case
112 the item is index to wxPropertyGrid's custom values.
114 virtual wxSize
GetImageSize( const wxPGProperty
* property
,
118 /** Paints property category selection rectangle.
120 virtual void DrawCaptionSelectionRect( wxDC
& dc
,
122 int w
, int h
) const;
124 /** Utility to draw vertically centered text.
126 void DrawText( wxDC
& dc
,
129 const wxString
& text
) const;
132 Utility to draw editor's value, or vertically aligned text if editor is
135 void DrawEditorValue( wxDC
& dc
, const wxRect
& rect
,
136 int xOffset
, const wxString
& text
,
137 wxPGProperty
* property
,
138 const wxPGEditor
* editor
) const;
140 /** Utility to render cell bitmap and set text colour plus bg brush colour.
142 Returns image width that, for instance, can be passed to DrawText.
144 int PreDrawCell( wxDC
& dc
,
146 const wxPGCell
& cell
,
163 unsigned int m_refCount
;
167 class WXDLLIMPEXP_PROPGRID wxPGCellData
: public wxObjectRefData
169 friend class wxPGCell
;
173 void SetText( const wxString
& text
)
176 m_hasValidText
= true;
178 void SetBitmap( const wxBitmap
& bitmap
) { m_bitmap
= bitmap
; }
179 void SetFgCol( const wxColour
& col
) { m_fgCol
= col
; }
180 void SetBgCol( const wxColour
& col
) { m_bgCol
= col
; }
183 virtual ~wxPGCellData() { }
190 // True if m_text is valid and specified
196 Base class for simple wxPropertyGrid cell information.
198 class WXDLLIMPEXP_PROPGRID wxPGCell
: public wxObject
202 wxPGCell(const wxPGCell
& other
)
207 wxPGCell( const wxString
& text
,
208 const wxBitmap
& bitmap
= wxNullBitmap
,
209 const wxColour
& fgCol
= wxNullColour
,
210 const wxColour
& bgCol
= wxNullColour
);
212 virtual ~wxPGCell() { }
214 wxPGCellData
* GetData()
216 return (wxPGCellData
*) m_refData
;
219 const wxPGCellData
* GetData() const
221 return (const wxPGCellData
*) m_refData
;
226 return (m_refData
&& GetData()->m_hasValidText
);
230 Merges valid data from srcCell into this.
232 void MergeFrom( const wxPGCell
& srcCell
);
234 void SetText( const wxString
& text
);
235 void SetBitmap( const wxBitmap
& bitmap
);
236 void SetFgCol( const wxColour
& col
);
237 void SetBgCol( const wxColour
& col
);
239 const wxString
& GetText() const { return GetData()->m_text
; }
240 const wxBitmap
& GetBitmap() const { return GetData()->m_bitmap
; }
241 const wxColour
& GetFgCol() const { return GetData()->m_fgCol
; }
242 const wxColour
& GetBgCol() const { return GetData()->m_bgCol
; }
244 wxPGCell
& operator=( const wxPGCell
& other
)
246 if ( this != &other
)
254 virtual wxObjectRefData
*CreateRefData() const
255 { return new wxPGCellData(); }
257 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
261 /** @class wxPGDefaultRenderer
263 Default cell renderer, that can handles the common
266 class WXDLLIMPEXP_PROPGRID wxPGDefaultRenderer
: public wxPGCellRenderer
269 virtual void Render( wxDC
& dc
,
271 const wxPropertyGrid
* propertyGrid
,
272 wxPGProperty
* property
,
277 virtual wxSize
GetImageSize( const wxPGProperty
* property
,
284 // -----------------------------------------------------------------------
286 /** @class wxPGAttributeStorage
288 wxPGAttributeStorage is somewhat optimized storage for
289 key=variant pairs (ie. a map).
291 class WXDLLIMPEXP_PROPGRID wxPGAttributeStorage
294 wxPGAttributeStorage();
295 ~wxPGAttributeStorage();
297 void Set( const wxString
& name
, const wxVariant
& value
);
298 unsigned int GetCount() const { return (unsigned int) m_map
.size(); }
299 wxVariant
FindValue( const wxString
& name
) const
301 wxPGHashMapS2P::const_iterator it
= m_map
.find(name
);
302 if ( it
!= m_map
.end() )
304 wxVariantData
* data
= (wxVariantData
*) it
->second
;
306 return wxVariant(data
, it
->first
);
311 typedef wxPGHashMapS2P::const_iterator const_iterator
;
312 const_iterator
StartIteration() const
314 return m_map
.begin();
316 bool GetNext( const_iterator
& it
, wxVariant
& variant
) const
318 if ( it
== m_map
.end() )
321 wxVariantData
* data
= (wxVariantData
*) it
->second
;
323 variant
.SetData(data
);
324 variant
.SetName(it
->first
);
330 wxPGHashMapS2P m_map
;
335 // -----------------------------------------------------------------------
337 /** @section propgrid_propflags wxPGProperty Flags
341 enum wxPG_PROPERTY_FLAGS
344 /** Indicates bold font.
346 wxPG_PROP_MODIFIED
= 0x0001,
348 /** Disables ('greyed' text and editor does not activate) property.
350 wxPG_PROP_DISABLED
= 0x0002,
352 /** Hider button will hide this property.
354 wxPG_PROP_HIDDEN
= 0x0004,
356 /** This property has custom paint image just in front of its value.
357 If property only draws custom images into a popup list, then this
358 flag should not be set.
360 wxPG_PROP_CUSTOMIMAGE
= 0x0008,
362 /** Do not create text based editor for this property (but button-triggered
363 dialog and choice are ok).
365 wxPG_PROP_NOEDITOR
= 0x0010,
367 /** Property is collapsed, ie. it's children are hidden.
369 wxPG_PROP_COLLAPSED
= 0x0020,
372 If property is selected, then indicates that validation failed for pending
375 If property is not selected, then indicates that the the actual property
376 value has failed validation (NB: this behavior is not currently supported,
377 but may be used in future).
379 wxPG_PROP_INVALID_VALUE
= 0x0040,
383 /** Switched via SetWasModified(). Temporary flag - only used when
384 setting/changing property value.
386 wxPG_PROP_WAS_MODIFIED
= 0x0200,
389 If set, then child properties (if any) are private, and should be
390 "invisible" to the application.
392 wxPG_PROP_AGGREGATE
= 0x0400,
394 /** If set, then child properties (if any) are copies and should not
397 wxPG_PROP_CHILDREN_ARE_COPIES
= 0x0800,
400 Classifies this item as a non-category.
402 Used for faster item type identification.
404 wxPG_PROP_PROPERTY
= 0x1000,
407 Classifies this item as a category.
409 Used for faster item type identification.
411 wxPG_PROP_CATEGORY
= 0x2000,
413 /** Classifies this item as a property that has children, but is not aggregate
414 (ie children are not private).
416 wxPG_PROP_MISC_PARENT
= 0x4000,
418 /** Property is read-only. Editor is still created.
420 wxPG_PROP_READONLY
= 0x8000,
423 // NB: FLAGS ABOVE 0x8000 CANNOT BE USED WITH PROPERTY ITERATORS
426 /** Property's value is composed from values of child properties.
428 This flag cannot be used with property iterators.
430 wxPG_PROP_COMPOSED_VALUE
= 0x00010000,
432 /** Common value of property is selectable in editor.
434 This flag cannot be used with property iterators.
436 wxPG_PROP_USES_COMMON_VALUE
= 0x00020000,
438 /** Property can be set to unspecified value via editor.
439 Currently, this applies to following properties:
440 - wxIntProperty, wxUIntProperty, wxFloatProperty, wxEditEnumProperty:
444 This flag cannot be used with property iterators.
446 wxPG_PROP_AUTO_UNSPECIFIED
= 0x00040000,
448 /** Indicates the bit useable by derived properties.
450 wxPG_PROP_CLASS_SPECIFIC_1
= 0x00080000,
452 /** Indicates the bit useable by derived properties.
454 wxPG_PROP_CLASS_SPECIFIC_2
= 0x00100000
460 #define wxPG_PROP_MAX wxPG_PROP_AUTO_UNSPECIFIED
462 /** Property with children must have one of these set, otherwise iterators
463 will not work correctly.
464 Code should automatically take care of this, however.
466 #define wxPG_PROP_PARENTAL_FLAGS \
467 (wxPG_PROP_AGGREGATE|wxPG_PROP_CATEGORY|wxPG_PROP_MISC_PARENT)
472 // Combination of flags that can be stored by GetFlagsAsString
473 #define wxPG_STRING_STORED_FLAGS \
474 (wxPG_PROP_DISABLED|wxPG_PROP_HIDDEN|wxPG_PROP_NOEDITOR|wxPG_PROP_COLLAPSED)
476 // -----------------------------------------------------------------------
481 @section propgrid_property_attributes wxPropertyGrid Property Attribute
484 wxPGProperty::SetAttribute() and
485 wxPropertyGridInterface::SetPropertyAttribute() accept one of these as
486 attribute name argument.
488 You can use strings instead of constants. However, some of these
489 constants are redefined to use cached strings which may reduce
490 your binary size by some amount.
495 /** Set default value for property.
497 #define wxPG_ATTR_DEFAULT_VALUE wxS("DefaultValue")
499 /** Universal, int or double. Minimum value for numeric properties.
501 #define wxPG_ATTR_MIN wxS("Min")
503 /** Universal, int or double. Maximum value for numeric properties.
505 #define wxPG_ATTR_MAX wxS("Max")
507 /** Universal, string. When set, will be shown as text after the displayed
508 text value. Alternatively, if third column is enabled, text will be shown
509 there (for any type of property).
511 #define wxPG_ATTR_UNITS wxS("Units")
513 /** Universal, string. When set, will be shown in property's value cell
514 when displayed value string is empty, or value is unspecified.
516 #define wxPG_ATTR_INLINE_HELP wxS("InlineHelp")
518 /** Universal, wxArrayString. Set to enable auto-completion in any
519 wxTextCtrl-based property editor.
521 #define wxPG_ATTR_AUTOCOMPLETE wxS("AutoComplete")
523 /** wxBoolProperty and wxFlagsProperty specific. Value type is bool.
524 Default value is False.
526 When set to True, bool property will use check box instead of a
527 combo box as its editor control. If you set this attribute
528 for a wxFlagsProperty, it is automatically applied to child
531 #define wxPG_BOOL_USE_CHECKBOX wxS("UseCheckbox")
533 /** wxBoolProperty and wxFlagsProperty specific. Value type is bool.
534 Default value is False.
536 Set to True for the bool property to cycle value on double click
537 (instead of showing the popup listbox). If you set this attribute
538 for a wxFlagsProperty, it is automatically applied to child
541 #define wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING wxS("UseDClickCycling")
544 wxFloatProperty (and similar) specific, int, default -1.
546 Sets the (max) precision used when floating point value is rendered as
547 text. The default -1 means infinite precision.
549 #define wxPG_FLOAT_PRECISION wxS("Precision")
552 The text will be echoed as asterisks (wxTE_PASSWORD will be passed to
555 #define wxPG_STRING_PASSWORD wxS("Password")
557 /** Define base used by a wxUIntProperty. Valid constants are
558 wxPG_BASE_OCT, wxPG_BASE_DEC, wxPG_BASE_HEX and wxPG_BASE_HEXL
559 (lowercase characters).
561 #define wxPG_UINT_BASE wxS("Base")
563 /** Define prefix rendered to wxUIntProperty. Accepted constants
564 wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and wxPG_PREFIX_DOLLAR_SIGN.
565 <b>Note:</b> Only wxPG_PREFIX_NONE works with Decimal and Octal
568 #define wxPG_UINT_PREFIX wxS("Prefix")
571 wxFileProperty/wxImageFileProperty specific, wxChar*, default is
573 Sets the wildcard used in the triggered wxFileDialog. Format is the same.
575 #define wxPG_FILE_WILDCARD wxS("Wildcard")
577 /** wxFileProperty/wxImageFileProperty specific, int, default 1.
578 When 0, only the file name is shown (i.e. drive and directory are hidden).
580 #define wxPG_FILE_SHOW_FULL_PATH wxS("ShowFullPath")
582 /** Specific to wxFileProperty and derived properties, wxString, default empty.
583 If set, then the filename is shown relative to the given path string.
585 #define wxPG_FILE_SHOW_RELATIVE_PATH wxS("ShowRelativePath")
588 Specific to wxFileProperty and derived properties, wxString, default is
591 Sets the initial path of where to look for files.
593 #define wxPG_FILE_INITIAL_PATH wxS("InitialPath")
595 /** Specific to wxFileProperty and derivatives, wxString, default is empty.
596 Sets a specific title for the dir dialog.
598 #define wxPG_FILE_DIALOG_TITLE wxS("DialogTitle")
600 /** Specific to wxDirProperty, wxString, default is empty.
601 Sets a specific message for the dir dialog.
603 #define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage")
605 /** Sets displayed date format for wxDateProperty.
607 #define wxPG_DATE_FORMAT wxS("DateFormat")
609 /** Sets wxDatePickerCtrl window style used with wxDateProperty. Default
610 is wxDP_DEFAULT | wxDP_SHOWCENTURY.
612 #define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
614 /** SpinCtrl editor, int or double. How much number changes when button is
615 pressed (or up/down on keybard).
617 #define wxPG_ATTR_SPINCTRL_STEP wxS("Step")
619 /** SpinCtrl editor, bool. If true, value wraps at Min/Max.
621 #define wxPG_ATTR_SPINCTRL_WRAP wxS("Wrap")
624 wxMultiChoiceProperty, int.
625 If 0, no user strings allowed. If 1, user strings appear before list
626 strings. If 2, user strings appear after list string.
628 #define wxPG_ATTR_MULTICHOICE_USERSTRINGMODE wxS("UserStringMode")
631 wxColourProperty and its kind, int, default 1.
633 Setting this attribute to 0 hides custom colour from property's list of
636 #define wxPG_COLOUR_ALLOW_CUSTOM wxS("AllowCustom")
641 // Redefine attribute macros to use cached strings
642 #undef wxPG_ATTR_DEFAULT_VALUE
643 #define wxPG_ATTR_DEFAULT_VALUE wxPGGlobalVars->m_strDefaultValue
645 #define wxPG_ATTR_MIN wxPGGlobalVars->m_strMin
647 #define wxPG_ATTR_MAX wxPGGlobalVars->m_strMax
648 #undef wxPG_ATTR_UNITS
649 #define wxPG_ATTR_UNITS wxPGGlobalVars->m_strUnits
650 #undef wxPG_ATTR_INLINE_HELP
651 #define wxPG_ATTR_INLINE_HELP wxPGGlobalVars->m_strInlineHelp
655 // -----------------------------------------------------------------------
659 /** @class wxPGChoiceEntry
660 Data of a single wxPGChoices choice.
662 class WXDLLIMPEXP_PROPGRID wxPGChoiceEntry
: public wxPGCell
666 wxPGChoiceEntry(const wxPGChoiceEntry
& other
)
669 m_value
= other
.m_value
;
671 wxPGChoiceEntry( const wxString
& label
,
672 int value
= wxPG_INVALID_VALUE
)
673 : wxPGCell(), m_value(value
)
678 virtual ~wxPGChoiceEntry() { }
680 void SetValue( int value
) { m_value
= value
; }
681 int GetValue() const { return m_value
; }
683 wxPGChoiceEntry
& operator=( const wxPGChoiceEntry
& other
)
685 if ( this != &other
)
689 m_value
= other
.m_value
;
698 typedef void* wxPGChoicesId
;
700 class WXDLLIMPEXP_PROPGRID wxPGChoicesData
702 friend class wxPGChoices
;
704 // Constructor sets m_refCount to 1.
707 void CopyDataFrom( wxPGChoicesData
* data
);
709 wxPGChoiceEntry
& Insert( int index
, const wxPGChoiceEntry
& item
);
711 // Delete all entries
714 unsigned int GetCount() const
716 return (unsigned int) m_items
.size();
719 const wxPGChoiceEntry
& Item( unsigned int i
) const
721 wxASSERT_MSG( i
< GetCount(), "invalid index" );
725 wxPGChoiceEntry
& Item( unsigned int i
)
727 wxASSERT_MSG( i
< GetCount(), "invalid index" );
734 wxASSERT( m_refCount
>= 0 );
735 if ( m_refCount
== 0 )
740 wxVector
<wxPGChoiceEntry
> m_items
;
742 // So that multiple properties can use the same set
745 virtual ~wxPGChoicesData();
748 #define wxPGChoicesEmptyData ((wxPGChoicesData*)NULL)
752 /** @class wxPGChoices
754 Helper class for managing choices of wxPropertyGrid properties.
755 Each entry can have label, value, bitmap, text colour, and background
758 wxPGChoices uses reference counting, similar to other wxWidgets classes.
759 This means that assignment operator and copy constructor only copy the
760 reference and not the actual data. Use Copy() member function to create a
763 @remarks If you do not specify value for entry, index is used.
768 class WXDLLIMPEXP_PROPGRID wxPGChoices
771 typedef long ValArrItem
;
773 /** Default constructor. */
780 Copy constructor, uses reference counting. To create a real copy,
781 use Copy() member function instead.
783 wxPGChoices( const wxPGChoices
& a
)
785 if ( a
.m_data
!= wxPGChoicesEmptyData
)
788 m_data
->m_refCount
++;
799 Values for choices. If NULL, indexes are used.
801 wxPGChoices( const wxChar
** labels
, const long* values
= NULL
)
814 Values for choices. If empty, indexes are used.
816 wxPGChoices( const wxArrayString
& labels
,
817 const wxArrayInt
& values
= wxArrayInt() )
823 /** Simple interface constructor. */
824 wxPGChoices( wxPGChoicesData
* data
)
840 If did not have own copies, creates them now. If was empty, identical
841 to set except that creates copies.
844 Labels for added choices.
847 Values for added choices. If empty, relevant entry indexes are used.
849 void Add( const wxChar
** labels
, const ValArrItem
* values
= NULL
);
851 /** Version that works with wxArrayString and wxArrayInt. */
852 void Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
= wxArrayInt() );
855 Adds a single choice.
858 Label for added choice.
861 Value for added choice. If unspecified, index is used.
863 wxPGChoiceEntry
& Add( const wxString
& label
,
864 int value
= wxPG_INVALID_VALUE
);
866 /** Adds a single item, with bitmap. */
867 wxPGChoiceEntry
& Add( const wxString
& label
,
868 const wxBitmap
& bitmap
,
869 int value
= wxPG_INVALID_VALUE
);
871 /** Adds a single item with full entry information. */
872 wxPGChoiceEntry
& Add( const wxPGChoiceEntry
& entry
)
874 return Insert(entry
, -1);
877 /** Adds single item. */
878 wxPGChoiceEntry
& AddAsSorted( const wxString
& label
,
879 int value
= wxPG_INVALID_VALUE
);
882 Assigns choices data, using reference counting. To create a real copy,
883 use Copy() member function instead.
885 void Assign( const wxPGChoices
& a
)
887 AssignData(a
.m_data
);
890 void AssignData( wxPGChoicesData
* data
);
892 /** Delete all choices. */
896 Returns a real copy of the choices.
898 wxPGChoices
Copy() const
902 dst
.m_data
->CopyDataFrom(m_data
);
908 if ( m_data
== wxPGChoicesEmptyData
)
909 m_data
= new wxPGChoicesData();
912 /** Gets a unsigned number identifying this list. */
913 wxPGChoicesId
GetId() const { return (wxPGChoicesId
) m_data
; };
915 const wxString
& GetLabel( unsigned int ind
) const
917 return Item(ind
).GetText();
920 unsigned int GetCount () const
925 return m_data
->GetCount();
928 int GetValue( unsigned int ind
) const { return Item(ind
).GetValue(); }
930 /** Returns array of values matching the given strings. Unmatching strings
931 result in wxPG_INVALID_VALUE entry in array.
933 wxArrayInt
GetValuesForStrings( const wxArrayString
& strings
) const;
935 /** Returns array of indices matching given strings. Unmatching strings
936 are added to 'unmatched', if not NULL.
938 wxArrayInt
GetIndicesForStrings( const wxArrayString
& strings
,
939 wxArrayString
* unmatched
= NULL
) const;
941 int Index( const wxString
& str
) const;
942 int Index( int val
) const;
944 /** Inserts single item. */
945 wxPGChoiceEntry
& Insert( const wxString
& label
,
947 int value
= wxPG_INVALID_VALUE
);
949 /** Inserts a single item with full entry information. */
950 wxPGChoiceEntry
& Insert( const wxPGChoiceEntry
& entry
, int index
);
952 /** Returns false if this is a constant empty set of choices,
953 which should not be modified.
957 return ( m_data
!= wxPGChoicesEmptyData
);
960 const wxPGChoiceEntry
& Item( unsigned int i
) const
963 return m_data
->Item(i
);
966 wxPGChoiceEntry
& Item( unsigned int i
)
969 return m_data
->Item(i
);
972 /** Removes count items starting at position nIndex. */
973 void RemoveAt(size_t nIndex
, size_t count
= 1);
976 /** Does not create copies for itself. */
977 void Set( const wxChar
** labels
, const long* values
= NULL
)
984 /** Version that works with wxArrayString and wxArrayInt. */
985 void Set( const wxArrayString
& labels
,
986 const wxArrayInt
& values
= wxArrayInt() )
995 // Creates exclusive copy of current choices
996 void AllocExclusive();
998 // Returns data, increases refcount.
999 wxPGChoicesData
* GetData()
1001 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
1002 m_data
->m_refCount
++;
1006 // Returns plain data ptr - no refcounting stuff is done.
1007 wxPGChoicesData
* GetDataPtr() const { return m_data
; }
1009 // Changes ownership of data to you.
1010 wxPGChoicesData
* ExtractData()
1012 wxPGChoicesData
* data
= m_data
;
1013 m_data
= wxPGChoicesEmptyData
;
1017 wxArrayString
GetLabels() const;
1020 void operator= (const wxPGChoices
& a
)
1023 AssignData(a
.m_data
);
1026 wxPGChoiceEntry
& operator[](unsigned int i
)
1031 const wxPGChoiceEntry
& operator[](unsigned int i
) const
1037 wxPGChoicesData
* m_data
;
1044 // -----------------------------------------------------------------------
1046 /** @class wxPGProperty
1048 wxPGProperty is base class for all wxPropertyGrid properties.
1050 NB: Full class overview is now only present in
1051 interface/wx/propgrid/property.h.
1053 @library{wxpropgrid}
1056 class WXDLLIMPEXP_PROPGRID wxPGProperty
: public wxObject
1058 friend class wxPropertyGrid
;
1059 friend class wxPropertyGridInterface
;
1060 friend class wxPropertyGridPageState
;
1061 friend class wxPropertyGridPopulator
;
1062 friend class wxStringProperty
; // Proper "<composed>" support requires this
1064 DECLARE_ABSTRACT_CLASS(wxPGProperty
)
1066 typedef wxUint32 FlagType
;
1068 /** Basic constructor.
1073 Non-abstract property classes should have constructor of this style:
1077 // If T is a class, then it should be a constant reference
1078 // (e.g. const T& ) instead.
1079 MyProperty( const wxString& label, const wxString& name, T value )
1082 // Generally recommended way to set the initial value
1083 // (as it should work in pretty much 100% of cases).
1088 // If has private child properties then create them here. Also
1089 // set flag that indicates presence of private children. E.g.:
1091 // AddPrivateChild( new wxStringProperty("Subprop 1",
1093 // value.GetSubProp1() ) );
1098 wxPGProperty( const wxString
& label
, const wxString
& name
);
1102 It is customary for derived properties to implement this.
1104 virtual ~wxPGProperty();
1106 /** This virtual function is called after m_value has been set.
1109 - If m_value was set to Null variant (ie. unspecified value),
1110 OnSetValue() will not be called.
1111 - m_value may be of any variant type. Typically properties internally
1112 support only one variant type, and as such OnSetValue() provides a
1113 good opportunity to convert
1114 supported values into internal type.
1115 - Default implementation does nothing.
1117 virtual void OnSetValue();
1119 /** Override this to return something else than m_value as the value.
1121 virtual wxVariant
DoGetValue() const { return m_value
; }
1123 #if !defined(SWIG) || defined(CREATE_VCW)
1124 /** Implement this function in derived class to check the value.
1125 Return true if it is ok. Returning false prevents property change events
1129 - Default implementation always returns true.
1131 virtual bool ValidateValue( wxVariant
& value
,
1132 wxPGValidationInfo
& validationInfo
) const;
1135 Converts text into wxVariant value appropriate for this property.
1138 On function entry this is the old value (should not be wxNullVariant
1139 in normal cases). Translated value must be assigned back to it.
1142 Text to be translated into variant.
1145 If wxPG_FULL_VALUE is set, returns complete, storable value instead
1146 of displayable one (they may be different).
1147 If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of
1148 composite property string value (as generated by ValueToString()
1149 called with this same flag).
1151 @return Returns @true if resulting wxVariant value was different.
1153 @remarks Default implementation converts semicolon delimited tokens into
1154 child values. Only works for properties with children.
1156 You might want to take into account that m_value is Null variant
1157 if property value is unspecified (which is usually only case if
1158 you explicitly enabled that sort behavior).
1160 virtual bool StringToValue( wxVariant
& variant
,
1161 const wxString
& text
,
1162 int argFlags
= 0 ) const;
1165 Converts integer (possibly a choice selection) into wxVariant value
1166 appropriate for this property.
1169 On function entry this is the old value (should not be wxNullVariant
1170 in normal cases). Translated value must be assigned back to it.
1173 Integer to be translated into variant.
1176 If wxPG_FULL_VALUE is set, returns complete, storable value instead
1179 @return Returns @true if resulting wxVariant value was different.
1182 - If property is not supposed to use choice or spinctrl or other editor
1183 with int-based value, it is not necessary to implement this method.
1184 - Default implementation simply assign given int to m_value.
1185 - If property uses choice control, and displays a dialog on some choice
1186 items, then it is preferred to display that dialog in IntToValue
1188 - You might want to take into account that m_value is Null variant if
1189 property value is unspecified (which is usually only case if you
1190 explicitly enabled that sort behavior).
1192 virtual bool IntToValue( wxVariant
& value
,
1194 int argFlags
= 0 ) const;
1195 #endif // !defined(SWIG) || defined(CREATE_VCW)
1197 Converts property value into a text representation.
1200 Value to be converted.
1203 If 0 (default value), then displayed string is returned.
1204 If wxPG_FULL_VALUE is set, returns complete, storable string value
1205 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
1206 string value that must be editable in textctrl. If
1207 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
1208 display as a part of string property's composite text
1211 @remarks Default implementation calls GenerateComposedValue().
1213 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
1215 /** Converts string to a value, and if successful, calls SetValue() on it.
1216 Default behavior is to do nothing.
1218 String to get the value from.
1220 true if value was changed.
1222 bool SetValueFromString( const wxString
& text
, int flags
= wxPG_PROGRAMMATIC_VALUE
);
1224 /** Converts integer to a value, and if succesful, calls SetValue() on it.
1225 Default behavior is to do nothing.
1227 Int to get the value from.
1229 If has wxPG_FULL_VALUE, then the value given is a actual value and
1232 True if value was changed.
1234 bool SetValueFromInt( long value
, int flags
= 0 );
1237 Returns size of the custom painted image in front of property.
1239 This method must be overridden to return non-default value if
1240 OnCustomPaint is to be called.
1242 Normally -1, but can be an index to the property's list of items.
1244 - Default behavior is to return wxSize(0,0), which means no image.
1245 - Default image width or height is indicated with dimension -1.
1246 - You can also return wxPG_DEFAULT_IMAGE_SIZE, i.e. wxSize(-1, -1).
1248 virtual wxSize
OnMeasureImage( int item
= -1 ) const;
1251 Events received by editor widgets are processed here.
1253 Note that editor class usually processes most events. Some, such as
1254 button press events of TextCtrlAndButton class, can be handled here.
1255 Also, if custom handling for regular events is desired, then that can
1256 also be done (for example, wxSystemColourProperty custom handles
1257 wxEVT_COMMAND_CHOICE_SELECTED to display colour picker dialog when
1258 'custom' selection is made).
1260 If the event causes value to be changed, SetValueInEvent()
1261 should be called to set the new value.
1266 Should return true if any changes in value should be reported.
1268 If property uses choice control, and displays a dialog on some choice
1269 items, then it is preferred to display that dialog in IntToValue
1272 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
1273 wxWindow
* wnd_primary
,
1277 Called after value of a child property has been altered. Must return
1278 new value of the whole property (after any alterations warrented by
1281 Note that this function is usually called at the time that value of
1282 this property, or given child property, is still pending for change,
1283 and as such, result of GetValue() or m_value should not be relied
1286 Sample pseudo-code implementation:
1289 wxVariant MyProperty::ChildChanged( wxVariant& thisValue,
1291 wxVariant& childValue ) const
1293 // Acquire reference to actual type of data stored in variant
1294 // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros
1295 // were used to create the variant class).
1296 T& data = TFromVariant(thisValue);
1298 // Copy childValue into data.
1299 switch ( childIndex )
1302 data.SetSubProp1( childvalue.GetLong() );
1305 data.SetSubProp2( childvalue.GetString() );
1310 // Return altered data
1316 Value of this property. Changed value should be returned (in
1317 previous versions of wxPropertyGrid it was only necessary to
1318 write value back to this argument).
1320 Index of child changed (you can use Item(childIndex) to get
1323 (Pending) value of the child property.
1326 Modified value of the whole property.
1328 virtual wxVariant
ChildChanged( wxVariant
& thisValue
,
1330 wxVariant
& childValue
) const;
1332 /** Returns pointer to an instance of used editor.
1334 virtual const wxPGEditor
* DoGetEditorClass() const;
1336 /** Returns pointer to the wxValidator that should be used
1337 with the editor of this property (NULL for no validator).
1338 Setting validator explicitly via SetPropertyValidator
1341 In most situations, code like this should work well
1342 (macros are used to maintain one actual validator instance,
1343 so on the second call the function exits within the first
1348 wxValidator* wxMyPropertyClass::DoGetValidator () const
1350 WX_PG_DOGETVALIDATOR_ENTRY()
1352 wxMyValidator* validator = new wxMyValidator(...);
1354 ... prepare validator...
1356 WX_PG_DOGETVALIDATOR_EXIT(validator)
1362 You can get common filename validator by returning
1363 wxFileProperty::GetClassValidator(). wxDirProperty,
1364 for example, uses it.
1366 virtual wxValidator
* DoGetValidator () const;
1369 Override to paint an image in front of the property value text or
1370 drop-down list item (but only if wxPGProperty::OnMeasureImage is
1371 overridden as well).
1373 If property's OnMeasureImage() returns size that has height != 0 but
1374 less than row height ( < 0 has special meanings), wxPropertyGrid calls
1375 this method to draw a custom image in a limited area in front of the
1376 editor control or value text/graphics, and if control has drop-down
1377 list, then the image is drawn there as well (even in the case
1378 OnMeasureImage() returned higher height than row height).
1380 NOTE: Following applies when OnMeasureImage() returns a "flexible"
1381 height ( using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable
1382 height items: If rect.x is < 0, then this is a measure item call, which
1383 means that dc is invalid and only thing that should be done is to set
1384 paintdata.m_drawnHeight to the height of the image of item at index
1385 paintdata.m_choiceItem. This call may be done even as often as once
1386 every drop-down popup show.
1391 Box reserved for custom graphics. Includes surrounding rectangle,
1392 if any. If x is < 0, then this is a measure item call (see above).
1394 wxPGPaintData structure with much useful data.
1397 - You can actually exceed rect width, but if you do so then
1398 paintdata.m_drawnWidth must be set to the full width drawn in
1400 - Due to technical reasons, rect's height will be default even if
1401 custom height was reported during measure call.
1402 - Brush is guaranteed to be default background colour. It has been
1403 already used to clear the background of area being painted. It
1405 - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper
1406 colour) pen for drawing framing rectangle. It can be changed as
1409 @see ValueToString()
1411 virtual void OnCustomPaint( wxDC
& dc
,
1413 wxPGPaintData
& paintdata
);
1416 Returns used wxPGCellRenderer instance for given property column
1419 Default implementation returns editor's renderer for all columns.
1421 virtual wxPGCellRenderer
* GetCellRenderer( int column
) const;
1423 /** Returns which choice is currently selected. Only applies to properties
1426 Needs to reimplemented in derived class if property value does not
1427 map directly to a choice. Integer as index, bool, and string usually do.
1429 virtual int GetChoiceSelection() const;
1432 Refresh values of child properties.
1434 Automatically called after value is set.
1436 virtual void RefreshChildren();
1438 /** Special handling for attributes of this property.
1440 If returns false, then the attribute will be automatically stored in
1443 Default implementation simply returns false.
1445 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
1447 /** Returns value of an attribute.
1449 Override if custom handling of attributes is needed.
1451 Default implementation simply return NULL variant.
1453 virtual wxVariant
DoGetAttribute( const wxString
& name
) const;
1455 /** Returns instance of a new wxPGEditorDialogAdapter instance, which is
1456 used when user presses the (optional) button next to the editor control;
1458 Default implementation returns NULL (ie. no action is generated when
1461 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
1464 Called whenever validation has failed with given pending value.
1466 @remarks If you implement this in your custom property class, please
1467 remember to call the baser implementation as well, since they
1468 may use it to revert property into pre-change state.
1470 virtual void OnValidationFailure( wxVariant
& pendingValue
);
1472 /** Append a new choice to property's list of choices.
1474 int AddChoice( const wxString
& label
, int value
= wxPG_INVALID_VALUE
)
1476 return InsertChoice(label
, wxNOT_FOUND
, value
);
1480 Returns true if children of this property are component values (for
1481 instance, points size, face name, and is_underlined are component
1484 bool AreChildrenComponents() const
1486 if ( m_flags
& (wxPG_PROP_COMPOSED_VALUE
|wxPG_PROP_AGGREGATE
) )
1493 Deletes children of the property.
1495 void DeleteChildren();
1498 Removes entry from property's wxPGChoices and editor control (if it is
1501 If selected item is deleted, then the value is set to unspecified.
1503 void DeleteChoice( int index
);
1506 Call to enable or disable usage of common value (integer value that can
1507 be selected for properties instead of their normal values) for this
1510 Common values are disabled by the default for all properties.
1512 void EnableCommonValue( bool enable
= true )
1514 if ( enable
) SetFlag( wxPG_PROP_USES_COMMON_VALUE
);
1515 else ClearFlag( wxPG_PROP_USES_COMMON_VALUE
);
1519 Composes text from values of child properties.
1521 wxString
GenerateComposedValue() const
1524 DoGenerateComposedValue(s
);
1528 /** Returns property's label. */
1529 const wxString
& GetLabel() const { return m_label
; }
1531 /** Returns property's name with all (non-category, non-root) parents. */
1532 wxString
GetName() const;
1535 Returns property's base name (ie parent's name is not added in any
1538 const wxString
& GetBaseName() const { return m_name
; }
1540 /** Returns read-only reference to property's list of choices.
1542 const wxPGChoices
& GetChoices() const
1547 /** Returns coordinate to the top y of the property. Note that the
1548 position of scrollbars is not taken into account.
1552 wxVariant
GetValue() const
1554 return DoGetValue();
1557 /** Returns reference to the internal stored value. GetValue is preferred
1558 way to get the actual value, since GetValueRef ignores DoGetValue,
1559 which may override stored value.
1561 wxVariant
& GetValueRef()
1566 const wxVariant
& GetValueRef() const
1571 // Helper function (for wxPython bindings and such) for settings protected
1573 wxVariant
GetValuePlain() const
1578 /** Returns text representation of property's value.
1581 If 0 (default value), then displayed string is returned.
1582 If wxPG_FULL_VALUE is set, returns complete, storable string value
1583 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
1584 string value that must be editable in textctrl. If
1585 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
1586 display as a part of string property's composite text
1589 @remarks In older versions, this function used to be overridden to convert
1590 property's value into a string representation. This function is
1591 now handled by ValueToString(), and overriding this function now
1592 will result in run-time assertion failure.
1594 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
1596 /** Synonymous to GetValueAsString().
1598 @deprecated Use GetValueAsString() instead.
1600 @see GetValueAsString()
1602 wxDEPRECATED( wxString
GetValueString( int argFlags
= 0 ) const );
1605 Returns wxPGCell of given column.
1607 const wxPGCell
& GetCell( unsigned int column
) const;
1609 wxPGCell
& GetCell( unsigned int column
);
1611 /** Return number of displayed common values for this property.
1613 int GetDisplayedCommonValueCount() const;
1615 wxString
GetDisplayedString() const
1617 return GetValueAsString(0);
1620 /** Returns property grid where property lies. */
1621 wxPropertyGrid
* GetGrid() const;
1623 /** Returns owner wxPropertyGrid, but only if one is currently on a page
1624 displaying this property. */
1625 wxPropertyGrid
* GetGridIfDisplayed() const;
1627 /** Returns highest level non-category, non-root parent. Useful when you
1628 have nested wxCustomProperties/wxParentProperties.
1630 Thus, if immediate parent is root or category, this will return the
1633 wxPGProperty
* GetMainParent() const;
1635 /** Return parent of property */
1636 wxPGProperty
* GetParent() const { return m_parent
; }
1638 /** Returns true if property has editable wxTextCtrl when selected.
1641 Altough disabled properties do not displayed editor, they still
1642 return True here as being disabled is considered a temporary
1643 condition (unlike being read-only or having limited editing enabled).
1645 bool IsTextEditable() const;
1647 bool IsValueUnspecified() const
1649 return m_value
.IsNull();
1652 FlagType
HasFlag( FlagType flag
) const
1654 return ( m_flags
& flag
);
1657 /** Returns comma-delimited string of property attributes.
1659 const wxPGAttributeStorage
& GetAttributes() const
1661 return m_attributes
;
1664 /** Returns m_attributes as list wxVariant.
1666 wxVariant
GetAttributesAsList() const;
1668 FlagType
GetFlags() const
1673 const wxPGEditor
* GetEditorClass() const;
1675 wxString
GetValueType() const
1677 return m_value
.GetType();
1680 /** Returns editor used for given column. NULL for no editor.
1682 const wxPGEditor
* GetColumnEditor( int column
) const
1685 return GetEditorClass();
1690 /** Returns common value selected for this property. -1 for none.
1692 int GetCommonValue() const
1694 return m_commonValue
;
1697 /** Returns true if property has even one visible child.
1699 bool HasVisibleChildren() const;
1702 Use this member function to add independent (ie. regular) children to
1705 @return Inserted childProperty.
1707 @remarks wxPropertyGrid is not automatically refreshed by this
1710 @see AddPrivateChild()
1712 wxPGProperty
* InsertChild( int index
, wxPGProperty
* childProperty
);
1714 /** Inserts a new choice to property's list of choices.
1716 int InsertChoice( const wxString
& label
, int index
, int value
= wxPG_INVALID_VALUE
);
1719 Returns true if this property is actually a wxPropertyCategory.
1721 bool IsCategory() const { return HasFlag(wxPG_PROP_CATEGORY
)?true:false; }
1723 /** Returns true if this property is actually a wxRootProperty.
1725 bool IsRoot() const { return (m_parent
== NULL
); }
1727 /** Returns true if this is a sub-property. */
1728 bool IsSubProperty() const
1730 wxPGProperty
* parent
= (wxPGProperty
*)m_parent
;
1731 if ( parent
&& !parent
->IsCategory() )
1736 /** Returns last visible sub-property, recursively.
1738 const wxPGProperty
* GetLastVisibleSubItem() const;
1740 wxVariant
GetDefaultValue() const;
1742 int GetMaxLength() const
1744 return (int) m_maxLen
;
1748 Determines, recursively, if all children are not unspecified.
1751 Assumes members in this wxVariant list as pending
1754 bool AreAllChildrenSpecified( wxVariant
* pendingList
= NULL
) const;
1756 /** Updates composed values of parent non-category properties, recursively.
1757 Returns topmost property updated.
1760 - Must not call SetValue() (as can be called in it).
1762 wxPGProperty
* UpdateParentValues();
1764 /** Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
1766 bool UsesAutoUnspecified() const
1768 return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED
)?true:false;
1771 wxBitmap
* GetValueImage() const
1773 return m_valueBitmap
;
1776 wxVariant
GetAttribute( const wxString
& name
) const;
1779 Returns named attribute, as string, if found.
1781 Otherwise defVal is returned.
1783 wxString
GetAttribute( const wxString
& name
, const wxString
& defVal
) const;
1786 Returns named attribute, as long, if found.
1788 Otherwise defVal is returned.
1790 long GetAttributeAsLong( const wxString
& name
, long defVal
) const;
1793 Returns named attribute, as double, if found.
1795 Otherwise defVal is returned.
1797 double GetAttributeAsDouble( const wxString
& name
, double defVal
) const;
1799 unsigned int GetDepth() const { return (unsigned int)m_depth
; }
1801 /** Gets flags as a'|' delimited string. Note that flag names are not
1802 prepended with 'wxPG_PROP_'.
1804 String will only be made to include flags combined by this parameter.
1806 wxString
GetFlagsAsString( FlagType flagsMask
) const;
1808 /** Returns position in parent's array. */
1809 unsigned int GetIndexInParent() const
1811 return (unsigned int)m_arrIndex
;
1814 /** Hides or reveals the property.
1816 true for hide, false for reveal.
1818 By default changes are applied recursively. Set this paramter
1819 wxPG_DONT_RECURSE to prevent this.
1821 inline bool Hide( bool hide
, int flags
= wxPG_RECURSE
);
1823 bool IsExpanded() const
1824 { return (!(m_flags
& wxPG_PROP_COLLAPSED
) && GetChildCount()); }
1826 /** Returns true if all parents expanded.
1828 bool IsVisible() const;
1830 bool IsEnabled() const { return !(m_flags
& wxPG_PROP_DISABLED
); }
1832 /** If property's editor is created this forces its recreation.
1833 Useful in SetAttribute etc. Returns true if actually did anything.
1835 bool RecreateEditor();
1837 /** If property's editor is active, then update it's value.
1839 void RefreshEditor();
1841 /** Sets an attribute for this property.
1843 Text identifier of attribute. See @ref propgrid_property_attributes.
1847 void SetAttribute( const wxString
& name
, wxVariant value
);
1849 void SetAttributes( const wxPGAttributeStorage
& attributes
);
1852 Sets property's background colour.
1855 Background colour to use.
1858 If @true, children are affected recursively, and any categories
1861 void SetBackgroundColour( const wxColour
& colour
,
1862 bool recursively
= false );
1865 Sets property's text colour.
1871 If @true, children are affected recursively, and any categories
1874 void SetTextColour( const wxColour
& colour
,
1875 bool recursively
= false );
1877 /** Set default value of a property. Synonymous to
1880 SetAttribute("DefaultValue", value);
1883 void SetDefaultValue( wxVariant
& value
);
1886 /** Sets editor for a property.
1889 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1890 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full
1893 For custom editors, use pointer you received from
1894 wxPropertyGrid::RegisterEditorClass().
1896 void SetEditor( const wxPGEditor
* editor
)
1898 m_customEditor
= editor
;
1902 /** Sets editor for a property.
1904 inline void SetEditor( const wxString
& editorName
);
1907 Sets cell information for given column.
1909 void SetCell( int column
, const wxPGCell
& cell
);
1911 /** Sets common value selected for this property. -1 for none.
1913 void SetCommonValue( int commonValue
)
1915 m_commonValue
= commonValue
;
1918 /** Sets flags from a '|' delimited string. Note that flag names are not
1919 prepended with 'wxPG_PROP_'.
1921 void SetFlagsFromString( const wxString
& str
);
1923 /** Sets property's "is it modified?" flag. Affects children recursively.
1925 void SetModifiedStatus( bool modified
)
1927 SetFlagRecursively(wxPG_PROP_MODIFIED
, modified
);
1930 /** Call in OnEvent(), OnButtonClick() etc. to change the property value
1931 based on user input.
1934 This method is const since it doesn't actually modify value, but posts
1935 given variant as pending value, stored in wxPropertyGrid.
1937 void SetValueInEvent( wxVariant value
) const;
1940 Call this to set value of the property.
1942 Unlike methods in wxPropertyGrid, this does not automatically update
1946 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run
1947 through validation process and send property change event.
1949 If you need to change property value in event, based on user input, use
1950 SetValueInEvent() instead.
1953 Pointer to list variant that contains child values. Used to
1954 indicate which children should be marked as modified.
1957 Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR, which is
1958 enabled by default).
1960 void SetValue( wxVariant value
, wxVariant
* pList
= NULL
,
1961 int flags
= wxPG_SETVAL_REFRESH_EDITOR
);
1963 /** Set wxBitmap in front of the value. This bitmap may be ignored
1964 by custom cell renderers.
1966 void SetValueImage( wxBitmap
& bmp
);
1968 /** Sets selected choice and changes property value.
1970 Tries to retain value type, although currently if it is not string,
1971 then it is forced to integer.
1973 void SetChoiceSelection( int newValue
);
1975 void SetExpanded( bool expanded
)
1977 if ( !expanded
) m_flags
|= wxPG_PROP_COLLAPSED
;
1978 else m_flags
&= ~wxPG_PROP_COLLAPSED
;
1982 Sets given property flag(s).
1984 void SetFlag( FlagType flag
) { m_flags
|= flag
; }
1987 Sets or clears given property flag(s).
1989 void ChangeFlag( FlagType flag
, bool set
)
1997 void SetFlagRecursively( FlagType flag
, bool set
);
1999 void SetHelpString( const wxString
& helpString
)
2001 m_helpString
= helpString
;
2004 void SetLabel( const wxString
& label
) { m_label
= label
; }
2006 inline void SetName( const wxString
& newName
);
2009 Changes what sort of parent this property is for its children.
2012 Use one of the following values: wxPG_PROP_MISC_PARENT (for
2013 generic parents), wxPG_PROP_CATEGORY (for categories), or
2014 wxPG_PROP_AGGREGATE (for derived property classes with private
2017 @remarks You generally do not need to call this function.
2019 void SetParentalType( int flag
)
2021 m_flags
&= ~(wxPG_PROP_PROPERTY
|wxPG_PROP_PARENTAL_FLAGS
);
2025 void SetValueToUnspecified()
2027 wxVariant val
; // Create NULL variant
2031 // Helper function (for wxPython bindings and such) for settings protected
2033 void SetValuePlain( wxVariant value
)
2038 #if wxUSE_VALIDATORS
2039 /** Sets wxValidator for a property*/
2040 void SetValidator( const wxValidator
& validator
)
2042 m_validator
= wxDynamicCast(validator
.Clone(),wxValidator
);
2045 /** Gets assignable version of property's validator. */
2046 wxValidator
* GetValidator() const
2050 return DoGetValidator();
2052 #endif // #if wxUSE_VALIDATORS
2055 /** Returns client data (void*) of a property.
2057 void* GetClientData() const
2059 return m_clientData
;
2062 /** Sets client data (void*) of a property.
2064 This untyped client data has to be deleted manually.
2066 void SetClientData( void* clientData
)
2068 m_clientData
= clientData
;
2071 /** Returns client object of a property.
2073 void SetClientObject(wxClientData
* clientObject
)
2075 delete m_clientObject
;
2076 m_clientObject
= clientObject
;
2079 /** Sets managed client object of a property.
2081 wxClientData
*GetClientObject() const { return m_clientObject
; }
2084 /** Sets new set of choices for property.
2087 This operation clears the property value.
2089 bool SetChoices( wxPGChoices
& choices
);
2091 /** Set max length of text in text editor.
2093 inline bool SetMaxLength( int maxLen
);
2095 /** Call with 'false' in OnSetValue to cancel value changes after all
2096 (ie. cancel 'true' returned by StringToValue() or IntToValue()).
2098 void SetWasModified( bool set
= true )
2100 if ( set
) m_flags
|= wxPG_PROP_WAS_MODIFIED
;
2101 else m_flags
&= ~wxPG_PROP_WAS_MODIFIED
;
2104 const wxString
& GetHelpString() const
2106 return m_helpString
;
2109 void ClearFlag( FlagType flag
) { m_flags
&= ~(flag
); }
2111 // Use, for example, to detect if item is inside collapsed section.
2112 bool IsSomeParent( wxPGProperty
* candidate_parent
) const;
2115 Adapts list variant into proper value using consecutive
2118 void AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const;
2120 #if wxPG_COMPATIBILITY_1_4
2122 Adds a private child property.
2124 @deprecated Use AddPrivateChild() instead.
2126 @see AddPrivateChild()
2128 wxDEPRECATED( void AddChild( wxPGProperty
* prop
) );
2132 Adds a private child property. If you use this instead of
2133 wxPropertyGridInterface::Insert() or
2134 wxPropertyGridInterface::AppendIn(), then property's parental
2135 type will automatically be set up to wxPG_PROP_AGGREGATE. In other
2136 words, all properties of this property will become private.
2138 void AddPrivateChild( wxPGProperty
* prop
);
2141 Appends a new child property.
2143 wxPGProperty
* AppendChild( wxPGProperty
* prop
)
2145 return InsertChild(-1, prop
);
2148 /** Returns height of children, recursively, and
2149 by taking expanded/collapsed status into account.
2151 iMax is used when finding property y-positions.
2153 int GetChildrenHeight( int lh
, int iMax
= -1 ) const;
2155 /** Returns number of child properties */
2156 unsigned int GetChildCount() const
2158 return (unsigned int) m_children
.size();
2161 /** Returns sub-property at index i. */
2162 wxPGProperty
* Item( unsigned int i
) const
2163 { return m_children
[i
]; }
2165 /** Returns last sub-property.
2167 wxPGProperty
* Last() const { return m_children
.back(); }
2169 /** Returns index of given child property. */
2170 int Index( const wxPGProperty
* p
) const;
2172 // Puts correct indexes to children
2173 void FixIndicesOfChildren( unsigned int starthere
= 0 );
2176 Converts image width into full image offset, with margins.
2178 int GetImageOffset( int imageWidth
) const;
2181 // Returns wxPropertyGridPageState in which this property resides.
2182 wxPropertyGridPageState
* GetParentState() const { return m_parentState
; }
2186 wxPGProperty
* GetItemAtY( unsigned int y
,
2188 unsigned int* nextItemY
) const;
2191 /** Returns property at given virtual y coordinate.
2193 wxPGProperty
* GetItemAtY( unsigned int y
) const;
2195 /** Returns (direct) child property with given name (or NULL if not found).
2197 wxPGProperty
* GetPropertyByName( const wxString
& name
) const;
2201 // Returns various display-related information for given column
2202 void GetDisplayInfo( unsigned int column
,
2206 const wxPGCell
** pCell
);
2208 static wxString
* sm_wxPG_LABEL
;
2210 /** This member is public so scripting language bindings
2211 wrapper code can access it freely.
2218 Sets property cell in fashion that reduces number of exclusive
2219 copies of cell data. Used when setting, for instance, same
2220 background colour for a number of properties.
2223 First column to affect.
2226 Last column to affect.
2229 Pre-prepared cell that is used for those which cell data
2230 before this matched unmodCellData.
2233 If unmodCellData did not match, valid cell data from this
2234 is merged into cell (usually generating new exclusive copy
2237 @param unmodCellData
2238 If cell's cell data matches this, its cell is now set to
2241 @param ignoreWithFlags
2242 Properties with any one of these flags are skipped.
2245 If @true, apply this operation recursively in child properties.
2247 void AdaptiveSetCell( unsigned int firstCol
,
2248 unsigned int lastCol
,
2249 const wxPGCell
& preparedCell
,
2250 const wxPGCell
& srcData
,
2251 wxPGCellData
* unmodCellData
,
2252 FlagType ignoreWithFlags
,
2256 Makes sure m_cells has size of column+1 (or more).
2258 void EnsureCells( unsigned int column
);
2260 /** Returns (direct) child property with given name (or NULL if not found),
2264 Start looking for the child at this index.
2267 Does not support scope (ie. Parent.Child notation).
2269 wxPGProperty
* GetPropertyByNameWH( const wxString
& name
,
2270 unsigned int hintIndex
) const;
2272 /** This is used by Insert etc. */
2273 void DoAddChild( wxPGProperty
* prop
,
2275 bool correct_mode
= true );
2277 void DoGenerateComposedValue( wxString
& text
,
2278 int argFlags
= wxPG_VALUE_IS_CURRENT
,
2279 const wxVariantList
* valueOverrides
= NULL
,
2280 wxPGHashMapS2S
* childResults
= NULL
) const;
2282 void DoSetName(const wxString
& str
) { m_name
= str
; }
2284 /** Deletes all sub-properties. */
2287 void InitAfterAdded( wxPropertyGridPageState
* pageState
,
2288 wxPropertyGrid
* propgrid
);
2290 // Removes child property with given pointer. Does not delete it.
2291 void RemoveChild( wxPGProperty
* p
);
2293 void DoPreAddChild( int index
, wxPGProperty
* prop
);
2295 void SetParentState( wxPropertyGridPageState
* pstate
)
2296 { m_parentState
= pstate
; }
2298 // Call after fixed sub-properties added/removed after creation.
2299 // if oldSelInd >= 0 and < new max items, then selection is
2301 void SubPropsChanged( int oldSelInd
= -1 );
2303 int GetY2( int lh
) const;
2307 wxPGProperty
* m_parent
;
2308 wxPropertyGridPageState
* m_parentState
;
2310 wxClientData
* m_clientObject
;
2312 // Overrides editor returned by property class
2313 const wxPGEditor
* m_customEditor
;
2314 #if wxUSE_VALIDATORS
2315 // Editor is going to get this validator
2316 wxValidator
* m_validator
;
2318 // Show this in front of the value
2320 // TODO: Can bitmap be implemented with wxPGCell?
2321 wxBitmap
* m_valueBitmap
;
2324 wxPGAttributeStorage m_attributes
;
2325 wxArrayPGProperty m_children
;
2327 // Extended cell information
2328 wxVector
<wxPGCell
> m_cells
;
2330 // Choices shown in drop-down list of editor control.
2331 wxPGChoices m_choices
;
2333 // Help shown in statusbar or help box.
2334 wxString m_helpString
;
2336 // Index in parent's property array.
2337 unsigned int m_arrIndex
;
2339 // If not -1, then overrides m_value
2344 // Maximum length (mainly for string properties). Could be in some sort of
2345 // wxBaseStringProperty, but currently, for maximum flexibility and
2346 // compatibility, we'll stick it here. Anyway, we had 3 excess bytes to use
2347 // so short int will fit in just fine.
2350 // Root has 0, categories etc. at that level 1, etc.
2351 unsigned char m_depth
;
2353 // m_depthBgCol indicates width of background colour between margin and item
2354 // (essentially this is category's depth, if none then equals m_depth).
2355 unsigned char m_depthBgCol
;
2358 // Called in constructors.
2360 void Init( const wxString
& label
, const wxString
& name
);
2361 #endif // #ifndef SWIG
2364 // -----------------------------------------------------------------------
2367 // Property class declaration helper macros
2368 // (wxPGRootPropertyClass and wxPropertyCategory require this).
2371 #define WX_PG_DECLARE_DOGETEDITORCLASS \
2372 virtual const wxPGEditor* DoGetEditorClass() const;
2375 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
2377 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
2378 WX_PG_DECLARE_DOGETEDITORCLASS \
2381 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME)
2384 // Implements sans constructor function. Also, first arg is class name, not
2386 #define WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(PROPNAME,T,EDITOR) \
2387 const wxPGEditor* PROPNAME::DoGetEditorClass() const \
2389 return wxPGEditor_##EDITOR; \
2392 // -----------------------------------------------------------------------
2396 /** @class wxPGRootProperty
2398 Root parent property.
2400 class WXDLLIMPEXP_PROPGRID wxPGRootProperty
: public wxPGProperty
2403 WX_PG_DECLARE_PROPERTY_CLASS(wxPGRootProperty
)
2407 wxPGRootProperty( const wxString
& name
= wxS("<Root>") );
2408 virtual ~wxPGRootProperty();
2410 virtual bool StringToValue( wxVariant
&, const wxString
&, int ) const
2418 // -----------------------------------------------------------------------
2420 /** @class wxPropertyCategory
2422 Category (caption) property.
2424 class WXDLLIMPEXP_PROPGRID wxPropertyCategory
: public wxPGProperty
2426 friend class wxPropertyGrid
;
2427 friend class wxPropertyGridPageState
;
2428 WX_PG_DECLARE_PROPERTY_CLASS(wxPropertyCategory
)
2431 /** Default constructor is only used in special cases. */
2432 wxPropertyCategory();
2434 wxPropertyCategory( const wxString
& label
,
2435 const wxString
& name
= wxPG_LABEL
);
2436 ~wxPropertyCategory();
2438 int GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const;
2440 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
) const;
2443 void SetTextColIndex( unsigned int colInd
)
2444 { m_capFgColIndex
= (wxByte
) colInd
; }
2445 unsigned int GetTextColIndex() const
2446 { return (unsigned int) m_capFgColIndex
; }
2448 void CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
);
2450 int m_textExtent
; // pre-calculated length of text
2451 wxByte m_capFgColIndex
; // caption text colour index
2459 // -----------------------------------------------------------------------
2461 #endif // wxUSE_PROPGRID
2463 #endif // _WX_PROPGRID_PROPERTY_H_