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