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