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