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
|
102 Returns @true if rendered something in the foreground (text or
105 virtual bool Render( wxDC
& dc
,
107 const wxPropertyGrid
* propertyGrid
,
108 wxPGProperty
* property
,
111 int flags
) const = 0;
113 /** Returns size of the image in front of the editable area.
115 If property is NULL, then this call is for a custom value. In that case
116 the item is index to wxPropertyGrid's custom values.
118 virtual wxSize
GetImageSize( const wxPGProperty
* property
,
122 /** Paints property category selection rectangle.
124 virtual void DrawCaptionSelectionRect( wxDC
& dc
,
126 int w
, int h
) const;
128 /** Utility to draw vertically centered text.
130 void DrawText( wxDC
& dc
,
133 const wxString
& text
) const;
136 Utility to draw editor's value, or vertically aligned text if editor is
139 void DrawEditorValue( wxDC
& dc
, const wxRect
& rect
,
140 int xOffset
, const wxString
& text
,
141 wxPGProperty
* property
,
142 const wxPGEditor
* editor
) const;
144 /** Utility to render cell bitmap and set text colour plus bg brush
147 @return Returns image width, which, for instance, can be passed to
150 int PreDrawCell( wxDC
& dc
,
152 const wxPGCell
& cell
,
156 Utility to be called after drawing is done, to revert whatever
157 changes PreDrawCell() did.
160 Same as those passed to PreDrawCell().
162 void PostDrawCell( wxDC
& dc
,
163 const wxPropertyGrid
* propGrid
,
164 const wxPGCell
& cell
,
170 @class wxPGDefaultRenderer
172 Default cell renderer, that can handles the common
175 class WXDLLIMPEXP_PROPGRID wxPGDefaultRenderer
: public wxPGCellRenderer
178 virtual bool Render( wxDC
& dc
,
180 const wxPropertyGrid
* propertyGrid
,
181 wxPGProperty
* property
,
186 virtual wxSize
GetImageSize( const wxPGProperty
* property
,
194 class WXDLLIMPEXP_PROPGRID wxPGCellData
: public wxObjectRefData
196 friend class wxPGCell
;
200 void SetText( const wxString
& text
)
203 m_hasValidText
= true;
205 void SetBitmap( const wxBitmap
& bitmap
) { m_bitmap
= bitmap
; }
206 void SetFgCol( const wxColour
& col
) { m_fgCol
= col
; }
207 void SetBgCol( const wxColour
& col
) { m_bgCol
= col
; }
208 void SetFont( const wxFont
& font
) { m_font
= font
; }
211 virtual ~wxPGCellData() { }
219 // True if m_text is valid and specified
228 Base class for wxPropertyGrid cell information.
230 class WXDLLIMPEXP_PROPGRID wxPGCell
: public wxObject
234 wxPGCell(const wxPGCell
& other
)
239 wxPGCell( const wxString
& text
,
240 const wxBitmap
& bitmap
= wxNullBitmap
,
241 const wxColour
& fgCol
= wxNullColour
,
242 const wxColour
& bgCol
= wxNullColour
);
244 virtual ~wxPGCell() { }
246 wxPGCellData
* GetData()
248 return (wxPGCellData
*) m_refData
;
251 const wxPGCellData
* GetData() const
253 return (const wxPGCellData
*) m_refData
;
258 return (m_refData
&& GetData()->m_hasValidText
);
262 Sets empty but valid data to this cell object.
267 Merges valid data from srcCell into this.
269 void MergeFrom( const wxPGCell
& srcCell
);
271 void SetText( const wxString
& text
);
272 void SetBitmap( const wxBitmap
& bitmap
);
273 void SetFgCol( const wxColour
& col
);
276 Sets font of the cell.
278 @remarks Because wxPropertyGrid does not support rows of
279 different height, it makes little sense to change
280 size of the font. Therefore it is recommended
281 to use return value of wxPropertyGrid::GetFont()
282 or wxPropertyGrid::GetCaptionFont() as a basis
283 for the font that, after modifications, is passed
284 to this member function.
286 void SetFont( const wxFont
& font
);
288 void SetBgCol( const wxColour
& col
);
290 const wxString
& GetText() const { return GetData()->m_text
; }
291 const wxBitmap
& GetBitmap() const { return GetData()->m_bitmap
; }
292 const wxColour
& GetFgCol() const { return GetData()->m_fgCol
; }
295 Returns font of the cell. If no specific font is set for this
296 cell, then the font will be invalid.
298 const wxFont
& GetFont() const { return GetData()->m_font
; }
300 const wxColour
& GetBgCol() const { return GetData()->m_bgCol
; }
302 wxPGCell
& operator=( const wxPGCell
& other
)
304 if ( this != &other
)
312 virtual wxObjectRefData
*CreateRefData() const
313 { return new wxPGCellData(); }
315 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
318 // -----------------------------------------------------------------------
322 /** @class wxPGAttributeStorage
324 wxPGAttributeStorage is somewhat optimized storage for
325 key=variant pairs (ie. a map).
327 class WXDLLIMPEXP_PROPGRID wxPGAttributeStorage
330 wxPGAttributeStorage();
331 ~wxPGAttributeStorage();
333 void Set( const wxString
& name
, const wxVariant
& value
);
334 unsigned int GetCount() const { return (unsigned int) m_map
.size(); }
335 wxVariant
FindValue( const wxString
& name
) const
337 wxPGHashMapS2P::const_iterator it
= m_map
.find(name
);
338 if ( it
!= m_map
.end() )
340 wxVariantData
* data
= (wxVariantData
*) it
->second
;
342 return wxVariant(data
, it
->first
);
347 typedef wxPGHashMapS2P::const_iterator const_iterator
;
348 const_iterator
StartIteration() const
350 return m_map
.begin();
352 bool GetNext( const_iterator
& it
, wxVariant
& variant
) const
354 if ( it
== m_map
.end() )
357 wxVariantData
* data
= (wxVariantData
*) it
->second
;
359 variant
.SetData(data
);
360 variant
.SetName(it
->first
);
366 wxPGHashMapS2P m_map
;
371 // -----------------------------------------------------------------------
373 /** @section propgrid_propflags wxPGProperty Flags
377 enum wxPG_PROPERTY_FLAGS
380 /** Indicates bold font.
382 wxPG_PROP_MODIFIED
= 0x0001,
384 /** Disables ('greyed' text and editor does not activate) property.
386 wxPG_PROP_DISABLED
= 0x0002,
388 /** Hider button will hide this property.
390 wxPG_PROP_HIDDEN
= 0x0004,
392 /** This property has custom paint image just in front of its value.
393 If property only draws custom images into a popup list, then this
394 flag should not be set.
396 wxPG_PROP_CUSTOMIMAGE
= 0x0008,
398 /** Do not create text based editor for this property (but button-triggered
399 dialog and choice are ok).
401 wxPG_PROP_NOEDITOR
= 0x0010,
403 /** Property is collapsed, ie. it's children are hidden.
405 wxPG_PROP_COLLAPSED
= 0x0020,
408 If property is selected, then indicates that validation failed for pending
411 If property is not selected, then indicates that the the actual property
412 value has failed validation (NB: this behavior is not currently supported,
413 but may be used in future).
415 wxPG_PROP_INVALID_VALUE
= 0x0040,
419 /** Switched via SetWasModified(). Temporary flag - only used when
420 setting/changing property value.
422 wxPG_PROP_WAS_MODIFIED
= 0x0200,
425 If set, then child properties (if any) are private, and should be
426 "invisible" to the application.
428 wxPG_PROP_AGGREGATE
= 0x0400,
430 /** If set, then child properties (if any) are copies and should not
433 wxPG_PROP_CHILDREN_ARE_COPIES
= 0x0800,
436 Classifies this item as a non-category.
438 Used for faster item type identification.
440 wxPG_PROP_PROPERTY
= 0x1000,
443 Classifies this item as a category.
445 Used for faster item type identification.
447 wxPG_PROP_CATEGORY
= 0x2000,
449 /** Classifies this item as a property that has children, but is not aggregate
450 (ie children are not private).
452 wxPG_PROP_MISC_PARENT
= 0x4000,
454 /** Property is read-only. Editor is still created for wxTextCtrl-based
455 property editors. For others, editor is not usually created because
456 they do implement wxTE_READONLY style or equivalent.
458 wxPG_PROP_READONLY
= 0x8000,
461 // NB: FLAGS ABOVE 0x8000 CANNOT BE USED WITH PROPERTY ITERATORS
464 /** Property's value is composed from values of child properties.
466 This flag cannot be used with property iterators.
468 wxPG_PROP_COMPOSED_VALUE
= 0x00010000,
470 /** Common value of property is selectable in editor.
472 This flag cannot be used with property iterators.
474 wxPG_PROP_USES_COMMON_VALUE
= 0x00020000,
476 /** Property can be set to unspecified value via editor.
477 Currently, this applies to following properties:
478 - wxIntProperty, wxUIntProperty, wxFloatProperty, wxEditEnumProperty:
482 This flag cannot be used with property iterators.
484 wxPG_PROP_AUTO_UNSPECIFIED
= 0x00040000,
486 /** Indicates the bit useable by derived properties.
488 wxPG_PROP_CLASS_SPECIFIC_1
= 0x00080000,
490 /** Indicates the bit useable by derived properties.
492 wxPG_PROP_CLASS_SPECIFIC_2
= 0x00100000,
494 /** Indicates that the property is being deleted and should be ignored.
496 wxPG_PROP_BEING_DELETED
= 0x00200000
502 #define wxPG_PROP_MAX wxPG_PROP_AUTO_UNSPECIFIED
504 /** Property with children must have one of these set, otherwise iterators
505 will not work correctly.
506 Code should automatically take care of this, however.
508 #define wxPG_PROP_PARENTAL_FLAGS \
509 (wxPG_PROP_AGGREGATE|wxPG_PROP_CATEGORY|wxPG_PROP_MISC_PARENT)
514 // Combination of flags that can be stored by GetFlagsAsString
515 #define wxPG_STRING_STORED_FLAGS \
516 (wxPG_PROP_DISABLED|wxPG_PROP_HIDDEN|wxPG_PROP_NOEDITOR|wxPG_PROP_COLLAPSED)
518 // -----------------------------------------------------------------------
523 @section propgrid_property_attributes wxPropertyGrid Property Attribute
526 wxPGProperty::SetAttribute() and
527 wxPropertyGridInterface::SetPropertyAttribute() accept one of these as
528 attribute name argument.
530 You can use strings instead of constants. However, some of these
531 constants are redefined to use cached strings which may reduce
532 your binary size by some amount.
537 /** Set default value for property.
539 #define wxPG_ATTR_DEFAULT_VALUE wxS("DefaultValue")
541 /** Universal, int or double. Minimum value for numeric properties.
543 #define wxPG_ATTR_MIN wxS("Min")
545 /** Universal, int or double. Maximum value for numeric properties.
547 #define wxPG_ATTR_MAX wxS("Max")
549 /** Universal, string. When set, will be shown as text after the displayed
550 text value. Alternatively, if third column is enabled, text will be shown
551 there (for any type of property).
553 #define wxPG_ATTR_UNITS wxS("Units")
555 /** When set, will be shown as 'greyed' text in property's value cell when
556 the actual displayed value is blank.
558 #define wxPG_ATTR_HINT wxS("Hint")
560 #if wxPG_COMPATIBILITY_1_4
562 @deprecated Use "Hint" (wxPG_ATTR_HINT) instead.
564 #define wxPG_ATTR_INLINE_HELP wxS("InlineHelp")
567 /** Universal, wxArrayString. Set to enable auto-completion in any
568 wxTextCtrl-based property editor.
570 #define wxPG_ATTR_AUTOCOMPLETE wxS("AutoComplete")
572 /** wxBoolProperty and wxFlagsProperty specific. Value type is bool.
573 Default value is False.
575 When set to True, bool property will use check box instead of a
576 combo box as its editor control. If you set this attribute
577 for a wxFlagsProperty, it is automatically applied to child
580 #define wxPG_BOOL_USE_CHECKBOX wxS("UseCheckbox")
582 /** wxBoolProperty and wxFlagsProperty specific. Value type is bool.
583 Default value is False.
585 Set to True for the bool property to cycle value on double click
586 (instead of showing the popup listbox). If you set this attribute
587 for a wxFlagsProperty, it is automatically applied to child
590 #define wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING wxS("UseDClickCycling")
593 wxFloatProperty (and similar) specific, int, default -1.
595 Sets the (max) precision used when floating point value is rendered as
596 text. The default -1 means infinite precision.
598 #define wxPG_FLOAT_PRECISION wxS("Precision")
601 The text will be echoed as asterisks (wxTE_PASSWORD will be passed to
604 #define wxPG_STRING_PASSWORD wxS("Password")
606 /** Define base used by a wxUIntProperty. Valid constants are
607 wxPG_BASE_OCT, wxPG_BASE_DEC, wxPG_BASE_HEX and wxPG_BASE_HEXL
608 (lowercase characters).
610 #define wxPG_UINT_BASE wxS("Base")
612 /** Define prefix rendered to wxUIntProperty. Accepted constants
613 wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and wxPG_PREFIX_DOLLAR_SIGN.
614 <b>Note:</b> Only wxPG_PREFIX_NONE works with Decimal and Octal
617 #define wxPG_UINT_PREFIX wxS("Prefix")
620 wxFileProperty/wxImageFileProperty specific, wxChar*, default is
622 Sets the wildcard used in the triggered wxFileDialog. Format is the same.
624 #define wxPG_FILE_WILDCARD wxS("Wildcard")
626 /** wxFileProperty/wxImageFileProperty specific, int, default 1.
627 When 0, only the file name is shown (i.e. drive and directory are hidden).
629 #define wxPG_FILE_SHOW_FULL_PATH wxS("ShowFullPath")
631 /** Specific to wxFileProperty and derived properties, wxString, default empty.
632 If set, then the filename is shown relative to the given path string.
634 #define wxPG_FILE_SHOW_RELATIVE_PATH wxS("ShowRelativePath")
637 Specific to wxFileProperty and derived properties, wxString, default is
640 Sets the initial path of where to look for files.
642 #define wxPG_FILE_INITIAL_PATH wxS("InitialPath")
644 /** Specific to wxFileProperty and derivatives, wxString, default is empty.
645 Sets a specific title for the dir dialog.
647 #define wxPG_FILE_DIALOG_TITLE wxS("DialogTitle")
649 /** Specific to wxDirProperty, wxString, default is empty.
650 Sets a specific message for the dir dialog.
652 #define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage")
654 /** Sets displayed date format for wxDateProperty.
656 #define wxPG_DATE_FORMAT wxS("DateFormat")
658 /** Sets wxDatePickerCtrl window style used with wxDateProperty. Default
659 is wxDP_DEFAULT | wxDP_SHOWCENTURY.
661 #define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
663 /** SpinCtrl editor, int or double. How much number changes when button is
664 pressed (or up/down on keybard).
666 #define wxPG_ATTR_SPINCTRL_STEP wxS("Step")
668 /** SpinCtrl editor, bool. If true, value wraps at Min/Max.
670 #define wxPG_ATTR_SPINCTRL_WRAP wxS("Wrap")
673 wxMultiChoiceProperty, int.
674 If 0, no user strings allowed. If 1, user strings appear before list
675 strings. If 2, user strings appear after list string.
677 #define wxPG_ATTR_MULTICHOICE_USERSTRINGMODE wxS("UserStringMode")
680 wxColourProperty and its kind, int, default 1.
682 Setting this attribute to 0 hides custom colour from property's list of
685 #define wxPG_COLOUR_ALLOW_CUSTOM wxS("AllowCustom")
690 // Redefine attribute macros to use cached strings
691 #undef wxPG_ATTR_DEFAULT_VALUE
692 #define wxPG_ATTR_DEFAULT_VALUE wxPGGlobalVars->m_strDefaultValue
694 #define wxPG_ATTR_MIN wxPGGlobalVars->m_strMin
696 #define wxPG_ATTR_MAX wxPGGlobalVars->m_strMax
697 #undef wxPG_ATTR_UNITS
698 #define wxPG_ATTR_UNITS wxPGGlobalVars->m_strUnits
699 #undef wxPG_ATTR_HINT
700 #define wxPG_ATTR_HINT wxPGGlobalVars->m_strHint
701 #if wxPG_COMPATIBILITY_1_4
702 #undef wxPG_ATTR_INLINE_HELP
703 #define wxPG_ATTR_INLINE_HELP wxPGGlobalVars->m_strInlineHelp
708 // -----------------------------------------------------------------------
712 /** @class wxPGChoiceEntry
713 Data of a single wxPGChoices choice.
715 class WXDLLIMPEXP_PROPGRID wxPGChoiceEntry
: public wxPGCell
719 wxPGChoiceEntry(const wxPGChoiceEntry
& other
)
722 m_value
= other
.m_value
;
724 wxPGChoiceEntry( const wxString
& label
,
725 int value
= wxPG_INVALID_VALUE
)
726 : wxPGCell(), m_value(value
)
731 virtual ~wxPGChoiceEntry() { }
733 void SetValue( int value
) { m_value
= value
; }
734 int GetValue() const { return m_value
; }
736 wxPGChoiceEntry
& operator=( const wxPGChoiceEntry
& other
)
738 if ( this != &other
)
742 m_value
= other
.m_value
;
751 typedef void* wxPGChoicesId
;
753 class WXDLLIMPEXP_PROPGRID wxPGChoicesData
: public wxObjectRefData
755 friend class wxPGChoices
;
757 // Constructor sets m_refCount to 1.
760 void CopyDataFrom( wxPGChoicesData
* data
);
762 wxPGChoiceEntry
& Insert( int index
, const wxPGChoiceEntry
& item
);
764 // Delete all entries
767 unsigned int GetCount() const
769 return (unsigned int) m_items
.size();
772 const wxPGChoiceEntry
& Item( unsigned int i
) const
774 wxASSERT_MSG( i
< GetCount(), "invalid index" );
778 wxPGChoiceEntry
& Item( unsigned int i
)
780 wxASSERT_MSG( i
< GetCount(), "invalid index" );
785 wxVector
<wxPGChoiceEntry
> m_items
;
787 virtual ~wxPGChoicesData();
790 #define wxPGChoicesEmptyData ((wxPGChoicesData*)NULL)
794 /** @class wxPGChoices
796 Helper class for managing choices of wxPropertyGrid properties.
797 Each entry can have label, value, bitmap, text colour, and background
800 wxPGChoices uses reference counting, similar to other wxWidgets classes.
801 This means that assignment operator and copy constructor only copy the
802 reference and not the actual data. Use Copy() member function to create a
805 @remarks If you do not specify value for entry, index is used.
810 class WXDLLIMPEXP_PROPGRID wxPGChoices
813 typedef long ValArrItem
;
815 /** Default constructor. */
822 Copy constructor, uses reference counting. To create a real copy,
823 use Copy() member function instead.
825 wxPGChoices( const wxPGChoices
& a
)
827 if ( a
.m_data
!= wxPGChoicesEmptyData
)
841 Values for choices. If NULL, indexes are used.
843 wxPGChoices( const wxChar
* const* labels
, const long* values
= NULL
)
856 Values for choices. If empty, indexes are used.
858 wxPGChoices( const wxArrayString
& labels
,
859 const wxArrayInt
& values
= wxArrayInt() )
865 /** Simple interface constructor. */
866 wxPGChoices( wxPGChoicesData
* data
)
882 If did not have own copies, creates them now. If was empty, identical
883 to set except that creates copies.
886 Labels for added choices.
889 Values for added choices. If empty, relevant entry indexes are used.
891 void Add( const wxChar
* const* labels
, const ValArrItem
* values
= NULL
);
893 /** Version that works with wxArrayString and wxArrayInt. */
894 void Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
= wxArrayInt() );
897 Adds a single choice.
900 Label for added choice.
903 Value for added choice. If unspecified, index is used.
905 wxPGChoiceEntry
& Add( const wxString
& label
,
906 int value
= wxPG_INVALID_VALUE
);
908 /** Adds a single item, with bitmap. */
909 wxPGChoiceEntry
& Add( const wxString
& label
,
910 const wxBitmap
& bitmap
,
911 int value
= wxPG_INVALID_VALUE
);
913 /** Adds a single item with full entry information. */
914 wxPGChoiceEntry
& Add( const wxPGChoiceEntry
& entry
)
916 return Insert(entry
, -1);
919 /** Adds single item. */
920 wxPGChoiceEntry
& AddAsSorted( const wxString
& label
,
921 int value
= wxPG_INVALID_VALUE
);
924 Assigns choices data, using reference counting. To create a real copy,
925 use Copy() member function instead.
927 void Assign( const wxPGChoices
& a
)
929 AssignData(a
.m_data
);
932 void AssignData( wxPGChoicesData
* data
);
934 /** Delete all choices. */
938 Returns a real copy of the choices.
940 wxPGChoices
Copy() const
944 dst
.m_data
->CopyDataFrom(m_data
);
950 if ( m_data
== wxPGChoicesEmptyData
)
951 m_data
= new wxPGChoicesData();
954 /** Gets a unsigned number identifying this list. */
955 wxPGChoicesId
GetId() const { return (wxPGChoicesId
) m_data
; };
957 const wxString
& GetLabel( unsigned int ind
) const
959 return Item(ind
).GetText();
962 unsigned int GetCount () const
967 return m_data
->GetCount();
970 int GetValue( unsigned int ind
) const { return Item(ind
).GetValue(); }
972 /** Returns array of values matching the given strings. Unmatching strings
973 result in wxPG_INVALID_VALUE entry in array.
975 wxArrayInt
GetValuesForStrings( const wxArrayString
& strings
) const;
977 /** Returns array of indices matching given strings. Unmatching strings
978 are added to 'unmatched', if not NULL.
980 wxArrayInt
GetIndicesForStrings( const wxArrayString
& strings
,
981 wxArrayString
* unmatched
= NULL
) const;
983 int Index( const wxString
& str
) const;
984 int Index( int val
) const;
986 /** Inserts single item. */
987 wxPGChoiceEntry
& Insert( const wxString
& label
,
989 int value
= wxPG_INVALID_VALUE
);
991 /** Inserts a single item with full entry information. */
992 wxPGChoiceEntry
& Insert( const wxPGChoiceEntry
& entry
, int index
);
994 /** Returns false if this is a constant empty set of choices,
995 which should not be modified.
999 return ( m_data
!= wxPGChoicesEmptyData
);
1002 const wxPGChoiceEntry
& Item( unsigned int i
) const
1005 return m_data
->Item(i
);
1008 wxPGChoiceEntry
& Item( unsigned int i
)
1011 return m_data
->Item(i
);
1014 /** Removes count items starting at position nIndex. */
1015 void RemoveAt(size_t nIndex
, size_t count
= 1);
1018 /** Does not create copies for itself. */
1019 void Set( const wxChar
* const* labels
, const long* values
= NULL
)
1026 /** Version that works with wxArrayString and wxArrayInt. */
1027 void Set( const wxArrayString
& labels
,
1028 const wxArrayInt
& values
= wxArrayInt() )
1037 // Creates exclusive copy of current choices
1038 void AllocExclusive();
1040 // Returns data, increases refcount.
1041 wxPGChoicesData
* GetData()
1043 wxASSERT( m_data
->GetRefCount() != -1 );
1048 // Returns plain data ptr - no refcounting stuff is done.
1049 wxPGChoicesData
* GetDataPtr() const { return m_data
; }
1051 // Changes ownership of data to you.
1052 wxPGChoicesData
* ExtractData()
1054 wxPGChoicesData
* data
= m_data
;
1055 m_data
= wxPGChoicesEmptyData
;
1059 wxArrayString
GetLabels() const;
1062 void operator= (const wxPGChoices
& a
)
1065 AssignData(a
.m_data
);
1068 wxPGChoiceEntry
& operator[](unsigned int i
)
1073 const wxPGChoiceEntry
& operator[](unsigned int i
) const
1079 wxPGChoicesData
* m_data
;
1086 // -----------------------------------------------------------------------
1088 /** @class wxPGProperty
1090 wxPGProperty is base class for all wxPropertyGrid properties.
1092 NB: Full class overview is now only present in
1093 interface/wx/propgrid/property.h.
1095 @library{wxpropgrid}
1098 class WXDLLIMPEXP_PROPGRID wxPGProperty
: public wxObject
1100 friend class wxPropertyGrid
;
1101 friend class wxPropertyGridInterface
;
1102 friend class wxPropertyGridPageState
;
1103 friend class wxPropertyGridPopulator
;
1104 friend class wxStringProperty
; // Proper "<composed>" support requires this
1106 DECLARE_ABSTRACT_CLASS(wxPGProperty
)
1108 typedef wxUint32 FlagType
;
1111 Default constructor.
1118 All non-abstract property classes should have a constructor with
1119 the same first two arguments as this one.
1121 wxPGProperty( const wxString
& label
, const wxString
& name
);
1125 It is customary for derived properties to implement this.
1127 virtual ~wxPGProperty();
1129 /** This virtual function is called after m_value has been set.
1132 - If m_value was set to Null variant (ie. unspecified value),
1133 OnSetValue() will not be called.
1134 - m_value may be of any variant type. Typically properties internally
1135 support only one variant type, and as such OnSetValue() provides a
1136 good opportunity to convert
1137 supported values into internal type.
1138 - Default implementation does nothing.
1140 virtual void OnSetValue();
1142 /** Override this to return something else than m_value as the value.
1144 virtual wxVariant
DoGetValue() const { return m_value
; }
1146 #if !defined(SWIG) || defined(CREATE_VCW)
1147 /** Implement this function in derived class to check the value.
1148 Return true if it is ok. Returning false prevents property change events
1152 - Default implementation always returns true.
1154 virtual bool ValidateValue( wxVariant
& value
,
1155 wxPGValidationInfo
& validationInfo
) const;
1158 Converts text into wxVariant value appropriate for this property.
1161 On function entry this is the old value (should not be wxNullVariant
1162 in normal cases). Translated value must be assigned back to it.
1165 Text to be translated into variant.
1168 If wxPG_FULL_VALUE is set, returns complete, storable value instead
1169 of displayable one (they may be different).
1170 If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of
1171 composite property string value (as generated by ValueToString()
1172 called with this same flag).
1174 @return Returns @true if resulting wxVariant value was different.
1176 @remarks Default implementation converts semicolon delimited tokens into
1177 child values. Only works for properties with children.
1179 You might want to take into account that m_value is Null variant
1180 if property value is unspecified (which is usually only case if
1181 you explicitly enabled that sort behavior).
1183 virtual bool StringToValue( wxVariant
& variant
,
1184 const wxString
& text
,
1185 int argFlags
= 0 ) const;
1188 Converts integer (possibly a choice selection) into wxVariant value
1189 appropriate for this property.
1192 On function entry this is the old value (should not be wxNullVariant
1193 in normal cases). Translated value must be assigned back to it.
1196 Integer to be translated into variant.
1199 If wxPG_FULL_VALUE is set, returns complete, storable value instead
1202 @return Returns @true if resulting wxVariant value was different.
1205 - If property is not supposed to use choice or spinctrl or other editor
1206 with int-based value, it is not necessary to implement this method.
1207 - Default implementation simply assign given int to m_value.
1208 - If property uses choice control, and displays a dialog on some choice
1209 items, then it is preferred to display that dialog in IntToValue
1211 - You might want to take into account that m_value is Null variant if
1212 property value is unspecified (which is usually only case if you
1213 explicitly enabled that sort behavior).
1215 virtual bool IntToValue( wxVariant
& value
,
1217 int argFlags
= 0 ) const;
1218 #endif // !defined(SWIG) || defined(CREATE_VCW)
1220 Converts property value into a text representation.
1223 Value to be converted.
1226 If 0 (default value), then displayed string is returned.
1227 If wxPG_FULL_VALUE is set, returns complete, storable string value
1228 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
1229 string value that must be editable in textctrl. If
1230 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
1231 display as a part of string property's composite text
1234 @remarks Default implementation calls GenerateComposedValue().
1236 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
1238 /** Converts string to a value, and if successful, calls SetValue() on it.
1239 Default behavior is to do nothing.
1241 String to get the value from.
1243 true if value was changed.
1245 bool SetValueFromString( const wxString
& text
, int flags
= wxPG_PROGRAMMATIC_VALUE
);
1247 /** Converts integer to a value, and if succesful, calls SetValue() on it.
1248 Default behavior is to do nothing.
1250 Int to get the value from.
1252 If has wxPG_FULL_VALUE, then the value given is a actual value and
1255 True if value was changed.
1257 bool SetValueFromInt( long value
, int flags
= 0 );
1260 Returns size of the custom painted image in front of property.
1262 This method must be overridden to return non-default value if
1263 OnCustomPaint is to be called.
1265 Normally -1, but can be an index to the property's list of items.
1267 - Default behavior is to return wxSize(0,0), which means no image.
1268 - Default image width or height is indicated with dimension -1.
1269 - You can also return wxPG_DEFAULT_IMAGE_SIZE, i.e. wxSize(-1, -1).
1271 virtual wxSize
OnMeasureImage( int item
= -1 ) const;
1274 Events received by editor widgets are processed here.
1276 Note that editor class usually processes most events. Some, such as
1277 button press events of TextCtrlAndButton class, can be handled here.
1278 Also, if custom handling for regular events is desired, then that can
1279 also be done (for example, wxSystemColourProperty custom handles
1280 wxEVT_COMMAND_CHOICE_SELECTED to display colour picker dialog when
1281 'custom' selection is made).
1283 If the event causes value to be changed, SetValueInEvent()
1284 should be called to set the new value.
1289 Should return true if any changes in value should be reported.
1291 If property uses choice control, and displays a dialog on some choice
1292 items, then it is preferred to display that dialog in IntToValue
1295 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
1296 wxWindow
* wnd_primary
,
1300 Called after value of a child property has been altered. Must return
1301 new value of the whole property (after any alterations warrented by
1304 Note that this function is usually called at the time that value of
1305 this property, or given child property, is still pending for change,
1306 and as such, result of GetValue() or m_value should not be relied
1309 Sample pseudo-code implementation:
1312 wxVariant MyProperty::ChildChanged( wxVariant& thisValue,
1314 wxVariant& childValue ) const
1316 // Acquire reference to actual type of data stored in variant
1317 // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros
1318 // were used to create the variant class).
1319 T& data = TFromVariant(thisValue);
1321 // Copy childValue into data.
1322 switch ( childIndex )
1325 data.SetSubProp1( childvalue.GetLong() );
1328 data.SetSubProp2( childvalue.GetString() );
1333 // Return altered data
1339 Value of this property. Changed value should be returned (in
1340 previous versions of wxPropertyGrid it was only necessary to
1341 write value back to this argument).
1343 Index of child changed (you can use Item(childIndex) to get
1346 (Pending) value of the child property.
1349 Modified value of the whole property.
1351 virtual wxVariant
ChildChanged( wxVariant
& thisValue
,
1353 wxVariant
& childValue
) const;
1355 /** Returns pointer to an instance of used editor.
1357 virtual const wxPGEditor
* DoGetEditorClass() const;
1359 /** Returns pointer to the wxValidator that should be used
1360 with the editor of this property (NULL for no validator).
1361 Setting validator explicitly via SetPropertyValidator
1364 In most situations, code like this should work well
1365 (macros are used to maintain one actual validator instance,
1366 so on the second call the function exits within the first
1371 wxValidator* wxMyPropertyClass::DoGetValidator () const
1373 WX_PG_DOGETVALIDATOR_ENTRY()
1375 wxMyValidator* validator = new wxMyValidator(...);
1377 ... prepare validator...
1379 WX_PG_DOGETVALIDATOR_EXIT(validator)
1385 You can get common filename validator by returning
1386 wxFileProperty::GetClassValidator(). wxDirProperty,
1387 for example, uses it.
1389 virtual wxValidator
* DoGetValidator () const;
1392 Override to paint an image in front of the property value text or
1393 drop-down list item (but only if wxPGProperty::OnMeasureImage is
1394 overridden as well).
1396 If property's OnMeasureImage() returns size that has height != 0 but
1397 less than row height ( < 0 has special meanings), wxPropertyGrid calls
1398 this method to draw a custom image in a limited area in front of the
1399 editor control or value text/graphics, and if control has drop-down
1400 list, then the image is drawn there as well (even in the case
1401 OnMeasureImage() returned higher height than row height).
1403 NOTE: Following applies when OnMeasureImage() returns a "flexible"
1404 height ( using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable
1405 height items: If rect.x is < 0, then this is a measure item call, which
1406 means that dc is invalid and only thing that should be done is to set
1407 paintdata.m_drawnHeight to the height of the image of item at index
1408 paintdata.m_choiceItem. This call may be done even as often as once
1409 every drop-down popup show.
1414 Box reserved for custom graphics. Includes surrounding rectangle,
1415 if any. If x is < 0, then this is a measure item call (see above).
1417 wxPGPaintData structure with much useful data.
1420 - You can actually exceed rect width, but if you do so then
1421 paintdata.m_drawnWidth must be set to the full width drawn in
1423 - Due to technical reasons, rect's height will be default even if
1424 custom height was reported during measure call.
1425 - Brush is guaranteed to be default background colour. It has been
1426 already used to clear the background of area being painted. It
1428 - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper
1429 colour) pen for drawing framing rectangle. It can be changed as
1432 @see ValueToString()
1434 virtual void OnCustomPaint( wxDC
& dc
,
1436 wxPGPaintData
& paintdata
);
1439 Returns used wxPGCellRenderer instance for given property column
1442 Default implementation returns editor's renderer for all columns.
1444 virtual wxPGCellRenderer
* GetCellRenderer( int column
) const;
1446 /** Returns which choice is currently selected. Only applies to properties
1449 Needs to reimplemented in derived class if property value does not
1450 map directly to a choice. Integer as index, bool, and string usually do.
1452 virtual int GetChoiceSelection() const;
1455 Refresh values of child properties.
1457 Automatically called after value is set.
1459 virtual void RefreshChildren();
1462 Reimplement this member function to add special handling for
1463 attributes of this property.
1465 @return Return @false to have the attribute automatically stored in
1466 m_attributes. Default implementation simply does that and
1469 @remarks To actually set property attribute values from the
1470 application, use wxPGProperty::SetAttribute() instead.
1472 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
1474 /** Returns value of an attribute.
1476 Override if custom handling of attributes is needed.
1478 Default implementation simply return NULL variant.
1480 virtual wxVariant
DoGetAttribute( const wxString
& name
) const;
1482 /** Returns instance of a new wxPGEditorDialogAdapter instance, which is
1483 used when user presses the (optional) button next to the editor control;
1485 Default implementation returns NULL (ie. no action is generated when
1488 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
1491 Called whenever validation has failed with given pending value.
1493 @remarks If you implement this in your custom property class, please
1494 remember to call the baser implementation as well, since they
1495 may use it to revert property into pre-change state.
1497 virtual void OnValidationFailure( wxVariant
& pendingValue
);
1499 /** Append a new choice to property's list of choices.
1501 int AddChoice( const wxString
& label
, int value
= wxPG_INVALID_VALUE
)
1503 return InsertChoice(label
, wxNOT_FOUND
, value
);
1507 Returns true if children of this property are component values (for
1508 instance, points size, face name, and is_underlined are component
1511 bool AreChildrenComponents() const
1513 if ( m_flags
& (wxPG_PROP_COMPOSED_VALUE
|wxPG_PROP_AGGREGATE
) )
1520 Deletes children of the property.
1522 void DeleteChildren();
1525 Removes entry from property's wxPGChoices and editor control (if it is
1528 If selected item is deleted, then the value is set to unspecified.
1530 void DeleteChoice( int index
);
1533 Call to enable or disable usage of common value (integer value that can
1534 be selected for properties instead of their normal values) for this
1537 Common values are disabled by the default for all properties.
1539 void EnableCommonValue( bool enable
= true )
1541 if ( enable
) SetFlag( wxPG_PROP_USES_COMMON_VALUE
);
1542 else ClearFlag( wxPG_PROP_USES_COMMON_VALUE
);
1546 Composes text from values of child properties.
1548 wxString
GenerateComposedValue() const
1551 DoGenerateComposedValue(s
);
1555 /** Returns property's label. */
1556 const wxString
& GetLabel() const { return m_label
; }
1558 /** Returns property's name with all (non-category, non-root) parents. */
1559 wxString
GetName() const;
1562 Returns property's base name (ie parent's name is not added in any
1565 const wxString
& GetBaseName() const { return m_name
; }
1567 /** Returns read-only reference to property's list of choices.
1569 const wxPGChoices
& GetChoices() const
1574 /** Returns coordinate to the top y of the property. Note that the
1575 position of scrollbars is not taken into account.
1579 wxVariant
GetValue() const
1581 return DoGetValue();
1584 /** Returns reference to the internal stored value. GetValue is preferred
1585 way to get the actual value, since GetValueRef ignores DoGetValue,
1586 which may override stored value.
1588 wxVariant
& GetValueRef()
1593 const wxVariant
& GetValueRef() const
1598 // Helper function (for wxPython bindings and such) for settings protected
1600 wxVariant
GetValuePlain() const
1605 /** Returns text representation of property's value.
1608 If 0 (default value), then displayed string is returned.
1609 If wxPG_FULL_VALUE is set, returns complete, storable string value
1610 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
1611 string value that must be editable in textctrl. If
1612 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
1613 display as a part of string property's composite text
1616 @remarks In older versions, this function used to be overridden to convert
1617 property's value into a string representation. This function is
1618 now handled by ValueToString(), and overriding this function now
1619 will result in run-time assertion failure.
1621 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
1623 /** Synonymous to GetValueAsString().
1625 @deprecated Use GetValueAsString() instead.
1627 @see GetValueAsString()
1629 wxDEPRECATED( wxString
GetValueString( int argFlags
= 0 ) const );
1632 Returns wxPGCell of given column.
1634 @remarks const version of this member function returns 'default'
1635 wxPGCell object if the property itself didn't hold
1638 const wxPGCell
& GetCell( unsigned int column
) const;
1641 Returns wxPGCell of given column, creating one if necessary.
1643 wxPGCell
& GetCell( unsigned int column
)
1645 return GetOrCreateCell(column
);
1649 Returns wxPGCell of given column, creating one if necessary.
1651 wxPGCell
& GetOrCreateCell( unsigned int column
);
1653 /** Return number of displayed common values for this property.
1655 int GetDisplayedCommonValueCount() const;
1657 wxString
GetDisplayedString() const
1659 return GetValueAsString(0);
1663 Returns property's hint text (shown in empty value cell).
1665 inline wxString
GetHintText() const;
1667 /** Returns property grid where property lies. */
1668 wxPropertyGrid
* GetGrid() const;
1670 /** Returns owner wxPropertyGrid, but only if one is currently on a page
1671 displaying this property. */
1672 wxPropertyGrid
* GetGridIfDisplayed() const;
1674 /** Returns highest level non-category, non-root parent. Useful when you
1675 have nested wxCustomProperties/wxParentProperties.
1677 Thus, if immediate parent is root or category, this will return the
1680 wxPGProperty
* GetMainParent() const;
1682 /** Return parent of property */
1683 wxPGProperty
* GetParent() const { return m_parent
; }
1685 /** Returns true if property has editable wxTextCtrl when selected.
1688 Altough disabled properties do not displayed editor, they still
1689 return True here as being disabled is considered a temporary
1690 condition (unlike being read-only or having limited editing enabled).
1692 bool IsTextEditable() const;
1694 bool IsValueUnspecified() const
1696 return m_value
.IsNull();
1699 FlagType
HasFlag( FlagType flag
) const
1701 return ( m_flags
& flag
);
1704 /** Returns comma-delimited string of property attributes.
1706 const wxPGAttributeStorage
& GetAttributes() const
1708 return m_attributes
;
1711 /** Returns m_attributes as list wxVariant.
1713 wxVariant
GetAttributesAsList() const;
1715 FlagType
GetFlags() const
1720 const wxPGEditor
* GetEditorClass() const;
1722 wxString
GetValueType() const
1724 return m_value
.GetType();
1727 /** Returns editor used for given column. NULL for no editor.
1729 const wxPGEditor
* GetColumnEditor( int column
) const
1732 return GetEditorClass();
1737 /** Returns common value selected for this property. -1 for none.
1739 int GetCommonValue() const
1741 return m_commonValue
;
1744 /** Returns true if property has even one visible child.
1746 bool HasVisibleChildren() const;
1749 Use this member function to add independent (ie. regular) children to
1752 @return Inserted childProperty.
1754 @remarks wxPropertyGrid is not automatically refreshed by this
1757 @see AddPrivateChild()
1759 wxPGProperty
* InsertChild( int index
, wxPGProperty
* childProperty
);
1761 /** Inserts a new choice to property's list of choices.
1763 int InsertChoice( const wxString
& label
, int index
, int value
= wxPG_INVALID_VALUE
);
1766 Returns true if this property is actually a wxPropertyCategory.
1768 bool IsCategory() const { return HasFlag(wxPG_PROP_CATEGORY
)?true:false; }
1770 /** Returns true if this property is actually a wxRootProperty.
1772 bool IsRoot() const { return (m_parent
== NULL
); }
1774 /** Returns true if this is a sub-property. */
1775 bool IsSubProperty() const
1777 wxPGProperty
* parent
= (wxPGProperty
*)m_parent
;
1778 if ( parent
&& !parent
->IsCategory() )
1783 /** Returns last visible sub-property, recursively.
1785 const wxPGProperty
* GetLastVisibleSubItem() const;
1787 wxVariant
GetDefaultValue() const;
1789 int GetMaxLength() const
1791 return (int) m_maxLen
;
1795 Determines, recursively, if all children are not unspecified.
1798 Assumes members in this wxVariant list as pending
1801 bool AreAllChildrenSpecified( wxVariant
* pendingList
= NULL
) const;
1803 /** Updates composed values of parent non-category properties, recursively.
1804 Returns topmost property updated.
1807 - Must not call SetValue() (as can be called in it).
1809 wxPGProperty
* UpdateParentValues();
1811 /** Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
1813 bool UsesAutoUnspecified() const
1815 return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED
)?true:false;
1818 wxBitmap
* GetValueImage() const
1820 return m_valueBitmap
;
1823 wxVariant
GetAttribute( const wxString
& name
) const;
1826 Returns named attribute, as string, if found.
1828 Otherwise defVal is returned.
1830 wxString
GetAttribute( const wxString
& name
, const wxString
& defVal
) const;
1833 Returns named attribute, as long, if found.
1835 Otherwise defVal is returned.
1837 long GetAttributeAsLong( const wxString
& name
, long defVal
) const;
1840 Returns named attribute, as double, if found.
1842 Otherwise defVal is returned.
1844 double GetAttributeAsDouble( const wxString
& name
, double defVal
) const;
1846 unsigned int GetDepth() const { return (unsigned int)m_depth
; }
1848 /** Gets flags as a'|' delimited string. Note that flag names are not
1849 prepended with 'wxPG_PROP_'.
1851 String will only be made to include flags combined by this parameter.
1853 wxString
GetFlagsAsString( FlagType flagsMask
) const;
1855 /** Returns position in parent's array. */
1856 unsigned int GetIndexInParent() const
1858 return (unsigned int)m_arrIndex
;
1861 /** Hides or reveals the property.
1863 true for hide, false for reveal.
1865 By default changes are applied recursively. Set this paramter
1866 wxPG_DONT_RECURSE to prevent this.
1868 inline bool Hide( bool hide
, int flags
= wxPG_RECURSE
);
1870 bool IsExpanded() const
1871 { return (!(m_flags
& wxPG_PROP_COLLAPSED
) && GetChildCount()); }
1873 /** Returns true if all parents expanded.
1875 bool IsVisible() const;
1877 bool IsEnabled() const { return !(m_flags
& wxPG_PROP_DISABLED
); }
1879 /** If property's editor is created this forces its recreation.
1880 Useful in SetAttribute etc. Returns true if actually did anything.
1882 bool RecreateEditor();
1884 /** If property's editor is active, then update it's value.
1886 void RefreshEditor();
1888 /** Sets an attribute for this property.
1890 Text identifier of attribute. See @ref propgrid_property_attributes.
1894 void SetAttribute( const wxString
& name
, wxVariant value
);
1896 void SetAttributes( const wxPGAttributeStorage
& attributes
);
1899 Sets property's background colour.
1902 Background colour to use.
1905 Default is wxPG_RECURSE which causes colour to be set recursively.
1906 Omit this flag to only set colour for the property in question
1907 and not any of its children.
1909 void SetBackgroundColour( const wxColour
& colour
,
1910 int flags
= wxPG_RECURSE
);
1913 Sets property's text colour.
1919 Default is wxPG_RECURSE which causes colour to be set recursively.
1920 Omit this flag to only set colour for the property in question
1921 and not any of its children.
1923 void SetTextColour( const wxColour
& colour
,
1924 int flags
= wxPG_RECURSE
);
1926 /** Set default value of a property. Synonymous to
1929 SetAttribute("DefaultValue", value);
1932 void SetDefaultValue( wxVariant
& value
);
1935 /** Sets editor for a property.
1938 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1939 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full
1942 For custom editors, use pointer you received from
1943 wxPropertyGrid::RegisterEditorClass().
1945 void SetEditor( const wxPGEditor
* editor
)
1947 m_customEditor
= editor
;
1951 /** Sets editor for a property.
1953 inline void SetEditor( const wxString
& editorName
);
1956 Sets cell information for given column.
1958 void SetCell( int column
, const wxPGCell
& cell
);
1960 /** Sets common value selected for this property. -1 for none.
1962 void SetCommonValue( int commonValue
)
1964 m_commonValue
= commonValue
;
1967 /** Sets flags from a '|' delimited string. Note that flag names are not
1968 prepended with 'wxPG_PROP_'.
1970 void SetFlagsFromString( const wxString
& str
);
1972 /** Sets property's "is it modified?" flag. Affects children recursively.
1974 void SetModifiedStatus( bool modified
)
1976 SetFlagRecursively(wxPG_PROP_MODIFIED
, modified
);
1979 /** Call in OnEvent(), OnButtonClick() etc. to change the property value
1980 based on user input.
1983 This method is const since it doesn't actually modify value, but posts
1984 given variant as pending value, stored in wxPropertyGrid.
1986 void SetValueInEvent( wxVariant value
) const;
1989 Call this to set value of the property.
1991 Unlike methods in wxPropertyGrid, this does not automatically update
1995 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run
1996 through validation process and send property change event.
1998 If you need to change property value in event, based on user input, use
1999 SetValueInEvent() instead.
2002 Pointer to list variant that contains child values. Used to
2003 indicate which children should be marked as modified.
2006 Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR, which is
2007 enabled by default).
2009 void SetValue( wxVariant value
, wxVariant
* pList
= NULL
,
2010 int flags
= wxPG_SETVAL_REFRESH_EDITOR
);
2012 /** Set wxBitmap in front of the value. This bitmap may be ignored
2013 by custom cell renderers.
2015 void SetValueImage( wxBitmap
& bmp
);
2017 /** Sets selected choice and changes property value.
2019 Tries to retain value type, although currently if it is not string,
2020 then it is forced to integer.
2022 void SetChoiceSelection( int newValue
);
2024 void SetExpanded( bool expanded
)
2026 if ( !expanded
) m_flags
|= wxPG_PROP_COLLAPSED
;
2027 else m_flags
&= ~wxPG_PROP_COLLAPSED
;
2031 Sets given property flag(s).
2033 void SetFlag( FlagType flag
) { m_flags
|= flag
; }
2036 Sets or clears given property flag(s).
2038 void ChangeFlag( FlagType flag
, bool set
)
2046 void SetFlagRecursively( FlagType flag
, bool set
);
2048 void SetHelpString( const wxString
& helpString
)
2050 m_helpString
= helpString
;
2053 void SetLabel( const wxString
& label
) { m_label
= label
; }
2055 void SetName( const wxString
& newName
);
2058 Changes what sort of parent this property is for its children.
2061 Use one of the following values: wxPG_PROP_MISC_PARENT (for
2062 generic parents), wxPG_PROP_CATEGORY (for categories), or
2063 wxPG_PROP_AGGREGATE (for derived property classes with private
2066 @remarks You generally do not need to call this function.
2068 void SetParentalType( int flag
)
2070 m_flags
&= ~(wxPG_PROP_PROPERTY
|wxPG_PROP_PARENTAL_FLAGS
);
2074 void SetValueToUnspecified()
2076 wxVariant val
; // Create NULL variant
2077 SetValue(val
, NULL
, wxPG_SETVAL_REFRESH_EDITOR
);
2080 // Helper function (for wxPython bindings and such) for settings protected
2082 void SetValuePlain( wxVariant value
)
2087 #if wxUSE_VALIDATORS
2088 /** Sets wxValidator for a property*/
2089 void SetValidator( const wxValidator
& validator
)
2091 m_validator
= wxDynamicCast(validator
.Clone(),wxValidator
);
2094 /** Gets assignable version of property's validator. */
2095 wxValidator
* GetValidator() const
2099 return DoGetValidator();
2101 #endif // wxUSE_VALIDATORS
2104 /** Returns client data (void*) of a property.
2106 void* GetClientData() const
2108 return m_clientData
;
2111 /** Sets client data (void*) of a property.
2113 This untyped client data has to be deleted manually.
2115 void SetClientData( void* clientData
)
2117 m_clientData
= clientData
;
2120 /** Returns client object of a property.
2122 void SetClientObject(wxClientData
* clientObject
)
2124 delete m_clientObject
;
2125 m_clientObject
= clientObject
;
2128 /** Sets managed client object of a property.
2130 wxClientData
*GetClientObject() const { return m_clientObject
; }
2133 /** Sets new set of choices for property.
2136 This operation clears the property value.
2138 bool SetChoices( wxPGChoices
& choices
);
2140 /** Set max length of text in text editor.
2142 inline bool SetMaxLength( int maxLen
);
2144 /** Call with 'false' in OnSetValue to cancel value changes after all
2145 (ie. cancel 'true' returned by StringToValue() or IntToValue()).
2147 void SetWasModified( bool set
= true )
2149 if ( set
) m_flags
|= wxPG_PROP_WAS_MODIFIED
;
2150 else m_flags
&= ~wxPG_PROP_WAS_MODIFIED
;
2153 const wxString
& GetHelpString() const
2155 return m_helpString
;
2158 void ClearFlag( FlagType flag
) { m_flags
&= ~(flag
); }
2160 // Use, for example, to detect if item is inside collapsed section.
2161 bool IsSomeParent( wxPGProperty
* candidate_parent
) const;
2164 Adapts list variant into proper value using consecutive
2167 void AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const;
2169 #if wxPG_COMPATIBILITY_1_4
2171 Adds a private child property.
2173 @deprecated Use AddPrivateChild() instead.
2175 @see AddPrivateChild()
2177 wxDEPRECATED( void AddChild( wxPGProperty
* prop
) );
2181 Adds a private child property. If you use this instead of
2182 wxPropertyGridInterface::Insert() or
2183 wxPropertyGridInterface::AppendIn(), then property's parental
2184 type will automatically be set up to wxPG_PROP_AGGREGATE. In other
2185 words, all properties of this property will become private.
2187 void AddPrivateChild( wxPGProperty
* prop
);
2190 Appends a new child property.
2192 wxPGProperty
* AppendChild( wxPGProperty
* prop
)
2194 return InsertChild(-1, prop
);
2197 /** Returns height of children, recursively, and
2198 by taking expanded/collapsed status into account.
2200 iMax is used when finding property y-positions.
2202 int GetChildrenHeight( int lh
, int iMax
= -1 ) const;
2204 /** Returns number of child properties */
2205 unsigned int GetChildCount() const
2207 return (unsigned int) m_children
.size();
2210 /** Returns sub-property at index i. */
2211 wxPGProperty
* Item( unsigned int i
) const
2212 { return m_children
[i
]; }
2214 /** Returns last sub-property.
2216 wxPGProperty
* Last() const { return m_children
.back(); }
2218 /** Returns index of given child property. */
2219 int Index( const wxPGProperty
* p
) const;
2221 // Puts correct indexes to children
2222 void FixIndicesOfChildren( unsigned int starthere
= 0 );
2225 Converts image width into full image offset, with margins.
2227 int GetImageOffset( int imageWidth
) const;
2230 // Returns wxPropertyGridPageState in which this property resides.
2231 wxPropertyGridPageState
* GetParentState() const { return m_parentState
; }
2235 wxPGProperty
* GetItemAtY( unsigned int y
,
2237 unsigned int* nextItemY
) const;
2240 /** Returns property at given virtual y coordinate.
2242 wxPGProperty
* GetItemAtY( unsigned int y
) const;
2244 /** Returns (direct) child property with given name (or NULL if not found).
2246 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
);
2417 #endif // #ifndef SWIG
2420 // -----------------------------------------------------------------------
2423 // Property class declaration helper macros
2424 // (wxPGRootPropertyClass and wxPropertyCategory require this).
2427 #define WX_PG_DECLARE_DOGETEDITORCLASS \
2428 virtual const wxPGEditor* DoGetEditorClass() const;
2431 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
2433 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
2434 WX_PG_DECLARE_DOGETEDITORCLASS \
2437 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME)
2440 // Implements sans constructor function. Also, first arg is class name, not
2442 #define WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(PROPNAME,T,EDITOR) \
2443 const wxPGEditor* PROPNAME::DoGetEditorClass() const \
2445 return wxPGEditor_##EDITOR; \
2448 // -----------------------------------------------------------------------
2452 /** @class wxPGRootProperty
2454 Root parent property.
2456 class WXDLLIMPEXP_PROPGRID wxPGRootProperty
: public wxPGProperty
2459 WX_PG_DECLARE_PROPERTY_CLASS(wxPGRootProperty
)
2463 wxPGRootProperty( const wxString
& name
= wxS("<Root>") );
2464 virtual ~wxPGRootProperty();
2466 virtual bool StringToValue( wxVariant
&, const wxString
&, int ) const
2474 // -----------------------------------------------------------------------
2476 /** @class wxPropertyCategory
2478 Category (caption) property.
2480 class WXDLLIMPEXP_PROPGRID wxPropertyCategory
: public wxPGProperty
2482 friend class wxPropertyGrid
;
2483 friend class wxPropertyGridPageState
;
2484 WX_PG_DECLARE_PROPERTY_CLASS(wxPropertyCategory
)
2487 /** Default constructor is only used in special cases. */
2488 wxPropertyCategory();
2490 wxPropertyCategory( const wxString
& label
,
2491 const wxString
& name
= wxPG_LABEL
);
2492 ~wxPropertyCategory();
2494 int GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const;
2496 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
) const;
2497 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
2500 void SetTextColIndex( unsigned int colInd
)
2501 { m_capFgColIndex
= (wxByte
) colInd
; }
2502 unsigned int GetTextColIndex() const
2503 { return (unsigned int) m_capFgColIndex
; }
2505 void CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
);
2507 int m_textExtent
; // pre-calculated length of text
2508 wxByte m_capFgColIndex
; // caption text colour index
2516 // -----------------------------------------------------------------------
2518 #endif // wxUSE_PROPGRID
2520 #endif // _WX_PROPGRID_PROPERTY_H_