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