]> git.saurik.com Git - wxWidgets.git/blame - include/wx/propgrid/property.h
don't draw borders for bitmap buttons with wxBORDER_NONE style
[wxWidgets.git] / include / wx / propgrid / property.h
CommitLineData
1c4293cb
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/propgrid/property.h
3// Purpose: wxPGProperty and related support classes
4// Author: Jaakko Salli
5// Modified by:
6// Created: 2008-08-23
ea5af9c5 7// RCS-ID: $Id$
1c4293cb
VZ
8// Copyright: (c) Jaakko Salli
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_PROPGRID_PROPERTY_H_
13#define _WX_PROPGRID_PROPERTY_H_
14
f4bc1aa2
JS
15#if wxUSE_PROPGRID
16
1c4293cb
VZ
17#include "wx/propgrid/propgriddefs.h"
18
19// -----------------------------------------------------------------------
20
21#define wxNullProperty ((wxPGProperty*)NULL)
22
23
24/** @class wxPGPaintData
25
26 Contains information relayed to property's OnCustomPaint.
27*/
28struct wxPGPaintData
29{
30 /** wxPropertyGrid. */
31 const wxPropertyGrid* m_parent;
32
33 /**
34 Normally -1, otherwise index to drop-down list item that has to be
35 drawn.
36 */
37 int m_choiceItem;
38
39 /** Set to drawn width in OnCustomPaint (optional). */
40 int m_drawnWidth;
41
42 /**
43 In a measure item call, set this to the height of item at m_choiceItem
44 index.
45 */
46 int m_drawnHeight;
47};
48
49
1c4293cb
VZ
50#ifndef SWIG
51
52
53// space between vertical sides of a custom image
54#define wxPG_CUSTOM_IMAGE_SPACINGY 1
55
56// space between caption and selection rectangle,
57#define wxPG_CAPRECTXMARGIN 2
58
59// horizontally and vertically
60#define wxPG_CAPRECTYMARGIN 1
61
62
63/** @class wxPGCellRenderer
64
65 Base class for wxPropertyGrid cell renderers.
66*/
92ffc98a 67class WXDLLIMPEXP_PROPGRID wxPGCellRenderer : public wxObjectRefData
1c4293cb
VZ
68{
69public:
70
bd035313
JS
71 wxPGCellRenderer()
72 : wxObjectRefData() { }
1c4293cb
VZ
73 virtual ~wxPGCellRenderer() { }
74
75 // Render flags
76 enum
77 {
d7e2b522 78 // We are painting selected item
1c4293cb 79 Selected = 0x00010000,
d7e2b522
JS
80
81 // We are painting item in choice popup
82 ChoicePopup = 0x00020000,
83
84 // We are rendering wxOwnerDrawnComboBox control
85 // (or other owner drawn control, but that is only
86 // officially supported one ATM).
87 Control = 0x00040000,
88
89 // We are painting a disable property
90 Disabled = 0x00080000,
91
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 |
98 DontUseCellBgCol
1c4293cb
VZ
99 };
100
101 virtual void Render( wxDC& dc,
102 const wxRect& rect,
103 const wxPropertyGrid* propertyGrid,
104 wxPGProperty* property,
105 int column,
106 int item,
107 int flags ) const = 0;
108
109 /** Returns size of the image in front of the editable area.
110 @remarks
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.
113 */
114 virtual wxSize GetImageSize( const wxPGProperty* property,
115 int column,
116 int item ) const;
117
118 /** Paints property category selection rectangle.
119 */
120 virtual void DrawCaptionSelectionRect( wxDC& dc,
121 int x, int y,
122 int w, int h ) const;
123
124 /** Utility to draw vertically centered text.
125 */
126 void DrawText( wxDC& dc,
127 const wxRect& rect,
128 int imageWidth,
129 const wxString& text ) const;
130
131 /**
132 Utility to draw editor's value, or vertically aligned text if editor is
133 NULL.
134 */
135 void DrawEditorValue( wxDC& dc, const wxRect& rect,
136 int xOffset, const wxString& text,
137 wxPGProperty* property,
138 const wxPGEditor* editor ) const;
139
140 /** Utility to render cell bitmap and set text colour plus bg brush colour.
141
142 Returns image width that, for instance, can be passed to DrawText.
143 */
144 int PreDrawCell( wxDC& dc,
145 const wxRect& rect,
146 const wxPGCell& cell,
147 int flags ) const;
1c4293cb
VZ
148};
149
150
d7e2b522
JS
151class WXDLLIMPEXP_PROPGRID wxPGCellData : public wxObjectRefData
152{
153 friend class wxPGCell;
154public:
155 wxPGCellData();
156
157 void SetText( const wxString& text )
158 {
159 m_text = text;
160 m_hasValidText = true;
161 }
162 void SetBitmap( const wxBitmap& bitmap ) { m_bitmap = bitmap; }
163 void SetFgCol( const wxColour& col ) { m_fgCol = col; }
164 void SetBgCol( const wxColour& col ) { m_bgCol = col; }
165
166protected:
167 virtual ~wxPGCellData() { }
168
169 wxString m_text;
170 wxBitmap m_bitmap;
171 wxColour m_fgCol;
172 wxColour m_bgCol;
173
174 // True if m_text is valid and specified
175 bool m_hasValidText;
176};
177
1c4293cb
VZ
178/** @class wxPGCell
179
180 Base class for simple wxPropertyGrid cell information.
181*/
d7e2b522 182class WXDLLIMPEXP_PROPGRID wxPGCell : public wxObject
1c4293cb
VZ
183{
184public:
185 wxPGCell();
18415eb5
VZ
186 wxPGCell(const wxPGCell& other)
187 : wxObject(other)
d7e2b522 188 {
d7e2b522
JS
189 }
190
1c4293cb
VZ
191 wxPGCell( const wxString& text,
192 const wxBitmap& bitmap = wxNullBitmap,
193 const wxColour& fgCol = wxNullColour,
194 const wxColour& bgCol = wxNullColour );
195
196 virtual ~wxPGCell() { }
197
d7e2b522
JS
198 wxPGCellData* GetData()
199 {
200 return (wxPGCellData*) m_refData;
201 }
202
203 const wxPGCellData* GetData() const
204 {
205 return (const wxPGCellData*) m_refData;
206 }
207
208 bool HasText() const
209 {
210 return (m_refData && GetData()->m_hasValidText);
211 }
1c4293cb 212
d7e2b522
JS
213 /**
214 Merges valid data from srcCell into this.
215 */
216 void MergeFrom( const wxPGCell& srcCell );
217
218 void SetText( const wxString& text );
219 void SetBitmap( const wxBitmap& bitmap );
220 void SetFgCol( const wxColour& col );
221 void SetBgCol( const wxColour& col );
222
223 const wxString& GetText() const { return GetData()->m_text; }
224 const wxBitmap& GetBitmap() const { return GetData()->m_bitmap; }
225 const wxColour& GetFgCol() const { return GetData()->m_fgCol; }
226 const wxColour& GetBgCol() const { return GetData()->m_bgCol; }
227
228 wxPGCell& operator=( const wxPGCell& other )
229 {
230 if ( this != &other )
231 {
232 Ref(other);
233 }
234 return *this;
235 }
1c4293cb
VZ
236
237protected:
d7e2b522
JS
238 virtual wxObjectRefData *CreateRefData() const
239 { return new wxPGCellData(); }
240
241 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
1c4293cb
VZ
242};
243
244
245/** @class wxPGDefaultRenderer
246
247 Default cell renderer, that can handles the common
248 scenarios.
249*/
250class WXDLLIMPEXP_PROPGRID wxPGDefaultRenderer : public wxPGCellRenderer
251{
252public:
253 virtual void Render( wxDC& dc,
254 const wxRect& rect,
255 const wxPropertyGrid* propertyGrid,
256 wxPGProperty* property,
257 int column,
258 int item,
259 int flags ) const;
260
261 virtual wxSize GetImageSize( const wxPGProperty* property,
262 int column,
263 int item ) const;
264
265protected:
266};
267
268// -----------------------------------------------------------------------
269
270/** @class wxPGAttributeStorage
271
272 wxPGAttributeStorage is somewhat optimized storage for
273 key=variant pairs (ie. a map).
274*/
275class WXDLLIMPEXP_PROPGRID wxPGAttributeStorage
276{
277public:
278 wxPGAttributeStorage();
279 ~wxPGAttributeStorage();
280
281 void Set( const wxString& name, const wxVariant& value );
68bcfd2c 282 unsigned int GetCount() const { return (unsigned int) m_map.size(); }
1c4293cb
VZ
283 wxVariant FindValue( const wxString& name ) const
284 {
285 wxPGHashMapS2P::const_iterator it = m_map.find(name);
286 if ( it != m_map.end() )
287 {
288 wxVariantData* data = (wxVariantData*) it->second;
289 data->IncRef();
290 return wxVariant(data, it->first);
291 }
292 return wxVariant();
293 }
294
295 typedef wxPGHashMapS2P::const_iterator const_iterator;
296 const_iterator StartIteration() const
297 {
298 return m_map.begin();
299 }
300 bool GetNext( const_iterator& it, wxVariant& variant ) const
301 {
302 if ( it == m_map.end() )
303 return false;
304
305 wxVariantData* data = (wxVariantData*) it->second;
306 data->IncRef();
307 variant.SetData(data);
308 variant.SetName(it->first);
a09307ab 309 ++it;
1c4293cb
VZ
310 return true;
311 }
312
313protected:
314 wxPGHashMapS2P m_map;
315};
316
317#endif // !SWIG
318
319// -----------------------------------------------------------------------
320
321/** @section propgrid_propflags wxPGProperty Flags
322 @{
323*/
324
325enum wxPG_PROPERTY_FLAGS
326{
327
328/** Indicates bold font.
329*/
330wxPG_PROP_MODIFIED = 0x0001,
331
332/** Disables ('greyed' text and editor does not activate) property.
333*/
334wxPG_PROP_DISABLED = 0x0002,
335
336/** Hider button will hide this property.
337*/
338wxPG_PROP_HIDDEN = 0x0004,
339
340/** This property has custom paint image just in front of its value.
341 If property only draws custom images into a popup list, then this
342 flag should not be set.
343*/
344wxPG_PROP_CUSTOMIMAGE = 0x0008,
345
346/** Do not create text based editor for this property (but button-triggered
347 dialog and choice are ok).
348*/
349wxPG_PROP_NOEDITOR = 0x0010,
350
351/** Property is collapsed, ie. it's children are hidden.
352*/
353wxPG_PROP_COLLAPSED = 0x0020,
354
355/**
356 If property is selected, then indicates that validation failed for pending
357 value.
358
359 If property is not selected, then indicates that the the actual property
360 value has failed validation (NB: this behavior is not currently supported,
361 but may be used in future).
362*/
363wxPG_PROP_INVALID_VALUE = 0x0040,
364
365// 0x0080,
366
367/** Switched via SetWasModified(). Temporary flag - only used when
368 setting/changing property value.
369*/
370wxPG_PROP_WAS_MODIFIED = 0x0200,
371
372/**
373 If set, then child properties (if any) are private, and should be
374 "invisible" to the application.
375*/
376wxPG_PROP_AGGREGATE = 0x0400,
377
378/** If set, then child properties (if any) are copies and should not
379 be deleted in dtor.
380*/
381wxPG_PROP_CHILDREN_ARE_COPIES = 0x0800,
382
383/**
384 Classifies this item as a non-category.
385
386 Used for faster item type identification.
387*/
388wxPG_PROP_PROPERTY = 0x1000,
389
390/**
391 Classifies this item as a category.
392
393 Used for faster item type identification.
394*/
395wxPG_PROP_CATEGORY = 0x2000,
396
397/** Classifies this item as a property that has children, but is not aggregate
398 (ie children are not private).
399*/
400wxPG_PROP_MISC_PARENT = 0x4000,
401
402/** Property is read-only. Editor is still created.
403*/
404wxPG_PROP_READONLY = 0x8000,
405
406//
407// NB: FLAGS ABOVE 0x8000 CANNOT BE USED WITH PROPERTY ITERATORS
408//
409
410/** Property's value is composed from values of child properties.
411 @remarks
412 This flag cannot be used with property iterators.
413*/
414wxPG_PROP_COMPOSED_VALUE = 0x00010000,
415
416/** Common value of property is selectable in editor.
417 @remarks
418 This flag cannot be used with property iterators.
419*/
420wxPG_PROP_USES_COMMON_VALUE = 0x00020000,
421
422/** Property can be set to unspecified value via editor.
423 Currently, this applies to following properties:
424 - wxIntProperty, wxUIntProperty, wxFloatProperty, wxEditEnumProperty:
425 Clear the text field
426
427 @remarks
428 This flag cannot be used with property iterators.
429*/
430wxPG_PROP_AUTO_UNSPECIFIED = 0x00040000,
431
432/** Indicates the bit useable by derived properties.
433*/
434wxPG_PROP_CLASS_SPECIFIC_1 = 0x00080000,
435
436/** Indicates the bit useable by derived properties.
437*/
438wxPG_PROP_CLASS_SPECIFIC_2 = 0x00100000
439
440};
441
442/** Topmost flag.
443*/
444#define wxPG_PROP_MAX wxPG_PROP_AUTO_UNSPECIFIED
445
446/** Property with children must have one of these set, otherwise iterators
447 will not work correctly.
448 Code should automatically take care of this, however.
449*/
450#define wxPG_PROP_PARENTAL_FLAGS \
451 (wxPG_PROP_AGGREGATE|wxPG_PROP_CATEGORY|wxPG_PROP_MISC_PARENT)
452
453/** @}
454*/
455
1c4293cb
VZ
456// Combination of flags that can be stored by GetFlagsAsString
457#define wxPG_STRING_STORED_FLAGS \
458 (wxPG_PROP_DISABLED|wxPG_PROP_HIDDEN|wxPG_PROP_NOEDITOR|wxPG_PROP_COLLAPSED)
459
460// -----------------------------------------------------------------------
461
462#ifndef SWIG
463
464/**
465 @section propgrid_property_attributes wxPropertyGrid Property Attribute
466 Identifiers.
467
468 wxPGProperty::SetAttribute() and
15cbcd00 469 wxPropertyGridInterface::SetPropertyAttribute() accept one of these as
1c4293cb
VZ
470 attribute name argument.
471
472 You can use strings instead of constants. However, some of these
473 constants are redefined to use cached strings which may reduce
474 your binary size by some amount.
475
476 @{
477*/
478
479/** Set default value for property.
480*/
481#define wxPG_ATTR_DEFAULT_VALUE wxS("DefaultValue")
482
483/** Universal, int or double. Minimum value for numeric properties.
484*/
485#define wxPG_ATTR_MIN wxS("Min")
486
487/** Universal, int or double. Maximum value for numeric properties.
488*/
489#define wxPG_ATTR_MAX wxS("Max")
490
491/** Universal, string. When set, will be shown as text after the displayed
492 text value. Alternatively, if third column is enabled, text will be shown
493 there (for any type of property).
494*/
495#define wxPG_ATTR_UNITS wxS("Units")
496
497/** Universal, string. When set, will be shown in property's value cell
498 when displayed value string is empty, or value is unspecified.
499*/
500#define wxPG_ATTR_INLINE_HELP wxS("InlineHelp")
501
66fb9e12
JS
502/** Universal, wxArrayString. Set to enable auto-completion in any
503 wxTextCtrl-based property editor.
504*/
505#define wxPG_ATTR_AUTOCOMPLETE wxS("AutoComplete")
506
16372f0d
JS
507/** wxBoolProperty and wxFlagsProperty specific. Value type is bool.
508 Default value is False.
509
510 When set to True, bool property will use check box instead of a
511 combo box as its editor control. If you set this attribute
512 for a wxFlagsProperty, it is automatically applied to child
513 bool properties.
1c4293cb
VZ
514*/
515#define wxPG_BOOL_USE_CHECKBOX wxS("UseCheckbox")
516
16372f0d
JS
517/** wxBoolProperty and wxFlagsProperty specific. Value type is bool.
518 Default value is False.
519
520 Set to True for the bool property to cycle value on double click
521 (instead of showing the popup listbox). If you set this attribute
522 for a wxFlagsProperty, it is automatically applied to child
523 bool properties.
1c4293cb
VZ
524*/
525#define wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING wxS("UseDClickCycling")
526
527/**
528 wxFloatProperty (and similar) specific, int, default -1.
529
530 Sets the (max) precision used when floating point value is rendered as
531 text. The default -1 means infinite precision.
532*/
533#define wxPG_FLOAT_PRECISION wxS("Precision")
534
535/**
536 The text will be echoed as asterisks (wxTE_PASSWORD will be passed to
537 textctrl etc).
538*/
539#define wxPG_STRING_PASSWORD wxS("Password")
540
541/** Define base used by a wxUIntProperty. Valid constants are
542 wxPG_BASE_OCT, wxPG_BASE_DEC, wxPG_BASE_HEX and wxPG_BASE_HEXL
543 (lowercase characters).
544*/
545#define wxPG_UINT_BASE wxS("Base")
546
547/** Define prefix rendered to wxUIntProperty. Accepted constants
548 wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and wxPG_PREFIX_DOLLAR_SIGN.
549 <b>Note:</b> Only wxPG_PREFIX_NONE works with Decimal and Octal
550 numbers.
551*/
552#define wxPG_UINT_PREFIX wxS("Prefix")
553
554/**
555 wxFileProperty/wxImageFileProperty specific, wxChar*, default is
556 detected/varies.
557 Sets the wildcard used in the triggered wxFileDialog. Format is the same.
558*/
559#define wxPG_FILE_WILDCARD wxS("Wildcard")
560
561/** wxFileProperty/wxImageFileProperty specific, int, default 1.
562 When 0, only the file name is shown (i.e. drive and directory are hidden).
563*/
564#define wxPG_FILE_SHOW_FULL_PATH wxS("ShowFullPath")
565
566/** Specific to wxFileProperty and derived properties, wxString, default empty.
567 If set, then the filename is shown relative to the given path string.
568*/
569#define wxPG_FILE_SHOW_RELATIVE_PATH wxS("ShowRelativePath")
570
571/**
572 Specific to wxFileProperty and derived properties, wxString, default is
573 empty.
574
575 Sets the initial path of where to look for files.
576*/
577#define wxPG_FILE_INITIAL_PATH wxS("InitialPath")
578
579/** Specific to wxFileProperty and derivatives, wxString, default is empty.
580 Sets a specific title for the dir dialog.
581*/
582#define wxPG_FILE_DIALOG_TITLE wxS("DialogTitle")
583
584/** Specific to wxDirProperty, wxString, default is empty.
585 Sets a specific message for the dir dialog.
586*/
587#define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage")
588
589/** Sets displayed date format for wxDateProperty.
590*/
591#define wxPG_DATE_FORMAT wxS("DateFormat")
592
593/** Sets wxDatePickerCtrl window style used with wxDateProperty. Default
594 is wxDP_DEFAULT | wxDP_SHOWCENTURY.
595*/
596#define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
597
598/** SpinCtrl editor, int or double. How much number changes when button is
599 pressed (or up/down on keybard).
600*/
601#define wxPG_ATTR_SPINCTRL_STEP wxS("Step")
602
603/** SpinCtrl editor, bool. If true, value wraps at Min/Max.
604*/
605#define wxPG_ATTR_SPINCTRL_WRAP wxS("Wrap")
606
607/**
608 wxMultiChoiceProperty, int.
609 If 0, no user strings allowed. If 1, user strings appear before list
610 strings. If 2, user strings appear after list string.
611*/
612#define wxPG_ATTR_MULTICHOICE_USERSTRINGMODE wxS("UserStringMode")
613
614/**
615 wxColourProperty and its kind, int, default 1.
616
617 Setting this attribute to 0 hides custom colour from property's list of
618 choices.
619*/
620#define wxPG_COLOUR_ALLOW_CUSTOM wxS("AllowCustom")
621
1c4293cb
VZ
622/** @}
623*/
624
1c4293cb 625// Redefine attribute macros to use cached strings
0ce8e27f
JS
626#undef wxPG_ATTR_DEFAULT_VALUE
627#define wxPG_ATTR_DEFAULT_VALUE wxPGGlobalVars->m_strDefaultValue
1c4293cb
VZ
628#undef wxPG_ATTR_MIN
629#define wxPG_ATTR_MIN wxPGGlobalVars->m_strMin
630#undef wxPG_ATTR_MAX
631#define wxPG_ATTR_MAX wxPGGlobalVars->m_strMax
632#undef wxPG_ATTR_UNITS
633#define wxPG_ATTR_UNITS wxPGGlobalVars->m_strUnits
634#undef wxPG_ATTR_INLINE_HELP
635#define wxPG_ATTR_INLINE_HELP wxPGGlobalVars->m_strInlineHelp
636
1c4293cb
VZ
637#endif // !SWIG
638
639// -----------------------------------------------------------------------
640
939d9364 641#ifndef SWIG
1c4293cb 642
939d9364
JS
643/** @class wxPGChoiceEntry
644 Data of a single wxPGChoices choice.
1c4293cb 645*/
939d9364 646class WXDLLIMPEXP_PROPGRID wxPGChoiceEntry : public wxPGCell
1c4293cb 647{
1c4293cb 648public:
939d9364 649 wxPGChoiceEntry();
d7e2b522 650 wxPGChoiceEntry(const wxPGChoiceEntry& other)
18415eb5 651 : wxPGCell(other)
d7e2b522 652 {
d7e2b522
JS
653 m_value = other.m_value;
654 }
939d9364
JS
655 wxPGChoiceEntry( const wxString& label,
656 int value = wxPG_INVALID_VALUE )
657 : wxPGCell(), m_value(value)
658 {
d7e2b522 659 SetText(label);
939d9364 660 }
1c4293cb 661
d7e2b522 662 virtual ~wxPGChoiceEntry() { }
1c4293cb 663
939d9364 664 void SetValue( int value ) { m_value = value; }
939d9364 665 int GetValue() const { return m_value; }
1c4293cb 666
d7e2b522
JS
667 wxPGChoiceEntry& operator=( const wxPGChoiceEntry& other )
668 {
669 if ( this != &other )
670 {
671 Ref(other);
672 }
673 m_value = other.m_value;
674 return *this;
675 }
676
939d9364
JS
677protected:
678 int m_value;
679};
1c4293cb 680
1c4293cb 681
939d9364 682typedef void* wxPGChoicesId;
1c4293cb 683
92ffc98a 684class WXDLLIMPEXP_PROPGRID wxPGChoicesData : public wxObjectRefData
939d9364
JS
685{
686 friend class wxPGChoices;
687public:
688 // Constructor sets m_refCount to 1.
689 wxPGChoicesData();
1c4293cb 690
939d9364 691 void CopyDataFrom( wxPGChoicesData* data );
1c4293cb 692
d7e2b522 693 wxPGChoiceEntry& Insert( int index, const wxPGChoiceEntry& item );
1c4293cb 694
939d9364
JS
695 // Delete all entries
696 void Clear();
1c4293cb 697
68bcfd2c
JS
698 unsigned int GetCount() const
699 {
700 return (unsigned int) m_items.size();
701 }
1c4293cb 702
d7e2b522 703 const wxPGChoiceEntry& Item( unsigned int i ) const
939d9364 704 {
d7e2b522
JS
705 wxASSERT_MSG( i < GetCount(), "invalid index" );
706 return m_items[i];
707 }
1c4293cb 708
d7e2b522
JS
709 wxPGChoiceEntry& Item( unsigned int i )
710 {
711 wxASSERT_MSG( i < GetCount(), "invalid index" );
f7a094e1 712 return m_items[i];
939d9364 713 }
1c4293cb 714
939d9364 715private:
d7e2b522 716 wxVector<wxPGChoiceEntry> m_items;
1c4293cb 717
939d9364
JS
718 virtual ~wxPGChoicesData();
719};
1c4293cb 720
939d9364 721#define wxPGChoicesEmptyData ((wxPGChoicesData*)NULL)
1c4293cb 722
939d9364 723#endif // SWIG
1c4293cb 724
939d9364 725/** @class wxPGChoices
1c4293cb 726
939d9364
JS
727 Helper class for managing choices of wxPropertyGrid properties.
728 Each entry can have label, value, bitmap, text colour, and background
729 colour.
e1ef506e
JS
730
731 wxPGChoices uses reference counting, similar to other wxWidgets classes.
732 This means that assignment operator and copy constructor only copy the
733 reference and not the actual data. Use Copy() member function to create a
734 real copy.
1c4293cb 735
98c04633
JS
736 @remarks If you do not specify value for entry, index is used.
737
939d9364
JS
738 @library{wxpropgrid}
739 @category{propgrid}
740*/
741class WXDLLIMPEXP_PROPGRID wxPGChoices
742{
743public:
744 typedef long ValArrItem;
1c4293cb 745
939d9364
JS
746 /** Default constructor. */
747 wxPGChoices()
748 {
749 Init();
750 }
1c4293cb 751
e1ef506e
JS
752 /**
753 Copy constructor, uses reference counting. To create a real copy,
754 use Copy() member function instead.
755 */
939d9364
JS
756 wxPGChoices( const wxPGChoices& a )
757 {
758 if ( a.m_data != wxPGChoicesEmptyData )
759 {
760 m_data = a.m_data;
92ffc98a 761 m_data->IncRef();
939d9364
JS
762 }
763 }
1c4293cb 764
98c04633
JS
765 /**
766 Constructor.
767
768 @param labels
769 Labels for choices
770
771 @param values
772 Values for choices. If NULL, indexes are used.
773 */
939d9364
JS
774 wxPGChoices( const wxChar** labels, const long* values = NULL )
775 {
776 Init();
777 Set(labels,values);
778 }
1c4293cb 779
98c04633
JS
780 /**
781 Constructor.
782
783 @param labels
784 Labels for choices
785
786 @param values
787 Values for choices. If empty, indexes are used.
788 */
939d9364
JS
789 wxPGChoices( const wxArrayString& labels,
790 const wxArrayInt& values = wxArrayInt() )
791 {
792 Init();
793 Set(labels,values);
794 }
1c4293cb 795
939d9364
JS
796 /** Simple interface constructor. */
797 wxPGChoices( wxPGChoicesData* data )
798 {
799 wxASSERT(data);
800 m_data = data;
92ffc98a 801 data->IncRef();
939d9364 802 }
1c4293cb 803
939d9364
JS
804 /** Destructor. */
805 ~wxPGChoices()
806 {
807 Free();
808 }
1c4293cb 809
939d9364
JS
810 /**
811 Adds to current.
1c4293cb 812
939d9364
JS
813 If did not have own copies, creates them now. If was empty, identical
814 to set except that creates copies.
98c04633
JS
815
816 @param labels
817 Labels for added choices.
818
819 @param values
820 Values for added choices. If empty, relevant entry indexes are used.
1c4293cb 821 */
939d9364 822 void Add( const wxChar** labels, const ValArrItem* values = NULL );
1c4293cb 823
939d9364 824 /** Version that works with wxArrayString and wxArrayInt. */
d7e2b522 825 void Add( const wxArrayString& arr, const wxArrayInt& arrint = wxArrayInt() );
1c4293cb 826
98c04633
JS
827 /**
828 Adds a single choice.
829
830 @param label
831 Label for added choice.
832
833 @param value
834 Value for added choice. If unspecified, index is used.
835 */
939d9364
JS
836 wxPGChoiceEntry& Add( const wxString& label,
837 int value = wxPG_INVALID_VALUE );
1c4293cb 838
939d9364
JS
839 /** Adds a single item, with bitmap. */
840 wxPGChoiceEntry& Add( const wxString& label,
841 const wxBitmap& bitmap,
842 int value = wxPG_INVALID_VALUE );
1c4293cb 843
939d9364
JS
844 /** Adds a single item with full entry information. */
845 wxPGChoiceEntry& Add( const wxPGChoiceEntry& entry )
846 {
847 return Insert(entry, -1);
848 }
1c4293cb 849
939d9364
JS
850 /** Adds single item. */
851 wxPGChoiceEntry& AddAsSorted( const wxString& label,
852 int value = wxPG_INVALID_VALUE );
1c4293cb 853
e1ef506e
JS
854 /**
855 Assigns choices data, using reference counting. To create a real copy,
856 use Copy() member function instead.
857 */
939d9364
JS
858 void Assign( const wxPGChoices& a )
859 {
860 AssignData(a.m_data);
861 }
1c4293cb 862
939d9364 863 void AssignData( wxPGChoicesData* data );
1c4293cb 864
939d9364 865 /** Delete all choices. */
2728c3bf 866 void Clear();
1c4293cb 867
e1ef506e
JS
868 /**
869 Returns a real copy of the choices.
870 */
871 wxPGChoices Copy() const
872 {
873 wxPGChoices dst;
874 dst.EnsureData();
875 dst.m_data->CopyDataFrom(m_data);
876 return dst;
877 }
878
939d9364
JS
879 void EnsureData()
880 {
881 if ( m_data == wxPGChoicesEmptyData )
882 m_data = new wxPGChoicesData();
883 }
1c4293cb 884
939d9364
JS
885 /** Gets a unsigned number identifying this list. */
886 wxPGChoicesId GetId() const { return (wxPGChoicesId) m_data; };
1c4293cb 887
68bcfd2c 888 const wxString& GetLabel( unsigned int ind ) const
939d9364
JS
889 {
890 return Item(ind).GetText();
891 }
1c4293cb 892
68bcfd2c 893 unsigned int GetCount () const
939d9364
JS
894 {
895 if ( !m_data )
896 return 0;
1c4293cb 897
939d9364
JS
898 return m_data->GetCount();
899 }
1c4293cb 900
68bcfd2c 901 int GetValue( unsigned int ind ) const { return Item(ind).GetValue(); }
1c4293cb 902
939d9364
JS
903 /** Returns array of values matching the given strings. Unmatching strings
904 result in wxPG_INVALID_VALUE entry in array.
1c4293cb 905 */
939d9364 906 wxArrayInt GetValuesForStrings( const wxArrayString& strings ) const;
1c4293cb 907
939d9364
JS
908 /** Returns array of indices matching given strings. Unmatching strings
909 are added to 'unmatched', if not NULL.
910 */
911 wxArrayInt GetIndicesForStrings( const wxArrayString& strings,
912 wxArrayString* unmatched = NULL ) const;
1c4293cb 913
939d9364
JS
914 int Index( const wxString& str ) const;
915 int Index( int val ) const;
1c4293cb 916
939d9364
JS
917 /** Inserts single item. */
918 wxPGChoiceEntry& Insert( const wxString& label,
919 int index,
920 int value = wxPG_INVALID_VALUE );
1c4293cb 921
939d9364
JS
922 /** Inserts a single item with full entry information. */
923 wxPGChoiceEntry& Insert( const wxPGChoiceEntry& entry, int index );
1c4293cb 924
939d9364
JS
925 /** Returns false if this is a constant empty set of choices,
926 which should not be modified.
1c4293cb 927 */
939d9364
JS
928 bool IsOk() const
929 {
930 return ( m_data != wxPGChoicesEmptyData );
931 }
1c4293cb 932
939d9364
JS
933 const wxPGChoiceEntry& Item( unsigned int i ) const
934 {
935 wxASSERT( IsOk() );
d7e2b522 936 return m_data->Item(i);
939d9364 937 }
1c4293cb 938
939d9364
JS
939 wxPGChoiceEntry& Item( unsigned int i )
940 {
941 wxASSERT( IsOk() );
d7e2b522 942 return m_data->Item(i);
939d9364 943 }
1c4293cb 944
939d9364
JS
945 /** Removes count items starting at position nIndex. */
946 void RemoveAt(size_t nIndex, size_t count = 1);
1c4293cb 947
939d9364
JS
948#ifndef SWIG
949 /** Does not create copies for itself. */
950 void Set( const wxChar** labels, const long* values = NULL )
951 {
952 Free();
953 Add(labels,values);
954 }
939d9364
JS
955#endif // SWIG
956
957 /** Version that works with wxArrayString and wxArrayInt. */
958 void Set( const wxArrayString& labels,
959 const wxArrayInt& values = wxArrayInt() )
960 {
961 Free();
962 if ( &values )
963 Add(labels,values);
964 else
965 Add(labels);
966 }
967
968 // Creates exclusive copy of current choices
2728c3bf 969 void AllocExclusive();
939d9364
JS
970
971 // Returns data, increases refcount.
972 wxPGChoicesData* GetData()
973 {
92ffc98a
VZ
974 wxASSERT( m_data->GetRefCount() != -1 );
975 m_data->IncRef();
939d9364
JS
976 return m_data;
977 }
1c4293cb 978
939d9364
JS
979 // Returns plain data ptr - no refcounting stuff is done.
980 wxPGChoicesData* GetDataPtr() const { return m_data; }
1c4293cb 981
939d9364
JS
982 // Changes ownership of data to you.
983 wxPGChoicesData* ExtractData()
1c4293cb 984 {
939d9364
JS
985 wxPGChoicesData* data = m_data;
986 m_data = wxPGChoicesEmptyData;
987 return data;
1c4293cb
VZ
988 }
989
939d9364 990 wxArrayString GetLabels() const;
1c4293cb 991
939d9364
JS
992#ifndef SWIG
993 void operator= (const wxPGChoices& a)
994 {
a09307ab
PC
995 if (this != &a)
996 AssignData(a.m_data);
1c4293cb
VZ
997 }
998
939d9364 999 wxPGChoiceEntry& operator[](unsigned int i)
1c4293cb 1000 {
939d9364 1001 return Item(i);
1c4293cb
VZ
1002 }
1003
939d9364 1004 const wxPGChoiceEntry& operator[](unsigned int i) const
1c4293cb 1005 {
939d9364 1006 return Item(i);
1c4293cb
VZ
1007 }
1008
939d9364
JS
1009protected:
1010 wxPGChoicesData* m_data;
1c4293cb 1011
939d9364
JS
1012 void Init();
1013 void Free();
1014#endif // !SWIG
1015};
1c4293cb 1016
939d9364 1017// -----------------------------------------------------------------------
1c4293cb 1018
939d9364 1019/** @class wxPGProperty
1c4293cb 1020
939d9364 1021 wxPGProperty is base class for all wxPropertyGrid properties.
1c4293cb 1022
939d9364
JS
1023 NB: Full class overview is now only present in
1024 interface/wx/propgrid/property.h.
1c4293cb 1025
939d9364
JS
1026 @library{wxpropgrid}
1027 @category{propgrid}
1028*/
1029class WXDLLIMPEXP_PROPGRID wxPGProperty : public wxObject
1030{
1031 friend class wxPropertyGrid;
1032 friend class wxPropertyGridInterface;
1033 friend class wxPropertyGridPageState;
1034 friend class wxPropertyGridPopulator;
1035 friend class wxStringProperty; // Proper "<composed>" support requires this
14bac4b5 1036
939d9364 1037 DECLARE_ABSTRACT_CLASS(wxPGProperty)
939d9364
JS
1038public:
1039 typedef wxUint32 FlagType;
1c4293cb 1040
939d9364 1041 /** Basic constructor.
1c4293cb 1042 */
939d9364 1043 wxPGProperty();
1c4293cb 1044
939d9364
JS
1045 /** Constructor.
1046 Non-abstract property classes should have constructor of this style:
1c4293cb 1047
939d9364 1048 @code
1c4293cb 1049
939d9364
JS
1050 // If T is a class, then it should be a constant reference
1051 // (e.g. const T& ) instead.
1052 MyProperty( const wxString& label, const wxString& name, T value )
1053 : wxPGProperty()
1054 {
1055 // Generally recommended way to set the initial value
1056 // (as it should work in pretty much 100% of cases).
1057 wxVariant variant;
1058 variant << value;
1059 SetValue(variant);
1c4293cb 1060
2fd4a524
JS
1061 // If has private child properties then create them here. Also
1062 // set flag that indicates presence of private children. E.g.:
1063 //
48a32cf6
JS
1064 // AddPrivateChild( new wxStringProperty("Subprop 1",
1065 // wxPG_LABEL,
1066 // value.GetSubProp1() ) );
939d9364 1067 }
1c4293cb 1068
939d9364
JS
1069 @endcode
1070 */
1071 wxPGProperty( const wxString& label, const wxString& name );
1c4293cb 1072
939d9364
JS
1073 /**
1074 Virtual destructor.
1075 It is customary for derived properties to implement this.
1c4293cb 1076 */
939d9364 1077 virtual ~wxPGProperty();
1c4293cb 1078
939d9364 1079 /** This virtual function is called after m_value has been set.
1c4293cb 1080
939d9364
JS
1081 @remarks
1082 - If m_value was set to Null variant (ie. unspecified value),
1083 OnSetValue() will not be called.
1084 - m_value may be of any variant type. Typically properties internally
1085 support only one variant type, and as such OnSetValue() provides a
1086 good opportunity to convert
1087 supported values into internal type.
1088 - Default implementation does nothing.
1089 */
1090 virtual void OnSetValue();
1c4293cb 1091
939d9364
JS
1092 /** Override this to return something else than m_value as the value.
1093 */
1094 virtual wxVariant DoGetValue() const { return m_value; }
1095
1096#if !defined(SWIG) || defined(CREATE_VCW)
1097 /** Implement this function in derived class to check the value.
1098 Return true if it is ok. Returning false prevents property change events
1099 from occurring.
1c4293cb 1100
1c4293cb 1101 @remarks
939d9364 1102 - Default implementation always returns true.
1c4293cb 1103 */
939d9364
JS
1104 virtual bool ValidateValue( wxVariant& value,
1105 wxPGValidationInfo& validationInfo ) const;
1c4293cb 1106
939d9364 1107 /**
9e6bebdc
JS
1108 Converts text into wxVariant value appropriate for this property.
1109
1110 @param variant
1111 On function entry this is the old value (should not be wxNullVariant
1112 in normal cases). Translated value must be assigned back to it.
1113
1114 @param text
1115 Text to be translated into variant.
1116
939d9364
JS
1117 @param argFlags
1118 If wxPG_FULL_VALUE is set, returns complete, storable value instead
1119 of displayable one (they may be different).
1120 If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of
1425eca5 1121 composite property string value (as generated by ValueToString()
939d9364 1122 called with this same flag).
1c4293cb 1123
9e6bebdc
JS
1124 @return Returns @true if resulting wxVariant value was different.
1125
1126 @remarks Default implementation converts semicolon delimited tokens into
1127 child values. Only works for properties with children.
1128
1129 You might want to take into account that m_value is Null variant
1130 if property value is unspecified (which is usually only case if
1131 you explicitly enabled that sort behavior).
1c4293cb 1132 */
939d9364
JS
1133 virtual bool StringToValue( wxVariant& variant,
1134 const wxString& text,
1135 int argFlags = 0 ) const;
1c4293cb 1136
939d9364 1137 /**
9e6bebdc
JS
1138 Converts integer (possibly a choice selection) into wxVariant value
1139 appropriate for this property.
1c4293cb 1140
9e6bebdc
JS
1141 @param variant
1142 On function entry this is the old value (should not be wxNullVariant
1143 in normal cases). Translated value must be assigned back to it.
1144
1145 @param number
1146 Integer to be translated into variant.
1c4293cb 1147
939d9364
JS
1148 @param argFlags
1149 If wxPG_FULL_VALUE is set, returns complete, storable value instead
1150 of displayable one.
1c4293cb 1151
9e6bebdc
JS
1152 @return Returns @true if resulting wxVariant value was different.
1153
939d9364
JS
1154 @remarks
1155 - If property is not supposed to use choice or spinctrl or other editor
1156 with int-based value, it is not necessary to implement this method.
1157 - Default implementation simply assign given int to m_value.
1158 - If property uses choice control, and displays a dialog on some choice
1159 items, then it is preferred to display that dialog in IntToValue
1160 instead of OnEvent.
9e6bebdc
JS
1161 - You might want to take into account that m_value is Null variant if
1162 property value is unspecified (which is usually only case if you
1163 explicitly enabled that sort behavior).
1c4293cb 1164 */
939d9364
JS
1165 virtual bool IntToValue( wxVariant& value,
1166 int number,
1167 int argFlags = 0 ) const;
1168#endif // !defined(SWIG) || defined(CREATE_VCW)
1425eca5
JS
1169 /**
1170 Converts property value into a text representation.
1c4293cb 1171
1425eca5
JS
1172 @param value
1173 Value to be converted.
1c4293cb 1174
939d9364 1175 @param argFlags
1425eca5 1176 If 0 (default value), then displayed string is returned.
939d9364
JS
1177 If wxPG_FULL_VALUE is set, returns complete, storable string value
1178 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
1179 string value that must be editable in textctrl. If
1180 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
1425eca5
JS
1181 display as a part of string property's composite text
1182 representation.
1c4293cb 1183
1425eca5 1184 @remarks Default implementation calls GenerateComposedValue().
1c4293cb 1185 */
1425eca5 1186 virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
1c4293cb 1187
939d9364
JS
1188 /** Converts string to a value, and if successful, calls SetValue() on it.
1189 Default behavior is to do nothing.
1190 @param text
1191 String to get the value from.
1192 @return
1193 true if value was changed.
1c4293cb 1194 */
f275b5db 1195 bool SetValueFromString( const wxString& text, int flags = wxPG_PROGRAMMATIC_VALUE );
1c4293cb 1196
939d9364
JS
1197 /** Converts integer to a value, and if succesful, calls SetValue() on it.
1198 Default behavior is to do nothing.
1199 @param value
1200 Int to get the value from.
1201 @param flags
1202 If has wxPG_FULL_VALUE, then the value given is a actual value and
1203 not an index.
1204 @return
1205 True if value was changed.
1c4293cb 1206 */
939d9364 1207 bool SetValueFromInt( long value, int flags = 0 );
1c4293cb
VZ
1208
1209 /**
939d9364 1210 Returns size of the custom painted image in front of property.
1c4293cb 1211
939d9364
JS
1212 This method must be overridden to return non-default value if
1213 OnCustomPaint is to be called.
1214 @param item
1215 Normally -1, but can be an index to the property's list of items.
1216 @remarks
1217 - Default behavior is to return wxSize(0,0), which means no image.
1218 - Default image width or height is indicated with dimension -1.
1219 - You can also return wxPG_DEFAULT_IMAGE_SIZE, i.e. wxSize(-1, -1).
1c4293cb 1220 */
939d9364 1221 virtual wxSize OnMeasureImage( int item = -1 ) const;
1c4293cb
VZ
1222
1223 /**
939d9364 1224 Events received by editor widgets are processed here.
1c4293cb 1225
939d9364
JS
1226 Note that editor class usually processes most events. Some, such as
1227 button press events of TextCtrlAndButton class, can be handled here.
1228 Also, if custom handling for regular events is desired, then that can
1229 also be done (for example, wxSystemColourProperty custom handles
1230 wxEVT_COMMAND_CHOICE_SELECTED to display colour picker dialog when
1231 'custom' selection is made).
1c4293cb 1232
939d9364
JS
1233 If the event causes value to be changed, SetValueInEvent()
1234 should be called to set the new value.
1c4293cb 1235
939d9364
JS
1236 @param event
1237 Associated wxEvent.
1238 @return
1239 Should return true if any changes in value should be reported.
1240 @remarks
1241 If property uses choice control, and displays a dialog on some choice
1242 items, then it is preferred to display that dialog in IntToValue
1243 instead of OnEvent.
1c4293cb 1244 */
939d9364
JS
1245 virtual bool OnEvent( wxPropertyGrid* propgrid,
1246 wxWindow* wnd_primary,
1247 wxEvent& event );
1c4293cb 1248
939d9364 1249 /**
b8b1ff48
JS
1250 Called after value of a child property has been altered. Must return
1251 new value of the whole property (after any alterations warrented by
1252 child's new value).
1c4293cb 1253
939d9364 1254 Note that this function is usually called at the time that value of
b8b1ff48
JS
1255 this property, or given child property, is still pending for change,
1256 and as such, result of GetValue() or m_value should not be relied
1257 on.
1c4293cb 1258
939d9364 1259 Sample pseudo-code implementation:
1c4293cb 1260
939d9364 1261 @code
b8b1ff48
JS
1262 wxVariant MyProperty::ChildChanged( wxVariant& thisValue,
1263 int childIndex,
1264 wxVariant& childValue ) const
939d9364
JS
1265 {
1266 // Acquire reference to actual type of data stored in variant
1267 // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros
1268 // were used to create the variant class).
1269 T& data = TFromVariant(thisValue);
1c4293cb 1270
939d9364
JS
1271 // Copy childValue into data.
1272 switch ( childIndex )
1273 {
1274 case 0:
1275 data.SetSubProp1( childvalue.GetLong() );
1276 break;
1277 case 1:
1278 data.SetSubProp2( childvalue.GetString() );
1279 break;
1280 ...
1281 }
b8b1ff48
JS
1282
1283 // Return altered data
1284 return data;
939d9364
JS
1285 }
1286 @endcode
1c4293cb 1287
939d9364 1288 @param thisValue
b8b1ff48
JS
1289 Value of this property. Changed value should be returned (in
1290 previous versions of wxPropertyGrid it was only necessary to
1291 write value back to this argument).
939d9364 1292 @param childIndex
b8b1ff48
JS
1293 Index of child changed (you can use Item(childIndex) to get
1294 child property).
939d9364 1295 @param childValue
b8b1ff48
JS
1296 (Pending) value of the child property.
1297
1298 @return
1299 Modified value of the whole property.
1c4293cb 1300 */
b8b1ff48
JS
1301 virtual wxVariant ChildChanged( wxVariant& thisValue,
1302 int childIndex,
1303 wxVariant& childValue ) const;
1c4293cb 1304
939d9364 1305 /** Returns pointer to an instance of used editor.
1c4293cb 1306 */
939d9364 1307 virtual const wxPGEditor* DoGetEditorClass() const;
1c4293cb 1308
939d9364
JS
1309 /** Returns pointer to the wxValidator that should be used
1310 with the editor of this property (NULL for no validator).
1311 Setting validator explicitly via SetPropertyValidator
1312 will override this.
1c4293cb 1313
939d9364
JS
1314 In most situations, code like this should work well
1315 (macros are used to maintain one actual validator instance,
1316 so on the second call the function exits within the first
1317 macro):
1c4293cb 1318
939d9364 1319 @code
1c4293cb 1320
939d9364
JS
1321 wxValidator* wxMyPropertyClass::DoGetValidator () const
1322 {
1323 WX_PG_DOGETVALIDATOR_ENTRY()
1c4293cb 1324
939d9364 1325 wxMyValidator* validator = new wxMyValidator(...);
1c4293cb 1326
939d9364 1327 ... prepare validator...
1c4293cb 1328
939d9364
JS
1329 WX_PG_DOGETVALIDATOR_EXIT(validator)
1330 }
1c4293cb 1331
939d9364
JS
1332 @endcode
1333
1334 @remarks
1335 You can get common filename validator by returning
1336 wxFileProperty::GetClassValidator(). wxDirProperty,
1337 for example, uses it.
1c4293cb 1338 */
939d9364 1339 virtual wxValidator* DoGetValidator () const;
1c4293cb 1340
939d9364
JS
1341 /**
1342 Override to paint an image in front of the property value text or
1343 drop-down list item (but only if wxPGProperty::OnMeasureImage is
1344 overridden as well).
1c4293cb 1345
939d9364
JS
1346 If property's OnMeasureImage() returns size that has height != 0 but
1347 less than row height ( < 0 has special meanings), wxPropertyGrid calls
1348 this method to draw a custom image in a limited area in front of the
1349 editor control or value text/graphics, and if control has drop-down
1350 list, then the image is drawn there as well (even in the case
1351 OnMeasureImage() returned higher height than row height).
1c4293cb 1352
939d9364
JS
1353 NOTE: Following applies when OnMeasureImage() returns a "flexible"
1354 height ( using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable
1355 height items: If rect.x is < 0, then this is a measure item call, which
1356 means that dc is invalid and only thing that should be done is to set
1357 paintdata.m_drawnHeight to the height of the image of item at index
1358 paintdata.m_choiceItem. This call may be done even as often as once
1359 every drop-down popup show.
1c4293cb 1360
939d9364
JS
1361 @param dc
1362 wxDC to paint on.
1363 @param rect
1364 Box reserved for custom graphics. Includes surrounding rectangle,
1365 if any. If x is < 0, then this is a measure item call (see above).
1366 @param paintdata
1367 wxPGPaintData structure with much useful data.
1c4293cb 1368
939d9364
JS
1369 @remarks
1370 - You can actually exceed rect width, but if you do so then
1371 paintdata.m_drawnWidth must be set to the full width drawn in
1372 pixels.
1373 - Due to technical reasons, rect's height will be default even if
1374 custom height was reported during measure call.
1375 - Brush is guaranteed to be default background colour. It has been
1376 already used to clear the background of area being painted. It
1377 can be modified.
1378 - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper
1379 colour) pen for drawing framing rectangle. It can be changed as
1380 well.
1381
1425eca5 1382 @see ValueToString()
1c4293cb 1383 */
939d9364
JS
1384 virtual void OnCustomPaint( wxDC& dc,
1385 const wxRect& rect,
1386 wxPGPaintData& paintdata );
1c4293cb 1387
939d9364
JS
1388 /**
1389 Returns used wxPGCellRenderer instance for given property column
1390 (label=0, value=1).
1c4293cb 1391
939d9364 1392 Default implementation returns editor's renderer for all columns.
1c4293cb 1393 */
939d9364 1394 virtual wxPGCellRenderer* GetCellRenderer( int column ) const;
1c4293cb 1395
939d9364
JS
1396 /** Returns which choice is currently selected. Only applies to properties
1397 which have choices.
1c4293cb 1398
939d9364
JS
1399 Needs to reimplemented in derived class if property value does not
1400 map directly to a choice. Integer as index, bool, and string usually do.
1c4293cb 1401 */
939d9364 1402 virtual int GetChoiceSelection() const;
1c4293cb 1403
939d9364
JS
1404 /**
1405 Refresh values of child properties.
1c4293cb 1406
939d9364 1407 Automatically called after value is set.
1c4293cb 1408 */
939d9364 1409 virtual void RefreshChildren();
1c4293cb 1410
939d9364 1411 /** Special handling for attributes of this property.
1c4293cb 1412
939d9364
JS
1413 If returns false, then the attribute will be automatically stored in
1414 m_attributes.
1c4293cb 1415
939d9364 1416 Default implementation simply returns false.
1c4293cb 1417 */
939d9364 1418 virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
1c4293cb 1419
939d9364 1420 /** Returns value of an attribute.
1c4293cb 1421
939d9364 1422 Override if custom handling of attributes is needed.
1c4293cb 1423
939d9364 1424 Default implementation simply return NULL variant.
1c4293cb 1425 */
939d9364 1426 virtual wxVariant DoGetAttribute( const wxString& name ) const;
1c4293cb 1427
939d9364
JS
1428 /** Returns instance of a new wxPGEditorDialogAdapter instance, which is
1429 used when user presses the (optional) button next to the editor control;
1c4293cb 1430
939d9364
JS
1431 Default implementation returns NULL (ie. no action is generated when
1432 button is pressed).
1c4293cb 1433 */
939d9364
JS
1434 virtual wxPGEditorDialogAdapter* GetEditorDialog() const;
1435
d8812c6e
JS
1436 /**
1437 Called whenever validation has failed with given pending value.
1438
1439 @remarks If you implement this in your custom property class, please
1440 remember to call the baser implementation as well, since they
1441 may use it to revert property into pre-change state.
1442 */
1443 virtual void OnValidationFailure( wxVariant& pendingValue );
1444
939d9364 1445 /** Append a new choice to property's list of choices.
1c4293cb 1446 */
939d9364
JS
1447 int AddChoice( const wxString& label, int value = wxPG_INVALID_VALUE )
1448 {
1449 return InsertChoice(label, wxNOT_FOUND, value);
1450 }
1c4293cb 1451
939d9364
JS
1452 /**
1453 Returns true if children of this property are component values (for
1454 instance, points size, face name, and is_underlined are component
1455 values of a font).
1c4293cb 1456 */
939d9364 1457 bool AreChildrenComponents() const
1c4293cb 1458 {
939d9364
JS
1459 if ( m_flags & (wxPG_PROP_COMPOSED_VALUE|wxPG_PROP_AGGREGATE) )
1460 return true;
1461
1462 return false;
1c4293cb
VZ
1463 }
1464
91c818f8
JS
1465 /**
1466 Deletes children of the property.
1467 */
1468 void DeleteChildren();
1469
939d9364
JS
1470 /**
1471 Removes entry from property's wxPGChoices and editor control (if it is
1472 active).
1c4293cb 1473
939d9364 1474 If selected item is deleted, then the value is set to unspecified.
1c4293cb 1475 */
939d9364 1476 void DeleteChoice( int index );
1c4293cb
VZ
1477
1478 /**
939d9364
JS
1479 Call to enable or disable usage of common value (integer value that can
1480 be selected for properties instead of their normal values) for this
1481 property.
1c4293cb 1482
939d9364
JS
1483 Common values are disabled by the default for all properties.
1484 */
1485 void EnableCommonValue( bool enable = true )
1486 {
1487 if ( enable ) SetFlag( wxPG_PROP_USES_COMMON_VALUE );
1488 else ClearFlag( wxPG_PROP_USES_COMMON_VALUE );
1489 }
1c4293cb 1490
1425eca5 1491 /**
c82a80e8 1492 Composes text from values of child properties.
1425eca5 1493 */
c82a80e8
JS
1494 wxString GenerateComposedValue() const
1495 {
1496 wxString s;
1497 DoGenerateComposedValue(s);
1498 return s;
1499 }
1c4293cb 1500
939d9364
JS
1501 /** Returns property's label. */
1502 const wxString& GetLabel() const { return m_label; }
1c4293cb 1503
939d9364
JS
1504 /** Returns property's name with all (non-category, non-root) parents. */
1505 wxString GetName() const;
1c4293cb 1506
939d9364
JS
1507 /**
1508 Returns property's base name (ie parent's name is not added in any
1509 case)
1510 */
1511 const wxString& GetBaseName() const { return m_name; }
1512
1513 /** Returns read-only reference to property's list of choices.
1c4293cb 1514 */
939d9364
JS
1515 const wxPGChoices& GetChoices() const
1516 {
1517 return m_choices;
1518 }
1c4293cb 1519
939d9364
JS
1520 /** Returns coordinate to the top y of the property. Note that the
1521 position of scrollbars is not taken into account.
1c4293cb 1522 */
939d9364 1523 int GetY() const;
1c4293cb 1524
939d9364 1525 wxVariant GetValue() const
1c4293cb 1526 {
939d9364 1527 return DoGetValue();
1c4293cb
VZ
1528 }
1529
939d9364
JS
1530 /** Returns reference to the internal stored value. GetValue is preferred
1531 way to get the actual value, since GetValueRef ignores DoGetValue,
1532 which may override stored value.
1533 */
1534 wxVariant& GetValueRef()
1535 {
1536 return m_value;
1537 }
1c4293cb 1538
939d9364 1539 const wxVariant& GetValueRef() const
1c4293cb 1540 {
939d9364 1541 return m_value;
1c4293cb 1542 }
ac1013c0
JS
1543
1544 // Helper function (for wxPython bindings and such) for settings protected
1545 // m_value.
1546 wxVariant GetValuePlain() const
1547 {
1548 return m_value;
1549 }
1c4293cb 1550
1425eca5
JS
1551 /** Returns text representation of property's value.
1552
1553 @param argFlags
1554 If 0 (default value), then displayed string is returned.
1555 If wxPG_FULL_VALUE is set, returns complete, storable string value
1556 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
1557 string value that must be editable in textctrl. If
1558 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
1559 display as a part of string property's composite text
1560 representation.
1561
1562 @remarks In older versions, this function used to be overridden to convert
1563 property's value into a string representation. This function is
1564 now handled by ValueToString(), and overriding this function now
1565 will result in run-time assertion failure.
1566 */
1567 virtual wxString GetValueAsString( int argFlags = 0 ) const;
1568
1569 /** Synonymous to GetValueAsString().
1570
1571 @deprecated Use GetValueAsString() instead.
1572
1573 @see GetValueAsString()
939d9364 1574 */
1425eca5 1575 wxDEPRECATED( wxString GetValueString( int argFlags = 0 ) const );
1c4293cb 1576
d7e2b522
JS
1577 /**
1578 Returns wxPGCell of given column.
939d9364 1579 */
d7e2b522 1580 const wxPGCell& GetCell( unsigned int column ) const;
1c4293cb 1581
d7e2b522 1582 wxPGCell& GetCell( unsigned int column );
1c4293cb 1583
939d9364
JS
1584 /** Return number of displayed common values for this property.
1585 */
1586 int GetDisplayedCommonValueCount() const;
1587
1588 wxString GetDisplayedString() const
1c4293cb 1589 {
1425eca5 1590 return GetValueAsString(0);
1c4293cb 1591 }
1c4293cb 1592
939d9364
JS
1593 /** Returns property grid where property lies. */
1594 wxPropertyGrid* GetGrid() const;
1595
1596 /** Returns owner wxPropertyGrid, but only if one is currently on a page
1597 displaying this property. */
1598 wxPropertyGrid* GetGridIfDisplayed() const;
1599
1600 /** Returns highest level non-category, non-root parent. Useful when you
1601 have nested wxCustomProperties/wxParentProperties.
1c4293cb 1602 @remarks
939d9364
JS
1603 Thus, if immediate parent is root or category, this will return the
1604 property itself.
1c4293cb 1605 */
939d9364 1606 wxPGProperty* GetMainParent() const;
1c4293cb 1607
939d9364
JS
1608 /** Return parent of property */
1609 wxPGProperty* GetParent() const { return m_parent; }
1610
1611 /** Returns true if property has editable wxTextCtrl when selected.
1612
1613 @remarks
1614 Altough disabled properties do not displayed editor, they still
1615 return True here as being disabled is considered a temporary
1616 condition (unlike being read-only or having limited editing enabled).
1c4293cb 1617 */
939d9364
JS
1618 bool IsTextEditable() const;
1619
1620 bool IsValueUnspecified() const
1c4293cb 1621 {
939d9364 1622 return m_value.IsNull();
1c4293cb
VZ
1623 }
1624
939d9364 1625 FlagType HasFlag( FlagType flag ) const
1c4293cb 1626 {
939d9364 1627 return ( m_flags & flag );
1c4293cb
VZ
1628 }
1629
939d9364 1630 /** Returns comma-delimited string of property attributes.
1c4293cb 1631 */
939d9364 1632 const wxPGAttributeStorage& GetAttributes() const
1c4293cb 1633 {
939d9364 1634 return m_attributes;
1c4293cb
VZ
1635 }
1636
939d9364 1637 /** Returns m_attributes as list wxVariant.
1c4293cb 1638 */
939d9364 1639 wxVariant GetAttributesAsList() const;
1c4293cb 1640
939d9364
JS
1641 FlagType GetFlags() const
1642 {
1643 return m_flags;
1644 }
1c4293cb 1645
939d9364 1646 const wxPGEditor* GetEditorClass() const;
1c4293cb 1647
939d9364
JS
1648 wxString GetValueType() const
1649 {
1650 return m_value.GetType();
1651 }
1c4293cb 1652
939d9364 1653 /** Returns editor used for given column. NULL for no editor.
1c4293cb 1654 */
939d9364 1655 const wxPGEditor* GetColumnEditor( int column ) const
1c4293cb 1656 {
939d9364
JS
1657 if ( column == 1 )
1658 return GetEditorClass();
1659
1660 return NULL;
1c4293cb
VZ
1661 }
1662
939d9364
JS
1663 /** Returns common value selected for this property. -1 for none.
1664 */
1665 int GetCommonValue() const
1c4293cb 1666 {
939d9364 1667 return m_commonValue;
1c4293cb
VZ
1668 }
1669
939d9364
JS
1670 /** Returns true if property has even one visible child.
1671 */
1672 bool HasVisibleChildren() const;
1c4293cb 1673
48a32cf6
JS
1674 /**
1675 Use this member function to add independent (ie. regular) children to
1676 a property.
1677
1678 @return Inserted childProperty.
1679
1680 @remarks wxPropertyGrid is not automatically refreshed by this
1681 function.
1682
1683 @see AddPrivateChild()
1684 */
1685 wxPGProperty* InsertChild( int index, wxPGProperty* childProperty );
1686
939d9364
JS
1687 /** Inserts a new choice to property's list of choices.
1688 */
1689 int InsertChoice( const wxString& label, int index, int value = wxPG_INVALID_VALUE );
1c4293cb
VZ
1690
1691 /**
939d9364 1692 Returns true if this property is actually a wxPropertyCategory.
1c4293cb 1693 */
939d9364 1694 bool IsCategory() const { return HasFlag(wxPG_PROP_CATEGORY)?true:false; }
1c4293cb 1695
939d9364 1696 /** Returns true if this property is actually a wxRootProperty.
1c4293cb 1697 */
939d9364 1698 bool IsRoot() const { return (m_parent == NULL); }
1c4293cb 1699
939d9364
JS
1700 /** Returns true if this is a sub-property. */
1701 bool IsSubProperty() const
1702 {
1703 wxPGProperty* parent = (wxPGProperty*)m_parent;
1704 if ( parent && !parent->IsCategory() )
1705 return true;
1706 return false;
1707 }
1c4293cb 1708
939d9364 1709 /** Returns last visible sub-property, recursively.
1c4293cb 1710 */
939d9364 1711 const wxPGProperty* GetLastVisibleSubItem() const;
1c4293cb 1712
939d9364 1713 wxVariant GetDefaultValue() const;
1c4293cb 1714
939d9364
JS
1715 int GetMaxLength() const
1716 {
1717 return (int) m_maxLen;
1718 }
1c4293cb 1719
939d9364
JS
1720 /**
1721 Determines, recursively, if all children are not unspecified.
1c4293cb 1722
bb6720bb
JS
1723 @param pendingList
1724 Assumes members in this wxVariant list as pending
1725 replacement values.
939d9364
JS
1726 */
1727 bool AreAllChildrenSpecified( wxVariant* pendingList = NULL ) const;
1c4293cb 1728
939d9364
JS
1729 /** Updates composed values of parent non-category properties, recursively.
1730 Returns topmost property updated.
1c4293cb 1731
939d9364
JS
1732 @remarks
1733 - Must not call SetValue() (as can be called in it).
1c4293cb 1734 */
939d9364 1735 wxPGProperty* UpdateParentValues();
1c4293cb 1736
939d9364
JS
1737 /** Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
1738 */
bb6720bb 1739 bool UsesAutoUnspecified() const
939d9364 1740 {
bb6720bb 1741 return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED)?true:false;
1c4293cb 1742 }
939d9364
JS
1743
1744 wxBitmap* GetValueImage() const
1745 {
1746 return m_valueBitmap;
1c4293cb 1747 }
1c4293cb 1748
939d9364 1749 wxVariant GetAttribute( const wxString& name ) const;
1c4293cb 1750
939d9364
JS
1751 /**
1752 Returns named attribute, as string, if found.
1c4293cb 1753
939d9364 1754 Otherwise defVal is returned.
1c4293cb 1755 */
939d9364 1756 wxString GetAttribute( const wxString& name, const wxString& defVal ) const;
1c4293cb 1757
939d9364
JS
1758 /**
1759 Returns named attribute, as long, if found.
1c4293cb 1760
939d9364
JS
1761 Otherwise defVal is returned.
1762 */
1763 long GetAttributeAsLong( const wxString& name, long defVal ) const;
1c4293cb 1764
939d9364
JS
1765 /**
1766 Returns named attribute, as double, if found.
1c4293cb 1767
939d9364 1768 Otherwise defVal is returned.
1c4293cb 1769 */
939d9364 1770 double GetAttributeAsDouble( const wxString& name, double defVal ) const;
1c4293cb 1771
939d9364 1772 unsigned int GetDepth() const { return (unsigned int)m_depth; }
1c4293cb 1773
939d9364
JS
1774 /** Gets flags as a'|' delimited string. Note that flag names are not
1775 prepended with 'wxPG_PROP_'.
1776 @param flagsMask
1777 String will only be made to include flags combined by this parameter.
1778 */
1779 wxString GetFlagsAsString( FlagType flagsMask ) const;
1c4293cb 1780
939d9364
JS
1781 /** Returns position in parent's array. */
1782 unsigned int GetIndexInParent() const
1c4293cb 1783 {
939d9364 1784 return (unsigned int)m_arrIndex;
1c4293cb
VZ
1785 }
1786
939d9364
JS
1787 /** Hides or reveals the property.
1788 @param hide
1789 true for hide, false for reveal.
1790 @param flags
1791 By default changes are applied recursively. Set this paramter
1792 wxPG_DONT_RECURSE to prevent this.
1793 */
1794 inline bool Hide( bool hide, int flags = wxPG_RECURSE );
1c4293cb 1795
939d9364
JS
1796 bool IsExpanded() const
1797 { return (!(m_flags & wxPG_PROP_COLLAPSED) && GetChildCount()); }
1c4293cb 1798
939d9364
JS
1799 /** Returns true if all parents expanded.
1800 */
1801 bool IsVisible() const;
1c4293cb 1802
939d9364 1803 bool IsEnabled() const { return !(m_flags & wxPG_PROP_DISABLED); }
1c4293cb 1804
939d9364
JS
1805 /** If property's editor is created this forces its recreation.
1806 Useful in SetAttribute etc. Returns true if actually did anything.
1807 */
1808 bool RecreateEditor();
1c4293cb 1809
939d9364
JS
1810 /** If property's editor is active, then update it's value.
1811 */
1812 void RefreshEditor();
1c4293cb 1813
939d9364
JS
1814 /** Sets an attribute for this property.
1815 @param name
1816 Text identifier of attribute. See @ref propgrid_property_attributes.
1817 @param value
1818 Value of attribute.
1819 */
1820 void SetAttribute( const wxString& name, wxVariant value );
1c4293cb 1821
939d9364 1822 void SetAttributes( const wxPGAttributeStorage& attributes );
1c4293cb 1823
d7e2b522
JS
1824 /**
1825 Sets property's background colour.
1826
1827 @param colour
1828 Background colour to use.
1829
1830 @param recursively
1831 If @true, children are affected recursively, and any categories
1832 are not.
1833 */
1834 void SetBackgroundColour( const wxColour& colour,
1835 bool recursively = false );
1836
1837 /**
1838 Sets property's text colour.
1839
1840 @param colour
1841 Text colour to use.
1842
1843 @param recursively
1844 If @true, children are affected recursively, and any categories
1845 are not.
1846 */
1847 void SetTextColour( const wxColour& colour,
1848 bool recursively = false );
1849
0ce8e27f
JS
1850 /** Set default value of a property. Synonymous to
1851
1852 @code
1853 SetAttribute("DefaultValue", value);
1854 @endcode
1855 */
1856 void SetDefaultValue( wxVariant& value );
1857
939d9364
JS
1858#ifndef SWIG
1859 /** Sets editor for a property.
1c4293cb 1860
939d9364
JS
1861 @param editor
1862 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1863 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full
1864 list).
1c4293cb 1865
939d9364
JS
1866 For custom editors, use pointer you received from
1867 wxPropertyGrid::RegisterEditorClass().
1868 */
1869 void SetEditor( const wxPGEditor* editor )
1870 {
1871 m_customEditor = editor;
1872 }
1873#endif
1c4293cb 1874
939d9364
JS
1875 /** Sets editor for a property.
1876 */
1877 inline void SetEditor( const wxString& editorName );
1c4293cb 1878
d7e2b522
JS
1879 /**
1880 Sets cell information for given column.
939d9364 1881 */
d7e2b522 1882 void SetCell( int column, const wxPGCell& cell );
1c4293cb 1883
939d9364
JS
1884 /** Sets common value selected for this property. -1 for none.
1885 */
1886 void SetCommonValue( int commonValue )
1887 {
1888 m_commonValue = commonValue;
1889 }
1c4293cb 1890
939d9364
JS
1891 /** Sets flags from a '|' delimited string. Note that flag names are not
1892 prepended with 'wxPG_PROP_'.
1893 */
1894 void SetFlagsFromString( const wxString& str );
1c4293cb 1895
939d9364
JS
1896 /** Sets property's "is it modified?" flag. Affects children recursively.
1897 */
1898 void SetModifiedStatus( bool modified )
1899 {
1900 SetFlagRecursively(wxPG_PROP_MODIFIED, modified);
1901 }
1c4293cb 1902
939d9364
JS
1903 /** Call in OnEvent(), OnButtonClick() etc. to change the property value
1904 based on user input.
1c4293cb 1905
939d9364
JS
1906 @remarks
1907 This method is const since it doesn't actually modify value, but posts
1908 given variant as pending value, stored in wxPropertyGrid.
1909 */
1910 void SetValueInEvent( wxVariant value ) const;
1c4293cb 1911
939d9364
JS
1912 /**
1913 Call this to set value of the property.
1c4293cb 1914
939d9364
JS
1915 Unlike methods in wxPropertyGrid, this does not automatically update
1916 the display.
1c4293cb 1917
939d9364
JS
1918 @remarks
1919 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run
1920 through validation process and send property change event.
1c4293cb 1921
939d9364
JS
1922 If you need to change property value in event, based on user input, use
1923 SetValueInEvent() instead.
1c4293cb 1924
939d9364 1925 @param pList
e777bd14
JS
1926 Pointer to list variant that contains child values. Used to
1927 indicate which children should be marked as modified.
1928
939d9364 1929 @param flags
e777bd14
JS
1930 Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR, which is
1931 enabled by default).
939d9364 1932 */
e777bd14
JS
1933 void SetValue( wxVariant value, wxVariant* pList = NULL,
1934 int flags = wxPG_SETVAL_REFRESH_EDITOR );
1c4293cb 1935
939d9364
JS
1936 /** Set wxBitmap in front of the value. This bitmap may be ignored
1937 by custom cell renderers.
1938 */
1939 void SetValueImage( wxBitmap& bmp );
1c4293cb 1940
939d9364 1941 /** Sets selected choice and changes property value.
1c4293cb 1942
939d9364
JS
1943 Tries to retain value type, although currently if it is not string,
1944 then it is forced to integer.
1945 */
1946 void SetChoiceSelection( int newValue );
1c4293cb 1947
939d9364
JS
1948 void SetExpanded( bool expanded )
1949 {
1950 if ( !expanded ) m_flags |= wxPG_PROP_COLLAPSED;
1951 else m_flags &= ~wxPG_PROP_COLLAPSED;
1952 }
1c4293cb 1953
d58526d5
JS
1954 /**
1955 Sets given property flag(s).
1956 */
939d9364 1957 void SetFlag( FlagType flag ) { m_flags |= flag; }
1c4293cb 1958
d58526d5
JS
1959 /**
1960 Sets or clears given property flag(s).
1961 */
1962 void ChangeFlag( FlagType flag, bool set )
1963 {
1964 if ( set )
1965 m_flags |= flag;
1966 else
1967 m_flags &= ~flag;
1968 }
1969
939d9364 1970 void SetFlagRecursively( FlagType flag, bool set );
1c4293cb 1971
939d9364
JS
1972 void SetHelpString( const wxString& helpString )
1973 {
1974 m_helpString = helpString;
1975 }
1c4293cb 1976
939d9364 1977 void SetLabel( const wxString& label ) { m_label = label; }
1c4293cb 1978
939d9364 1979 inline void SetName( const wxString& newName );
1c4293cb 1980
2fd4a524
JS
1981 /**
1982 Changes what sort of parent this property is for its children.
1983
1984 @param flag
48a32cf6
JS
1985 Use one of the following values: wxPG_PROP_MISC_PARENT (for
1986 generic parents), wxPG_PROP_CATEGORY (for categories), or
2fd4a524
JS
1987 wxPG_PROP_AGGREGATE (for derived property classes with private
1988 children).
1989
48a32cf6 1990 @remarks You generally do not need to call this function.
2fd4a524
JS
1991 */
1992 void SetParentalType( int flag )
1993 {
1994 m_flags &= ~(wxPG_PROP_PROPERTY|wxPG_PROP_PARENTAL_FLAGS);
1995 m_flags |= flag;
1996 }
1997
939d9364
JS
1998 void SetValueToUnspecified()
1999 {
2000 wxVariant val; // Create NULL variant
2001 SetValue(val);
2002 }
1c4293cb 2003
ac1013c0
JS
2004 // Helper function (for wxPython bindings and such) for settings protected
2005 // m_value.
2006 void SetValuePlain( wxVariant value )
2007 {
2008 m_value = value;
2009 }
2010
939d9364
JS
2011#if wxUSE_VALIDATORS
2012 /** Sets wxValidator for a property*/
2013 void SetValidator( const wxValidator& validator )
2014 {
2015 m_validator = wxDynamicCast(validator.Clone(),wxValidator);
2016 }
1c4293cb 2017
939d9364
JS
2018 /** Gets assignable version of property's validator. */
2019 wxValidator* GetValidator() const
2020 {
2021 if ( m_validator )
2022 return m_validator;
2023 return DoGetValidator();
2024 }
2025#endif // #if wxUSE_VALIDATORS
1c4293cb 2026
1c4293cb 2027#ifndef SWIG
939d9364
JS
2028 /** Returns client data (void*) of a property.
2029 */
2030 void* GetClientData() const
1c4293cb 2031 {
939d9364 2032 return m_clientData;
1c4293cb
VZ
2033 }
2034
939d9364
JS
2035 /** Sets client data (void*) of a property.
2036 @remarks
2037 This untyped client data has to be deleted manually.
2038 */
2039 void SetClientData( void* clientData )
1c4293cb 2040 {
939d9364 2041 m_clientData = clientData;
1c4293cb
VZ
2042 }
2043
939d9364
JS
2044 /** Returns client object of a property.
2045 */
2046 void SetClientObject(wxClientData* clientObject)
1c4293cb 2047 {
939d9364
JS
2048 delete m_clientObject;
2049 m_clientObject = clientObject;
1c4293cb
VZ
2050 }
2051
939d9364
JS
2052 /** Sets managed client object of a property.
2053 */
2054 wxClientData *GetClientObject() const { return m_clientObject; }
2055#endif
1c4293cb 2056
939d9364 2057 /** Sets new set of choices for property.
1c4293cb 2058
939d9364
JS
2059 @remarks
2060 This operation clears the property value.
2061 */
2062 bool SetChoices( wxPGChoices& choices );
1c4293cb 2063
939d9364
JS
2064 /** Set max length of text in text editor.
2065 */
2066 inline bool SetMaxLength( int maxLen );
1c4293cb 2067
939d9364
JS
2068 /** Call with 'false' in OnSetValue to cancel value changes after all
2069 (ie. cancel 'true' returned by StringToValue() or IntToValue()).
2070 */
2071 void SetWasModified( bool set = true )
1c4293cb 2072 {
939d9364
JS
2073 if ( set ) m_flags |= wxPG_PROP_WAS_MODIFIED;
2074 else m_flags &= ~wxPG_PROP_WAS_MODIFIED;
2075 }
1c4293cb 2076
939d9364
JS
2077 const wxString& GetHelpString() const
2078 {
2079 return m_helpString;
1c4293cb
VZ
2080 }
2081
939d9364 2082 void ClearFlag( FlagType flag ) { m_flags &= ~(flag); }
1c4293cb 2083
939d9364
JS
2084 // Use, for example, to detect if item is inside collapsed section.
2085 bool IsSomeParent( wxPGProperty* candidate_parent ) const;
1c4293cb 2086
939d9364
JS
2087 /**
2088 Adapts list variant into proper value using consecutive
2089 ChildChanged-calls.
2090 */
2091 void AdaptListToValue( wxVariant& list, wxVariant* value ) const;
99774d58 2092
48a32cf6
JS
2093#if wxPG_COMPATIBILITY_1_4
2094 /**
2095 Adds a private child property.
2096
2097 @deprecated Use AddPrivateChild() instead.
2098
2099 @see AddPrivateChild()
2100 */
2101 wxDEPRECATED( void AddChild( wxPGProperty* prop ) );
2102#endif
2103
2fd4a524 2104 /**
48a32cf6 2105 Adds a private child property. If you use this instead of
2fd4a524 2106 wxPropertyGridInterface::Insert() or
48a32cf6
JS
2107 wxPropertyGridInterface::AppendIn(), then property's parental
2108 type will automatically be set up to wxPG_PROP_AGGREGATE. In other
2109 words, all properties of this property will become private.
2110 */
2111 void AddPrivateChild( wxPGProperty* prop );
2fd4a524 2112
48a32cf6
JS
2113 /**
2114 Appends a new child property.
2fd4a524 2115 */
48a32cf6
JS
2116 wxPGProperty* AppendChild( wxPGProperty* prop )
2117 {
2118 return InsertChild(-1, prop);
2119 }
1c4293cb 2120
939d9364
JS
2121 /** Returns height of children, recursively, and
2122 by taking expanded/collapsed status into account.
1c4293cb 2123
939d9364
JS
2124 iMax is used when finding property y-positions.
2125 */
2126 int GetChildrenHeight( int lh, int iMax = -1 ) const;
1c4293cb 2127
939d9364 2128 /** Returns number of child properties */
68bcfd2c
JS
2129 unsigned int GetChildCount() const
2130 {
2131 return (unsigned int) m_children.size();
2132 }
1c4293cb 2133
939d9364 2134 /** Returns sub-property at index i. */
68bcfd2c 2135 wxPGProperty* Item( unsigned int i ) const
f7a094e1 2136 { return m_children[i]; }
1c4293cb 2137
939d9364
JS
2138 /** Returns last sub-property.
2139 */
f7a094e1 2140 wxPGProperty* Last() const { return m_children.back(); }
1c4293cb 2141
f7a094e1
JS
2142 /** Returns index of given child property. */
2143 int Index( const wxPGProperty* p ) const;
1c4293cb 2144
939d9364 2145 // Puts correct indexes to children
1b895132 2146 void FixIndicesOfChildren( unsigned int starthere = 0 );
1c4293cb 2147
4aee8334
JS
2148 /**
2149 Converts image width into full image offset, with margins.
2150 */
2151 int GetImageOffset( int imageWidth ) const;
2152
939d9364
JS
2153#ifndef SWIG
2154 // Returns wxPropertyGridPageState in which this property resides.
2155 wxPropertyGridPageState* GetParentState() const { return m_parentState; }
2156#endif
1c4293cb 2157
14bac4b5 2158#ifndef SWIG
939d9364
JS
2159 wxPGProperty* GetItemAtY( unsigned int y,
2160 unsigned int lh,
2161 unsigned int* nextItemY ) const;
14bac4b5
JS
2162#endif
2163
2164 /** Returns property at given virtual y coordinate.
2165 */
2166 wxPGProperty* GetItemAtY( unsigned int y ) const;
1c4293cb 2167
939d9364
JS
2168 /** Returns (direct) child property with given name (or NULL if not found).
2169 */
2170 wxPGProperty* GetPropertyByName( const wxString& name ) const;
1c4293cb 2171
939d9364 2172#ifndef SWIG
1c4293cb 2173
d7e2b522
JS
2174 // Returns various display-related information for given column
2175 void GetDisplayInfo( unsigned int column,
2176 int choiceIndex,
2177 int flags,
2178 wxString* pString,
2179 const wxPGCell** pCell );
2180
939d9364 2181 static wxString* sm_wxPG_LABEL;
1c4293cb 2182
939d9364
JS
2183 /** This member is public so scripting language bindings
2184 wrapper code can access it freely.
2185 */
2186 void* m_clientData;
1c4293cb 2187
939d9364 2188protected:
d7e2b522
JS
2189
2190 /**
2191 Sets property cell in fashion that reduces number of exclusive
2192 copies of cell data. Used when setting, for instance, same
2193 background colour for a number of properties.
2194
2195 @param firstCol
2196 First column to affect.
2197
2198 @param lastCol
2199 Last column to affect.
2200
2201 @param preparedCell
2202 Pre-prepared cell that is used for those which cell data
2203 before this matched unmodCellData.
2204
2205 @param srcData
2206 If unmodCellData did not match, valid cell data from this
2207 is merged into cell (usually generating new exclusive copy
2208 of cell's data).
2209
2210 @param unmodCellData
2211 If cell's cell data matches this, its cell is now set to
2212 preparedCell.
2213
2214 @param ignoreWithFlags
2215 Properties with any one of these flags are skipped.
2216
2217 @param recursively
2218 If @true, apply this operation recursively in child properties.
1c4293cb 2219 */
d7e2b522
JS
2220 void AdaptiveSetCell( unsigned int firstCol,
2221 unsigned int lastCol,
2222 const wxPGCell& preparedCell,
2223 const wxPGCell& srcData,
2224 wxPGCellData* unmodCellData,
2225 FlagType ignoreWithFlags,
2226 bool recursively );
2227
2228 /**
2229 Makes sure m_cells has size of column+1 (or more).
2230 */
2231 void EnsureCells( unsigned int column );
1c4293cb 2232
939d9364
JS
2233 /** Returns (direct) child property with given name (or NULL if not found),
2234 with hint index.
1c4293cb 2235
939d9364
JS
2236 @param hintIndex
2237 Start looking for the child at this index.
1c4293cb 2238
939d9364
JS
2239 @remarks
2240 Does not support scope (ie. Parent.Child notation).
2241 */
2242 wxPGProperty* GetPropertyByNameWH( const wxString& name,
2243 unsigned int hintIndex ) const;
1c4293cb 2244
939d9364 2245 /** This is used by Insert etc. */
48a32cf6
JS
2246 void DoAddChild( wxPGProperty* prop,
2247 int index = -1,
2248 bool correct_mode = true );
1c4293cb 2249
c82a80e8
JS
2250 void DoGenerateComposedValue( wxString& text,
2251 int argFlags = wxPG_VALUE_IS_CURRENT,
2252 const wxVariantList* valueOverrides = NULL,
2253 wxPGHashMapS2S* childResults = NULL ) const;
2254
939d9364
JS
2255 void DoSetName(const wxString& str) { m_name = str; }
2256
91c818f8
JS
2257 /** Deletes all sub-properties. */
2258 void Empty();
2259
2fd4a524
JS
2260 void InitAfterAdded( wxPropertyGridPageState* pageState,
2261 wxPropertyGrid* propgrid );
939d9364 2262
d8c74d04
JS
2263 // Removes child property with given pointer. Does not delete it.
2264 void RemoveChild( wxPGProperty* p );
2265
48a32cf6
JS
2266 void DoPreAddChild( int index, wxPGProperty* prop );
2267
939d9364
JS
2268 void SetParentState( wxPropertyGridPageState* pstate )
2269 { m_parentState = pstate; }
2270
2271 // Call after fixed sub-properties added/removed after creation.
2272 // if oldSelInd >= 0 and < new max items, then selection is
2273 // moved to it.
2274 void SubPropsChanged( int oldSelInd = -1 );
1c4293cb 2275
939d9364 2276 int GetY2( int lh ) const;
1c4293cb 2277
939d9364
JS
2278 wxString m_label;
2279 wxString m_name;
2280 wxPGProperty* m_parent;
d7e2b522 2281 wxPropertyGridPageState* m_parentState;
1c4293cb 2282
939d9364 2283 wxClientData* m_clientObject;
1c4293cb 2284
939d9364
JS
2285 // Overrides editor returned by property class
2286 const wxPGEditor* m_customEditor;
2287#if wxUSE_VALIDATORS
2288 // Editor is going to get this validator
2289 wxValidator* m_validator;
2290#endif
2291 // Show this in front of the value
2292 //
2293 // TODO: Can bitmap be implemented with wxPGCell?
2294 wxBitmap* m_valueBitmap;
1c4293cb 2295
939d9364
JS
2296 wxVariant m_value;
2297 wxPGAttributeStorage m_attributes;
f7a094e1 2298 wxArrayPGProperty m_children;
1c4293cb 2299
939d9364 2300 // Extended cell information
d7e2b522 2301 wxVector<wxPGCell> m_cells;
1c4293cb 2302
939d9364
JS
2303 // Choices shown in drop-down list of editor control.
2304 wxPGChoices m_choices;
1c4293cb 2305
939d9364
JS
2306 // Help shown in statusbar or help box.
2307 wxString m_helpString;
1c4293cb 2308
939d9364
JS
2309 // Index in parent's property array.
2310 unsigned int m_arrIndex;
1c4293cb 2311
939d9364
JS
2312 // If not -1, then overrides m_value
2313 int m_commonValue;
1c4293cb 2314
939d9364 2315 FlagType m_flags;
1c4293cb 2316
939d9364
JS
2317 // Maximum length (mainly for string properties). Could be in some sort of
2318 // wxBaseStringProperty, but currently, for maximum flexibility and
2319 // compatibility, we'll stick it here. Anyway, we had 3 excess bytes to use
2320 // so short int will fit in just fine.
2321 short m_maxLen;
1c4293cb 2322
939d9364
JS
2323 // Root has 0, categories etc. at that level 1, etc.
2324 unsigned char m_depth;
1c4293cb 2325
939d9364
JS
2326 // m_depthBgCol indicates width of background colour between margin and item
2327 // (essentially this is category's depth, if none then equals m_depth).
2328 unsigned char m_depthBgCol;
1c4293cb 2329
939d9364
JS
2330private:
2331 // Called in constructors.
2332 void Init();
2333 void Init( const wxString& label, const wxString& name );
2334#endif // #ifndef SWIG
2335};
1c4293cb 2336
939d9364 2337// -----------------------------------------------------------------------
1c4293cb 2338
939d9364
JS
2339//
2340// Property class declaration helper macros
2341// (wxPGRootPropertyClass and wxPropertyCategory require this).
2342//
1c4293cb 2343
939d9364
JS
2344#define WX_PG_DECLARE_DOGETEDITORCLASS \
2345 virtual const wxPGEditor* DoGetEditorClass() const;
1c4293cb
VZ
2346
2347#ifndef SWIG
939d9364
JS
2348 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
2349 public: \
2350 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
2351 WX_PG_DECLARE_DOGETEDITORCLASS \
2352 private:
2353#else
2354 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME)
2355#endif
1c4293cb 2356
939d9364
JS
2357// Implements sans constructor function. Also, first arg is class name, not
2358// property name.
2359#define WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(PROPNAME,T,EDITOR) \
2360const wxPGEditor* PROPNAME::DoGetEditorClass() const \
2361{ \
2362 return wxPGEditor_##EDITOR; \
2363}
1c4293cb 2364
939d9364 2365// -----------------------------------------------------------------------
1c4293cb 2366
939d9364 2367#ifndef SWIG
1c4293cb 2368
939d9364
JS
2369/** @class wxPGRootProperty
2370 @ingroup classes
2371 Root parent property.
2372*/
2373class WXDLLIMPEXP_PROPGRID wxPGRootProperty : public wxPGProperty
2374{
2375public:
2376 WX_PG_DECLARE_PROPERTY_CLASS(wxPGRootProperty)
2377public:
1c4293cb 2378
939d9364 2379 /** Constructor. */
94b8ecf1 2380 wxPGRootProperty( const wxString& name = wxS("<Root>") );
939d9364 2381 virtual ~wxPGRootProperty();
1c4293cb 2382
939d9364 2383 virtual bool StringToValue( wxVariant&, const wxString&, int ) const
1c4293cb 2384 {
939d9364 2385 return false;
1c4293cb
VZ
2386 }
2387
939d9364
JS
2388protected:
2389};
1c4293cb 2390
939d9364 2391// -----------------------------------------------------------------------
1c4293cb 2392
939d9364
JS
2393/** @class wxPropertyCategory
2394 @ingroup classes
2395 Category (caption) property.
2396*/
2397class WXDLLIMPEXP_PROPGRID wxPropertyCategory : public wxPGProperty
2398{
2399 friend class wxPropertyGrid;
2400 friend class wxPropertyGridPageState;
2401 WX_PG_DECLARE_PROPERTY_CLASS(wxPropertyCategory)
2402public:
1c4293cb 2403
939d9364
JS
2404 /** Default constructor is only used in special cases. */
2405 wxPropertyCategory();
2406
2407 wxPropertyCategory( const wxString& label,
2408 const wxString& name = wxPG_LABEL );
2409 ~wxPropertyCategory();
2410
2411 int GetTextExtent( const wxWindow* wnd, const wxFont& font ) const;
1c4293cb 2412
1425eca5 2413 virtual wxString ValueToString( wxVariant& value, int argFlags ) const;
1c4293cb 2414
a09307ab 2415protected:
939d9364
JS
2416 void SetTextColIndex( unsigned int colInd )
2417 { m_capFgColIndex = (wxByte) colInd; }
2418 unsigned int GetTextColIndex() const
2419 { return (unsigned int) m_capFgColIndex; }
2420
2421 void CalculateTextExtent( wxWindow* wnd, const wxFont& font );
2422
2423 int m_textExtent; // pre-calculated length of text
2424 wxByte m_capFgColIndex; // caption text colour index
2425
2426private:
1c4293cb 2427 void Init();
1c4293cb
VZ
2428};
2429
939d9364 2430#endif // !SWIG
1c4293cb
VZ
2431
2432// -----------------------------------------------------------------------
2433
f4bc1aa2
JS
2434#endif // wxUSE_PROPGRID
2435
1c4293cb 2436#endif // _WX_PROPGRID_PROPERTY_H_