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 /** wxBoolProperty specific, int, default 0. When 1 sets bool property to
519 use checkbox instead of choice.
521 #define wxPG_BOOL_USE_CHECKBOX wxS("UseCheckbox")
523 /** wxBoolProperty specific, int, default 0. When 1 sets bool property value
524 to cycle on double click (instead of showing the popup listbox).
526 #define wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING wxS("UseDClickCycling")
529 wxFloatProperty (and similar) specific, int, default -1.
531 Sets the (max) precision used when floating point value is rendered as
532 text. The default -1 means infinite precision.
534 #define wxPG_FLOAT_PRECISION wxS("Precision")
537 The text will be echoed as asterisks (wxTE_PASSWORD will be passed to
540 #define wxPG_STRING_PASSWORD wxS("Password")
542 /** Define base used by a wxUIntProperty. Valid constants are
543 wxPG_BASE_OCT, wxPG_BASE_DEC, wxPG_BASE_HEX and wxPG_BASE_HEXL
544 (lowercase characters).
546 #define wxPG_UINT_BASE wxS("Base")
548 /** Define prefix rendered to wxUIntProperty. Accepted constants
549 wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and wxPG_PREFIX_DOLLAR_SIGN.
550 <b>Note:</b> Only wxPG_PREFIX_NONE works with Decimal and Octal
553 #define wxPG_UINT_PREFIX wxS("Prefix")
556 wxFileProperty/wxImageFileProperty specific, wxChar*, default is
558 Sets the wildcard used in the triggered wxFileDialog. Format is the same.
560 #define wxPG_FILE_WILDCARD wxS("Wildcard")
562 /** wxFileProperty/wxImageFileProperty specific, int, default 1.
563 When 0, only the file name is shown (i.e. drive and directory are hidden).
565 #define wxPG_FILE_SHOW_FULL_PATH wxS("ShowFullPath")
567 /** Specific to wxFileProperty and derived properties, wxString, default empty.
568 If set, then the filename is shown relative to the given path string.
570 #define wxPG_FILE_SHOW_RELATIVE_PATH wxS("ShowRelativePath")
573 Specific to wxFileProperty and derived properties, wxString, default is
576 Sets the initial path of where to look for files.
578 #define wxPG_FILE_INITIAL_PATH wxS("InitialPath")
580 /** Specific to wxFileProperty and derivatives, wxString, default is empty.
581 Sets a specific title for the dir dialog.
583 #define wxPG_FILE_DIALOG_TITLE wxS("DialogTitle")
585 /** Specific to wxDirProperty, wxString, default is empty.
586 Sets a specific message for the dir dialog.
588 #define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage")
590 /** Sets displayed date format for wxDateProperty.
592 #define wxPG_DATE_FORMAT wxS("DateFormat")
594 /** Sets wxDatePickerCtrl window style used with wxDateProperty. Default
595 is wxDP_DEFAULT | wxDP_SHOWCENTURY.
597 #define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
599 /** SpinCtrl editor, int or double. How much number changes when button is
600 pressed (or up/down on keybard).
602 #define wxPG_ATTR_SPINCTRL_STEP wxS("Step")
604 /** SpinCtrl editor, bool. If true, value wraps at Min/Max.
606 #define wxPG_ATTR_SPINCTRL_WRAP wxS("Wrap")
609 wxMultiChoiceProperty, int.
610 If 0, no user strings allowed. If 1, user strings appear before list
611 strings. If 2, user strings appear after list string.
613 #define wxPG_ATTR_MULTICHOICE_USERSTRINGMODE wxS("UserStringMode")
616 wxColourProperty and its kind, int, default 1.
618 Setting this attribute to 0 hides custom colour from property's list of
621 #define wxPG_COLOUR_ALLOW_CUSTOM wxS("AllowCustom")
626 // Redefine attribute macros to use cached strings
628 #define wxPG_ATTR_MIN wxPGGlobalVars->m_strMin
630 #define wxPG_ATTR_MAX wxPGGlobalVars->m_strMax
631 #undef wxPG_ATTR_UNITS
632 #define wxPG_ATTR_UNITS wxPGGlobalVars->m_strUnits
633 #undef wxPG_ATTR_INLINE_HELP
634 #define wxPG_ATTR_INLINE_HELP wxPGGlobalVars->m_strInlineHelp
638 // -----------------------------------------------------------------------
642 /** @class wxPGChoiceEntry
643 Data of a single wxPGChoices choice.
645 class WXDLLIMPEXP_PROPGRID wxPGChoiceEntry
: public wxPGCell
649 wxPGChoiceEntry(const wxPGChoiceEntry
& other
)
652 m_value
= other
.m_value
;
654 wxPGChoiceEntry( const wxString
& label
,
655 int value
= wxPG_INVALID_VALUE
)
656 : wxPGCell(), m_value(value
)
661 virtual ~wxPGChoiceEntry() { }
663 void SetValue( int value
) { m_value
= value
; }
664 int GetValue() const { return m_value
; }
666 wxPGChoiceEntry
& operator=( const wxPGChoiceEntry
& other
)
668 if ( this != &other
)
672 m_value
= other
.m_value
;
681 typedef void* wxPGChoicesId
;
683 class WXDLLIMPEXP_PROPGRID wxPGChoicesData
685 friend class wxPGChoices
;
687 // Constructor sets m_refCount to 1.
690 void CopyDataFrom( wxPGChoicesData
* data
);
692 wxPGChoiceEntry
& Insert( int index
, const wxPGChoiceEntry
& item
);
694 // Delete all entries
697 unsigned int GetCount() const
699 return (unsigned int) m_items
.size();
702 const wxPGChoiceEntry
& Item( unsigned int i
) const
704 wxASSERT_MSG( i
< GetCount(), "invalid index" );
708 wxPGChoiceEntry
& Item( unsigned int i
)
710 wxASSERT_MSG( i
< GetCount(), "invalid index" );
717 wxASSERT( m_refCount
>= 0 );
718 if ( m_refCount
== 0 )
723 wxVector
<wxPGChoiceEntry
> m_items
;
725 // So that multiple properties can use the same set
728 virtual ~wxPGChoicesData();
731 #define wxPGChoicesEmptyData ((wxPGChoicesData*)NULL)
735 /** @class wxPGChoices
737 Helper class for managing choices of wxPropertyGrid properties.
738 Each entry can have label, value, bitmap, text colour, and background
741 @remarks If you do not specify value for entry, index is used.
746 class WXDLLIMPEXP_PROPGRID wxPGChoices
749 typedef long ValArrItem
;
751 /** Default constructor. */
757 /** Copy constructor. */
758 wxPGChoices( const wxPGChoices
& a
)
760 if ( a
.m_data
!= wxPGChoicesEmptyData
)
763 m_data
->m_refCount
++;
774 Values for choices. If NULL, indexes are used.
776 wxPGChoices( const wxChar
** labels
, const long* values
= NULL
)
789 Values for choices. If empty, indexes are used.
791 wxPGChoices( const wxArrayString
& labels
,
792 const wxArrayInt
& values
= wxArrayInt() )
798 /** Simple interface constructor. */
799 wxPGChoices( wxPGChoicesData
* data
)
815 If did not have own copies, creates them now. If was empty, identical
816 to set except that creates copies.
819 Labels for added choices.
822 Values for added choices. If empty, relevant entry indexes are used.
824 void Add( const wxChar
** labels
, const ValArrItem
* values
= NULL
);
826 /** Version that works with wxArrayString and wxArrayInt. */
827 void Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
= wxArrayInt() );
830 Adds a single choice.
833 Label for added choice.
836 Value for added choice. If unspecified, index is used.
838 wxPGChoiceEntry
& Add( const wxString
& label
,
839 int value
= wxPG_INVALID_VALUE
);
841 /** Adds a single item, with bitmap. */
842 wxPGChoiceEntry
& Add( const wxString
& label
,
843 const wxBitmap
& bitmap
,
844 int value
= wxPG_INVALID_VALUE
);
846 /** Adds a single item with full entry information. */
847 wxPGChoiceEntry
& Add( const wxPGChoiceEntry
& entry
)
849 return Insert(entry
, -1);
852 /** Adds single item. */
853 wxPGChoiceEntry
& AddAsSorted( const wxString
& label
,
854 int value
= wxPG_INVALID_VALUE
);
856 void Assign( const wxPGChoices
& a
)
858 AssignData(a
.m_data
);
861 void AssignData( wxPGChoicesData
* data
);
863 /** Delete all choices. */
866 if ( m_data
!= wxPGChoicesEmptyData
)
872 if ( m_data
== wxPGChoicesEmptyData
)
873 m_data
= new wxPGChoicesData();
876 /** Gets a unsigned number identifying this list. */
877 wxPGChoicesId
GetId() const { return (wxPGChoicesId
) m_data
; };
879 const wxString
& GetLabel( unsigned int ind
) const
881 return Item(ind
).GetText();
884 unsigned int GetCount () const
889 return m_data
->GetCount();
892 int GetValue( unsigned int ind
) const { return Item(ind
).GetValue(); }
894 /** Returns array of values matching the given strings. Unmatching strings
895 result in wxPG_INVALID_VALUE entry in array.
897 wxArrayInt
GetValuesForStrings( const wxArrayString
& strings
) const;
899 /** Returns array of indices matching given strings. Unmatching strings
900 are added to 'unmatched', if not NULL.
902 wxArrayInt
GetIndicesForStrings( const wxArrayString
& strings
,
903 wxArrayString
* unmatched
= NULL
) const;
905 int Index( const wxString
& str
) const;
906 int Index( int val
) const;
908 /** Inserts single item. */
909 wxPGChoiceEntry
& Insert( const wxString
& label
,
911 int value
= wxPG_INVALID_VALUE
);
913 /** Inserts a single item with full entry information. */
914 wxPGChoiceEntry
& Insert( const wxPGChoiceEntry
& entry
, int index
);
916 /** Returns false if this is a constant empty set of choices,
917 which should not be modified.
921 return ( m_data
!= wxPGChoicesEmptyData
);
924 const wxPGChoiceEntry
& Item( unsigned int i
) const
927 return m_data
->Item(i
);
930 wxPGChoiceEntry
& Item( unsigned int i
)
933 return m_data
->Item(i
);
936 /** Removes count items starting at position nIndex. */
937 void RemoveAt(size_t nIndex
, size_t count
= 1);
940 /** Does not create copies for itself. */
941 void Set( const wxChar
** labels
, const long* values
= NULL
)
948 /** Version that works with wxArrayString and wxArrayInt. */
949 void Set( const wxArrayString
& labels
,
950 const wxArrayInt
& values
= wxArrayInt() )
959 // Creates exclusive copy of current choices
962 if ( m_data
->m_refCount
!= 1 )
964 wxPGChoicesData
* data
= new wxPGChoicesData();
965 data
->CopyDataFrom(m_data
);
971 // Returns data, increases refcount.
972 wxPGChoicesData
* GetData()
974 wxASSERT( m_data
->m_refCount
!= 0xFFFFFFF );
975 m_data
->m_refCount
++;
979 // Returns plain data ptr - no refcounting stuff is done.
980 wxPGChoicesData
* GetDataPtr() const { return m_data
; }
982 // Changes ownership of data to you.
983 wxPGChoicesData
* ExtractData()
985 wxPGChoicesData
* data
= m_data
;
986 m_data
= wxPGChoicesEmptyData
;
990 wxArrayString
GetLabels() const;
993 void operator= (const wxPGChoices
& a
)
996 AssignData(a
.m_data
);
999 wxPGChoiceEntry
& operator[](unsigned int i
)
1004 const wxPGChoiceEntry
& operator[](unsigned int i
) const
1010 wxPGChoicesData
* m_data
;
1017 // -----------------------------------------------------------------------
1019 /** @class wxPGProperty
1021 wxPGProperty is base class for all wxPropertyGrid properties.
1023 NB: Full class overview is now only present in
1024 interface/wx/propgrid/property.h.
1026 @library{wxpropgrid}
1029 class WXDLLIMPEXP_PROPGRID wxPGProperty
: public wxObject
1031 friend class wxPropertyGrid
;
1032 friend class wxPropertyGridInterface
;
1033 friend class wxPropertyGridPageState
;
1034 friend class wxPropertyGridPopulator
;
1035 friend class wxStringProperty
; // Proper "<composed>" support requires this
1037 DECLARE_ABSTRACT_CLASS(wxPGProperty
)
1040 typedef wxUint32 FlagType
;
1042 /** Basic constructor.
1047 Non-abstract property classes should have constructor of this style:
1051 // If T is a class, then it should be a constant reference
1052 // (e.g. const T& ) instead.
1053 MyProperty( const wxString& label, const wxString& name, T value )
1056 // Generally recommended way to set the initial value
1057 // (as it should work in pretty much 100% of cases).
1062 // If has private child properties then create them here. Also
1063 // set flag that indicates presence of private children. E.g.:
1065 // SetParentalType(wxPG_PROP_AGGREGATE);
1067 // AddChild( new wxStringProperty( "Subprop 1",
1069 // value.GetSubProp1() ) );
1074 wxPGProperty( const wxString
& label
, const wxString
& name
);
1078 It is customary for derived properties to implement this.
1080 virtual ~wxPGProperty();
1082 /** This virtual function is called after m_value has been set.
1085 - If m_value was set to Null variant (ie. unspecified value),
1086 OnSetValue() will not be called.
1087 - m_value may be of any variant type. Typically properties internally
1088 support only one variant type, and as such OnSetValue() provides a
1089 good opportunity to convert
1090 supported values into internal type.
1091 - Default implementation does nothing.
1093 virtual void OnSetValue();
1095 /** Override this to return something else than m_value as the value.
1097 virtual wxVariant
DoGetValue() const { return m_value
; }
1099 #if !defined(SWIG) || defined(CREATE_VCW)
1100 /** Implement this function in derived class to check the value.
1101 Return true if it is ok. Returning false prevents property change events
1105 - Default implementation always returns true.
1107 virtual bool ValidateValue( wxVariant
& value
,
1108 wxPGValidationInfo
& validationInfo
) const;
1111 Converts text into wxVariant value appropriate for this property.
1114 On function entry this is the old value (should not be wxNullVariant
1115 in normal cases). Translated value must be assigned back to it.
1118 Text to be translated into variant.
1121 If wxPG_FULL_VALUE is set, returns complete, storable value instead
1122 of displayable one (they may be different).
1123 If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of
1124 composite property string value (as generated by ValueToString()
1125 called with this same flag).
1127 @return Returns @true if resulting wxVariant value was different.
1129 @remarks Default implementation converts semicolon delimited tokens into
1130 child values. Only works for properties with children.
1132 You might want to take into account that m_value is Null variant
1133 if property value is unspecified (which is usually only case if
1134 you explicitly enabled that sort behavior).
1136 virtual bool StringToValue( wxVariant
& variant
,
1137 const wxString
& text
,
1138 int argFlags
= 0 ) const;
1141 Converts integer (possibly a choice selection) into wxVariant value
1142 appropriate for this property.
1145 On function entry this is the old value (should not be wxNullVariant
1146 in normal cases). Translated value must be assigned back to it.
1149 Integer to be translated into variant.
1152 If wxPG_FULL_VALUE is set, returns complete, storable value instead
1155 @return Returns @true if resulting wxVariant value was different.
1158 - If property is not supposed to use choice or spinctrl or other editor
1159 with int-based value, it is not necessary to implement this method.
1160 - Default implementation simply assign given int to m_value.
1161 - If property uses choice control, and displays a dialog on some choice
1162 items, then it is preferred to display that dialog in IntToValue
1164 - You might want to take into account that m_value is Null variant if
1165 property value is unspecified (which is usually only case if you
1166 explicitly enabled that sort behavior).
1168 virtual bool IntToValue( wxVariant
& value
,
1170 int argFlags
= 0 ) const;
1171 #endif // !defined(SWIG) || defined(CREATE_VCW)
1173 Converts property value into a text representation.
1176 Value to be converted.
1179 If 0 (default value), then displayed string is returned.
1180 If wxPG_FULL_VALUE is set, returns complete, storable string value
1181 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
1182 string value that must be editable in textctrl. If
1183 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
1184 display as a part of string property's composite text
1187 @remarks Default implementation calls GenerateComposedValue().
1189 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
1191 /** Converts string to a value, and if successful, calls SetValue() on it.
1192 Default behavior is to do nothing.
1194 String to get the value from.
1196 true if value was changed.
1198 bool SetValueFromString( const wxString
& text
, int flags
= wxPG_PROGRAMMATIC_VALUE
);
1200 /** Converts integer to a value, and if succesful, calls SetValue() on it.
1201 Default behavior is to do nothing.
1203 Int to get the value from.
1205 If has wxPG_FULL_VALUE, then the value given is a actual value and
1208 True if value was changed.
1210 bool SetValueFromInt( long value
, int flags
= 0 );
1213 Returns size of the custom painted image in front of property.
1215 This method must be overridden to return non-default value if
1216 OnCustomPaint is to be called.
1218 Normally -1, but can be an index to the property's list of items.
1220 - Default behavior is to return wxSize(0,0), which means no image.
1221 - Default image width or height is indicated with dimension -1.
1222 - You can also return wxPG_DEFAULT_IMAGE_SIZE, i.e. wxSize(-1, -1).
1224 virtual wxSize
OnMeasureImage( int item
= -1 ) const;
1227 Events received by editor widgets are processed here.
1229 Note that editor class usually processes most events. Some, such as
1230 button press events of TextCtrlAndButton class, can be handled here.
1231 Also, if custom handling for regular events is desired, then that can
1232 also be done (for example, wxSystemColourProperty custom handles
1233 wxEVT_COMMAND_CHOICE_SELECTED to display colour picker dialog when
1234 'custom' selection is made).
1236 If the event causes value to be changed, SetValueInEvent()
1237 should be called to set the new value.
1242 Should return true if any changes in value should be reported.
1244 If property uses choice control, and displays a dialog on some choice
1245 items, then it is preferred to display that dialog in IntToValue
1248 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
1249 wxWindow
* wnd_primary
,
1253 Called after value of a child property has been altered.
1255 Note that this function is usually called at the time that value of
1256 this property, or given child property, is still pending for change.
1258 Sample pseudo-code implementation:
1261 void MyProperty::ChildChanged( wxVariant& thisValue,
1263 wxVariant& childValue ) const
1265 // Acquire reference to actual type of data stored in variant
1266 // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros
1267 // were used to create the variant class).
1268 T& data = TFromVariant(thisValue);
1270 // Copy childValue into data.
1271 switch ( childIndex )
1274 data.SetSubProp1( childvalue.GetLong() );
1277 data.SetSubProp2( childvalue.GetString() );
1285 Value of this property, that should be altered.
1287 Index of child changed (you can use Item(childIndex) to get).
1289 Value of the child property.
1291 virtual void ChildChanged( wxVariant
& thisValue
,
1293 wxVariant
& childValue
) const;
1295 /** Returns pointer to an instance of used editor.
1297 virtual const wxPGEditor
* DoGetEditorClass() const;
1299 /** Returns pointer to the wxValidator that should be used
1300 with the editor of this property (NULL for no validator).
1301 Setting validator explicitly via SetPropertyValidator
1304 In most situations, code like this should work well
1305 (macros are used to maintain one actual validator instance,
1306 so on the second call the function exits within the first
1311 wxValidator* wxMyPropertyClass::DoGetValidator () const
1313 WX_PG_DOGETVALIDATOR_ENTRY()
1315 wxMyValidator* validator = new wxMyValidator(...);
1317 ... prepare validator...
1319 WX_PG_DOGETVALIDATOR_EXIT(validator)
1325 You can get common filename validator by returning
1326 wxFileProperty::GetClassValidator(). wxDirProperty,
1327 for example, uses it.
1329 virtual wxValidator
* DoGetValidator () const;
1332 Override to paint an image in front of the property value text or
1333 drop-down list item (but only if wxPGProperty::OnMeasureImage is
1334 overridden as well).
1336 If property's OnMeasureImage() returns size that has height != 0 but
1337 less than row height ( < 0 has special meanings), wxPropertyGrid calls
1338 this method to draw a custom image in a limited area in front of the
1339 editor control or value text/graphics, and if control has drop-down
1340 list, then the image is drawn there as well (even in the case
1341 OnMeasureImage() returned higher height than row height).
1343 NOTE: Following applies when OnMeasureImage() returns a "flexible"
1344 height ( using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable
1345 height items: If rect.x is < 0, then this is a measure item call, which
1346 means that dc is invalid and only thing that should be done is to set
1347 paintdata.m_drawnHeight to the height of the image of item at index
1348 paintdata.m_choiceItem. This call may be done even as often as once
1349 every drop-down popup show.
1354 Box reserved for custom graphics. Includes surrounding rectangle,
1355 if any. If x is < 0, then this is a measure item call (see above).
1357 wxPGPaintData structure with much useful data.
1360 - You can actually exceed rect width, but if you do so then
1361 paintdata.m_drawnWidth must be set to the full width drawn in
1363 - Due to technical reasons, rect's height will be default even if
1364 custom height was reported during measure call.
1365 - Brush is guaranteed to be default background colour. It has been
1366 already used to clear the background of area being painted. It
1368 - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper
1369 colour) pen for drawing framing rectangle. It can be changed as
1372 @see ValueToString()
1374 virtual void OnCustomPaint( wxDC
& dc
,
1376 wxPGPaintData
& paintdata
);
1379 Returns used wxPGCellRenderer instance for given property column
1382 Default implementation returns editor's renderer for all columns.
1384 virtual wxPGCellRenderer
* GetCellRenderer( int column
) const;
1386 /** Returns which choice is currently selected. Only applies to properties
1389 Needs to reimplemented in derived class if property value does not
1390 map directly to a choice. Integer as index, bool, and string usually do.
1392 virtual int GetChoiceSelection() const;
1395 Refresh values of child properties.
1397 Automatically called after value is set.
1399 virtual void RefreshChildren();
1401 /** Special handling for attributes of this property.
1403 If returns false, then the attribute will be automatically stored in
1406 Default implementation simply returns false.
1408 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
1410 /** Returns value of an attribute.
1412 Override if custom handling of attributes is needed.
1414 Default implementation simply return NULL variant.
1416 virtual wxVariant
DoGetAttribute( const wxString
& name
) const;
1418 /** Returns instance of a new wxPGEditorDialogAdapter instance, which is
1419 used when user presses the (optional) button next to the editor control;
1421 Default implementation returns NULL (ie. no action is generated when
1424 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
1427 Called whenever validation has failed with given pending value.
1429 @remarks If you implement this in your custom property class, please
1430 remember to call the baser implementation as well, since they
1431 may use it to revert property into pre-change state.
1433 virtual void OnValidationFailure( wxVariant
& pendingValue
);
1435 /** Append a new choice to property's list of choices.
1437 int AddChoice( const wxString
& label
, int value
= wxPG_INVALID_VALUE
)
1439 return InsertChoice(label
, wxNOT_FOUND
, value
);
1443 Returns true if children of this property are component values (for
1444 instance, points size, face name, and is_underlined are component
1447 bool AreChildrenComponents() const
1449 if ( m_flags
& (wxPG_PROP_COMPOSED_VALUE
|wxPG_PROP_AGGREGATE
) )
1456 Deletes children of the property.
1458 void DeleteChildren();
1461 Removes entry from property's wxPGChoices and editor control (if it is
1464 If selected item is deleted, then the value is set to unspecified.
1466 void DeleteChoice( int index
);
1469 Call to enable or disable usage of common value (integer value that can
1470 be selected for properties instead of their normal values) for this
1473 Common values are disabled by the default for all properties.
1475 void EnableCommonValue( bool enable
= true )
1477 if ( enable
) SetFlag( wxPG_PROP_USES_COMMON_VALUE
);
1478 else ClearFlag( wxPG_PROP_USES_COMMON_VALUE
);
1482 Composes text from values of child properties.
1484 wxString
GenerateComposedValue() const
1487 DoGenerateComposedValue(s
);
1491 /** Returns property's label. */
1492 const wxString
& GetLabel() const { return m_label
; }
1494 /** Returns property's name with all (non-category, non-root) parents. */
1495 wxString
GetName() const;
1498 Returns property's base name (ie parent's name is not added in any
1501 const wxString
& GetBaseName() const { return m_name
; }
1503 /** Returns read-only reference to property's list of choices.
1505 const wxPGChoices
& GetChoices() const
1510 /** Returns coordinate to the top y of the property. Note that the
1511 position of scrollbars is not taken into account.
1515 wxVariant
GetValue() const
1517 return DoGetValue();
1521 /** Returns reference to the internal stored value. GetValue is preferred
1522 way to get the actual value, since GetValueRef ignores DoGetValue,
1523 which may override stored value.
1525 wxVariant
& GetValueRef()
1530 const wxVariant
& GetValueRef() const
1536 /** Returns text representation of property's value.
1539 If 0 (default value), then displayed string is returned.
1540 If wxPG_FULL_VALUE is set, returns complete, storable string value
1541 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
1542 string value that must be editable in textctrl. If
1543 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
1544 display as a part of string property's composite text
1547 @remarks In older versions, this function used to be overridden to convert
1548 property's value into a string representation. This function is
1549 now handled by ValueToString(), and overriding this function now
1550 will result in run-time assertion failure.
1552 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
1554 /** Synonymous to GetValueAsString().
1556 @deprecated Use GetValueAsString() instead.
1558 @see GetValueAsString()
1560 wxDEPRECATED( wxString
GetValueString( int argFlags
= 0 ) const );
1563 Returns wxPGCell of given column.
1565 const wxPGCell
& GetCell( unsigned int column
) const;
1567 wxPGCell
& GetCell( unsigned int column
);
1569 /** Return number of displayed common values for this property.
1571 int GetDisplayedCommonValueCount() const;
1573 wxString
GetDisplayedString() const
1575 return GetValueAsString(0);
1578 /** Returns property grid where property lies. */
1579 wxPropertyGrid
* GetGrid() const;
1581 /** Returns owner wxPropertyGrid, but only if one is currently on a page
1582 displaying this property. */
1583 wxPropertyGrid
* GetGridIfDisplayed() const;
1585 /** Returns highest level non-category, non-root parent. Useful when you
1586 have nested wxCustomProperties/wxParentProperties.
1588 Thus, if immediate parent is root or category, this will return the
1591 wxPGProperty
* GetMainParent() const;
1593 /** Return parent of property */
1594 wxPGProperty
* GetParent() const { return m_parent
; }
1596 /** Returns true if property has editable wxTextCtrl when selected.
1599 Altough disabled properties do not displayed editor, they still
1600 return True here as being disabled is considered a temporary
1601 condition (unlike being read-only or having limited editing enabled).
1603 bool IsTextEditable() const;
1605 bool IsValueUnspecified() const
1607 return m_value
.IsNull();
1610 FlagType
HasFlag( FlagType flag
) const
1612 return ( m_flags
& flag
);
1615 /** Returns comma-delimited string of property attributes.
1617 const wxPGAttributeStorage
& GetAttributes() const
1619 return m_attributes
;
1622 /** Returns m_attributes as list wxVariant.
1624 wxVariant
GetAttributesAsList() const;
1626 FlagType
GetFlags() const
1631 const wxPGEditor
* GetEditorClass() const;
1633 wxString
GetValueType() const
1635 return m_value
.GetType();
1638 /** Returns editor used for given column. NULL for no editor.
1640 const wxPGEditor
* GetColumnEditor( int column
) const
1643 return GetEditorClass();
1648 /** Returns common value selected for this property. -1 for none.
1650 int GetCommonValue() const
1652 return m_commonValue
;
1655 /** Returns true if property has even one visible child.
1657 bool HasVisibleChildren() const;
1659 /** Inserts a new choice to property's list of choices.
1661 int InsertChoice( const wxString
& label
, int index
, int value
= wxPG_INVALID_VALUE
);
1664 Returns true if this property is actually a wxPropertyCategory.
1666 bool IsCategory() const { return HasFlag(wxPG_PROP_CATEGORY
)?true:false; }
1668 /** Returns true if this property is actually a wxRootProperty.
1670 bool IsRoot() const { return (m_parent
== NULL
); }
1672 /** Returns true if this is a sub-property. */
1673 bool IsSubProperty() const
1675 wxPGProperty
* parent
= (wxPGProperty
*)m_parent
;
1676 if ( parent
&& !parent
->IsCategory() )
1681 /** Returns last visible sub-property, recursively.
1683 const wxPGProperty
* GetLastVisibleSubItem() const;
1685 wxVariant
GetDefaultValue() const;
1687 int GetMaxLength() const
1689 return (int) m_maxLen
;
1693 Determines, recursively, if all children are not unspecified.
1696 Assumes members in this wxVariant list as pending
1699 bool AreAllChildrenSpecified( wxVariant
* pendingList
= NULL
) const;
1701 /** Updates composed values of parent non-category properties, recursively.
1702 Returns topmost property updated.
1705 - Must not call SetValue() (as can be called in it).
1707 wxPGProperty
* UpdateParentValues();
1709 /** Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
1711 bool UsesAutoUnspecified() const
1713 return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED
)?true:false;
1716 wxBitmap
* GetValueImage() const
1718 return m_valueBitmap
;
1721 wxVariant
GetAttribute( const wxString
& name
) const;
1724 Returns named attribute, as string, if found.
1726 Otherwise defVal is returned.
1728 wxString
GetAttribute( const wxString
& name
, const wxString
& defVal
) const;
1731 Returns named attribute, as long, if found.
1733 Otherwise defVal is returned.
1735 long GetAttributeAsLong( const wxString
& name
, long defVal
) const;
1738 Returns named attribute, as double, if found.
1740 Otherwise defVal is returned.
1742 double GetAttributeAsDouble( const wxString
& name
, double defVal
) const;
1744 unsigned int GetDepth() const { return (unsigned int)m_depth
; }
1746 /** Gets flags as a'|' delimited string. Note that flag names are not
1747 prepended with 'wxPG_PROP_'.
1749 String will only be made to include flags combined by this parameter.
1751 wxString
GetFlagsAsString( FlagType flagsMask
) const;
1753 /** Returns position in parent's array. */
1754 unsigned int GetIndexInParent() const
1756 return (unsigned int)m_arrIndex
;
1759 /** Hides or reveals the property.
1761 true for hide, false for reveal.
1763 By default changes are applied recursively. Set this paramter
1764 wxPG_DONT_RECURSE to prevent this.
1766 inline bool Hide( bool hide
, int flags
= wxPG_RECURSE
);
1768 bool IsExpanded() const
1769 { return (!(m_flags
& wxPG_PROP_COLLAPSED
) && GetChildCount()); }
1771 /** Returns true if all parents expanded.
1773 bool IsVisible() const;
1775 bool IsEnabled() const { return !(m_flags
& wxPG_PROP_DISABLED
); }
1777 /** If property's editor is created this forces its recreation.
1778 Useful in SetAttribute etc. Returns true if actually did anything.
1780 bool RecreateEditor();
1782 /** If property's editor is active, then update it's value.
1784 void RefreshEditor();
1786 /** Sets an attribute for this property.
1788 Text identifier of attribute. See @ref propgrid_property_attributes.
1792 void SetAttribute( const wxString
& name
, wxVariant value
);
1794 void SetAttributes( const wxPGAttributeStorage
& attributes
);
1797 Sets property's background colour.
1800 Background colour to use.
1803 If @true, children are affected recursively, and any categories
1806 void SetBackgroundColour( const wxColour
& colour
,
1807 bool recursively
= false );
1810 Sets property's text colour.
1816 If @true, children are affected recursively, and any categories
1819 void SetTextColour( const wxColour
& colour
,
1820 bool recursively
= false );
1823 /** Sets editor for a property.
1826 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1827 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full
1830 For custom editors, use pointer you received from
1831 wxPropertyGrid::RegisterEditorClass().
1833 void SetEditor( const wxPGEditor
* editor
)
1835 m_customEditor
= editor
;
1839 /** Sets editor for a property.
1841 inline void SetEditor( const wxString
& editorName
);
1844 Sets cell information for given column.
1846 void SetCell( int column
, const wxPGCell
& cell
);
1848 /** Sets common value selected for this property. -1 for none.
1850 void SetCommonValue( int commonValue
)
1852 m_commonValue
= commonValue
;
1855 /** Sets flags from a '|' delimited string. Note that flag names are not
1856 prepended with 'wxPG_PROP_'.
1858 void SetFlagsFromString( const wxString
& str
);
1860 /** Sets property's "is it modified?" flag. Affects children recursively.
1862 void SetModifiedStatus( bool modified
)
1864 SetFlagRecursively(wxPG_PROP_MODIFIED
, modified
);
1867 /** Call in OnEvent(), OnButtonClick() etc. to change the property value
1868 based on user input.
1871 This method is const since it doesn't actually modify value, but posts
1872 given variant as pending value, stored in wxPropertyGrid.
1874 void SetValueInEvent( wxVariant value
) const;
1877 Call this to set value of the property.
1879 Unlike methods in wxPropertyGrid, this does not automatically update
1883 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run
1884 through validation process and send property change event.
1886 If you need to change property value in event, based on user input, use
1887 SetValueInEvent() instead.
1890 Pointer to list variant that contains child values. Used to indicate
1891 which children should be marked as modified.
1893 Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR).
1895 void SetValue( wxVariant value
, wxVariant
* pList
= NULL
, int flags
= 0 );
1897 /** Set wxBitmap in front of the value. This bitmap may be ignored
1898 by custom cell renderers.
1900 void SetValueImage( wxBitmap
& bmp
);
1902 /** If property has choices and they are not yet exclusive, new such copy
1903 of them will be created.
1905 void SetChoicesExclusive()
1907 m_choices
.SetExclusive();
1910 /** Sets selected choice and changes property value.
1912 Tries to retain value type, although currently if it is not string,
1913 then it is forced to integer.
1915 void SetChoiceSelection( int newValue
);
1917 void SetExpanded( bool expanded
)
1919 if ( !expanded
) m_flags
|= wxPG_PROP_COLLAPSED
;
1920 else m_flags
&= ~wxPG_PROP_COLLAPSED
;
1923 void SetFlag( FlagType flag
) { m_flags
|= flag
; }
1925 void SetFlagRecursively( FlagType flag
, bool set
);
1927 void SetHelpString( const wxString
& helpString
)
1929 m_helpString
= helpString
;
1932 void SetLabel( const wxString
& label
) { m_label
= label
; }
1934 inline void SetName( const wxString
& newName
);
1937 Changes what sort of parent this property is for its children.
1940 Use one of the following values: wxPG_PROP_MISC_PARENT (for generic
1941 parents), wxPG_PROP_CATEGORY (for categories), or
1942 wxPG_PROP_AGGREGATE (for derived property classes with private
1945 @remarks You only need to call this if you use AddChild() to add
1946 child properties. Adding properties with
1947 wxPropertyGridInterface::Insert() or
1948 wxPropertyGridInterface::AppendIn() will automatically set
1949 property to use wxPG_PROP_MISC_PARENT style.
1951 void SetParentalType( int flag
)
1953 m_flags
&= ~(wxPG_PROP_PROPERTY
|wxPG_PROP_PARENTAL_FLAGS
);
1957 void SetValueToUnspecified()
1959 wxVariant val
; // Create NULL variant
1963 #if wxUSE_VALIDATORS
1964 /** Sets wxValidator for a property*/
1965 void SetValidator( const wxValidator
& validator
)
1967 m_validator
= wxDynamicCast(validator
.Clone(),wxValidator
);
1970 /** Gets assignable version of property's validator. */
1971 wxValidator
* GetValidator() const
1975 return DoGetValidator();
1977 #endif // #if wxUSE_VALIDATORS
1980 /** Returns client data (void*) of a property.
1982 void* GetClientData() const
1984 return m_clientData
;
1987 /** Sets client data (void*) of a property.
1989 This untyped client data has to be deleted manually.
1991 void SetClientData( void* clientData
)
1993 m_clientData
= clientData
;
1996 /** Returns client object of a property.
1998 void SetClientObject(wxClientData
* clientObject
)
2000 delete m_clientObject
;
2001 m_clientObject
= clientObject
;
2004 /** Sets managed client object of a property.
2006 wxClientData
*GetClientObject() const { return m_clientObject
; }
2009 /** Sets new set of choices for property.
2012 This operation clears the property value.
2014 bool SetChoices( wxPGChoices
& choices
);
2016 /** Set max length of text in text editor.
2018 inline bool SetMaxLength( int maxLen
);
2020 /** Call with 'false' in OnSetValue to cancel value changes after all
2021 (ie. cancel 'true' returned by StringToValue() or IntToValue()).
2023 void SetWasModified( bool set
= true )
2025 if ( set
) m_flags
|= wxPG_PROP_WAS_MODIFIED
;
2026 else m_flags
&= ~wxPG_PROP_WAS_MODIFIED
;
2029 const wxString
& GetHelpString() const
2031 return m_helpString
;
2034 void ClearFlag( FlagType flag
) { m_flags
&= ~(flag
); }
2036 // Use, for example, to detect if item is inside collapsed section.
2037 bool IsSomeParent( wxPGProperty
* candidate_parent
) const;
2040 Adapts list variant into proper value using consecutive
2043 void AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const;
2046 Adds a child property. If you use this instead of
2047 wxPropertyGridInterface::Insert() or
2048 wxPropertyGridInterface::AppendIn(), then you must set up
2049 property's parental type before making the call. To do this,
2050 call property's SetParentalType() function with either
2051 wxPG_PROP_MISC_PARENT (normal, public children) or with
2052 wxPG_PROP_AGGREGATE (private children for subclassed property).
2056 wxPGProperty* prop = new wxStringProperty(wxS("Property"));
2057 prop->SetParentalType(wxPG_PROP_MISC_PARENT);
2058 wxPGProperty* prop2 = new wxStringProperty(wxS("Property2"));
2059 prop->AddChild(prop2);
2062 void AddChild( wxPGProperty
* prop
);
2064 /** Returns height of children, recursively, and
2065 by taking expanded/collapsed status into account.
2067 iMax is used when finding property y-positions.
2069 int GetChildrenHeight( int lh
, int iMax
= -1 ) const;
2071 /** Returns number of child properties */
2072 unsigned int GetChildCount() const
2074 return (unsigned int) m_children
.size();
2077 /** Returns sub-property at index i. */
2078 wxPGProperty
* Item( unsigned int i
) const
2079 { return m_children
[i
]; }
2081 /** Returns last sub-property.
2083 wxPGProperty
* Last() const { return m_children
.back(); }
2085 /** Returns index of given child property. */
2086 int Index( const wxPGProperty
* p
) const;
2088 // Puts correct indexes to children
2089 void FixIndicesOfChildren( unsigned int starthere
= 0 );
2092 // Returns wxPropertyGridPageState in which this property resides.
2093 wxPropertyGridPageState
* GetParentState() const { return m_parentState
; }
2096 wxPGProperty
* GetItemAtY( unsigned int y
,
2098 unsigned int* nextItemY
) const;
2100 /** Returns (direct) child property with given name (or NULL if not found).
2102 wxPGProperty
* GetPropertyByName( const wxString
& name
) const;
2106 DocStr(GetClientData
,
2107 "Returns the client data object for a property", "");
2108 PyObject
* GetClientData() {
2109 wxPyClientData
* data
= (wxPyClientData
*)self
->GetClientObject();
2111 Py_INCREF(data
->m_obj
);
2119 DocStr(SetClientData
,
2120 "Associate the given client data.", "");
2121 void SetClientData(PyObject
* clientData
) {
2122 wxPyClientData
* data
= new wxPyClientData(clientData
);
2123 self
->SetClientObject(data
);
2127 GetClientObject
= GetClientData
2128 SetClientObject
= SetClientData
2134 // Returns various display-related information for given column
2135 void GetDisplayInfo( unsigned int column
,
2139 const wxPGCell
** pCell
);
2141 static wxString
* sm_wxPG_LABEL
;
2143 /** This member is public so scripting language bindings
2144 wrapper code can access it freely.
2151 Sets property cell in fashion that reduces number of exclusive
2152 copies of cell data. Used when setting, for instance, same
2153 background colour for a number of properties.
2156 First column to affect.
2159 Last column to affect.
2162 Pre-prepared cell that is used for those which cell data
2163 before this matched unmodCellData.
2166 If unmodCellData did not match, valid cell data from this
2167 is merged into cell (usually generating new exclusive copy
2170 @param unmodCellData
2171 If cell's cell data matches this, its cell is now set to
2174 @param ignoreWithFlags
2175 Properties with any one of these flags are skipped.
2178 If @true, apply this operation recursively in child properties.
2180 void AdaptiveSetCell( unsigned int firstCol
,
2181 unsigned int lastCol
,
2182 const wxPGCell
& preparedCell
,
2183 const wxPGCell
& srcData
,
2184 wxPGCellData
* unmodCellData
,
2185 FlagType ignoreWithFlags
,
2189 Makes sure m_cells has size of column+1 (or more).
2191 void EnsureCells( unsigned int column
);
2193 /** Returns (direct) child property with given name (or NULL if not found),
2197 Start looking for the child at this index.
2200 Does not support scope (ie. Parent.Child notation).
2202 wxPGProperty
* GetPropertyByNameWH( const wxString
& name
,
2203 unsigned int hintIndex
) const;
2205 /** This is used by Insert etc. */
2206 void AddChild2( wxPGProperty
* prop
,
2208 bool correct_mode
= true );
2210 void DoGenerateComposedValue( wxString
& text
,
2211 int argFlags
= wxPG_VALUE_IS_CURRENT
,
2212 const wxVariantList
* valueOverrides
= NULL
,
2213 wxPGHashMapS2S
* childResults
= NULL
) const;
2215 void DoSetName(const wxString
& str
) { m_name
= str
; }
2217 /** Deletes all sub-properties. */
2220 void InitAfterAdded( wxPropertyGridPageState
* pageState
,
2221 wxPropertyGrid
* propgrid
);
2223 // Removes child property with given pointer. Does not delete it.
2224 void RemoveChild( wxPGProperty
* p
);
2226 void SetParentState( wxPropertyGridPageState
* pstate
)
2227 { m_parentState
= pstate
; }
2229 // Call after fixed sub-properties added/removed after creation.
2230 // if oldSelInd >= 0 and < new max items, then selection is
2232 void SubPropsChanged( int oldSelInd
= -1 );
2234 int GetY2( int lh
) const;
2238 wxPGProperty
* m_parent
;
2239 wxPropertyGridPageState
* m_parentState
;
2241 wxClientData
* m_clientObject
;
2243 // Overrides editor returned by property class
2244 const wxPGEditor
* m_customEditor
;
2245 #if wxUSE_VALIDATORS
2246 // Editor is going to get this validator
2247 wxValidator
* m_validator
;
2249 // Show this in front of the value
2251 // TODO: Can bitmap be implemented with wxPGCell?
2252 wxBitmap
* m_valueBitmap
;
2255 wxPGAttributeStorage m_attributes
;
2256 wxArrayPGProperty m_children
;
2258 // Extended cell information
2259 wxVector
<wxPGCell
> m_cells
;
2261 // Choices shown in drop-down list of editor control.
2262 wxPGChoices m_choices
;
2264 // Help shown in statusbar or help box.
2265 wxString m_helpString
;
2267 // Index in parent's property array.
2268 unsigned int m_arrIndex
;
2270 // If not -1, then overrides m_value
2275 // Maximum length (mainly for string properties). Could be in some sort of
2276 // wxBaseStringProperty, but currently, for maximum flexibility and
2277 // compatibility, we'll stick it here. Anyway, we had 3 excess bytes to use
2278 // so short int will fit in just fine.
2281 // Root has 0, categories etc. at that level 1, etc.
2282 unsigned char m_depth
;
2284 // m_depthBgCol indicates width of background colour between margin and item
2285 // (essentially this is category's depth, if none then equals m_depth).
2286 unsigned char m_depthBgCol
;
2289 // Called in constructors.
2291 void Init( const wxString
& label
, const wxString
& name
);
2292 #endif // #ifndef SWIG
2295 // -----------------------------------------------------------------------
2298 // Property class declaration helper macros
2299 // (wxPGRootPropertyClass and wxPropertyCategory require this).
2302 #define WX_PG_DECLARE_DOGETEDITORCLASS \
2303 virtual const wxPGEditor* DoGetEditorClass() const;
2306 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
2308 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
2309 WX_PG_DECLARE_DOGETEDITORCLASS \
2312 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME)
2315 // Implements sans constructor function. Also, first arg is class name, not
2317 #define WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(PROPNAME,T,EDITOR) \
2318 const wxPGEditor* PROPNAME::DoGetEditorClass() const \
2320 return wxPGEditor_##EDITOR; \
2323 // -----------------------------------------------------------------------
2327 /** @class wxPGRootProperty
2329 Root parent property.
2331 class WXDLLIMPEXP_PROPGRID wxPGRootProperty
: public wxPGProperty
2334 WX_PG_DECLARE_PROPERTY_CLASS(wxPGRootProperty
)
2339 virtual ~wxPGRootProperty();
2341 virtual bool StringToValue( wxVariant
&, const wxString
&, int ) const
2349 // -----------------------------------------------------------------------
2351 /** @class wxPropertyCategory
2353 Category (caption) property.
2355 class WXDLLIMPEXP_PROPGRID wxPropertyCategory
: public wxPGProperty
2357 friend class wxPropertyGrid
;
2358 friend class wxPropertyGridPageState
;
2359 WX_PG_DECLARE_PROPERTY_CLASS(wxPropertyCategory
)
2362 /** Default constructor is only used in special cases. */
2363 wxPropertyCategory();
2365 wxPropertyCategory( const wxString
& label
,
2366 const wxString
& name
= wxPG_LABEL
);
2367 ~wxPropertyCategory();
2369 int GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const;
2371 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
) const;
2374 void SetTextColIndex( unsigned int colInd
)
2375 { m_capFgColIndex
= (wxByte
) colInd
; }
2376 unsigned int GetTextColIndex() const
2377 { return (unsigned int) m_capFgColIndex
; }
2379 void CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
);
2381 int m_textExtent
; // pre-calculated length of text
2382 wxByte m_capFgColIndex
; // caption text colour index
2390 // -----------------------------------------------------------------------
2392 #endif // wxUSE_PROPGRID
2394 #endif // _WX_PROPGRID_PROPERTY_H_