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