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