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