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