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