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
: public wxObjectRefData
72 : wxObjectRefData() { }
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
143 @return Returns image width, which, for instance, can be passed to
146 int PreDrawCell( wxDC
& dc
,
148 const wxPGCell
& cell
,
152 Utility to be called after drawing is done, to revert whatever
153 changes PreDrawCell() did.
156 Same as those passed to PreDrawCell().
158 void PostDrawCell( wxDC
& dc
,
159 const wxPropertyGrid
* propGrid
,
160 const wxPGCell
& cell
,
165 class WXDLLIMPEXP_PROPGRID wxPGCellData
: public wxObjectRefData
167 friend class wxPGCell
;
171 void SetText( const wxString
& text
)
174 m_hasValidText
= true;
176 void SetBitmap( const wxBitmap
& bitmap
) { m_bitmap
= bitmap
; }
177 void SetFgCol( const wxColour
& col
) { m_fgCol
= col
; }
178 void SetBgCol( const wxColour
& col
) { m_bgCol
= col
; }
179 void SetFont( const wxFont
& font
) { m_font
= font
; }
182 virtual ~wxPGCellData() { }
190 // True if m_text is valid and specified
197 Base class for wxPropertyGrid cell information.
199 class WXDLLIMPEXP_PROPGRID wxPGCell
: public wxObject
203 wxPGCell(const wxPGCell
& other
)
208 wxPGCell( const wxString
& text
,
209 const wxBitmap
& bitmap
= wxNullBitmap
,
210 const wxColour
& fgCol
= wxNullColour
,
211 const wxColour
& bgCol
= wxNullColour
);
213 virtual ~wxPGCell() { }
215 wxPGCellData
* GetData()
217 return (wxPGCellData
*) m_refData
;
220 const wxPGCellData
* GetData() const
222 return (const wxPGCellData
*) m_refData
;
227 return (m_refData
&& GetData()->m_hasValidText
);
231 Merges valid data from srcCell into this.
233 void MergeFrom( const wxPGCell
& srcCell
);
235 void SetText( const wxString
& text
);
236 void SetBitmap( const wxBitmap
& bitmap
);
237 void SetFgCol( const wxColour
& col
);
240 Sets font of the cell.
242 @remarks Because wxPropertyGrid does not support rows of
243 different height, it makes little sense to change
244 size of the font. Therefore it is recommended
245 to use return value of wxPropertyGrid::GetFont()
246 or wxPropertyGrid::GetCaptionFont() as a basis
247 for the font that, after modifications, is passed
248 to this member function.
250 void SetFont( const wxFont
& font
);
252 void SetBgCol( const wxColour
& col
);
254 const wxString
& GetText() const { return GetData()->m_text
; }
255 const wxBitmap
& GetBitmap() const { return GetData()->m_bitmap
; }
256 const wxColour
& GetFgCol() const { return GetData()->m_fgCol
; }
259 Returns font of the cell. If no specific font is set for this
260 cell, then the font will be invalid.
262 const wxFont
& GetFont() const { return GetData()->m_font
; }
264 const wxColour
& GetBgCol() const { return GetData()->m_bgCol
; }
266 wxPGCell
& operator=( const wxPGCell
& other
)
268 if ( this != &other
)
276 virtual wxObjectRefData
*CreateRefData() const
277 { return new wxPGCellData(); }
279 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
283 /** @class wxPGDefaultRenderer
285 Default cell renderer, that can handles the common
288 class WXDLLIMPEXP_PROPGRID wxPGDefaultRenderer
: public wxPGCellRenderer
291 virtual void Render( wxDC
& dc
,
293 const wxPropertyGrid
* propertyGrid
,
294 wxPGProperty
* property
,
299 virtual wxSize
GetImageSize( const wxPGProperty
* property
,
306 // -----------------------------------------------------------------------
308 /** @class wxPGAttributeStorage
310 wxPGAttributeStorage is somewhat optimized storage for
311 key=variant pairs (ie. a map).
313 class WXDLLIMPEXP_PROPGRID wxPGAttributeStorage
316 wxPGAttributeStorage();
317 ~wxPGAttributeStorage();
319 void Set( const wxString
& name
, const wxVariant
& value
);
320 unsigned int GetCount() const { return (unsigned int) m_map
.size(); }
321 wxVariant
FindValue( const wxString
& name
) const
323 wxPGHashMapS2P::const_iterator it
= m_map
.find(name
);
324 if ( it
!= m_map
.end() )
326 wxVariantData
* data
= (wxVariantData
*) it
->second
;
328 return wxVariant(data
, it
->first
);
333 typedef wxPGHashMapS2P::const_iterator const_iterator
;
334 const_iterator
StartIteration() const
336 return m_map
.begin();
338 bool GetNext( const_iterator
& it
, wxVariant
& variant
) const
340 if ( it
== m_map
.end() )
343 wxVariantData
* data
= (wxVariantData
*) it
->second
;
345 variant
.SetData(data
);
346 variant
.SetName(it
->first
);
352 wxPGHashMapS2P m_map
;
357 // -----------------------------------------------------------------------
359 /** @section propgrid_propflags wxPGProperty Flags
363 enum wxPG_PROPERTY_FLAGS
366 /** Indicates bold font.
368 wxPG_PROP_MODIFIED
= 0x0001,
370 /** Disables ('greyed' text and editor does not activate) property.
372 wxPG_PROP_DISABLED
= 0x0002,
374 /** Hider button will hide this property.
376 wxPG_PROP_HIDDEN
= 0x0004,
378 /** This property has custom paint image just in front of its value.
379 If property only draws custom images into a popup list, then this
380 flag should not be set.
382 wxPG_PROP_CUSTOMIMAGE
= 0x0008,
384 /** Do not create text based editor for this property (but button-triggered
385 dialog and choice are ok).
387 wxPG_PROP_NOEDITOR
= 0x0010,
389 /** Property is collapsed, ie. it's children are hidden.
391 wxPG_PROP_COLLAPSED
= 0x0020,
394 If property is selected, then indicates that validation failed for pending
397 If property is not selected, then indicates that the the actual property
398 value has failed validation (NB: this behavior is not currently supported,
399 but may be used in future).
401 wxPG_PROP_INVALID_VALUE
= 0x0040,
405 /** Switched via SetWasModified(). Temporary flag - only used when
406 setting/changing property value.
408 wxPG_PROP_WAS_MODIFIED
= 0x0200,
411 If set, then child properties (if any) are private, and should be
412 "invisible" to the application.
414 wxPG_PROP_AGGREGATE
= 0x0400,
416 /** If set, then child properties (if any) are copies and should not
419 wxPG_PROP_CHILDREN_ARE_COPIES
= 0x0800,
422 Classifies this item as a non-category.
424 Used for faster item type identification.
426 wxPG_PROP_PROPERTY
= 0x1000,
429 Classifies this item as a category.
431 Used for faster item type identification.
433 wxPG_PROP_CATEGORY
= 0x2000,
435 /** Classifies this item as a property that has children, but is not aggregate
436 (ie children are not private).
438 wxPG_PROP_MISC_PARENT
= 0x4000,
440 /** Property is read-only. Editor is still created.
442 wxPG_PROP_READONLY
= 0x8000,
445 // NB: FLAGS ABOVE 0x8000 CANNOT BE USED WITH PROPERTY ITERATORS
448 /** Property's value is composed from values of child properties.
450 This flag cannot be used with property iterators.
452 wxPG_PROP_COMPOSED_VALUE
= 0x00010000,
454 /** Common value of property is selectable in editor.
456 This flag cannot be used with property iterators.
458 wxPG_PROP_USES_COMMON_VALUE
= 0x00020000,
460 /** Property can be set to unspecified value via editor.
461 Currently, this applies to following properties:
462 - wxIntProperty, wxUIntProperty, wxFloatProperty, wxEditEnumProperty:
466 This flag cannot be used with property iterators.
468 wxPG_PROP_AUTO_UNSPECIFIED
= 0x00040000,
470 /** Indicates the bit useable by derived properties.
472 wxPG_PROP_CLASS_SPECIFIC_1
= 0x00080000,
474 /** Indicates the bit useable by derived properties.
476 wxPG_PROP_CLASS_SPECIFIC_2
= 0x00100000,
478 /** Indicates that the property is being deleted and should be ignored.
480 wxPG_PROP_BEING_DELETED
= 0x00200000
486 #define wxPG_PROP_MAX wxPG_PROP_AUTO_UNSPECIFIED
488 /** Property with children must have one of these set, otherwise iterators
489 will not work correctly.
490 Code should automatically take care of this, however.
492 #define wxPG_PROP_PARENTAL_FLAGS \
493 (wxPG_PROP_AGGREGATE|wxPG_PROP_CATEGORY|wxPG_PROP_MISC_PARENT)
498 // Combination of flags that can be stored by GetFlagsAsString
499 #define wxPG_STRING_STORED_FLAGS \
500 (wxPG_PROP_DISABLED|wxPG_PROP_HIDDEN|wxPG_PROP_NOEDITOR|wxPG_PROP_COLLAPSED)
502 // -----------------------------------------------------------------------
507 @section propgrid_property_attributes wxPropertyGrid Property Attribute
510 wxPGProperty::SetAttribute() and
511 wxPropertyGridInterface::SetPropertyAttribute() accept one of these as
512 attribute name argument.
514 You can use strings instead of constants. However, some of these
515 constants are redefined to use cached strings which may reduce
516 your binary size by some amount.
521 /** Set default value for property.
523 #define wxPG_ATTR_DEFAULT_VALUE wxS("DefaultValue")
525 /** Universal, int or double. Minimum value for numeric properties.
527 #define wxPG_ATTR_MIN wxS("Min")
529 /** Universal, int or double. Maximum value for numeric properties.
531 #define wxPG_ATTR_MAX wxS("Max")
533 /** Universal, string. When set, will be shown as text after the displayed
534 text value. Alternatively, if third column is enabled, text will be shown
535 there (for any type of property).
537 #define wxPG_ATTR_UNITS wxS("Units")
539 /** Universal, string. When set, will be shown in property's value cell
540 when displayed value string is empty, or value is unspecified.
542 #define wxPG_ATTR_INLINE_HELP wxS("InlineHelp")
544 /** Universal, wxArrayString. Set to enable auto-completion in any
545 wxTextCtrl-based property editor.
547 #define wxPG_ATTR_AUTOCOMPLETE wxS("AutoComplete")
549 /** wxBoolProperty and wxFlagsProperty specific. Value type is bool.
550 Default value is False.
552 When set to True, bool property will use check box instead of a
553 combo box as its editor control. If you set this attribute
554 for a wxFlagsProperty, it is automatically applied to child
557 #define wxPG_BOOL_USE_CHECKBOX wxS("UseCheckbox")
559 /** wxBoolProperty and wxFlagsProperty specific. Value type is bool.
560 Default value is False.
562 Set to True for the bool property to cycle value on double click
563 (instead of showing the popup listbox). If you set this attribute
564 for a wxFlagsProperty, it is automatically applied to child
567 #define wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING wxS("UseDClickCycling")
570 wxFloatProperty (and similar) specific, int, default -1.
572 Sets the (max) precision used when floating point value is rendered as
573 text. The default -1 means infinite precision.
575 #define wxPG_FLOAT_PRECISION wxS("Precision")
578 The text will be echoed as asterisks (wxTE_PASSWORD will be passed to
581 #define wxPG_STRING_PASSWORD wxS("Password")
583 /** Define base used by a wxUIntProperty. Valid constants are
584 wxPG_BASE_OCT, wxPG_BASE_DEC, wxPG_BASE_HEX and wxPG_BASE_HEXL
585 (lowercase characters).
587 #define wxPG_UINT_BASE wxS("Base")
589 /** Define prefix rendered to wxUIntProperty. Accepted constants
590 wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and wxPG_PREFIX_DOLLAR_SIGN.
591 <b>Note:</b> Only wxPG_PREFIX_NONE works with Decimal and Octal
594 #define wxPG_UINT_PREFIX wxS("Prefix")
597 wxFileProperty/wxImageFileProperty specific, wxChar*, default is
599 Sets the wildcard used in the triggered wxFileDialog. Format is the same.
601 #define wxPG_FILE_WILDCARD wxS("Wildcard")
603 /** wxFileProperty/wxImageFileProperty specific, int, default 1.
604 When 0, only the file name is shown (i.e. drive and directory are hidden).
606 #define wxPG_FILE_SHOW_FULL_PATH wxS("ShowFullPath")
608 /** Specific to wxFileProperty and derived properties, wxString, default empty.
609 If set, then the filename is shown relative to the given path string.
611 #define wxPG_FILE_SHOW_RELATIVE_PATH wxS("ShowRelativePath")
614 Specific to wxFileProperty and derived properties, wxString, default is
617 Sets the initial path of where to look for files.
619 #define wxPG_FILE_INITIAL_PATH wxS("InitialPath")
621 /** Specific to wxFileProperty and derivatives, wxString, default is empty.
622 Sets a specific title for the dir dialog.
624 #define wxPG_FILE_DIALOG_TITLE wxS("DialogTitle")
626 /** Specific to wxDirProperty, wxString, default is empty.
627 Sets a specific message for the dir dialog.
629 #define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage")
631 /** Sets displayed date format for wxDateProperty.
633 #define wxPG_DATE_FORMAT wxS("DateFormat")
635 /** Sets wxDatePickerCtrl window style used with wxDateProperty. Default
636 is wxDP_DEFAULT | wxDP_SHOWCENTURY.
638 #define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
640 /** SpinCtrl editor, int or double. How much number changes when button is
641 pressed (or up/down on keybard).
643 #define wxPG_ATTR_SPINCTRL_STEP wxS("Step")
645 /** SpinCtrl editor, bool. If true, value wraps at Min/Max.
647 #define wxPG_ATTR_SPINCTRL_WRAP wxS("Wrap")
650 wxMultiChoiceProperty, int.
651 If 0, no user strings allowed. If 1, user strings appear before list
652 strings. If 2, user strings appear after list string.
654 #define wxPG_ATTR_MULTICHOICE_USERSTRINGMODE wxS("UserStringMode")
657 wxColourProperty and its kind, int, default 1.
659 Setting this attribute to 0 hides custom colour from property's list of
662 #define wxPG_COLOUR_ALLOW_CUSTOM wxS("AllowCustom")
667 // Redefine attribute macros to use cached strings
668 #undef wxPG_ATTR_DEFAULT_VALUE
669 #define wxPG_ATTR_DEFAULT_VALUE wxPGGlobalVars->m_strDefaultValue
671 #define wxPG_ATTR_MIN wxPGGlobalVars->m_strMin
673 #define wxPG_ATTR_MAX wxPGGlobalVars->m_strMax
674 #undef wxPG_ATTR_UNITS
675 #define wxPG_ATTR_UNITS wxPGGlobalVars->m_strUnits
676 #undef wxPG_ATTR_INLINE_HELP
677 #define wxPG_ATTR_INLINE_HELP wxPGGlobalVars->m_strInlineHelp
681 // -----------------------------------------------------------------------
685 /** @class wxPGChoiceEntry
686 Data of a single wxPGChoices choice.
688 class WXDLLIMPEXP_PROPGRID wxPGChoiceEntry
: public wxPGCell
692 wxPGChoiceEntry(const wxPGChoiceEntry
& other
)
695 m_value
= other
.m_value
;
697 wxPGChoiceEntry( const wxString
& label
,
698 int value
= wxPG_INVALID_VALUE
)
699 : wxPGCell(), m_value(value
)
704 virtual ~wxPGChoiceEntry() { }
706 void SetValue( int value
) { m_value
= value
; }
707 int GetValue() const { return m_value
; }
709 wxPGChoiceEntry
& operator=( const wxPGChoiceEntry
& other
)
711 if ( this != &other
)
715 m_value
= other
.m_value
;
724 typedef void* wxPGChoicesId
;
726 class WXDLLIMPEXP_PROPGRID wxPGChoicesData
: public wxObjectRefData
728 friend class wxPGChoices
;
730 // Constructor sets m_refCount to 1.
733 void CopyDataFrom( wxPGChoicesData
* data
);
735 wxPGChoiceEntry
& Insert( int index
, const wxPGChoiceEntry
& item
);
737 // Delete all entries
740 unsigned int GetCount() const
742 return (unsigned int) m_items
.size();
745 const wxPGChoiceEntry
& Item( unsigned int i
) const
747 wxASSERT_MSG( i
< GetCount(), "invalid index" );
751 wxPGChoiceEntry
& Item( unsigned int i
)
753 wxASSERT_MSG( i
< GetCount(), "invalid index" );
758 wxVector
<wxPGChoiceEntry
> m_items
;
760 virtual ~wxPGChoicesData();
763 #define wxPGChoicesEmptyData ((wxPGChoicesData*)NULL)
767 /** @class wxPGChoices
769 Helper class for managing choices of wxPropertyGrid properties.
770 Each entry can have label, value, bitmap, text colour, and background
773 wxPGChoices uses reference counting, similar to other wxWidgets classes.
774 This means that assignment operator and copy constructor only copy the
775 reference and not the actual data. Use Copy() member function to create a
778 @remarks If you do not specify value for entry, index is used.
783 class WXDLLIMPEXP_PROPGRID wxPGChoices
786 typedef long ValArrItem
;
788 /** Default constructor. */
795 Copy constructor, uses reference counting. To create a real copy,
796 use Copy() member function instead.
798 wxPGChoices( const wxPGChoices
& a
)
800 if ( a
.m_data
!= wxPGChoicesEmptyData
)
814 Values for choices. If NULL, indexes are used.
816 wxPGChoices( const wxChar
** labels
, const long* values
= NULL
)
829 Values for choices. If empty, indexes are used.
831 wxPGChoices( const wxArrayString
& labels
,
832 const wxArrayInt
& values
= wxArrayInt() )
838 /** Simple interface constructor. */
839 wxPGChoices( wxPGChoicesData
* data
)
855 If did not have own copies, creates them now. If was empty, identical
856 to set except that creates copies.
859 Labels for added choices.
862 Values for added choices. If empty, relevant entry indexes are used.
864 void Add( const wxChar
** labels
, const ValArrItem
* values
= NULL
);
866 /** Version that works with wxArrayString and wxArrayInt. */
867 void Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
= wxArrayInt() );
870 Adds a single choice.
873 Label for added choice.
876 Value for added choice. If unspecified, index is used.
878 wxPGChoiceEntry
& Add( const wxString
& label
,
879 int value
= wxPG_INVALID_VALUE
);
881 /** Adds a single item, with bitmap. */
882 wxPGChoiceEntry
& Add( const wxString
& label
,
883 const wxBitmap
& bitmap
,
884 int value
= wxPG_INVALID_VALUE
);
886 /** Adds a single item with full entry information. */
887 wxPGChoiceEntry
& Add( const wxPGChoiceEntry
& entry
)
889 return Insert(entry
, -1);
892 /** Adds single item. */
893 wxPGChoiceEntry
& AddAsSorted( const wxString
& label
,
894 int value
= wxPG_INVALID_VALUE
);
897 Assigns choices data, using reference counting. To create a real copy,
898 use Copy() member function instead.
900 void Assign( const wxPGChoices
& a
)
902 AssignData(a
.m_data
);
905 void AssignData( wxPGChoicesData
* data
);
907 /** Delete all choices. */
911 Returns a real copy of the choices.
913 wxPGChoices
Copy() const
917 dst
.m_data
->CopyDataFrom(m_data
);
923 if ( m_data
== wxPGChoicesEmptyData
)
924 m_data
= new wxPGChoicesData();
927 /** Gets a unsigned number identifying this list. */
928 wxPGChoicesId
GetId() const { return (wxPGChoicesId
) m_data
; };
930 const wxString
& GetLabel( unsigned int ind
) const
932 return Item(ind
).GetText();
935 unsigned int GetCount () const
940 return m_data
->GetCount();
943 int GetValue( unsigned int ind
) const { return Item(ind
).GetValue(); }
945 /** Returns array of values matching the given strings. Unmatching strings
946 result in wxPG_INVALID_VALUE entry in array.
948 wxArrayInt
GetValuesForStrings( const wxArrayString
& strings
) const;
950 /** Returns array of indices matching given strings. Unmatching strings
951 are added to 'unmatched', if not NULL.
953 wxArrayInt
GetIndicesForStrings( const wxArrayString
& strings
,
954 wxArrayString
* unmatched
= NULL
) const;
956 int Index( const wxString
& str
) const;
957 int Index( int val
) const;
959 /** Inserts single item. */
960 wxPGChoiceEntry
& Insert( const wxString
& label
,
962 int value
= wxPG_INVALID_VALUE
);
964 /** Inserts a single item with full entry information. */
965 wxPGChoiceEntry
& Insert( const wxPGChoiceEntry
& entry
, int index
);
967 /** Returns false if this is a constant empty set of choices,
968 which should not be modified.
972 return ( m_data
!= wxPGChoicesEmptyData
);
975 const wxPGChoiceEntry
& Item( unsigned int i
) const
978 return m_data
->Item(i
);
981 wxPGChoiceEntry
& Item( unsigned int i
)
984 return m_data
->Item(i
);
987 /** Removes count items starting at position nIndex. */
988 void RemoveAt(size_t nIndex
, size_t count
= 1);
991 /** Does not create copies for itself. */
992 void Set( const wxChar
** labels
, const long* values
= NULL
)
999 /** Version that works with wxArrayString and wxArrayInt. */
1000 void Set( const wxArrayString
& labels
,
1001 const wxArrayInt
& values
= wxArrayInt() )
1010 // Creates exclusive copy of current choices
1011 void AllocExclusive();
1013 // Returns data, increases refcount.
1014 wxPGChoicesData
* GetData()
1016 wxASSERT( m_data
->GetRefCount() != -1 );
1021 // Returns plain data ptr - no refcounting stuff is done.
1022 wxPGChoicesData
* GetDataPtr() const { return m_data
; }
1024 // Changes ownership of data to you.
1025 wxPGChoicesData
* ExtractData()
1027 wxPGChoicesData
* data
= m_data
;
1028 m_data
= wxPGChoicesEmptyData
;
1032 wxArrayString
GetLabels() const;
1035 void operator= (const wxPGChoices
& a
)
1038 AssignData(a
.m_data
);
1041 wxPGChoiceEntry
& operator[](unsigned int i
)
1046 const wxPGChoiceEntry
& operator[](unsigned int i
) const
1052 wxPGChoicesData
* m_data
;
1059 // -----------------------------------------------------------------------
1061 /** @class wxPGProperty
1063 wxPGProperty is base class for all wxPropertyGrid properties.
1065 NB: Full class overview is now only present in
1066 interface/wx/propgrid/property.h.
1068 @library{wxpropgrid}
1071 class WXDLLIMPEXP_PROPGRID wxPGProperty
: public wxObject
1073 friend class wxPropertyGrid
;
1074 friend class wxPropertyGridInterface
;
1075 friend class wxPropertyGridPageState
;
1076 friend class wxPropertyGridPopulator
;
1077 friend class wxStringProperty
; // Proper "<composed>" support requires this
1079 DECLARE_ABSTRACT_CLASS(wxPGProperty
)
1081 typedef wxUint32 FlagType
;
1084 Default constructor.
1091 All non-abstract property classes should have a constructor with
1092 the same first two arguments as this one.
1094 wxPGProperty( const wxString
& label
, const wxString
& name
);
1098 It is customary for derived properties to implement this.
1100 virtual ~wxPGProperty();
1102 /** This virtual function is called after m_value has been set.
1105 - If m_value was set to Null variant (ie. unspecified value),
1106 OnSetValue() will not be called.
1107 - m_value may be of any variant type. Typically properties internally
1108 support only one variant type, and as such OnSetValue() provides a
1109 good opportunity to convert
1110 supported values into internal type.
1111 - Default implementation does nothing.
1113 virtual void OnSetValue();
1115 /** Override this to return something else than m_value as the value.
1117 virtual wxVariant
DoGetValue() const { return m_value
; }
1119 #if !defined(SWIG) || defined(CREATE_VCW)
1120 /** Implement this function in derived class to check the value.
1121 Return true if it is ok. Returning false prevents property change events
1125 - Default implementation always returns true.
1127 virtual bool ValidateValue( wxVariant
& value
,
1128 wxPGValidationInfo
& validationInfo
) const;
1131 Converts text into wxVariant value appropriate for this property.
1134 On function entry this is the old value (should not be wxNullVariant
1135 in normal cases). Translated value must be assigned back to it.
1138 Text to be translated into variant.
1141 If wxPG_FULL_VALUE is set, returns complete, storable value instead
1142 of displayable one (they may be different).
1143 If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of
1144 composite property string value (as generated by ValueToString()
1145 called with this same flag).
1147 @return Returns @true if resulting wxVariant value was different.
1149 @remarks Default implementation converts semicolon delimited tokens into
1150 child values. Only works for properties with children.
1152 You might want to take into account that m_value is Null variant
1153 if property value is unspecified (which is usually only case if
1154 you explicitly enabled that sort behavior).
1156 virtual bool StringToValue( wxVariant
& variant
,
1157 const wxString
& text
,
1158 int argFlags
= 0 ) const;
1161 Converts integer (possibly a choice selection) into wxVariant value
1162 appropriate for this property.
1165 On function entry this is the old value (should not be wxNullVariant
1166 in normal cases). Translated value must be assigned back to it.
1169 Integer to be translated into variant.
1172 If wxPG_FULL_VALUE is set, returns complete, storable value instead
1175 @return Returns @true if resulting wxVariant value was different.
1178 - If property is not supposed to use choice or spinctrl or other editor
1179 with int-based value, it is not necessary to implement this method.
1180 - Default implementation simply assign given int to m_value.
1181 - If property uses choice control, and displays a dialog on some choice
1182 items, then it is preferred to display that dialog in IntToValue
1184 - You might want to take into account that m_value is Null variant if
1185 property value is unspecified (which is usually only case if you
1186 explicitly enabled that sort behavior).
1188 virtual bool IntToValue( wxVariant
& value
,
1190 int argFlags
= 0 ) const;
1191 #endif // !defined(SWIG) || defined(CREATE_VCW)
1193 Converts property value into a text representation.
1196 Value to be converted.
1199 If 0 (default value), then displayed string is returned.
1200 If wxPG_FULL_VALUE is set, returns complete, storable string value
1201 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
1202 string value that must be editable in textctrl. If
1203 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
1204 display as a part of string property's composite text
1207 @remarks Default implementation calls GenerateComposedValue().
1209 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
1211 /** Converts string to a value, and if successful, calls SetValue() on it.
1212 Default behavior is to do nothing.
1214 String to get the value from.
1216 true if value was changed.
1218 bool SetValueFromString( const wxString
& text
, int flags
= wxPG_PROGRAMMATIC_VALUE
);
1220 /** Converts integer to a value, and if succesful, calls SetValue() on it.
1221 Default behavior is to do nothing.
1223 Int to get the value from.
1225 If has wxPG_FULL_VALUE, then the value given is a actual value and
1228 True if value was changed.
1230 bool SetValueFromInt( long value
, int flags
= 0 );
1233 Returns size of the custom painted image in front of property.
1235 This method must be overridden to return non-default value if
1236 OnCustomPaint is to be called.
1238 Normally -1, but can be an index to the property's list of items.
1240 - Default behavior is to return wxSize(0,0), which means no image.
1241 - Default image width or height is indicated with dimension -1.
1242 - You can also return wxPG_DEFAULT_IMAGE_SIZE, i.e. wxSize(-1, -1).
1244 virtual wxSize
OnMeasureImage( int item
= -1 ) const;
1247 Events received by editor widgets are processed here.
1249 Note that editor class usually processes most events. Some, such as
1250 button press events of TextCtrlAndButton class, can be handled here.
1251 Also, if custom handling for regular events is desired, then that can
1252 also be done (for example, wxSystemColourProperty custom handles
1253 wxEVT_COMMAND_CHOICE_SELECTED to display colour picker dialog when
1254 'custom' selection is made).
1256 If the event causes value to be changed, SetValueInEvent()
1257 should be called to set the new value.
1262 Should return true if any changes in value should be reported.
1264 If property uses choice control, and displays a dialog on some choice
1265 items, then it is preferred to display that dialog in IntToValue
1268 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
1269 wxWindow
* wnd_primary
,
1273 Called after value of a child property has been altered. Must return
1274 new value of the whole property (after any alterations warrented by
1277 Note that this function is usually called at the time that value of
1278 this property, or given child property, is still pending for change,
1279 and as such, result of GetValue() or m_value should not be relied
1282 Sample pseudo-code implementation:
1285 wxVariant MyProperty::ChildChanged( wxVariant& thisValue,
1287 wxVariant& childValue ) const
1289 // Acquire reference to actual type of data stored in variant
1290 // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros
1291 // were used to create the variant class).
1292 T& data = TFromVariant(thisValue);
1294 // Copy childValue into data.
1295 switch ( childIndex )
1298 data.SetSubProp1( childvalue.GetLong() );
1301 data.SetSubProp2( childvalue.GetString() );
1306 // Return altered data
1312 Value of this property. Changed value should be returned (in
1313 previous versions of wxPropertyGrid it was only necessary to
1314 write value back to this argument).
1316 Index of child changed (you can use Item(childIndex) to get
1319 (Pending) value of the child property.
1322 Modified value of the whole property.
1324 virtual wxVariant
ChildChanged( wxVariant
& thisValue
,
1326 wxVariant
& childValue
) const;
1328 /** Returns pointer to an instance of used editor.
1330 virtual const wxPGEditor
* DoGetEditorClass() const;
1332 /** Returns pointer to the wxValidator that should be used
1333 with the editor of this property (NULL for no validator).
1334 Setting validator explicitly via SetPropertyValidator
1337 In most situations, code like this should work well
1338 (macros are used to maintain one actual validator instance,
1339 so on the second call the function exits within the first
1344 wxValidator* wxMyPropertyClass::DoGetValidator () const
1346 WX_PG_DOGETVALIDATOR_ENTRY()
1348 wxMyValidator* validator = new wxMyValidator(...);
1350 ... prepare validator...
1352 WX_PG_DOGETVALIDATOR_EXIT(validator)
1358 You can get common filename validator by returning
1359 wxFileProperty::GetClassValidator(). wxDirProperty,
1360 for example, uses it.
1362 virtual wxValidator
* DoGetValidator () const;
1365 Override to paint an image in front of the property value text or
1366 drop-down list item (but only if wxPGProperty::OnMeasureImage is
1367 overridden as well).
1369 If property's OnMeasureImage() returns size that has height != 0 but
1370 less than row height ( < 0 has special meanings), wxPropertyGrid calls
1371 this method to draw a custom image in a limited area in front of the
1372 editor control or value text/graphics, and if control has drop-down
1373 list, then the image is drawn there as well (even in the case
1374 OnMeasureImage() returned higher height than row height).
1376 NOTE: Following applies when OnMeasureImage() returns a "flexible"
1377 height ( using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable
1378 height items: If rect.x is < 0, then this is a measure item call, which
1379 means that dc is invalid and only thing that should be done is to set
1380 paintdata.m_drawnHeight to the height of the image of item at index
1381 paintdata.m_choiceItem. This call may be done even as often as once
1382 every drop-down popup show.
1387 Box reserved for custom graphics. Includes surrounding rectangle,
1388 if any. If x is < 0, then this is a measure item call (see above).
1390 wxPGPaintData structure with much useful data.
1393 - You can actually exceed rect width, but if you do so then
1394 paintdata.m_drawnWidth must be set to the full width drawn in
1396 - Due to technical reasons, rect's height will be default even if
1397 custom height was reported during measure call.
1398 - Brush is guaranteed to be default background colour. It has been
1399 already used to clear the background of area being painted. It
1401 - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper
1402 colour) pen for drawing framing rectangle. It can be changed as
1405 @see ValueToString()
1407 virtual void OnCustomPaint( wxDC
& dc
,
1409 wxPGPaintData
& paintdata
);
1412 Returns used wxPGCellRenderer instance for given property column
1415 Default implementation returns editor's renderer for all columns.
1417 virtual wxPGCellRenderer
* GetCellRenderer( int column
) const;
1419 /** Returns which choice is currently selected. Only applies to properties
1422 Needs to reimplemented in derived class if property value does not
1423 map directly to a choice. Integer as index, bool, and string usually do.
1425 virtual int GetChoiceSelection() const;
1428 Refresh values of child properties.
1430 Automatically called after value is set.
1432 virtual void RefreshChildren();
1434 /** Special handling for attributes of this property.
1436 If returns false, then the attribute will be automatically stored in
1439 Default implementation simply returns false.
1441 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
1443 /** Returns value of an attribute.
1445 Override if custom handling of attributes is needed.
1447 Default implementation simply return NULL variant.
1449 virtual wxVariant
DoGetAttribute( const wxString
& name
) const;
1451 /** Returns instance of a new wxPGEditorDialogAdapter instance, which is
1452 used when user presses the (optional) button next to the editor control;
1454 Default implementation returns NULL (ie. no action is generated when
1457 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
1460 Called whenever validation has failed with given pending value.
1462 @remarks If you implement this in your custom property class, please
1463 remember to call the baser implementation as well, since they
1464 may use it to revert property into pre-change state.
1466 virtual void OnValidationFailure( wxVariant
& pendingValue
);
1468 /** Append a new choice to property's list of choices.
1470 int AddChoice( const wxString
& label
, int value
= wxPG_INVALID_VALUE
)
1472 return InsertChoice(label
, wxNOT_FOUND
, value
);
1476 Returns true if children of this property are component values (for
1477 instance, points size, face name, and is_underlined are component
1480 bool AreChildrenComponents() const
1482 if ( m_flags
& (wxPG_PROP_COMPOSED_VALUE
|wxPG_PROP_AGGREGATE
) )
1489 Deletes children of the property.
1491 void DeleteChildren();
1494 Removes entry from property's wxPGChoices and editor control (if it is
1497 If selected item is deleted, then the value is set to unspecified.
1499 void DeleteChoice( int index
);
1502 Call to enable or disable usage of common value (integer value that can
1503 be selected for properties instead of their normal values) for this
1506 Common values are disabled by the default for all properties.
1508 void EnableCommonValue( bool enable
= true )
1510 if ( enable
) SetFlag( wxPG_PROP_USES_COMMON_VALUE
);
1511 else ClearFlag( wxPG_PROP_USES_COMMON_VALUE
);
1515 Composes text from values of child properties.
1517 wxString
GenerateComposedValue() const
1520 DoGenerateComposedValue(s
);
1524 /** Returns property's label. */
1525 const wxString
& GetLabel() const { return m_label
; }
1527 /** Returns property's name with all (non-category, non-root) parents. */
1528 wxString
GetName() const;
1531 Returns property's base name (ie parent's name is not added in any
1534 const wxString
& GetBaseName() const { return m_name
; }
1536 /** Returns read-only reference to property's list of choices.
1538 const wxPGChoices
& GetChoices() const
1543 /** Returns coordinate to the top y of the property. Note that the
1544 position of scrollbars is not taken into account.
1548 wxVariant
GetValue() const
1550 return DoGetValue();
1553 /** Returns reference to the internal stored value. GetValue is preferred
1554 way to get the actual value, since GetValueRef ignores DoGetValue,
1555 which may override stored value.
1557 wxVariant
& GetValueRef()
1562 const wxVariant
& GetValueRef() const
1567 // Helper function (for wxPython bindings and such) for settings protected
1569 wxVariant
GetValuePlain() const
1574 /** Returns text representation of property's value.
1577 If 0 (default value), then displayed string is returned.
1578 If wxPG_FULL_VALUE is set, returns complete, storable string value
1579 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
1580 string value that must be editable in textctrl. If
1581 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
1582 display as a part of string property's composite text
1585 @remarks In older versions, this function used to be overridden to convert
1586 property's value into a string representation. This function is
1587 now handled by ValueToString(), and overriding this function now
1588 will result in run-time assertion failure.
1590 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
1592 /** Synonymous to GetValueAsString().
1594 @deprecated Use GetValueAsString() instead.
1596 @see GetValueAsString()
1598 wxDEPRECATED( wxString
GetValueString( int argFlags
= 0 ) const );
1601 Returns wxPGCell of given column.
1603 @remarks const version of this member function returns 'default'
1604 wxPGCell object if the property itself didn't hold
1607 const wxPGCell
& GetCell( unsigned int column
) const;
1610 Returns wxPGCell of given column, creating one if necessary.
1612 wxPGCell
& GetCell( unsigned int column
)
1614 return GetOrCreateCell(column
);
1618 Returns wxPGCell of given column, creating one if necessary.
1620 wxPGCell
& GetOrCreateCell( unsigned int column
);
1622 /** Return number of displayed common values for this property.
1624 int GetDisplayedCommonValueCount() const;
1626 wxString
GetDisplayedString() const
1628 return GetValueAsString(0);
1631 /** Returns property grid where property lies. */
1632 wxPropertyGrid
* GetGrid() const;
1634 /** Returns owner wxPropertyGrid, but only if one is currently on a page
1635 displaying this property. */
1636 wxPropertyGrid
* GetGridIfDisplayed() const;
1638 /** Returns highest level non-category, non-root parent. Useful when you
1639 have nested wxCustomProperties/wxParentProperties.
1641 Thus, if immediate parent is root or category, this will return the
1644 wxPGProperty
* GetMainParent() const;
1646 /** Return parent of property */
1647 wxPGProperty
* GetParent() const { return m_parent
; }
1649 /** Returns true if property has editable wxTextCtrl when selected.
1652 Altough disabled properties do not displayed editor, they still
1653 return True here as being disabled is considered a temporary
1654 condition (unlike being read-only or having limited editing enabled).
1656 bool IsTextEditable() const;
1658 bool IsValueUnspecified() const
1660 return m_value
.IsNull();
1663 FlagType
HasFlag( FlagType flag
) const
1665 return ( m_flags
& flag
);
1668 /** Returns comma-delimited string of property attributes.
1670 const wxPGAttributeStorage
& GetAttributes() const
1672 return m_attributes
;
1675 /** Returns m_attributes as list wxVariant.
1677 wxVariant
GetAttributesAsList() const;
1679 FlagType
GetFlags() const
1684 const wxPGEditor
* GetEditorClass() const;
1686 wxString
GetValueType() const
1688 return m_value
.GetType();
1691 /** Returns editor used for given column. NULL for no editor.
1693 const wxPGEditor
* GetColumnEditor( int column
) const
1696 return GetEditorClass();
1701 /** Returns common value selected for this property. -1 for none.
1703 int GetCommonValue() const
1705 return m_commonValue
;
1708 /** Returns true if property has even one visible child.
1710 bool HasVisibleChildren() const;
1713 Use this member function to add independent (ie. regular) children to
1716 @return Inserted childProperty.
1718 @remarks wxPropertyGrid is not automatically refreshed by this
1721 @see AddPrivateChild()
1723 wxPGProperty
* InsertChild( int index
, wxPGProperty
* childProperty
);
1725 /** Inserts a new choice to property's list of choices.
1727 int InsertChoice( const wxString
& label
, int index
, int value
= wxPG_INVALID_VALUE
);
1730 Returns true if this property is actually a wxPropertyCategory.
1732 bool IsCategory() const { return HasFlag(wxPG_PROP_CATEGORY
)?true:false; }
1734 /** Returns true if this property is actually a wxRootProperty.
1736 bool IsRoot() const { return (m_parent
== NULL
); }
1738 /** Returns true if this is a sub-property. */
1739 bool IsSubProperty() const
1741 wxPGProperty
* parent
= (wxPGProperty
*)m_parent
;
1742 if ( parent
&& !parent
->IsCategory() )
1747 /** Returns last visible sub-property, recursively.
1749 const wxPGProperty
* GetLastVisibleSubItem() const;
1751 wxVariant
GetDefaultValue() const;
1753 int GetMaxLength() const
1755 return (int) m_maxLen
;
1759 Determines, recursively, if all children are not unspecified.
1762 Assumes members in this wxVariant list as pending
1765 bool AreAllChildrenSpecified( wxVariant
* pendingList
= NULL
) const;
1767 /** Updates composed values of parent non-category properties, recursively.
1768 Returns topmost property updated.
1771 - Must not call SetValue() (as can be called in it).
1773 wxPGProperty
* UpdateParentValues();
1775 /** Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
1777 bool UsesAutoUnspecified() const
1779 return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED
)?true:false;
1782 wxBitmap
* GetValueImage() const
1784 return m_valueBitmap
;
1787 wxVariant
GetAttribute( const wxString
& name
) const;
1790 Returns named attribute, as string, if found.
1792 Otherwise defVal is returned.
1794 wxString
GetAttribute( const wxString
& name
, const wxString
& defVal
) const;
1797 Returns named attribute, as long, if found.
1799 Otherwise defVal is returned.
1801 long GetAttributeAsLong( const wxString
& name
, long defVal
) const;
1804 Returns named attribute, as double, if found.
1806 Otherwise defVal is returned.
1808 double GetAttributeAsDouble( const wxString
& name
, double defVal
) const;
1810 unsigned int GetDepth() const { return (unsigned int)m_depth
; }
1812 /** Gets flags as a'|' delimited string. Note that flag names are not
1813 prepended with 'wxPG_PROP_'.
1815 String will only be made to include flags combined by this parameter.
1817 wxString
GetFlagsAsString( FlagType flagsMask
) const;
1819 /** Returns position in parent's array. */
1820 unsigned int GetIndexInParent() const
1822 return (unsigned int)m_arrIndex
;
1825 /** Hides or reveals the property.
1827 true for hide, false for reveal.
1829 By default changes are applied recursively. Set this paramter
1830 wxPG_DONT_RECURSE to prevent this.
1832 inline bool Hide( bool hide
, int flags
= wxPG_RECURSE
);
1834 bool IsExpanded() const
1835 { return (!(m_flags
& wxPG_PROP_COLLAPSED
) && GetChildCount()); }
1837 /** Returns true if all parents expanded.
1839 bool IsVisible() const;
1841 bool IsEnabled() const { return !(m_flags
& wxPG_PROP_DISABLED
); }
1843 /** If property's editor is created this forces its recreation.
1844 Useful in SetAttribute etc. Returns true if actually did anything.
1846 bool RecreateEditor();
1848 /** If property's editor is active, then update it's value.
1850 void RefreshEditor();
1852 /** Sets an attribute for this property.
1854 Text identifier of attribute. See @ref propgrid_property_attributes.
1858 void SetAttribute( const wxString
& name
, wxVariant value
);
1860 void SetAttributes( const wxPGAttributeStorage
& attributes
);
1863 Sets property's background colour.
1866 Background colour to use.
1869 Default is wxPG_RECURSE which causes colour to be set recursively.
1870 Omit this flag to only set colour for the property in question
1871 and not any of its children.
1873 void SetBackgroundColour( const wxColour
& colour
,
1874 int flags
= wxPG_RECURSE
);
1877 Sets property's text colour.
1883 Default is wxPG_RECURSE which causes colour to be set recursively.
1884 Omit this flag to only set colour for the property in question
1885 and not any of its children.
1887 void SetTextColour( const wxColour
& colour
,
1888 int flags
= wxPG_RECURSE
);
1890 /** Set default value of a property. Synonymous to
1893 SetAttribute("DefaultValue", value);
1896 void SetDefaultValue( wxVariant
& value
);
1899 /** Sets editor for a property.
1902 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1903 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full
1906 For custom editors, use pointer you received from
1907 wxPropertyGrid::RegisterEditorClass().
1909 void SetEditor( const wxPGEditor
* editor
)
1911 m_customEditor
= editor
;
1915 /** Sets editor for a property.
1917 inline void SetEditor( const wxString
& editorName
);
1920 Sets cell information for given column.
1922 void SetCell( int column
, const wxPGCell
& cell
);
1924 /** Sets common value selected for this property. -1 for none.
1926 void SetCommonValue( int commonValue
)
1928 m_commonValue
= commonValue
;
1931 /** Sets flags from a '|' delimited string. Note that flag names are not
1932 prepended with 'wxPG_PROP_'.
1934 void SetFlagsFromString( const wxString
& str
);
1936 /** Sets property's "is it modified?" flag. Affects children recursively.
1938 void SetModifiedStatus( bool modified
)
1940 SetFlagRecursively(wxPG_PROP_MODIFIED
, modified
);
1943 /** Call in OnEvent(), OnButtonClick() etc. to change the property value
1944 based on user input.
1947 This method is const since it doesn't actually modify value, but posts
1948 given variant as pending value, stored in wxPropertyGrid.
1950 void SetValueInEvent( wxVariant value
) const;
1953 Call this to set value of the property.
1955 Unlike methods in wxPropertyGrid, this does not automatically update
1959 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run
1960 through validation process and send property change event.
1962 If you need to change property value in event, based on user input, use
1963 SetValueInEvent() instead.
1966 Pointer to list variant that contains child values. Used to
1967 indicate which children should be marked as modified.
1970 Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR, which is
1971 enabled by default).
1973 void SetValue( wxVariant value
, wxVariant
* pList
= NULL
,
1974 int flags
= wxPG_SETVAL_REFRESH_EDITOR
);
1976 /** Set wxBitmap in front of the value. This bitmap may be ignored
1977 by custom cell renderers.
1979 void SetValueImage( wxBitmap
& bmp
);
1981 /** Sets selected choice and changes property value.
1983 Tries to retain value type, although currently if it is not string,
1984 then it is forced to integer.
1986 void SetChoiceSelection( int newValue
);
1988 void SetExpanded( bool expanded
)
1990 if ( !expanded
) m_flags
|= wxPG_PROP_COLLAPSED
;
1991 else m_flags
&= ~wxPG_PROP_COLLAPSED
;
1995 Sets given property flag(s).
1997 void SetFlag( FlagType flag
) { m_flags
|= flag
; }
2000 Sets or clears given property flag(s).
2002 void ChangeFlag( FlagType flag
, bool set
)
2010 void SetFlagRecursively( FlagType flag
, bool set
);
2012 void SetHelpString( const wxString
& helpString
)
2014 m_helpString
= helpString
;
2017 void SetLabel( const wxString
& label
) { m_label
= label
; }
2019 void SetName( const wxString
& newName
);
2022 Changes what sort of parent this property is for its children.
2025 Use one of the following values: wxPG_PROP_MISC_PARENT (for
2026 generic parents), wxPG_PROP_CATEGORY (for categories), or
2027 wxPG_PROP_AGGREGATE (for derived property classes with private
2030 @remarks You generally do not need to call this function.
2032 void SetParentalType( int flag
)
2034 m_flags
&= ~(wxPG_PROP_PROPERTY
|wxPG_PROP_PARENTAL_FLAGS
);
2038 void SetValueToUnspecified()
2040 wxVariant val
; // Create NULL variant
2044 // Helper function (for wxPython bindings and such) for settings protected
2046 void SetValuePlain( wxVariant value
)
2051 #if wxUSE_VALIDATORS
2052 /** Sets wxValidator for a property*/
2053 void SetValidator( const wxValidator
& validator
)
2055 m_validator
= wxDynamicCast(validator
.Clone(),wxValidator
);
2058 /** Gets assignable version of property's validator. */
2059 wxValidator
* GetValidator() const
2063 return DoGetValidator();
2065 #endif // #if wxUSE_VALIDATORS
2068 /** Returns client data (void*) of a property.
2070 void* GetClientData() const
2072 return m_clientData
;
2075 /** Sets client data (void*) of a property.
2077 This untyped client data has to be deleted manually.
2079 void SetClientData( void* clientData
)
2081 m_clientData
= clientData
;
2084 /** Returns client object of a property.
2086 void SetClientObject(wxClientData
* clientObject
)
2088 delete m_clientObject
;
2089 m_clientObject
= clientObject
;
2092 /** Sets managed client object of a property.
2094 wxClientData
*GetClientObject() const { return m_clientObject
; }
2097 /** Sets new set of choices for property.
2100 This operation clears the property value.
2102 bool SetChoices( wxPGChoices
& choices
);
2104 /** Set max length of text in text editor.
2106 inline bool SetMaxLength( int maxLen
);
2108 /** Call with 'false' in OnSetValue to cancel value changes after all
2109 (ie. cancel 'true' returned by StringToValue() or IntToValue()).
2111 void SetWasModified( bool set
= true )
2113 if ( set
) m_flags
|= wxPG_PROP_WAS_MODIFIED
;
2114 else m_flags
&= ~wxPG_PROP_WAS_MODIFIED
;
2117 const wxString
& GetHelpString() const
2119 return m_helpString
;
2122 void ClearFlag( FlagType flag
) { m_flags
&= ~(flag
); }
2124 // Use, for example, to detect if item is inside collapsed section.
2125 bool IsSomeParent( wxPGProperty
* candidate_parent
) const;
2128 Adapts list variant into proper value using consecutive
2131 void AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const;
2133 #if wxPG_COMPATIBILITY_1_4
2135 Adds a private child property.
2137 @deprecated Use AddPrivateChild() instead.
2139 @see AddPrivateChild()
2141 wxDEPRECATED( void AddChild( wxPGProperty
* prop
) );
2145 Adds a private child property. If you use this instead of
2146 wxPropertyGridInterface::Insert() or
2147 wxPropertyGridInterface::AppendIn(), then property's parental
2148 type will automatically be set up to wxPG_PROP_AGGREGATE. In other
2149 words, all properties of this property will become private.
2151 void AddPrivateChild( wxPGProperty
* prop
);
2154 Appends a new child property.
2156 wxPGProperty
* AppendChild( wxPGProperty
* prop
)
2158 return InsertChild(-1, prop
);
2161 /** Returns height of children, recursively, and
2162 by taking expanded/collapsed status into account.
2164 iMax is used when finding property y-positions.
2166 int GetChildrenHeight( int lh
, int iMax
= -1 ) const;
2168 /** Returns number of child properties */
2169 unsigned int GetChildCount() const
2171 return (unsigned int) m_children
.size();
2174 /** Returns sub-property at index i. */
2175 wxPGProperty
* Item( unsigned int i
) const
2176 { return m_children
[i
]; }
2178 /** Returns last sub-property.
2180 wxPGProperty
* Last() const { return m_children
.back(); }
2182 /** Returns index of given child property. */
2183 int Index( const wxPGProperty
* p
) const;
2185 // Puts correct indexes to children
2186 void FixIndicesOfChildren( unsigned int starthere
= 0 );
2189 Converts image width into full image offset, with margins.
2191 int GetImageOffset( int imageWidth
) const;
2194 // Returns wxPropertyGridPageState in which this property resides.
2195 wxPropertyGridPageState
* GetParentState() const { return m_parentState
; }
2199 wxPGProperty
* GetItemAtY( unsigned int y
,
2201 unsigned int* nextItemY
) const;
2204 /** Returns property at given virtual y coordinate.
2206 wxPGProperty
* GetItemAtY( unsigned int y
) const;
2208 /** Returns (direct) child property with given name (or NULL if not found).
2210 wxPGProperty
* GetPropertyByName( const wxString
& name
) const;
2214 // Returns various display-related information for given column
2215 void GetDisplayInfo( unsigned int column
,
2219 const wxPGCell
** pCell
);
2221 static wxString
* sm_wxPG_LABEL
;
2223 /** This member is public so scripting language bindings
2224 wrapper code can access it freely.
2231 Sets property cell in fashion that reduces number of exclusive
2232 copies of cell data. Used when setting, for instance, same
2233 background colour for a number of properties.
2236 First column to affect.
2239 Last column to affect.
2242 Pre-prepared cell that is used for those which cell data
2243 before this matched unmodCellData.
2246 If unmodCellData did not match, valid cell data from this
2247 is merged into cell (usually generating new exclusive copy
2250 @param unmodCellData
2251 If cell's cell data matches this, its cell is now set to
2254 @param ignoreWithFlags
2255 Properties with any one of these flags are skipped.
2258 If @true, apply this operation recursively in child properties.
2260 void AdaptiveSetCell( unsigned int firstCol
,
2261 unsigned int lastCol
,
2262 const wxPGCell
& preparedCell
,
2263 const wxPGCell
& srcData
,
2264 wxPGCellData
* unmodCellData
,
2265 FlagType ignoreWithFlags
,
2269 Makes sure m_cells has size of column+1 (or more).
2271 void EnsureCells( unsigned int column
);
2273 /** Returns (direct) child property with given name (or NULL if not found),
2277 Start looking for the child at this index.
2280 Does not support scope (ie. Parent.Child notation).
2282 wxPGProperty
* GetPropertyByNameWH( const wxString
& name
,
2283 unsigned int hintIndex
) const;
2285 /** This is used by Insert etc. */
2286 void DoAddChild( wxPGProperty
* prop
,
2288 bool correct_mode
= true );
2290 void DoGenerateComposedValue( wxString
& text
,
2291 int argFlags
= wxPG_VALUE_IS_CURRENT
,
2292 const wxVariantList
* valueOverrides
= NULL
,
2293 wxPGHashMapS2S
* childResults
= NULL
) const;
2295 void DoSetName(const wxString
& str
) { m_name
= str
; }
2297 /** Deletes all sub-properties. */
2300 bool HasCell( unsigned int column
) const
2302 if ( m_cells
.size() > column
)
2307 void InitAfterAdded( wxPropertyGridPageState
* pageState
,
2308 wxPropertyGrid
* propgrid
);
2310 // Removes child property with given pointer. Does not delete it.
2311 void RemoveChild( wxPGProperty
* p
);
2313 void DoPreAddChild( int index
, wxPGProperty
* prop
);
2315 void SetParentState( wxPropertyGridPageState
* pstate
)
2316 { m_parentState
= pstate
; }
2318 // Call after fixed sub-properties added/removed after creation.
2319 // if oldSelInd >= 0 and < new max items, then selection is
2321 void SubPropsChanged( int oldSelInd
= -1 );
2323 int GetY2( int lh
) const;
2327 wxPGProperty
* m_parent
;
2328 wxPropertyGridPageState
* m_parentState
;
2330 wxClientData
* m_clientObject
;
2332 // Overrides editor returned by property class
2333 const wxPGEditor
* m_customEditor
;
2334 #if wxUSE_VALIDATORS
2335 // Editor is going to get this validator
2336 wxValidator
* m_validator
;
2338 // Show this in front of the value
2340 // TODO: Can bitmap be implemented with wxPGCell?
2341 wxBitmap
* m_valueBitmap
;
2344 wxPGAttributeStorage m_attributes
;
2345 wxArrayPGProperty m_children
;
2347 // Extended cell information
2348 wxVector
<wxPGCell
> m_cells
;
2350 // Choices shown in drop-down list of editor control.
2351 wxPGChoices m_choices
;
2353 // Help shown in statusbar or help box.
2354 wxString m_helpString
;
2356 // Index in parent's property array.
2357 unsigned int m_arrIndex
;
2359 // If not -1, then overrides m_value
2364 // Maximum length (mainly for string properties). Could be in some sort of
2365 // wxBaseStringProperty, but currently, for maximum flexibility and
2366 // compatibility, we'll stick it here. Anyway, we had 3 excess bytes to use
2367 // so short int will fit in just fine.
2370 // Root has 0, categories etc. at that level 1, etc.
2371 unsigned char m_depth
;
2373 // m_depthBgCol indicates width of background colour between margin and item
2374 // (essentially this is category's depth, if none then equals m_depth).
2375 unsigned char m_depthBgCol
;
2378 // Called in constructors.
2380 void Init( const wxString
& label
, const wxString
& name
);
2381 #endif // #ifndef SWIG
2384 // -----------------------------------------------------------------------
2387 // Property class declaration helper macros
2388 // (wxPGRootPropertyClass and wxPropertyCategory require this).
2391 #define WX_PG_DECLARE_DOGETEDITORCLASS \
2392 virtual const wxPGEditor* DoGetEditorClass() const;
2395 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
2397 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
2398 WX_PG_DECLARE_DOGETEDITORCLASS \
2401 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME)
2404 // Implements sans constructor function. Also, first arg is class name, not
2406 #define WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(PROPNAME,T,EDITOR) \
2407 const wxPGEditor* PROPNAME::DoGetEditorClass() const \
2409 return wxPGEditor_##EDITOR; \
2412 // -----------------------------------------------------------------------
2416 /** @class wxPGRootProperty
2418 Root parent property.
2420 class WXDLLIMPEXP_PROPGRID wxPGRootProperty
: public wxPGProperty
2423 WX_PG_DECLARE_PROPERTY_CLASS(wxPGRootProperty
)
2427 wxPGRootProperty( const wxString
& name
= wxS("<Root>") );
2428 virtual ~wxPGRootProperty();
2430 virtual bool StringToValue( wxVariant
&, const wxString
&, int ) const
2438 // -----------------------------------------------------------------------
2440 /** @class wxPropertyCategory
2442 Category (caption) property.
2444 class WXDLLIMPEXP_PROPGRID wxPropertyCategory
: public wxPGProperty
2446 friend class wxPropertyGrid
;
2447 friend class wxPropertyGridPageState
;
2448 WX_PG_DECLARE_PROPERTY_CLASS(wxPropertyCategory
)
2451 /** Default constructor is only used in special cases. */
2452 wxPropertyCategory();
2454 wxPropertyCategory( const wxString
& label
,
2455 const wxString
& name
= wxPG_LABEL
);
2456 ~wxPropertyCategory();
2458 int GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const;
2460 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
) const;
2463 void SetTextColIndex( unsigned int colInd
)
2464 { m_capFgColIndex
= (wxByte
) colInd
; }
2465 unsigned int GetTextColIndex() const
2466 { return (unsigned int) m_capFgColIndex
; }
2468 void CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
);
2470 int m_textExtent
; // pre-calculated length of text
2471 wxByte m_capFgColIndex
; // caption text colour index
2479 // -----------------------------------------------------------------------
2481 #endif // wxUSE_PROPGRID
2483 #endif // _WX_PROPGRID_PROPERTY_H_