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