]> git.saurik.com Git - wxWidgets.git/blob - include/wx/propgrid/property.h
c319c2e164a349c8cfe71661731e05369cdd29c9
[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 wxPropertyGridInterfaces::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 /** First attribute id that is guaranteed not to be used built-in
554 properties.
555 */
556 //#define wxPG_USER_ATTRIBUTE 192
557
558 /** @}
559 */
560
561 #ifndef DOXYGEN
562
563 // Redefine attribute macros to use cached strings
564 #undef wxPG_ATTR_MIN
565 #define wxPG_ATTR_MIN wxPGGlobalVars->m_strMin
566 #undef wxPG_ATTR_MAX
567 #define wxPG_ATTR_MAX wxPGGlobalVars->m_strMax
568 #undef wxPG_ATTR_UNITS
569 #define wxPG_ATTR_UNITS wxPGGlobalVars->m_strUnits
570 #undef wxPG_ATTR_INLINE_HELP
571 #define wxPG_ATTR_INLINE_HELP wxPGGlobalVars->m_strInlineHelp
572
573 #endif // !DOXYGEN
574
575 #endif // !SWIG
576
577 // -----------------------------------------------------------------------
578
579 /** @class wxPGProperty
580
581 wxPGProperty is base class for all wxPropertyGrid properties. In
582 sections below we cover few related topics.
583
584 @li @ref pgproperty_properties
585 @li @ref pgproperty_creating
586
587 @section pgproperty_properties Supplied Ready-to-use Property Classes
588
589 Here is a list and short description of supplied fully-functional
590 property classes. They are located in either props.h or advprops.h.
591
592 @li @ref wxArrayStringProperty
593 @li @ref wxBoolProperty
594 @li @ref wxColourProperty
595 @li @ref wxCursorProperty
596 @li @ref wxDateProperty
597 @li @ref wxDirProperty
598 @li @ref wxEditEnumProperty
599 @li @ref wxEnumProperty
600 @li @ref wxFileProperty
601 @li @ref wxFlagsProperty
602 @li @ref wxFloatProperty
603 @li @ref wxFontProperty
604 @li @ref wxImageFileProperty
605 @li @ref wxIntProperty
606 @li @ref wxLongStringProperty
607 @li @ref wxMultiChoiceProperty
608 @li @ref wxPropertyCategory
609 @li @ref wxStringProperty
610 @li @ref wxSystemColourProperty
611 @li @ref wxUIntProperty
612
613 @subsection wxPropertyCategory
614
615 Not an actual property per se, but a header for a group of properties.
616 Regardless inherits from wxPGProperty.
617
618 @subsection wxStringProperty
619
620 Simple string property. wxPG_STRING_PASSWORD attribute may be used
621 to echo value as asterisks and use wxTE_PASSWORD for wxTextCtrl.
622
623 @remarks
624 * wxStringProperty has a special trait: if it has value of "<composed>",
625 and also has child properties, then its displayed value becomes
626 composition of child property values, similar as with wxFontProperty,
627 for instance.
628
629 @subsection wxIntProperty
630
631 Like wxStringProperty, but converts text to a signed long integer.
632 wxIntProperty seamlessly supports 64-bit integers (ie. wxLongLong).
633
634 @subsection wxUIntProperty
635
636 Like wxIntProperty, but displays value as unsigned int. To set
637 the prefix used globally, manipulate wxPG_UINT_PREFIX string attribute.
638 To set the globally used base, manipulate wxPG_UINT_BASE int
639 attribute. Regardless of current prefix, understands (hex) values starting
640 with both "0x" and "$".
641 wxUIntProperty seamlessly supports 64-bit unsigned integers (ie.
642 wxULongLong).
643
644 @subsection wxFloatProperty
645
646 Like wxStringProperty, but converts text to a double-precision floating
647 point. Default float-to-text precision is 6 decimals, but this can be
648 changed by modifying wxPG_FLOAT_PRECISION attribute.
649
650 @subsection wxBoolProperty
651
652 Represents a boolean value. wxChoice is used as editor control, by the
653 default. wxPG_BOOL_USE_CHECKBOX attribute can be set to true inorder to use
654 check box instead.
655
656 @subsection wxLongStringProperty
657
658 Like wxStringProperty, but has a button that triggers a small text editor
659 dialog. Note that in long string values, tabs are represented by "\t" and
660 line break by "\n".
661
662 @subsection wxDirProperty
663
664 Like wxLongStringProperty, but the button triggers dir selector instead.
665 Supported properties (all with string value): wxPG_DIR_DIALOG_MESSAGE.
666
667 @subsection wxFileProperty
668
669 Like wxLongStringProperty, but the button triggers file selector instead.
670 Default wildcard is "All files..." but this can be changed by setting
671 wxPG_FILE_WILDCARD attribute (see wxFileDialog for format details).
672 Attribute wxPG_FILE_SHOW_FULL_PATH can be set to false inorder to show
673 only the filename, not the entire path.
674
675 @subsection wxEnumProperty
676
677 Represents a single selection from a list of choices -
678 wxOwnerDrawnComboBox is used to edit the value.
679
680 @subsection wxFlagsProperty
681
682 Represents a bit set that fits in a long integer. wxBoolProperty
683 sub-properties are created for editing individual bits. Textctrl is created
684 to manually edit the flags as a text; a continous sequence of spaces,
685 commas and semicolons is considered as a flag id separator.
686 <b>Note: </b> When changing "choices" (ie. flag labels) of wxFlagsProperty,
687 you will need to use SetPropertyChoices - otherwise they will not get
688 updated properly.
689
690 @subsection wxArrayStringProperty
691
692 Allows editing of a list of strings in wxTextCtrl and in a separate dialog.
693
694 @subsection wxDateProperty
695
696 wxDateTime property. Default editor is DatePickerCtrl, altough TextCtrl
697 should work as well. wxPG_DATE_FORMAT attribute can be used to change
698 string wxDateTime::Format uses (altough default is recommended as it is
699 locale-dependant), and wxPG_DATE_PICKER_STYLE allows changing window
700 style given to DatePickerCtrl (default is wxDP_DEFAULT|wxDP_SHOWCENTURY).
701
702 @subsection wxEditEnumProperty
703
704 Represents a string that can be freely edited or selected from list of
705 choices - custom combobox control is used to edit the value.
706
707 @subsection wxMultiChoiceProperty
708
709 Allows editing a multiple selection from a list of strings. This is
710 property is pretty much built around concept of wxMultiChoiceDialog.
711 It uses wxArrayString value.
712
713 @subsection wxImageFileProperty
714
715 Like wxFileProperty, but has thumbnail of the image in front of
716 the filename and autogenerates wildcard from available image handlers.
717
718 @subsection wxColourProperty
719
720 <b>Useful alternate editor:</b> Choice.
721
722 Represents wxColour. wxButton is used to trigger a colour picker dialog.
723
724 @subsection wxFontProperty
725
726 Represents wxFont. Various sub-properties are used to edit individual
727 subvalues.
728
729 @subsection wxSystemColourProperty
730
731 Represents wxColour and a system colour index. wxChoice is used to edit
732 the value. Drop-down list has color images. Note that value type
733 is wxColourPropertyValue instead of wxColour.
734 @code
735 class wxColourPropertyValue : public wxObject
736 {
737 public:
738 // An integer value relating to the colour, and which exact
739 // meaning depends on the property with which it is used.
740 //
741 // For wxSystemColourProperty:
742 // Any of wxSYS_COLOUR_XXX, or any web-colour (use
743 // wxPG_TO_WEB_COLOUR macro - (currently unsupported) ),
744 // or wxPG_COLOUR_CUSTOM.
745 wxUint32 m_type;
746
747 // Resulting colour. Should be correct regardless of type.
748 wxColour m_colour;
749 };
750 @endcode
751
752 @subsection wxCursorProperty
753
754 Represents a wxCursor. wxChoice is used to edit the value.
755 Drop-down list has cursor images under some (wxMSW) platforms.
756
757
758 @section pgproperty_creating Creating Custom Properties
759
760 New properties can be created by subclassing wxPGProperty or one
761 of the provided property classes, and (re)implementing necessary
762 member functions. Below, each virtual member function has ample
763 documentation about its purpose and any odd details which to keep
764 in mind.
765
766 Here is a very simple 'template' code:
767
768 @code
769 class MyProperty : public wxPGProperty
770 {
771 public:
772 // All arguments of ctor must have a default value -
773 // use wxPG_LABEL for label and name
774 MyProperty( const wxString& label = wxPG_LABEL,
775 const wxString& name = wxPG_LABEL,
776 const wxString& value = wxEmptyString )
777 {
778 // m_value is wxVariant
779 m_value = value;
780 }
781
782 virtual ~MyProperty() { }
783
784 const wxPGEditor* DoGetEditorClass() const
785 {
786 // Determines editor used by property.
787 // You can replace 'TextCtrl' below with any of these
788 // builtin-in property editor identifiers: Choice, ComboBox,
789 // TextCtrlAndButton, ChoiceAndButton, CheckBox, SpinCtrl,
790 // DatePickerCtrl.
791 return wxPGEditor_TextCtrl;
792 }
793
794 virtual wxString GetValueAsString( int argFlags ) const
795 {
796 // TODO: Return property value in string format
797 }
798
799 virtual bool StringToValue( wxVariant& variant,
800 const wxString& text,
801 int argFlags )
802 {
803 // TODO: Adapt string to property value.
804 }
805
806 protected:
807 };
808 @endcode
809
810 Since wxPGProperty derives from wxObject, you can use standard
811 DECLARE_DYNAMIC_CLASS and IMPLEMENT_DYNAMIC_CLASS macros. From the
812 above example they were omitted for sake of simplicity, and besides,
813 they are only really needed if you need to use wxRTTI with your
814 property class.
815
816 You can change the 'value type' of a property by simply assigning different
817 type of variant with SetValue. <b>It is mandatory to implement
818 wxVariantData class for all data types used as property values.</b>
819 You can use macros declared in wxPropertyGrid headers. For instance:
820
821 @code
822 // In header file:
823 // (If you need to have export declaration, use version of macros
824 // with _EXPORTED postfix)
825 WX_PG_DECLARE_VARIANT_DATA(MyDataClass)
826
827 // In sources file:
828 WX_PG_IMPLEMENT_VARIANT_DATA(MyDataClass)
829
830 // Or, if you don't have valid == operator:
831 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(MyDataClass)
832 @endcode
833
834 @library{wxpropgrid}
835 @category{propgrid}
836 */
837 class WXDLLIMPEXP_PROPGRID wxPGProperty : public wxObject
838 {
839 friend class wxPropertyGrid;
840 friend class wxPropertyGridInterface;
841 friend class wxPropertyGridPageState;
842 friend class wxPropertyGridPopulator;
843 friend class wxStringProperty; // Proper "<composed>" support requires this
844 #ifndef SWIG
845 DECLARE_ABSTRACT_CLASS(wxPGProperty)
846 #endif
847 public:
848 typedef wxUint32 FlagType;
849
850 /** Basic constructor.
851 */
852 wxPGProperty();
853
854 /** Constructor.
855 Non-abstract property classes should have constructor of this style:
856
857 @code
858
859 // If T is a class, then it should be a constant reference
860 // (e.g. const T& ) instead.
861 MyProperty( const wxString& label, const wxString& name, T value )
862 : wxPGProperty()
863 {
864 // Generally recommended way to set the initial value
865 // (as it should work in pretty much 100% of cases).
866 wxVariant variant;
867 variant << value;
868 SetValue(variant);
869
870 // If has private child properties then create them here, e.g.:
871 // AddChild( new wxStringProperty( "Subprop 1",
872 // wxPG_LABEL,
873 // value.GetSubProp1() ) );
874 }
875
876 @endcode
877 */
878 wxPGProperty( const wxString& label, const wxString& name );
879
880 /**
881 Virtual destructor.
882 It is customary for derived properties to implement this.
883 */
884 virtual ~wxPGProperty();
885
886 /** This virtual function is called after m_value has been set.
887
888 @remarks
889 - If m_value was set to Null variant (ie. unspecified value),
890 OnSetValue() will not be called.
891 - m_value may be of any variant type. Typically properties internally
892 support only one variant type, and as such OnSetValue() provides a
893 good opportunity to convert
894 supported values into internal type.
895 - Default implementation does nothing.
896 */
897 virtual void OnSetValue();
898
899 /** Override this to return something else than m_value as the value.
900 */
901 virtual wxVariant DoGetValue() const { return m_value; }
902
903 #if !defined(SWIG) || defined(CREATE_VCW)
904 /** Implement this function in derived class to check the value.
905 Return true if it is ok. Returning false prevents property change events
906 from occurring.
907
908 @remarks
909 - Default implementation always returns true.
910 */
911 virtual bool ValidateValue( wxVariant& value,
912 wxPGValidationInfo& validationInfo ) const;
913
914 /**
915 Converts 'text' into proper value 'variant'.
916 Returns true if new (different than m_value) value could be interpreted
917 from the text.
918 @param argFlags
919 If wxPG_FULL_VALUE is set, returns complete, storable value instead
920 of displayable one (they may be different).
921 If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of
922 composite property string value (as generated by GetValueAsString()
923 called with this same flag).
924
925 @remarks
926 Default implementation converts semicolon delimited tokens into child
927 values. Only works for properties with children.
928 */
929 virtual bool StringToValue( wxVariant& variant,
930 const wxString& text,
931 int argFlags = 0 ) const;
932
933 /**
934 Converts 'number' (including choice selection) into proper value
935 'variant'.
936
937 Returns true if new (different than m_value) value could be interpreted
938 from the integer.
939
940 @param argFlags
941 If wxPG_FULL_VALUE is set, returns complete, storable value instead
942 of displayable one.
943
944 @remarks
945 - If property is not supposed to use choice or spinctrl or other editor
946 with int-based value, it is not necessary to implement this method.
947 - Default implementation simply assign given int to m_value.
948 - If property uses choice control, and displays a dialog on some choice
949 items, then it is preferred to display that dialog in IntToValue
950 instead of OnEvent.
951 */
952 virtual bool IntToValue( wxVariant& value,
953 int number,
954 int argFlags = 0 ) const;
955 #endif // !defined(SWIG) || defined(CREATE_VCW)
956
957 public:
958 /** Returns text representation of property's value.
959
960 @param argFlags
961 If wxPG_FULL_VALUE is set, returns complete, storable string value
962 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
963 string value that must be editable in textctrl. If
964 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
965 display as a part of composite property string value.
966
967 @remarks
968 Default implementation returns string composed from text
969 representations of child properties.
970 */
971 virtual wxString GetValueAsString( int argFlags = 0 ) const;
972
973 /** Converts string to a value, and if successful, calls SetValue() on it.
974 Default behavior is to do nothing.
975 @param text
976 String to get the value from.
977 @return
978 true if value was changed.
979 */
980 bool SetValueFromString( const wxString& text, int flags = 0 );
981
982 /** Converts integer to a value, and if succesful, calls SetValue() on it.
983 Default behavior is to do nothing.
984 @param value
985 Int to get the value from.
986 @param flags
987 If has wxPG_FULL_VALUE, then the value given is a actual value and
988 not an index.
989 @return
990 True if value was changed.
991 */
992 bool SetValueFromInt( long value, int flags = 0 );
993
994 /**
995 Returns size of the custom painted image in front of property.
996
997 This method must be overridden to return non-default value if
998 OnCustomPaint is to be called.
999 @param item
1000 Normally -1, but can be an index to the property's list of items.
1001 @remarks
1002 - Default behavior is to return wxSize(0,0), which means no image.
1003 - Default image width or height is indicated with dimension -1.
1004 - You can also return wxPG_DEFAULT_IMAGE_SIZE, i.e. wxSize(-1, -1).
1005 */
1006 virtual wxSize OnMeasureImage( int item = -1 ) const;
1007
1008 /**
1009 Events received by editor widgets are processed here.
1010
1011 Note that editor class usually processes most events. Some, such as
1012 button press events of TextCtrlAndButton class, can be handled here.
1013 Also, if custom handling for regular events is desired, then that can
1014 also be done (for example, wxSystemColourProperty custom handles
1015 wxEVT_COMMAND_CHOICE_SELECTED to display colour picker dialog when
1016 'custom' selection is made).
1017
1018 If the event causes value to be changed, SetValueInEvent()
1019 should be called to set the new value.
1020
1021 @param event
1022 Associated wxEvent.
1023 @return
1024 Should return true if any changes in value should be reported.
1025 @remarks
1026 If property uses choice control, and displays a dialog on some choice
1027 items, then it is preferred to display that dialog in IntToValue
1028 instead of OnEvent.
1029 */
1030 virtual bool OnEvent( wxPropertyGrid* propgrid,
1031 wxWindow* wnd_primary,
1032 wxEvent& event );
1033
1034 /**
1035 Called after value of a child property has been altered.
1036
1037 Note that this function is usually called at the time that value of
1038 this property, or given child property, is still pending for change.
1039
1040 Sample pseudo-code implementation:
1041
1042 @code
1043 void MyProperty::ChildChanged( wxVariant& thisValue,
1044 int childIndex,
1045 wxVariant& childValue ) const
1046 {
1047 // Acquire reference to actual type of data stored in variant
1048 // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros
1049 // were used to create the variant class).
1050 T& data = TFromVariant(thisValue);
1051
1052 // Copy childValue into data.
1053 switch ( childIndex )
1054 {
1055 case 0:
1056 data.SetSubProp1( childvalue.GetLong() );
1057 break;
1058 case 1:
1059 data.SetSubProp2( childvalue.GetString() );
1060 break;
1061 ...
1062 }
1063 }
1064 @endcode
1065
1066 @param thisValue
1067 Value of this property, that should be altered.
1068 @param childIndex
1069 Index of child changed (you can use Item(childIndex) to get).
1070 @param childValue
1071 Value of the child property.
1072 */
1073 virtual void ChildChanged( wxVariant& thisValue,
1074 int childIndex,
1075 wxVariant& childValue ) const;
1076
1077 /** Returns pointer to an instance of used editor.
1078 */
1079 virtual const wxPGEditor* DoGetEditorClass() const;
1080
1081 /** Returns pointer to the wxValidator that should be used
1082 with the editor of this property (NULL for no validator).
1083 Setting validator explicitly via SetPropertyValidator
1084 will override this.
1085
1086 In most situations, code like this should work well
1087 (macros are used to maintain one actual validator instance,
1088 so on the second call the function exits within the first
1089 macro):
1090
1091 @code
1092
1093 wxValidator* wxMyPropertyClass::DoGetValidator () const
1094 {
1095 WX_PG_DOGETVALIDATOR_ENTRY()
1096
1097 wxMyValidator* validator = new wxMyValidator(...);
1098
1099 ... prepare validator...
1100
1101 WX_PG_DOGETVALIDATOR_EXIT(validator)
1102 }
1103
1104 @endcode
1105
1106 @remarks
1107 You can get common filename validator by returning
1108 wxFileProperty::GetClassValidator(). wxDirProperty,
1109 for example, uses it.
1110 */
1111 virtual wxValidator* DoGetValidator () const;
1112
1113 /**
1114 Returns current value's index to the choice control.
1115
1116 May also return, through pointer arguments, strings that should be
1117 inserted to that control. Irrelevant to classes which do not employ
1118 wxPGEditor_Choice or similar.
1119
1120 @remarks
1121 - If returns NULL in choiceinfo.m_choices, then this class must be
1122 derived from wxBaseEnumProperty.
1123 - Must be able to cope situation where property's set of choices is
1124 uninitialized.
1125 */
1126 virtual int GetChoiceInfo( wxPGChoiceInfo* choiceinfo );
1127
1128 /**
1129 Override to paint an image in front of the property value text or
1130 drop-down list item (but only if wxPGProperty::OnMeasureImage is
1131 overridden as well).
1132
1133 If property's OnMeasureImage() returns size that has height != 0 but
1134 less than row height ( < 0 has special meanings), wxPropertyGrid calls
1135 this method to draw a custom image in a limited area in front of the
1136 editor control or value text/graphics, and if control has drop-down
1137 list, then the image is drawn there as well (even in the case
1138 OnMeasureImage() returned higher height than row height).
1139
1140 NOTE: Following applies when OnMeasureImage() returns a "flexible"
1141 height ( using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable
1142 height items: If rect.x is < 0, then this is a measure item call, which
1143 means that dc is invalid and only thing that should be done is to set
1144 paintdata.m_drawnHeight to the height of the image of item at index
1145 paintdata.m_choiceItem. This call may be done even as often as once
1146 every drop-down popup show.
1147
1148 @param dc
1149 wxDC to paint on.
1150 @param rect
1151 Box reserved for custom graphics. Includes surrounding rectangle,
1152 if any. If x is < 0, then this is a measure item call (see above).
1153 @param paintdata
1154 wxPGPaintData structure with much useful data.
1155
1156 @remarks
1157 - You can actually exceed rect width, but if you do so then
1158 paintdata.m_drawnWidth must be set to the full width drawn in
1159 pixels.
1160 - Due to technical reasons, rect's height will be default even if
1161 custom height was reported during measure call.
1162 - Brush is guaranteed to be default background colour. It has been
1163 already used to clear the background of area being painted. It
1164 can be modified.
1165 - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper
1166 colour) pen for drawing framing rectangle. It can be changed as
1167 well.
1168
1169 @see GetValueAsString()
1170 */
1171 virtual void OnCustomPaint( wxDC& dc,
1172 const wxRect& rect,
1173 wxPGPaintData& paintdata );
1174
1175 /**
1176 Returns used wxPGCellRenderer instance for given property column
1177 (label=0, value=1).
1178
1179 Default implementation returns editor's renderer for all columns.
1180 */
1181 virtual wxPGCellRenderer* GetCellRenderer( int column ) const;
1182
1183 /**
1184 Refresh values of child properties.
1185
1186 Automatically called after value is set.
1187 */
1188 virtual void RefreshChildren();
1189
1190 /** Special handling for attributes of this property.
1191
1192 If returns false, then the attribute will be automatically stored in
1193 m_attributes.
1194
1195 Default implementation simply returns false.
1196 */
1197 virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
1198
1199 /** Returns value of an attribute.
1200
1201 Override if custom handling of attributes is needed.
1202
1203 Default implementation simply return NULL variant.
1204 */
1205 virtual wxVariant DoGetAttribute( const wxString& name ) const;
1206
1207 /** Returns instance of a new wxPGEditorDialogAdapter instance, which is
1208 used when user presses the (optional) button next to the editor control;
1209
1210 Default implementation returns NULL (ie. no action is generated when
1211 button is pressed).
1212 */
1213 virtual wxPGEditorDialogAdapter* GetEditorDialog() const;
1214
1215 /**
1216 Adds entry to property's wxPGChoices and editor control (if it is
1217 active).
1218
1219 Returns index of item added.
1220 */
1221 int AppendChoice( const wxString& label, int value = wxPG_INVALID_VALUE )
1222 {
1223 return InsertChoice(label,-1,value);
1224 }
1225
1226 /** Returns wxPGCell of given column, NULL if none. If valid
1227 object is returned, caller will gain its ownership.
1228 */
1229 wxPGCell* AcquireCell( unsigned int column )
1230 {
1231 if ( column >= m_cells.size() )
1232 return NULL;
1233
1234 wxPGCell* cell = (wxPGCell*) m_cells[column];
1235 m_cells[column] = NULL;
1236 return cell;
1237 }
1238
1239 /**
1240 Returns true if children of this property are component values (for
1241 instance, points size, face name, and is_underlined are component
1242 values of a font).
1243 */
1244 bool AreChildrenComponents() const
1245 {
1246 if ( m_flags & (wxPG_PROP_COMPOSED_VALUE|wxPG_PROP_AGGREGATE) )
1247 return true;
1248
1249 return false;
1250 }
1251
1252 /**
1253 Removes entry from property's wxPGChoices and editor control (if it is
1254 active).
1255
1256 If selected item is deleted, then the value is set to unspecified.
1257 */
1258 void DeleteChoice( int index );
1259
1260 /**
1261 Call to enable or disable usage of common value (integer value that can
1262 be selected for properties instead of their normal values) for this
1263 property.
1264
1265 Common values are disabled by the default for all properties.
1266 */
1267 void EnableCommonValue( bool enable = true )
1268 {
1269 if ( enable ) SetFlag( wxPG_PROP_USES_COMMON_VALUE );
1270 else ClearFlag( wxPG_PROP_USES_COMMON_VALUE );
1271 }
1272
1273 /** Composes text from values of child properties. */
1274 void GenerateComposedValue( wxString& text, int argFlags = 0 ) const;
1275
1276 /** Returns property's label. */
1277 const wxString& GetLabel() const { return m_label; }
1278
1279 /** Returns property's name with all (non-category, non-root) parents. */
1280 wxString GetName() const;
1281
1282 /**
1283 Returns property's base name (ie parent's name is not added in any
1284 case)
1285 */
1286 const wxString& GetBaseName() const { return m_name; }
1287
1288 wxPGChoices& GetChoices();
1289
1290 const wxPGChoices& GetChoices() const;
1291
1292 const wxPGChoiceEntry* GetCurrentChoice() const;
1293
1294 /** Returns coordinate to the top y of the property. Note that the
1295 position of scrollbars is not taken into account.
1296 */
1297 int GetY() const;
1298
1299 wxVariant GetValue() const
1300 {
1301 return DoGetValue();
1302 }
1303
1304 #ifndef SWIG
1305 /** Returns reference to the internal stored value. GetValue is preferred
1306 way to get the actual value, since GetValueRef ignores DoGetValue,
1307 which may override stored value.
1308 */
1309 wxVariant& GetValueRef()
1310 {
1311 return m_value;
1312 }
1313
1314 const wxVariant& GetValueRef() const
1315 {
1316 return m_value;
1317 }
1318 #endif
1319
1320 /** Same as GetValueAsString, except takes common value into account.
1321 */
1322 wxString GetValueString( int argFlags = 0 ) const;
1323
1324 void UpdateControl( wxWindow* primary );
1325
1326 /** Returns wxPGCell of given column, NULL if none. wxPGProperty
1327 will retain ownership of the cell object.
1328 */
1329 wxPGCell* GetCell( unsigned int column ) const
1330 {
1331 if ( column >= m_cells.size() )
1332 return NULL;
1333
1334 return (wxPGCell*) m_cells[column];
1335 }
1336
1337 unsigned int GetChoiceCount() const;
1338
1339 wxString GetChoiceString( unsigned int index );
1340
1341 /** Return number of displayed common values for this property.
1342 */
1343 int GetDisplayedCommonValueCount() const;
1344
1345 wxString GetDisplayedString() const
1346 {
1347 return GetValueString(0);
1348 }
1349
1350 /** Returns property grid where property lies. */
1351 wxPropertyGrid* GetGrid() const;
1352
1353 /** Returns owner wxPropertyGrid, but only if one is currently on a page
1354 displaying this property. */
1355 wxPropertyGrid* GetGridIfDisplayed() const;
1356
1357 /** Returns highest level non-category, non-root parent. Useful when you
1358 have nested wxCustomProperties/wxParentProperties.
1359 @remarks
1360 Thus, if immediate parent is root or category, this will return the
1361 property itself.
1362 */
1363 wxPGProperty* GetMainParent() const;
1364
1365 /** Return parent of property */
1366 wxPGProperty* GetParent() const { return m_parent; }
1367
1368 /** Returns true if property has editable wxTextCtrl when selected.
1369
1370 @remarks
1371 Altough disabled properties do not displayed editor, they still
1372 return True here as being disabled is considered a temporary
1373 condition (unlike being read-only or having limited editing enabled).
1374 */
1375 bool IsTextEditable() const;
1376
1377 bool IsValueUnspecified() const
1378 {
1379 return m_value.IsNull();
1380 }
1381
1382 FlagType HasFlag( FlagType flag ) const
1383 {
1384 return ( m_flags & flag );
1385 }
1386
1387 /** Returns comma-delimited string of property attributes.
1388 */
1389 const wxPGAttributeStorage& GetAttributes() const
1390 {
1391 return m_attributes;
1392 }
1393
1394 /** Returns m_attributes as list wxVariant.
1395 */
1396 wxVariant GetAttributesAsList() const;
1397
1398 FlagType GetFlags() const
1399 {
1400 return m_flags;
1401 }
1402
1403 const wxPGEditor* GetEditorClass() const;
1404
1405 wxString GetValueType() const
1406 {
1407 return m_value.GetType();
1408 }
1409
1410 /** Returns editor used for given column. NULL for no editor.
1411 */
1412 const wxPGEditor* GetColumnEditor( int column ) const
1413 {
1414 if ( column == 1 )
1415 return GetEditorClass();
1416
1417 return NULL;
1418 }
1419
1420 /** Returns common value selected for this property. -1 for none.
1421 */
1422 int GetCommonValue() const
1423 {
1424 return m_commonValue;
1425 }
1426
1427 /** Returns true if property has even one visible child.
1428 */
1429 bool HasVisibleChildren() const;
1430
1431 /**
1432 Adds entry to property's wxPGChoices and editor control (if it is
1433 active).
1434
1435 Returns index of item added.
1436 */
1437 int InsertChoice( const wxString& label,
1438 int index,
1439 int value = wxPG_INVALID_VALUE );
1440
1441 /**
1442 Returns true if this property is actually a wxPropertyCategory.
1443 */
1444 bool IsCategory() const { return HasFlag(wxPG_PROP_CATEGORY)?true:false; }
1445
1446 /** Returns true if this property is actually a wxRootProperty.
1447 */
1448 bool IsRoot() const { return (m_parent == NULL); }
1449
1450 /** Returns true if this is a sub-property. */
1451 bool IsSubProperty() const
1452 {
1453 wxPGProperty* parent = (wxPGProperty*)m_parent;
1454 if ( parent && !parent->IsCategory() )
1455 return true;
1456 return false;
1457 }
1458
1459 /** Returns last visible sub-property, recursively.
1460 */
1461 const wxPGProperty* GetLastVisibleSubItem() const;
1462
1463 wxVariant GetDefaultValue() const;
1464
1465 int GetMaxLength() const
1466 {
1467 return (int) m_maxLen;
1468 }
1469
1470 /**
1471 Determines, recursively, if all children are not unspecified.
1472
1473 Takes values in given list into account.
1474 */
1475 bool AreAllChildrenSpecified( wxVariant* pendingList = NULL ) const;
1476
1477 /** Updates composed values of parent non-category properties, recursively.
1478 Returns topmost property updated.
1479
1480 @remarks
1481 - Must not call SetValue() (as can be called in it).
1482 */
1483 wxPGProperty* UpdateParentValues();
1484
1485 /** Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
1486 */
1487 FlagType UsesAutoUnspecified() const
1488 {
1489 return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED);
1490 }
1491
1492 wxBitmap* GetValueImage() const
1493 {
1494 return m_valueBitmap;
1495 }
1496
1497 wxVariant GetAttribute( const wxString& name ) const;
1498
1499 /**
1500 Returns named attribute, as string, if found.
1501
1502 Otherwise defVal is returned.
1503 */
1504 wxString GetAttribute( const wxString& name, const wxString& defVal ) const;
1505
1506 /**
1507 Returns named attribute, as long, if found.
1508
1509 Otherwise defVal is returned.
1510 */
1511 long GetAttributeAsLong( const wxString& name, long defVal ) const;
1512
1513 /**
1514 Returns named attribute, as double, if found.
1515
1516 Otherwise defVal is returned.
1517 */
1518 double GetAttributeAsDouble( const wxString& name, double defVal ) const;
1519
1520 unsigned int GetArrIndex() const { return m_arrIndex; }
1521
1522 unsigned int GetDepth() const { return (unsigned int)m_depth; }
1523
1524 /** Gets flags as a'|' delimited string. Note that flag names are not
1525 prepended with 'wxPG_PROP_'.
1526 @param flagsMask
1527 String will only be made to include flags combined by this parameter.
1528 */
1529 wxString GetFlagsAsString( FlagType flagsMask ) const;
1530
1531 /** Returns position in parent's array. */
1532 unsigned int GetIndexInParent() const
1533 {
1534 return (unsigned int)m_arrIndex;
1535 }
1536
1537 /** Hides or reveals the property.
1538 @param hide
1539 true for hide, false for reveal.
1540 @param flags
1541 By default changes are applied recursively. Set this paramter
1542 wxPG_DONT_RECURSE to prevent this.
1543 */
1544 inline bool Hide( bool hide, int flags = wxPG_RECURSE );
1545
1546 bool IsExpanded() const
1547 { return (!(m_flags & wxPG_PROP_COLLAPSED) && GetChildCount()); }
1548
1549 /** Returns true if all parents expanded.
1550 */
1551 bool IsVisible() const;
1552
1553 bool IsEnabled() const { return !(m_flags & wxPG_PROP_DISABLED); }
1554
1555 /** If property's editor is created this forces its recreation.
1556 Useful in SetAttribute etc. Returns true if actually did anything.
1557 */
1558 bool RecreateEditor();
1559
1560 /** If property's editor is active, then update it's value.
1561 */
1562 void RefreshEditor();
1563
1564 /** Sets an attribute for this property.
1565 @param name
1566 Text identifier of attribute. See @ref propgrid_property_attributes.
1567 @param value
1568 Value of attribute.
1569 */
1570 void SetAttribute( const wxString& name, wxVariant value );
1571
1572 void SetAttributes( const wxPGAttributeStorage& attributes );
1573
1574 #ifndef SWIG
1575 /** Sets editor for a property.
1576
1577 @param editor
1578 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1579 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full
1580 list).
1581
1582 For custom editors, use pointer you received from
1583 wxPropertyGrid::RegisterEditorClass().
1584 */
1585 void SetEditor( const wxPGEditor* editor )
1586 {
1587 m_customEditor = editor;
1588 }
1589 #endif
1590
1591 /** Sets editor for a property.
1592 */
1593 inline void SetEditor( const wxString& editorName );
1594
1595 /** Sets cell information for given column.
1596
1597 Note that the property takes ownership of given wxPGCell instance.
1598 */
1599 void SetCell( int column, wxPGCell* cellObj );
1600
1601 /** Changes value of a property with choices, but only
1602 works if the value type is long or string. */
1603 void SetChoiceSelection( int newValue, const wxPGChoiceInfo& choiceInfo );
1604
1605 /** Sets common value selected for this property. -1 for none.
1606 */
1607 void SetCommonValue( int commonValue )
1608 {
1609 m_commonValue = commonValue;
1610 }
1611
1612 /** Sets flags from a '|' delimited string. Note that flag names are not
1613 prepended with 'wxPG_PROP_'.
1614 */
1615 void SetFlagsFromString( const wxString& str );
1616
1617 /** Sets property's "is it modified?" flag. Affects children recursively.
1618 */
1619 void SetModifiedStatus( bool modified )
1620 {
1621 SetFlagRecursively(wxPG_PROP_MODIFIED, modified);
1622 }
1623
1624 /** Call in OnEvent(), OnButtonClick() etc. to change the property value
1625 based on user input.
1626
1627 @remarks
1628 This method is const since it doesn't actually modify value, but posts
1629 given variant as pending value, stored in wxPropertyGrid.
1630 */
1631 void SetValueInEvent( wxVariant value ) const;
1632
1633 /**
1634 Call this to set value of the property.
1635
1636 Unlike methods in wxPropertyGrid, this does not automatically update
1637 the display.
1638
1639 @remarks
1640 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run
1641 through validation process and send property change event.
1642
1643 If you need to change property value in event, based on user input, use
1644 SetValueInEvent() instead.
1645
1646 @param pList
1647 Pointer to list variant that contains child values. Used to indicate
1648 which children should be marked as modified.
1649 @param flags
1650 Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR).
1651 */
1652 void SetValue( wxVariant value, wxVariant* pList = NULL, int flags = 0 );
1653
1654 /** Set wxBitmap in front of the value. This bitmap may be ignored
1655 by custom cell renderers.
1656 */
1657 void SetValueImage( wxBitmap& bmp );
1658
1659 /** If property has choices and they are not yet exclusive, new such copy
1660 of them will be created.
1661 */
1662 void SetChoicesExclusive();
1663
1664 void SetExpanded( bool expanded )
1665 {
1666 if ( !expanded ) m_flags |= wxPG_PROP_COLLAPSED;
1667 else m_flags &= ~wxPG_PROP_COLLAPSED;
1668 }
1669
1670 void SetFlag( FlagType flag ) { m_flags |= flag; }
1671
1672 void SetFlagRecursively( FlagType flag, bool set );
1673
1674 void SetHelpString( const wxString& helpString )
1675 {
1676 m_helpString = helpString;
1677 }
1678
1679 void SetLabel( const wxString& label ) { m_label = label; }
1680
1681 inline void SetName( const wxString& newName );
1682
1683 void SetValueToUnspecified()
1684 {
1685 wxVariant val; // Create NULL variant
1686 SetValue(val);
1687 }
1688
1689 #if wxUSE_VALIDATORS
1690 /** Sets wxValidator for a property*/
1691 void SetValidator( const wxValidator& validator )
1692 {
1693 m_validator = wxDynamicCast(validator.Clone(),wxValidator);
1694 }
1695
1696 /** Gets assignable version of property's validator. */
1697 wxValidator* GetValidator() const
1698 {
1699 if ( m_validator )
1700 return m_validator;
1701 return DoGetValidator();
1702 }
1703 #endif // #if wxUSE_VALIDATORS
1704
1705 /** Updates property value in case there were last minute
1706 changes. If value was unspecified, it will be set to default.
1707 Use only for properties that have TextCtrl-based editor.
1708 @remarks
1709 If you have code similar to
1710 @code
1711 // Update the value in case of last minute changes
1712 if ( primary && propgrid->IsEditorsValueModified() )
1713 GetEditorClass()->CopyValueFromControl( this, primary );
1714 @endcode
1715 in wxPGProperty::OnEvent wxEVT_COMMAND_BUTTON_CLICKED handler,
1716 then replace it with call to this method.
1717 @return
1718 True if value changed.
1719 */
1720 bool PrepareValueForDialogEditing( wxPropertyGrid* propgrid );
1721
1722 #ifndef SWIG
1723 /** Returns client data (void*) of a property.
1724 */
1725 void* GetClientData() const
1726 {
1727 return m_clientData;
1728 }
1729
1730 /** Sets client data (void*) of a property.
1731 @remarks
1732 This untyped client data has to be deleted manually.
1733 */
1734 void SetClientData( void* clientData )
1735 {
1736 m_clientData = clientData;
1737 }
1738
1739 /** Returns client object of a property.
1740 */
1741 void SetClientObject(wxClientData* clientObject)
1742 {
1743 delete m_clientObject;
1744 m_clientObject = clientObject;
1745 }
1746
1747 /** Sets managed client object of a property.
1748 */
1749 wxClientData *GetClientObject() const { return m_clientObject; }
1750 #endif
1751
1752 /** Sets new set of choices for property.
1753
1754 @remarks
1755 This operation clears the property value.
1756 */
1757 bool SetChoices( wxPGChoices& choices );
1758
1759 /** Sets new set of choices for property.
1760 */
1761 inline bool SetChoices( const wxArrayString& labels,
1762 const wxArrayInt& values = wxArrayInt() );
1763
1764 /** Set max length of text in text editor.
1765 */
1766 inline bool SetMaxLength( int maxLen );
1767
1768 /** Call with 'false' in OnSetValue to cancel value changes after all
1769 (ie. cancel 'true' returned by StringToValue() or IntToValue()).
1770 */
1771 void SetWasModified( bool set = true )
1772 {
1773 if ( set ) m_flags |= wxPG_PROP_WAS_MODIFIED;
1774 else m_flags &= ~wxPG_PROP_WAS_MODIFIED;
1775 }
1776
1777 const wxString& GetHelpString() const
1778 {
1779 return m_helpString;
1780 }
1781
1782 void ClearFlag( FlagType flag ) { m_flags &= ~(flag); }
1783
1784 // Use, for example, to detect if item is inside collapsed section.
1785 bool IsSomeParent( wxPGProperty* candidate_parent ) const;
1786
1787 /**
1788 Adapts list variant into proper value using consecutive
1789 ChildChanged-calls.
1790 */
1791 void AdaptListToValue( wxVariant& list, wxVariant* value ) const;
1792
1793 /** This is used by properties that have fixed sub-properties. */
1794 void AddChild( wxPGProperty* prop );
1795
1796 /** Returns height of children, recursively, and
1797 by taking expanded/collapsed status into account.
1798
1799 iMax is used when finding property y-positions.
1800 */
1801 int GetChildrenHeight( int lh, int iMax = -1 ) const;
1802
1803 /** Returns number of child properties */
1804 unsigned int GetChildCount() const { return m_children.GetCount(); }
1805
1806 /** Returns sub-property at index i. */
1807 wxPGProperty* Item( size_t i ) const
1808 { return (wxPGProperty*)m_children.Item(i); }
1809
1810 /** Returns last sub-property.
1811 */
1812 wxPGProperty* Last() const { return (wxPGProperty*)m_children.Last(); }
1813
1814 /** Returns index of given sub-property. */
1815 int Index( const wxPGProperty* p ) const
1816 { return m_children.Index((wxPGProperty*)p); }
1817
1818 /** Deletes all sub-properties. */
1819 void Empty();
1820
1821 // Puts correct indexes to children
1822 void FixIndexesOfChildren( size_t starthere = 0 );
1823
1824 #ifndef SWIG
1825 // Returns wxPropertyGridPageState in which this property resides.
1826 wxPropertyGridPageState* GetParentState() const { return m_parentState; }
1827 #endif
1828
1829 wxPGProperty* GetItemAtY( unsigned int y,
1830 unsigned int lh,
1831 unsigned int* nextItemY ) const;
1832
1833 /** Returns (direct) child property with given name (or NULL if not found).
1834 */
1835 wxPGProperty* GetPropertyByName( const wxString& name ) const;
1836
1837 #ifdef SWIG
1838 %extend {
1839 DocStr(GetClientData,
1840 "Returns the client data object for a property", "");
1841 PyObject* GetClientData() {
1842 wxPyClientData* data = (wxPyClientData*)self->GetClientObject();
1843 if (data) {
1844 Py_INCREF(data->m_obj);
1845 return data->m_obj;
1846 } else {
1847 Py_INCREF(Py_None);
1848 return Py_None;
1849 }
1850 }
1851
1852 DocStr(SetClientData,
1853 "Associate the given client data.", "");
1854 void SetClientData(PyObject* clientData) {
1855 wxPyClientData* data = new wxPyClientData(clientData);
1856 self->SetClientObject(data);
1857 }
1858 }
1859 %pythoncode {
1860 GetClientObject = GetClientData
1861 SetClientObject = SetClientData
1862 }
1863 #endif
1864
1865 #ifndef SWIG
1866
1867 static wxString* sm_wxPG_LABEL;
1868
1869 /** This member is public so scripting language bindings
1870 wrapper code can access it freely.
1871 */
1872 void* m_clientData;
1873
1874 protected:
1875 /** Returns text for given column.
1876 */
1877 wxString GetColumnText( unsigned int col ) const;
1878
1879 /** Returns (direct) child property with given name (or NULL if not found),
1880 with hint index.
1881
1882 @param hintIndex
1883 Start looking for the child at this index.
1884
1885 @remarks
1886 Does not support scope (ie. Parent.Child notation).
1887 */
1888 wxPGProperty* GetPropertyByNameWH( const wxString& name,
1889 unsigned int hintIndex ) const;
1890
1891 /** This is used by Insert etc. */
1892 void AddChild2( wxPGProperty* prop,
1893 int index = -1,
1894 bool correct_mode = true );
1895
1896 void DoSetName(const wxString& str) { m_name = str; }
1897
1898 // Call for after sub-properties added with AddChild
1899 void PrepareSubProperties();
1900
1901 void SetParentalType( int flag )
1902 {
1903 m_flags &= ~(wxPG_PROP_PROPERTY|wxPG_PROP_PARENTAL_FLAGS);
1904 m_flags |= flag;
1905 }
1906
1907 void SetParentState( wxPropertyGridPageState* pstate )
1908 { m_parentState = pstate; }
1909
1910 // Call after fixed sub-properties added/removed after creation.
1911 // if oldSelInd >= 0 and < new max items, then selection is
1912 // moved to it.
1913 void SubPropsChanged( int oldSelInd = -1 );
1914
1915 int GetY2( int lh ) const;
1916
1917 wxString m_label;
1918 wxString m_name;
1919 wxPGProperty* m_parent;
1920 wxPropertyGridPageState* m_parentState;
1921
1922 wxClientData* m_clientObject;
1923
1924 // Overrides editor returned by property class
1925 const wxPGEditor* m_customEditor;
1926 #if wxUSE_VALIDATORS
1927 // Editor is going to get this validator
1928 wxValidator* m_validator;
1929 #endif
1930 // Show this in front of the value
1931 //
1932 // TODO: Can bitmap be implemented with wxPGCell?
1933 wxBitmap* m_valueBitmap;
1934
1935 wxVariant m_value;
1936 wxPGAttributeStorage m_attributes;
1937 wxArrayPtrVoid m_children;
1938
1939 // Extended cell information
1940 wxArrayPtrVoid m_cells;
1941
1942 // Help shown in statusbar or help box.
1943 wxString m_helpString;
1944
1945 // Index in parent's property array.
1946 unsigned int m_arrIndex;
1947
1948 // If not -1, then overrides m_value
1949 int m_commonValue;
1950
1951 FlagType m_flags;
1952
1953 // Maximum length (mainly for string properties). Could be in some sort of
1954 // wxBaseStringProperty, but currently, for maximum flexibility and
1955 // compatibility, we'll stick it here. Anyway, we had 3 excess bytes to use
1956 // so short int will fit in just fine.
1957 short m_maxLen;
1958
1959 // Root has 0, categories etc. at that level 1, etc.
1960 unsigned char m_depth;
1961
1962 // m_depthBgCol indicates width of background colour between margin and item
1963 // (essentially this is category's depth, if none then equals m_depth).
1964 unsigned char m_depthBgCol;
1965
1966 unsigned char m_bgColIndex; // Background brush index.
1967 unsigned char m_fgColIndex; // Foreground colour index.
1968
1969 private:
1970 // Called in constructors.
1971 void Init();
1972 void Init( const wxString& label, const wxString& name );
1973 #endif // #ifndef SWIG
1974 };
1975
1976 // -----------------------------------------------------------------------
1977
1978 //
1979 // Property class declaration helper macros
1980 // (wxPGRootPropertyClass and wxPropertyCategory require this).
1981 //
1982
1983 #define WX_PG_DECLARE_DOGETEDITORCLASS \
1984 virtual const wxPGEditor* DoGetEditorClass() const;
1985
1986 #ifndef SWIG
1987 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
1988 public: \
1989 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
1990 WX_PG_DECLARE_DOGETEDITORCLASS \
1991 private:
1992 #else
1993 #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME)
1994 #endif
1995
1996 // Implements sans constructor function. Also, first arg is class name, not
1997 // property name.
1998 #define WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(PROPNAME,T,EDITOR) \
1999 const wxPGEditor* PROPNAME::DoGetEditorClass() const \
2000 { \
2001 return wxPGEditor_##EDITOR; \
2002 }
2003
2004 // -----------------------------------------------------------------------
2005
2006 #ifndef SWIG
2007
2008 /** @class wxPGRootProperty
2009 @ingroup classes
2010 Root parent property.
2011 */
2012 class WXDLLIMPEXP_PROPGRID wxPGRootProperty : public wxPGProperty
2013 {
2014 public:
2015 WX_PG_DECLARE_PROPERTY_CLASS(wxPGRootProperty)
2016 public:
2017
2018 /** Constructor. */
2019 wxPGRootProperty();
2020 virtual ~wxPGRootProperty();
2021
2022 virtual bool StringToValue( wxVariant&, const wxString&, int ) const
2023 {
2024 return false;
2025 }
2026
2027 protected:
2028 };
2029
2030 // -----------------------------------------------------------------------
2031
2032 /** @class wxPropertyCategory
2033 @ingroup classes
2034 Category (caption) property.
2035 */
2036 class WXDLLIMPEXP_PROPGRID wxPropertyCategory : public wxPGProperty
2037 {
2038 friend class wxPropertyGrid;
2039 friend class wxPropertyGridPageState;
2040 WX_PG_DECLARE_PROPERTY_CLASS(wxPropertyCategory)
2041 public:
2042
2043 /** Default constructor is only used in special cases. */
2044 wxPropertyCategory();
2045
2046 wxPropertyCategory( const wxString& label,
2047 const wxString& name = wxPG_LABEL );
2048 ~wxPropertyCategory();
2049
2050 int GetTextExtent( const wxWindow* wnd, const wxFont& font ) const;
2051
2052 protected:
2053 virtual wxString GetValueAsString( int argFlags ) const;
2054
2055 void SetTextColIndex( unsigned int colInd )
2056 { m_capFgColIndex = (wxByte) colInd; }
2057 unsigned int GetTextColIndex() const
2058 { return (unsigned int) m_capFgColIndex; }
2059
2060 void CalculateTextExtent( wxWindow* wnd, const wxFont& font );
2061
2062 int m_textExtent; // pre-calculated length of text
2063 wxByte m_capFgColIndex; // caption text colour index
2064
2065 private:
2066 void Init();
2067 };
2068
2069 #endif // !SWIG
2070
2071 // -----------------------------------------------------------------------
2072
2073 #ifndef SWIG
2074
2075 /** @class wxPGChoiceEntry
2076 Data of a single wxPGChoices choice.
2077 */
2078 class WXDLLIMPEXP_PROPGRID wxPGChoiceEntry : public wxPGCell
2079 {
2080 public:
2081 wxPGChoiceEntry();
2082 wxPGChoiceEntry( const wxPGChoiceEntry& entry );
2083 wxPGChoiceEntry( const wxString& label,
2084 int value = wxPG_INVALID_VALUE )
2085 : wxPGCell(), m_value(value)
2086 {
2087 m_text = label;
2088 }
2089
2090 wxPGChoiceEntry( const wxString& label,
2091 int value,
2092 const wxBitmap& bitmap,
2093 const wxColour& fgCol = wxNullColour,
2094 const wxColour& bgCol = wxNullColour )
2095 : wxPGCell(label, bitmap, fgCol, bgCol), m_value(value)
2096 {
2097 }
2098
2099 virtual ~wxPGChoiceEntry()
2100 {
2101 }
2102
2103 void SetValue( int value ) { m_value = value; }
2104
2105 int GetValue() const { return m_value; }
2106
2107 bool HasValue() const { return (m_value != wxPG_INVALID_VALUE); }
2108
2109 protected:
2110 int m_value;
2111 };
2112
2113
2114 typedef void* wxPGChoicesId;
2115
2116 class WXDLLIMPEXP_PROPGRID wxPGChoicesData
2117 {
2118 friend class wxPGChoices;
2119 public:
2120 // Constructor sets m_refCount to 1.
2121 wxPGChoicesData();
2122
2123 void CopyDataFrom( wxPGChoicesData* data );
2124
2125 // Takes ownership of 'item'
2126 void Insert( int index, wxPGChoiceEntry* item )
2127 {
2128 wxArrayPtrVoid::iterator it;
2129 if ( index == -1 )
2130 {
2131 it = m_items.end();
2132 index = m_items.size();
2133 }
2134 else
2135 {
2136 it = m_items.begin() + index;
2137 }
2138
2139 // Need to fix value?
2140 if ( item->GetValue() == wxPG_INVALID_VALUE )
2141 item->SetValue(index);
2142
2143 m_items.insert(it, item);
2144 }
2145
2146 // Delete all entries
2147 void Clear();
2148
2149 size_t GetCount() const { return m_items.size(); }
2150
2151 wxPGChoiceEntry* Item( unsigned int i ) const
2152 {
2153 wxCHECK_MSG( i < GetCount(), NULL, "invalid index" );
2154
2155 return (wxPGChoiceEntry*) m_items[i];
2156 }
2157
2158 void DecRef()
2159 {
2160 m_refCount--;
2161 wxASSERT( m_refCount >= 0 );
2162 if ( m_refCount == 0 )
2163 delete this;
2164 }
2165
2166 private:
2167 wxArrayPtrVoid m_items;
2168
2169 // So that multiple properties can use the same set
2170 int m_refCount;
2171
2172 virtual ~wxPGChoicesData();
2173 };
2174
2175 #define wxPGChoicesEmptyData ((wxPGChoicesData*)NULL)
2176
2177 #endif // SWIG
2178
2179
2180 /** @class wxPGChoices
2181
2182 Helper class for managing choices of wxPropertyGrid properties.
2183 Each entry can have label, value, bitmap, text colour, and background
2184 colour.
2185
2186 @library{wxpropgrid}
2187 @category{propgrid}
2188 */
2189 class WXDLLIMPEXP_PROPGRID wxPGChoices
2190 {
2191 public:
2192 typedef long ValArrItem;
2193
2194 /** Default constructor. */
2195 wxPGChoices()
2196 {
2197 Init();
2198 }
2199
2200 /** Copy constructor. */
2201 wxPGChoices( const wxPGChoices& a )
2202 {
2203 if ( a.m_data != wxPGChoicesEmptyData )
2204 {
2205 m_data = a.m_data;
2206 m_data->m_refCount++;
2207 }
2208 }
2209
2210 /** Constructor. */
2211 wxPGChoices( const wxChar** labels, const long* values = NULL )
2212 {
2213 Init();
2214 Set(labels,values);
2215 }
2216
2217 /** Constructor. */
2218 wxPGChoices( const wxArrayString& labels,
2219 const wxArrayInt& values = wxArrayInt() )
2220 {
2221 Init();
2222 Set(labels,values);
2223 }
2224
2225 /** Simple interface constructor. */
2226 wxPGChoices( wxPGChoicesData* data )
2227 {
2228 wxASSERT(data);
2229 m_data = data;
2230 data->m_refCount++;
2231 }
2232
2233 /** Destructor. */
2234 ~wxPGChoices()
2235 {
2236 Free();
2237 }
2238
2239 /**
2240 Adds to current.
2241
2242 If did not have own copies, creates them now. If was empty, identical
2243 to set except that creates copies.
2244 */
2245 void Add( const wxChar** labels, const ValArrItem* values = NULL );
2246
2247 /** Version that works with wxArrayString. */
2248 void Add( const wxArrayString& arr, const ValArrItem* values = NULL );
2249
2250 /** Version that works with wxArrayString and wxArrayInt. */
2251 void Add( const wxArrayString& arr, const wxArrayInt& arrint );
2252
2253 /** Adds single item. */
2254 wxPGChoiceEntry& Add( const wxString& label,
2255 int value = wxPG_INVALID_VALUE );
2256
2257 /** Adds a single item, with bitmap. */
2258 wxPGChoiceEntry& Add( const wxString& label,
2259 const wxBitmap& bitmap,
2260 int value = wxPG_INVALID_VALUE );
2261
2262 /** Adds a single item with full entry information. */
2263 wxPGChoiceEntry& Add( const wxPGChoiceEntry& entry )
2264 {
2265 return Insert(entry, -1);
2266 }
2267
2268 /** Adds single item. */
2269 wxPGChoiceEntry& AddAsSorted( const wxString& label,
2270 int value = wxPG_INVALID_VALUE );
2271
2272 void Assign( const wxPGChoices& a )
2273 {
2274 AssignData(a.m_data);
2275 }
2276
2277 void AssignData( wxPGChoicesData* data );
2278
2279 /** Delete all choices. */
2280 void Clear()
2281 {
2282 if ( m_data != wxPGChoicesEmptyData )
2283 m_data->Clear();
2284 }
2285
2286 void EnsureData()
2287 {
2288 if ( m_data == wxPGChoicesEmptyData )
2289 m_data = new wxPGChoicesData();
2290 }
2291
2292 /** Gets a unsigned number identifying this list. */
2293 wxPGChoicesId GetId() const { return (wxPGChoicesId) m_data; };
2294
2295 const wxString& GetLabel( size_t ind ) const
2296 {
2297 return Item(ind).GetText();
2298 }
2299
2300 size_t GetCount () const
2301 {
2302 wxASSERT_MSG( m_data, "When checking if wxPGChoices is valid, "
2303 "use IsOk() instead of GetCount()" );
2304 return m_data->GetCount();
2305 }
2306
2307 int GetValue( size_t ind ) const { return Item(ind).GetValue(); }
2308
2309 /** Returns array of values matching the given strings. Unmatching strings
2310 result in wxPG_INVALID_VALUE entry in array.
2311 */
2312 wxArrayInt GetValuesForStrings( const wxArrayString& strings ) const;
2313
2314 /** Returns array of indices matching given strings. Unmatching strings
2315 are added to 'unmatched', if not NULL.
2316 */
2317 wxArrayInt GetIndicesForStrings( const wxArrayString& strings,
2318 wxArrayString* unmatched = NULL ) const;
2319
2320 /** Returns true if choices in general are likely to have values
2321 (depens on that all entries have values or none has)
2322 */
2323 bool HasValues() const;
2324
2325 bool HasValue( unsigned int i ) const
2326 { return (i < m_data->GetCount()) && m_data->Item(i)->HasValue(); }
2327
2328 int Index( const wxString& str ) const;
2329 int Index( int val ) const;
2330
2331 /** Inserts single item. */
2332 wxPGChoiceEntry& Insert( const wxString& label,
2333 int index,
2334 int value = wxPG_INVALID_VALUE );
2335
2336 /** Inserts a single item with full entry information. */
2337 wxPGChoiceEntry& Insert( const wxPGChoiceEntry& entry, int index );
2338
2339 /** Returns false if this is a constant empty set of choices,
2340 which should not be modified.
2341 */
2342 bool IsOk() const
2343 {
2344 return ( m_data != wxPGChoicesEmptyData );
2345 }
2346
2347 const wxPGChoiceEntry& Item( unsigned int i ) const
2348 {
2349 wxASSERT( IsOk() );
2350 return *m_data->Item(i);
2351 }
2352
2353 wxPGChoiceEntry& Item( unsigned int i )
2354 {
2355 wxASSERT( IsOk() );
2356 return *m_data->Item(i);
2357 }
2358
2359 /** Removes count items starting at position nIndex. */
2360 void RemoveAt(size_t nIndex, size_t count = 1);
2361
2362 #ifndef SWIG
2363 /** Does not create copies for itself. */
2364 void Set( const wxChar** labels, const long* values = NULL )
2365 {
2366 Free();
2367 Add(labels,values);
2368 }
2369
2370 /** Version that works with wxArrayString.
2371 TODO: Deprecate this.
2372 */
2373 void Set( wxArrayString& arr, const long* values = (const long*) NULL )
2374 {
2375 Free();
2376 Add(arr,values);
2377 }
2378 #endif // SWIG
2379
2380 /** Version that works with wxArrayString and wxArrayInt. */
2381 void Set( const wxArrayString& labels,
2382 const wxArrayInt& values = wxArrayInt() )
2383 {
2384 Free();
2385 if ( &values )
2386 Add(labels,values);
2387 else
2388 Add(labels);
2389 }
2390
2391 // Creates exclusive copy of current choices
2392 void SetExclusive()
2393 {
2394 if ( m_data->m_refCount != 1 )
2395 {
2396 wxPGChoicesData* data = new wxPGChoicesData();
2397 data->CopyDataFrom(m_data);
2398 Free();
2399 m_data = data;
2400 }
2401 }
2402
2403 // Returns data, increases refcount.
2404 wxPGChoicesData* GetData()
2405 {
2406 wxASSERT( m_data->m_refCount != 0xFFFFFFF );
2407 m_data->m_refCount++;
2408 return m_data;
2409 }
2410
2411 // Returns plain data ptr - no refcounting stuff is done.
2412 wxPGChoicesData* GetDataPtr() const { return m_data; }
2413
2414 // Changes ownership of data to you.
2415 wxPGChoicesData* ExtractData()
2416 {
2417 wxPGChoicesData* data = m_data;
2418 m_data = wxPGChoicesEmptyData;
2419 return data;
2420 }
2421
2422 wxArrayString GetLabels() const;
2423
2424 #ifndef SWIG
2425 void operator= (const wxPGChoices& a)
2426 {
2427 AssignData(a.m_data);
2428 }
2429
2430 wxPGChoiceEntry& operator[](unsigned int i)
2431 {
2432 return Item(i);
2433 }
2434
2435 const wxPGChoiceEntry& operator[](unsigned int i) const
2436 {
2437 return Item(i);
2438 }
2439
2440 protected:
2441 wxPGChoicesData* m_data;
2442
2443 void Init();
2444 void Free();
2445 #endif // !SWIG
2446 };
2447
2448 inline bool wxPGProperty::SetChoices( const wxArrayString& labels,
2449 const wxArrayInt& values )
2450 {
2451 wxPGChoices chs(labels, values);
2452 return SetChoices(chs);
2453 }
2454
2455 // -----------------------------------------------------------------------
2456
2457 #endif // wxUSE_PROPGRID
2458
2459 #endif // _WX_PROPGRID_PROPERTY_H_