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