]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/propgrid/property.h
wxPGProperty::GenerateComposedValue() -> protected DoGenerateComposedValue(), added...
[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 wxStringProperty has a special trait: if it has value of
191 "<composed>", and also has child properties, then its displayed
192 value becomes composition of child property values, similar as
193 with wxFontProperty, for instance.
194
195 @subsection wxIntProperty
196
197 Like wxStringProperty, but converts text to a signed long integer.
198 wxIntProperty seamlessly supports 64-bit integers (ie. wxLongLong).
199 To safely convert variant to integer, use code like this:
200
201 @code
202 wxLongLong ll;
203 ll << property->GetValue();
204
205 // or
206 wxLongLong ll = propertyGrid->GetPropertyValueAsLong(property);
207 @endcode
208
209 @subsection wxUIntProperty
210
211 Like wxIntProperty, but displays value as unsigned int. To set
212 the prefix used globally, manipulate wxPG_UINT_PREFIX string attribute.
213 To set the globally used base, manipulate wxPG_UINT_BASE int
214 attribute. Regardless of current prefix, understands (hex) values starting
215 with both "0x" and "$".
216 Like wxIntProperty, wxUIntProperty seamlessly supports 64-bit unsigned
217 integers (ie. wxULongLong). Same wxVariant safety rules apply.
218
219 @subsection wxFloatProperty
220
221 Like wxStringProperty, but converts text to a double-precision floating point.
222 Default float-to-text precision is 6 decimals, but this can be changed
223 by modifying wxPG_FLOAT_PRECISION attribute.
224
225 @subsection wxBoolProperty
226
227 Represents a boolean value. wxChoice is used as editor control, by the
228 default. wxPG_BOOL_USE_CHECKBOX attribute can be set to true inorder to use
229 check box instead.
230
231 @subsection wxLongStringProperty
232
233 Like wxStringProperty, but has a button that triggers a small text editor
234 dialog. Note that in long string values, tabs are represented by "\t" and
235 line break by "\n".
236
237 To display custom dialog on button press, you can subclass
238 wxLongStringProperty and implement OnButtonClick, like this:
239
240 @code
241 virtual bool OnButtonClick( wxPropertyGrid* propGrid, wxString& value )
242 {
243 wxSize dialogSize(...size of your dialog...);
244
245 wxPoint dlgPos = propGrid->GetGoodEditorDialogPosition(this,
246 dialogSize)
247
248 // Create dialog dlg at dlgPos. Use value as initial string
249 // value.
250 ...
251
252 if ( dlg.ShowModal() == wxID_OK )
253 {
254 value = dlg.GetStringValue);
255 return true;
256 }
257 return false;
258 }
259 @endcode
260
261 Also, if you wish not to have line breaks and tabs translated to
262 escape sequences, then do following in constructor of your subclass:
263
264 @code
265 m_flags |= wxPG_PROP_NO_ESCAPE;
266 @endcode
267
268 @subsection wxDirProperty
269
270 Like wxLongStringProperty, but the button triggers dir selector instead.
271 Supported properties (all with string value): wxPG_DIR_DIALOG_MESSAGE.
272
273 @subsection wxFileProperty
274
275 Like wxLongStringProperty, but the button triggers file selector instead.
276 Default wildcard is "All files..." but this can be changed by setting
277 wxPG_FILE_WILDCARD attribute (see wxFileDialog for format details).
278 Attribute wxPG_FILE_SHOW_FULL_PATH can be set to false inorder to show
279 only the filename, not the entire path.
280
281 @subsection wxEnumProperty
282
283 Represents a single selection from a list of choices -
284 wxOwnerDrawnComboBox is used to edit the value.
285
286 @subsection wxFlagsProperty
287
288 Represents a bit set that fits in a long integer. wxBoolProperty sub-properties
289 are created for editing individual bits. Textctrl is created to manually edit
290 the flags as a text; a continous sequence of spaces, commas and semicolons
291 is considered as a flag id separator.
292 <b>Note: </b> When changing "choices" (ie. flag labels) of wxFlagsProperty, you
293 will need to use wxPGProperty::SetChoices() - otherwise they will not get updated
294 properly.
295
296 @subsection wxArrayStringProperty
297
298 Allows editing of a list of strings in wxTextCtrl and in a separate dialog.
299
300 @subsection wxDateProperty
301
302 wxDateTime property. Default editor is DatePickerCtrl, altough TextCtrl
303 should work as well. wxPG_DATE_FORMAT attribute can be used to change
304 string wxDateTime::Format uses (altough default is recommended as it is
305 locale-dependant), and wxPG_DATE_PICKER_STYLE allows changing window
306 style given to DatePickerCtrl (default is wxDP_DEFAULT|wxDP_SHOWCENTURY).
307
308 @subsection wxEditEnumProperty
309
310 Represents a string that can be freely edited or selected from list of choices -
311 custom combobox control is used to edit the value.
312
313 @subsection wxMultiChoiceProperty
314
315 Allows editing a multiple selection from a list of strings. This is
316 property is pretty much built around concept of wxMultiChoiceDialog.
317 It uses wxArrayString value.
318
319 @subsection wxImageFileProperty
320
321 Like wxFileProperty, but has thumbnail of the image in front of
322 the filename and autogenerates wildcard from available image handlers.
323
324 @subsection wxColourProperty
325
326 <b>Useful alternate editor:</b> Choice.
327
328 Represents wxColour. wxButton is used to trigger a colour picker dialog.
329 There are various sub-classing opportunities with this class. See
330 below in wxSystemColourProperty section for details.
331
332 @subsection wxFontProperty
333
334 Represents wxFont. Various sub-properties are used to edit individual
335 subvalues.
336
337 @subsection wxSystemColourProperty
338
339 Represents wxColour and a system colour index. wxChoice is used to edit
340 the value. Drop-down list has color images. Note that value type
341 is wxColourPropertyValue instead of wxColour (which wxColourProperty
342 uses).
343
344 @code
345 class wxColourPropertyValue : public wxObject
346 {
347 public:
348 // An integer value relating to the colour, and which exact
349 // meaning depends on the property with which it is used.
350 //
351 // For wxSystemColourProperty:
352 // Any of wxSYS_COLOUR_XXX, or any web-colour ( use wxPG_TO_WEB_COLOUR
353 // macro - (currently unsupported) ), or wxPG_COLOUR_CUSTOM.
354 wxUint32 m_type;
355
356 // Resulting colour. Should be correct regardless of type.
357 wxColour m_colour;
358 };
359 @endcode
360
361 in wxSystemColourProperty, and its derived class wxColourProperty, there
362 are various sub-classing features. To set basic list list of colour
363 names, call wxPGProperty::SetChoices().
364
365 @code
366 // Override in derived class to customize how colours are translated
367 // to strings.
368 virtual wxString ColourToString( const wxColour& col, int index ) const;
369
370 // Returns index of entry that triggers colour picker dialog
371 // (default is last).
372 virtual int GetCustomColourIndex() const;
373
374 // Helper function to show the colour dialog
375 bool QueryColourFromUser( wxVariant& variant ) const;
376
377 // Returns colour for given choice.
378 // Default function returns wxSystemSettings::GetColour(index).
379 virtual wxColour GetColour( int index ) const;
380 @endcode
381
382 @subsection wxCursorProperty
383
384 Represents a wxCursor. wxChoice is used to edit the value.
385 Drop-down list has cursor images under some (wxMSW) platforms.
386
387
388 @section pgproperty_creating Creating Custom Properties
389
390 New properties can be created by subclassing wxPGProperty or one
391 of the provided property classes, and (re)implementing necessary
392 member functions. Below, each virtual member function has ample
393 documentation about its purpose and any odd details which to keep
394 in mind.
395
396 Here is a very simple 'template' code:
397
398 @code
399 class MyProperty : public wxPGProperty
400 {
401 public:
402 // All arguments of ctor must have a default value -
403 // use wxPG_LABEL for label and name
404 MyProperty( const wxString& label = wxPG_LABEL,
405 const wxString& name = wxPG_LABEL,
406 const wxString& value = wxEmptyString )
407 {
408 // m_value is wxVariant
409 m_value = value;
410 }
411
412 virtual ~MyProperty() { }
413
414 const wxPGEditor* DoGetEditorClass() const
415 {
416 // Determines editor used by property.
417 // You can replace 'TextCtrl' below with any of these
418 // builtin-in property editor identifiers: Choice, ComboBox,
419 // TextCtrlAndButton, ChoiceAndButton, CheckBox, SpinCtrl,
420 // DatePickerCtrl.
421 return wxPGEditor_TextCtrl;
422 }
423
424 virtual wxString ValueToString( wxVariant& value,
425 int argFlags ) const
426 {
427 // TODO: Convert given property value to a string
428 }
429
430 virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags )
431 {
432 // TODO: Adapt string to property value.
433 }
434
435 protected:
436 };
437 @endcode
438
439 Since wxPGProperty derives from wxObject, you can use standard
440 DECLARE_DYNAMIC_CLASS and IMPLEMENT_DYNAMIC_CLASS macros. From the
441 above example they were omitted for sake of simplicity, and besides,
442 they are only really needed if you need to use wxRTTI with your
443 property class.
444
445 You can change the 'value type' of a property by simply assigning different
446 type of variant with SetValue. <b>It is mandatory to implement
447 wxVariantData class for all data types used as property values.</b>
448 You can use macros declared in wxPropertyGrid headers. For instance:
449
450 @code
451 // In header file:
452 // (If you need to have export declaration, use version of macros
453 // with _EXPORTED postfix)
454 WX_PG_DECLARE_VARIANT_DATA(MyDataClass)
455
456 // In sources file:
457 WX_PG_IMPLEMENT_VARIANT_DATA(MyDataClass)
458
459 // Or, if you don't have valid == operator:
460 WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(MyDataClass)
461 @endcode
462
463 @library{wxpropgrid}
464 @category{propgrid}
465 */
466 class wxPGProperty : public wxObject
467 {
468 public:
469 typedef wxUint32 FlagType;
470
471 /**
472 Default constructor.
473 */
474 wxPGProperty();
475
476 /**
477 Constructor.
478 Non-abstract property classes should have constructor of this style:
479
480 @code
481
482 MyProperty( const wxString& label, const wxString& name, const T& value )
483 : wxPGProperty()
484 {
485 // Generally recommended way to set the initial value
486 // (as it should work in pretty much 100% of cases).
487 wxVariant variant;
488 variant << value;
489 SetValue(variant);
490
491 // If has private child properties then create them here. For example:
492 // AddChild( new wxStringProperty( "Subprop 1", wxPG_LABEL, value.GetSubProp1() ) );
493 }
494
495 @endcode
496 */
497 wxPGProperty( const wxString& label, const wxString& name );
498
499 /**
500 Virtual destructor. It is customary for derived properties to implement this.
501 */
502 virtual ~wxPGProperty();
503
504 /**
505 This virtual function is called after m_value has been set.
506
507 @remarks
508 - If m_value was set to Null variant (ie. unspecified value), OnSetValue()
509 will not be called.
510 - m_value may be of any variant type. Typically properties internally support only
511 one variant type, and as such OnSetValue() provides a good opportunity to convert
512 supported values into internal type.
513 - Default implementation does nothing.
514 */
515 virtual void OnSetValue();
516
517 /**
518 Override this to return something else than m_value as the value.
519 */
520 virtual wxVariant DoGetValue() const { return m_value; }
521
522 /**
523 Implement this function in derived class to check the value.
524 Return true if it is ok. Returning false prevents property change events
525 from occurring.
526
527 @remarks
528 - Default implementation always returns true.
529 */
530 virtual bool ValidateValue( wxVariant& value, wxPGValidationInfo& validationInfo ) const;
531
532 /**
533 Converts text into wxVariant value appropriate for this property.
534
535 @param variant
536 On function entry this is the old value (should not be wxNullVariant
537 in normal cases). Translated value must be assigned back to it.
538
539 @param text
540 Text to be translated into variant.
541
542 @param argFlags
543 If wxPG_FULL_VALUE is set, returns complete, storable value instead
544 of displayable one (they may be different).
545 If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of
546 composite property string value (as generated by ValueToString()
547 called with this same flag).
548
549 @return Returns @true if resulting wxVariant value was different.
550
551 @remarks Default implementation converts semicolon delimited tokens into
552 child values. Only works for properties with children.
553
554 You might want to take into account that m_value is Null variant
555 if property value is unspecified (which is usually only case if
556 you explicitly enabled that sort behavior).
557 */
558 virtual bool StringToValue( wxVariant& variant, const wxString& text, int argFlags = 0 ) const;
559
560 /**
561 Converts integer (possibly a choice selection) into wxVariant value
562 appropriate for this property.
563
564 @param variant
565 On function entry this is the old value (should not be wxNullVariant
566 in normal cases). Translated value must be assigned back to it.
567
568 @param number
569 Integer to be translated into variant.
570
571 @param argFlags
572 If wxPG_FULL_VALUE is set, returns complete, storable value instead
573 of displayable one.
574
575 @return Returns @true if resulting wxVariant value was different.
576
577 @remarks
578 - If property is not supposed to use choice or spinctrl or other editor
579 with int-based value, it is not necessary to implement this method.
580 - Default implementation simply assign given int to m_value.
581 - If property uses choice control, and displays a dialog on some choice
582 items, then it is preferred to display that dialog in IntToValue
583 instead of OnEvent.
584 - You might want to take into account that m_value is Null variant if
585 property value is unspecified (which is usually only case if you
586 explicitly enabled that sort behavior).
587 */
588 virtual bool IntToValue( wxVariant& value, int number, int argFlags = 0 ) const;
589
590 /**
591 Converts property value into a text representation.
592
593 @param value
594 Value to be converted.
595
596 @param argFlags
597 If 0 (default value), then displayed string is returned.
598 If wxPG_FULL_VALUE is set, returns complete, storable string value
599 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
600 string value that must be editable in textctrl. If
601 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
602 display as a part of string property's composite text
603 representation.
604
605 @remarks Default implementation calls GenerateComposedValue().
606 */
607 virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
608
609 /**
610 Converts string to a value, and if successful, calls SetValue() on it.
611 Default behavior is to do nothing.
612 @param text
613 String to get the value from.
614 @retval
615 true if value was changed.
616 */
617 bool SetValueFromString( const wxString& text, int flags = 0 );
618
619 /**
620 Converts integer to a value, and if succesful, calls SetValue() on it.
621 Default behavior is to do nothing.
622 @param value
623 Int to get the value from.
624 @param flags
625 If has wxPG_FULL_VALUE, then the value given is a actual value and not an index.
626 @retval
627 True if value was changed.
628 */
629 bool SetValueFromInt( long value, int flags = 0 );
630
631 /**
632 Returns size of the custom painted image in front of property. This method
633 must be overridden to return non-default value if OnCustomPaint is to be
634 called.
635 @param item
636 Normally -1, but can be an index to the property's list of items.
637 @remarks
638 - Default behavior is to return wxSize(0,0), which means no image.
639 - Default image width or height is indicated with dimension -1.
640 - You can also return wxPG_DEFAULT_IMAGE_SIZE which equals wxSize(-1, -1).
641 */
642 virtual wxSize OnMeasureImage( int item = -1 ) const;
643
644 /**
645 Events received by editor widgets are processed here. Note that editor class
646 usually processes most events. Some, such as button press events of
647 TextCtrlAndButton class, can be handled here. Also, if custom handling
648 for regular events is desired, then that can also be done (for example,
649 wxSystemColourProperty custom handles wxEVT_COMMAND_CHOICE_SELECTED
650 to display colour picker dialog when 'custom' selection is made).
651
652 If the event causes value to be changed, SetValueInEvent()
653 should be called to set the new value.
654
655 @param event
656 Associated wxEvent.
657 @retval
658 Should return true if any changes in value should be reported.
659 @remarks
660 - If property uses choice control, and displays a dialog on some choice items,
661 then it is preferred to display that dialog in IntToValue instead of OnEvent.
662 */
663 virtual bool OnEvent( wxPropertyGrid* propgrid, wxWindow* wnd_primary, wxEvent& event );
664
665 /**
666 Called after value of a child property has been altered. Note that this function is
667 usually called at the time that value of this property, or given child property, is
668 still pending for change.
669
670 Sample pseudo-code implementation:
671
672 @code
673 void MyProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const
674 {
675 // Acquire reference to actual type of data stored in variant
676 // (TFromVariant only exists if wxPropertyGrid's wxVariant-macros were used to create
677 // the variant class).
678 T& data = TFromVariant(thisValue);
679
680 // Copy childValue into data.
681 switch ( childIndex )
682 {
683 case 0:
684 data.SetSubProp1( childvalue.GetLong() );
685 break;
686 case 1:
687 data.SetSubProp2( childvalue.GetString() );
688 break;
689 ...
690 }
691 }
692 @endcode
693
694 @param thisValue
695 Value of this property, that should be altered.
696 @param childIndex
697 Index of child changed (you can use Item(childIndex) to get).
698 @param childValue
699 Value of the child property.
700 */
701 virtual void ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const;
702
703 /**
704 Returns pointer to an instance of used editor.
705 */
706 virtual const wxPGEditor* DoGetEditorClass() const;
707
708 /**
709 Returns pointer to the wxValidator that should be used
710 with the editor of this property (NULL for no validator).
711 Setting validator explicitly via SetPropertyValidator
712 will override this.
713
714 In most situations, code like this should work well
715 (macros are used to maintain one actual validator instance,
716 so on the second call the function exits within the first
717 macro):
718
719 @code
720
721 wxValidator* wxMyPropertyClass::DoGetValidator () const
722 {
723 WX_PG_DOGETVALIDATOR_ENTRY()
724
725 wxMyValidator* validator = new wxMyValidator(...);
726
727 ... prepare validator...
728
729 WX_PG_DOGETVALIDATOR_EXIT(validator)
730 }
731
732 @endcode
733
734 @remarks
735 You can get common filename validator by returning
736 wxFileProperty::GetClassValidator(). wxDirProperty,
737 for example, uses it.
738 */
739 virtual wxValidator* DoGetValidator () const;
740
741 /**
742 Override to paint an image in front of the property value text or drop-down
743 list item (but only if wxPGProperty::OnMeasureImage is overridden as well).
744
745 If property's OnMeasureImage() returns size that has height != 0 but less than
746 row height ( < 0 has special meanings), wxPropertyGrid calls this method to
747 draw a custom image in a limited area in front of the editor control or
748 value text/graphics, and if control has drop-down list, then the image is
749 drawn there as well (even in the case OnMeasureImage() returned higher height
750 than row height).
751
752 NOTE: Following applies when OnMeasureImage() returns a "flexible" height (
753 using wxPG_FLEXIBLE_SIZE(W,H) macro), which implies variable height items:
754 If rect.x is < 0, then this is a measure item call, which means that
755 dc is invalid and only thing that should be done is to set paintdata.m_drawnHeight
756 to the height of the image of item at index paintdata.m_choiceItem. This call
757 may be done even as often as once every drop-down popup show.
758
759 @param dc
760 wxDC to paint on.
761 @param rect
762 Box reserved for custom graphics. Includes surrounding rectangle, if any.
763 If x is < 0, then this is a measure item call (see above).
764 @param paintdata
765 wxPGPaintData structure with much useful data about painted item.
766 @code
767 struct wxPGPaintData
768 {
769 // wxPropertyGrid.
770 const wxPropertyGrid* m_parent;
771
772 // Normally -1, otherwise index to drop-down list item that has to be drawn.
773 int m_choiceItem;
774
775 // Set to drawn width in OnCustomPaint (optional).
776 int m_drawnWidth;
777
778 // In a measure item call, set this to the height of item at m_choiceItem index
779 int m_drawnHeight;
780 };
781 @endcode
782
783 @remarks
784 - You can actually exceed rect width, but if you do so then paintdata.m_drawnWidth
785 must be set to the full width drawn in pixels.
786 - Due to technical reasons, rect's height will be default even if custom height
787 was reported during measure call.
788 - Brush is guaranteed to be default background colour. It has been already used to
789 clear the background of area being painted. It can be modified.
790 - Pen is guaranteed to be 1-wide 'black' (or whatever is the proper colour) pen for
791 drawing framing rectangle. It can be changed as well.
792
793 @see ValueToString()
794 */
795 virtual void OnCustomPaint( wxDC& dc, const wxRect& rect, wxPGPaintData& paintdata );
796
797 /**
798 Returns used wxPGCellRenderer instance for given property column (label=0, value=1).
799
800 Default implementation returns editor's renderer for all columns.
801 */
802 virtual wxPGCellRenderer* GetCellRenderer( int column ) const;
803
804 /**
805 Returns which choice is currently selected. Only applies to properties
806 which have choices.
807
808 Needs to reimplemented in derived class if property value does not
809 map directly to a choice. Integer as index, bool, and string usually do.
810 */
811 virtual int GetChoiceSelection() const;
812
813 /**
814 Refresh values of child properties. Automatically called after value is set.
815 */
816 virtual void RefreshChildren();
817
818 /**
819 Special handling for attributes of this property.
820
821 If returns false, then the attribute will be automatically stored in
822 m_attributes.
823
824 Default implementation simply returns false.
825 */
826 virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
827
828 /**
829 Returns value of an attribute.
830
831 Override if custom handling of attributes is needed.
832
833 Default implementation simply return NULL variant.
834 */
835 virtual wxVariant DoGetAttribute( const wxString& name ) const;
836
837 /**
838 Returns instance of a new wxPGEditorDialogAdapter instance, which is
839 used when user presses the (optional) button next to the editor control;
840
841 Default implementation returns NULL (ie. no action is generated when
842 button is pressed).
843 */
844 virtual wxPGEditorDialogAdapter* GetEditorDialog() const;
845
846 /**
847 Returns wxPGCell of given column, NULL if none. If valid
848 object is returned, caller will gain its ownership.
849 */
850 wxPGCell* AcquireCell( unsigned int column )
851 {
852 if ( column >= m_cells.size() )
853 return NULL;
854
855 wxPGCell* cell = (wxPGCell*) m_cells[column];
856 m_cells[column] = NULL;
857 return cell;
858 }
859
860 /**
861 Append a new choice to property's list of choices.
862
863 @param label
864 Label for added choice.
865
866 @param value
867 Value for new choice. Do not specify if you wish this
868 to equal choice index.
869
870 @return
871 Index to added choice.
872 */
873 int AddChoice( const wxString& label, int value = wxPG_INVALID_VALUE );
874
875 /**
876 Adds a child property. If you use this instead of
877 wxPropertyGridInterface::Insert() or
878 wxPropertyGridInterface::AppendIn(), then you must set up
879 property's parental type before making the call. To do this,
880 call property's SetParentalType() function with either
881 wxPG_PROP_MISC_PARENT (normal, public children) or with
882 wxPG_PROP_AGGREGATE (private children for subclassed property).
883 For instance:
884
885 @code
886 wxPGProperty* prop = new wxStringProperty(wxS("Property"));
887 prop->SetParentalType(wxPG_PROP_MISC_PARENT);
888 wxPGProperty* prop2 = new wxStringProperty(wxS("Property2"));
889 prop->AddChild(prop2);
890 @endcode
891 */
892 void AddChild( wxPGProperty* property );
893
894 /**
895 Adapts list variant into proper value using consecutive
896 ChildChanged() calls.
897 */
898 void AdaptListToValue( wxVariant& list, wxVariant* value ) const;
899
900 /**
901 Determines, recursively, if all children are not unspecified.
902
903 @param pendingList
904 Assumes members in this wxVariant list as pending
905 replacement values.
906 */
907 bool AreAllChildrenSpecified( wxVariant* pendingList = NULL ) const;
908
909 /**
910 Returns true if children of this property are component values (for instance,
911 points size, face name, and is_underlined are component values of a font).
912 */
913 bool AreChildrenComponents() const
914 {
915 if ( m_flags & (wxPG_PROP_COMPOSED_VALUE|wxPG_PROP_AGGREGATE) )
916 return true;
917
918 return false;
919 }
920
921 /**
922 Removes entry from property's wxPGChoices and editor control (if it is active).
923
924 If selected item is deleted, then the value is set to unspecified.
925 */
926 void DeleteChoice( int index );
927
928 /** Deletes all child properties. */
929 void Empty();
930
931 /**
932 Composes text from values of child properties.
933 */
934 wxString GenerateComposedValue() const;
935
936 /**
937 Returns property attribute value, null variant if not found.
938 */
939 wxVariant GetAttribute( const wxString& name ) const;
940
941 /** Returns named attribute, as string, if found. Otherwise defVal is returned.
942 */
943 wxString GetAttribute( const wxString& name, const wxString& defVal ) const;
944
945 /** Returns named attribute, as long, if found. Otherwise defVal is returned.
946 */
947 long GetAttributeAsLong( const wxString& name, long defVal ) const;
948
949 /** Returns named attribute, as double, if found. Otherwise defVal is returned.
950 */
951 double GetAttributeAsDouble( const wxString& name, double defVal ) const;
952
953 /**
954 Returns attributes as list wxVariant.
955 */
956 wxVariant GetAttributesAsList() const;
957
958 /**
959 Returns editor used for given column. NULL for no editor.
960 */
961 const wxPGEditor* GetColumnEditor( int column ) const
962 {
963 if ( column == 1 )
964 return GetEditorClass();
965
966 return NULL;
967 }
968
969 /** Returns property's base name (ie. parent's name is not added in any case) */
970 const wxString& GetBaseName() const { return m_name; }
971
972 /**
973 Returns wxPGCell of given column, NULL if none. wxPGProperty
974 will retain ownership of the cell object.
975 */
976 wxPGCell* GetCell( unsigned int column ) const
977 {
978 if ( column >= m_cells.size() )
979 return NULL;
980
981 return (wxPGCell*) m_cells[column];
982 }
983
984 /**
985 Returns number of child properties.
986 */
987 unsigned int GetChildCount() const;
988
989 /**
990 Returns height of children, recursively, and
991 by taking expanded/collapsed status into account.
992
993 @param lh
994 Line height. Pass result of GetGrid()->GetRowHeight() here.
995
996 @param iMax
997 Only used (internally) when finding property y-positions.
998 */
999 int GetChildrenHeight( int lh, int iMax = -1 ) const;
1000
1001 /**
1002 Returns read-only reference to property's list of choices.
1003 */
1004 const wxPGChoices& GetChoices() const;
1005
1006 /**
1007 Returns client data (void*) of a property.
1008 */
1009 void* GetClientData() const;
1010
1011 /** Sets managed client object of a property.
1012 */
1013 wxClientData *GetClientObject() const;
1014
1015 /**
1016 Returns property's default value. If property's value type is not
1017 a built-in one, and "DefaultValue" attribute is not defined, then
1018 this function usually returns Null variant.
1019 */
1020 wxVariant GetDefaultValue() const;
1021
1022 /** Returns property's displayed text.
1023 */
1024 wxString GetDisplayedString() const
1025 {
1026 return GetValueString(0);
1027 }
1028
1029 /**
1030 Returns wxPGEditor that will be used and created when
1031 property becomes selected. Returns more accurate value
1032 than DoGetEditorClass().
1033 */
1034 const wxPGEditor* GetEditorClass() const;
1035
1036 /** Returns property grid where property lies. */
1037 wxPropertyGrid* GetGrid() const;
1038
1039 /**
1040 Returns owner wxPropertyGrid, but only if one is currently on a page
1041 displaying this property.
1042 */
1043 wxPropertyGrid* GetGridIfDisplayed() const;
1044
1045 /**
1046 Returns property's help or description text.
1047
1048 @see SetHelpString()
1049 */
1050 const wxString& GetHelpString() const;
1051
1052 /**
1053 Returns position in parent's array.
1054 */
1055 unsigned int GetIndexInParent() const;
1056
1057 /** Returns property's label. */
1058 const wxString& GetLabel() const { return m_label; }
1059
1060 /**
1061 Returns last visible child property, recursively.
1062 */
1063 const wxPGProperty* GetLastVisibleSubItem() const;
1064
1065 /**
1066 Returns highest level non-category, non-root parent. Useful when you
1067 have nested properties with children.
1068
1069 @remarks If immediate parent is root or category, this will return the
1070 property itself.
1071 */
1072 wxPGProperty* GetMainParent() const;
1073
1074 /** Returns maximum allowed length of property's text value.
1075 */
1076 int GetMaxLength() const
1077 {
1078 return (int) m_maxLen;
1079 }
1080
1081 /** Returns property's name with all (non-category, non-root) parents. */
1082 wxString GetName() const;
1083
1084 /** Return parent of property */
1085 wxPGProperty* GetParent() const { return m_parent; }
1086
1087 /**
1088 Returns (direct) child property with given name (or NULL if not found).
1089 */
1090 wxPGProperty* GetPropertyByName( const wxString& name ) const;
1091
1092 /** Gets assignable version of property's validator. */
1093 wxValidator* GetValidator() const;
1094
1095 /**
1096 Returns property's value.
1097 */
1098 wxVariant GetValue() const
1099 {
1100 return DoGetValue();
1101 }
1102
1103 /**
1104 Returns bitmap that appears next to value text. Only returns non-NULL
1105 bitmap if one was set with SetValueImage().
1106 */
1107 wxBitmap* GetValueImage() const;
1108
1109 /** Returns text representation of property's value.
1110
1111 @param argFlags
1112 If 0 (default value), then displayed string is returned.
1113 If wxPG_FULL_VALUE is set, returns complete, storable string value
1114 instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
1115 string value that must be editable in textctrl. If
1116 wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
1117 display as a part of string property's composite text
1118 representation.
1119
1120 @remarks In older versions, this function used to be overridden to convert
1121 property's value into a string representation. This function is
1122 now handled by ValueToString(), and overriding this function now
1123 will result in run-time assertion failure.
1124 */
1125 virtual wxString GetValueAsString( int argFlags = 0 ) const;
1126
1127 /** Synonymous to GetValueAsString().
1128
1129 @deprecated Use GetValueAsString() instead.
1130
1131 @see GetValueAsString()
1132 */
1133 wxDEPRECATED( wxString GetValueString( int argFlags = 0 ) const );
1134
1135 /**
1136 Returns value type used by this property.
1137 */
1138 wxString GetValueType() const
1139 {
1140 return m_value.GetType();
1141 }
1142
1143 /**
1144 Returns coordinate to the top y of the property. Note that the
1145 position of scrollbars is not taken into account.
1146 */
1147 int GetY() const;
1148
1149 /**
1150 Returns true if property has even one visible child.
1151 */
1152 bool HasVisibleChildren() const;
1153
1154 /**
1155 Hides or reveals the property.
1156
1157 @param hide
1158 @true for hide, @false for reveal.
1159
1160 @param flags
1161 By default changes are applied recursively. Set this parameter wxPG_DONT_RECURSE to prevent this.
1162 */
1163 bool Hide( bool hide, int flags = wxPG_RECURSE );
1164
1165 /**
1166 Returns index of given child property. wxNOT_FOUND if
1167 given property is not child of this.
1168 */
1169 int Index( const wxPGProperty* p ) const;
1170
1171 /**
1172 Inserts a new choice to property's list of choices.
1173
1174 @param label
1175 Text for new choice
1176
1177 @param index
1178 Insertion position. Use wxNOT_FOUND to append.
1179
1180 @param value
1181 Value for new choice. Do not specify if you wish this
1182 to equal choice index.
1183 */
1184 int InsertChoice( const wxString& label, int index, int value = wxPG_INVALID_VALUE );
1185
1186 /**
1187 Returns @true if this property is actually a wxPropertyCategory.
1188 */
1189 bool IsCategory() const;
1190
1191 /**
1192 Returns @true if property is enabled.
1193 */
1194 bool IsEnabled() const;
1195
1196 /**
1197 Returns @true if property has visible children.
1198 */
1199 bool IsExpanded() const;
1200
1201 /**
1202 Returns @true if this property is actually a wxRootProperty.
1203 */
1204 bool IsRoot() const { return (m_parent == NULL); }
1205
1206 /**
1207 Returns @true if candidateParent is some parent of this property.
1208 */
1209 bool IsSomeParent( wxPGProperty* candidateParent ) const;
1210
1211 /**
1212 Returns true if property has editable wxTextCtrl when selected.
1213
1214 @remarks Altough disabled properties do not displayed editor, they still
1215 return @true here as being disabled is considered a temporary
1216 condition (unlike being read-only or having limited editing enabled).
1217 */
1218 bool IsTextEditable() const;
1219
1220 /**
1221 Returns @true if property's value is considered unspecified. This
1222 usually means that value is Null variant.
1223 */
1224 bool IsValueUnspecified() const;
1225
1226 /**
1227 Returns true if all parents expanded.
1228 */
1229 bool IsVisible() const;
1230
1231 /**
1232 Returns child property at index i.
1233 */
1234 wxPGProperty* Item( unsigned int i ) const;
1235
1236 /**
1237 If property's editor is active, then update it's value.
1238 */
1239 void RefreshEditor();
1240
1241 /**
1242 Sets an attribute for this property.
1243
1244 @param name
1245 Text identifier of attribute. See @ref propgrid_property_attributes.
1246
1247 @param value
1248 Value of attribute.
1249
1250 @remarks Setting attribute's value to Null variant will simply remove it
1251 from property's set of attributes.
1252 */
1253 void SetAttribute( const wxString& name, wxVariant value );
1254
1255 /**
1256 Sets editor for a property.
1257
1258 @param editor
1259 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1260 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full list).
1261
1262 For custom editors, use pointer you received from wxPropertyGrid::RegisterEditorClass().
1263 */
1264 void SetEditor( const wxPGEditor* editor );
1265
1266 /**
1267 Sets editor for a property, by editor name.
1268 */
1269 void SetEditor( const wxString& editorName );
1270
1271 /**
1272 Sets cell information for given column.
1273
1274 Note that the property takes ownership of given wxPGCell instance.
1275 */
1276 void SetCell( int column, wxPGCell* cellObj );
1277
1278 /**
1279 Sets new set of choices for property.
1280
1281 @remarks This operation clears the property value.
1282 */
1283 bool SetChoices( wxPGChoices& choices );
1284
1285 /**
1286 If property has choices and they are not yet exclusive, new such copy
1287 of them will be created.
1288 */
1289 void SetChoicesExclusive();
1290
1291 /**
1292 Sets client data (void*) of a property.
1293
1294 @remarks This untyped client data has to be deleted manually.
1295 */
1296 void SetClientData( void* clientData );
1297
1298 /** Returns client object of a property.
1299 */
1300 void SetClientObject(wxClientData* clientObject);
1301
1302 /**
1303 Sets selected choice and changes property value.
1304
1305 Tries to retain value type, although currently if it is not string,
1306 then it is forced to integer.
1307 */
1308 void SetChoiceSelection( int newValue );
1309
1310 /**
1311 Sets property's help string, which is shown, for example, in
1312 wxPropertyGridManager's description text box.
1313 */
1314 void SetHelpString( const wxString& helpString );
1315
1316 /**
1317 Sets property's label.
1318
1319 @remarks Properties under same parent may have same labels. However,
1320 property names must still remain unique.
1321 */
1322 void SetLabel( const wxString& label ) { m_label = label; }
1323
1324 /**
1325 Set max length of text in text editor.
1326 */
1327 bool SetMaxLength( int maxLen );
1328
1329 /**
1330 Sets property's "is it modified?" flag. Affects children recursively.
1331 */
1332 void SetModifiedStatus( bool modified );
1333
1334 /**
1335 Sets new (base) name for property.
1336 */
1337 void SetName( const wxString& newName );
1338
1339 /**
1340 Changes what sort of parent this property is for its children.
1341
1342 @param flag
1343 Use one of the following values: wxPG_PROP_MISC_PARENT (for generic
1344 parents), wxPG_PROP_CATEGORY (for categories), or
1345 wxPG_PROP_AGGREGATE (for derived property classes with private
1346 children).
1347
1348 @remarks You only need to call this if you use AddChild() to add
1349 child properties. Adding properties with
1350 wxPropertyGridInterface::Insert() or
1351 wxPropertyGridInterface::AppendIn() will automatically set
1352 property to use wxPG_PROP_MISC_PARENT style.
1353 */
1354 void SetParentalType( int flag );
1355
1356 /** Sets wxValidator for a property */
1357 void SetValidator( const wxValidator& validator );
1358
1359 /**
1360 Call this to set value of the property. Unlike methods in wxPropertyGrid,
1361 this does not automatically update the display.
1362
1363 @remarks
1364 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run through
1365 validation process and send property change event.
1366
1367 If you need to change property value in event, based on user input, use
1368 SetValueInEvent() instead.
1369
1370 @param pList
1371 Pointer to list variant that contains child values. Used to indicate
1372 which children should be marked as modified. Usually you just use NULL.
1373
1374 @param flags
1375 Use wxPG_SETVAL_REFRESH_EDITOR to update editor control, if it
1376 was selected.
1377 */
1378 void SetValue( wxVariant value, wxVariant* pList = NULL, int flags = 0 );
1379
1380 /**
1381 Set wxBitmap in front of the value. This bitmap may be ignored
1382 by custom cell renderers.
1383 */
1384 void SetValueImage( wxBitmap& bmp );
1385
1386 /**
1387 Call this function in OnEvent(), OnButtonClick() etc. to change the
1388 property value based on user input.
1389
1390 @remarks This method is const since it doesn't actually modify value, but posts
1391 given variant as pending value, stored in wxPropertyGrid.
1392 */
1393 void SetValueInEvent( wxVariant value ) const;
1394
1395 /**
1396 Sets property's value to unspecified (ie. Null variant).
1397 */
1398 void SetValueToUnspecified();
1399
1400 /**
1401 Call with @false in OnSetValue() to cancel value changes after all
1402 (ie. cancel @true returned by StringToValue() or IntToValue()).
1403 */
1404 void SetWasModified( bool set = true );
1405
1406 /**
1407 Updates composed values of parent non-category properties, recursively.
1408 Returns topmost property updated.
1409 */
1410 wxPGProperty* UpdateParentValues();
1411
1412 /**
1413 Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
1414 */
1415 bool UsesAutoUnspecified() const;
1416 };
1417
1418
1419 /** @class wxPGChoices
1420
1421 Helper class for managing choices of wxPropertyGrid properties.
1422 Each entry can have label, value, bitmap, text colour, and background colour.
1423
1424 @library{wxpropgrid}
1425 @category{propgrid}
1426 */
1427 class WXDLLIMPEXP_PROPGRID wxPGChoices
1428 {
1429 public:
1430 typedef long ValArrItem;
1431
1432 /**
1433 Default constructor.
1434 */
1435 wxPGChoices();
1436
1437 /** Copy constructor. */
1438 wxPGChoices( const wxPGChoices& a );
1439
1440 /** Constructor. */
1441 wxPGChoices( const wxChar** labels, const long* values = NULL );
1442
1443 /** Constructor. */
1444 wxPGChoices( const wxArrayString& labels, const wxArrayInt& values = wxArrayInt() );
1445
1446 /** Constructor. */
1447 wxPGChoices( wxPGChoicesData* data );
1448
1449 /** Destructor. */
1450 ~wxPGChoices();
1451
1452 /**
1453 Adds to current. If did not have own copies, creates them now. If was empty,
1454 identical to set except that creates copies.
1455 */
1456 void Add( const wxChar** labels, const ValArrItem* values = NULL );
1457
1458 /** Version that works with wxArrayString. */
1459 void Add( const wxArrayString& arr, const ValArrItem* values = NULL );
1460
1461 /** Version that works with wxArrayString and wxArrayInt. */
1462 void Add( const wxArrayString& arr, const wxArrayInt& arrint );
1463
1464 /** Adds single item. */
1465 wxPGChoiceEntry& Add( const wxString& label, int value = wxPG_INVALID_VALUE );
1466
1467 /** Adds a single item, with bitmap. */
1468 wxPGChoiceEntry& Add( const wxString& label, const wxBitmap& bitmap,
1469 int value = wxPG_INVALID_VALUE );
1470
1471 /** Adds a single item with full entry information. */
1472 wxPGChoiceEntry& Add( const wxPGChoiceEntry& entry )
1473 {
1474 return Insert(entry, -1);
1475 }
1476
1477 /** Adds single item, sorted. */
1478 wxPGChoiceEntry& AddAsSorted( const wxString& label, int value = wxPG_INVALID_VALUE );
1479
1480 /**
1481 Assigns data from another set of choices.
1482 */
1483 void Assign( const wxPGChoices& a )
1484 {
1485 AssignData(a.m_data);
1486 }
1487
1488 /**
1489 Assigns data from another set of choices.
1490 */
1491 void AssignData( wxPGChoicesData* data );
1492
1493 /**
1494 Deletes all items.
1495 */
1496 void Clear()
1497 {
1498 if ( m_data != wxPGChoicesEmptyData )
1499 m_data->Clear();
1500 }
1501
1502 /**
1503 Returns labe of item.
1504 */
1505 const wxString& GetLabel( unsigned int ind ) const;
1506
1507 /**
1508 Returns number of items.
1509 */
1510 unsigned int GetCount() const;
1511
1512 /**
1513 Returns value of item;
1514 */
1515 int GetValue( unsigned int ind ) const;
1516
1517 /**
1518 Returns array of values matching the given strings. Unmatching strings
1519 result in wxPG_INVALID_VALUE entry in array.
1520 */
1521 wxArrayInt GetValuesForStrings( const wxArrayString& strings ) const;
1522
1523 /**
1524 Returns array of indices matching given strings. Unmatching strings
1525 are added to 'unmatched', if not NULL.
1526 */
1527 wxArrayInt GetIndicesForStrings( const wxArrayString& strings,
1528 wxArrayString* unmatched = NULL ) const;
1529
1530 /**
1531 Returns @true if item at given index has a valid value;
1532 */
1533 bool HasValue( unsigned int i ) const;
1534
1535 /**
1536 Returns index of item with given label.
1537 */
1538 int Index( const wxString& label ) const;
1539
1540 /**
1541 Returns index of item with given value.
1542 */
1543 int Index( int val ) const;
1544
1545 /**
1546 Inserts single item.
1547 */
1548 wxPGChoiceEntry& Insert( const wxString& label, int index, int value = wxPG_INVALID_VALUE );
1549
1550 /**
1551 Inserts a single item with full entry information.
1552 */
1553 wxPGChoiceEntry& Insert( const wxPGChoiceEntry& entry, int index );
1554
1555 /**
1556 Returns false if this is a constant empty set of choices,
1557 which should not be modified.
1558 */
1559 bool IsOk() const
1560 {
1561 return ( m_data != wxPGChoicesEmptyData );
1562 }
1563
1564 /**
1565 Returns item at given index.
1566 */
1567 const wxPGChoiceEntry& Item( unsigned int i ) const
1568 {
1569 wxASSERT( IsOk() );
1570 return *m_data->Item(i);
1571 }
1572
1573 /**
1574 Returns item at given index.
1575 */
1576 wxPGChoiceEntry& Item( unsigned int i )
1577 {
1578 wxASSERT( IsOk() );
1579 return *m_data->Item(i);
1580 }
1581
1582 /**
1583 Removes count items starting at position nIndex.
1584 */
1585 void RemoveAt(size_t nIndex, size_t count = 1);
1586
1587 /**
1588 Sets contents from lists of strings and values.
1589 */
1590 void Set( const wxChar** labels, const long* values = NULL );
1591
1592 /**
1593 Sets contents from lists of strings and values.
1594 */
1595 void Set( const wxArrayString& labels, const wxArrayInt& values = wxArrayInt() );
1596
1597 /**
1598 Creates exclusive copy of current choices.
1599 */
1600 void SetExclusive();
1601
1602 /**
1603 Returns array of choice labels.
1604 */
1605 wxArrayString GetLabels() const;
1606
1607 void operator= (const wxPGChoices& a)
1608 {
1609 AssignData(a.m_data);
1610 }
1611
1612 wxPGChoiceEntry& operator[](unsigned int i)
1613 {
1614 return Item(i);
1615 }
1616
1617 const wxPGChoiceEntry& operator[](unsigned int i) const
1618 {
1619 return Item(i);
1620 }
1621 };
1622
1623 // -----------------------------------------------------------------------