1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgrid/property.h
3 // Purpose: wxPGProperty and related support classes
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PROPGRID_PROPERTY_H_
13 #define _WX_PROPGRID_PROPERTY_H_
17 #include "wx/propgrid/propgriddefs.h"
19 // -----------------------------------------------------------------------
21 #define wxNullProperty ((wxPGProperty*)NULL)
24 /** @class wxPGPaintData
26 Contains information relayed to property's OnCustomPaint.
30 /** wxPropertyGrid. */
31 const wxPropertyGrid
* m_parent
;
34 Normally -1, otherwise index to drop-down list item that has to be
39 /** Set to drawn width in OnCustomPaint (optional). */
43 In a measure item call, set this to the height of item at m_choiceItem
53 // space between vertical sides of a custom image
54 #define wxPG_CUSTOM_IMAGE_SPACINGY 1
56 // space between caption and selection rectangle,
57 #define wxPG_CAPRECTXMARGIN 2
59 // horizontally and vertically
60 #define wxPG_CAPRECTYMARGIN 1
63 /** @class wxPGCellRenderer
65 Base class for wxPropertyGrid cell renderers.
67 class WXDLLIMPEXP_PROPGRID wxPGCellRenderer
: public wxObjectRefData
72 : wxObjectRefData() { }
73 virtual ~wxPGCellRenderer() { }
78 // We are painting selected item
79 Selected
= 0x00010000,
81 // We are painting item in choice popup
82 ChoicePopup
= 0x00020000,
84 // We are rendering wxOwnerDrawnComboBox control
85 // (or other owner drawn control, but that is only
86 // officially supported one ATM).
89 // We are painting a disable property
90 Disabled
= 0x00080000,
92 // We are painting selected, disabled, or similar
93 // item that dictates fore- and background colours,
94 // overriding any cell values.
95 DontUseCellFgCol
= 0x00100000,
96 DontUseCellBgCol
= 0x00200000,
97 DontUseCellColours
= DontUseCellFgCol
|
101 virtual void Render( wxDC
& dc
,
103 const wxPropertyGrid
* propertyGrid
,
104 wxPGProperty
* property
,
107 int flags
) const = 0;
109 /** Returns size of the image in front of the editable area.
111 If property is NULL, then this call is for a custom value. In that case
112 the item is index to wxPropertyGrid's custom values.
114 virtual wxSize
GetImageSize( const wxPGProperty
* property
,
118 /** Paints property category selection rectangle.
120 virtual void DrawCaptionSelectionRect( wxDC
& dc
,
122 int w
, int h
) const;
124 /** Utility to draw vertically centered text.
126 void DrawText( wxDC
& dc
,
129 const wxString
& text
) const;
132 Utility to draw editor's value, or vertically aligned text if editor is
135 void DrawEditorValue( wxDC
& dc
, const wxRect
& rect
,
136 int xOffset
, const wxString
& text
,
137 wxPGProperty
* property
,
138 const wxPGEditor
* editor
) const;
140 /** Utility to render cell bitmap and set text colour plus bg brush
143 @return Returns image width, which, for instance, can be passed to
146 int PreDrawCell( wxDC
& dc
,
148 const wxPGCell
& cell
,
152 Utility to be called after drawing is done, to revert whatever
153 changes PreDrawCell() did.
156 Same as those passed to PreDrawCell().
158 void PostDrawCell( wxDC
& dc
,
159 const wxPropertyGrid
* propGrid
,
160 const wxPGCell
& cell
,
166 @class wxPGDefaultRenderer
168 Default cell renderer, that can handles the common
171 class WXDLLIMPEXP_PROPGRID wxPGDefaultRenderer
: public wxPGCellRenderer
174 virtual void Render( wxDC
& dc
,
176 const wxPropertyGrid
* propertyGrid
,
177 wxPGProperty
* property
,
182 virtual wxSize
GetImageSize( const wxPGProperty
* property
,
190 class WXDLLIMPEXP_PROPGRID wxPGCellData
: public wxObjectRefData
192 friend class wxPGCell
;
196 void SetText( const wxString
& text
)
199 m_hasValidText
= true;
201 void SetBitmap( const wxBitmap
& bitmap
) { m_bitmap
= bitmap
; }
202 void SetFgCol( const wxColour
& col
) { m_fgCol
= col
; }
203 void SetBgCol( const wxColour
& col
) { m_bgCol
= col
; }
204 void SetFont( const wxFont
& font
) { m_font
= font
; }
207 virtual ~wxPGCellData() { }
215 // 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 // -----------------------------------------------------------------------
318 /** @class wxPGAttributeStorage
320 wxPGAttributeStorage is somewhat optimized storage for
321 key=variant pairs (ie. a map).
323 class WXDLLIMPEXP_PROPGRID wxPGAttributeStorage
326 wxPGAttributeStorage();
327 ~wxPGAttributeStorage();
329 void Set( const wxString
& name
, const wxVariant
& value
);
330 unsigned int GetCount() const { return (unsigned int) m_map
.size(); }
331 wxVariant
FindValue( const wxString
& name
) const
333 wxPGHashMapS2P::const_iterator it
= m_map
.find(name
);
334 if ( it
!= m_map
.end() )
336 wxVariantData
* data
= (wxVariantData
*) it
->second
;
338 return wxVariant(data
, it
->first
);
343 typedef wxPGHashMapS2P::const_iterator const_iterator
;
344 const_iterator
StartIteration() const
346 return m_map
.begin();
348 bool GetNext( const_iterator
& it
, wxVariant
& variant
) const
350 if ( it
== m_map
.end() )
353 wxVariantData
* data
= (wxVariantData
*) it
->second
;
355 variant
.SetData(data
);
356 variant
.SetName(it
->first
);
362 wxPGHashMapS2P m_map
;
367 // -----------------------------------------------------------------------
369 /** @section propgrid_propflags wxPGProperty Flags
373 enum wxPG_PROPERTY_FLAGS
376 /** Indicates bold font.
378 wxPG_PROP_MODIFIED
= 0x0001,
380 /** Disables ('greyed' text and editor does not activate) property.
382 wxPG_PROP_DISABLED
= 0x0002,
384 /** Hider button will hide this property.
386 wxPG_PROP_HIDDEN
= 0x0004,
388 /** This property has custom paint image just in front of its value.
389 If property only draws custom images into a popup list, then this
390 flag should not be set.
392 wxPG_PROP_CUSTOMIMAGE
= 0x0008,
394 /** Do not create text based editor for this property (but button-triggered
395 dialog and choice are ok).
397 wxPG_PROP_NOEDITOR
= 0x0010,
399 /** Property is collapsed, ie. it's children are hidden.
401 wxPG_PROP_COLLAPSED
= 0x0020,
404 If property is selected, then indicates that validation failed for pending
407 If property is not selected, then indicates that the the actual property
408 value has failed validation (NB: this behavior is not currently supported,
409 but may be used in future).
411 wxPG_PROP_INVALID_VALUE
= 0x0040,
415 /** Switched via SetWasModified(). Temporary flag - only used when
416 setting/changing property value.
418 wxPG_PROP_WAS_MODIFIED
= 0x0200,
421 If set, then child properties (if any) are private, and should be
422 "invisible" to the application.
424 wxPG_PROP_AGGREGATE
= 0x0400,
426 /** If set, then child properties (if any) are copies and should not
429 wxPG_PROP_CHILDREN_ARE_COPIES
= 0x0800,
432 Classifies this item as a non-category.
434 Used for faster item type identification.
436 wxPG_PROP_PROPERTY
= 0x1000,
439 Classifies this item as a category.
441 Used for faster item type identification.
443 wxPG_PROP_CATEGORY
= 0x2000,
445 /** Classifies this item as a property that has children, but is not aggregate
446 (ie children are not private).
448 wxPG_PROP_MISC_PARENT
= 0x4000,
450 /** Property is read-only. Editor is still created.
452 wxPG_PROP_READONLY
= 0x8000,
455 // NB: FLAGS ABOVE 0x8000 CANNOT BE USED WITH PROPERTY ITERATORS
458 /** Property's value is composed from values of child properties.
460 This flag cannot be used with property iterators.
462 wxPG_PROP_COMPOSED_VALUE
= 0x00010000,
464 /** Common value of property is selectable in editor.
466 This flag cannot be used with property iterators.
468 wxPG_PROP_USES_COMMON_VALUE
= 0x00020000,
470 /** Property can be set to unspecified value via editor.
471 Currently, this applies to following properties:
472 - wxIntProperty, wxUIntProperty, wxFloatProperty, wxEditEnumProperty:
476 This flag cannot be used with property iterators.
478 wxPG_PROP_AUTO_UNSPECIFIED
= 0x00040000,
480 /** Indicates the bit useable by derived properties.
482 wxPG_PROP_CLASS_SPECIFIC_1
= 0x00080000,
484 /** Indicates the bit useable by derived properties.
486 wxPG_PROP_CLASS_SPECIFIC_2
= 0x00100000,
488 /** Indicates that the property is being deleted and should be ignored.
490 wxPG_PROP_BEING_DELETED
= 0x00200000
496 #define wxPG_PROP_MAX wxPG_PROP_AUTO_UNSPECIFIED
498 /** Property with children must have one of these set, otherwise iterators
499 will not work correctly.
500 Code should automatically take care of this, however.
502 #define wxPG_PROP_PARENTAL_FLAGS \
503 (wxPG_PROP_AGGREGATE|wxPG_PROP_CATEGORY|wxPG_PROP_MISC_PARENT)
508 // Combination of flags that can be stored by GetFlagsAsString
509 #define wxPG_STRING_STORED_FLAGS \
510 (wxPG_PROP_DISABLED|wxPG_PROP_HIDDEN|wxPG_PROP_NOEDITOR|wxPG_PROP_COLLAPSED)
512 // -----------------------------------------------------------------------
517 @section propgrid_property_attributes wxPropertyGrid Property Attribute
520 wxPGProperty::SetAttribute() and
521 wxPropertyGridInterface::SetPropertyAttribute() accept one of these as
522 attribute name argument.
524 You can use strings instead of constants. However, some of these
525 constants are redefined to use cached strings which may reduce
526 your binary size by some amount.
531 /** Set default value for property.
533 #define wxPG_ATTR_DEFAULT_VALUE wxS("DefaultValue")
535 /** Universal, int or double. Minimum value for numeric properties.
537 #define wxPG_ATTR_MIN wxS("Min")
539 /** Universal, int or double. Maximum value for numeric properties.
541 #define wxPG_ATTR_MAX wxS("Max")
543 /** Universal, string. When set, will be shown as text after the displayed
544 text value. Alternatively, if third column is enabled, text will be shown
545 there (for any type of property).
547 #define wxPG_ATTR_UNITS wxS("Units")
549 /** When set, will be shown as 'greyed' text in property's value cell when
550 the actual displayed value is blank.
552 #define wxPG_ATTR_HINT wxS("Hint")
554 #if wxPG_COMPATIBILITY_1_4
556 @deprecated Use "Hint" (wxPG_ATTR_INLINE_HELP) instead.
558 #define wxPG_ATTR_INLINE_HELP wxS("InlineHelp")
561 /** Universal, wxArrayString. Set to enable auto-completion in any
562 wxTextCtrl-based property editor.
564 #define wxPG_ATTR_AUTOCOMPLETE wxS("AutoComplete")
566 /** wxBoolProperty and wxFlagsProperty specific. Value type is bool.
567 Default value is False.
569 When set to True, bool property will use check box instead of a
570 combo box as its editor control. If you set this attribute
571 for a wxFlagsProperty, it is automatically applied to child
574 #define wxPG_BOOL_USE_CHECKBOX wxS("UseCheckbox")
576 /** wxBoolProperty and wxFlagsProperty specific. Value type is bool.
577 Default value is False.
579 Set to True for the bool property to cycle value on double click
580 (instead of showing the popup listbox). If you set this attribute
581 for a wxFlagsProperty, it is automatically applied to child
584 #define wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING wxS("UseDClickCycling")
587 wxFloatProperty (and similar) specific, int, default -1.
589 Sets the (max) precision used when floating point value is rendered as
590 text. The default -1 means infinite precision.
592 #define wxPG_FLOAT_PRECISION wxS("Precision")
595 The text will be echoed as asterisks (wxTE_PASSWORD will be passed to
598 #define wxPG_STRING_PASSWORD wxS("Password")
600 /** Define base used by a wxUIntProperty. Valid constants are
601 wxPG_BASE_OCT, wxPG_BASE_DEC, wxPG_BASE_HEX and wxPG_BASE_HEXL
602 (lowercase characters).
604 #define wxPG_UINT_BASE wxS("Base")
606 /** Define prefix rendered to wxUIntProperty. Accepted constants
607 wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and wxPG_PREFIX_DOLLAR_SIGN.
608 <b>Note:</b> Only wxPG_PREFIX_NONE works with Decimal and Octal
611 #define wxPG_UINT_PREFIX wxS("Prefix")
614 wxFileProperty/wxImageFileProperty specific, wxChar*, default is
616 Sets the wildcard used in the triggered wxFileDialog. Format is the same.
618 #define wxPG_FILE_WILDCARD wxS("Wildcard")
620 /** wxFileProperty/wxImageFileProperty specific, int, default 1.
621 When 0, only the file name is shown (i.e. drive and directory are hidden).
623 #define wxPG_FILE_SHOW_FULL_PATH wxS("ShowFullPath")
625 /** Specific to wxFileProperty and derived properties, wxString, default empty.
626 If set, then the filename is shown relative to the given path string.
628 #define wxPG_FILE_SHOW_RELATIVE_PATH wxS("ShowRelativePath")
631 Specific to wxFileProperty and derived properties, wxString, default is
634 Sets the initial path of where to look for files.
636 #define wxPG_FILE_INITIAL_PATH wxS("InitialPath")
638 /** Specific to wxFileProperty and derivatives, wxString, default is empty.
639 Sets a specific title for the dir dialog.
641 #define wxPG_FILE_DIALOG_TITLE wxS("DialogTitle")
643 /** Specific to wxDirProperty, wxString, default is empty.
644 Sets a specific message for the dir dialog.
646 #define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage")
648 /** Sets displayed date format for wxDateProperty.
650 #define wxPG_DATE_FORMAT wxS("DateFormat")
652 /** Sets wxDatePickerCtrl window style used with wxDateProperty. Default
653 is wxDP_DEFAULT | wxDP_SHOWCENTURY.
655 #define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
657 /** SpinCtrl editor, int or double. How much number changes when button is
658 pressed (or up/down on keybard).
660 #define wxPG_ATTR_SPINCTRL_STEP wxS("Step")
662 /** SpinCtrl editor, bool. If true, value wraps at Min/Max.
664 #define wxPG_ATTR_SPINCTRL_WRAP wxS("Wrap")
667 wxMultiChoiceProperty, int.
668 If 0, no user strings allowed. If 1, user strings appear before list
669 strings. If 2, user strings appear after list string.
671 #define wxPG_ATTR_MULTICHOICE_USERSTRINGMODE wxS("UserStringMode")
674 wxColourProperty and its kind, int, default 1.
676 Setting this attribute to 0 hides custom colour from property's list of
679 #define wxPG_COLOUR_ALLOW_CUSTOM wxS("AllowCustom")
684 // Redefine attribute macros to use cached strings
685 #undef wxPG_ATTR_DEFAULT_VALUE
686 #define wxPG_ATTR_DEFAULT_VALUE wxPGGlobalVars->m_strDefaultValue
688 #define wxPG_ATTR_MIN wxPGGlobalVars->m_strMin
690 #define wxPG_ATTR_MAX wxPGGlobalVars->m_strMax
691 #undef wxPG_ATTR_UNITS
692 #define wxPG_ATTR_UNITS wxPGGlobalVars->m_strUnits
693 #undef wxPG_ATTR_HINT
694 #define wxPG_ATTR_HINT wxPGGlobalVars->m_strHint
695 #if wxPG_COMPATIBILITY_1_4
696 #undef wxPG_ATTR_INLINE_HELP
697 #define wxPG_ATTR_INLINE_HELP wxPGGlobalVars->m_strInlineHelp
702 // -----------------------------------------------------------------------
706 /** @class wxPGChoiceEntry
707 Data of a single wxPGChoices choice.
709 class WXDLLIMPEXP_PROPGRID wxPGChoiceEntry
: public wxPGCell
713 wxPGChoiceEntry(const wxPGChoiceEntry
& other
)
716 m_value
= other
.m_value
;
718 wxPGChoiceEntry( const wxString
& label
,
719 int value
= wxPG_INVALID_VALUE
)
720 : wxPGCell(), m_value(value
)
725 virtual ~wxPGChoiceEntry() { }
727 void SetValue( int value
) { m_value
= value
; }
728 int GetValue() const { return m_value
; }
730 wxPGChoiceEntry
& operator=( const wxPGChoiceEntry
& other
)
732 if ( this != &other
)
736 m_value
= other
.m_value
;
745 typedef void* wxPGChoicesId
;
747 class WXDLLIMPEXP_PROPGRID wxPGChoicesData
: public wxObjectRefData
749 friend class wxPGChoices
;
751 // Constructor sets m_refCount to 1.
754 void CopyDataFrom( wxPGChoicesData
* data
);
756 wxPGChoiceEntry
& Insert( int index
, const wxPGChoiceEntry
& item
);
758 // Delete all entries
761 unsigned int GetCount() const
763 return (unsigned int) m_items
.size();
766 const wxPGChoiceEntry
& Item( unsigned int i
) const
768 wxASSERT_MSG( i
< GetCount(), "invalid index" );
772 wxPGChoiceEntry
& Item( unsigned int i
)
774 wxASSERT_MSG( i
< GetCount(), "invalid index" );
779 wxVector
<wxPGChoiceEntry
> m_items
;
781 virtual ~wxPGChoicesData();
784 #define wxPGChoicesEmptyData ((wxPGChoicesData*)NULL)
788 /** @class wxPGChoices
790 Helper class for managing choices of wxPropertyGrid properties.
791 Each entry can have label, value, bitmap, text colour, and background
794 wxPGChoices uses reference counting, similar to other wxWidgets classes.
795 This means that assignment operator and copy constructor only copy the
796 reference and not the actual data. Use Copy() member function to create a
799 @remarks If you do not specify value for entry, index is used.
804 class WXDLLIMPEXP_PROPGRID wxPGChoices
807 typedef long ValArrItem
;
809 /** Default constructor. */
816 Copy constructor, uses reference counting. To create a real copy,
817 use Copy() member function instead.
819 wxPGChoices( const wxPGChoices
& a
)
821 if ( a
.m_data
!= wxPGChoicesEmptyData
)
835 Values for choices. If NULL, indexes are used.
837 wxPGChoices( const wxChar
* const* labels
, const long* values
= NULL
)
850 Values for choices. If empty, indexes are used.
852 wxPGChoices( const wxArrayString
& labels
,
853 const wxArrayInt
& values
= wxArrayInt() )
859 /** Simple interface constructor. */
860 wxPGChoices( wxPGChoicesData
* data
)
876 If did not have own copies, creates them now. If was empty, identical
877 to set except that creates copies.
880 Labels for added choices.
883 Values for added choices. If empty, relevant entry indexes are used.
885 void Add( const wxChar
* const* labels
, const ValArrItem
* values
= NULL
);
887 /** Version that works with wxArrayString and wxArrayInt. */
888 void Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
= wxArrayInt() );
891 Adds a single choice.
894 Label for added choice.
897 Value for added choice. If unspecified, index is used.
899 wxPGChoiceEntry
& Add( const wxString
& label
,
900 int value
= wxPG_INVALID_VALUE
);
902 /** Adds a single item, with bitmap. */
903 wxPGChoiceEntry
& Add( const wxString
& label
,
904 const wxBitmap
& bitmap
,
905 int value
= wxPG_INVALID_VALUE
);
907 /** Adds a single item with full entry information. */
908 wxPGChoiceEntry
& Add( const wxPGChoiceEntry
& entry
)
910 return Insert(entry
, -1);
913 /** Adds single item. */
914 wxPGChoiceEntry
& AddAsSorted( const wxString
& label
,
915 int value
= wxPG_INVALID_VALUE
);
918 Assigns choices data, using reference counting. To create a real copy,
919 use Copy() member function instead.
921 void Assign( const wxPGChoices
& a
)
923 AssignData(a
.m_data
);
926 void AssignData( wxPGChoicesData
* data
);
928 /** Delete all choices. */
932 Returns a real copy of the choices.
934 wxPGChoices
Copy() const
938 dst
.m_data
->CopyDataFrom(m_data
);
944 if ( m_data
== wxPGChoicesEmptyData
)
945 m_data
= new wxPGChoicesData();
948 /** Gets a unsigned number identifying this list. */
949 wxPGChoicesId
GetId() const { return (wxPGChoicesId
) m_data
; };
951 const wxString
& GetLabel( unsigned int ind
) const
953 return Item(ind
).GetText();
956 unsigned int GetCount () const
961 return m_data
->GetCount();
964 int GetValue( unsigned int ind
) const { return Item(ind
).GetValue(); }
966 /** Returns array of values matching the given strings. Unmatching strings
967 result in wxPG_INVALID_VALUE entry in array.
969 wxArrayInt
GetValuesForStrings( const wxArrayString
& strings
) const;
971 /** Returns array of indices matching given strings. Unmatching strings
972 are added to 'unmatched', if not NULL.
974 wxArrayInt
GetIndicesForStrings( const wxArrayString
& strings
,
975 wxArrayString
* unmatched
= NULL
) const;
977 int Index( const wxString
& str
) const;
978 int Index( int val
) const;
980 /** Inserts single item. */
981 wxPGChoiceEntry
& Insert( const wxString
& label
,
983 int value
= wxPG_INVALID_VALUE
);
985 /** Inserts a single item with full entry information. */
986 wxPGChoiceEntry
& Insert( const wxPGChoiceEntry
& entry
, int index
);
988 /** Returns false if this is a constant empty set of choices,
989 which should not be modified.
993 return ( m_data
!= wxPGChoicesEmptyData
);
996 const wxPGChoiceEntry
& Item( unsigned int i
) const
999 return m_data
->Item(i
);
1002 wxPGChoiceEntry
& Item( unsigned int i
)
1005 return m_data
->Item(i
);
1008 /** Removes count items starting at position nIndex. */
1009 void RemoveAt(size_t nIndex
, size_t count
= 1);
1012 /** Does not create copies for itself. */
1013 void Set( const wxChar
* const* labels
, const long* values
= NULL
)
1020 /** Version that works with wxArrayString and wxArrayInt. */
1021 void Set( const wxArrayString
& labels
,
1022 const wxArrayInt
& values
= wxArrayInt() )
1031 // Creates exclusive copy of current choices
1032 void AllocExclusive();
1034 // Returns data, increases refcount.
1035 wxPGChoicesData
* GetData()
1037 wxASSERT( m_data
->GetRefCount() != -1 );
1042 // Returns plain data ptr - no refcounting stuff is done.
1043 wxPGChoicesData
* GetDataPtr() const { return m_data
; }
1045 // Changes ownership of data to you.
1046 wxPGChoicesData
* ExtractData()
1048 wxPGChoicesData
* data
= m_data
;
1049 m_data
= wxPGChoicesEmptyData
;
1053 wxArrayString
GetLabels() const;
1056 void operator= (const wxPGChoices
& a
)
1059 AssignData(a
.m_data
);
1062 wxPGChoiceEntry
& operator[](unsigned int i
)
1067 const wxPGChoiceEntry
& operator[](unsigned int i
) const
1073 wxPGChoicesData
* m_data
;
1080 // -----------------------------------------------------------------------
1082 /** @class wxPGProperty
1084 wxPGProperty is base class for all wxPropertyGrid properties.
1086 NB: Full class overview is now only present in
1087 interface/wx/propgrid/property.h.
1089 @library{wxpropgrid}
1092 class WXDLLIMPEXP_PROPGRID wxPGProperty
: public wxObject
1094 friend class wxPropertyGrid
;
1095 friend class wxPropertyGridInterface
;
1096 friend class wxPropertyGridPageState
;
1097 friend class wxPropertyGridPopulator
;
1098 friend class wxStringProperty
; // Proper "<composed>" support requires this
1100 DECLARE_ABSTRACT_CLASS(wxPGProperty
)
1102 typedef wxUint32 FlagType
;
1105 Default constructor.
1112 All non-abstract property classes should have a constructor with
1113 the same first two arguments as this one.
1115 wxPGProperty( const wxString
& label
, const wxString
& name
);
1119 It is customary for derived properties to implement this.
1121 virtual ~wxPGProperty();
1123 /** This virtual function is called after m_value has been set.
1126 - If m_value was set to Null variant (ie. unspecified value),
1127 OnSetValue() will not be called.
1128 - m_value may be of any variant type. Typically properties internally
1129 support only one variant type, and as such OnSetValue() provides a
1130 good opportunity to convert
1131 supported values into internal type.
1132 - Default implementation does nothing.
1134 virtual void OnSetValue();
1136 /** Override this to return something else than m_value as the value.
1138 virtual wxVariant
DoGetValue() const { return m_value
; }
1140 #if !defined(SWIG) || defined(CREATE_VCW)
1141 /** Implement this function in derived class to check the value.
1142 Return true if it is ok. Returning false prevents property change events
1146 - Default implementation always returns true.
1148 virtual bool ValidateValue( wxVariant
& value
,
1149 wxPGValidationInfo
& validationInfo
) const;
1152 Converts text into wxVariant value appropriate for this property.
1155 On function entry this is the old value (should not be wxNullVariant
1156 in normal cases). Translated value must be assigned back to it.
1159 Text to be translated into variant.
1162 If wxPG_FULL_VALUE is set, returns complete, storable value instead
1163 of displayable one (they may be different).
1164 If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of
1165 composite property string value (as generated by ValueToString()
1166 called with this same flag).
1168 @return Returns @true if resulting wxVariant value was different.
1170 @remarks Default implementation converts semicolon delimited tokens into
1171 child values. Only works for properties with children.
1173 You might want to take into account that m_value is Null variant
1174 if property value is unspecified (which is usually only case if
1175 you explicitly enabled that sort behavior).
1177 virtual bool StringToValue( wxVariant
& variant
,
1178 const wxString
& text
,
1179 int argFlags
= 0 ) const;
1182 Converts integer (possibly a choice selection) into wxVariant value
1183 appropriate for this property.
1186 On function entry this is the old value (should not be wxNullVariant
1187 in normal cases). Translated value must be assigned back to it.
1190 Integer to be translated into variant.
1193 If wxPG_FULL_VALUE is set, returns complete, storable value instead
1196 @return Returns @true if resulting wxVariant value was different.
1199 - If property is not supposed to use choice or spinctrl or other editor
1200 with int-based value, it is not necessary to implement this method.
1201 - Default implementation simply assign given int to m_value.
1202 - If property uses choice control, and displays a dialog on some choice
1203 items, then it is preferred to display that dialog in IntToValue
1205 - You might want to take into account that m_value is Null variant if
1206 property value is unspecified (which is usually only case if you
1207 explicitly enabled that sort behavior).
1209 virtual bool IntToValue( wxVariant
& value
,
1211 int argFlags
= 0 ) const;
1212 #endif // !defined(SWIG) || defined(CREATE_VCW)
1214 Converts property value into a text representation.
1217 Value to be converted.
1220 If 0 (default value), then displayed string is returned.
1221 If wxPG_FULL_VALUE is set, returns complete, storable string value
1222 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
1223 string value that must be editable in textctrl. If
1224 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
1225 display as a part of string property's composite text
1228 @remarks Default implementation calls GenerateComposedValue().
1230 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
1232 /** Converts string to a value, and if successful, calls SetValue() on it.
1233 Default behavior is to do nothing.
1235 String to get the value from.
1237 true if value was changed.
1239 bool SetValueFromString( const wxString
& text
, int flags
= wxPG_PROGRAMMATIC_VALUE
);
1241 /** Converts integer to a value, and if succesful, calls SetValue() on it.
1242 Default behavior is to do nothing.
1244 Int to get the value from.
1246 If has wxPG_FULL_VALUE, then the value given is a actual value and
1249 True if value was changed.
1251 bool SetValueFromInt( long value
, int flags
= 0 );
1254 Returns size of the custom painted image in front of property.
1256 This method must be overridden to return non-default value if
1257 OnCustomPaint is to be called.
1259 Normally -1, but can be an index to the property's list of items.
1261 - Default behavior is to return wxSize(0,0), which means no image.
1262 - Default image width or height is indicated with dimension -1.
1263 - You can also return wxPG_DEFAULT_IMAGE_SIZE, i.e. wxSize(-1, -1).
1265 virtual wxSize
OnMeasureImage( int item
= -1 ) const;
1268 Events received by editor widgets are processed here.
1270 Note that editor class usually processes most events. Some, such as
1271 button press events of TextCtrlAndButton class, can be handled here.
1272 Also, if custom handling for regular events is desired, then that can
1273 also be done (for example, wxSystemColourProperty custom handles
1274 wxEVT_COMMAND_CHOICE_SELECTED to display colour picker dialog when
1275 'custom' selection is made).
1277 If the event causes value to be changed, SetValueInEvent()
1278 should be called to set the new value.
1283 Should return true if any changes in value should be reported.
1285 If property uses choice control, and displays a dialog on some choice
1286 items, then it is preferred to display that dialog in IntToValue
1289 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
1290 wxWindow
* wnd_primary
,
1294 Called after value of a child property has been altered. Must return
1295 new value of the whole property (after any alterations warrented by
1298 Note that this function is usually called at the time that value of
1299 this property, or given child property, is still pending for change,
1300 and as such, result of GetValue() or m_value should not be relied
1303 Sample pseudo-code implementation:
1306 wxVariant MyProperty::ChildChanged( wxVariant& thisValue,
1308 wxVariant& childValue ) const
1310 // Acquire reference to actual type of data stored in variant
1311 // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros
1312 // were used to create the variant class).
1313 T& data = TFromVariant(thisValue);
1315 // Copy childValue into data.
1316 switch ( childIndex )
1319 data.SetSubProp1( childvalue.GetLong() );
1322 data.SetSubProp2( childvalue.GetString() );
1327 // Return altered data
1333 Value of this property. Changed value should be returned (in
1334 previous versions of wxPropertyGrid it was only necessary to
1335 write value back to this argument).
1337 Index of child changed (you can use Item(childIndex) to get
1340 (Pending) value of the child property.
1343 Modified value of the whole property.
1345 virtual wxVariant
ChildChanged( wxVariant
& thisValue
,
1347 wxVariant
& childValue
) const;
1349 /** Returns pointer to an instance of used editor.
1351 virtual const wxPGEditor
* DoGetEditorClass() const;
1353 /** Returns pointer to the wxValidator that should be used
1354 with the editor of this property (NULL for no validator).
1355 Setting validator explicitly via SetPropertyValidator
1358 In most situations, code like this should work well
1359 (macros are used to maintain one actual validator instance,
1360 so on the second call the function exits within the first
1365 wxValidator* wxMyPropertyClass::DoGetValidator () const
1367 WX_PG_DOGETVALIDATOR_ENTRY()
1369 wxMyValidator* validator = new wxMyValidator(...);
1371 ... prepare validator...
1373 WX_PG_DOGETVALIDATOR_EXIT(validator)
1379 You can get common filename validator by returning
1380 wxFileProperty::GetClassValidator(). wxDirProperty,
1381 for example, uses it.
1383 virtual wxValidator
* DoGetValidator () const;
1386 Override to paint an image in front of the property value text or
1387 drop-down list item (but only if wxPGProperty::OnMeasureImage is
1388 overridden as well).
1390 If property's OnMeasureImage() returns size that has height != 0 but
1391 less than row height ( < 0 has special meanings), wxPropertyGrid calls
1392 this method to draw a custom image in a limited area in front of the
1393 editor control or value text/graphics, and if control has drop-down
1394 list, then the image is drawn there as well (even in the case
1395 OnMeasureImage() returned higher height than row height).
1397 NOTE: Following applies when OnMeasureImage() returns a "flexible"
1398 height ( using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable
1399 height items: If rect.x is < 0, then this is a measure item call, which
1400 means that dc is invalid and only thing that should be done is to set
1401 paintdata.m_drawnHeight to the height of the image of item at index
1402 paintdata.m_choiceItem. This call may be done even as often as once
1403 every drop-down popup show.
1408 Box reserved for custom graphics. Includes surrounding rectangle,
1409 if any. If x is < 0, then this is a measure item call (see above).
1411 wxPGPaintData structure with much useful data.
1414 - You can actually exceed rect width, but if you do so then
1415 paintdata.m_drawnWidth must be set to the full width drawn in
1417 - Due to technical reasons, rect's height will be default even if
1418 custom height was reported during measure call.
1419 - Brush is guaranteed to be default background colour. It has been
1420 already used to clear the background of area being painted. It
1422 - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper
1423 colour) pen for drawing framing rectangle. It can be changed as
1426 @see ValueToString()
1428 virtual void OnCustomPaint( wxDC
& dc
,
1430 wxPGPaintData
& paintdata
);
1433 Returns used wxPGCellRenderer instance for given property column
1436 Default implementation returns editor's renderer for all columns.
1438 virtual wxPGCellRenderer
* GetCellRenderer( int column
) const;
1440 /** Returns which choice is currently selected. Only applies to properties
1443 Needs to reimplemented in derived class if property value does not
1444 map directly to a choice. Integer as index, bool, and string usually do.
1446 virtual int GetChoiceSelection() const;
1449 Refresh values of child properties.
1451 Automatically called after value is set.
1453 virtual void RefreshChildren();
1455 /** Special handling for attributes of this property.
1457 If returns false, then the attribute will be automatically stored in
1460 Default implementation simply returns false.
1462 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
1464 /** Returns value of an attribute.
1466 Override if custom handling of attributes is needed.
1468 Default implementation simply return NULL variant.
1470 virtual wxVariant
DoGetAttribute( const wxString
& name
) const;
1472 /** Returns instance of a new wxPGEditorDialogAdapter instance, which is
1473 used when user presses the (optional) button next to the editor control;
1475 Default implementation returns NULL (ie. no action is generated when
1478 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
1481 Called whenever validation has failed with given pending value.
1483 @remarks If you implement this in your custom property class, please
1484 remember to call the baser implementation as well, since they
1485 may use it to revert property into pre-change state.
1487 virtual void OnValidationFailure( wxVariant
& pendingValue
);
1489 /** Append a new choice to property's list of choices.
1491 int AddChoice( const wxString
& label
, int value
= wxPG_INVALID_VALUE
)
1493 return InsertChoice(label
, wxNOT_FOUND
, value
);
1497 Returns true if children of this property are component values (for
1498 instance, points size, face name, and is_underlined are component
1501 bool AreChildrenComponents() const
1503 if ( m_flags
& (wxPG_PROP_COMPOSED_VALUE
|wxPG_PROP_AGGREGATE
) )
1510 Deletes children of the property.
1512 void DeleteChildren();
1515 Removes entry from property's wxPGChoices and editor control (if it is
1518 If selected item is deleted, then the value is set to unspecified.
1520 void DeleteChoice( int index
);
1523 Call to enable or disable usage of common value (integer value that can
1524 be selected for properties instead of their normal values) for this
1527 Common values are disabled by the default for all properties.
1529 void EnableCommonValue( bool enable
= true )
1531 if ( enable
) SetFlag( wxPG_PROP_USES_COMMON_VALUE
);
1532 else ClearFlag( wxPG_PROP_USES_COMMON_VALUE
);
1536 Composes text from values of child properties.
1538 wxString
GenerateComposedValue() const
1541 DoGenerateComposedValue(s
);
1545 /** Returns property's label. */
1546 const wxString
& GetLabel() const { return m_label
; }
1548 /** Returns property's name with all (non-category, non-root) parents. */
1549 wxString
GetName() const;
1552 Returns property's base name (ie parent's name is not added in any
1555 const wxString
& GetBaseName() const { return m_name
; }
1557 /** Returns read-only reference to property's list of choices.
1559 const wxPGChoices
& GetChoices() const
1564 /** Returns coordinate to the top y of the property. Note that the
1565 position of scrollbars is not taken into account.
1569 wxVariant
GetValue() const
1571 return DoGetValue();
1574 /** Returns reference to the internal stored value. GetValue is preferred
1575 way to get the actual value, since GetValueRef ignores DoGetValue,
1576 which may override stored value.
1578 wxVariant
& GetValueRef()
1583 const wxVariant
& GetValueRef() const
1588 // Helper function (for wxPython bindings and such) for settings protected
1590 wxVariant
GetValuePlain() const
1595 /** Returns text representation of property's value.
1598 If 0 (default value), then displayed string is returned.
1599 If wxPG_FULL_VALUE is set, returns complete, storable string value
1600 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
1601 string value that must be editable in textctrl. If
1602 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
1603 display as a part of string property's composite text
1606 @remarks In older versions, this function used to be overridden to convert
1607 property's value into a string representation. This function is
1608 now handled by ValueToString(), and overriding this function now
1609 will result in run-time assertion failure.
1611 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
1613 /** Synonymous to GetValueAsString().
1615 @deprecated Use GetValueAsString() instead.
1617 @see GetValueAsString()
1619 wxDEPRECATED( wxString
GetValueString( int argFlags
= 0 ) const );
1622 Returns wxPGCell of given column.
1624 @remarks const version of this member function returns 'default'
1625 wxPGCell object if the property itself didn't hold
1628 const wxPGCell
& GetCell( unsigned int column
) const;
1631 Returns wxPGCell of given column, creating one if necessary.
1633 wxPGCell
& GetCell( unsigned int column
)
1635 return GetOrCreateCell(column
);
1639 Returns wxPGCell of given column, creating one if necessary.
1641 wxPGCell
& GetOrCreateCell( unsigned int column
);
1643 /** Return number of displayed common values for this property.
1645 int GetDisplayedCommonValueCount() const;
1647 wxString
GetDisplayedString() const
1649 return GetValueAsString(0);
1653 Returns property's hint text (shown in empty value cell).
1655 inline wxString
GetHintText() const;
1657 /** Returns property grid where property lies. */
1658 wxPropertyGrid
* GetGrid() const;
1660 /** Returns owner wxPropertyGrid, but only if one is currently on a page
1661 displaying this property. */
1662 wxPropertyGrid
* GetGridIfDisplayed() const;
1664 /** Returns highest level non-category, non-root parent. Useful when you
1665 have nested wxCustomProperties/wxParentProperties.
1667 Thus, if immediate parent is root or category, this will return the
1670 wxPGProperty
* GetMainParent() const;
1672 /** Return parent of property */
1673 wxPGProperty
* GetParent() const { return m_parent
; }
1675 /** Returns true if property has editable wxTextCtrl when selected.
1678 Altough disabled properties do not displayed editor, they still
1679 return True here as being disabled is considered a temporary
1680 condition (unlike being read-only or having limited editing enabled).
1682 bool IsTextEditable() const;
1684 bool IsValueUnspecified() const
1686 return m_value
.IsNull();
1689 FlagType
HasFlag( FlagType 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;
1705 FlagType
GetFlags() const
1710 const wxPGEditor
* GetEditorClass() const;
1712 wxString
GetValueType() const
1714 return m_value
.GetType();
1717 /** Returns editor used for given column. NULL for no editor.
1719 const wxPGEditor
* GetColumnEditor( int column
) const
1722 return GetEditorClass();
1727 /** Returns common value selected for this property. -1 for none.
1729 int GetCommonValue() const
1731 return m_commonValue
;
1734 /** Returns true if property has even one visible child.
1736 bool HasVisibleChildren() const;
1739 Use this member function to add independent (ie. regular) children to
1742 @return Inserted childProperty.
1744 @remarks wxPropertyGrid is not automatically refreshed by this
1747 @see AddPrivateChild()
1749 wxPGProperty
* InsertChild( int index
, wxPGProperty
* childProperty
);
1751 /** Inserts a new choice to property's list of choices.
1753 int InsertChoice( const wxString
& label
, int index
, int value
= wxPG_INVALID_VALUE
);
1756 Returns true if this property is actually a wxPropertyCategory.
1758 bool IsCategory() const { return HasFlag(wxPG_PROP_CATEGORY
)?true:false; }
1760 /** Returns true if this property is actually a wxRootProperty.
1762 bool IsRoot() const { return (m_parent
== NULL
); }
1764 /** Returns true if this is a sub-property. */
1765 bool IsSubProperty() const
1767 wxPGProperty
* parent
= (wxPGProperty
*)m_parent
;
1768 if ( parent
&& !parent
->IsCategory() )
1773 /** Returns last visible sub-property, recursively.
1775 const wxPGProperty
* GetLastVisibleSubItem() const;
1777 wxVariant
GetDefaultValue() const;
1779 int GetMaxLength() const
1781 return (int) m_maxLen
;
1785 Determines, recursively, if all children are not unspecified.
1788 Assumes members in this wxVariant list as pending
1791 bool AreAllChildrenSpecified( wxVariant
* pendingList
= NULL
) const;
1793 /** Updates composed values of parent non-category properties, recursively.
1794 Returns topmost property updated.
1797 - Must not call SetValue() (as can be called in it).
1799 wxPGProperty
* UpdateParentValues();
1801 /** Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
1803 bool UsesAutoUnspecified() const
1805 return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED
)?true:false;
1808 wxBitmap
* GetValueImage() const
1810 return m_valueBitmap
;
1813 wxVariant
GetAttribute( const wxString
& name
) const;
1816 Returns named attribute, as string, if found.
1818 Otherwise defVal is returned.
1820 wxString
GetAttribute( const wxString
& name
, const wxString
& defVal
) const;
1823 Returns named attribute, as long, if found.
1825 Otherwise defVal is returned.
1827 long GetAttributeAsLong( const wxString
& name
, long defVal
) const;
1830 Returns named attribute, as double, if found.
1832 Otherwise defVal is returned.
1834 double GetAttributeAsDouble( const wxString
& name
, double defVal
) const;
1836 unsigned int GetDepth() const { return (unsigned int)m_depth
; }
1838 /** Gets flags as a'|' delimited string. Note that flag names are not
1839 prepended with 'wxPG_PROP_'.
1841 String will only be made to include flags combined by this parameter.
1843 wxString
GetFlagsAsString( FlagType flagsMask
) const;
1845 /** Returns position in parent's array. */
1846 unsigned int GetIndexInParent() const
1848 return (unsigned int)m_arrIndex
;
1851 /** Hides or reveals the property.
1853 true for hide, false for reveal.
1855 By default changes are applied recursively. Set this paramter
1856 wxPG_DONT_RECURSE to prevent this.
1858 inline bool Hide( bool hide
, int flags
= wxPG_RECURSE
);
1860 bool IsExpanded() const
1861 { return (!(m_flags
& wxPG_PROP_COLLAPSED
) && GetChildCount()); }
1863 /** Returns true if all parents expanded.
1865 bool IsVisible() const;
1867 bool IsEnabled() const { return !(m_flags
& wxPG_PROP_DISABLED
); }
1869 /** If property's editor is created this forces its recreation.
1870 Useful in SetAttribute etc. Returns true if actually did anything.
1872 bool RecreateEditor();
1874 /** If property's editor is active, then update it's value.
1876 void RefreshEditor();
1878 /** Sets an attribute for this property.
1880 Text identifier of attribute. See @ref propgrid_property_attributes.
1884 void SetAttribute( const wxString
& name
, wxVariant value
);
1886 void SetAttributes( const wxPGAttributeStorage
& attributes
);
1889 Sets property's background colour.
1892 Background colour to use.
1895 Default is wxPG_RECURSE which causes colour to be set recursively.
1896 Omit this flag to only set colour for the property in question
1897 and not any of its children.
1899 void SetBackgroundColour( const wxColour
& colour
,
1900 int flags
= wxPG_RECURSE
);
1903 Sets property's text colour.
1909 Default is wxPG_RECURSE which causes colour to be set recursively.
1910 Omit this flag to only set colour for the property in question
1911 and not any of its children.
1913 void SetTextColour( const wxColour
& colour
,
1914 int flags
= wxPG_RECURSE
);
1916 /** Set default value of a property. Synonymous to
1919 SetAttribute("DefaultValue", value);
1922 void SetDefaultValue( wxVariant
& value
);
1925 /** Sets editor for a property.
1928 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1929 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full
1932 For custom editors, use pointer you received from
1933 wxPropertyGrid::RegisterEditorClass().
1935 void SetEditor( const wxPGEditor
* editor
)
1937 m_customEditor
= editor
;
1941 /** Sets editor for a property.
1943 inline void SetEditor( const wxString
& editorName
);
1946 Sets cell information for given column.
1948 void SetCell( int column
, const wxPGCell
& cell
);
1950 /** Sets common value selected for this property. -1 for none.
1952 void SetCommonValue( int commonValue
)
1954 m_commonValue
= commonValue
;
1957 /** Sets flags from a '|' delimited string. Note that flag names are not
1958 prepended with 'wxPG_PROP_'.
1960 void SetFlagsFromString( const wxString
& str
);
1962 /** Sets property's "is it modified?" flag. Affects children recursively.
1964 void SetModifiedStatus( bool modified
)
1966 SetFlagRecursively(wxPG_PROP_MODIFIED
, modified
);
1969 /** Call in OnEvent(), OnButtonClick() etc. to change the property value
1970 based on user input.
1973 This method is const since it doesn't actually modify value, but posts
1974 given variant as pending value, stored in wxPropertyGrid.
1976 void SetValueInEvent( wxVariant value
) const;
1979 Call this to set value of the property.
1981 Unlike methods in wxPropertyGrid, this does not automatically update
1985 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run
1986 through validation process and send property change event.
1988 If you need to change property value in event, based on user input, use
1989 SetValueInEvent() instead.
1992 Pointer to list variant that contains child values. Used to
1993 indicate which children should be marked as modified.
1996 Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR, which is
1997 enabled by default).
1999 void SetValue( wxVariant value
, wxVariant
* pList
= NULL
,
2000 int flags
= wxPG_SETVAL_REFRESH_EDITOR
);
2002 /** Set wxBitmap in front of the value. This bitmap may be ignored
2003 by custom cell renderers.
2005 void SetValueImage( wxBitmap
& bmp
);
2007 /** Sets selected choice and changes property value.
2009 Tries to retain value type, although currently if it is not string,
2010 then it is forced to integer.
2012 void SetChoiceSelection( int newValue
);
2014 void SetExpanded( bool expanded
)
2016 if ( !expanded
) m_flags
|= wxPG_PROP_COLLAPSED
;
2017 else m_flags
&= ~wxPG_PROP_COLLAPSED
;
2021 Sets given property flag(s).
2023 void SetFlag( FlagType flag
) { m_flags
|= flag
; }
2026 Sets or clears given property flag(s).
2028 void ChangeFlag( FlagType flag
, bool set
)
2036 void SetFlagRecursively( FlagType flag
, bool set
);
2038 void SetHelpString( const wxString
& helpString
)
2040 m_helpString
= helpString
;
2043 void SetLabel( const wxString
& label
) { m_label
= label
; }
2045 void SetName( const wxString
& newName
);
2048 Changes what sort of parent this property is for its children.
2051 Use one of the following values: wxPG_PROP_MISC_PARENT (for
2052 generic parents), wxPG_PROP_CATEGORY (for categories), or
2053 wxPG_PROP_AGGREGATE (for derived property classes with private
2056 @remarks You generally do not need to call this function.
2058 void SetParentalType( int flag
)
2060 m_flags
&= ~(wxPG_PROP_PROPERTY
|wxPG_PROP_PARENTAL_FLAGS
);
2064 void SetValueToUnspecified()
2066 wxVariant val
; // Create NULL variant
2067 SetValue(val
, NULL
, wxPG_SETVAL_REFRESH_EDITOR
);
2070 // Helper function (for wxPython bindings and such) for settings protected
2072 void SetValuePlain( wxVariant value
)
2077 #if wxUSE_VALIDATORS
2078 /** Sets wxValidator for a property*/
2079 void SetValidator( const wxValidator
& validator
)
2081 m_validator
= wxDynamicCast(validator
.Clone(),wxValidator
);
2084 /** Gets assignable version of property's validator. */
2085 wxValidator
* GetValidator() const
2089 return DoGetValidator();
2091 #endif // wxUSE_VALIDATORS
2094 /** Returns client data (void*) of a property.
2096 void* GetClientData() const
2098 return m_clientData
;
2101 /** Sets client data (void*) of a property.
2103 This untyped client data has to be deleted manually.
2105 void SetClientData( void* clientData
)
2107 m_clientData
= clientData
;
2110 /** Returns client object of a property.
2112 void SetClientObject(wxClientData
* clientObject
)
2114 delete m_clientObject
;
2115 m_clientObject
= clientObject
;
2118 /** Sets managed client object of a property.
2120 wxClientData
*GetClientObject() const { return m_clientObject
; }
2123 /** Sets new set of choices for property.
2126 This operation clears the property value.
2128 bool SetChoices( wxPGChoices
& choices
);
2130 /** Set max length of text in text editor.
2132 inline bool SetMaxLength( int maxLen
);
2134 /** Call with 'false' in OnSetValue to cancel value changes after all
2135 (ie. cancel 'true' returned by StringToValue() or IntToValue()).
2137 void SetWasModified( bool set
= true )
2139 if ( set
) m_flags
|= wxPG_PROP_WAS_MODIFIED
;
2140 else m_flags
&= ~wxPG_PROP_WAS_MODIFIED
;
2143 const wxString
& GetHelpString() const
2145 return m_helpString
;
2148 void ClearFlag( FlagType flag
) { m_flags
&= ~(flag
); }
2150 // Use, for example, to detect if item is inside collapsed section.
2151 bool IsSomeParent( wxPGProperty
* candidate_parent
) const;
2154 Adapts list variant into proper value using consecutive
2157 void AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const;
2159 #if wxPG_COMPATIBILITY_1_4
2161 Adds a private child property.
2163 @deprecated Use AddPrivateChild() instead.
2165 @see AddPrivateChild()
2167 wxDEPRECATED( void AddChild( wxPGProperty
* prop
) );
2171 Adds a private child property. If you use this instead of
2172 wxPropertyGridInterface::Insert() or
2173 wxPropertyGridInterface::AppendIn(), then property's parental
2174 type will automatically be set up to wxPG_PROP_AGGREGATE. In other
2175 words, all properties of this property will become private.
2177 void AddPrivateChild( wxPGProperty
* prop
);
2180 Appends a new child property.
2182 wxPGProperty
* AppendChild( wxPGProperty
* prop
)
2184 return InsertChild(-1, prop
);
2187 /** Returns height of children, recursively, and
2188 by taking expanded/collapsed status into account.
2190 iMax is used when finding property y-positions.
2192 int GetChildrenHeight( int lh
, int iMax
= -1 ) const;
2194 /** Returns number of child properties */
2195 unsigned int GetChildCount() const
2197 return (unsigned int) m_children
.size();
2200 /** Returns sub-property at index i. */
2201 wxPGProperty
* Item( unsigned int i
) const
2202 { return m_children
[i
]; }
2204 /** Returns last sub-property.
2206 wxPGProperty
* Last() const { return m_children
.back(); }
2208 /** Returns index of given child property. */
2209 int Index( const wxPGProperty
* p
) const;
2211 // Puts correct indexes to children
2212 void FixIndicesOfChildren( unsigned int starthere
= 0 );
2215 Converts image width into full image offset, with margins.
2217 int GetImageOffset( int imageWidth
) const;
2220 // Returns wxPropertyGridPageState in which this property resides.
2221 wxPropertyGridPageState
* GetParentState() const { return m_parentState
; }
2225 wxPGProperty
* GetItemAtY( unsigned int y
,
2227 unsigned int* nextItemY
) const;
2230 /** Returns property at given virtual y coordinate.
2232 wxPGProperty
* GetItemAtY( unsigned int y
) const;
2234 /** Returns (direct) child property with given name (or NULL if not found).
2236 wxPGProperty
* GetPropertyByName( const wxString
& name
) const;
2240 // Returns various display-related information for given column
2241 void GetDisplayInfo( unsigned int column
,
2245 const wxPGCell
** pCell
);
2247 static wxString
* sm_wxPG_LABEL
;
2249 /** This member is public so scripting language bindings
2250 wrapper code can access it freely.
2257 Sets property cell in fashion that reduces number of exclusive
2258 copies of cell data. Used when setting, for instance, same
2259 background colour for a number of properties.
2262 First column to affect.
2265 Last column to affect.
2268 Pre-prepared cell that is used for those which cell data
2269 before this matched unmodCellData.
2272 If unmodCellData did not match, valid cell data from this
2273 is merged into cell (usually generating new exclusive copy
2276 @param unmodCellData
2277 If cell's cell data matches this, its cell is now set to
2280 @param ignoreWithFlags
2281 Properties with any one of these flags are skipped.
2284 If @true, apply this operation recursively in child properties.
2286 void AdaptiveSetCell( unsigned int firstCol
,
2287 unsigned int lastCol
,
2288 const wxPGCell
& preparedCell
,
2289 const wxPGCell
& srcData
,
2290 wxPGCellData
* unmodCellData
,
2291 FlagType ignoreWithFlags
,
2295 Makes sure m_cells has size of column+1 (or more).
2297 void EnsureCells( unsigned int column
);
2299 /** Returns (direct) child property with given name (or NULL if not found),
2303 Start looking for the child at this index.
2306 Does not support scope (ie. Parent.Child notation).
2308 wxPGProperty
* GetPropertyByNameWH( const wxString
& name
,
2309 unsigned int hintIndex
) const;
2311 /** This is used by Insert etc. */
2312 void DoAddChild( wxPGProperty
* prop
,
2314 bool correct_mode
= true );
2316 void DoGenerateComposedValue( wxString
& text
,
2317 int argFlags
= wxPG_VALUE_IS_CURRENT
,
2318 const wxVariantList
* valueOverrides
= NULL
,
2319 wxPGHashMapS2S
* childResults
= NULL
) const;
2321 void DoSetName(const wxString
& str
) { m_name
= str
; }
2323 /** Deletes all sub-properties. */
2326 bool HasCell( unsigned int column
) const
2328 if ( m_cells
.size() > column
)
2333 void InitAfterAdded( wxPropertyGridPageState
* pageState
,
2334 wxPropertyGrid
* propgrid
);
2336 // Removes child property with given pointer. Does not delete it.
2337 void RemoveChild( wxPGProperty
* p
);
2339 void DoPreAddChild( int index
, wxPGProperty
* prop
);
2341 void SetParentState( wxPropertyGridPageState
* pstate
)
2342 { m_parentState
= pstate
; }
2344 // Call after fixed sub-properties added/removed after creation.
2345 // if oldSelInd >= 0 and < new max items, then selection is
2347 void SubPropsChanged( int oldSelInd
= -1 );
2349 int GetY2( int lh
) const;
2353 wxPGProperty
* m_parent
;
2354 wxPropertyGridPageState
* m_parentState
;
2356 wxClientData
* m_clientObject
;
2358 // Overrides editor returned by property class
2359 const wxPGEditor
* m_customEditor
;
2360 #if wxUSE_VALIDATORS
2361 // Editor is going to get this validator
2362 wxValidator
* m_validator
;
2364 // Show this in front of the value
2366 // TODO: Can bitmap be implemented with wxPGCell?
2367 wxBitmap
* m_valueBitmap
;
2370 wxPGAttributeStorage m_attributes
;
2371 wxArrayPGProperty m_children
;
2373 // Extended cell information
2374 wxVector
<wxPGCell
> m_cells
;
2376 // Choices shown in drop-down list of editor control.
2377 wxPGChoices m_choices
;
2379 // Help shown in statusbar or help box.
2380 wxString m_helpString
;
2382 // Index in parent's property array.
2383 unsigned int m_arrIndex
;
2385 // If not -1, then overrides m_value
2390 // Maximum length (mainly for string properties). Could be in some sort of
2391 // wxBaseStringProperty, but currently, for maximum flexibility and
2392 // compatibility, we'll stick it here. Anyway, we had 3 excess bytes to use
2393 // so short int will fit in just fine.
2396 // Root has 0, categories etc. at that level 1, etc.
2397 unsigned char m_depth
;
2399 // m_depthBgCol indicates width of background colour between margin and item
2400 // (essentially this is category's depth, if none then equals m_depth).
2401 unsigned char m_depthBgCol
;
2404 // Called in constructors.
2406 void Init( const wxString
& label
, const wxString
& name
);
2407 #endif // #ifndef SWIG
2410 // -----------------------------------------------------------------------
2413 // Property class declaration helper macros
2414 // (wxPGRootPropertyClass and wxPropertyCategory require this).
2417 #define WX_PG_DECLARE_DOGETEDITORCLASS \
2418 virtual const wxPGEditor* DoGetEditorClass() const;
2421 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
2423 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
2424 WX_PG_DECLARE_DOGETEDITORCLASS \
2427 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME)
2430 // Implements sans constructor function. Also, first arg is class name, not
2432 #define WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(PROPNAME,T,EDITOR) \
2433 const wxPGEditor* PROPNAME::DoGetEditorClass() const \
2435 return wxPGEditor_##EDITOR; \
2438 // -----------------------------------------------------------------------
2442 /** @class wxPGRootProperty
2444 Root parent property.
2446 class WXDLLIMPEXP_PROPGRID wxPGRootProperty
: public wxPGProperty
2449 WX_PG_DECLARE_PROPERTY_CLASS(wxPGRootProperty
)
2453 wxPGRootProperty( const wxString
& name
= wxS("<Root>") );
2454 virtual ~wxPGRootProperty();
2456 virtual bool StringToValue( wxVariant
&, const wxString
&, int ) const
2464 // -----------------------------------------------------------------------
2466 /** @class wxPropertyCategory
2468 Category (caption) property.
2470 class WXDLLIMPEXP_PROPGRID wxPropertyCategory
: public wxPGProperty
2472 friend class wxPropertyGrid
;
2473 friend class wxPropertyGridPageState
;
2474 WX_PG_DECLARE_PROPERTY_CLASS(wxPropertyCategory
)
2477 /** Default constructor is only used in special cases. */
2478 wxPropertyCategory();
2480 wxPropertyCategory( const wxString
& label
,
2481 const wxString
& name
= wxPG_LABEL
);
2482 ~wxPropertyCategory();
2484 int GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const;
2486 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
) const;
2489 void SetTextColIndex( unsigned int colInd
)
2490 { m_capFgColIndex
= (wxByte
) colInd
; }
2491 unsigned int GetTextColIndex() const
2492 { return (unsigned int) m_capFgColIndex
; }
2494 void CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
);
2496 int m_textExtent
; // pre-calculated length of text
2497 wxByte m_capFgColIndex
; // caption text colour index
2505 // -----------------------------------------------------------------------
2507 #endif // wxUSE_PROPGRID
2509 #endif // _WX_PROPGRID_PROPERTY_H_