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