1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgrid/property.h
3 // Purpose: wxPGProperty and related support classes
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PROPGRID_PROPERTY_H_
13 #define _WX_PROPGRID_PROPERTY_H_
17 #include "wx/propgrid/propgriddefs.h"
19 // -----------------------------------------------------------------------
21 #define wxNullProperty ((wxPGProperty*)NULL)
24 /** @class wxPGPaintData
26 Contains information relayed to property's OnCustomPaint.
30 /** wxPropertyGrid. */
31 const wxPropertyGrid
* m_parent
;
34 Normally -1, otherwise index to drop-down list item that has to be
39 /** Set to drawn width in OnCustomPaint (optional). */
43 In a measure item call, set this to the height of item at m_choiceItem
50 // space between vertical sides of a custom image
51 #define wxPG_CUSTOM_IMAGE_SPACINGY 1
53 // space between caption and selection rectangle,
54 #define wxPG_CAPRECTXMARGIN 2
56 // horizontally and vertically
57 #define wxPG_CAPRECTYMARGIN 1
60 /** @class wxPGCellRenderer
62 Base class for wxPropertyGrid cell renderers.
64 class WXDLLIMPEXP_PROPGRID wxPGCellRenderer
: public wxObjectRefData
69 : wxObjectRefData() { }
70 virtual ~wxPGCellRenderer() { }
75 // We are painting selected item
76 Selected
= 0x00010000,
78 // We are painting item in choice popup
79 ChoicePopup
= 0x00020000,
81 // We are rendering wxOwnerDrawnComboBox control
82 // (or other owner drawn control, but that is only
83 // officially supported one ATM).
86 // We are painting a disable property
87 Disabled
= 0x00080000,
89 // We are painting selected, disabled, or similar
90 // item that dictates fore- and background colours,
91 // overriding any cell values.
92 DontUseCellFgCol
= 0x00100000,
93 DontUseCellBgCol
= 0x00200000,
94 DontUseCellColours
= DontUseCellFgCol
|
99 Returns @true if rendered something in the foreground (text or
102 virtual bool Render( wxDC
& dc
,
104 const wxPropertyGrid
* propertyGrid
,
105 wxPGProperty
* property
,
108 int flags
) const = 0;
110 /** Returns size of the image in front of the editable area.
112 If property is NULL, then this call is for a custom value. In that case
113 the item is index to wxPropertyGrid's custom values.
115 virtual wxSize
GetImageSize( const wxPGProperty
* property
,
119 /** Paints property category selection rectangle.
121 virtual void DrawCaptionSelectionRect( wxDC
& dc
,
123 int w
, int h
) const;
125 /** Utility to draw vertically centered text.
127 void DrawText( wxDC
& dc
,
130 const wxString
& text
) const;
133 Utility to draw editor's value, or vertically aligned text if editor is
136 void DrawEditorValue( wxDC
& dc
, const wxRect
& rect
,
137 int xOffset
, const wxString
& text
,
138 wxPGProperty
* property
,
139 const wxPGEditor
* editor
) const;
141 /** Utility to render cell bitmap and set text colour plus bg brush
144 @return Returns image width, which, for instance, can be passed to
147 int PreDrawCell( wxDC
& dc
,
149 const wxPGCell
& cell
,
153 Utility to be called after drawing is done, to revert whatever
154 changes PreDrawCell() did.
157 Same as those passed to PreDrawCell().
159 void PostDrawCell( wxDC
& dc
,
160 const wxPropertyGrid
* propGrid
,
161 const wxPGCell
& cell
,
167 @class wxPGDefaultRenderer
169 Default cell renderer, that can handles the common
172 class WXDLLIMPEXP_PROPGRID wxPGDefaultRenderer
: public wxPGCellRenderer
175 virtual bool Render( wxDC
& dc
,
177 const wxPropertyGrid
* propertyGrid
,
178 wxPGProperty
* property
,
183 virtual wxSize
GetImageSize( const wxPGProperty
* property
,
191 class WXDLLIMPEXP_PROPGRID wxPGCellData
: public wxObjectRefData
193 friend class wxPGCell
;
197 void SetText( const wxString
& text
)
200 m_hasValidText
= true;
202 void SetBitmap( const wxBitmap
& bitmap
) { m_bitmap
= bitmap
; }
203 void SetFgCol( const wxColour
& col
) { m_fgCol
= col
; }
204 void SetBgCol( const wxColour
& col
) { m_bgCol
= col
; }
205 void SetFont( const wxFont
& font
) { m_font
= font
; }
208 virtual ~wxPGCellData() { }
216 // True if m_text is valid and specified
224 Base class for wxPropertyGrid cell information.
226 class WXDLLIMPEXP_PROPGRID wxPGCell
: public wxObject
230 wxPGCell(const wxPGCell
& other
)
235 wxPGCell( const wxString
& text
,
236 const wxBitmap
& bitmap
= wxNullBitmap
,
237 const wxColour
& fgCol
= wxNullColour
,
238 const wxColour
& bgCol
= wxNullColour
);
240 virtual ~wxPGCell() { }
242 wxPGCellData
* GetData()
244 return (wxPGCellData
*) m_refData
;
247 const wxPGCellData
* GetData() const
249 return (const wxPGCellData
*) m_refData
;
254 return (m_refData
&& GetData()->m_hasValidText
);
258 Sets empty but valid data to this cell object.
263 Merges valid data from srcCell into this.
265 void MergeFrom( const wxPGCell
& srcCell
);
267 void SetText( const wxString
& text
);
268 void SetBitmap( const wxBitmap
& bitmap
);
269 void SetFgCol( const wxColour
& col
);
272 Sets font of the cell.
274 @remarks Because wxPropertyGrid does not support rows of
275 different height, it makes little sense to change
276 size of the font. Therefore it is recommended
277 to use return value of wxPropertyGrid::GetFont()
278 or wxPropertyGrid::GetCaptionFont() as a basis
279 for the font that, after modifications, is passed
280 to this member function.
282 void SetFont( const wxFont
& font
);
284 void SetBgCol( const wxColour
& col
);
286 const wxString
& GetText() const { return GetData()->m_text
; }
287 const wxBitmap
& GetBitmap() const { return GetData()->m_bitmap
; }
288 const wxColour
& GetFgCol() const { return GetData()->m_fgCol
; }
291 Returns font of the cell. If no specific font is set for this
292 cell, then the font will be invalid.
294 const wxFont
& GetFont() const { return GetData()->m_font
; }
296 const wxColour
& GetBgCol() const { return GetData()->m_bgCol
; }
298 wxPGCell
& operator=( const wxPGCell
& other
)
300 if ( this != &other
)
308 virtual wxObjectRefData
*CreateRefData() const
309 { return new wxPGCellData(); }
311 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
314 // -----------------------------------------------------------------------
316 /** @class wxPGAttributeStorage
318 wxPGAttributeStorage is somewhat optimized storage for
319 key=variant pairs (ie. a map).
321 class WXDLLIMPEXP_PROPGRID wxPGAttributeStorage
324 wxPGAttributeStorage();
325 ~wxPGAttributeStorage();
327 void Set( const wxString
& name
, const wxVariant
& value
);
328 unsigned int GetCount() const { return (unsigned int) m_map
.size(); }
329 wxVariant
FindValue( const wxString
& name
) const
331 wxPGHashMapS2P::const_iterator it
= m_map
.find(name
);
332 if ( it
!= m_map
.end() )
334 wxVariantData
* data
= (wxVariantData
*) it
->second
;
336 return wxVariant(data
, it
->first
);
341 typedef wxPGHashMapS2P::const_iterator const_iterator
;
342 const_iterator
StartIteration() const
344 return m_map
.begin();
346 bool GetNext( const_iterator
& it
, wxVariant
& variant
) const
348 if ( it
== m_map
.end() )
351 wxVariantData
* data
= (wxVariantData
*) it
->second
;
353 variant
.SetData(data
);
354 variant
.SetName(it
->first
);
360 wxPGHashMapS2P m_map
;
364 // -----------------------------------------------------------------------
366 /** @section propgrid_propflags wxPGProperty Flags
370 enum wxPGPropertyFlags
373 /** Indicates bold font.
375 wxPG_PROP_MODIFIED
= 0x0001,
377 /** Disables ('greyed' text and editor does not activate) property.
379 wxPG_PROP_DISABLED
= 0x0002,
381 /** Hider button will hide this property.
383 wxPG_PROP_HIDDEN
= 0x0004,
385 /** This property has custom paint image just in front of its value.
386 If property only draws custom images into a popup list, then this
387 flag should not be set.
389 wxPG_PROP_CUSTOMIMAGE
= 0x0008,
391 /** Do not create text based editor for this property (but button-triggered
392 dialog and choice are ok).
394 wxPG_PROP_NOEDITOR
= 0x0010,
396 /** Property is collapsed, ie. it's children are hidden.
398 wxPG_PROP_COLLAPSED
= 0x0020,
401 If property is selected, then indicates that validation failed for pending
404 If property is not selected, then indicates that the the actual property
405 value has failed validation (NB: this behavior is not currently supported,
406 but may be used in future).
408 wxPG_PROP_INVALID_VALUE
= 0x0040,
412 /** Switched via SetWasModified(). Temporary flag - only used when
413 setting/changing property value.
415 wxPG_PROP_WAS_MODIFIED
= 0x0200,
418 If set, then child properties (if any) are private, and should be
419 "invisible" to the application.
421 wxPG_PROP_AGGREGATE
= 0x0400,
423 /** If set, then child properties (if any) are copies and should not
426 wxPG_PROP_CHILDREN_ARE_COPIES
= 0x0800,
429 Classifies this item as a non-category.
431 Used for faster item type identification.
433 wxPG_PROP_PROPERTY
= 0x1000,
436 Classifies this item as a category.
438 Used for faster item type identification.
440 wxPG_PROP_CATEGORY
= 0x2000,
442 /** Classifies this item as a property that has children, but is not aggregate
443 (ie children are not private).
445 wxPG_PROP_MISC_PARENT
= 0x4000,
447 /** Property is read-only. Editor is still created for wxTextCtrl-based
448 property editors. For others, editor is not usually created because
449 they do implement wxTE_READONLY style or equivalent.
451 wxPG_PROP_READONLY
= 0x8000,
454 // NB: FLAGS ABOVE 0x8000 CANNOT BE USED WITH PROPERTY ITERATORS
457 /** Property's value is composed from values of child properties.
459 This flag cannot be used with property iterators.
461 wxPG_PROP_COMPOSED_VALUE
= 0x00010000,
463 /** Common value of property is selectable in editor.
465 This flag cannot be used with property iterators.
467 wxPG_PROP_USES_COMMON_VALUE
= 0x00020000,
469 /** Property can be set to unspecified value via editor.
470 Currently, this applies to following properties:
471 - wxIntProperty, wxUIntProperty, wxFloatProperty, wxEditEnumProperty:
475 This flag cannot be used with property iterators.
477 wxPG_PROP_AUTO_UNSPECIFIED
= 0x00040000,
479 /** Indicates the bit useable by derived properties.
481 wxPG_PROP_CLASS_SPECIFIC_1
= 0x00080000,
483 /** Indicates the bit useable by derived properties.
485 wxPG_PROP_CLASS_SPECIFIC_2
= 0x00100000,
487 /** Indicates that the property is being deleted and should be ignored.
489 wxPG_PROP_BEING_DELETED
= 0x00200000
495 #define wxPG_PROP_MAX wxPG_PROP_AUTO_UNSPECIFIED
497 /** Property with children must have one of these set, otherwise iterators
498 will not work correctly.
499 Code should automatically take care of this, however.
501 #define wxPG_PROP_PARENTAL_FLAGS \
502 ((wxPGPropertyFlags)(wxPG_PROP_AGGREGATE | \
503 wxPG_PROP_CATEGORY | \
504 wxPG_PROP_MISC_PARENT))
509 // Combination of flags that can be stored by GetFlagsAsString
510 #define wxPG_STRING_STORED_FLAGS \
511 (wxPG_PROP_DISABLED|wxPG_PROP_HIDDEN|wxPG_PROP_NOEDITOR|wxPG_PROP_COLLAPSED)
513 // -----------------------------------------------------------------------
516 @section propgrid_property_attributes wxPropertyGrid Property Attribute
519 wxPGProperty::SetAttribute() and
520 wxPropertyGridInterface::SetPropertyAttribute() accept one of these as
521 attribute name argument.
523 You can use strings instead of constants. However, some of these
524 constants are redefined to use cached strings which may reduce
525 your binary size by some amount.
530 /** Set default value for property.
532 #define wxPG_ATTR_DEFAULT_VALUE wxS("DefaultValue")
534 /** Universal, int or double. Minimum value for numeric properties.
536 #define wxPG_ATTR_MIN wxS("Min")
538 /** Universal, int or double. Maximum value for numeric properties.
540 #define wxPG_ATTR_MAX wxS("Max")
542 /** Universal, string. When set, will be shown as text after the displayed
543 text value. Alternatively, if third column is enabled, text will be shown
544 there (for any type of property).
546 #define wxPG_ATTR_UNITS wxS("Units")
548 /** When set, will be shown as 'greyed' text in property's value cell when
549 the actual displayed value is blank.
551 #define wxPG_ATTR_HINT wxS("Hint")
553 #if wxPG_COMPATIBILITY_1_4
555 @deprecated Use "Hint" (wxPG_ATTR_HINT) instead.
557 #define wxPG_ATTR_INLINE_HELP wxS("InlineHelp")
560 /** Universal, wxArrayString. Set to enable auto-completion in any
561 wxTextCtrl-based property editor.
563 #define wxPG_ATTR_AUTOCOMPLETE wxS("AutoComplete")
565 /** wxBoolProperty and wxFlagsProperty specific. Value type is bool.
566 Default value is False.
568 When set to True, bool property will use check box instead of a
569 combo box as its editor control. If you set this attribute
570 for a wxFlagsProperty, it is automatically applied to child
573 #define wxPG_BOOL_USE_CHECKBOX wxS("UseCheckbox")
575 /** wxBoolProperty and wxFlagsProperty specific. Value type is bool.
576 Default value is False.
578 Set to True for the bool property to cycle value on double click
579 (instead of showing the popup listbox). If you set this attribute
580 for a wxFlagsProperty, it is automatically applied to child
583 #define wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING wxS("UseDClickCycling")
586 wxFloatProperty (and similar) specific, int, default -1.
588 Sets the (max) precision used when floating point value is rendered as
589 text. The default -1 means infinite precision.
591 #define wxPG_FLOAT_PRECISION wxS("Precision")
594 The text will be echoed as asterisks (wxTE_PASSWORD will be passed to
597 #define wxPG_STRING_PASSWORD wxS("Password")
599 /** Define base used by a wxUIntProperty. Valid constants are
600 wxPG_BASE_OCT, wxPG_BASE_DEC, wxPG_BASE_HEX and wxPG_BASE_HEXL
601 (lowercase characters).
603 #define wxPG_UINT_BASE wxS("Base")
605 /** Define prefix rendered to wxUIntProperty. Accepted constants
606 wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and wxPG_PREFIX_DOLLAR_SIGN.
607 <b>Note:</b> Only wxPG_PREFIX_NONE works with Decimal and Octal
610 #define wxPG_UINT_PREFIX wxS("Prefix")
613 wxFileProperty/wxImageFileProperty specific, wxChar*, default is
615 Sets the wildcard used in the triggered wxFileDialog. Format is the same.
617 #define wxPG_FILE_WILDCARD wxS("Wildcard")
619 /** wxFileProperty/wxImageFileProperty specific, int, default 1.
620 When 0, only the file name is shown (i.e. drive and directory are hidden).
622 #define wxPG_FILE_SHOW_FULL_PATH wxS("ShowFullPath")
624 /** Specific to wxFileProperty and derived properties, wxString, default empty.
625 If set, then the filename is shown relative to the given path string.
627 #define wxPG_FILE_SHOW_RELATIVE_PATH wxS("ShowRelativePath")
630 Specific to wxFileProperty and derived properties, wxString, default is
633 Sets the initial path of where to look for files.
635 #define wxPG_FILE_INITIAL_PATH wxS("InitialPath")
637 /** Specific to wxFileProperty and derivatives, wxString, default is empty.
638 Sets a specific title for the dir dialog.
640 #define wxPG_FILE_DIALOG_TITLE wxS("DialogTitle")
642 /** Specific to wxDirProperty, wxString, default is empty.
643 Sets a specific message for the dir dialog.
645 #define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage")
647 /** Sets displayed date format for wxDateProperty.
649 #define wxPG_DATE_FORMAT wxS("DateFormat")
651 /** Sets wxDatePickerCtrl window style used with wxDateProperty. Default
652 is wxDP_DEFAULT | wxDP_SHOWCENTURY.
654 #define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
656 /** SpinCtrl editor, int or double. How much number changes when button is
657 pressed (or up/down on keybard).
659 #define wxPG_ATTR_SPINCTRL_STEP wxS("Step")
661 /** SpinCtrl editor, bool. If true, value wraps at Min/Max.
663 #define wxPG_ATTR_SPINCTRL_WRAP wxS("Wrap")
666 wxMultiChoiceProperty, int.
667 If 0, no user strings allowed. If 1, user strings appear before list
668 strings. If 2, user strings appear after list string.
670 #define wxPG_ATTR_MULTICHOICE_USERSTRINGMODE wxS("UserStringMode")
673 wxColourProperty and its kind, int, default 1.
675 Setting this attribute to 0 hides custom colour from property's list of
678 #define wxPG_COLOUR_ALLOW_CUSTOM wxS("AllowCustom")
683 // Redefine attribute macros to use cached strings
684 #undef wxPG_ATTR_DEFAULT_VALUE
685 #define wxPG_ATTR_DEFAULT_VALUE wxPGGlobalVars->m_strDefaultValue
687 #define wxPG_ATTR_MIN wxPGGlobalVars->m_strMin
689 #define wxPG_ATTR_MAX wxPGGlobalVars->m_strMax
690 #undef wxPG_ATTR_UNITS
691 #define wxPG_ATTR_UNITS wxPGGlobalVars->m_strUnits
692 #undef wxPG_ATTR_HINT
693 #define wxPG_ATTR_HINT wxPGGlobalVars->m_strHint
694 #if wxPG_COMPATIBILITY_1_4
695 #undef wxPG_ATTR_INLINE_HELP
696 #define wxPG_ATTR_INLINE_HELP wxPGGlobalVars->m_strInlineHelp
699 // -----------------------------------------------------------------------
701 /** @class wxPGChoiceEntry
702 Data of a single wxPGChoices choice.
704 class WXDLLIMPEXP_PROPGRID wxPGChoiceEntry
: public wxPGCell
708 wxPGChoiceEntry(const wxPGChoiceEntry
& other
)
711 m_value
= other
.m_value
;
713 wxPGChoiceEntry( const wxString
& label
,
714 int value
= wxPG_INVALID_VALUE
)
715 : wxPGCell(), m_value(value
)
720 virtual ~wxPGChoiceEntry() { }
722 void SetValue( int value
) { m_value
= value
; }
723 int GetValue() const { return m_value
; }
725 wxPGChoiceEntry
& operator=( const wxPGChoiceEntry
& other
)
727 if ( this != &other
)
731 m_value
= other
.m_value
;
740 typedef void* wxPGChoicesId
;
742 class WXDLLIMPEXP_PROPGRID wxPGChoicesData
: public wxObjectRefData
744 friend class wxPGChoices
;
746 // Constructor sets m_refCount to 1.
749 void CopyDataFrom( wxPGChoicesData
* data
);
751 wxPGChoiceEntry
& Insert( int index
, const wxPGChoiceEntry
& item
);
753 // Delete all entries
756 unsigned int GetCount() const
758 return (unsigned int) m_items
.size();
761 const wxPGChoiceEntry
& Item( unsigned int i
) const
763 wxASSERT_MSG( i
< GetCount(), "invalid index" );
767 wxPGChoiceEntry
& Item( unsigned int i
)
769 wxASSERT_MSG( i
< GetCount(), "invalid index" );
774 wxVector
<wxPGChoiceEntry
> m_items
;
776 virtual ~wxPGChoicesData();
779 #define wxPGChoicesEmptyData ((wxPGChoicesData*)NULL)
782 /** @class wxPGChoices
784 Helper class for managing choices of wxPropertyGrid properties.
785 Each entry can have label, value, bitmap, text colour, and background
788 wxPGChoices uses reference counting, similar to other wxWidgets classes.
789 This means that assignment operator and copy constructor only copy the
790 reference and not the actual data. Use Copy() member function to create a
793 @remarks If you do not specify value for entry, index is used.
798 class WXDLLIMPEXP_PROPGRID wxPGChoices
801 typedef long ValArrItem
;
803 /** Default constructor. */
810 Copy constructor, uses reference counting. To create a real copy,
811 use Copy() member function instead.
813 wxPGChoices( const wxPGChoices
& a
)
815 if ( a
.m_data
!= wxPGChoicesEmptyData
)
829 Values for choices. If NULL, indexes are used.
831 wxPGChoices( const wxChar
* const* labels
, const long* values
= NULL
)
844 Values for choices. If empty, indexes are used.
846 wxPGChoices( const wxArrayString
& labels
,
847 const wxArrayInt
& values
= wxArrayInt() )
853 /** Simple interface constructor. */
854 wxPGChoices( wxPGChoicesData
* data
)
870 If did not have own copies, creates them now. If was empty, identical
871 to set except that creates copies.
874 Labels for added choices.
877 Values for added choices. If empty, relevant entry indexes are used.
879 void Add( const wxChar
* const* labels
, const ValArrItem
* values
= NULL
);
881 /** Version that works with wxArrayString and wxArrayInt. */
882 void Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
= wxArrayInt() );
885 Adds a single choice.
888 Label for added choice.
891 Value for added choice. If unspecified, index is used.
893 wxPGChoiceEntry
& Add( const wxString
& label
,
894 int value
= wxPG_INVALID_VALUE
);
896 /** Adds a single item, with bitmap. */
897 wxPGChoiceEntry
& Add( const wxString
& label
,
898 const wxBitmap
& bitmap
,
899 int value
= wxPG_INVALID_VALUE
);
901 /** Adds a single item with full entry information. */
902 wxPGChoiceEntry
& Add( const wxPGChoiceEntry
& entry
)
904 return Insert(entry
, -1);
907 /** Adds single item. */
908 wxPGChoiceEntry
& AddAsSorted( const wxString
& label
,
909 int value
= wxPG_INVALID_VALUE
);
912 Assigns choices data, using reference counting. To create a real copy,
913 use Copy() member function instead.
915 void Assign( const wxPGChoices
& a
)
917 AssignData(a
.m_data
);
920 void AssignData( wxPGChoicesData
* data
);
922 /** Delete all choices. */
926 Returns a real copy of the choices.
928 wxPGChoices
Copy() const
932 dst
.m_data
->CopyDataFrom(m_data
);
938 if ( m_data
== wxPGChoicesEmptyData
)
939 m_data
= new wxPGChoicesData();
942 /** Gets a unsigned number identifying this list. */
943 wxPGChoicesId
GetId() const { return (wxPGChoicesId
) m_data
; };
945 const wxString
& GetLabel( unsigned int ind
) const
947 return Item(ind
).GetText();
950 unsigned int GetCount () const
955 return m_data
->GetCount();
958 int GetValue( unsigned int ind
) const { return Item(ind
).GetValue(); }
960 /** Returns array of values matching the given strings. Unmatching strings
961 result in wxPG_INVALID_VALUE entry in array.
963 wxArrayInt
GetValuesForStrings( const wxArrayString
& strings
) const;
965 /** Returns array of indices matching given strings. Unmatching strings
966 are added to 'unmatched', if not NULL.
968 wxArrayInt
GetIndicesForStrings( const wxArrayString
& strings
,
969 wxArrayString
* unmatched
= NULL
) const;
971 int Index( const wxString
& str
) const;
972 int Index( int val
) const;
974 /** Inserts single item. */
975 wxPGChoiceEntry
& Insert( const wxString
& label
,
977 int value
= wxPG_INVALID_VALUE
);
979 /** Inserts a single item with full entry information. */
980 wxPGChoiceEntry
& Insert( const wxPGChoiceEntry
& entry
, int index
);
982 /** Returns false if this is a constant empty set of choices,
983 which should not be modified.
987 return ( m_data
!= wxPGChoicesEmptyData
);
990 const wxPGChoiceEntry
& Item( unsigned int i
) const
993 return m_data
->Item(i
);
996 wxPGChoiceEntry
& Item( unsigned int i
)
999 return m_data
->Item(i
);
1002 /** Removes count items starting at position nIndex. */
1003 void RemoveAt(size_t nIndex
, size_t count
= 1);
1005 /** Does not create copies for itself.
1008 void Set( const wxChar
* const* labels
, const long* values
= NULL
)
1014 /** Version that works with wxArrayString and wxArrayInt. */
1015 void Set( const wxArrayString
& labels
,
1016 const wxArrayInt
& values
= wxArrayInt() )
1025 // Creates exclusive copy of current choices
1026 void AllocExclusive();
1028 // Returns data, increases refcount.
1029 wxPGChoicesData
* GetData()
1031 wxASSERT( m_data
->GetRefCount() != -1 );
1036 // Returns plain data ptr - no refcounting stuff is done.
1037 wxPGChoicesData
* GetDataPtr() const { return m_data
; }
1039 // Changes ownership of data to you.
1040 wxPGChoicesData
* ExtractData()
1042 wxPGChoicesData
* data
= m_data
;
1043 m_data
= wxPGChoicesEmptyData
;
1047 wxArrayString
GetLabels() const;
1049 void operator= (const wxPGChoices
& a
)
1052 AssignData(a
.m_data
);
1055 wxPGChoiceEntry
& operator[](unsigned int i
)
1060 const wxPGChoiceEntry
& operator[](unsigned int i
) const
1066 wxPGChoicesData
* m_data
;
1072 // -----------------------------------------------------------------------
1074 /** @class wxPGProperty
1076 wxPGProperty is base class for all wxPropertyGrid properties.
1078 NB: Full class overview is now only present in
1079 interface/wx/propgrid/property.h.
1081 @library{wxpropgrid}
1084 class WXDLLIMPEXP_PROPGRID wxPGProperty
: public wxObject
1086 friend class wxPropertyGrid
;
1087 friend class wxPropertyGridInterface
;
1088 friend class wxPropertyGridPageState
;
1089 friend class wxPropertyGridPopulator
;
1090 friend class wxStringProperty
; // Proper "<composed>" support requires this
1092 DECLARE_ABSTRACT_CLASS(wxPGProperty
)
1094 typedef wxUint32 FlagType
;
1097 Default constructor.
1104 All non-abstract property classes should have a constructor with
1105 the same first two arguments as this one.
1107 wxPGProperty( const wxString
& label
, const wxString
& name
);
1111 It is customary for derived properties to implement this.
1113 virtual ~wxPGProperty();
1115 /** This virtual function is called after m_value has been set.
1118 - If m_value was set to Null variant (ie. unspecified value),
1119 OnSetValue() will not be called.
1120 - m_value may be of any variant type. Typically properties internally
1121 support only one variant type, and as such OnSetValue() provides a
1122 good opportunity to convert
1123 supported values into internal type.
1124 - Default implementation does nothing.
1126 virtual void OnSetValue();
1128 /** Override this to return something else than m_value as the value.
1130 virtual wxVariant
DoGetValue() const { return m_value
; }
1132 /** Implement this function in derived class to check the value.
1133 Return true if it is ok. Returning false prevents property change events
1137 - Default implementation always returns true.
1139 virtual bool ValidateValue( wxVariant
& value
,
1140 wxPGValidationInfo
& validationInfo
) const;
1143 Converts text into wxVariant value appropriate for this property.
1146 On function entry this is the old value (should not be wxNullVariant
1147 in normal cases). Translated value must be assigned back to it.
1150 Text to be translated into variant.
1153 If wxPG_FULL_VALUE is set, returns complete, storable value instead
1154 of displayable one (they may be different).
1155 If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of
1156 composite property string value (as generated by ValueToString()
1157 called with this same flag).
1159 @return Returns @true if resulting wxVariant value was different.
1161 @remarks Default implementation converts semicolon delimited tokens into
1162 child values. Only works for properties with children.
1164 You might want to take into account that m_value is Null variant
1165 if property value is unspecified (which is usually only case if
1166 you explicitly enabled that sort behavior).
1168 virtual bool StringToValue( wxVariant
& variant
,
1169 const wxString
& text
,
1170 int argFlags
= 0 ) const;
1173 Converts integer (possibly a choice selection) into wxVariant value
1174 appropriate for this property.
1177 On function entry this is the old value (should not be wxNullVariant
1178 in normal cases). Translated value must be assigned back to it.
1181 Integer to be translated into variant.
1184 If wxPG_FULL_VALUE is set, returns complete, storable value instead
1187 @return Returns @true if resulting wxVariant value was different.
1190 - If property is not supposed to use choice or spinctrl or other editor
1191 with int-based value, it is not necessary to implement this method.
1192 - Default implementation simply assign given int to m_value.
1193 - If property uses choice control, and displays a dialog on some choice
1194 items, then it is preferred to display that dialog in IntToValue
1196 - You might want to take into account that m_value is Null variant if
1197 property value is unspecified (which is usually only case if you
1198 explicitly enabled that sort behavior).
1200 virtual bool IntToValue( wxVariant
& value
,
1202 int argFlags
= 0 ) const;
1205 Converts property value into a text representation.
1208 Value to be converted.
1211 If 0 (default value), then displayed string is returned.
1212 If wxPG_FULL_VALUE is set, returns complete, storable string value
1213 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
1214 string value that must be editable in textctrl. If
1215 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
1216 display as a part of string property's composite text
1219 @remarks Default implementation calls GenerateComposedValue().
1221 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
1223 /** Converts string to a value, and if successful, calls SetValue() on it.
1224 Default behavior is to do nothing.
1226 String to get the value from.
1228 true if value was changed.
1230 bool SetValueFromString( const wxString
& text
, int flags
= wxPG_PROGRAMMATIC_VALUE
);
1232 /** Converts integer to a value, and if succesful, calls SetValue() on it.
1233 Default behavior is to do nothing.
1235 Int to get the value from.
1237 If has wxPG_FULL_VALUE, then the value given is a actual value and
1240 True if value was changed.
1242 bool SetValueFromInt( long value
, int flags
= 0 );
1245 Returns size of the custom painted image in front of property.
1247 This method must be overridden to return non-default value if
1248 OnCustomPaint is to be called.
1250 Normally -1, but can be an index to the property's list of items.
1252 - Default behavior is to return wxSize(0,0), which means no image.
1253 - Default image width or height is indicated with dimension -1.
1254 - You can also return wxPG_DEFAULT_IMAGE_SIZE, i.e. wxSize(-1, -1).
1256 virtual wxSize
OnMeasureImage( int item
= -1 ) const;
1259 Events received by editor widgets are processed here.
1261 Note that editor class usually processes most events. Some, such as
1262 button press events of TextCtrlAndButton class, can be handled here.
1263 Also, if custom handling for regular events is desired, then that can
1264 also be done (for example, wxSystemColourProperty custom handles
1265 wxEVT_COMMAND_CHOICE_SELECTED to display colour picker dialog when
1266 'custom' selection is made).
1268 If the event causes value to be changed, SetValueInEvent()
1269 should be called to set the new value.
1274 Should return true if any changes in value should be reported.
1276 If property uses choice control, and displays a dialog on some choice
1277 items, then it is preferred to display that dialog in IntToValue
1280 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
1281 wxWindow
* wnd_primary
,
1285 Called after value of a child property has been altered. Must return
1286 new value of the whole property (after any alterations warrented by
1289 Note that this function is usually called at the time that value of
1290 this property, or given child property, is still pending for change,
1291 and as such, result of GetValue() or m_value should not be relied
1294 Sample pseudo-code implementation:
1297 wxVariant MyProperty::ChildChanged( wxVariant& thisValue,
1299 wxVariant& childValue ) const
1301 // Acquire reference to actual type of data stored in variant
1302 // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros
1303 // were used to create the variant class).
1304 T& data = TFromVariant(thisValue);
1306 // Copy childValue into data.
1307 switch ( childIndex )
1310 data.SetSubProp1( childvalue.GetLong() );
1313 data.SetSubProp2( childvalue.GetString() );
1318 // Return altered data
1324 Value of this property. Changed value should be returned (in
1325 previous versions of wxPropertyGrid it was only necessary to
1326 write value back to this argument).
1328 Index of child changed (you can use Item(childIndex) to get
1331 (Pending) value of the child property.
1334 Modified value of the whole property.
1336 virtual wxVariant
ChildChanged( wxVariant
& thisValue
,
1338 wxVariant
& childValue
) const;
1340 /** Returns pointer to an instance of used editor.
1342 virtual const wxPGEditor
* DoGetEditorClass() const;
1344 /** Returns pointer to the wxValidator that should be used
1345 with the editor of this property (NULL for no validator).
1346 Setting validator explicitly via SetPropertyValidator
1349 In most situations, code like this should work well
1350 (macros are used to maintain one actual validator instance,
1351 so on the second call the function exits within the first
1356 wxValidator* wxMyPropertyClass::DoGetValidator () const
1358 WX_PG_DOGETVALIDATOR_ENTRY()
1360 wxMyValidator* validator = new wxMyValidator(...);
1362 ... prepare validator...
1364 WX_PG_DOGETVALIDATOR_EXIT(validator)
1370 You can get common filename validator by returning
1371 wxFileProperty::GetClassValidator(). wxDirProperty,
1372 for example, uses it.
1374 virtual wxValidator
* DoGetValidator () const;
1377 Override to paint an image in front of the property value text or
1378 drop-down list item (but only if wxPGProperty::OnMeasureImage is
1379 overridden as well).
1381 If property's OnMeasureImage() returns size that has height != 0 but
1382 less than row height ( < 0 has special meanings), wxPropertyGrid calls
1383 this method to draw a custom image in a limited area in front of the
1384 editor control or value text/graphics, and if control has drop-down
1385 list, then the image is drawn there as well (even in the case
1386 OnMeasureImage() returned higher height than row height).
1388 NOTE: Following applies when OnMeasureImage() returns a "flexible"
1389 height ( using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable
1390 height items: If rect.x is < 0, then this is a measure item call, which
1391 means that dc is invalid and only thing that should be done is to set
1392 paintdata.m_drawnHeight to the height of the image of item at index
1393 paintdata.m_choiceItem. This call may be done even as often as once
1394 every drop-down popup show.
1399 Box reserved for custom graphics. Includes surrounding rectangle,
1400 if any. If x is < 0, then this is a measure item call (see above).
1402 wxPGPaintData structure with much useful data.
1405 - You can actually exceed rect width, but if you do so then
1406 paintdata.m_drawnWidth must be set to the full width drawn in
1408 - Due to technical reasons, rect's height will be default even if
1409 custom height was reported during measure call.
1410 - Brush is guaranteed to be default background colour. It has been
1411 already used to clear the background of area being painted. It
1413 - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper
1414 colour) pen for drawing framing rectangle. It can be changed as
1417 @see ValueToString()
1419 virtual void OnCustomPaint( wxDC
& dc
,
1421 wxPGPaintData
& paintdata
);
1424 Returns used wxPGCellRenderer instance for given property column
1427 Default implementation returns editor's renderer for all columns.
1429 virtual wxPGCellRenderer
* GetCellRenderer( int column
) const;
1431 /** Returns which choice is currently selected. Only applies to properties
1434 Needs to reimplemented in derived class if property value does not
1435 map directly to a choice. Integer as index, bool, and string usually do.
1437 virtual int GetChoiceSelection() const;
1440 Refresh values of child properties.
1442 Automatically called after value is set.
1444 virtual void RefreshChildren();
1447 Reimplement this member function to add special handling for
1448 attributes of this property.
1450 @return Return @false to have the attribute automatically stored in
1451 m_attributes. Default implementation simply does that and
1454 @remarks To actually set property attribute values from the
1455 application, use wxPGProperty::SetAttribute() instead.
1457 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
1459 /** Returns value of an attribute.
1461 Override if custom handling of attributes is needed.
1463 Default implementation simply return NULL variant.
1465 virtual wxVariant
DoGetAttribute( const wxString
& name
) const;
1467 /** Returns instance of a new wxPGEditorDialogAdapter instance, which is
1468 used when user presses the (optional) button next to the editor control;
1470 Default implementation returns NULL (ie. no action is generated when
1473 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
1476 Called whenever validation has failed with given pending value.
1478 @remarks If you implement this in your custom property class, please
1479 remember to call the baser implementation as well, since they
1480 may use it to revert property into pre-change state.
1482 virtual void OnValidationFailure( wxVariant
& pendingValue
);
1484 /** Append a new choice to property's list of choices.
1486 int AddChoice( const wxString
& label
, int value
= wxPG_INVALID_VALUE
)
1488 return InsertChoice(label
, wxNOT_FOUND
, value
);
1492 Returns true if children of this property are component values (for
1493 instance, points size, face name, and is_underlined are component
1496 bool AreChildrenComponents() const
1498 if ( m_flags
& (wxPG_PROP_COMPOSED_VALUE
|wxPG_PROP_AGGREGATE
) )
1505 Deletes children of the property.
1507 void DeleteChildren();
1510 Removes entry from property's wxPGChoices and editor control (if it is
1513 If selected item is deleted, then the value is set to unspecified.
1515 void DeleteChoice( int index
);
1518 Call to enable or disable usage of common value (integer value that can
1519 be selected for properties instead of their normal values) for this
1522 Common values are disabled by the default for all properties.
1524 void EnableCommonValue( bool enable
= true )
1526 if ( enable
) SetFlag( wxPG_PROP_USES_COMMON_VALUE
);
1527 else ClearFlag( wxPG_PROP_USES_COMMON_VALUE
);
1531 Composes text from values of child properties.
1533 wxString
GenerateComposedValue() const
1536 DoGenerateComposedValue(s
);
1540 /** Returns property's label. */
1541 const wxString
& GetLabel() const { return m_label
; }
1543 /** Returns property's name with all (non-category, non-root) parents. */
1544 wxString
GetName() const;
1547 Returns property's base name (ie parent's name is not added in any
1550 const wxString
& GetBaseName() const { return m_name
; }
1552 /** Returns read-only reference to property's list of choices.
1554 const wxPGChoices
& GetChoices() const
1559 /** Returns coordinate to the top y of the property. Note that the
1560 position of scrollbars is not taken into account.
1564 wxVariant
GetValue() const
1566 return DoGetValue();
1569 /** Returns reference to the internal stored value. GetValue is preferred
1570 way to get the actual value, since GetValueRef ignores DoGetValue,
1571 which may override stored value.
1573 wxVariant
& GetValueRef()
1578 const wxVariant
& GetValueRef() const
1583 // Helper function (for wxPython bindings and such) for settings protected
1585 wxVariant
GetValuePlain() const
1590 /** Returns text representation of property's value.
1593 If 0 (default value), then displayed string is returned.
1594 If wxPG_FULL_VALUE is set, returns complete, storable string value
1595 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
1596 string value that must be editable in textctrl. If
1597 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
1598 display as a part of string property's composite text
1601 @remarks In older versions, this function used to be overridden to convert
1602 property's value into a string representation. This function is
1603 now handled by ValueToString(), and overriding this function now
1604 will result in run-time assertion failure.
1606 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
1608 /** Synonymous to GetValueAsString().
1610 @deprecated Use GetValueAsString() instead.
1612 @see GetValueAsString()
1614 wxDEPRECATED( wxString
GetValueString( int argFlags
= 0 ) const );
1617 Returns wxPGCell of given column.
1619 @remarks const version of this member function returns 'default'
1620 wxPGCell object if the property itself didn't hold
1623 const wxPGCell
& GetCell( unsigned int column
) const;
1626 Returns wxPGCell of given column, creating one if necessary.
1628 wxPGCell
& GetCell( unsigned int column
)
1630 return GetOrCreateCell(column
);
1634 Returns wxPGCell of given column, creating one if necessary.
1636 wxPGCell
& GetOrCreateCell( unsigned int column
);
1638 /** Return number of displayed common values for this property.
1640 int GetDisplayedCommonValueCount() const;
1642 wxString
GetDisplayedString() const
1644 return GetValueAsString(0);
1648 Returns property's hint text (shown in empty value cell).
1650 inline wxString
GetHintText() const;
1652 /** Returns property grid where property lies. */
1653 wxPropertyGrid
* GetGrid() const;
1655 /** Returns owner wxPropertyGrid, but only if one is currently on a page
1656 displaying this property. */
1657 wxPropertyGrid
* GetGridIfDisplayed() const;
1659 /** Returns highest level non-category, non-root parent. Useful when you
1660 have nested wxCustomProperties/wxParentProperties.
1662 Thus, if immediate parent is root or category, this will return the
1665 wxPGProperty
* GetMainParent() const;
1667 /** Return parent of property */
1668 wxPGProperty
* GetParent() const { return m_parent
; }
1670 /** Returns true if property has editable wxTextCtrl when selected.
1673 Altough disabled properties do not displayed editor, they still
1674 return True here as being disabled is considered a temporary
1675 condition (unlike being read-only or having limited editing enabled).
1677 bool IsTextEditable() const;
1679 bool IsValueUnspecified() const
1681 return m_value
.IsNull();
1685 Returns non-zero if property has given flag set.
1687 @see propgrid_propflags
1689 FlagType
HasFlag( wxPGPropertyFlags flag
) const
1691 return ( m_flags
& flag
);
1694 /** Returns comma-delimited string of property attributes.
1696 const wxPGAttributeStorage
& GetAttributes() const
1698 return m_attributes
;
1701 /** Returns m_attributes as list wxVariant.
1703 wxVariant
GetAttributesAsList() const;
1706 Returns property flags.
1708 FlagType
GetFlags() const
1713 const wxPGEditor
* GetEditorClass() const;
1715 wxString
GetValueType() const
1717 return m_value
.GetType();
1720 /** Returns editor used for given column. NULL for no editor.
1722 const wxPGEditor
* GetColumnEditor( int column
) const
1725 return GetEditorClass();
1730 /** Returns common value selected for this property. -1 for none.
1732 int GetCommonValue() const
1734 return m_commonValue
;
1737 /** Returns true if property has even one visible child.
1739 bool HasVisibleChildren() const;
1742 Use this member function to add independent (ie. regular) children to
1745 @return Inserted childProperty.
1747 @remarks wxPropertyGrid is not automatically refreshed by this
1750 @see AddPrivateChild()
1752 wxPGProperty
* InsertChild( int index
, wxPGProperty
* childProperty
);
1754 /** Inserts a new choice to property's list of choices.
1756 int InsertChoice( const wxString
& label
, int index
, int value
= wxPG_INVALID_VALUE
);
1759 Returns true if this property is actually a wxPropertyCategory.
1761 bool IsCategory() const { return HasFlag(wxPG_PROP_CATEGORY
)?true:false; }
1763 /** Returns true if this property is actually a wxRootProperty.
1765 bool IsRoot() const { return (m_parent
== NULL
); }
1767 /** Returns true if this is a sub-property. */
1768 bool IsSubProperty() const
1770 wxPGProperty
* parent
= (wxPGProperty
*)m_parent
;
1771 if ( parent
&& !parent
->IsCategory() )
1776 /** Returns last visible sub-property, recursively.
1778 const wxPGProperty
* GetLastVisibleSubItem() const;
1780 wxVariant
GetDefaultValue() const;
1782 int GetMaxLength() const
1784 return (int) m_maxLen
;
1788 Determines, recursively, if all children are not unspecified.
1791 Assumes members in this wxVariant list as pending
1794 bool AreAllChildrenSpecified( wxVariant
* pendingList
= NULL
) const;
1796 /** Updates composed values of parent non-category properties, recursively.
1797 Returns topmost property updated.
1800 - Must not call SetValue() (as can be called in it).
1802 wxPGProperty
* UpdateParentValues();
1804 /** Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
1806 bool UsesAutoUnspecified() const
1808 return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED
)?true:false;
1811 wxBitmap
* GetValueImage() const
1813 return m_valueBitmap
;
1816 wxVariant
GetAttribute( const wxString
& name
) const;
1819 Returns named attribute, as string, if found.
1821 Otherwise defVal is returned.
1823 wxString
GetAttribute( const wxString
& name
, const wxString
& defVal
) const;
1826 Returns named attribute, as long, if found.
1828 Otherwise defVal is returned.
1830 long GetAttributeAsLong( const wxString
& name
, long defVal
) const;
1833 Returns named attribute, as double, if found.
1835 Otherwise defVal is returned.
1837 double GetAttributeAsDouble( const wxString
& name
, double defVal
) const;
1839 unsigned int GetDepth() const { return (unsigned int)m_depth
; }
1841 /** Gets flags as a'|' delimited string. Note that flag names are not
1842 prepended with 'wxPG_PROP_'.
1844 String will only be made to include flags combined by this parameter.
1846 wxString
GetFlagsAsString( FlagType flagsMask
) const;
1848 /** Returns position in parent's array. */
1849 unsigned int GetIndexInParent() const
1851 return (unsigned int)m_arrIndex
;
1854 /** Hides or reveals the property.
1856 true for hide, false for reveal.
1858 By default changes are applied recursively. Set this paramter
1859 wxPG_DONT_RECURSE to prevent this.
1861 inline bool Hide( bool hide
, int flags
= wxPG_RECURSE
);
1863 bool IsExpanded() const
1864 { return (!(m_flags
& wxPG_PROP_COLLAPSED
) && GetChildCount()); }
1866 /** Returns true if all parents expanded.
1868 bool IsVisible() const;
1870 bool IsEnabled() const { return !(m_flags
& wxPG_PROP_DISABLED
); }
1872 /** If property's editor is created this forces its recreation.
1873 Useful in SetAttribute etc. Returns true if actually did anything.
1875 bool RecreateEditor();
1877 /** If property's editor is active, then update it's value.
1879 void RefreshEditor();
1881 /** Sets an attribute for this property.
1883 Text identifier of attribute. See @ref propgrid_property_attributes.
1887 void SetAttribute( const wxString
& name
, wxVariant value
);
1889 void SetAttributes( const wxPGAttributeStorage
& attributes
);
1892 Sets property's background colour.
1895 Background colour to use.
1898 Default is wxPG_RECURSE which causes colour to be set recursively.
1899 Omit this flag to only set colour for the property in question
1900 and not any of its children.
1902 void SetBackgroundColour( const wxColour
& colour
,
1903 int flags
= wxPG_RECURSE
);
1906 Sets property's text colour.
1912 Default is wxPG_RECURSE which causes colour to be set recursively.
1913 Omit this flag to only set colour for the property in question
1914 and not any of its children.
1916 void SetTextColour( const wxColour
& colour
,
1917 int flags
= wxPG_RECURSE
);
1919 /** Set default value of a property. Synonymous to
1922 SetAttribute("DefaultValue", value);
1925 void SetDefaultValue( wxVariant
& value
);
1927 /** Sets editor for a property.
1930 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1931 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full
1934 For custom editors, use pointer you received from
1935 wxPropertyGrid::RegisterEditorClass().
1937 void SetEditor( const wxPGEditor
* editor
)
1939 m_customEditor
= editor
;
1942 /** Sets editor for a property.
1944 inline void SetEditor( const wxString
& editorName
);
1947 Sets cell information for given column.
1949 void SetCell( int column
, const wxPGCell
& cell
);
1951 /** Sets common value selected for this property. -1 for none.
1953 void SetCommonValue( int commonValue
)
1955 m_commonValue
= commonValue
;
1958 /** Sets flags from a '|' delimited string. Note that flag names are not
1959 prepended with 'wxPG_PROP_'.
1961 void SetFlagsFromString( const wxString
& str
);
1963 /** Sets property's "is it modified?" flag. Affects children recursively.
1965 void SetModifiedStatus( bool modified
)
1967 SetFlagRecursively(wxPG_PROP_MODIFIED
, modified
);
1970 /** Call in OnEvent(), OnButtonClick() etc. to change the property value
1971 based on user input.
1974 This method is const since it doesn't actually modify value, but posts
1975 given variant as pending value, stored in wxPropertyGrid.
1977 void SetValueInEvent( wxVariant value
) const;
1980 Call this to set value of the property.
1982 Unlike methods in wxPropertyGrid, this does not automatically update
1986 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run
1987 through validation process and send property change event.
1989 If you need to change property value in event, based on user input, use
1990 SetValueInEvent() instead.
1993 Pointer to list variant that contains child values. Used to
1994 indicate which children should be marked as modified.
1997 Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR, which is
1998 enabled by default).
2000 void SetValue( wxVariant value
, wxVariant
* pList
= NULL
,
2001 int flags
= wxPG_SETVAL_REFRESH_EDITOR
);
2003 /** Set wxBitmap in front of the value. This bitmap may be ignored
2004 by custom cell renderers.
2006 void SetValueImage( wxBitmap
& bmp
);
2008 /** Sets selected choice and changes property value.
2010 Tries to retain value type, although currently if it is not string,
2011 then it is forced to integer.
2013 void SetChoiceSelection( int newValue
);
2015 void SetExpanded( bool expanded
)
2017 if ( !expanded
) m_flags
|= wxPG_PROP_COLLAPSED
;
2018 else m_flags
&= ~wxPG_PROP_COLLAPSED
;
2022 Sets given property flag.
2024 @see propgrid_propflags
2026 void SetFlag( wxPGPropertyFlags flag
)
2029 // NB: While using wxPGPropertyFlags here makes it difficult to
2030 // combine different flags, it usefully prevents user from
2031 // using incorrect flags (say, wxWindow styles).
2036 Sets or clears given property flag.
2038 @see propgrid_propflags
2040 void ChangeFlag( wxPGPropertyFlags flag
, bool set
)
2049 Sets or clears given property flag, recursively.
2051 @see propgrid_propflags
2053 void SetFlagRecursively( wxPGPropertyFlags flag
, bool set
);
2055 void SetHelpString( const wxString
& helpString
)
2057 m_helpString
= helpString
;
2060 void SetLabel( const wxString
& label
) { m_label
= label
; }
2062 void SetName( const wxString
& newName
);
2065 Changes what sort of parent this property is for its children.
2068 Use one of the following values: wxPG_PROP_MISC_PARENT (for
2069 generic parents), wxPG_PROP_CATEGORY (for categories), or
2070 wxPG_PROP_AGGREGATE (for derived property classes with private
2073 @remarks You generally do not need to call this function.
2075 void SetParentalType( int flag
)
2077 m_flags
&= ~(wxPG_PROP_PROPERTY
|wxPG_PROP_PARENTAL_FLAGS
);
2081 void SetValueToUnspecified()
2083 wxVariant val
; // Create NULL variant
2084 SetValue(val
, NULL
, wxPG_SETVAL_REFRESH_EDITOR
);
2087 // Helper function (for wxPython bindings and such) for settings protected
2089 void SetValuePlain( wxVariant value
)
2094 #if wxUSE_VALIDATORS
2095 /** Sets wxValidator for a property*/
2096 void SetValidator( const wxValidator
& validator
)
2098 m_validator
= wxDynamicCast(validator
.Clone(),wxValidator
);
2101 /** Gets assignable version of property's validator. */
2102 wxValidator
* GetValidator() const
2106 return DoGetValidator();
2108 #endif // wxUSE_VALIDATORS
2110 /** Returns client data (void*) of a property.
2112 void* GetClientData() const
2114 return m_clientData
;
2117 /** Sets client data (void*) of a property.
2119 This untyped client data has to be deleted manually.
2121 void SetClientData( void* clientData
)
2123 m_clientData
= clientData
;
2126 /** Returns client object of a property.
2128 void SetClientObject(wxClientData
* clientObject
)
2130 delete m_clientObject
;
2131 m_clientObject
= clientObject
;
2134 /** Sets managed client object of a property.
2136 wxClientData
*GetClientObject() const { return m_clientObject
; }
2139 Sets new set of choices for the property.
2141 @remarks This operation deselects the property and clears its
2144 bool SetChoices( wxPGChoices
& choices
);
2146 /** Set max length of text in text editor.
2148 inline bool SetMaxLength( int maxLen
);
2150 /** Call with 'false' in OnSetValue to cancel value changes after all
2151 (ie. cancel 'true' returned by StringToValue() or IntToValue()).
2153 void SetWasModified( bool set
= true )
2155 if ( set
) m_flags
|= wxPG_PROP_WAS_MODIFIED
;
2156 else m_flags
&= ~wxPG_PROP_WAS_MODIFIED
;
2159 const wxString
& GetHelpString() const
2161 return m_helpString
;
2164 void ClearFlag( FlagType flag
) { m_flags
&= ~(flag
); }
2166 // Use, for example, to detect if item is inside collapsed section.
2167 bool IsSomeParent( wxPGProperty
* candidate_parent
) const;
2170 Adapts list variant into proper value using consecutive
2173 void AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const;
2175 #if wxPG_COMPATIBILITY_1_4
2177 Adds a private child property.
2179 @deprecated Use AddPrivateChild() instead.
2181 @see AddPrivateChild()
2183 wxDEPRECATED( void AddChild( wxPGProperty
* prop
) );
2187 Adds a private child property. If you use this instead of
2188 wxPropertyGridInterface::Insert() or
2189 wxPropertyGridInterface::AppendIn(), then property's parental
2190 type will automatically be set up to wxPG_PROP_AGGREGATE. In other
2191 words, all properties of this property will become private.
2193 void AddPrivateChild( wxPGProperty
* prop
);
2196 Appends a new child property.
2198 wxPGProperty
* AppendChild( wxPGProperty
* prop
)
2200 return InsertChild(-1, prop
);
2203 /** Returns height of children, recursively, and
2204 by taking expanded/collapsed status into account.
2206 iMax is used when finding property y-positions.
2208 int GetChildrenHeight( int lh
, int iMax
= -1 ) const;
2210 /** Returns number of child properties */
2211 unsigned int GetChildCount() const
2213 return (unsigned int) m_children
.size();
2216 /** Returns sub-property at index i. */
2217 wxPGProperty
* Item( unsigned int i
) const
2218 { return m_children
[i
]; }
2220 /** Returns last sub-property.
2222 wxPGProperty
* Last() const { return m_children
.back(); }
2224 /** Returns index of given child property. */
2225 int Index( const wxPGProperty
* p
) const;
2227 // Puts correct indexes to children
2228 void FixIndicesOfChildren( unsigned int starthere
= 0 );
2231 Converts image width into full image offset, with margins.
2233 int GetImageOffset( int imageWidth
) const;
2235 // Returns wxPropertyGridPageState in which this property resides.
2236 wxPropertyGridPageState
* GetParentState() const { return m_parentState
; }
2238 wxPGProperty
* GetItemAtY( unsigned int y
,
2240 unsigned int* nextItemY
) const;
2242 /** Returns property at given virtual y coordinate.
2244 wxPGProperty
* GetItemAtY( unsigned int y
) const;
2246 /** Returns (direct) child property with given name (or NULL if not found).
2248 wxPGProperty
* GetPropertyByName( const wxString
& name
) const;
2250 // Returns various display-related information for given column
2251 void GetDisplayInfo( unsigned int column
,
2255 const wxPGCell
** pCell
);
2257 static wxString
* sm_wxPG_LABEL
;
2259 /** This member is public so scripting language bindings
2260 wrapper code can access it freely.
2267 Sets property cell in fashion that reduces number of exclusive
2268 copies of cell data. Used when setting, for instance, same
2269 background colour for a number of properties.
2272 First column to affect.
2275 Last column to affect.
2278 Pre-prepared cell that is used for those which cell data
2279 before this matched unmodCellData.
2282 If unmodCellData did not match, valid cell data from this
2283 is merged into cell (usually generating new exclusive copy
2286 @param unmodCellData
2287 If cell's cell data matches this, its cell is now set to
2290 @param ignoreWithFlags
2291 Properties with any one of these flags are skipped.
2294 If @true, apply this operation recursively in child properties.
2296 void AdaptiveSetCell( unsigned int firstCol
,
2297 unsigned int lastCol
,
2298 const wxPGCell
& preparedCell
,
2299 const wxPGCell
& srcData
,
2300 wxPGCellData
* unmodCellData
,
2301 FlagType ignoreWithFlags
,
2305 Makes sure m_cells has size of column+1 (or more).
2307 void EnsureCells( unsigned int column
);
2309 /** Returns (direct) child property with given name (or NULL if not found),
2313 Start looking for the child at this index.
2316 Does not support scope (ie. Parent.Child notation).
2318 wxPGProperty
* GetPropertyByNameWH( const wxString
& name
,
2319 unsigned int hintIndex
) const;
2321 /** This is used by Insert etc. */
2322 void DoAddChild( wxPGProperty
* prop
,
2324 bool correct_mode
= true );
2326 void DoGenerateComposedValue( wxString
& text
,
2327 int argFlags
= wxPG_VALUE_IS_CURRENT
,
2328 const wxVariantList
* valueOverrides
= NULL
,
2329 wxPGHashMapS2S
* childResults
= NULL
) const;
2331 void DoSetName(const wxString
& str
) { m_name
= str
; }
2333 /** Deletes all sub-properties. */
2336 bool HasCell( unsigned int column
) const
2338 if ( m_cells
.size() > column
)
2343 void InitAfterAdded( wxPropertyGridPageState
* pageState
,
2344 wxPropertyGrid
* propgrid
);
2346 // Removes child property with given pointer. Does not delete it.
2347 void RemoveChild( wxPGProperty
* p
);
2349 void DoPreAddChild( int index
, wxPGProperty
* prop
);
2351 void SetParentState( wxPropertyGridPageState
* pstate
)
2352 { m_parentState
= pstate
; }
2354 // Call after fixed sub-properties added/removed after creation.
2355 // if oldSelInd >= 0 and < new max items, then selection is
2357 void SubPropsChanged( int oldSelInd
= -1 );
2359 int GetY2( int lh
) const;
2363 wxPGProperty
* m_parent
;
2364 wxPropertyGridPageState
* m_parentState
;
2366 wxClientData
* m_clientObject
;
2368 // Overrides editor returned by property class
2369 const wxPGEditor
* m_customEditor
;
2370 #if wxUSE_VALIDATORS
2371 // Editor is going to get this validator
2372 wxValidator
* m_validator
;
2374 // Show this in front of the value
2376 // TODO: Can bitmap be implemented with wxPGCell?
2377 wxBitmap
* m_valueBitmap
;
2380 wxPGAttributeStorage m_attributes
;
2381 wxArrayPGProperty m_children
;
2383 // Extended cell information
2384 wxVector
<wxPGCell
> m_cells
;
2386 // Choices shown in drop-down list of editor control.
2387 wxPGChoices m_choices
;
2389 // Help shown in statusbar or help box.
2390 wxString m_helpString
;
2392 // Index in parent's property array.
2393 unsigned int m_arrIndex
;
2395 // If not -1, then overrides m_value
2400 // Maximum length (mainly for string properties). Could be in some sort of
2401 // wxBaseStringProperty, but currently, for maximum flexibility and
2402 // compatibility, we'll stick it here. Anyway, we had 3 excess bytes to use
2403 // so short int will fit in just fine.
2406 // Root has 0, categories etc. at that level 1, etc.
2407 unsigned char m_depth
;
2409 // m_depthBgCol indicates width of background colour between margin and item
2410 // (essentially this is category's depth, if none then equals m_depth).
2411 unsigned char m_depthBgCol
;
2414 // Called in constructors.
2416 void Init( const wxString
& label
, const wxString
& name
);
2419 // -----------------------------------------------------------------------
2422 // Property class declaration helper macros
2423 // (wxPGRootPropertyClass and wxPropertyCategory require this).
2426 #define WX_PG_DECLARE_DOGETEDITORCLASS \
2427 virtual const wxPGEditor* DoGetEditorClass() const;
2429 #ifndef WX_PG_DECLARE_PROPERTY_CLASS
2430 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
2432 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
2433 WX_PG_DECLARE_DOGETEDITORCLASS \
2437 // Implements sans constructor function. Also, first arg is class name, not
2439 #define WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(PROPNAME,T,EDITOR) \
2440 const wxPGEditor* PROPNAME::DoGetEditorClass() const \
2442 return wxPGEditor_##EDITOR; \
2445 // -----------------------------------------------------------------------
2447 /** @class wxPGRootProperty
2449 Root parent property.
2451 class WXDLLIMPEXP_PROPGRID wxPGRootProperty
: public wxPGProperty
2454 WX_PG_DECLARE_PROPERTY_CLASS(wxPGRootProperty
)
2458 wxPGRootProperty( const wxString
& name
= wxS("<Root>") );
2459 virtual ~wxPGRootProperty();
2461 virtual bool StringToValue( wxVariant
&, const wxString
&, int ) const
2469 // -----------------------------------------------------------------------
2471 /** @class wxPropertyCategory
2473 Category (caption) property.
2475 class WXDLLIMPEXP_PROPGRID wxPropertyCategory
: public wxPGProperty
2477 friend class wxPropertyGrid
;
2478 friend class wxPropertyGridPageState
;
2479 WX_PG_DECLARE_PROPERTY_CLASS(wxPropertyCategory
)
2482 /** Default constructor is only used in special cases. */
2483 wxPropertyCategory();
2485 wxPropertyCategory( const wxString
& label
,
2486 const wxString
& name
= wxPG_LABEL
);
2487 ~wxPropertyCategory();
2489 int GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const;
2491 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
) const;
2492 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
2495 void SetTextColIndex( unsigned int colInd
)
2496 { m_capFgColIndex
= (wxByte
) colInd
; }
2497 unsigned int GetTextColIndex() const
2498 { return (unsigned int) m_capFgColIndex
; }
2500 void CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
);
2502 int m_textExtent
; // pre-calculated length of text
2503 wxByte m_capFgColIndex
; // caption text colour index
2509 // -----------------------------------------------------------------------
2511 #endif // wxUSE_PROPGRID
2513 #endif // _WX_PROPGRID_PROPERTY_H_