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