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