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