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