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