]> git.saurik.com Git - wxWidgets.git/blame - include/wx/propgrid/property.h
Remove use of wxPG_EDITOR macro
[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 );
218 size_t GetCount() const { return m_map.size(); }
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
392// Amalgam of flags that should be inherited by sub-properties
393#define wxPG_INHERITED_PROPFLAGS (wxPG_PROP_HIDDEN|wxPG_PROP_NOEDITOR)
394
395// Combination of flags that can be stored by GetFlagsAsString
396#define wxPG_STRING_STORED_FLAGS \
397 (wxPG_PROP_DISABLED|wxPG_PROP_HIDDEN|wxPG_PROP_NOEDITOR|wxPG_PROP_COLLAPSED)
398
399// -----------------------------------------------------------------------
400
401#ifndef SWIG
402
403/**
404 @section propgrid_property_attributes wxPropertyGrid Property Attribute
405 Identifiers.
406
407 wxPGProperty::SetAttribute() and
15cbcd00 408 wxPropertyGridInterface::SetPropertyAttribute() accept one of these as
1c4293cb
VZ
409 attribute name argument.
410
411 You can use strings instead of constants. However, some of these
412 constants are redefined to use cached strings which may reduce
413 your binary size by some amount.
414
415 @{
416*/
417
418/** Set default value for property.
419*/
420#define wxPG_ATTR_DEFAULT_VALUE wxS("DefaultValue")
421
422/** Universal, int or double. Minimum value for numeric properties.
423*/
424#define wxPG_ATTR_MIN wxS("Min")
425
426/** Universal, int or double. Maximum value for numeric properties.
427*/
428#define wxPG_ATTR_MAX wxS("Max")
429
430/** Universal, string. When set, will be shown as text after the displayed
431 text value. Alternatively, if third column is enabled, text will be shown
432 there (for any type of property).
433*/
434#define wxPG_ATTR_UNITS wxS("Units")
435
436/** Universal, string. When set, will be shown in property's value cell
437 when displayed value string is empty, or value is unspecified.
438*/
439#define wxPG_ATTR_INLINE_HELP wxS("InlineHelp")
440
441/** wxBoolProperty specific, int, default 0. When 1 sets bool property to
442 use checkbox instead of choice.
443*/
444#define wxPG_BOOL_USE_CHECKBOX wxS("UseCheckbox")
445
446/** wxBoolProperty specific, int, default 0. When 1 sets bool property value
447 to cycle on double click (instead of showing the popup listbox).
448*/
449#define wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING wxS("UseDClickCycling")
450
451/**
452 wxFloatProperty (and similar) specific, int, default -1.
453
454 Sets the (max) precision used when floating point value is rendered as
455 text. The default -1 means infinite precision.
456*/
457#define wxPG_FLOAT_PRECISION wxS("Precision")
458
459/**
460 The text will be echoed as asterisks (wxTE_PASSWORD will be passed to
461 textctrl etc).
462*/
463#define wxPG_STRING_PASSWORD wxS("Password")
464
465/** Define base used by a wxUIntProperty. Valid constants are
466 wxPG_BASE_OCT, wxPG_BASE_DEC, wxPG_BASE_HEX and wxPG_BASE_HEXL
467 (lowercase characters).
468*/
469#define wxPG_UINT_BASE wxS("Base")
470
471/** Define prefix rendered to wxUIntProperty. Accepted constants
472 wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and wxPG_PREFIX_DOLLAR_SIGN.
473 <b>Note:</b> Only wxPG_PREFIX_NONE works with Decimal and Octal
474 numbers.
475*/
476#define wxPG_UINT_PREFIX wxS("Prefix")
477
478/**
479 wxFileProperty/wxImageFileProperty specific, wxChar*, default is
480 detected/varies.
481 Sets the wildcard used in the triggered wxFileDialog. Format is the same.
482*/
483#define wxPG_FILE_WILDCARD wxS("Wildcard")
484
485/** wxFileProperty/wxImageFileProperty specific, int, default 1.
486 When 0, only the file name is shown (i.e. drive and directory are hidden).
487*/
488#define wxPG_FILE_SHOW_FULL_PATH wxS("ShowFullPath")
489
490/** Specific to wxFileProperty and derived properties, wxString, default empty.
491 If set, then the filename is shown relative to the given path string.
492*/
493#define wxPG_FILE_SHOW_RELATIVE_PATH wxS("ShowRelativePath")
494
495/**
496 Specific to wxFileProperty and derived properties, wxString, default is
497 empty.
498
499 Sets the initial path of where to look for files.
500*/
501#define wxPG_FILE_INITIAL_PATH wxS("InitialPath")
502
503/** Specific to wxFileProperty and derivatives, wxString, default is empty.
504 Sets a specific title for the dir dialog.
505*/
506#define wxPG_FILE_DIALOG_TITLE wxS("DialogTitle")
507
508/** Specific to wxDirProperty, wxString, default is empty.
509 Sets a specific message for the dir dialog.
510*/
511#define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage")
512
513/** Sets displayed date format for wxDateProperty.
514*/
515#define wxPG_DATE_FORMAT wxS("DateFormat")
516
517/** Sets wxDatePickerCtrl window style used with wxDateProperty. Default
518 is wxDP_DEFAULT | wxDP_SHOWCENTURY.
519*/
520#define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
521
522/** SpinCtrl editor, int or double. How much number changes when button is
523 pressed (or up/down on keybard).
524*/
525#define wxPG_ATTR_SPINCTRL_STEP wxS("Step")
526
527/** SpinCtrl editor, bool. If true, value wraps at Min/Max.
528*/
529#define wxPG_ATTR_SPINCTRL_WRAP wxS("Wrap")
530
531/**
532 wxMultiChoiceProperty, int.
533 If 0, no user strings allowed. If 1, user strings appear before list
534 strings. If 2, user strings appear after list string.
535*/
536#define wxPG_ATTR_MULTICHOICE_USERSTRINGMODE wxS("UserStringMode")
537
538/**
539 wxColourProperty and its kind, int, default 1.
540
541 Setting this attribute to 0 hides custom colour from property's list of
542 choices.
543*/
544#define wxPG_COLOUR_ALLOW_CUSTOM wxS("AllowCustom")
545
1c4293cb
VZ
546/** @}
547*/
548
1c4293cb
VZ
549// Redefine attribute macros to use cached strings
550#undef wxPG_ATTR_MIN
551#define wxPG_ATTR_MIN wxPGGlobalVars->m_strMin
552#undef wxPG_ATTR_MAX
553#define wxPG_ATTR_MAX wxPGGlobalVars->m_strMax
554#undef wxPG_ATTR_UNITS
555#define wxPG_ATTR_UNITS wxPGGlobalVars->m_strUnits
556#undef wxPG_ATTR_INLINE_HELP
557#define wxPG_ATTR_INLINE_HELP wxPGGlobalVars->m_strInlineHelp
558
1c4293cb
VZ
559#endif // !SWIG
560
561// -----------------------------------------------------------------------
562
939d9364 563#ifndef SWIG
1c4293cb 564
939d9364
JS
565/** @class wxPGChoiceEntry
566 Data of a single wxPGChoices choice.
1c4293cb 567*/
939d9364 568class WXDLLIMPEXP_PROPGRID wxPGChoiceEntry : public wxPGCell
1c4293cb 569{
1c4293cb 570public:
939d9364
JS
571 wxPGChoiceEntry();
572 wxPGChoiceEntry( const wxPGChoiceEntry& entry );
573 wxPGChoiceEntry( const wxString& label,
574 int value = wxPG_INVALID_VALUE )
575 : wxPGCell(), m_value(value)
576 {
577 m_text = label;
578 }
1c4293cb 579
939d9364
JS
580 wxPGChoiceEntry( const wxString& label,
581 int value,
582 const wxBitmap& bitmap,
583 const wxColour& fgCol = wxNullColour,
584 const wxColour& bgCol = wxNullColour )
585 : wxPGCell(label, bitmap, fgCol, bgCol), m_value(value)
586 {
587 }
1c4293cb 588
939d9364
JS
589 virtual ~wxPGChoiceEntry()
590 {
591 }
1c4293cb 592
939d9364 593 void SetValue( int value ) { m_value = value; }
1c4293cb 594
939d9364 595 int GetValue() const { return m_value; }
1c4293cb 596
939d9364 597 bool HasValue() const { return (m_value != wxPG_INVALID_VALUE); }
1c4293cb 598
939d9364
JS
599protected:
600 int m_value;
601};
1c4293cb 602
1c4293cb 603
939d9364 604typedef void* wxPGChoicesId;
1c4293cb 605
939d9364
JS
606class WXDLLIMPEXP_PROPGRID wxPGChoicesData
607{
608 friend class wxPGChoices;
609public:
610 // Constructor sets m_refCount to 1.
611 wxPGChoicesData();
1c4293cb 612
939d9364 613 void CopyDataFrom( wxPGChoicesData* data );
1c4293cb 614
939d9364
JS
615 // Takes ownership of 'item'
616 void Insert( int index, wxPGChoiceEntry* item )
617 {
f7a094e1 618 wxVector<wxPGChoiceEntry*>::iterator it;
939d9364
JS
619 if ( index == -1 )
620 {
621 it = m_items.end();
622 index = m_items.size();
623 }
624 else
625 {
626 it = m_items.begin() + index;
627 }
1c4293cb 628
939d9364
JS
629 // Need to fix value?
630 if ( item->GetValue() == wxPG_INVALID_VALUE )
631 item->SetValue(index);
1c4293cb 632
939d9364
JS
633 m_items.insert(it, item);
634 }
1c4293cb 635
939d9364
JS
636 // Delete all entries
637 void Clear();
1c4293cb 638
939d9364 639 size_t GetCount() const { return m_items.size(); }
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
939d9364
JS
784 const wxString& GetLabel( size_t ind ) const
785 {
786 return Item(ind).GetText();
787 }
1c4293cb 788
939d9364
JS
789 size_t GetCount () const
790 {
791 if ( !m_data )
792 return 0;
1c4293cb 793
939d9364
JS
794 return m_data->GetCount();
795 }
1c4293cb 796
939d9364 797 int GetValue( size_t 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
939d9364
JS
974 // If has private child properties then create them here, e.g.:
975 // AddChild( new wxStringProperty( "Subprop 1",
976 // wxPG_LABEL,
977 // value.GetSubProp1() ) );
978 }
1c4293cb 979
939d9364
JS
980 @endcode
981 */
982 wxPGProperty( const wxString& label, const wxString& name );
1c4293cb 983
939d9364
JS
984 /**
985 Virtual destructor.
986 It is customary for derived properties to implement this.
1c4293cb 987 */
939d9364 988 virtual ~wxPGProperty();
1c4293cb 989
939d9364 990 /** This virtual function is called after m_value has been set.
1c4293cb 991
939d9364
JS
992 @remarks
993 - If m_value was set to Null variant (ie. unspecified value),
994 OnSetValue() will not be called.
995 - m_value may be of any variant type. Typically properties internally
996 support only one variant type, and as such OnSetValue() provides a
997 good opportunity to convert
998 supported values into internal type.
999 - Default implementation does nothing.
1000 */
1001 virtual void OnSetValue();
1c4293cb 1002
939d9364
JS
1003 /** Override this to return something else than m_value as the value.
1004 */
1005 virtual wxVariant DoGetValue() const { return m_value; }
1006
1007#if !defined(SWIG) || defined(CREATE_VCW)
1008 /** Implement this function in derived class to check the value.
1009 Return true if it is ok. Returning false prevents property change events
1010 from occurring.
1c4293cb 1011
1c4293cb 1012 @remarks
939d9364 1013 - Default implementation always returns true.
1c4293cb 1014 */
939d9364
JS
1015 virtual bool ValidateValue( wxVariant& value,
1016 wxPGValidationInfo& validationInfo ) const;
1c4293cb 1017
939d9364 1018 /**
9e6bebdc
JS
1019 Converts text into wxVariant value appropriate for this property.
1020
1021 @param variant
1022 On function entry this is the old value (should not be wxNullVariant
1023 in normal cases). Translated value must be assigned back to it.
1024
1025 @param text
1026 Text to be translated into variant.
1027
939d9364
JS
1028 @param argFlags
1029 If wxPG_FULL_VALUE is set, returns complete, storable value instead
1030 of displayable one (they may be different).
1031 If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of
1032 composite property string value (as generated by GetValueAsString()
1033 called with this same flag).
1c4293cb 1034
9e6bebdc
JS
1035 @return Returns @true if resulting wxVariant value was different.
1036
1037 @remarks Default implementation converts semicolon delimited tokens into
1038 child values. Only works for properties with children.
1039
1040 You might want to take into account that m_value is Null variant
1041 if property value is unspecified (which is usually only case if
1042 you explicitly enabled that sort behavior).
1c4293cb 1043 */
939d9364
JS
1044 virtual bool StringToValue( wxVariant& variant,
1045 const wxString& text,
1046 int argFlags = 0 ) const;
1c4293cb 1047
939d9364 1048 /**
9e6bebdc
JS
1049 Converts integer (possibly a choice selection) into wxVariant value
1050 appropriate for this property.
1c4293cb 1051
9e6bebdc
JS
1052 @param variant
1053 On function entry this is the old value (should not be wxNullVariant
1054 in normal cases). Translated value must be assigned back to it.
1055
1056 @param number
1057 Integer to be translated into variant.
1c4293cb 1058
939d9364
JS
1059 @param argFlags
1060 If wxPG_FULL_VALUE is set, returns complete, storable value instead
1061 of displayable one.
1c4293cb 1062
9e6bebdc
JS
1063 @return Returns @true if resulting wxVariant value was different.
1064
939d9364
JS
1065 @remarks
1066 - If property is not supposed to use choice or spinctrl or other editor
1067 with int-based value, it is not necessary to implement this method.
1068 - Default implementation simply assign given int to m_value.
1069 - If property uses choice control, and displays a dialog on some choice
1070 items, then it is preferred to display that dialog in IntToValue
1071 instead of OnEvent.
9e6bebdc
JS
1072 - You might want to take into account that m_value is Null variant if
1073 property value is unspecified (which is usually only case if you
1074 explicitly enabled that sort behavior).
1c4293cb 1075 */
939d9364
JS
1076 virtual bool IntToValue( wxVariant& value,
1077 int number,
1078 int argFlags = 0 ) const;
1079#endif // !defined(SWIG) || defined(CREATE_VCW)
1c4293cb 1080
939d9364
JS
1081public:
1082 /** Returns text representation of property's value.
1c4293cb 1083
939d9364
JS
1084 @param argFlags
1085 If wxPG_FULL_VALUE is set, returns complete, storable string value
1086 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
1087 string value that must be editable in textctrl. If
1088 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
1089 display as a part of composite property string value.
1c4293cb 1090
939d9364
JS
1091 @remarks
1092 Default implementation returns string composed from text
1093 representations of child properties.
1c4293cb 1094 */
939d9364 1095 virtual wxString GetValueAsString( int argFlags = 0 ) const;
1c4293cb 1096
939d9364
JS
1097 /** Converts string to a value, and if successful, calls SetValue() on it.
1098 Default behavior is to do nothing.
1099 @param text
1100 String to get the value from.
1101 @return
1102 true if value was changed.
1c4293cb 1103 */
939d9364 1104 bool SetValueFromString( const wxString& text, int flags = 0 );
1c4293cb 1105
939d9364
JS
1106 /** Converts integer to a value, and if succesful, calls SetValue() on it.
1107 Default behavior is to do nothing.
1108 @param value
1109 Int to get the value from.
1110 @param flags
1111 If has wxPG_FULL_VALUE, then the value given is a actual value and
1112 not an index.
1113 @return
1114 True if value was changed.
1c4293cb 1115 */
939d9364 1116 bool SetValueFromInt( long value, int flags = 0 );
1c4293cb
VZ
1117
1118 /**
939d9364 1119 Returns size of the custom painted image in front of property.
1c4293cb 1120
939d9364
JS
1121 This method must be overridden to return non-default value if
1122 OnCustomPaint is to be called.
1123 @param item
1124 Normally -1, but can be an index to the property's list of items.
1125 @remarks
1126 - Default behavior is to return wxSize(0,0), which means no image.
1127 - Default image width or height is indicated with dimension -1.
1128 - You can also return wxPG_DEFAULT_IMAGE_SIZE, i.e. wxSize(-1, -1).
1c4293cb 1129 */
939d9364 1130 virtual wxSize OnMeasureImage( int item = -1 ) const;
1c4293cb
VZ
1131
1132 /**
939d9364 1133 Events received by editor widgets are processed here.
1c4293cb 1134
939d9364
JS
1135 Note that editor class usually processes most events. Some, such as
1136 button press events of TextCtrlAndButton class, can be handled here.
1137 Also, if custom handling for regular events is desired, then that can
1138 also be done (for example, wxSystemColourProperty custom handles
1139 wxEVT_COMMAND_CHOICE_SELECTED to display colour picker dialog when
1140 'custom' selection is made).
1c4293cb 1141
939d9364
JS
1142 If the event causes value to be changed, SetValueInEvent()
1143 should be called to set the new value.
1c4293cb 1144
939d9364
JS
1145 @param event
1146 Associated wxEvent.
1147 @return
1148 Should return true if any changes in value should be reported.
1149 @remarks
1150 If property uses choice control, and displays a dialog on some choice
1151 items, then it is preferred to display that dialog in IntToValue
1152 instead of OnEvent.
1c4293cb 1153 */
939d9364
JS
1154 virtual bool OnEvent( wxPropertyGrid* propgrid,
1155 wxWindow* wnd_primary,
1156 wxEvent& event );
1c4293cb 1157
939d9364
JS
1158 /**
1159 Called after value of a child property has been altered.
1c4293cb 1160
939d9364
JS
1161 Note that this function is usually called at the time that value of
1162 this property, or given child property, is still pending for change.
1c4293cb 1163
939d9364 1164 Sample pseudo-code implementation:
1c4293cb 1165
939d9364
JS
1166 @code
1167 void MyProperty::ChildChanged( wxVariant& thisValue,
1168 int childIndex,
1169 wxVariant& childValue ) const
1170 {
1171 // Acquire reference to actual type of data stored in variant
1172 // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros
1173 // were used to create the variant class).
1174 T& data = TFromVariant(thisValue);
1c4293cb 1175
939d9364
JS
1176 // Copy childValue into data.
1177 switch ( childIndex )
1178 {
1179 case 0:
1180 data.SetSubProp1( childvalue.GetLong() );
1181 break;
1182 case 1:
1183 data.SetSubProp2( childvalue.GetString() );
1184 break;
1185 ...
1186 }
1187 }
1188 @endcode
1c4293cb 1189
939d9364
JS
1190 @param thisValue
1191 Value of this property, that should be altered.
1192 @param childIndex
1193 Index of child changed (you can use Item(childIndex) to get).
1194 @param childValue
1195 Value of the child property.
1c4293cb 1196 */
939d9364
JS
1197 virtual void ChildChanged( wxVariant& thisValue,
1198 int childIndex,
1199 wxVariant& childValue ) const;
1c4293cb 1200
939d9364 1201 /** Returns pointer to an instance of used editor.
1c4293cb 1202 */
939d9364 1203 virtual const wxPGEditor* DoGetEditorClass() const;
1c4293cb 1204
939d9364
JS
1205 /** Returns pointer to the wxValidator that should be used
1206 with the editor of this property (NULL for no validator).
1207 Setting validator explicitly via SetPropertyValidator
1208 will override this.
1c4293cb 1209
939d9364
JS
1210 In most situations, code like this should work well
1211 (macros are used to maintain one actual validator instance,
1212 so on the second call the function exits within the first
1213 macro):
1c4293cb 1214
939d9364 1215 @code
1c4293cb 1216
939d9364
JS
1217 wxValidator* wxMyPropertyClass::DoGetValidator () const
1218 {
1219 WX_PG_DOGETVALIDATOR_ENTRY()
1c4293cb 1220
939d9364 1221 wxMyValidator* validator = new wxMyValidator(...);
1c4293cb 1222
939d9364 1223 ... prepare validator...
1c4293cb 1224
939d9364
JS
1225 WX_PG_DOGETVALIDATOR_EXIT(validator)
1226 }
1c4293cb 1227
939d9364
JS
1228 @endcode
1229
1230 @remarks
1231 You can get common filename validator by returning
1232 wxFileProperty::GetClassValidator(). wxDirProperty,
1233 for example, uses it.
1c4293cb 1234 */
939d9364 1235 virtual wxValidator* DoGetValidator () const;
1c4293cb 1236
939d9364
JS
1237 /**
1238 Override to paint an image in front of the property value text or
1239 drop-down list item (but only if wxPGProperty::OnMeasureImage is
1240 overridden as well).
1c4293cb 1241
939d9364
JS
1242 If property's OnMeasureImage() returns size that has height != 0 but
1243 less than row height ( < 0 has special meanings), wxPropertyGrid calls
1244 this method to draw a custom image in a limited area in front of the
1245 editor control or value text/graphics, and if control has drop-down
1246 list, then the image is drawn there as well (even in the case
1247 OnMeasureImage() returned higher height than row height).
1c4293cb 1248
939d9364
JS
1249 NOTE: Following applies when OnMeasureImage() returns a "flexible"
1250 height ( using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable
1251 height items: If rect.x is < 0, then this is a measure item call, which
1252 means that dc is invalid and only thing that should be done is to set
1253 paintdata.m_drawnHeight to the height of the image of item at index
1254 paintdata.m_choiceItem. This call may be done even as often as once
1255 every drop-down popup show.
1c4293cb 1256
939d9364
JS
1257 @param dc
1258 wxDC to paint on.
1259 @param rect
1260 Box reserved for custom graphics. Includes surrounding rectangle,
1261 if any. If x is < 0, then this is a measure item call (see above).
1262 @param paintdata
1263 wxPGPaintData structure with much useful data.
1c4293cb 1264
939d9364
JS
1265 @remarks
1266 - You can actually exceed rect width, but if you do so then
1267 paintdata.m_drawnWidth must be set to the full width drawn in
1268 pixels.
1269 - Due to technical reasons, rect's height will be default even if
1270 custom height was reported during measure call.
1271 - Brush is guaranteed to be default background colour. It has been
1272 already used to clear the background of area being painted. It
1273 can be modified.
1274 - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper
1275 colour) pen for drawing framing rectangle. It can be changed as
1276 well.
1277
1278 @see GetValueAsString()
1c4293cb 1279 */
939d9364
JS
1280 virtual void OnCustomPaint( wxDC& dc,
1281 const wxRect& rect,
1282 wxPGPaintData& paintdata );
1c4293cb 1283
939d9364
JS
1284 /**
1285 Returns used wxPGCellRenderer instance for given property column
1286 (label=0, value=1).
1c4293cb 1287
939d9364 1288 Default implementation returns editor's renderer for all columns.
1c4293cb 1289 */
939d9364 1290 virtual wxPGCellRenderer* GetCellRenderer( int column ) const;
1c4293cb 1291
939d9364
JS
1292 /** Returns which choice is currently selected. Only applies to properties
1293 which have choices.
1c4293cb 1294
939d9364
JS
1295 Needs to reimplemented in derived class if property value does not
1296 map directly to a choice. Integer as index, bool, and string usually do.
1c4293cb 1297 */
939d9364 1298 virtual int GetChoiceSelection() const;
1c4293cb 1299
939d9364
JS
1300 /**
1301 Refresh values of child properties.
1c4293cb 1302
939d9364 1303 Automatically called after value is set.
1c4293cb 1304 */
939d9364 1305 virtual void RefreshChildren();
1c4293cb 1306
939d9364 1307 /** Special handling for attributes of this property.
1c4293cb 1308
939d9364
JS
1309 If returns false, then the attribute will be automatically stored in
1310 m_attributes.
1c4293cb 1311
939d9364 1312 Default implementation simply returns false.
1c4293cb 1313 */
939d9364 1314 virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
1c4293cb 1315
939d9364 1316 /** Returns value of an attribute.
1c4293cb 1317
939d9364 1318 Override if custom handling of attributes is needed.
1c4293cb 1319
939d9364 1320 Default implementation simply return NULL variant.
1c4293cb 1321 */
939d9364 1322 virtual wxVariant DoGetAttribute( const wxString& name ) const;
1c4293cb 1323
939d9364
JS
1324 /** Returns instance of a new wxPGEditorDialogAdapter instance, which is
1325 used when user presses the (optional) button next to the editor control;
1c4293cb 1326
939d9364
JS
1327 Default implementation returns NULL (ie. no action is generated when
1328 button is pressed).
1c4293cb 1329 */
939d9364
JS
1330 virtual wxPGEditorDialogAdapter* GetEditorDialog() const;
1331
1332 /** Returns wxPGCell of given column, NULL if none. If valid
1333 object is returned, caller will gain its ownership.
1334 */
1335 wxPGCell* AcquireCell( unsigned int column )
1c4293cb 1336 {
939d9364
JS
1337 if ( column >= m_cells.size() )
1338 return NULL;
1339
1340 wxPGCell* cell = (wxPGCell*) m_cells[column];
1341 m_cells[column] = NULL;
1342 return cell;
1c4293cb
VZ
1343 }
1344
939d9364 1345 /** Append a new choice to property's list of choices.
1c4293cb 1346 */
939d9364
JS
1347 int AddChoice( const wxString& label, int value = wxPG_INVALID_VALUE )
1348 {
1349 return InsertChoice(label, wxNOT_FOUND, value);
1350 }
1c4293cb 1351
939d9364
JS
1352 /**
1353 Returns true if children of this property are component values (for
1354 instance, points size, face name, and is_underlined are component
1355 values of a font).
1c4293cb 1356 */
939d9364 1357 bool AreChildrenComponents() const
1c4293cb 1358 {
939d9364
JS
1359 if ( m_flags & (wxPG_PROP_COMPOSED_VALUE|wxPG_PROP_AGGREGATE) )
1360 return true;
1361
1362 return false;
1c4293cb
VZ
1363 }
1364
939d9364
JS
1365 /**
1366 Removes entry from property's wxPGChoices and editor control (if it is
1367 active).
1c4293cb 1368
939d9364 1369 If selected item is deleted, then the value is set to unspecified.
1c4293cb 1370 */
939d9364 1371 void DeleteChoice( int index );
1c4293cb
VZ
1372
1373 /**
939d9364
JS
1374 Call to enable or disable usage of common value (integer value that can
1375 be selected for properties instead of their normal values) for this
1376 property.
1c4293cb 1377
939d9364
JS
1378 Common values are disabled by the default for all properties.
1379 */
1380 void EnableCommonValue( bool enable = true )
1381 {
1382 if ( enable ) SetFlag( wxPG_PROP_USES_COMMON_VALUE );
1383 else ClearFlag( wxPG_PROP_USES_COMMON_VALUE );
1384 }
1c4293cb 1385
939d9364
JS
1386 /** Composes text from values of child properties. */
1387 void GenerateComposedValue( wxString& text, int argFlags = 0 ) const;
1c4293cb 1388
939d9364
JS
1389 /** Returns property's label. */
1390 const wxString& GetLabel() const { return m_label; }
1c4293cb 1391
939d9364
JS
1392 /** Returns property's name with all (non-category, non-root) parents. */
1393 wxString GetName() const;
1c4293cb 1394
939d9364
JS
1395 /**
1396 Returns property's base name (ie parent's name is not added in any
1397 case)
1398 */
1399 const wxString& GetBaseName() const { return m_name; }
1400
1401 /** Returns read-only reference to property's list of choices.
1c4293cb 1402 */
939d9364
JS
1403 const wxPGChoices& GetChoices() const
1404 {
1405 return m_choices;
1406 }
1c4293cb 1407
939d9364
JS
1408 /** Returns coordinate to the top y of the property. Note that the
1409 position of scrollbars is not taken into account.
1c4293cb 1410 */
939d9364 1411 int GetY() const;
1c4293cb 1412
939d9364 1413 wxVariant GetValue() const
1c4293cb 1414 {
939d9364 1415 return DoGetValue();
1c4293cb
VZ
1416 }
1417
939d9364
JS
1418#ifndef SWIG
1419 /** Returns reference to the internal stored value. GetValue is preferred
1420 way to get the actual value, since GetValueRef ignores DoGetValue,
1421 which may override stored value.
1422 */
1423 wxVariant& GetValueRef()
1424 {
1425 return m_value;
1426 }
1c4293cb 1427
939d9364 1428 const wxVariant& GetValueRef() const
1c4293cb 1429 {
939d9364 1430 return m_value;
1c4293cb 1431 }
939d9364 1432#endif
1c4293cb 1433
40924780
JS
1434 /** To acquire property's value as string, you should use this
1435 function (instead of GetValueAsString()), as it may produce
1436 more accurate value in future versions.
939d9364
JS
1437 */
1438 wxString GetValueString( int argFlags = 0 ) const;
1c4293cb 1439
939d9364 1440 void UpdateControl( wxWindow* primary );
1c4293cb 1441
939d9364
JS
1442 /** Returns wxPGCell of given column, NULL if none. wxPGProperty
1443 will retain ownership of the cell object.
1444 */
1445 wxPGCell* GetCell( unsigned int column ) const
1c4293cb 1446 {
939d9364
JS
1447 if ( column >= m_cells.size() )
1448 return NULL;
1c4293cb 1449
939d9364 1450 return (wxPGCell*) m_cells[column];
1c4293cb
VZ
1451 }
1452
939d9364
JS
1453 /** Return number of displayed common values for this property.
1454 */
1455 int GetDisplayedCommonValueCount() const;
1456
1457 wxString GetDisplayedString() const
1c4293cb 1458 {
939d9364 1459 return GetValueString(0);
1c4293cb 1460 }
1c4293cb 1461
939d9364
JS
1462 /** Returns property grid where property lies. */
1463 wxPropertyGrid* GetGrid() const;
1464
1465 /** Returns owner wxPropertyGrid, but only if one is currently on a page
1466 displaying this property. */
1467 wxPropertyGrid* GetGridIfDisplayed() const;
1468
1469 /** Returns highest level non-category, non-root parent. Useful when you
1470 have nested wxCustomProperties/wxParentProperties.
1c4293cb 1471 @remarks
939d9364
JS
1472 Thus, if immediate parent is root or category, this will return the
1473 property itself.
1c4293cb 1474 */
939d9364 1475 wxPGProperty* GetMainParent() const;
1c4293cb 1476
939d9364
JS
1477 /** Return parent of property */
1478 wxPGProperty* GetParent() const { return m_parent; }
1479
1480 /** Returns true if property has editable wxTextCtrl when selected.
1481
1482 @remarks
1483 Altough disabled properties do not displayed editor, they still
1484 return True here as being disabled is considered a temporary
1485 condition (unlike being read-only or having limited editing enabled).
1c4293cb 1486 */
939d9364
JS
1487 bool IsTextEditable() const;
1488
1489 bool IsValueUnspecified() const
1c4293cb 1490 {
939d9364 1491 return m_value.IsNull();
1c4293cb
VZ
1492 }
1493
939d9364 1494 FlagType HasFlag( FlagType flag ) const
1c4293cb 1495 {
939d9364 1496 return ( m_flags & flag );
1c4293cb
VZ
1497 }
1498
939d9364 1499 /** Returns comma-delimited string of property attributes.
1c4293cb 1500 */
939d9364 1501 const wxPGAttributeStorage& GetAttributes() const
1c4293cb 1502 {
939d9364 1503 return m_attributes;
1c4293cb
VZ
1504 }
1505
939d9364 1506 /** Returns m_attributes as list wxVariant.
1c4293cb 1507 */
939d9364 1508 wxVariant GetAttributesAsList() const;
1c4293cb 1509
939d9364
JS
1510 FlagType GetFlags() const
1511 {
1512 return m_flags;
1513 }
1c4293cb 1514
939d9364 1515 const wxPGEditor* GetEditorClass() const;
1c4293cb 1516
939d9364
JS
1517 wxString GetValueType() const
1518 {
1519 return m_value.GetType();
1520 }
1c4293cb 1521
939d9364 1522 /** Returns editor used for given column. NULL for no editor.
1c4293cb 1523 */
939d9364 1524 const wxPGEditor* GetColumnEditor( int column ) const
1c4293cb 1525 {
939d9364
JS
1526 if ( column == 1 )
1527 return GetEditorClass();
1528
1529 return NULL;
1c4293cb
VZ
1530 }
1531
939d9364
JS
1532 /** Returns common value selected for this property. -1 for none.
1533 */
1534 int GetCommonValue() const
1c4293cb 1535 {
939d9364 1536 return m_commonValue;
1c4293cb
VZ
1537 }
1538
939d9364
JS
1539 /** Returns true if property has even one visible child.
1540 */
1541 bool HasVisibleChildren() const;
1c4293cb 1542
939d9364
JS
1543 /** Inserts a new choice to property's list of choices.
1544 */
1545 int InsertChoice( const wxString& label, int index, int value = wxPG_INVALID_VALUE );
1c4293cb
VZ
1546
1547 /**
939d9364 1548 Returns true if this property is actually a wxPropertyCategory.
1c4293cb 1549 */
939d9364 1550 bool IsCategory() const { return HasFlag(wxPG_PROP_CATEGORY)?true:false; }
1c4293cb 1551
939d9364 1552 /** Returns true if this property is actually a wxRootProperty.
1c4293cb 1553 */
939d9364 1554 bool IsRoot() const { return (m_parent == NULL); }
1c4293cb 1555
939d9364
JS
1556 /** Returns true if this is a sub-property. */
1557 bool IsSubProperty() const
1558 {
1559 wxPGProperty* parent = (wxPGProperty*)m_parent;
1560 if ( parent && !parent->IsCategory() )
1561 return true;
1562 return false;
1563 }
1c4293cb 1564
939d9364 1565 /** Returns last visible sub-property, recursively.
1c4293cb 1566 */
939d9364 1567 const wxPGProperty* GetLastVisibleSubItem() const;
1c4293cb 1568
939d9364 1569 wxVariant GetDefaultValue() const;
1c4293cb 1570
939d9364
JS
1571 int GetMaxLength() const
1572 {
1573 return (int) m_maxLen;
1574 }
1c4293cb 1575
939d9364
JS
1576 /**
1577 Determines, recursively, if all children are not unspecified.
1c4293cb 1578
bb6720bb
JS
1579 @param pendingList
1580 Assumes members in this wxVariant list as pending
1581 replacement values.
939d9364
JS
1582 */
1583 bool AreAllChildrenSpecified( wxVariant* pendingList = NULL ) const;
1c4293cb 1584
939d9364
JS
1585 /** Updates composed values of parent non-category properties, recursively.
1586 Returns topmost property updated.
1c4293cb 1587
939d9364
JS
1588 @remarks
1589 - Must not call SetValue() (as can be called in it).
1c4293cb 1590 */
939d9364 1591 wxPGProperty* UpdateParentValues();
1c4293cb 1592
939d9364
JS
1593 /** Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
1594 */
bb6720bb 1595 bool UsesAutoUnspecified() const
939d9364 1596 {
bb6720bb 1597 return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED)?true:false;
1c4293cb 1598 }
939d9364
JS
1599
1600 wxBitmap* GetValueImage() const
1601 {
1602 return m_valueBitmap;
1c4293cb 1603 }
1c4293cb 1604
939d9364 1605 wxVariant GetAttribute( const wxString& name ) const;
1c4293cb 1606
939d9364
JS
1607 /**
1608 Returns named attribute, as string, if found.
1c4293cb 1609
939d9364 1610 Otherwise defVal is returned.
1c4293cb 1611 */
939d9364 1612 wxString GetAttribute( const wxString& name, const wxString& defVal ) const;
1c4293cb 1613
939d9364
JS
1614 /**
1615 Returns named attribute, as long, if found.
1c4293cb 1616
939d9364
JS
1617 Otherwise defVal is returned.
1618 */
1619 long GetAttributeAsLong( const wxString& name, long defVal ) const;
1c4293cb 1620
939d9364
JS
1621 /**
1622 Returns named attribute, as double, if found.
1c4293cb 1623
939d9364 1624 Otherwise defVal is returned.
1c4293cb 1625 */
939d9364 1626 double GetAttributeAsDouble( const wxString& name, double defVal ) const;
1c4293cb 1627
939d9364 1628 unsigned int GetDepth() const { return (unsigned int)m_depth; }
1c4293cb 1629
939d9364
JS
1630 /** Gets flags as a'|' delimited string. Note that flag names are not
1631 prepended with 'wxPG_PROP_'.
1632 @param flagsMask
1633 String will only be made to include flags combined by this parameter.
1634 */
1635 wxString GetFlagsAsString( FlagType flagsMask ) const;
1c4293cb 1636
939d9364
JS
1637 /** Returns position in parent's array. */
1638 unsigned int GetIndexInParent() const
1c4293cb 1639 {
939d9364 1640 return (unsigned int)m_arrIndex;
1c4293cb
VZ
1641 }
1642
939d9364
JS
1643 /** Hides or reveals the property.
1644 @param hide
1645 true for hide, false for reveal.
1646 @param flags
1647 By default changes are applied recursively. Set this paramter
1648 wxPG_DONT_RECURSE to prevent this.
1649 */
1650 inline bool Hide( bool hide, int flags = wxPG_RECURSE );
1c4293cb 1651
939d9364
JS
1652 bool IsExpanded() const
1653 { return (!(m_flags & wxPG_PROP_COLLAPSED) && GetChildCount()); }
1c4293cb 1654
939d9364
JS
1655 /** Returns true if all parents expanded.
1656 */
1657 bool IsVisible() const;
1c4293cb 1658
939d9364 1659 bool IsEnabled() const { return !(m_flags & wxPG_PROP_DISABLED); }
1c4293cb 1660
939d9364
JS
1661 /** If property's editor is created this forces its recreation.
1662 Useful in SetAttribute etc. Returns true if actually did anything.
1663 */
1664 bool RecreateEditor();
1c4293cb 1665
939d9364
JS
1666 /** If property's editor is active, then update it's value.
1667 */
1668 void RefreshEditor();
1c4293cb 1669
939d9364
JS
1670 /** Sets an attribute for this property.
1671 @param name
1672 Text identifier of attribute. See @ref propgrid_property_attributes.
1673 @param value
1674 Value of attribute.
1675 */
1676 void SetAttribute( const wxString& name, wxVariant value );
1c4293cb 1677
939d9364 1678 void SetAttributes( const wxPGAttributeStorage& attributes );
1c4293cb 1679
939d9364
JS
1680#ifndef SWIG
1681 /** Sets editor for a property.
1c4293cb 1682
939d9364
JS
1683 @param editor
1684 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1685 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full
1686 list).
1c4293cb 1687
939d9364
JS
1688 For custom editors, use pointer you received from
1689 wxPropertyGrid::RegisterEditorClass().
1690 */
1691 void SetEditor( const wxPGEditor* editor )
1692 {
1693 m_customEditor = editor;
1694 }
1695#endif
1c4293cb 1696
939d9364
JS
1697 /** Sets editor for a property.
1698 */
1699 inline void SetEditor( const wxString& editorName );
1c4293cb 1700
939d9364 1701 /** Sets cell information for given column.
1c4293cb 1702
939d9364
JS
1703 Note that the property takes ownership of given wxPGCell instance.
1704 */
1705 void SetCell( int column, wxPGCell* cellObj );
1c4293cb 1706
939d9364
JS
1707 /** Sets common value selected for this property. -1 for none.
1708 */
1709 void SetCommonValue( int commonValue )
1710 {
1711 m_commonValue = commonValue;
1712 }
1c4293cb 1713
939d9364
JS
1714 /** Sets flags from a '|' delimited string. Note that flag names are not
1715 prepended with 'wxPG_PROP_'.
1716 */
1717 void SetFlagsFromString( const wxString& str );
1c4293cb 1718
939d9364
JS
1719 /** Sets property's "is it modified?" flag. Affects children recursively.
1720 */
1721 void SetModifiedStatus( bool modified )
1722 {
1723 SetFlagRecursively(wxPG_PROP_MODIFIED, modified);
1724 }
1c4293cb 1725
939d9364
JS
1726 /** Call in OnEvent(), OnButtonClick() etc. to change the property value
1727 based on user input.
1c4293cb 1728
939d9364
JS
1729 @remarks
1730 This method is const since it doesn't actually modify value, but posts
1731 given variant as pending value, stored in wxPropertyGrid.
1732 */
1733 void SetValueInEvent( wxVariant value ) const;
1c4293cb 1734
939d9364
JS
1735 /**
1736 Call this to set value of the property.
1c4293cb 1737
939d9364
JS
1738 Unlike methods in wxPropertyGrid, this does not automatically update
1739 the display.
1c4293cb 1740
939d9364
JS
1741 @remarks
1742 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run
1743 through validation process and send property change event.
1c4293cb 1744
939d9364
JS
1745 If you need to change property value in event, based on user input, use
1746 SetValueInEvent() instead.
1c4293cb 1747
939d9364
JS
1748 @param pList
1749 Pointer to list variant that contains child values. Used to indicate
1750 which children should be marked as modified.
1751 @param flags
1752 Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR).
1753 */
1754 void SetValue( wxVariant value, wxVariant* pList = NULL, int flags = 0 );
1c4293cb 1755
939d9364
JS
1756 /** Set wxBitmap in front of the value. This bitmap may be ignored
1757 by custom cell renderers.
1758 */
1759 void SetValueImage( wxBitmap& bmp );
1c4293cb 1760
939d9364
JS
1761 /** If property has choices and they are not yet exclusive, new such copy
1762 of them will be created.
1763 */
1764 void SetChoicesExclusive()
1c4293cb 1765 {
939d9364 1766 m_choices.SetExclusive();
1c4293cb
VZ
1767 }
1768
939d9364 1769 /** Sets selected choice and changes property value.
1c4293cb 1770
939d9364
JS
1771 Tries to retain value type, although currently if it is not string,
1772 then it is forced to integer.
1773 */
1774 void SetChoiceSelection( int newValue );
1c4293cb 1775
939d9364
JS
1776 void SetExpanded( bool expanded )
1777 {
1778 if ( !expanded ) m_flags |= wxPG_PROP_COLLAPSED;
1779 else m_flags &= ~wxPG_PROP_COLLAPSED;
1780 }
1c4293cb 1781
939d9364 1782 void SetFlag( FlagType flag ) { m_flags |= flag; }
1c4293cb 1783
939d9364 1784 void SetFlagRecursively( FlagType flag, bool set );
1c4293cb 1785
939d9364
JS
1786 void SetHelpString( const wxString& helpString )
1787 {
1788 m_helpString = helpString;
1789 }
1c4293cb 1790
939d9364 1791 void SetLabel( const wxString& label ) { m_label = label; }
1c4293cb 1792
939d9364 1793 inline void SetName( const wxString& newName );
1c4293cb 1794
939d9364
JS
1795 void SetValueToUnspecified()
1796 {
1797 wxVariant val; // Create NULL variant
1798 SetValue(val);
1799 }
1c4293cb 1800
939d9364
JS
1801#if wxUSE_VALIDATORS
1802 /** Sets wxValidator for a property*/
1803 void SetValidator( const wxValidator& validator )
1804 {
1805 m_validator = wxDynamicCast(validator.Clone(),wxValidator);
1806 }
1c4293cb 1807
939d9364
JS
1808 /** Gets assignable version of property's validator. */
1809 wxValidator* GetValidator() const
1810 {
1811 if ( m_validator )
1812 return m_validator;
1813 return DoGetValidator();
1814 }
1815#endif // #if wxUSE_VALIDATORS
1c4293cb 1816
939d9364
JS
1817 /** Updates property value in case there were last minute
1818 changes. If value was unspecified, it will be set to default.
1819 Use only for properties that have TextCtrl-based editor.
1820 @remarks
1821 If you have code similar to
1822 @code
1823 // Update the value in case of last minute changes
1824 if ( primary && propgrid->IsEditorsValueModified() )
1825 GetEditorClass()->CopyValueFromControl( this, primary );
1826 @endcode
1827 in wxPGProperty::OnEvent wxEVT_COMMAND_BUTTON_CLICKED handler,
1828 then replace it with call to this method.
1829 @return
1830 True if value changed.
1831 */
1832 bool PrepareValueForDialogEditing( wxPropertyGrid* propgrid );
1c4293cb
VZ
1833
1834#ifndef SWIG
939d9364
JS
1835 /** Returns client data (void*) of a property.
1836 */
1837 void* GetClientData() const
1c4293cb 1838 {
939d9364 1839 return m_clientData;
1c4293cb
VZ
1840 }
1841
939d9364
JS
1842 /** Sets client data (void*) of a property.
1843 @remarks
1844 This untyped client data has to be deleted manually.
1845 */
1846 void SetClientData( void* clientData )
1c4293cb 1847 {
939d9364 1848 m_clientData = clientData;
1c4293cb
VZ
1849 }
1850
939d9364
JS
1851 /** Returns client object of a property.
1852 */
1853 void SetClientObject(wxClientData* clientObject)
1c4293cb 1854 {
939d9364
JS
1855 delete m_clientObject;
1856 m_clientObject = clientObject;
1c4293cb
VZ
1857 }
1858
939d9364
JS
1859 /** Sets managed client object of a property.
1860 */
1861 wxClientData *GetClientObject() const { return m_clientObject; }
1862#endif
1c4293cb 1863
939d9364 1864 /** Sets new set of choices for property.
1c4293cb 1865
939d9364
JS
1866 @remarks
1867 This operation clears the property value.
1868 */
1869 bool SetChoices( wxPGChoices& choices );
1c4293cb 1870
939d9364
JS
1871 /** Set max length of text in text editor.
1872 */
1873 inline bool SetMaxLength( int maxLen );
1c4293cb 1874
939d9364
JS
1875 /** Call with 'false' in OnSetValue to cancel value changes after all
1876 (ie. cancel 'true' returned by StringToValue() or IntToValue()).
1877 */
1878 void SetWasModified( bool set = true )
1c4293cb 1879 {
939d9364
JS
1880 if ( set ) m_flags |= wxPG_PROP_WAS_MODIFIED;
1881 else m_flags &= ~wxPG_PROP_WAS_MODIFIED;
1882 }
1c4293cb 1883
939d9364
JS
1884 const wxString& GetHelpString() const
1885 {
1886 return m_helpString;
1c4293cb
VZ
1887 }
1888
939d9364 1889 void ClearFlag( FlagType flag ) { m_flags &= ~(flag); }
1c4293cb 1890
939d9364
JS
1891 // Use, for example, to detect if item is inside collapsed section.
1892 bool IsSomeParent( wxPGProperty* candidate_parent ) const;
1c4293cb 1893
939d9364
JS
1894 /**
1895 Adapts list variant into proper value using consecutive
1896 ChildChanged-calls.
1897 */
1898 void AdaptListToValue( wxVariant& list, wxVariant* value ) const;
99774d58 1899
939d9364
JS
1900 /** This is used by properties that have fixed sub-properties. */
1901 void AddChild( wxPGProperty* prop );
1c4293cb 1902
939d9364
JS
1903 /** Returns height of children, recursively, and
1904 by taking expanded/collapsed status into account.
1c4293cb 1905
939d9364
JS
1906 iMax is used when finding property y-positions.
1907 */
1908 int GetChildrenHeight( int lh, int iMax = -1 ) const;
1c4293cb 1909
939d9364 1910 /** Returns number of child properties */
f7a094e1 1911 unsigned int GetChildCount() const { return m_children.size(); }
1c4293cb 1912
939d9364
JS
1913 /** Returns sub-property at index i. */
1914 wxPGProperty* Item( size_t i ) const
f7a094e1 1915 { return m_children[i]; }
1c4293cb 1916
939d9364
JS
1917 /** Returns last sub-property.
1918 */
f7a094e1 1919 wxPGProperty* Last() const { return m_children.back(); }
1c4293cb 1920
f7a094e1
JS
1921 /** Returns index of given child property. */
1922 int Index( const wxPGProperty* p ) const;
1c4293cb 1923
939d9364
JS
1924 /** Deletes all sub-properties. */
1925 void Empty();
1c4293cb 1926
939d9364
JS
1927 // Puts correct indexes to children
1928 void FixIndexesOfChildren( size_t starthere = 0 );
1c4293cb 1929
939d9364
JS
1930#ifndef SWIG
1931 // Returns wxPropertyGridPageState in which this property resides.
1932 wxPropertyGridPageState* GetParentState() const { return m_parentState; }
1933#endif
1c4293cb 1934
939d9364
JS
1935 wxPGProperty* GetItemAtY( unsigned int y,
1936 unsigned int lh,
1937 unsigned int* nextItemY ) const;
1c4293cb 1938
939d9364
JS
1939 /** Returns (direct) child property with given name (or NULL if not found).
1940 */
1941 wxPGProperty* GetPropertyByName( const wxString& name ) const;
1c4293cb 1942
939d9364
JS
1943#ifdef SWIG
1944 %extend {
1945 DocStr(GetClientData,
1946 "Returns the client data object for a property", "");
1947 PyObject* GetClientData() {
1948 wxPyClientData* data = (wxPyClientData*)self->GetClientObject();
1949 if (data) {
1950 Py_INCREF(data->m_obj);
1951 return data->m_obj;
1952 } else {
1953 Py_INCREF(Py_None);
1954 return Py_None;
1955 }
1c4293cb 1956 }
1c4293cb 1957
939d9364
JS
1958 DocStr(SetClientData,
1959 "Associate the given client data.", "");
1960 void SetClientData(PyObject* clientData) {
1961 wxPyClientData* data = new wxPyClientData(clientData);
1962 self->SetClientObject(data);
1963 }
1c4293cb 1964 }
939d9364
JS
1965 %pythoncode {
1966 GetClientObject = GetClientData
1967 SetClientObject = SetClientData
1c4293cb 1968 }
939d9364 1969#endif
1c4293cb 1970
939d9364 1971#ifndef SWIG
1c4293cb 1972
939d9364 1973 static wxString* sm_wxPG_LABEL;
1c4293cb 1974
939d9364
JS
1975 /** This member is public so scripting language bindings
1976 wrapper code can access it freely.
1977 */
1978 void* m_clientData;
1c4293cb 1979
939d9364
JS
1980protected:
1981 /** Returns text for given column.
1c4293cb 1982 */
939d9364 1983 wxString GetColumnText( unsigned int col ) const;
1c4293cb 1984
939d9364
JS
1985 /** Returns (direct) child property with given name (or NULL if not found),
1986 with hint index.
1c4293cb 1987
939d9364
JS
1988 @param hintIndex
1989 Start looking for the child at this index.
1c4293cb 1990
939d9364
JS
1991 @remarks
1992 Does not support scope (ie. Parent.Child notation).
1993 */
1994 wxPGProperty* GetPropertyByNameWH( const wxString& name,
1995 unsigned int hintIndex ) const;
1c4293cb 1996
939d9364
JS
1997 /** This is used by Insert etc. */
1998 void AddChild2( wxPGProperty* prop,
1999 int index = -1,
2000 bool correct_mode = true );
1c4293cb 2001
939d9364
JS
2002 void DoSetName(const wxString& str) { m_name = str; }
2003
2004 // Call for after sub-properties added with AddChild
2005 void PrepareSubProperties();
2006
d8c74d04
JS
2007 // Removes child property with given pointer. Does not delete it.
2008 void RemoveChild( wxPGProperty* p );
2009
939d9364 2010 void SetParentalType( int flag )
1c4293cb 2011 {
939d9364
JS
2012 m_flags &= ~(wxPG_PROP_PROPERTY|wxPG_PROP_PARENTAL_FLAGS);
2013 m_flags |= flag;
1c4293cb
VZ
2014 }
2015
939d9364
JS
2016 void SetParentState( wxPropertyGridPageState* pstate )
2017 { m_parentState = pstate; }
2018
2019 // Call after fixed sub-properties added/removed after creation.
2020 // if oldSelInd >= 0 and < new max items, then selection is
2021 // moved to it.
2022 void SubPropsChanged( int oldSelInd = -1 );
1c4293cb 2023
939d9364 2024 int GetY2( int lh ) const;
1c4293cb 2025
939d9364
JS
2026 wxString m_label;
2027 wxString m_name;
2028 wxPGProperty* m_parent;
2029 wxPropertyGridPageState* m_parentState;
1c4293cb 2030
939d9364 2031 wxClientData* m_clientObject;
1c4293cb 2032
939d9364
JS
2033 // Overrides editor returned by property class
2034 const wxPGEditor* m_customEditor;
2035#if wxUSE_VALIDATORS
2036 // Editor is going to get this validator
2037 wxValidator* m_validator;
2038#endif
2039 // Show this in front of the value
2040 //
2041 // TODO: Can bitmap be implemented with wxPGCell?
2042 wxBitmap* m_valueBitmap;
1c4293cb 2043
939d9364
JS
2044 wxVariant m_value;
2045 wxPGAttributeStorage m_attributes;
f7a094e1 2046 wxArrayPGProperty m_children;
1c4293cb 2047
939d9364
JS
2048 // Extended cell information
2049 wxArrayPtrVoid m_cells;
1c4293cb 2050
939d9364
JS
2051 // Choices shown in drop-down list of editor control.
2052 wxPGChoices m_choices;
1c4293cb 2053
939d9364
JS
2054 // Help shown in statusbar or help box.
2055 wxString m_helpString;
1c4293cb 2056
939d9364
JS
2057 // Index in parent's property array.
2058 unsigned int m_arrIndex;
1c4293cb 2059
939d9364
JS
2060 // If not -1, then overrides m_value
2061 int m_commonValue;
1c4293cb 2062
939d9364 2063 FlagType m_flags;
1c4293cb 2064
939d9364
JS
2065 // Maximum length (mainly for string properties). Could be in some sort of
2066 // wxBaseStringProperty, but currently, for maximum flexibility and
2067 // compatibility, we'll stick it here. Anyway, we had 3 excess bytes to use
2068 // so short int will fit in just fine.
2069 short m_maxLen;
1c4293cb 2070
939d9364
JS
2071 // Root has 0, categories etc. at that level 1, etc.
2072 unsigned char m_depth;
1c4293cb 2073
939d9364
JS
2074 // m_depthBgCol indicates width of background colour between margin and item
2075 // (essentially this is category's depth, if none then equals m_depth).
2076 unsigned char m_depthBgCol;
1c4293cb 2077
939d9364
JS
2078 unsigned char m_bgColIndex; // Background brush index.
2079 unsigned char m_fgColIndex; // Foreground colour index.
1c4293cb 2080
939d9364
JS
2081private:
2082 // Called in constructors.
2083 void Init();
2084 void Init( const wxString& label, const wxString& name );
2085#endif // #ifndef SWIG
2086};
1c4293cb 2087
939d9364 2088// -----------------------------------------------------------------------
1c4293cb 2089
939d9364
JS
2090//
2091// Property class declaration helper macros
2092// (wxPGRootPropertyClass and wxPropertyCategory require this).
2093//
1c4293cb 2094
939d9364
JS
2095#define WX_PG_DECLARE_DOGETEDITORCLASS \
2096 virtual const wxPGEditor* DoGetEditorClass() const;
1c4293cb
VZ
2097
2098#ifndef SWIG
939d9364
JS
2099 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
2100 public: \
2101 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
2102 WX_PG_DECLARE_DOGETEDITORCLASS \
2103 private:
2104#else
2105 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME)
2106#endif
1c4293cb 2107
939d9364
JS
2108// Implements sans constructor function. Also, first arg is class name, not
2109// property name.
2110#define WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(PROPNAME,T,EDITOR) \
2111const wxPGEditor* PROPNAME::DoGetEditorClass() const \
2112{ \
2113 return wxPGEditor_##EDITOR; \
2114}
1c4293cb 2115
939d9364 2116// -----------------------------------------------------------------------
1c4293cb 2117
939d9364 2118#ifndef SWIG
1c4293cb 2119
939d9364
JS
2120/** @class wxPGRootProperty
2121 @ingroup classes
2122 Root parent property.
2123*/
2124class WXDLLIMPEXP_PROPGRID wxPGRootProperty : public wxPGProperty
2125{
2126public:
2127 WX_PG_DECLARE_PROPERTY_CLASS(wxPGRootProperty)
2128public:
1c4293cb 2129
939d9364
JS
2130 /** Constructor. */
2131 wxPGRootProperty();
2132 virtual ~wxPGRootProperty();
1c4293cb 2133
939d9364 2134 virtual bool StringToValue( wxVariant&, const wxString&, int ) const
1c4293cb 2135 {
939d9364 2136 return false;
1c4293cb
VZ
2137 }
2138
939d9364
JS
2139protected:
2140};
1c4293cb 2141
939d9364 2142// -----------------------------------------------------------------------
1c4293cb 2143
939d9364
JS
2144/** @class wxPropertyCategory
2145 @ingroup classes
2146 Category (caption) property.
2147*/
2148class WXDLLIMPEXP_PROPGRID wxPropertyCategory : public wxPGProperty
2149{
2150 friend class wxPropertyGrid;
2151 friend class wxPropertyGridPageState;
2152 WX_PG_DECLARE_PROPERTY_CLASS(wxPropertyCategory)
2153public:
1c4293cb 2154
939d9364
JS
2155 /** Default constructor is only used in special cases. */
2156 wxPropertyCategory();
2157
2158 wxPropertyCategory( const wxString& label,
2159 const wxString& name = wxPG_LABEL );
2160 ~wxPropertyCategory();
2161
2162 int GetTextExtent( const wxWindow* wnd, const wxFont& font ) const;
1c4293cb
VZ
2163
2164protected:
939d9364 2165 virtual wxString GetValueAsString( int argFlags ) const;
1c4293cb 2166
939d9364
JS
2167 void SetTextColIndex( unsigned int colInd )
2168 { m_capFgColIndex = (wxByte) colInd; }
2169 unsigned int GetTextColIndex() const
2170 { return (unsigned int) m_capFgColIndex; }
2171
2172 void CalculateTextExtent( wxWindow* wnd, const wxFont& font );
2173
2174 int m_textExtent; // pre-calculated length of text
2175 wxByte m_capFgColIndex; // caption text colour index
2176
2177private:
1c4293cb 2178 void Init();
1c4293cb
VZ
2179};
2180
939d9364 2181#endif // !SWIG
1c4293cb
VZ
2182
2183// -----------------------------------------------------------------------
2184
f4bc1aa2
JS
2185#endif // wxUSE_PROPGRID
2186
1c4293cb 2187#endif // _WX_PROPGRID_PROPERTY_H_