Removed unused comment
[wxWidgets.git] / interface / wx / propgrid / property.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: property.h
3 // Purpose: interface of wxPGProperty
4 // Author: wxWidgets team
5 // RCS-ID: $Id:
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9
10 #define wxNullProperty ((wxPGProperty*)NULL)
11
12
13 // Structure for relaying choice/list info.
14 struct wxPGChoiceInfo
15 {
16 wxPGChoices* m_choices;
17 };
18
19
20 /** @section propgrid_property_attributes wxPropertyGrid Property Attribute Identifiers
21
22 wxPGProperty::SetAttribute() and
23 wxPropertyGridInterface::SetPropertyAttribute()
24 accept one of these as attribute name argument .
25
26 You can use strings instead of constants. However, some of these
27 constants are redefined to use cached strings which may reduce
28 your binary size by some amount.
29
30 @{
31 */
32
33 /** Set default value for property.
34 */
35 #define wxPG_ATTR_DEFAULT_VALUE wxS("DefaultValue")
36
37 /** Universal, int or double. Minimum value for numeric properties.
38 */
39 #define wxPG_ATTR_MIN wxS("Min")
40
41 /** Universal, int or double. Maximum value for numeric properties.
42 */
43 #define wxPG_ATTR_MAX wxS("Max")
44
45 /** Universal, string. When set, will be shown as text after the displayed
46 text value. Alternatively, if third column is enabled, text will be shown
47 there (for any type of property).
48 */
49 #define wxPG_ATTR_UNITS wxS("Units")
50
51 /** Universal, string. When set, will be shown in property's value cell
52 when displayed value string is empty, or value is unspecified.
53 */
54 #define wxPG_ATTR_INLINE_HELP wxS("InlineHelp")
55
56 /** wxBoolProperty specific, int, default 0. When 1 sets bool property to
57 use checkbox instead of choice.
58 */
59 #define wxPG_BOOL_USE_CHECKBOX wxS("UseCheckbox")
60
61 /** wxBoolProperty specific, int, default 0. When 1 sets bool property value
62 to cycle on double click (instead of showing the popup listbox).
63 */
64 #define wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING wxS("UseDClickCycling")
65
66 /** wxFloatProperty (and similar) specific, int, default -1. Sets the (max) precision
67 used when floating point value is rendered as text. The default -1 means infinite
68 precision.
69 */
70 #define wxPG_FLOAT_PRECISION wxS("Precision")
71
72 /** The text will be echoed as asterisks (wxTE_PASSWORD will be passed to textctrl etc).
73 */
74 #define wxPG_STRING_PASSWORD wxS("Password")
75
76 /** Define base used by a wxUIntProperty. Valid constants are
77 wxPG_BASE_OCT, wxPG_BASE_DEC, wxPG_BASE_HEX and wxPG_BASE_HEXL
78 (lowercase characters).
79 */
80 #define wxPG_UINT_BASE wxS("Base")
81
82 /** Define prefix rendered to wxUIntProperty. Accepted constants
83 wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and wxPG_PREFIX_DOLLAR_SIGN.
84 <b>Note:</b> Only wxPG_PREFIX_NONE works with Decimal and Octal
85 numbers.
86 */
87 #define wxPG_UINT_PREFIX wxS("Prefix")
88
89 /** wxFileProperty/wxImageFileProperty specific, wxChar*, default is detected/varies.
90 Sets the wildcard used in the triggered wxFileDialog. Format is the
91 same.
92 */
93 #define wxPG_FILE_WILDCARD wxS("Wildcard")
94
95 /** wxFileProperty/wxImageFileProperty specific, int, default 1.
96 When 0, only the file name is shown (i.e. drive and directory are hidden).
97 */
98 #define wxPG_FILE_SHOW_FULL_PATH wxS("ShowFullPath")
99
100 /** Specific to wxFileProperty and derived properties, wxString, default empty.
101 If set, then the filename is shown relative to the given path string.
102 */
103 #define wxPG_FILE_SHOW_RELATIVE_PATH wxS("ShowRelativePath")
104
105 /** Specific to wxFileProperty and derived properties, wxString, default is empty.
106 Sets the initial path of where to look for files.
107 */
108 #define wxPG_FILE_INITIAL_PATH wxS("InitialPath")
109
110 /** Specific to wxFileProperty and derivatives, wxString, default is empty.
111 Sets a specific title for the dir dialog.
112 */
113 #define wxPG_FILE_DIALOG_TITLE wxS("DialogTitle")
114
115 /** Specific to wxDirProperty, wxString, default is empty.
116 Sets a specific message for the dir dialog.
117 */
118 #define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage")
119
120 /** Sets displayed date format for wxDateProperty.
121 */
122 #define wxPG_DATE_FORMAT wxS("DateFormat")
123
124 /** Sets wxDatePickerCtrl window style used with wxDateProperty. Default
125 is wxDP_DEFAULT | wxDP_SHOWCENTURY.
126 */
127 #define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
128
129 /** SpinCtrl editor, int or double. How much number changes when button is
130 pressed (or up/down on keybard).
131 */
132 #define wxPG_ATTR_SPINCTRL_STEP wxS("Step")
133
134 /** SpinCtrl editor, bool. If true, value wraps at Min/Max.
135 */
136 #define wxPG_ATTR_SPINCTRL_WRAP wxS("Wrap")
137
138 /** wxMultiChoiceProperty, int. If 0, no user strings allowed. If 1, user strings
139 appear before list strings. If 2, user strings appear after list string.
140 */
141 #define wxPG_ATTR_MULTICHOICE_USERSTRINGMODE wxS("UserStringMode")
142
143 /** wxColourProperty and its kind, int, default 1. Setting this attribute to 0 hides custom
144 colour from property's list of choices.
145 */
146 #define wxPG_COLOUR_ALLOW_CUSTOM wxS("AllowCustom")
147
148 /** @}
149 */
150
151 // -----------------------------------------------------------------------
152
153 /** @class wxPGProperty
154
155 wxPGProperty is base class for all wxPropertyGrid properties. In
156 sections below we cover few related topics.
157
158 @li @ref pgproperty_properties
159 @li @ref pgproperty_creating
160
161 @section pgproperty_properties Supplied Ready-to-use Property Classes
162
163 Here is a list and short description of supplied fully-functional
164 property classes. They are located in either props.h or advprops.h.
165
166 @li @ref wxArrayStringProperty
167 @li @ref wxBoolProperty
168 @li @ref wxColourProperty
169 @li @ref wxCursorProperty
170 @li @ref wxDateProperty
171 @li @ref wxDirProperty
172 @li @ref wxEditEnumProperty
173 @li @ref wxEnumProperty
174 @li @ref wxFileProperty
175 @li @ref wxFlagsProperty
176 @li @ref wxFloatProperty
177 @li @ref wxFontProperty
178 @li @ref wxImageFileProperty
179 @li @ref wxIntProperty
180 @li @ref wxLongStringProperty
181 @li @ref wxMultiChoiceProperty
182 @li @ref wxPropertyCategory
183 @li @ref wxStringProperty
184 @li @ref wxSystemColourProperty
185 @li @ref wxUIntProperty
186
187 @subsection wxPropertyCategory
188
189 Not an actual property per se, but a header for a group of properties.
190 Regardless inherits from wxPGProperty.
191
192 @subsection wxStringProperty
193
194 Simple string property. wxPG_STRING_PASSWORD attribute may be used
195 to echo value as asterisks and use wxTE_PASSWORD for wxTextCtrl.
196
197 @remarks
198 * wxStringProperty has a special trait: if it has value of "<composed>",
199 and also has child properties, then its displayed value becomes
200 composition of child property values, similar as with wxFontProperty,
201 for instance.
202
203 @subsection wxIntProperty
204
205 Like wxStringProperty, but converts text to a signed long integer.
206 wxIntProperty seamlessly supports 64-bit integers (ie. wxLongLong).
207
208 @subsection wxUIntProperty
209
210 Like wxIntProperty, but displays value as unsigned int. To set
211 the prefix used globally, manipulate wxPG_UINT_PREFIX string attribute.
212 To set the globally used base, manipulate wxPG_UINT_BASE int
213 attribute. Regardless of current prefix, understands (hex) values starting
214 with both "0x" and "$".
215 wxUIntProperty seamlessly supports 64-bit unsigned integers (ie. wxULongLong).
216
217 @subsection wxFloatProperty
218
219 Like wxStringProperty, but converts text to a double-precision floating point.
220 Default float-to-text precision is 6 decimals, but this can be changed
221 by modifying wxPG_FLOAT_PRECISION attribute.
222
223 @subsection wxBoolProperty
224
225 Represents a boolean value. wxChoice is used as editor control, by the
226 default. wxPG_BOOL_USE_CHECKBOX attribute can be set to true inorder to use
227 check box instead.
228
229 @subsection wxLongStringProperty
230
231 Like wxStringProperty, but has a button that triggers a small text editor
232 dialog. Note that in long string values, tabs are represented by "\t" and
233 line break by "\n".
234
235 @subsection wxDirProperty
236
237 Like wxLongStringProperty, but the button triggers dir selector instead.
238 Supported properties (all with string value): wxPG_DIR_DIALOG_MESSAGE.
239
240 @subsection wxFileProperty
241
242 Like wxLongStringProperty, but the button triggers file selector instead.
243 Default wildcard is "All files..." but this can be changed by setting
244 wxPG_FILE_WILDCARD attribute (see wxFileDialog for format details).
245 Attribute wxPG_FILE_SHOW_FULL_PATH can be set to false inorder to show
246 only the filename, not the entire path.
247
248 @subsection wxEnumProperty
249
250 Represents a single selection from a list of choices -
251 wxOwnerDrawnComboBox is used to edit the value.
252
253 @subsection wxFlagsProperty
254
255 Represents a bit set that fits in a long integer. wxBoolProperty sub-properties
256 are created for editing individual bits. Textctrl is created to manually edit
257 the flags as a text; a continous sequence of spaces, commas and semicolons
258 is considered as a flag id separator.
259 <b>Note: </b> When changing "choices" (ie. flag labels) of wxFlagsProperty, you
260 will need to use SetPropertyChoices - otherwise they will not get updated properly.
261
262 @subsection wxArrayStringProperty
263
264 Allows editing of a list of strings in wxTextCtrl and in a separate dialog.
265
266 @subsection wxDateProperty
267
268 wxDateTime property. Default editor is DatePickerCtrl, altough TextCtrl
269 should work as well. wxPG_DATE_FORMAT attribute can be used to change
270 string wxDateTime::Format uses (altough default is recommended as it is
271 locale-dependant), and wxPG_DATE_PICKER_STYLE allows changing window
272 style given to DatePickerCtrl (default is wxDP_DEFAULT|wxDP_SHOWCENTURY).
273
274 @subsection wxEditEnumProperty
275
276 Represents a string that can be freely edited or selected from list of choices -
277 custom combobox control is used to edit the value.
278
279 @subsection wxMultiChoiceProperty
280
281 Allows editing a multiple selection from a list of strings. This is
282 property is pretty much built around concept of wxMultiChoiceDialog.
283 It uses wxArrayString value.
284
285 @subsection wxImageFileProperty
286
287 Like wxFileProperty, but has thumbnail of the image in front of
288 the filename and autogenerates wildcard from available image handlers.
289
290 @subsection wxColourProperty
291
292 <b>Useful alternate editor:</b> Choice.
293
294 Represents wxColour. wxButton is used to trigger a colour picker dialog.
295
296 @subsection wxFontProperty
297
298 Represents wxFont. Various sub-properties are used to edit individual
299 subvalues.
300
301 @subsection wxSystemColourProperty
302
303 Represents wxColour and a system colour index. wxChoice is used to edit
304 the value. Drop-down list has color images. Note that value type
305 is wxColourPropertyValue instead of wxColour.
306 @code
307 class wxColourPropertyValue : public wxObject
308 {
309 public:
310 // An integer value relating to the colour, and which exact
311 // meaning depends on the property with which it is used.
312 //
313 // For wxSystemColourProperty:
314 // Any of wxSYS_COLOUR_XXX, or any web-colour ( use wxPG_TO_WEB_COLOUR
315 // macro - (currently unsupported) ), or wxPG_COLOUR_CUSTOM.
316 wxUint32 m_type;
317
318 // Resulting colour. Should be correct regardless of type.
319 wxColour m_colour;
320 };
321 @endcode
322
323 @subsection wxCursorProperty
324
325 Represents a wxCursor. wxChoice is used to edit the value.
326 Drop-down list has cursor images under some (wxMSW) platforms.
327
328
329 @section pgproperty_creating Creating Custom Properties
330
331 New properties can be created by subclassing wxPGProperty or one
332 of the provided property classes, and (re)implementing necessary
333 member functions. Below, each virtual member function has ample
334 documentation about its purpose and any odd details which to keep
335 in mind.
336
337 Here is a very simple 'template' code:
338
339 @code
340 class MyProperty : public wxPGProperty
341 {
342 public:
343 // All arguments of ctor must have a default value -
344 // use wxPG_LABEL for label and name
345 MyProperty( const wxString& label = wxPG_LABEL,
346 const wxString& name = wxPG_LABEL,
347 const wxString& value = wxEmptyString )
348 {
349 // m_value is wxVariant
350 m_value = value;
351 }
352
353 virtual ~MyProperty() { }
354
355 const wxPGEditor* DoGetEditorClass() const
356 {
357 // Determines editor used by property.
358 // You can replace 'TextCtrl' below with any of these
359 // builtin-in property editor identifiers: Choice, ComboBox,
360 // TextCtrlAndButton, ChoiceAndButton, CheckBox, SpinCtrl,
361 // DatePickerCtrl.
362 return wxPGEditor_TextCtrl;
363 }
364
365 virtual wxString GetValueAsString( int argFlags ) const
366 {
367 // TODO: Return property value in string format
368 }
369
370 virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags )
371 {
372 // TODO: Adapt string to property value.
373 }
374
375 protected:
376 };
377 @endcode
378
379 Since wxPGProperty derives from wxObject, you can use standard
380 DECLARE_DYNAMIC_CLASS and IMPLEMENT_DYNAMIC_CLASS macros. From the
381 above example they were omitted for sake of simplicity, and besides,
382 they are only really needed if you need to use wxRTTI with your
383 property class.
384
385 You can change the 'value type' of a property by simply assigning different
386 type of variant with SetValue. <b>It is mandatory to implement
387 wxVariantData class for all data types used as property values.</b>
388 You can use macros declared in wxPropertyGrid headers. For instance:
389
390 @code
391 // In header file:
392 // (If you need to have export declaration, use version of macros
393 // with _EXPORTED postfix)
394 WX_PG_DECLARE_VARIANT_DATA(MyDataClass)
395
396 // In sources file:
397 WX_PG_IMPLEMENT_VARIANT_DATA(MyDataClass)
398
399 // Or, if you don't have valid == operator:
400 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(MyDataClass)
401 @endcode
402
403 @library{wxpropgrid}
404 @category{propgrid}
405 */
406 class wxPGProperty : public wxObject
407 {
408 public:
409 typedef wxUint32 FlagType;
410
411 /** Basic constructor.
412 */
413 wxPGProperty();
414
415 /** Constructor.
416 Non-abstract property classes should have constructor of this style:
417
418 @code
419
420 // If T is a class, then it should be a constant reference
421 // (e.g. const T& ) instead.
422 MyProperty( const wxString& label, const wxString& name, T value )
423 : wxPGProperty()
424 {
425 // Generally recommended way to set the initial value
426 // (as it should work in pretty much 100% of cases).
427 wxVariant variant;
428 variant << value;
429 SetValue(variant);
430
431 // If has private child properties then create them here. For example:
432 // AddChild( new wxStringProperty( "Subprop 1", wxPG_LABEL, value.GetSubProp1() ) );
433 }
434
435 @endcode
436 */
437 wxPGProperty( const wxString& label, const wxString& name );
438
439 /** Virtual destructor. It is customary for derived properties to implement this. */
440 virtual ~wxPGProperty();
441
442 /** This virtual function is called after m_value has been set.
443
444 @remarks
445 - If m_value was set to Null variant (ie. unspecified value), OnSetValue()
446 will not be called.
447 - m_value may be of any variant type. Typically properties internally support only
448 one variant type, and as such OnSetValue() provides a good opportunity to convert
449 supported values into internal type.
450 - Default implementation does nothing.
451 */
452 virtual void OnSetValue();
453
454 /** Override this to return something else than m_value as the value.
455 */
456 virtual wxVariant DoGetValue() const { return m_value; }
457
458 /** Implement this function in derived class to check the value.
459 Return true if it is ok. Returning false prevents property change events
460 from occurring.
461
462 @remarks
463 - Default implementation always returns true.
464 */
465 virtual bool ValidateValue( wxVariant& value, wxPGValidationInfo& validationInfo ) const;
466
467 /** Converts 'text' into proper value 'variant'. Returns true if new (different than
468 m_value) value could be interpreted from the text.
469 @param argFlags
470 If wxPG_FULL_VALUE is set, returns complete, storable value instead of displayable
471 one (they may be different).
472 If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of composite
473 property string value (as generated by GetValueAsString() called with this same
474 flag).
475
476 @remarks
477 Default implementation converts semicolon delimited tokens into child values. Only
478 works for properties with children.
479 */
480 virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags = 0 ) const;
481
482 /** Converts 'number' (including choice selection) into proper value 'variant'.
483 Returns true if new (different than m_value) value could be interpreted from the integer.
484 @param argFlags
485 If wxPG_FULL_VALUE is set, returns complete, storable value instead of displayable one.
486
487 @remarks
488 - If property is not supposed to use choice or spinctrl or other editor
489 with int-based value, it is not necessary to implement this method.
490 - Default implementation simply assign given int to m_value.
491 - If property uses choice control, and displays a dialog on some choice items,
492 then it is preferred to display that dialog in IntToValue instead of OnEvent.
493 */
494 virtual bool IntToValue( wxVariant& value, int number, int argFlags = 0 ) const;
495
496 public:
497
498 /** Returns text representation of property's value.
499
500 @param argFlags
501 If wxPG_FULL_VALUE is set, returns complete, storable string value instead of displayable.
502 If wxPG_EDITABLE_VALUE is set, returns string value that must be editable in textctrl.
503 If wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to display
504 as a part of composite property string value.
505
506 @remarks
507 Default implementation returns string composed from text representations of
508 child properties.
509 */
510 virtual wxString GetValueAsString( int argFlags = 0 ) const;
511
512 /** Converts string to a value, and if successful, calls SetValue() on it.
513 Default behavior is to do nothing.
514 @param text
515 String to get the value from.
516 @retval
517 true if value was changed.
518 */
519 bool SetValueFromString( const wxString& text, int flags = 0 );
520
521 /** Converts integer to a value, and if succesful, calls SetValue() on it.
522 Default behavior is to do nothing.
523 @param value
524 Int to get the value from.
525 @param flags
526 If has wxPG_FULL_VALUE, then the value given is a actual value and not an index.
527 @retval
528 True if value was changed.
529 */
530 bool SetValueFromInt( long value, int flags = 0 );
531
532 /** Returns size of the custom painted image in front of property. This method
533 must be overridden to return non-default value if OnCustomPaint is to be
534 called.
535 @param item
536 Normally -1, but can be an index to the property's list of items.
537 @remarks
538 - Default behavior is to return wxSize(0,0), which means no image.
539 - Default image width or height is indicated with dimension -1.
540 - You can also return wxPG_DEFAULT_IMAGE_SIZE which equals wxSize(-1, -1).
541 */
542 virtual wxSize OnMeasureImage( int item = -1 ) const;
543
544 /** Events received by editor widgets are processed here. Note that editor class
545 usually processes most events. Some, such as button press events of
546 TextCtrlAndButton class, can be handled here. Also, if custom handling
547 for regular events is desired, then that can also be done (for example,
548 wxSystemColourProperty custom handles wxEVT_COMMAND_CHOICE_SELECTED
549 to display colour picker dialog when 'custom' selection is made).
550
551 If the event causes value to be changed, SetValueInEvent()
552 should be called to set the new value.
553
554 @param event
555 Associated wxEvent.
556 @retval
557 Should return true if any changes in value should be reported.
558 @remarks
559 - If property uses choice control, and displays a dialog on some choice items,
560 then it is preferred to display that dialog in IntToValue instead of OnEvent.
561 */
562 virtual bool OnEvent( wxPropertyGrid* propgrid, wxWindow* wnd_primary, wxEvent& event );
563
564 /** Called after value of a child property has been altered. Note that this function is
565 usually called at the time that value of this property, or given child property, is
566 still pending for change.
567
568 Sample pseudo-code implementation:
569
570 @code
571 void MyProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const
572 {
573 // Acquire reference to actual type of data stored in variant
574 // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros were used to create
575 // the variant class).
576 T& data = TFromVariant(thisValue);
577
578 // Copy childValue into data.
579 switch ( childIndex )
580 {
581 case 0:
582 data.SetSubProp1( childvalue.GetLong() );
583 break;
584 case 1:
585 data.SetSubProp2( childvalue.GetString() );
586 break;
587 ...
588 }
589 }
590 @endcode
591
592 @param thisValue
593 Value of this property, that should be altered.
594 @param childIndex
595 Index of child changed (you can use Item(childIndex) to get).
596 @param childValue
597 Value of the child property.
598 */
599 virtual void ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const;
600
601 /** Returns pointer to an instance of used editor.
602 */
603 virtual const wxPGEditor* DoGetEditorClass() const;
604
605 /** Returns pointer to the wxValidator that should be used
606 with the editor of this property (NULL for no validator).
607 Setting validator explicitly via SetPropertyValidator
608 will override this.
609
610 In most situations, code like this should work well
611 (macros are used to maintain one actual validator instance,
612 so on the second call the function exits within the first
613 macro):
614
615 @code
616
617 wxValidator* wxMyPropertyClass::DoGetValidator () const
618 {
619 WX_PG_DOGETVALIDATOR_ENTRY()
620
621 wxMyValidator* validator = new wxMyValidator(...);
622
623 ... prepare validator...
624
625 WX_PG_DOGETVALIDATOR_EXIT(validator)
626 }
627
628 @endcode
629
630 @remarks
631 You can get common filename validator by returning
632 wxFileProperty::GetClassValidator(). wxDirProperty,
633 for example, uses it.
634 */
635 virtual wxValidator* DoGetValidator () const;
636
637 /** Returns current value's index to the choice control. May also return,
638 through pointer arguments, strings that should be inserted to that control.
639 Irrelevant to classes which do not employ wxPGEditor_Choice or similar.
640 @remarks
641 - If returns NULL in choiceinfo.m_choices, then this class must be
642 derived from wxBaseEnumProperty.
643 - Must be able to cope situation where property's set of choices is
644 uninitialized.
645 */
646 virtual int GetChoiceInfo( wxPGChoiceInfo* choiceinfo );
647
648 /** Override to paint an image in front of the property value text or drop-down
649 list item (but only if wxPGProperty::OnMeasureImage is overridden as well).
650
651 If property's OnMeasureImage() returns size that has height != 0 but less than
652 row height ( < 0 has special meanings), wxPropertyGrid calls this method to
653 draw a custom image in a limited area in front of the editor control or
654 value text/graphics, and if control has drop-down list, then the image is
655 drawn there as well (even in the case OnMeasureImage() returned higher height
656 than row height).
657
658 NOTE: Following applies when OnMeasureImage() returns a "flexible" height (
659 using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable height items:
660 If rect.x is < 0, then this is a measure item call, which means that
661 dc is invalid and only thing that should be done is to set paintdata.m_drawnHeight
662 to the height of the image of item at index paintdata.m_choiceItem. This call
663 may be done even as often as once every drop-down popup show.
664
665 @param dc
666 wxDC to paint on.
667 @param rect
668 Box reserved for custom graphics. Includes surrounding rectangle, if any.
669 If x is < 0, then this is a measure item call (see above).
670 @param paintdata
671 wxPGPaintData structure with much useful data about painted item.
672 @code
673 struct wxPGPaintData
674 {
675 // wxPropertyGrid.
676 const wxPropertyGrid* m_parent;
677
678 // Normally -1, otherwise index to drop-down list item that has to be drawn.
679 int m_choiceItem;
680
681 // Set to drawn width in OnCustomPaint (optional).
682 int m_drawnWidth;
683
684 // In a measure item call, set this to the height of item at m_choiceItem index
685 int m_drawnHeight;
686 };
687 @endcode
688
689 @remarks
690 - You can actually exceed rect width, but if you do so then paintdata.m_drawnWidth
691 must be set to the full width drawn in pixels.
692 - Due to technical reasons, rect's height will be default even if custom height
693 was reported during measure call.
694 - Brush is guaranteed to be default background colour. It has been already used to
695 clear the background of area being painted. It can be modified.
696 - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper colour) pen for
697 drawing framing rectangle. It can be changed as well.
698
699 @see GetValueAsString()
700 */
701 virtual void OnCustomPaint( wxDC& dc, const wxRect& rect, wxPGPaintData& paintdata );
702
703 /** Returns used wxPGCellRenderer instance for given property column (label=0, value=1).
704
705 Default implementation returns editor's renderer for all columns.
706 */
707 virtual wxPGCellRenderer* GetCellRenderer( int column ) const;
708
709 /** Refresh values of child properties. Automatically called after value is set.
710 */
711 virtual void RefreshChildren();
712
713 /** Special handling for attributes of this property.
714
715 If returns false, then the attribute will be automatically stored in
716 m_attributes.
717
718 Default implementation simply returns false.
719 */
720 virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
721
722 /** Returns value of an attribute.
723
724 Override if custom handling of attributes is needed.
725
726 Default implementation simply return NULL variant.
727 */
728 virtual wxVariant DoGetAttribute( const wxString& name ) const;
729
730 /** Returns instance of a new wxPGEditorDialogAdapter instance, which is
731 used when user presses the (optional) button next to the editor control;
732
733 Default implementation returns NULL (ie. no action is generated when
734 button is pressed).
735 */
736 virtual wxPGEditorDialogAdapter* GetEditorDialog() const;
737
738 /** Adds entry to property's wxPGChoices and editor control (if it is active).
739 Returns index of item added.
740 */
741 int AppendChoice( const wxString& label, int value = wxPG_INVALID_VALUE )
742 {
743 return InsertChoice(label,-1,value);
744 }
745
746 /** Returns wxPGCell of given column, NULL if none. If valid
747 object is returned, caller will gain its ownership.
748 */
749 wxPGCell* AcquireCell( unsigned int column )
750 {
751 if ( column >= m_cells.size() )
752 return NULL;
753
754 wxPGCell* cell = (wxPGCell*) m_cells[column];
755 m_cells[column] = NULL;
756 return cell;
757 }
758
759 /** Returns true if children of this property are component values (for instance,
760 points size, face name, and is_underlined are component values of a font).
761 */
762 bool AreChildrenComponents() const
763 {
764 if ( m_flags & (wxPG_PROP_COMPOSED_VALUE|wxPG_PROP_AGGREGATE) )
765 return true;
766
767 return false;
768 }
769
770 /** Removes entry from property's wxPGChoices and editor control (if it is active).
771
772 If selected item is deleted, then the value is set to unspecified.
773 */
774 void DeleteChoice( int index );
775
776 /** Call to enable or disable usage of common value (integer value that can be selected for
777 properties instead of their normal values) for this property.
778
779 Common values are disabled by the default for all properties.
780 */
781 void EnableCommonValue( bool enable = true )
782 {
783 if ( enable ) SetFlag( wxPG_PROP_USES_COMMON_VALUE );
784 else ClearFlag( wxPG_PROP_USES_COMMON_VALUE );
785 }
786
787 /** Composes text from values of child properties. */
788 void GenerateComposedValue( wxString& text, int argFlags = 0 ) const;
789
790 /** Returns property's label. */
791 const wxString& GetLabel() const { return m_label; }
792
793 /** Returns property's name with all (non-category, non-root) parents. */
794 wxString GetName() const;
795
796 /** Returns property's base name (ie. parent's name is not added in any case) */
797 const wxString& GetBaseName() const { return m_name; }
798
799 wxPGChoices& GetChoices();
800
801 const wxPGChoices& GetChoices() const;
802
803 const wxPGChoiceEntry* GetCurrentChoice() const;
804
805 /** Returns coordinate to the top y of the property. Note that the
806 position of scrollbars is not taken into account.
807 */
808 int GetY() const;
809
810 wxVariant GetValue() const
811 {
812 return DoGetValue();
813 }
814
815 /** Returns reference to the internal stored value. GetValue is preferred
816 way to get the actual value, since GetValueRef ignores DoGetValue,
817 which may override stored value.
818 */
819 wxVariant& GetValueRef()
820 {
821 return m_value;
822 }
823
824 const wxVariant& GetValueRef() const
825 {
826 return m_value;
827 }
828
829 /** Same as GetValueAsString, except takes common value into account.
830 */
831 wxString GetValueString( int argFlags = 0 ) const;
832
833 void UpdateControl( wxWindow* primary );
834
835 /** Returns wxPGCell of given column, NULL if none. wxPGProperty
836 will retain ownership of the cell object.
837 */
838 wxPGCell* GetCell( unsigned int column ) const
839 {
840 if ( column >= m_cells.size() )
841 return NULL;
842
843 return (wxPGCell*) m_cells[column];
844 }
845
846 unsigned int GetChoiceCount() const;
847
848 wxString GetChoiceString( unsigned int index );
849
850 /** Return number of displayed common values for this property.
851 */
852 int GetDisplayedCommonValueCount() const;
853
854 wxString GetDisplayedString() const
855 {
856 return GetValueString(0);
857 }
858
859 /** Returns property grid where property lies. */
860 wxPropertyGrid* GetGrid() const;
861
862 /** Returns owner wxPropertyGrid, but only if one is currently on a page
863 displaying this property. */
864 wxPropertyGrid* GetGridIfDisplayed() const;
865
866 /** Returns highest level non-category, non-root parent. Useful when you
867 have nested wxCustomProperties/wxParentProperties.
868 @remarks
869 Thus, if immediate parent is root or category, this will return the
870 property itself.
871 */
872 wxPGProperty* GetMainParent() const;
873
874 /** Return parent of property */
875 wxPGProperty* GetParent() const { return m_parent; }
876
877 /** Returns true if property has editable wxTextCtrl when selected.
878
879 @remarks
880 Altough disabled properties do not displayed editor, they still
881 return True here as being disabled is considered a temporary
882 condition (unlike being read-only or having limited editing enabled).
883 */
884 bool IsTextEditable() const;
885
886 bool IsValueUnspecified() const
887 {
888 return m_value.IsNull();
889 }
890
891 FlagType HasFlag( FlagType flag ) const
892 {
893 return ( m_flags & flag );
894 }
895
896 /** Returns comma-delimited string of property attributes.
897 */
898 const wxPGAttributeStorage& GetAttributes() const
899 {
900 return m_attributes;
901 }
902
903 /** Returns m_attributes as list wxVariant.
904 */
905 wxVariant GetAttributesAsList() const;
906
907 FlagType GetFlags() const
908 {
909 return m_flags;
910 }
911
912 const wxPGEditor* GetEditorClass() const;
913
914 wxString GetValueType() const
915 {
916 return m_value.GetType();
917 }
918
919 /** Returns editor used for given column. NULL for no editor.
920 */
921 const wxPGEditor* GetColumnEditor( int column ) const
922 {
923 if ( column == 1 )
924 return GetEditorClass();
925
926 return NULL;
927 }
928
929 /** Returns common value selected for this property. -1 for none.
930 */
931 int GetCommonValue() const
932 {
933 return m_commonValue;
934 }
935
936 /** Returns true if property has even one visible child.
937 */
938 bool HasVisibleChildren() const;
939
940 /** Adds entry to property's wxPGChoices and editor control (if it is active).
941 Returns index of item added.
942 */
943 int InsertChoice( const wxString& label, int index, int value = wxPG_INVALID_VALUE );
944
945 /** Returns true if this property is actually a wxPropertyCategory.
946 */
947 bool IsCategory() const { return HasFlag(wxPG_PROP_CATEGORY)?true:false; }
948
949 /** Returns true if this property is actually a wxRootProperty.
950 */
951 bool IsRoot() const { return (m_parent == NULL); }
952
953 /** Returns true if this is a sub-property. */
954 bool IsSubProperty() const
955 {
956 wxPGProperty* parent = (wxPGProperty*)m_parent;
957 if ( parent && !parent->IsCategory() )
958 return true;
959 return false;
960 }
961
962 /** Returns last visible sub-property, recursively.
963 */
964 const wxPGProperty* GetLastVisibleSubItem() const;
965
966 wxVariant GetDefaultValue() const;
967
968 int GetMaxLength() const
969 {
970 return (int) m_maxLen;
971 }
972
973 /** Determines, recursively, if all children are not unspecified. Takes values in given list into account.
974 */
975 bool AreAllChildrenSpecified( wxVariant* pendingList = NULL ) const;
976
977 /** Updates composed values of parent non-category properties, recursively.
978 Returns topmost property updated.
979
980 @remarks
981 - Must not call SetValue() (as can be called in it).
982 */
983 wxPGProperty* UpdateParentValues();
984
985 /** Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
986 */
987 FlagType UsesAutoUnspecified() const
988 {
989 return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED);
990 }
991
992 wxBitmap* GetValueImage() const
993 {
994 return m_valueBitmap;
995 }
996
997 wxVariant GetAttribute( const wxString& name ) const;
998
999 /** Returns named attribute, as string, if found. Otherwise defVal is returned.
1000 */
1001 wxString GetAttribute( const wxString& name, const wxString& defVal ) const;
1002
1003 /** Returns named attribute, as long, if found. Otherwise defVal is returned.
1004 */
1005 long GetAttributeAsLong( const wxString& name, long defVal ) const;
1006
1007 /** Returns named attribute, as double, if found. Otherwise defVal is returned.
1008 */
1009 double GetAttributeAsDouble( const wxString& name, double defVal ) const;
1010
1011 inline unsigned int GetArrIndex() const { return m_arrIndex; }
1012
1013 inline unsigned int GetDepth() const { return (unsigned int)m_depth; }
1014
1015 /** Gets flags as a'|' delimited string. Note that flag names are not
1016 prepended with 'wxPG_PROP_'.
1017 @param flagsMask
1018 String will only be made to include flags combined by this parameter.
1019 */
1020 wxString GetFlagsAsString( FlagType flagsMask ) const;
1021
1022 /** Returns position in parent's array. */
1023 unsigned int GetIndexInParent() const
1024 {
1025 return (unsigned int)m_arrIndex;
1026 }
1027
1028 /** Hides or reveals the property.
1029 @param hide
1030 true for hide, false for reveal.
1031 @param flags
1032 By default changes are applied recursively. Set this paramter wxPG_DONT_RECURSE to prevent this.
1033 */
1034 inline bool Hide( bool hide, int flags = wxPG_RECURSE );
1035
1036 bool IsExpanded() const { return (!(m_flags & wxPG_PROP_COLLAPSED) && GetChildCount()); }
1037
1038 /** Returns true if all parents expanded.
1039 */
1040 bool IsVisible() const;
1041
1042 bool IsEnabled() const
1043 {
1044 return ( m_flags & wxPG_PROP_DISABLED ) ? false : true;
1045 }
1046
1047 /** If property's editor is created this forces its recreation. Useful
1048 in SetAttribute etc. Returns true if actually did anything.
1049 */
1050 bool RecreateEditor();
1051
1052 /** If property's editor is active, then update it's value.
1053 */
1054 void RefreshEditor();
1055
1056 /** Sets an attribute for this property.
1057 @param name
1058 Text identifier of attribute. See @ref propgrid_property_attributes.
1059 @param value
1060 Value of attribute.
1061 */
1062 void SetAttribute( const wxString& name, wxVariant value );
1063
1064 void SetAttributes( const wxPGAttributeStorage& attributes );
1065
1066 /** Sets editor for a property.
1067
1068 @param editor
1069 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1070 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full list).
1071
1072 For custom editors, use pointer you received from wxPropertyGrid::RegisterEditorClass().
1073 */
1074 void SetEditor( const wxPGEditor* editor )
1075 {
1076 m_customEditor = editor;
1077 }
1078
1079 /** Sets editor for a property.
1080 */
1081 inline void SetEditor( const wxString& editorName );
1082
1083 /** Sets cell information for given column.
1084
1085 Note that the property takes ownership of given wxPGCell instance.
1086 */
1087 void SetCell( int column, wxPGCell* cellObj );
1088
1089 /** Changes value of a property with choices, but only
1090 works if the value type is long or string. */
1091 void SetChoiceSelection( int newValue, const wxPGChoiceInfo& choiceInfo );
1092
1093 /** Sets common value selected for this property. -1 for none.
1094 */
1095 void SetCommonValue( int commonValue )
1096 {
1097 m_commonValue = commonValue;
1098 }
1099
1100 /** Sets flags from a '|' delimited string. Note that flag names are not
1101 prepended with 'wxPG_PROP_'.
1102 */
1103 void SetFlagsFromString( const wxString& str );
1104
1105 /** Sets property's "is it modified?" flag. Affects children recursively.
1106 */
1107 void SetModifiedStatus( bool modified )
1108 {
1109 SetFlagRecursively(wxPG_PROP_MODIFIED, modified);
1110 }
1111
1112 /** Call in OnEvent(), OnButtonClick() etc. to change the property value
1113 based on user input.
1114
1115 @remarks
1116 This method is const since it doesn't actually modify value, but posts
1117 given variant as pending value, stored in wxPropertyGrid.
1118 */
1119 void SetValueInEvent( wxVariant value ) const;
1120
1121 /** Call this to set value of the property. Unlike methods in wxPropertyGrid,
1122 this does not automatically update the display.
1123
1124 @remarks
1125 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run through
1126 validation process and send property change event.
1127
1128 If you need to change property value in event, based on user input, use
1129 SetValueInEvent() instead.
1130
1131 @param pList
1132 Pointer to list variant that contains child values. Used to indicate
1133 which children should be marked as modified.
1134 @param flags
1135 Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR).
1136 */
1137 void SetValue( wxVariant value, wxVariant* pList = NULL, int flags = 0 );
1138
1139 /** Set wxBitmap in front of the value. This bitmap may be ignored
1140 by custom cell renderers.
1141 */
1142 void SetValueImage( wxBitmap& bmp );
1143
1144 /** If property has choices and they are not yet exclusive, new such copy
1145 of them will be created.
1146 */
1147 void SetChoicesExclusive();
1148
1149 void SetExpanded( bool expanded )
1150 {
1151 if ( !expanded ) m_flags |= wxPG_PROP_COLLAPSED;
1152 else m_flags &= ~wxPG_PROP_COLLAPSED;
1153 }
1154
1155 void SetFlag( FlagType flag ) { m_flags |= flag; }
1156
1157 void SetFlagRecursively( FlagType flag, bool set );
1158
1159 void SetHelpString( const wxString& helpString )
1160 {
1161 m_helpString = helpString;
1162 }
1163
1164 /** Sets property's label.
1165
1166 @remarks
1167 - Properties under same parent may have same labels. However,
1168 property names must still remain unique.
1169 */
1170 void SetLabel( const wxString& label ) { m_label = label; }
1171
1172 inline void SetName( const wxString& newName );
1173
1174 void SetValueToUnspecified()
1175 {
1176 wxVariant val; // Create NULL variant
1177 SetValue(val);
1178 }
1179
1180 /** Sets wxValidator for a property*/
1181 void SetValidator( const wxValidator& validator )
1182 {
1183 m_validator = wxDynamicCast(validator.Clone(),wxValidator);
1184 }
1185
1186 /** Gets assignable version of property's validator. */
1187 wxValidator* GetValidator() const
1188 {
1189 if ( m_validator )
1190 return m_validator;
1191 return DoGetValidator();
1192 }
1193
1194 /** Updates property value in case there were last minute
1195 changes. If value was unspecified, it will be set to default.
1196 Use only for properties that have TextCtrl-based editor.
1197 @remarks
1198 If you have code similar to
1199 @code
1200 // Update the value in case of last minute changes
1201 if ( primary && propgrid->IsEditorsValueModified() )
1202 GetEditorClass()->CopyValueFromControl( this, primary );
1203 @endcode
1204 in wxPGProperty::OnEvent wxEVT_COMMAND_BUTTON_CLICKED handler,
1205 then replace it with call to this method.
1206 @retval
1207 True if value changed.
1208 */
1209 bool PrepareValueForDialogEditing( wxPropertyGrid* propgrid );
1210
1211 /** Returns client data (void*) of a property.
1212 */
1213 void* GetClientData() const
1214 {
1215 return m_clientData;
1216 }
1217
1218 /** Sets client data (void*) of a property.
1219 @remarks
1220 This untyped client data has to be deleted manually.
1221 */
1222 void SetClientData( void* clientData )
1223 {
1224 m_clientData = clientData;
1225 }
1226
1227 /** Returns client object of a property.
1228 */
1229 void SetClientObject(wxClientData* clientObject)
1230 {
1231 delete m_clientObject;
1232 m_clientObject = clientObject;
1233 }
1234
1235 /** Sets managed client object of a property.
1236 */
1237 wxClientData *GetClientObject() const { return m_clientObject; }
1238
1239 /** Sets new set of choices for property.
1240
1241 @remarks
1242 This operation clears the property value.
1243 */
1244 bool SetChoices( wxPGChoices& choices );
1245
1246 /** Sets new set of choices for property.
1247 */
1248 inline bool SetChoices( const wxArrayString& labels,
1249 const wxArrayInt& values = wxArrayInt() );
1250
1251 /** Set max length of text in text editor.
1252 */
1253 inline bool SetMaxLength( int maxLen );
1254
1255 /** Call with 'false' in OnSetValue to cancel value changes after all
1256 (ie. cancel 'true' returned by StringToValue() or IntToValue()).
1257 */
1258 void SetWasModified( bool set = true )
1259 {
1260 if ( set ) m_flags |= wxPG_PROP_WAS_MODIFIED;
1261 else m_flags &= ~wxPG_PROP_WAS_MODIFIED;
1262 }
1263
1264 const wxString& GetHelpString() const
1265 {
1266 return m_helpString;
1267 }
1268
1269 void ClearFlag( FlagType flag ) { m_flags &= ~(flag); }
1270
1271 // Use, for example, to detect if item is inside collapsed section.
1272 bool IsSomeParent( wxPGProperty* candidate_parent ) const;
1273
1274 /** Adapts list variant into proper value using consequtive ChildChanged-calls.
1275 */
1276 void AdaptListToValue( wxVariant& list, wxVariant* value ) const;
1277
1278 /** This is used by properties that have fixed sub-properties. */
1279 void AddChild( wxPGProperty* prop );
1280
1281 /** Returns height of children, recursively, and
1282 by taking expanded/collapsed status into account.
1283
1284 iMax is used when finding property y-positions.
1285 */
1286 int GetChildrenHeight( int lh, int iMax = -1 ) const;
1287
1288 /** Returns number of child properties */
1289 unsigned int GetChildCount() const { return m_children.GetCount(); }
1290
1291 /** Returns sub-property at index i. */
1292 wxPGProperty* Item( size_t i ) const { return (wxPGProperty*)m_children.Item(i); }
1293
1294 /** Returns last sub-property.
1295 */
1296 wxPGProperty* Last() const { return (wxPGProperty*)m_children.Last(); }
1297
1298 /** Returns index of given sub-property. */
1299 int Index( const wxPGProperty* p ) const { return m_children.Index((wxPGProperty*)p); }
1300
1301 /** Deletes all sub-properties. */
1302 void Empty();
1303
1304 // Puts correct indexes to children
1305 void FixIndexesOfChildren( size_t starthere = 0 );
1306
1307 wxPGProperty* GetItemAtY( unsigned int y, unsigned int lh, unsigned int* nextItemY ) const;
1308
1309 /** Returns (direct) child property with given name (or NULL if not found).
1310 */
1311 wxPGProperty* GetPropertyByName( const wxString& name ) const;
1312 };
1313
1314
1315 /** @class wxPGChoices
1316
1317 Helper class for managing choices of wxPropertyGrid properties.
1318 Each entry can have label, value, bitmap, text colour, and background colour.
1319
1320 @library{wxpropgrid}
1321 @category{propgrid}
1322 */
1323 class WXDLLIMPEXP_PROPGRID wxPGChoices
1324 {
1325 public:
1326 typedef long ValArrItem;
1327
1328 /** Default constructor. */
1329 wxPGChoices()
1330 {
1331 Init();
1332 }
1333
1334 /** Copy constructor. */
1335 wxPGChoices( const wxPGChoices& a )
1336 {
1337 if ( a.m_data != wxPGChoicesEmptyData )
1338 {
1339 m_data = a.m_data;
1340 m_data->m_refCount++;
1341 }
1342 }
1343
1344 /** Constructor. */
1345 wxPGChoices( const wxChar** labels, const long* values = NULL )
1346 {
1347 Init();
1348 Set(labels,values);
1349 }
1350
1351 /** Constructor. */
1352 wxPGChoices( const wxArrayString& labels, const wxArrayInt& values = wxArrayInt() )
1353 {
1354 Init();
1355 Set(labels,values);
1356 }
1357
1358 /** Simple interface constructor. */
1359 wxPGChoices( wxPGChoicesData* data )
1360 {
1361 wxASSERT(data);
1362 m_data = data;
1363 data->m_refCount++;
1364 }
1365
1366 /** Destructor. */
1367 ~wxPGChoices()
1368 {
1369 Free();
1370 }
1371
1372 /** Adds to current. If did not have own copies, creates them now. If was empty,
1373 identical to set except that creates copies.
1374 */
1375 void Add( const wxChar** labels, const ValArrItem* values = NULL );
1376
1377 /** Version that works with wxArrayString. */
1378 void Add( const wxArrayString& arr, const ValArrItem* values = NULL );
1379
1380 /** Version that works with wxArrayString and wxArrayInt. */
1381 void Add( const wxArrayString& arr, const wxArrayInt& arrint );
1382
1383 /** Adds single item. */
1384 wxPGChoiceEntry& Add( const wxString& label, int value = wxPG_INVALID_VALUE );
1385
1386 /** Adds a single item, with bitmap. */
1387 wxPGChoiceEntry& Add( const wxString& label, const wxBitmap& bitmap, int value = wxPG_INVALID_VALUE );
1388
1389 /** Adds a single item with full entry information. */
1390 wxPGChoiceEntry& Add( const wxPGChoiceEntry& entry )
1391 {
1392 return Insert(entry, -1);
1393 }
1394
1395 /** Adds single item. */
1396 wxPGChoiceEntry& AddAsSorted( const wxString& label, int value = wxPG_INVALID_VALUE );
1397
1398 void Assign( const wxPGChoices& a )
1399 {
1400 AssignData(a.m_data);
1401 }
1402
1403 void AssignData( wxPGChoicesData* data );
1404
1405 /** Delete all choices. */
1406 void Clear()
1407 {
1408 if ( m_data != wxPGChoicesEmptyData )
1409 m_data->Clear();
1410 }
1411
1412 void EnsureData()
1413 {
1414 if ( m_data == wxPGChoicesEmptyData )
1415 m_data = new wxPGChoicesData();
1416 }
1417
1418 /** Gets a unsigned number identifying this list. */
1419 wxPGChoicesId GetId() const { return (wxPGChoicesId) m_data; };
1420
1421 const wxString& GetLabel( size_t ind ) const
1422 {
1423 wxASSERT( ind >= 0 && ind < GetCount() );
1424 return Item(ind).GetText();
1425 }
1426
1427 size_t GetCount () const
1428 {
1429 wxASSERT_MSG( m_data,
1430 wxT("When checking if wxPGChoices is valid, use IsOk() instead of GetCount()") );
1431 return m_data->GetCount();
1432 }
1433
1434 int GetValue( size_t ind ) const { return Item(ind).GetValue(); }
1435
1436 /** Returns array of values matching the given strings. Unmatching strings
1437 result in wxPG_INVALID_VALUE entry in array.
1438 */
1439 wxArrayInt GetValuesForStrings( const wxArrayString& strings ) const;
1440
1441 /** Returns array of indices matching given strings. Unmatching strings
1442 are added to 'unmatched', if not NULL.
1443 */
1444 wxArrayInt GetIndicesForStrings( const wxArrayString& strings, wxArrayString* unmatched = NULL ) const;
1445
1446 /** Returns true if choices in general are likely to have values
1447 (depens on that all entries have values or none has)
1448 */
1449 bool HasValues() const;
1450
1451 bool HasValue( unsigned int i ) const { return (m_data->GetCount() > i && m_data->Item(i)->HasValue()); }
1452
1453 int Index( const wxString& str ) const;
1454 int Index( int val ) const;
1455
1456 /** Inserts single item. */
1457 wxPGChoiceEntry& Insert( const wxString& label, int index, int value = wxPG_INVALID_VALUE );
1458
1459 /** Inserts a single item with full entry information. */
1460 wxPGChoiceEntry& Insert( const wxPGChoiceEntry& entry, int index );
1461
1462 /** Returns false if this is a constant empty set of choices,
1463 which should not be modified.
1464 */
1465 bool IsOk() const
1466 {
1467 return ( m_data != wxPGChoicesEmptyData );
1468 }
1469
1470 const wxPGChoiceEntry& Item( unsigned int i ) const
1471 {
1472 wxASSERT( IsOk() );
1473 return *m_data->Item(i);
1474 }
1475
1476 wxPGChoiceEntry& Item( unsigned int i )
1477 {
1478 wxASSERT( IsOk() );
1479 return *m_data->Item(i);
1480 }
1481
1482 /** Removes count items starting at position nIndex. */
1483 void RemoveAt(size_t nIndex, size_t count = 1);
1484
1485 /** Does not create copies for itself. */
1486 void Set( const wxChar** labels, const long* values = NULL )
1487 {
1488 Free();
1489 Add(labels,values);
1490 }
1491
1492 /** Version that works with wxArrayString.
1493 TODO: Deprecate this.
1494 */
1495 void Set( wxArrayString& arr, const long* values = (const long*) NULL )
1496 {
1497 Free();
1498 Add(arr,values);
1499 }
1500
1501 /** Version that works with wxArrayString and wxArrayInt. */
1502 void Set( const wxArrayString& labels, const wxArrayInt& values = wxArrayInt() )
1503 {
1504 Free();
1505 if ( &values )
1506 Add(labels,values);
1507 else
1508 Add(labels);
1509 }
1510
1511 // Creates exclusive copy of current choices
1512 void SetExclusive()
1513 {
1514 if ( m_data->m_refCount != 1 )
1515 {
1516 wxPGChoicesData* data = new wxPGChoicesData();
1517 data->CopyDataFrom(m_data);
1518 Free();
1519 m_data = data;
1520 }
1521 }
1522
1523 // Returns data, increases refcount.
1524 wxPGChoicesData* GetData()
1525 {
1526 wxASSERT( m_data->m_refCount != 0xFFFFFFF );
1527 m_data->m_refCount++;
1528 return m_data;
1529 }
1530
1531 // Returns plain data ptr - no refcounting stuff is done.
1532 wxPGChoicesData* GetDataPtr() const { return m_data; }
1533
1534 // Changes ownership of data to you.
1535 wxPGChoicesData* ExtractData()
1536 {
1537 wxPGChoicesData* data = m_data;
1538 m_data = wxPGChoicesEmptyData;
1539 return data;
1540 }
1541
1542 wxArrayString GetLabels() const;
1543
1544 void operator= (const wxPGChoices& a)
1545 {
1546 AssignData(a.m_data);
1547 }
1548
1549 wxPGChoiceEntry& operator[](unsigned int i)
1550 {
1551 return Item(i);
1552 }
1553
1554 const wxPGChoiceEntry& operator[](unsigned int i) const
1555 {
1556 return Item(i);
1557 }
1558 };
1559
1560 // -----------------------------------------------------------------------