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