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