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 licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PROPGRID_PROPERTY_H_
13 #define _WX_PROPGRID_PROPERTY_H_
17 #include "wx/propgrid/propgriddefs.h"
19 // -----------------------------------------------------------------------
21 #define wxNullProperty ((wxPGProperty*)NULL)
24 /** @class wxPGPaintData
26 Contains information relayed to property's OnCustomPaint.
30 /** wxPropertyGrid. */
31 const wxPropertyGrid
* m_parent
;
34 Normally -1, otherwise index to drop-down list item that has to be
39 /** Set to drawn width in OnCustomPaint (optional). */
43 In a measure item call, set this to the height of item at m_choiceItem
50 // space between vertical sides of a custom image
51 #define wxPG_CUSTOM_IMAGE_SPACINGY 1
53 // space between caption and selection rectangle,
54 #define wxPG_CAPRECTXMARGIN 2
56 // horizontally and vertically
57 #define wxPG_CAPRECTYMARGIN 1
60 /** @class wxPGCellRenderer
62 Base class for wxPropertyGrid cell renderers.
64 class WXDLLIMPEXP_PROPGRID wxPGCellRenderer
: public wxObjectRefData
69 : wxObjectRefData() { }
70 virtual ~wxPGCellRenderer() { }
75 // We are painting selected item
76 Selected
= 0x00010000,
78 // We are painting item in choice popup
79 ChoicePopup
= 0x00020000,
81 // We are rendering wxOwnerDrawnComboBox control
82 // (or other owner drawn control, but that is only
83 // officially supported one ATM).
86 // We are painting a disable property
87 Disabled
= 0x00080000,
89 // We are painting selected, disabled, or similar
90 // item that dictates fore- and background colours,
91 // overriding any cell values.
92 DontUseCellFgCol
= 0x00100000,
93 DontUseCellBgCol
= 0x00200000,
94 DontUseCellColours
= DontUseCellFgCol
|
99 Returns @true if rendered something in the foreground (text or
102 virtual bool Render( wxDC
& dc
,
104 const wxPropertyGrid
* propertyGrid
,
105 wxPGProperty
* property
,
108 int flags
) const = 0;
110 /** Returns size of the image in front of the editable area.
112 If property is NULL, then this call is for a custom value. In that case
113 the item is index to wxPropertyGrid's custom values.
115 virtual wxSize
GetImageSize( const wxPGProperty
* property
,
119 /** Paints property category selection rectangle.
121 virtual void DrawCaptionSelectionRect( wxDC
& dc
,
123 int w
, int h
) const;
125 /** Utility to draw vertically centered text.
127 void DrawText( wxDC
& dc
,
130 const wxString
& text
) const;
133 Utility to draw editor's value, or vertically aligned text if editor is
136 void DrawEditorValue( wxDC
& dc
, const wxRect
& rect
,
137 int xOffset
, const wxString
& text
,
138 wxPGProperty
* property
,
139 const wxPGEditor
* editor
) const;
141 /** Utility to render cell bitmap and set text colour plus bg brush
144 @return Returns image width, which, for instance, can be passed to
147 int PreDrawCell( wxDC
& dc
,
149 const wxPGCell
& cell
,
153 Utility to be called after drawing is done, to revert whatever
154 changes PreDrawCell() did.
157 Same as those passed to PreDrawCell().
159 void PostDrawCell( wxDC
& dc
,
160 const wxPropertyGrid
* propGrid
,
161 const wxPGCell
& cell
,
167 @class wxPGDefaultRenderer
169 Default cell renderer, that can handles the common
172 class WXDLLIMPEXP_PROPGRID wxPGDefaultRenderer
: public wxPGCellRenderer
175 virtual bool Render( wxDC
& dc
,
177 const wxPropertyGrid
* propertyGrid
,
178 wxPGProperty
* property
,
183 virtual wxSize
GetImageSize( const wxPGProperty
* property
,
191 class WXDLLIMPEXP_PROPGRID wxPGCellData
: public wxObjectRefData
193 friend class wxPGCell
;
197 void SetText( const wxString
& text
)
200 m_hasValidText
= true;
202 void SetBitmap( const wxBitmap
& bitmap
) { m_bitmap
= bitmap
; }
203 void SetFgCol( const wxColour
& col
) { m_fgCol
= col
; }
204 void SetBgCol( const wxColour
& col
) { m_bgCol
= col
; }
205 void SetFont( const wxFont
& font
) { m_font
= font
; }
208 virtual ~wxPGCellData() { }
216 // True if m_text is valid and specified
224 Base class for wxPropertyGrid cell information.
226 class WXDLLIMPEXP_PROPGRID wxPGCell
: public wxObject
230 wxPGCell(const wxPGCell
& other
)
235 wxPGCell( const wxString
& text
,
236 const wxBitmap
& bitmap
= wxNullBitmap
,
237 const wxColour
& fgCol
= wxNullColour
,
238 const wxColour
& bgCol
= wxNullColour
);
240 virtual ~wxPGCell() { }
242 wxPGCellData
* GetData()
244 return (wxPGCellData
*) m_refData
;
247 const wxPGCellData
* GetData() const
249 return (const wxPGCellData
*) m_refData
;
254 return (m_refData
&& GetData()->m_hasValidText
);
258 Sets empty but valid data to this cell object.
263 Merges valid data from srcCell into this.
265 void MergeFrom( const wxPGCell
& srcCell
);
267 void SetText( const wxString
& text
);
268 void SetBitmap( const wxBitmap
& bitmap
);
269 void SetFgCol( const wxColour
& col
);
272 Sets font of the cell.
274 @remarks Because wxPropertyGrid does not support rows of
275 different height, it makes little sense to change
276 size of the font. Therefore it is recommended
277 to use return value of wxPropertyGrid::GetFont()
278 or wxPropertyGrid::GetCaptionFont() as a basis
279 for the font that, after modifications, is passed
280 to this member function.
282 void SetFont( const wxFont
& font
);
284 void SetBgCol( const wxColour
& col
);
286 const wxString
& GetText() const { return GetData()->m_text
; }
287 const wxBitmap
& GetBitmap() const { return GetData()->m_bitmap
; }
288 const wxColour
& GetFgCol() const { return GetData()->m_fgCol
; }
291 Returns font of the cell. If no specific font is set for this
292 cell, then the font will be invalid.
294 const wxFont
& GetFont() const { return GetData()->m_font
; }
296 const wxColour
& GetBgCol() const { return GetData()->m_bgCol
; }
298 wxPGCell
& operator=( const wxPGCell
& other
)
300 if ( this != &other
)
308 virtual wxObjectRefData
*CreateRefData() const
309 { return new wxPGCellData(); }
311 virtual wxObjectRefData
*CloneRefData(const wxObjectRefData
*data
) const;
314 // -----------------------------------------------------------------------
316 /** @class wxPGAttributeStorage
318 wxPGAttributeStorage is somewhat optimized storage for
319 key=variant pairs (ie. a map).
321 class WXDLLIMPEXP_PROPGRID wxPGAttributeStorage
324 wxPGAttributeStorage();
325 ~wxPGAttributeStorage();
327 void Set( const wxString
& name
, const wxVariant
& value
);
328 unsigned int GetCount() const { return (unsigned int) m_map
.size(); }
329 wxVariant
FindValue( const wxString
& name
) const
331 wxPGHashMapS2P::const_iterator it
= m_map
.find(name
);
332 if ( it
!= m_map
.end() )
334 wxVariantData
* data
= (wxVariantData
*) it
->second
;
336 return wxVariant(data
, it
->first
);
341 typedef wxPGHashMapS2P::const_iterator const_iterator
;
342 const_iterator
StartIteration() const
344 return m_map
.begin();
346 bool GetNext( const_iterator
& it
, wxVariant
& variant
) const
348 if ( it
== m_map
.end() )
351 wxVariantData
* data
= (wxVariantData
*) it
->second
;
353 variant
.SetData(data
);
354 variant
.SetName(it
->first
);
360 wxPGHashMapS2P m_map
;
364 // -----------------------------------------------------------------------
366 /** @section propgrid_propflags wxPGProperty Flags
370 enum wxPGPropertyFlags
373 /** Indicates bold font.
375 wxPG_PROP_MODIFIED
= 0x0001,
377 /** Disables ('greyed' text and editor does not activate) property.
379 wxPG_PROP_DISABLED
= 0x0002,
381 /** Hider button will hide this property.
383 wxPG_PROP_HIDDEN
= 0x0004,
385 /** This property has custom paint image just in front of its value.
386 If property only draws custom images into a popup list, then this
387 flag should not be set.
389 wxPG_PROP_CUSTOMIMAGE
= 0x0008,
391 /** Do not create text based editor for this property (but button-triggered
392 dialog and choice are ok).
394 wxPG_PROP_NOEDITOR
= 0x0010,
396 /** Property is collapsed, ie. it's children are hidden.
398 wxPG_PROP_COLLAPSED
= 0x0020,
401 If property is selected, then indicates that validation failed for pending
404 If property is not selected, then indicates that the the actual property
405 value has failed validation (NB: this behavior is not currently supported,
406 but may be used in future).
408 wxPG_PROP_INVALID_VALUE
= 0x0040,
412 /** Switched via SetWasModified(). Temporary flag - only used when
413 setting/changing property value.
415 wxPG_PROP_WAS_MODIFIED
= 0x0200,
418 If set, then child properties (if any) are private, and should be
419 "invisible" to the application.
421 wxPG_PROP_AGGREGATE
= 0x0400,
423 /** If set, then child properties (if any) are copies and should not
426 wxPG_PROP_CHILDREN_ARE_COPIES
= 0x0800,
429 Classifies this item as a non-category.
431 Used for faster item type identification.
433 wxPG_PROP_PROPERTY
= 0x1000,
436 Classifies this item as a category.
438 Used for faster item type identification.
440 wxPG_PROP_CATEGORY
= 0x2000,
442 /** Classifies this item as a property that has children, but is not aggregate
443 (ie children are not private).
445 wxPG_PROP_MISC_PARENT
= 0x4000,
447 /** Property is read-only. Editor is still created for wxTextCtrl-based
448 property editors. For others, editor is not usually created because
449 they do implement wxTE_READONLY style or equivalent.
451 wxPG_PROP_READONLY
= 0x8000,
454 // NB: FLAGS ABOVE 0x8000 CANNOT BE USED WITH PROPERTY ITERATORS
457 /** Property's value is composed from values of child properties.
459 This flag cannot be used with property iterators.
461 wxPG_PROP_COMPOSED_VALUE
= 0x00010000,
463 /** Common value of property is selectable in editor.
465 This flag cannot be used with property iterators.
467 wxPG_PROP_USES_COMMON_VALUE
= 0x00020000,
469 /** Property can be set to unspecified value via editor.
470 Currently, this applies to following properties:
471 - wxIntProperty, wxUIntProperty, wxFloatProperty, wxEditEnumProperty:
475 This flag cannot be used with property iterators.
477 @see wxPGProperty::SetAutoUnspecified()
479 wxPG_PROP_AUTO_UNSPECIFIED
= 0x00040000,
481 /** Indicates the bit useable by derived properties.
483 wxPG_PROP_CLASS_SPECIFIC_1
= 0x00080000,
485 /** Indicates the bit useable by derived properties.
487 wxPG_PROP_CLASS_SPECIFIC_2
= 0x00100000,
489 /** Indicates that the property is being deleted and should be ignored.
491 wxPG_PROP_BEING_DELETED
= 0x00200000
497 #define wxPG_PROP_MAX wxPG_PROP_AUTO_UNSPECIFIED
499 /** Property with children must have one of these set, otherwise iterators
500 will not work correctly.
501 Code should automatically take care of this, however.
503 #define wxPG_PROP_PARENTAL_FLAGS \
504 ((wxPGPropertyFlags)(wxPG_PROP_AGGREGATE | \
505 wxPG_PROP_CATEGORY | \
506 wxPG_PROP_MISC_PARENT))
511 // Combination of flags that can be stored by GetFlagsAsString
512 #define wxPG_STRING_STORED_FLAGS \
513 (wxPG_PROP_DISABLED|wxPG_PROP_HIDDEN|wxPG_PROP_NOEDITOR|wxPG_PROP_COLLAPSED)
515 // -----------------------------------------------------------------------
518 @section propgrid_property_attributes wxPropertyGrid Property Attribute
521 wxPGProperty::SetAttribute() and
522 wxPropertyGridInterface::SetPropertyAttribute() accept one of these as
523 attribute name argument.
525 You can use strings instead of constants. However, some of these
526 constants are redefined to use cached strings which may reduce
527 your binary size by some amount.
532 /** Set default value for property.
534 #define wxPG_ATTR_DEFAULT_VALUE wxS("DefaultValue")
536 /** Universal, int or double. Minimum value for numeric properties.
538 #define wxPG_ATTR_MIN wxS("Min")
540 /** Universal, int or double. Maximum value for numeric properties.
542 #define wxPG_ATTR_MAX wxS("Max")
544 /** Universal, string. When set, will be shown as text after the displayed
545 text value. Alternatively, if third column is enabled, text will be shown
546 there (for any type of property).
548 #define wxPG_ATTR_UNITS wxS("Units")
550 /** When set, will be shown as 'greyed' text in property's value cell when
551 the actual displayed value is blank.
553 #define wxPG_ATTR_HINT wxS("Hint")
555 #if wxPG_COMPATIBILITY_1_4
557 @deprecated Use "Hint" (wxPG_ATTR_HINT) instead.
559 #define wxPG_ATTR_INLINE_HELP wxS("InlineHelp")
562 /** Universal, wxArrayString. Set to enable auto-completion in any
563 wxTextCtrl-based property editor.
565 #define wxPG_ATTR_AUTOCOMPLETE wxS("AutoComplete")
567 /** wxBoolProperty and wxFlagsProperty specific. Value type is bool.
568 Default value is False.
570 When set to True, bool property will use check box instead of a
571 combo box as its editor control. If you set this attribute
572 for a wxFlagsProperty, it is automatically applied to child
575 #define wxPG_BOOL_USE_CHECKBOX wxS("UseCheckbox")
577 /** wxBoolProperty and wxFlagsProperty specific. Value type is bool.
578 Default value is False.
580 Set to True for the bool property to cycle value on double click
581 (instead of showing the popup listbox). If you set this attribute
582 for a wxFlagsProperty, it is automatically applied to child
585 #define wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING wxS("UseDClickCycling")
588 wxFloatProperty (and similar) specific, int, default -1.
590 Sets the (max) precision used when floating point value is rendered as
591 text. The default -1 means infinite precision.
593 #define wxPG_FLOAT_PRECISION wxS("Precision")
596 The text will be echoed as asterisks (wxTE_PASSWORD will be passed to
599 #define wxPG_STRING_PASSWORD wxS("Password")
601 /** Define base used by a wxUIntProperty. Valid constants are
602 wxPG_BASE_OCT, wxPG_BASE_DEC, wxPG_BASE_HEX and wxPG_BASE_HEXL
603 (lowercase characters).
605 #define wxPG_UINT_BASE wxS("Base")
607 /** Define prefix rendered to wxUIntProperty. Accepted constants
608 wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and wxPG_PREFIX_DOLLAR_SIGN.
609 <b>Note:</b> Only wxPG_PREFIX_NONE works with Decimal and Octal
612 #define wxPG_UINT_PREFIX wxS("Prefix")
615 wxFileProperty/wxImageFileProperty specific, wxChar*, default is
617 Sets the wildcard used in the triggered wxFileDialog. Format is the same.
619 #define wxPG_FILE_WILDCARD wxS("Wildcard")
621 /** wxFileProperty/wxImageFileProperty specific, int, default 1.
622 When 0, only the file name is shown (i.e. drive and directory are hidden).
624 #define wxPG_FILE_SHOW_FULL_PATH wxS("ShowFullPath")
626 /** Specific to wxFileProperty and derived properties, wxString, default empty.
627 If set, then the filename is shown relative to the given path string.
629 #define wxPG_FILE_SHOW_RELATIVE_PATH wxS("ShowRelativePath")
632 Specific to wxFileProperty and derived properties, wxString, default is
635 Sets the initial path of where to look for files.
637 #define wxPG_FILE_INITIAL_PATH wxS("InitialPath")
639 /** Specific to wxFileProperty and derivatives, wxString, default is empty.
640 Sets a specific title for the dir dialog.
642 #define wxPG_FILE_DIALOG_TITLE wxS("DialogTitle")
644 /** Specific to wxDirProperty, wxString, default is empty.
645 Sets a specific message for the dir dialog.
647 #define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage")
650 wxArrayStringProperty's string delimiter character. If this is aquotation
651 mark or hyphen, then strings will be quoted instead (with given
654 Default delimiter is quotation mark.
656 #define wxPG_ARRAY_DELIMITER wxS("Delimiter")
658 /** Sets displayed date format for wxDateProperty.
660 #define wxPG_DATE_FORMAT wxS("DateFormat")
662 /** Sets wxDatePickerCtrl window style used with wxDateProperty. Default
663 is wxDP_DEFAULT | wxDP_SHOWCENTURY.
665 #define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
667 /** SpinCtrl editor, int or double. How much number changes when button is
668 pressed (or up/down on keybard).
670 #define wxPG_ATTR_SPINCTRL_STEP wxS("Step")
672 /** SpinCtrl editor, bool. If true, value wraps at Min/Max.
674 #define wxPG_ATTR_SPINCTRL_WRAP wxS("Wrap")
677 wxMultiChoiceProperty, int.
678 If 0, no user strings allowed. If 1, user strings appear before list
679 strings. If 2, user strings appear after list string.
681 #define wxPG_ATTR_MULTICHOICE_USERSTRINGMODE wxS("UserStringMode")
684 wxColourProperty and its kind, int, default 1.
686 Setting this attribute to 0 hides custom colour from property's list of
689 #define wxPG_COLOUR_ALLOW_CUSTOM wxS("AllowCustom")
694 // Redefine attribute macros to use cached strings
695 #undef wxPG_ATTR_DEFAULT_VALUE
696 #define wxPG_ATTR_DEFAULT_VALUE wxPGGlobalVars->m_strDefaultValue
698 #define wxPG_ATTR_MIN wxPGGlobalVars->m_strMin
700 #define wxPG_ATTR_MAX wxPGGlobalVars->m_strMax
701 #undef wxPG_ATTR_UNITS
702 #define wxPG_ATTR_UNITS wxPGGlobalVars->m_strUnits
703 #undef wxPG_ATTR_HINT
704 #define wxPG_ATTR_HINT wxPGGlobalVars->m_strHint
705 #if wxPG_COMPATIBILITY_1_4
706 #undef wxPG_ATTR_INLINE_HELP
707 #define wxPG_ATTR_INLINE_HELP wxPGGlobalVars->m_strInlineHelp
710 // -----------------------------------------------------------------------
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)
793 /** @class wxPGChoices
795 Helper class for managing choices of wxPropertyGrid properties.
796 Each entry can have label, value, bitmap, text colour, and background
799 wxPGChoices uses reference counting, similar to other wxWidgets classes.
800 This means that assignment operator and copy constructor only copy the
801 reference and not the actual data. Use Copy() member function to create a
804 @remarks If you do not specify value for entry, index is used.
809 class WXDLLIMPEXP_PROPGRID wxPGChoices
812 typedef long ValArrItem
;
814 /** Default constructor. */
821 Copy constructor, uses reference counting. To create a real copy,
822 use Copy() member function instead.
824 wxPGChoices( const wxPGChoices
& a
)
826 if ( a
.m_data
!= wxPGChoicesEmptyData
)
840 Values for choices. If NULL, indexes are used.
842 wxPGChoices( const wxChar
* const* labels
, const long* values
= NULL
)
855 Values for choices. If empty, indexes are used.
857 wxPGChoices( const wxArrayString
& labels
,
858 const wxArrayInt
& values
= wxArrayInt() )
864 /** Simple interface constructor. */
865 wxPGChoices( wxPGChoicesData
* data
)
881 If did not have own copies, creates them now. If was empty, identical
882 to set except that creates copies.
885 Labels for added choices.
888 Values for added choices. If empty, relevant entry indexes are used.
890 void Add( const wxChar
* const* labels
, const ValArrItem
* values
= NULL
);
892 /** Version that works with wxArrayString and wxArrayInt. */
893 void Add( const wxArrayString
& arr
, const wxArrayInt
& arrint
= wxArrayInt() );
896 Adds a single choice.
899 Label for added choice.
902 Value for added choice. If unspecified, index is used.
904 wxPGChoiceEntry
& Add( const wxString
& label
,
905 int value
= wxPG_INVALID_VALUE
);
907 /** Adds a single item, with bitmap. */
908 wxPGChoiceEntry
& Add( const wxString
& label
,
909 const wxBitmap
& bitmap
,
910 int value
= wxPG_INVALID_VALUE
);
912 /** Adds a single item with full entry information. */
913 wxPGChoiceEntry
& Add( const wxPGChoiceEntry
& entry
)
915 return Insert(entry
, -1);
918 /** Adds single item. */
919 wxPGChoiceEntry
& AddAsSorted( const wxString
& label
,
920 int value
= wxPG_INVALID_VALUE
);
923 Assigns choices data, using reference counting. To create a real copy,
924 use Copy() member function instead.
926 void Assign( const wxPGChoices
& a
)
928 AssignData(a
.m_data
);
931 void AssignData( wxPGChoicesData
* data
);
933 /** Delete all choices. */
937 Returns a real copy of the choices.
939 wxPGChoices
Copy() const
943 dst
.m_data
->CopyDataFrom(m_data
);
949 if ( m_data
== wxPGChoicesEmptyData
)
950 m_data
= new wxPGChoicesData();
953 /** Gets a unsigned number identifying this list. */
954 wxPGChoicesId
GetId() const { return (wxPGChoicesId
) m_data
; };
956 const wxString
& GetLabel( unsigned int ind
) const
958 return Item(ind
).GetText();
961 unsigned int GetCount () const
966 return m_data
->GetCount();
969 int GetValue( unsigned int ind
) const { return Item(ind
).GetValue(); }
971 /** Returns array of values matching the given strings. Unmatching strings
972 result in wxPG_INVALID_VALUE entry in array.
974 wxArrayInt
GetValuesForStrings( const wxArrayString
& strings
) const;
976 /** Returns array of indices matching given strings. Unmatching strings
977 are added to 'unmatched', if not NULL.
979 wxArrayInt
GetIndicesForStrings( const wxArrayString
& strings
,
980 wxArrayString
* unmatched
= NULL
) const;
982 int Index( const wxString
& str
) const;
983 int Index( int val
) const;
985 /** Inserts single item. */
986 wxPGChoiceEntry
& Insert( const wxString
& label
,
988 int value
= wxPG_INVALID_VALUE
);
990 /** Inserts a single item with full entry information. */
991 wxPGChoiceEntry
& Insert( const wxPGChoiceEntry
& entry
, int index
);
993 /** Returns false if this is a constant empty set of choices,
994 which should not be modified.
998 return ( m_data
!= wxPGChoicesEmptyData
);
1001 const wxPGChoiceEntry
& Item( unsigned int i
) const
1004 return m_data
->Item(i
);
1007 wxPGChoiceEntry
& Item( unsigned int i
)
1010 return m_data
->Item(i
);
1013 /** Removes count items starting at position nIndex. */
1014 void RemoveAt(size_t nIndex
, size_t count
= 1);
1016 /** Does not create copies for itself.
1019 void Set( const wxChar
* const* labels
, const long* values
= NULL
)
1025 /** Version that works with wxArrayString and wxArrayInt. */
1026 void Set( const wxArrayString
& labels
,
1027 const wxArrayInt
& values
= wxArrayInt() )
1036 // Creates exclusive copy of current choices
1037 void AllocExclusive();
1039 // Returns data, increases refcount.
1040 wxPGChoicesData
* GetData()
1042 wxASSERT( m_data
->GetRefCount() != -1 );
1047 // Returns plain data ptr - no refcounting stuff is done.
1048 wxPGChoicesData
* GetDataPtr() const { return m_data
; }
1050 // Changes ownership of data to you.
1051 wxPGChoicesData
* ExtractData()
1053 wxPGChoicesData
* data
= m_data
;
1054 m_data
= wxPGChoicesEmptyData
;
1058 wxArrayString
GetLabels() const;
1060 void operator= (const wxPGChoices
& a
)
1063 AssignData(a
.m_data
);
1066 wxPGChoiceEntry
& operator[](unsigned int i
)
1071 const wxPGChoiceEntry
& operator[](unsigned int i
) const
1077 wxPGChoicesData
* m_data
;
1083 // -----------------------------------------------------------------------
1085 /** @class wxPGProperty
1087 wxPGProperty is base class for all wxPropertyGrid properties.
1089 NB: Full class overview is now only present in
1090 interface/wx/propgrid/property.h.
1092 @library{wxpropgrid}
1095 class WXDLLIMPEXP_PROPGRID wxPGProperty
: public wxObject
1097 friend class wxPropertyGrid
;
1098 friend class wxPropertyGridInterface
;
1099 friend class wxPropertyGridPageState
;
1100 friend class wxPropertyGridPopulator
;
1101 friend class wxStringProperty
; // Proper "<composed>" support requires this
1103 DECLARE_ABSTRACT_CLASS(wxPGProperty
)
1105 typedef wxUint32 FlagType
;
1108 Default constructor.
1115 All non-abstract property classes should have a constructor with
1116 the same first two arguments as this one.
1118 wxPGProperty( const wxString
& label
, const wxString
& name
);
1122 It is customary for derived properties to implement this.
1124 virtual ~wxPGProperty();
1126 /** This virtual function is called after m_value has been set.
1129 - If m_value was set to Null variant (ie. unspecified value),
1130 OnSetValue() will not be called.
1131 - m_value may be of any variant type. Typically properties internally
1132 support only one variant type, and as such OnSetValue() provides a
1133 good opportunity to convert
1134 supported values into internal type.
1135 - Default implementation does nothing.
1137 virtual void OnSetValue();
1139 /** Override this to return something else than m_value as the value.
1141 virtual wxVariant
DoGetValue() const { return m_value
; }
1143 /** Implement this function in derived class to check the value.
1144 Return true if it is ok. Returning false prevents property change events
1148 - Default implementation always returns true.
1150 virtual bool ValidateValue( wxVariant
& value
,
1151 wxPGValidationInfo
& validationInfo
) const;
1154 Converts text into wxVariant value appropriate for this property.
1157 On function entry this is the old value (should not be wxNullVariant
1158 in normal cases). Translated value must be assigned back to it.
1161 Text to be translated into variant.
1164 If wxPG_FULL_VALUE is set, returns complete, storable value instead
1165 of displayable one (they may be different).
1166 If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of
1167 composite property string value (as generated by ValueToString()
1168 called with this same flag).
1170 @return Returns @true if resulting wxVariant value was different.
1172 @remarks Default implementation converts semicolon delimited tokens into
1173 child values. Only works for properties with children.
1175 You might want to take into account that m_value is Null variant
1176 if property value is unspecified (which is usually only case if
1177 you explicitly enabled that sort behavior).
1179 virtual bool StringToValue( wxVariant
& variant
,
1180 const wxString
& text
,
1181 int argFlags
= 0 ) const;
1184 Converts integer (possibly a choice selection) into wxVariant value
1185 appropriate for this property.
1188 On function entry this is the old value (should not be wxNullVariant
1189 in normal cases). Translated value must be assigned back to it.
1192 Integer to be translated into variant.
1195 If wxPG_FULL_VALUE is set, returns complete, storable value instead
1198 @return Returns @true if resulting wxVariant value was different.
1201 - If property is not supposed to use choice or spinctrl or other editor
1202 with int-based value, it is not necessary to implement this method.
1203 - Default implementation simply assign given int to m_value.
1204 - If property uses choice control, and displays a dialog on some choice
1205 items, then it is preferred to display that dialog in IntToValue
1207 - You might want to take into account that m_value is Null variant if
1208 property value is unspecified (which is usually only case if you
1209 explicitly enabled that sort behavior).
1211 virtual bool IntToValue( wxVariant
& value
,
1213 int argFlags
= 0 ) const;
1216 Converts property value into a text representation.
1219 Value to be converted.
1222 If 0 (default value), then displayed string is returned.
1223 If wxPG_FULL_VALUE is set, returns complete, storable string value
1224 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
1225 string value that must be editable in textctrl. If
1226 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
1227 display as a part of string property's composite text
1230 @remarks Default implementation calls GenerateComposedValue().
1232 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
1234 /** Converts string to a value, and if successful, calls SetValue() on it.
1235 Default behavior is to do nothing.
1237 String to get the value from.
1239 true if value was changed.
1241 bool SetValueFromString( const wxString
& text
, int flags
= wxPG_PROGRAMMATIC_VALUE
);
1243 /** Converts integer to a value, and if succesful, calls SetValue() on it.
1244 Default behavior is to do nothing.
1246 Int to get the value from.
1248 If has wxPG_FULL_VALUE, then the value given is a actual value and
1251 True if value was changed.
1253 bool SetValueFromInt( long value
, int flags
= 0 );
1256 Returns size of the custom painted image in front of property.
1258 This method must be overridden to return non-default value if
1259 OnCustomPaint is to be called.
1261 Normally -1, but can be an index to the property's list of items.
1263 - Default behavior is to return wxSize(0,0), which means no image.
1264 - Default image width or height is indicated with dimension -1.
1265 - You can also return wxPG_DEFAULT_IMAGE_SIZE, i.e. wxSize(-1, -1).
1267 virtual wxSize
OnMeasureImage( int item
= -1 ) const;
1270 Events received by editor widgets are processed here.
1272 Note that editor class usually processes most events. Some, such as
1273 button press events of TextCtrlAndButton class, can be handled here.
1274 Also, if custom handling for regular events is desired, then that can
1275 also be done (for example, wxSystemColourProperty custom handles
1276 wxEVT_COMMAND_CHOICE_SELECTED to display colour picker dialog when
1277 'custom' selection is made).
1279 If the event causes value to be changed, SetValueInEvent()
1280 should be called to set the new value.
1285 Should return true if any changes in value should be reported.
1287 If property uses choice control, and displays a dialog on some choice
1288 items, then it is preferred to display that dialog in IntToValue
1291 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
1292 wxWindow
* wnd_primary
,
1296 Called after value of a child property has been altered. Must return
1297 new value of the whole property (after any alterations warrented by
1300 Note that this function is usually called at the time that value of
1301 this property, or given child property, is still pending for change,
1302 and as such, result of GetValue() or m_value should not be relied
1305 Sample pseudo-code implementation:
1308 wxVariant MyProperty::ChildChanged( wxVariant& thisValue,
1310 wxVariant& childValue ) const
1312 // Acquire reference to actual type of data stored in variant
1313 // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros
1314 // were used to create the variant class).
1315 T& data = TFromVariant(thisValue);
1317 // Copy childValue into data.
1318 switch ( childIndex )
1321 data.SetSubProp1( childvalue.GetLong() );
1324 data.SetSubProp2( childvalue.GetString() );
1329 // Return altered data
1335 Value of this property. Changed value should be returned (in
1336 previous versions of wxPropertyGrid it was only necessary to
1337 write value back to this argument).
1339 Index of child changed (you can use Item(childIndex) to get
1342 (Pending) value of the child property.
1345 Modified value of the whole property.
1347 virtual wxVariant
ChildChanged( wxVariant
& thisValue
,
1349 wxVariant
& childValue
) const;
1351 /** Returns pointer to an instance of used editor.
1353 virtual const wxPGEditor
* DoGetEditorClass() const;
1355 /** Returns pointer to the wxValidator that should be used
1356 with the editor of this property (NULL for no validator).
1357 Setting validator explicitly via SetPropertyValidator
1360 In most situations, code like this should work well
1361 (macros are used to maintain one actual validator instance,
1362 so on the second call the function exits within the first
1367 wxValidator* wxMyPropertyClass::DoGetValidator () const
1369 WX_PG_DOGETVALIDATOR_ENTRY()
1371 wxMyValidator* validator = new wxMyValidator(...);
1373 ... prepare validator...
1375 WX_PG_DOGETVALIDATOR_EXIT(validator)
1381 You can get common filename validator by returning
1382 wxFileProperty::GetClassValidator(). wxDirProperty,
1383 for example, uses it.
1385 virtual wxValidator
* DoGetValidator () const;
1388 Override to paint an image in front of the property value text or
1389 drop-down list item (but only if wxPGProperty::OnMeasureImage is
1390 overridden as well).
1392 If property's OnMeasureImage() returns size that has height != 0 but
1393 less than row height ( < 0 has special meanings), wxPropertyGrid calls
1394 this method to draw a custom image in a limited area in front of the
1395 editor control or value text/graphics, and if control has drop-down
1396 list, then the image is drawn there as well (even in the case
1397 OnMeasureImage() returned higher height than row height).
1399 NOTE: Following applies when OnMeasureImage() returns a "flexible"
1400 height ( using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable
1401 height items: If rect.x is < 0, then this is a measure item call, which
1402 means that dc is invalid and only thing that should be done is to set
1403 paintdata.m_drawnHeight to the height of the image of item at index
1404 paintdata.m_choiceItem. This call may be done even as often as once
1405 every drop-down popup show.
1410 Box reserved for custom graphics. Includes surrounding rectangle,
1411 if any. If x is < 0, then this is a measure item call (see above).
1413 wxPGPaintData structure with much useful data.
1416 - You can actually exceed rect width, but if you do so then
1417 paintdata.m_drawnWidth must be set to the full width drawn in
1419 - Due to technical reasons, rect's height will be default even if
1420 custom height was reported during measure call.
1421 - Brush is guaranteed to be default background colour. It has been
1422 already used to clear the background of area being painted. It
1424 - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper
1425 colour) pen for drawing framing rectangle. It can be changed as
1428 @see ValueToString()
1430 virtual void OnCustomPaint( wxDC
& dc
,
1432 wxPGPaintData
& paintdata
);
1435 Returns used wxPGCellRenderer instance for given property column
1438 Default implementation returns editor's renderer for all columns.
1440 virtual wxPGCellRenderer
* GetCellRenderer( int column
) const;
1442 /** Returns which choice is currently selected. Only applies to properties
1445 Needs to reimplemented in derived class if property value does not
1446 map directly to a choice. Integer as index, bool, and string usually do.
1448 virtual int GetChoiceSelection() const;
1451 Refresh values of child properties.
1453 Automatically called after value is set.
1455 virtual void RefreshChildren();
1458 Reimplement this member function to add special handling for
1459 attributes of this property.
1461 @return Return @false to have the attribute automatically stored in
1462 m_attributes. Default implementation simply does that and
1465 @remarks To actually set property attribute values from the
1466 application, use wxPGProperty::SetAttribute() instead.
1468 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
1470 /** Returns value of an attribute.
1472 Override if custom handling of attributes is needed.
1474 Default implementation simply return NULL variant.
1476 virtual wxVariant
DoGetAttribute( const wxString
& name
) const;
1478 /** Returns instance of a new wxPGEditorDialogAdapter instance, which is
1479 used when user presses the (optional) button next to the editor control;
1481 Default implementation returns NULL (ie. no action is generated when
1484 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
1487 Called whenever validation has failed with given pending value.
1489 @remarks If you implement this in your custom property class, please
1490 remember to call the baser implementation as well, since they
1491 may use it to revert property into pre-change state.
1493 virtual void OnValidationFailure( wxVariant
& pendingValue
);
1495 /** Append a new choice to property's list of choices.
1497 int AddChoice( const wxString
& label
, int value
= wxPG_INVALID_VALUE
)
1499 return InsertChoice(label
, wxNOT_FOUND
, value
);
1503 Returns true if children of this property are component values (for
1504 instance, points size, face name, and is_underlined are component
1507 bool AreChildrenComponents() const
1509 if ( m_flags
& (wxPG_PROP_COMPOSED_VALUE
|wxPG_PROP_AGGREGATE
) )
1516 Deletes children of the property.
1518 void DeleteChildren();
1521 Removes entry from property's wxPGChoices and editor control (if it is
1524 If selected item is deleted, then the value is set to unspecified.
1526 void DeleteChoice( int index
);
1529 Enables or disables the property. Disabled property usually appears
1530 as having grey text.
1533 If @false, property is disabled instead.
1535 @see wxPropertyGridInterface::EnableProperty()
1537 void Enable( bool enable
= true );
1540 Call to enable or disable usage of common value (integer value that can
1541 be selected for properties instead of their normal values) for this
1544 Common values are disabled by the default for all properties.
1546 void EnableCommonValue( bool enable
= true )
1548 if ( enable
) SetFlag( wxPG_PROP_USES_COMMON_VALUE
);
1549 else ClearFlag( wxPG_PROP_USES_COMMON_VALUE
);
1553 Composes text from values of child properties.
1555 wxString
GenerateComposedValue() const
1558 DoGenerateComposedValue(s
);
1562 /** Returns property's label. */
1563 const wxString
& GetLabel() const { return m_label
; }
1565 /** Returns property's name with all (non-category, non-root) parents. */
1566 wxString
GetName() const;
1569 Returns property's base name (ie parent's name is not added in any
1572 const wxString
& GetBaseName() const { return m_name
; }
1574 /** Returns read-only reference to property's list of choices.
1576 const wxPGChoices
& GetChoices() const
1581 /** Returns coordinate to the top y of the property. Note that the
1582 position of scrollbars is not taken into account.
1586 wxVariant
GetValue() const
1588 return DoGetValue();
1591 /** Returns reference to the internal stored value. GetValue is preferred
1592 way to get the actual value, since GetValueRef ignores DoGetValue,
1593 which may override stored value.
1595 wxVariant
& GetValueRef()
1600 const wxVariant
& GetValueRef() const
1605 // Helper function (for wxPython bindings and such) for settings protected
1607 wxVariant
GetValuePlain() const
1612 /** Returns text representation of property's value.
1615 If 0 (default value), then displayed string is returned.
1616 If wxPG_FULL_VALUE is set, returns complete, storable string value
1617 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
1618 string value that must be editable in textctrl. If
1619 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
1620 display as a part of string property's composite text
1623 @remarks In older versions, this function used to be overridden to convert
1624 property's value into a string representation. This function is
1625 now handled by ValueToString(), and overriding this function now
1626 will result in run-time assertion failure.
1628 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
1630 /** Synonymous to GetValueAsString().
1632 @deprecated Use GetValueAsString() instead.
1634 @see GetValueAsString()
1636 wxDEPRECATED( wxString
GetValueString( int argFlags
= 0 ) const );
1639 Returns wxPGCell of given column.
1641 @remarks const version of this member function returns 'default'
1642 wxPGCell object if the property itself didn't hold
1645 const wxPGCell
& GetCell( unsigned int column
) const;
1648 Returns wxPGCell of given column, creating one if necessary.
1650 wxPGCell
& GetCell( unsigned int column
)
1652 return GetOrCreateCell(column
);
1656 Returns wxPGCell of given column, creating one if necessary.
1658 wxPGCell
& GetOrCreateCell( unsigned int column
);
1660 /** Return number of displayed common values for this property.
1662 int GetDisplayedCommonValueCount() const;
1664 wxString
GetDisplayedString() const
1666 return GetValueAsString(0);
1670 Returns property's hint text (shown in empty value cell).
1672 inline wxString
GetHintText() const;
1674 /** Returns property grid where property lies. */
1675 wxPropertyGrid
* GetGrid() const;
1677 /** Returns owner wxPropertyGrid, but only if one is currently on a page
1678 displaying this property. */
1679 wxPropertyGrid
* GetGridIfDisplayed() const;
1681 /** Returns highest level non-category, non-root parent. Useful when you
1682 have nested wxCustomProperties/wxParentProperties.
1684 Thus, if immediate parent is root or category, this will return the
1687 wxPGProperty
* GetMainParent() const;
1689 /** Return parent of property */
1690 wxPGProperty
* GetParent() const { return m_parent
; }
1692 /** Returns true if property has editable wxTextCtrl when selected.
1695 Altough disabled properties do not displayed editor, they still
1696 return True here as being disabled is considered a temporary
1697 condition (unlike being read-only or having limited editing enabled).
1699 bool IsTextEditable() const;
1701 bool IsValueUnspecified() const
1703 return m_value
.IsNull();
1707 Returns non-zero if property has given flag set.
1709 @see propgrid_propflags
1711 FlagType
HasFlag( wxPGPropertyFlags flag
) const
1713 return ( m_flags
& flag
);
1716 /** Returns comma-delimited string of property attributes.
1718 const wxPGAttributeStorage
& GetAttributes() const
1720 return m_attributes
;
1723 /** Returns m_attributes as list wxVariant.
1725 wxVariant
GetAttributesAsList() const;
1728 Returns property flags.
1730 FlagType
GetFlags() const
1735 const wxPGEditor
* GetEditorClass() const;
1737 wxString
GetValueType() const
1739 return m_value
.GetType();
1742 /** Returns editor used for given column. NULL for no editor.
1744 const wxPGEditor
* GetColumnEditor( int column
) const
1747 return GetEditorClass();
1752 /** Returns common value selected for this property. -1 for none.
1754 int GetCommonValue() const
1756 return m_commonValue
;
1759 /** Returns true if property has even one visible child.
1761 bool HasVisibleChildren() const;
1764 Use this member function to add independent (ie. regular) children to
1767 @return Inserted childProperty.
1769 @remarks wxPropertyGrid is not automatically refreshed by this
1772 @see AddPrivateChild()
1774 wxPGProperty
* InsertChild( int index
, wxPGProperty
* childProperty
);
1776 /** Inserts a new choice to property's list of choices.
1778 int InsertChoice( const wxString
& label
, int index
, int value
= wxPG_INVALID_VALUE
);
1781 Returns true if this property is actually a wxPropertyCategory.
1783 bool IsCategory() const { return HasFlag(wxPG_PROP_CATEGORY
)?true:false; }
1785 /** Returns true if this property is actually a wxRootProperty.
1787 bool IsRoot() const { return (m_parent
== NULL
); }
1789 /** Returns true if this is a sub-property. */
1790 bool IsSubProperty() const
1792 wxPGProperty
* parent
= (wxPGProperty
*)m_parent
;
1793 if ( parent
&& !parent
->IsCategory() )
1798 /** Returns last visible sub-property, recursively.
1800 const wxPGProperty
* GetLastVisibleSubItem() const;
1802 wxVariant
GetDefaultValue() const;
1804 int GetMaxLength() const
1806 return (int) m_maxLen
;
1810 Determines, recursively, if all children are not unspecified.
1813 Assumes members in this wxVariant list as pending
1816 bool AreAllChildrenSpecified( wxVariant
* pendingList
= NULL
) const;
1818 /** Updates composed values of parent non-category properties, recursively.
1819 Returns topmost property updated.
1822 - Must not call SetValue() (as can be called in it).
1824 wxPGProperty
* UpdateParentValues();
1826 /** Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
1828 bool UsesAutoUnspecified() const
1830 return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED
)?true:false;
1833 wxBitmap
* GetValueImage() const
1835 return m_valueBitmap
;
1838 wxVariant
GetAttribute( const wxString
& name
) const;
1841 Returns named attribute, as string, if found.
1843 Otherwise defVal is returned.
1845 wxString
GetAttribute( const wxString
& name
, const wxString
& defVal
) const;
1848 Returns named attribute, as long, if found.
1850 Otherwise defVal is returned.
1852 long GetAttributeAsLong( const wxString
& name
, long defVal
) const;
1855 Returns named attribute, as double, if found.
1857 Otherwise defVal is returned.
1859 double GetAttributeAsDouble( const wxString
& name
, double defVal
) const;
1861 unsigned int GetDepth() const { return (unsigned int)m_depth
; }
1863 /** Gets flags as a'|' delimited string. Note that flag names are not
1864 prepended with 'wxPG_PROP_'.
1866 String will only be made to include flags combined by this parameter.
1868 wxString
GetFlagsAsString( FlagType flagsMask
) const;
1870 /** Returns position in parent's array. */
1871 unsigned int GetIndexInParent() const
1873 return (unsigned int)m_arrIndex
;
1876 /** Hides or reveals the property.
1878 true for hide, false for reveal.
1880 By default changes are applied recursively. Set this paramter
1881 wxPG_DONT_RECURSE to prevent this.
1883 bool Hide( bool hide
, int flags
= wxPG_RECURSE
);
1885 bool IsExpanded() const
1886 { return (!(m_flags
& wxPG_PROP_COLLAPSED
) && GetChildCount()); }
1888 /** Returns true if all parents expanded.
1890 bool IsVisible() const;
1892 bool IsEnabled() const { return !(m_flags
& wxPG_PROP_DISABLED
); }
1894 /** If property's editor is created this forces its recreation.
1895 Useful in SetAttribute etc. Returns true if actually did anything.
1897 bool RecreateEditor();
1899 /** If property's editor is active, then update it's value.
1901 void RefreshEditor();
1903 /** Sets an attribute for this property.
1905 Text identifier of attribute. See @ref propgrid_property_attributes.
1909 void SetAttribute( const wxString
& name
, wxVariant value
);
1911 void SetAttributes( const wxPGAttributeStorage
& attributes
);
1914 Set if user can change the property's value to unspecified by
1915 modifying the value of the editor control (usually by clearing
1916 it). Currently, this can work with following properties:
1917 wxIntProperty, wxUIntProperty, wxFloatProperty, wxEditEnumProperty.
1920 Whether to enable or disable this behavior (it is disabled by
1923 void SetAutoUnspecified( bool enable
= true )
1925 ChangeFlag(wxPG_PROP_AUTO_UNSPECIFIED
, enable
);
1929 Sets property's background colour.
1932 Background colour to use.
1935 Default is wxPG_RECURSE which causes colour to be set recursively.
1936 Omit this flag to only set colour for the property in question
1937 and not any of its children.
1939 void SetBackgroundColour( const wxColour
& colour
,
1940 int flags
= wxPG_RECURSE
);
1943 Sets property's text colour.
1949 Default is wxPG_RECURSE which causes colour to be set recursively.
1950 Omit this flag to only set colour for the property in question
1951 and not any of its children.
1953 void SetTextColour( const wxColour
& colour
,
1954 int flags
= wxPG_RECURSE
);
1956 /** Set default value of a property. Synonymous to
1959 SetAttribute("DefaultValue", value);
1962 void SetDefaultValue( wxVariant
& value
);
1964 /** Sets editor for a property.
1967 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1968 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full
1971 For custom editors, use pointer you received from
1972 wxPropertyGrid::RegisterEditorClass().
1974 void SetEditor( const wxPGEditor
* editor
)
1976 m_customEditor
= editor
;
1979 /** Sets editor for a property.
1981 inline void SetEditor( const wxString
& editorName
);
1984 Sets cell information for given column.
1986 void SetCell( int column
, const wxPGCell
& cell
);
1988 /** Sets common value selected for this property. -1 for none.
1990 void SetCommonValue( int commonValue
)
1992 m_commonValue
= commonValue
;
1995 /** Sets flags from a '|' delimited string. Note that flag names are not
1996 prepended with 'wxPG_PROP_'.
1998 void SetFlagsFromString( const wxString
& str
);
2000 /** Sets property's "is it modified?" flag. Affects children recursively.
2002 void SetModifiedStatus( bool modified
)
2004 SetFlagRecursively(wxPG_PROP_MODIFIED
, modified
);
2007 /** Call in OnEvent(), OnButtonClick() etc. to change the property value
2008 based on user input.
2011 This method is const since it doesn't actually modify value, but posts
2012 given variant as pending value, stored in wxPropertyGrid.
2014 void SetValueInEvent( wxVariant value
) const;
2017 Call this to set value of the property.
2019 Unlike methods in wxPropertyGrid, this does not automatically update
2023 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run
2024 through validation process and send property change event.
2026 If you need to change property value in event, based on user input, use
2027 SetValueInEvent() instead.
2030 Pointer to list variant that contains child values. Used to
2031 indicate which children should be marked as modified.
2034 Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR, which is
2035 enabled by default).
2037 void SetValue( wxVariant value
, wxVariant
* pList
= NULL
,
2038 int flags
= wxPG_SETVAL_REFRESH_EDITOR
);
2040 /** Set wxBitmap in front of the value. This bitmap may be ignored
2041 by custom cell renderers.
2043 void SetValueImage( wxBitmap
& bmp
);
2045 /** Sets selected choice and changes property value.
2047 Tries to retain value type, although currently if it is not string,
2048 then it is forced to integer.
2050 void SetChoiceSelection( int newValue
);
2052 void SetExpanded( bool expanded
)
2054 if ( !expanded
) m_flags
|= wxPG_PROP_COLLAPSED
;
2055 else m_flags
&= ~wxPG_PROP_COLLAPSED
;
2059 Sets or clears given property flag. Mainly for internal use.
2061 @remarks Setting a property flag never has any side-effect, and is
2062 intended almost exclusively for internal use. So, for
2063 example, if you want to disable a property, call
2064 Enable(false) instead of setting wxPG_PROP_DISABLED flag.
2066 @see HasFlag(), GetFlags()
2068 void ChangeFlag( wxPGPropertyFlags flag
, bool set
)
2077 Sets or clears given property flag, recursively. This function is
2078 primarily intended for internal use.
2082 void SetFlagRecursively( wxPGPropertyFlags flag
, bool set
);
2084 void SetHelpString( const wxString
& helpString
)
2086 m_helpString
= helpString
;
2089 void SetLabel( const wxString
& label
) { m_label
= label
; }
2091 void SetName( const wxString
& newName
);
2094 Changes what sort of parent this property is for its children.
2097 Use one of the following values: wxPG_PROP_MISC_PARENT (for
2098 generic parents), wxPG_PROP_CATEGORY (for categories), or
2099 wxPG_PROP_AGGREGATE (for derived property classes with private
2102 @remarks You generally do not need to call this function.
2104 void SetParentalType( int flag
)
2106 m_flags
&= ~(wxPG_PROP_PROPERTY
|wxPG_PROP_PARENTAL_FLAGS
);
2110 void SetValueToUnspecified()
2112 wxVariant val
; // Create NULL variant
2113 SetValue(val
, NULL
, wxPG_SETVAL_REFRESH_EDITOR
);
2116 // Helper function (for wxPython bindings and such) for settings protected
2118 void SetValuePlain( wxVariant value
)
2123 #if wxUSE_VALIDATORS
2124 /** Sets wxValidator for a property*/
2125 void SetValidator( const wxValidator
& validator
)
2127 m_validator
= wxDynamicCast(validator
.Clone(),wxValidator
);
2130 /** Gets assignable version of property's validator. */
2131 wxValidator
* GetValidator() const
2135 return DoGetValidator();
2137 #endif // wxUSE_VALIDATORS
2139 /** Returns client data (void*) of a property.
2141 void* GetClientData() const
2143 return m_clientData
;
2146 /** Sets client data (void*) of a property.
2148 This untyped client data has to be deleted manually.
2150 void SetClientData( void* clientData
)
2152 m_clientData
= clientData
;
2155 /** Returns client object of a property.
2157 void SetClientObject(wxClientData
* clientObject
)
2159 delete m_clientObject
;
2160 m_clientObject
= clientObject
;
2163 /** Sets managed client object of a property.
2165 wxClientData
*GetClientObject() const { return m_clientObject
; }
2168 Sets new set of choices for the property.
2170 @remarks This operation deselects the property and clears its
2173 bool SetChoices( const wxPGChoices
& choices
);
2175 /** Set max length of text in text editor.
2177 inline bool SetMaxLength( int maxLen
);
2179 /** Call with 'false' in OnSetValue to cancel value changes after all
2180 (ie. cancel 'true' returned by StringToValue() or IntToValue()).
2182 void SetWasModified( bool set
= true )
2184 if ( set
) m_flags
|= wxPG_PROP_WAS_MODIFIED
;
2185 else m_flags
&= ~wxPG_PROP_WAS_MODIFIED
;
2188 const wxString
& GetHelpString() const
2190 return m_helpString
;
2193 // Use, for example, to detect if item is inside collapsed section.
2194 bool IsSomeParent( wxPGProperty
* candidate_parent
) const;
2197 Adapts list variant into proper value using consecutive
2200 void AdaptListToValue( wxVariant
& list
, wxVariant
* value
) const;
2202 #if wxPG_COMPATIBILITY_1_4
2204 Adds a private child property.
2206 @deprecated Use AddPrivateChild() instead.
2208 @see AddPrivateChild()
2210 wxDEPRECATED( void AddChild( wxPGProperty
* prop
) );
2214 Adds a private child property. If you use this instead of
2215 wxPropertyGridInterface::Insert() or
2216 wxPropertyGridInterface::AppendIn(), then property's parental
2217 type will automatically be set up to wxPG_PROP_AGGREGATE. In other
2218 words, all properties of this property will become private.
2220 void AddPrivateChild( wxPGProperty
* prop
);
2223 Appends a new child property.
2225 wxPGProperty
* AppendChild( wxPGProperty
* prop
)
2227 return InsertChild(-1, prop
);
2230 /** Returns height of children, recursively, and
2231 by taking expanded/collapsed status into account.
2233 iMax is used when finding property y-positions.
2235 int GetChildrenHeight( int lh
, int iMax
= -1 ) const;
2237 /** Returns number of child properties */
2238 unsigned int GetChildCount() const
2240 return (unsigned int) m_children
.size();
2243 /** Returns sub-property at index i. */
2244 wxPGProperty
* Item( unsigned int i
) const
2245 { return m_children
[i
]; }
2247 /** Returns last sub-property.
2249 wxPGProperty
* Last() const { return m_children
.back(); }
2251 /** Returns index of given child property. */
2252 int Index( const wxPGProperty
* p
) const;
2254 // Puts correct indexes to children
2255 void FixIndicesOfChildren( unsigned int starthere
= 0 );
2258 Converts image width into full image offset, with margins.
2260 int GetImageOffset( int imageWidth
) const;
2262 // Returns wxPropertyGridPageState in which this property resides.
2263 wxPropertyGridPageState
* GetParentState() const { return m_parentState
; }
2265 wxPGProperty
* GetItemAtY( unsigned int y
,
2267 unsigned int* nextItemY
) const;
2269 /** Returns property at given virtual y coordinate.
2271 wxPGProperty
* GetItemAtY( unsigned int y
) const;
2273 /** Returns (direct) child property with given name (or NULL if not found).
2275 wxPGProperty
* GetPropertyByName( const wxString
& name
) const;
2277 // Returns various display-related information for given column
2278 void GetDisplayInfo( unsigned int column
,
2282 const wxPGCell
** pCell
);
2284 static wxString
* sm_wxPG_LABEL
;
2286 /** This member is public so scripting language bindings
2287 wrapper code can access it freely.
2294 Sets property cell in fashion that reduces number of exclusive
2295 copies of cell data. Used when setting, for instance, same
2296 background colour for a number of properties.
2299 First column to affect.
2302 Last column to affect.
2305 Pre-prepared cell that is used for those which cell data
2306 before this matched unmodCellData.
2309 If unmodCellData did not match, valid cell data from this
2310 is merged into cell (usually generating new exclusive copy
2313 @param unmodCellData
2314 If cell's cell data matches this, its cell is now set to
2317 @param ignoreWithFlags
2318 Properties with any one of these flags are skipped.
2321 If @true, apply this operation recursively in child properties.
2323 void AdaptiveSetCell( unsigned int firstCol
,
2324 unsigned int lastCol
,
2325 const wxPGCell
& preparedCell
,
2326 const wxPGCell
& srcData
,
2327 wxPGCellData
* unmodCellData
,
2328 FlagType ignoreWithFlags
,
2332 Makes sure m_cells has size of column+1 (or more).
2334 void EnsureCells( unsigned int column
);
2336 /** Returns (direct) child property with given name (or NULL if not found),
2340 Start looking for the child at this index.
2343 Does not support scope (ie. Parent.Child notation).
2345 wxPGProperty
* GetPropertyByNameWH( const wxString
& name
,
2346 unsigned int hintIndex
) const;
2348 /** This is used by Insert etc. */
2349 void DoAddChild( wxPGProperty
* prop
,
2351 bool correct_mode
= true );
2353 void DoGenerateComposedValue( wxString
& text
,
2354 int argFlags
= wxPG_VALUE_IS_CURRENT
,
2355 const wxVariantList
* valueOverrides
= NULL
,
2356 wxPGHashMapS2S
* childResults
= NULL
) const;
2358 bool DoHide( bool hide
, int flags
);
2360 void DoSetName(const wxString
& str
) { m_name
= str
; }
2362 /** Deletes all sub-properties. */
2365 bool HasCell( unsigned int column
) const
2367 if ( m_cells
.size() > column
)
2372 void InitAfterAdded( wxPropertyGridPageState
* pageState
,
2373 wxPropertyGrid
* propgrid
);
2375 // Removes child property with given pointer. Does not delete it.
2376 void RemoveChild( wxPGProperty
* p
);
2378 void DoEnable( bool enable
);
2380 void DoPreAddChild( int index
, wxPGProperty
* prop
);
2382 void SetParentState( wxPropertyGridPageState
* pstate
)
2383 { m_parentState
= pstate
; }
2385 void SetFlag( wxPGPropertyFlags flag
)
2388 // NB: While using wxPGPropertyFlags here makes it difficult to
2389 // combine different flags, it usefully prevents user from
2390 // using incorrect flags (say, wxWindow styles).
2394 void ClearFlag( FlagType flag
) { m_flags
&= ~(flag
); }
2396 // Call after fixed sub-properties added/removed after creation.
2397 // if oldSelInd >= 0 and < new max items, then selection is
2399 void SubPropsChanged( int oldSelInd
= -1 );
2401 int GetY2( int lh
) const;
2405 wxPGProperty
* m_parent
;
2406 wxPropertyGridPageState
* m_parentState
;
2408 wxClientData
* m_clientObject
;
2410 // Overrides editor returned by property class
2411 const wxPGEditor
* m_customEditor
;
2412 #if wxUSE_VALIDATORS
2413 // Editor is going to get this validator
2414 wxValidator
* m_validator
;
2416 // Show this in front of the value
2418 // TODO: Can bitmap be implemented with wxPGCell?
2419 wxBitmap
* m_valueBitmap
;
2422 wxPGAttributeStorage m_attributes
;
2423 wxArrayPGProperty m_children
;
2425 // Extended cell information
2426 wxVector
<wxPGCell
> m_cells
;
2428 // Choices shown in drop-down list of editor control.
2429 wxPGChoices m_choices
;
2431 // Help shown in statusbar or help box.
2432 wxString m_helpString
;
2434 // Index in parent's property array.
2435 unsigned int m_arrIndex
;
2437 // If not -1, then overrides m_value
2442 // Maximum length (mainly for string properties). Could be in some sort of
2443 // wxBaseStringProperty, but currently, for maximum flexibility and
2444 // compatibility, we'll stick it here. Anyway, we had 3 excess bytes to use
2445 // so short int will fit in just fine.
2448 // Root has 0, categories etc. at that level 1, etc.
2449 unsigned char m_depth
;
2451 // m_depthBgCol indicates width of background colour between margin and item
2452 // (essentially this is category's depth, if none then equals m_depth).
2453 unsigned char m_depthBgCol
;
2456 // Called in constructors.
2458 void Init( const wxString
& label
, const wxString
& name
);
2461 // -----------------------------------------------------------------------
2464 // Property class declaration helper macros
2465 // (wxPGRootPropertyClass and wxPropertyCategory require this).
2468 #define WX_PG_DECLARE_DOGETEDITORCLASS \
2469 virtual const wxPGEditor* DoGetEditorClass() const;
2471 #ifndef WX_PG_DECLARE_PROPERTY_CLASS
2472 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
2474 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
2475 WX_PG_DECLARE_DOGETEDITORCLASS \
2479 // Implements sans constructor function. Also, first arg is class name, not
2481 #define WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(PROPNAME,T,EDITOR) \
2482 const wxPGEditor* PROPNAME::DoGetEditorClass() const \
2484 return wxPGEditor_##EDITOR; \
2487 // -----------------------------------------------------------------------
2489 /** @class wxPGRootProperty
2491 Root parent property.
2493 class WXDLLIMPEXP_PROPGRID wxPGRootProperty
: public wxPGProperty
2496 WX_PG_DECLARE_PROPERTY_CLASS(wxPGRootProperty
)
2500 wxPGRootProperty( const wxString
& name
= wxS("<Root>") );
2501 virtual ~wxPGRootProperty();
2503 virtual bool StringToValue( wxVariant
&, const wxString
&, int ) const
2511 // -----------------------------------------------------------------------
2513 /** @class wxPropertyCategory
2515 Category (caption) property.
2517 class WXDLLIMPEXP_PROPGRID wxPropertyCategory
: public wxPGProperty
2519 friend class wxPropertyGrid
;
2520 friend class wxPropertyGridPageState
;
2521 WX_PG_DECLARE_PROPERTY_CLASS(wxPropertyCategory
)
2524 /** Default constructor is only used in special cases. */
2525 wxPropertyCategory();
2527 wxPropertyCategory( const wxString
& label
,
2528 const wxString
& name
= wxPG_LABEL
);
2529 ~wxPropertyCategory();
2531 int GetTextExtent( const wxWindow
* wnd
, const wxFont
& font
) const;
2533 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
) const;
2534 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
2537 void SetTextColIndex( unsigned int colInd
)
2538 { m_capFgColIndex
= (wxByte
) colInd
; }
2539 unsigned int GetTextColIndex() const
2540 { return (unsigned int) m_capFgColIndex
; }
2542 void CalculateTextExtent( wxWindow
* wnd
, const wxFont
& font
);
2544 int m_textExtent
; // pre-calculated length of text
2545 wxByte m_capFgColIndex
; // caption text colour index
2551 // -----------------------------------------------------------------------
2553 #endif // wxUSE_PROPGRID
2555 #endif // _WX_PROPGRID_PROPERTY_H_