]> git.saurik.com Git - wxWidgets.git/blob - docs/doxygen/overviews/propgrid.h
Add <span> tag and limited support for CSS styles to wxHTML.
[wxWidgets.git] / docs / doxygen / overviews / propgrid.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: propgrid.h
3 // Purpose: topic overview
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9 /**
10
11 @page overview_propgrid wxPropertyGrid Overview
12
13 Key Classes:
14 @li wxPGProperty
15 @li wxPropertyGrid
16 @li wxPropertyGridEvent
17 @li wxPropertyGridManager
18 @li wxPropertyGridPage
19
20 wxPropertyGrid is a specialized grid for editing properties - in other
21 words name = value pairs. List of ready-to-use property classes include
22 strings, numbers, flag sets, fonts, colours and many others. It is possible,
23 for example, to categorize properties, set up a complete tree-hierarchy,
24 add more than two columns, and set arbitrary per-property attributes.
25
26 As this version of wxPropertyGrid has some backward-incompatible changes
27 from version 1.4, everybody who need to maintain custom property classes
28 should carefully read final section in @ref propgrid_compat.
29
30 @li @ref propgrid_basics
31 @li @ref propgrid_categories
32 @li @ref propgrid_parentprops
33 @li @ref propgrid_enumandflags
34 @li @ref propgrid_advprops
35 @li @ref propgrid_processingvalues
36 @li @ref propgrid_iterating
37 @li @ref propgrid_events
38 @li @ref propgrid_tooltipandhint
39 @li @ref propgrid_validating
40 @li @ref propgrid_populating
41 @li @ref propgrid_cellrender
42 @li @ref propgrid_customizing
43 @li @ref propgrid_usage2
44 @li @ref propgrid_subclassing
45 @li @ref propgrid_misc
46 @li @ref propgrid_proplist
47 @li @ref propgrid_compat
48
49 @section propgrid_basics Creating and Populating wxPropertyGrid
50
51 As seen here, wxPropertyGrid is constructed in the same way as
52 other wxWidgets controls:
53
54 @code
55
56 // Necessary header file
57 #include <wx/propgrid/propgrid.h>
58
59 ...
60
61 // Assumes code is in frame/dialog constructor
62
63 // Construct wxPropertyGrid control
64 wxPropertyGrid* pg = new wxPropertyGrid(
65 this, // parent
66 PGID, // id
67 wxDefaultPosition, // position
68 wxDefaultSize, // size
69 // Here are just some of the supported window styles
70 wxPG_AUTO_SORT | // Automatic sorting after items added
71 wxPG_SPLITTER_AUTO_CENTER | // Automatically center splitter until user manually adjusts it
72 // Default style
73 wxPG_DEFAULT_STYLE );
74
75 // Window style flags are at premium, so some less often needed ones are
76 // available as extra window styles (wxPG_EX_xxx) which must be set using
77 // SetExtraStyle member function. wxPG_EX_HELP_AS_TOOLTIPS, for instance,
78 // allows displaying help strings as tool tips.
79 pg->SetExtraStyle( wxPG_EX_HELP_AS_TOOLTIPS );
80
81 @endcode
82
83 (for complete list of new window styles, see @ref propgrid_window_styles)
84
85 wxPropertyGrid is usually populated with lines like this:
86
87 @code
88 pg->Append( new wxStringProperty("Label", "Name", "Initial Value") );
89 @endcode
90
91 Naturally, wxStringProperty is a property class. Only the first function argument (label)
92 is mandatory. Second one, name, defaults to label and, third, the initial value, to
93 default value. If constant wxPG_LABEL is used as the name argument, then the label is
94 automatically used as a name as well (this is more efficient than manually defining both
95 as the same). Use of empty name is discouraged and will sometimes result in run-time error.
96 Note that all property class constructors have quite similar constructor argument list.
97
98 To demonstrate other common property classes, here's another code snippet:
99
100 @code
101
102 // Add int property
103 pg->Append( new wxIntProperty("IntProperty", wxPG_LABEL, 12345678) );
104
105 // Add float property (value type is actually double)
106 pg->Append( new wxFloatProperty("FloatProperty", wxPG_LABEL, 12345.678) );
107
108 // Add a bool property
109 pg->Append( new wxBoolProperty("BoolProperty", wxPG_LABEL, false) );
110
111 // A string property that can be edited in a separate editor dialog.
112 pg->Append( new wxLongStringProperty("LongStringProperty",
113 wxPG_LABEL,
114 "This is much longer string than the "
115 "first one. Edit it by clicking the button."));
116
117 // String editor with dir selector button.
118 pg->Append( new wxDirProperty("DirProperty", wxPG_LABEL, ::wxGetUserHome()) );
119
120 // wxArrayStringProperty embeds a wxArrayString.
121 pg->Append( new wxArrayStringProperty("Label of ArrayStringProperty",
122 "NameOfArrayStringProp"));
123
124 // A file selector property.
125 pg->Append( new wxFileProperty("FileProperty", wxPG_LABEL, wxEmptyString) );
126
127 // Extra: set wild card for file property (format same as in wxFileDialog).
128 pg->SetPropertyAttribute( "FileProperty",
129 wxPG_FILE_WILDCARD,
130 "All files (*.*)|*.*" );
131
132 @endcode
133
134 Operations on properties are usually done by directly calling wxPGProperty's
135 or wxPropertyGridInterface's member functions. wxPropertyGridInterface is an
136 abstract base class for property containers such as wxPropertyGrid,
137 wxPropertyGridManager, and wxPropertyGridPage. Note however that wxPGProperty's
138 member functions generally do not refresh the grid.
139
140 wxPropertyGridInterface's property operation member functions , such as
141 SetPropertyValue() and DisableProperty(), all accept a special wxPGPropArg id
142 argument, using which you can refer to properties either by their pointer
143 (for performance) or by their name (for convenience). For instance:
144
145 @code
146 // Add a file selector property.
147 wxPGPropety* prop = pg->Append( new wxFileProperty("FileProperty",
148 wxPG_LABEL,
149 wxEmptyString) );
150
151 // Valid: Set wild card by name
152 pg->SetPropertyAttribute( "FileProperty",
153 wxPG_FILE_WILDCARD,
154 "All files (*.*)|*.*" );
155
156 // Also Valid: Set wild card by property pointer
157 pg->SetPropertyAttribute( prop,
158 wxPG_FILE_WILDCARD,
159 "All files (*.*)|*.*" );
160 @endcode
161
162 Using pointer is faster, since it doesn't require hash map lookup. Anyway,
163 you can always get property pointer (wxPGProperty*) as return value from Append()
164 or Insert(), or by calling wxPropertyGridInterface::GetPropertyByName() or
165 just plain GetProperty().
166
167 @section propgrid_categories Categories
168
169 wxPropertyGrid has a hierarchic property storage and display model, which
170 allows property categories to hold child properties and even other
171 categories. Other than that, from the programmer's point of view, categories
172 can be treated exactly the same as "other" properties. For example, despite
173 its name, GetPropertyByName() also returns a category by name. Note however
174 that sometimes the label of a property category may be referred as caption
175 (for example, there is wxPropertyGrid::SetCaptionTextColour() method
176 that sets text colour of property category labels).
177
178 When category is added at the top (i.e. root) level of the hierarchy,
179 it becomes a *current category*. This means that all other (non-category)
180 properties after it are automatically appended to it. You may add
181 properties to specific categories by using wxPropertyGridInterface::Insert
182 or wxPropertyGridInterface::AppendIn.
183
184 Category code sample:
185
186 @code
187
188 // One way to add category (similar to how other properties are added)
189 pg->Append( new wxPropertyCategory("Main") );
190
191 // All these are added to "Main" category
192 pg->Append( new wxStringProperty("Name") );
193 pg->Append( new wxIntProperty("Age",wxPG_LABEL,25) );
194 pg->Append( new wxIntProperty("Height",wxPG_LABEL,180) );
195 pg->Append( new wxIntProperty("Weight") );
196
197 // Another one
198 pg->Append( new wxPropertyCategory("Attributes") );
199
200 // All these are added to "Attributes" category
201 pg->Append( new wxIntProperty("Intelligence") );
202 pg->Append( new wxIntProperty("Agility") );
203 pg->Append( new wxIntProperty("Strength") );
204
205 @endcode
206
207
208 @section propgrid_parentprops Tree-like Property Structure
209
210 Basically any property can have children. There are few limitations, however.
211
212 @remarks
213 - Names of properties with non-category, non-root parents are not stored in global
214 hash map. Instead, they can be accessed with strings like "Parent.Child".
215 For instance, in the sample below, child property named "Max. Speed (mph)"
216 can be accessed by global name "Car.Speeds.Max Speed (mph)".
217 - If you want to property's value to be a string composed of the child property values,
218 you must use wxStringProperty as parent and use magic string "<composed>" as its
219 value.
220 - Events (eg. change of value) that occur in parent do not propagate to children. Events
221 that occur in children will propagate to parents, but only if they are wxStringProperties
222 with "<composed>" value.
223
224 Sample:
225
226 @code
227 wxPGProperty* carProp = pg->Append(new wxStringProperty("Car",
228 wxPG_LABEL,
229 "<composed>"));
230
231 pg->AppendIn(carProp, new wxStringProperty("Model",
232 wxPG_LABEL,
233 "Lamborghini Diablo SV"));
234
235 pg->AppendIn(carProp, new wxIntProperty("Engine Size (cc)",
236 wxPG_LABEL,
237 5707) );
238
239 wxPGProperty* speedsProp = pg->AppendIn(carProp,
240 new wxStringProperty("Speeds",
241 wxPG_LABEL,
242 "<composed>"));
243
244 pg->AppendIn( speedsProp, new wxIntProperty("Max. Speed (mph)",
245 wxPG_LABEL,290) );
246 pg->AppendIn( speedsProp, new wxFloatProperty("0-100 mph (sec)",
247 wxPG_LABEL,3.9) );
248 pg->AppendIn( speedsProp, new wxFloatProperty("1/4 mile (sec)",
249 wxPG_LABEL,8.6) );
250
251 // This is how child property can be referred to by name
252 pg->SetPropertyValue( "Car.Speeds.Max. Speed (mph)", 300 );
253
254 pg->AppendIn(carProp, new wxIntProperty("Price ($)",
255 wxPG_LABEL,
256 300000) );
257
258 // Displayed value of "Car" property is now very close to this:
259 // "Lamborghini Diablo SV; 5707 [300; 3.9; 8.6] 300000"
260
261 @endcode
262
263 @section propgrid_enumandflags wxEnumProperty and wxFlagsProperty
264
265 wxEnumProperty is used when you want property's (integer or string) value
266 to be selected from a popup list of choices.
267
268 Creating wxEnumProperty is slightly more complex than those described
269 earlier. You have to provide list of constant labels, and optionally relevant
270 values (if label indexes are not sufficient).
271
272 @remarks
273
274 - Value wxPG_INVALID_VALUE (equals INT_MAX) is not allowed as list
275 item value.
276
277 A very simple example:
278
279 @code
280
281 //
282 // Using wxArrayString
283 //
284 wxArrayString arrDiet;
285 arr.Add("Herbivore");
286 arr.Add("Carnivore");
287 arr.Add("Omnivore");
288
289 pg->Append( new wxEnumProperty("Diet",
290 wxPG_LABEL,
291 arrDiet) );
292
293 //
294 // Using wxChar* array
295 //
296 const wxChar* arrayDiet[] =
297 { wxT("Herbivore"), wxT("Carnivore"), wxT("Omnivore"), NULL };
298
299 pg->Append( new wxEnumProperty("Diet",
300 wxPG_LABEL,
301 arrayDiet) );
302
303 @endcode
304
305 Here's extended example using values as well:
306
307 @code
308
309 //
310 // Using wxArrayString and wxArrayInt
311 //
312 wxArrayString arrDiet;
313 arr.Add("Herbivore");
314 arr.Add("Carnivore");
315 arr.Add("Omnivore");
316
317 wxArrayInt arrIds;
318 arrIds.Add(40);
319 arrIds.Add(45);
320 arrIds.Add(50);
321
322 // Note that the initial value (the last argument) is the actual value,
323 // not index or anything like that. Thus, our value selects "Omnivore".
324 pg->Append( new wxEnumProperty("Diet",
325 wxPG_LABEL,
326 arrDiet,
327 arrIds,
328 50));
329
330 @endcode
331
332 wxPGChoices is a class where wxEnumProperty, and other properties which
333 require storage for list of items, actually stores strings and values. It is
334 used to facilitate reference counting, and therefore recommended way of
335 adding items when multiple properties share the same set.
336
337 You can use wxPGChoices directly as well, filling it and then passing it
338 to the constructor. In fact, if you wish to display bitmaps next to labels,
339 your best choice is to use this approach.
340
341 @code
342
343 wxPGChoices chs;
344 chs.Add("Herbivore", 40);
345 chs.Add("Carnivore", 45);
346 chs.Add("Omnivore", 50);
347
348 // Let's add an item with bitmap, too
349 chs.Add("None of the above", wxBitmap(), 60);
350
351 pg->Append( new wxEnumProperty("Primary Diet",
352 wxPG_LABEL,
353 chs) );
354
355 // Add same choices to another property as well - this is efficient due
356 // to reference counting
357 pg->Append( new wxEnumProperty("Secondary Diet",
358 wxPG_LABEL,
359 chs) );
360 @endcode
361
362 You can later change choices of property by using wxPGProperty::AddChoice(),
363 wxPGProperty::InsertChoice(), wxPGProperty::DeleteChoice(), and
364 wxPGProperty::SetChoices().
365
366 <b>wxEditEnumProperty</b> works exactly like wxEnumProperty, except
367 is uses non-read-only combo box as default editor, and value is stored as
368 string when it is not any of the choices.
369
370 wxFlagsProperty has similar construction:
371
372 @code
373
374 const wxChar* flags_prop_labels[] = { wxT("wxICONIZE"),
375 wxT("wxCAPTION"), wxT("wxMINIMIZE_BOX"), wxT("wxMAXIMIZE_BOX"), NULL };
376
377 // this value array would be optional if values matched string indexes
378 long flags_prop_values[] = { wxICONIZE, wxCAPTION, wxMINIMIZE_BOX,
379 wxMAXIMIZE_BOX };
380
381 pg->Append( new wxFlagsProperty("Window Style",
382 wxPG_LABEL,
383 flags_prop_labels,
384 flags_prop_values,
385 wxDEFAULT_FRAME_STYLE) );
386
387 @endcode
388
389 wxFlagsProperty can use wxPGChoices just the same way as wxEnumProperty
390 <b>Note:</b> When changing "choices" (ie. flag labels) of wxFlagsProperty,
391 you will need to use wxPGProperty::SetChoices() to replace all choices
392 at once - otherwise implicit child properties will not get updated properly.
393
394 @section propgrid_advprops Specialized Properties
395
396 This section describes the use of less often needed property classes.
397 To use them, you have to include <wx/propgrid/advprops.h>.
398
399 @code
400
401 // Necessary extra header file
402 #include <wx/propgrid/advprops.h>
403
404 ...
405
406 // Date property.
407 pg->Append( new wxDateProperty("MyDateProperty",
408 wxPG_LABEL,
409 wxDateTime::Now()) );
410
411 // Image file property. Wild card is auto-generated from available
412 // image handlers, so it is not set this time.
413 pg->Append( new wxImageFileProperty("Label of ImageFileProperty",
414 "NameOfImageFileProp") );
415
416 // Font property has sub-properties. Note that we give window's font as
417 // initial value.
418 pg->Append( new wxFontProperty("Font",
419 wxPG_LABEL,
420 GetFont()) );
421
422 // Colour property with arbitrary colour.
423 pg->Append( new wxColourProperty("My Colour 1",
424 wxPG_LABEL,
425 wxColour(242,109,0) ) );
426
427 // System colour property.
428 pg->Append( new wxSystemColourProperty("My SysColour 1",
429 wxPG_LABEL,
430 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)) );
431
432 // System colour property with custom colour.
433 pg->Append( new wxSystemColourProperty("My SysColour 2",
434 wxPG_LABEL,
435 wxColour(0,200,160) ) );
436
437 // Cursor property
438 pg->Append( new wxCursorProperty("My Cursor",
439 wxPG_LABEL,
440 wxCURSOR_ARROW));
441
442 @endcode
443
444
445 @section propgrid_processingvalues Processing Property Values
446
447 Properties store their values internally as wxVariant, but is also possible to
448 obtain them as wxAny, using implicit conversion. You can get property
449 values with wxPGProperty::GetValue() and
450 wxPropertyGridInterface::GetPropertyValue().
451
452 Below is a code example which handles wxEVT_PG_CHANGED event:
453
454 @code
455
456 void MyWindowClass::OnPropertyGridChanged(wxPropertyGridEvent& event)
457 {
458 wxPGProperty* property = event.GetProperty();
459
460 // Do nothing if event did not have associated property
461 if ( !property )
462 return;
463
464 // GetValue() returns wxVariant, but it is converted transparently to
465 // wxAny
466 wxAny value = property->GetValue();
467
468 // Also, handle the case where property value is unspecified
469 if ( value.IsNull() )
470 return;
471
472 // Handle changes in values, as needed
473 if ( property.GetName() == "MyStringProperty" )
474 OnMyStringPropertyChanged(value.As<wxString>());
475 else if ( property.GetName() == "MyColourProperty" )
476 OnMyColourPropertyChanged(value.As<wxColour>());
477 }
478
479 @endcode
480
481 You can get a string-representation of property's value using
482 wxPGProperty::GetValueAsString() or
483 wxPropertyGridInterface::GetPropertyValueAsString(). This particular function
484 is very safe to use with any kind of property.
485
486 @note There is a one case in which you may want to take extra care when
487 dealing with raw wxVariant values. That is, integer-type properties,
488 such as wxIntProperty and wxUIntProperty, store value internally as
489 wx(U)LongLong when number doesn't fit into standard long type. Using
490 << operator to get wx(U)LongLong from wxVariant is customized to work
491 quite safely with various types of variant data. However, you can also
492 bypass this problem by using wxAny in your code instead of wxVariant.
493
494 Note that in some cases property value can be Null variant, which means
495 that property value is unspecified. This usually occurs only when
496 wxPG_EX_AUTO_UNSPECIFIED_VALUES extra window style is defined or when you
497 manually set property value to Null (or unspecified).
498
499
500 @section propgrid_iterating Iterating through a property container
501
502 You can use somewhat STL'ish iterator classes to iterate through the grid.
503 Here is a simple example of forward iterating through all individual
504 properties (not categories nor private child properties that are normally
505 'transparent' to application code):
506
507 @code
508
509 wxPropertyGridIterator it;
510
511 for ( it = pg->GetIterator();
512 !it.AtEnd();
513 it++ )
514 {
515 wxPGProperty* p = *it;
516 // Do something with the property
517 }
518
519 @endcode
520
521 As expected there is also a const iterator:
522
523 @code
524
525 wxPropertyGridConstIterator it;
526
527 for ( it = pg->GetIterator();
528 !it.AtEnd();
529 it++ )
530 {
531 const wxPGProperty* p = *it;
532 // Do something with the property
533 }
534
535 @endcode
536
537 You can give some arguments to GetIterator to determine which properties
538 get automatically filtered out. For complete list of options, see
539 @ref propgrid_iterator_flags. GetIterator() also accepts other arguments.
540 See wxPropertyGridInterface::GetIterator() for details.
541
542 This example reverse-iterates through all visible items:
543
544 @code
545
546 wxPropertyGridIterator it;
547
548 for ( it = pg->GetIterator(wxPG_ITERATE_VISIBLE, wxBOTTOM);
549 !it.AtEnd();
550 it-- )
551 {
552 wxPGProperty* p = *it;
553 // Do something with the property
554 }
555
556 @endcode
557
558 <b>wxPython Note:</b> Instead of ++ operator, use Next() method, and instead of
559 * operator, use GetProperty() method.
560
561 GetIterator() only works with wxPropertyGrid and the individual pages
562 of wxPropertyGridManager. In order to iterate through an arbitrary
563 property container (such as entire wxPropertyGridManager), you need to use
564 wxPropertyGridInterface::GetVIterator(). Note however that this virtual
565 iterator is limited to forward iteration.
566
567 @code
568
569 wxPGVIterator it;
570
571 for ( it = manager->GetVIterator();
572 !it.AtEnd();
573 it.Next() )
574 {
575 wxPGProperty* p = it.GetProperty();
576 // Do something with the property
577 }
578
579 @endcode
580
581 @section propgrid_populating Populating wxPropertyGrid Automatically
582
583 @subsection propgrid_fromvariants Populating from List of wxVariants
584
585 Example of populating an empty wxPropertyGrid from a values stored
586 in an arbitrary list of wxVariants.
587
588 @code
589
590 // This is a static method that initializes *all* built-in type handlers
591 // available, including those for wxColour and wxFont. Refers to *all*
592 // included properties, so when compiling with static library, this
593 // method may increase the executable size noticeably.
594 pg->InitAllTypeHandlers();
595
596 // Get contents of the grid as a wxVariant list
597 wxVariant all_values = pg->GetPropertyValues();
598
599 // Populate the list with values. If a property with appropriate
600 // name is not found, it is created according to the type of variant.
601 pg->SetPropertyValues( my_list_variant );
602
603 @endcode
604
605 @subsection propgrid_fromfile Loading Population from a Text-based Storage
606
607 Class wxPropertyGridPopulator may be helpful when writing code that
608 loads properties from a text-source. In fact, the wxPropertyGrid xrc-handler
609 (which may not be currently included in wxWidgets, but probably will be in
610 near future) uses it.
611
612 @subsection editablestate Saving and Restoring User-Editable State
613
614 You can use wxPropertyGridInterface::SaveEditableState() and
615 wxPropertyGridInterface::RestoreEditableState() to save and restore
616 user-editable state (selected property, expanded/collapsed properties,
617 selected page, scrolled position, and splitter positions).
618
619 @section propgrid_events Event Handling
620
621 Probably the most important event is the Changed event which occurs when
622 value of any property is changed by the user. Use EVT_PG_CHANGED(id,func)
623 in your event table to use it.
624
625 For complete list of event types, see wxPropertyGrid class reference.
626
627 However, one type of event that might need focused attention is EVT_PG_CHANGING,
628 which occurs just prior property value is being changed by user. You can
629 acquire pending value using wxPropertyGridEvent::GetValue(), and if it is
630 not acceptable, call wxPropertyGridEvent::Veto() to prevent the value change
631 from taking place.
632
633 @code
634
635 void MyForm::OnPropertyGridChanging( wxPropertyGridEvent& event )
636 {
637 wxPGProperty* property = event.GetProperty();
638
639 if ( property == m_pWatchThisProperty )
640 {
641 // GetValue() returns the pending value, but is only
642 // supported by wxEVT_PG_CHANGING.
643 if ( event.GetValue().GetString() == g_pThisTextIsNotAllowed )
644 {
645 event.Veto();
646 return;
647 }
648 }
649 }
650
651 @endcode
652
653 @remarks On Child Property Event Handling
654 - For properties which have private, implicit children (wxFontProperty and
655 wxFlagsProperty), events occur for the main parent property only.
656 For other properties events occur for the children themselves. See
657 @ref propgrid_parentprops.
658
659 - When property's child gets changed, you can use wxPropertyGridEvent::GetMainParent()
660 to obtain its topmost non-category parent (useful, if you have deeply nested
661 properties).
662
663 @section propgrid_tooltipandhint Help String, Hint and Tool Tips
664
665 For each property you can specify two different types of help text. First,
666 you can use wxPropertyGridInterface::SetPropertyHelpString() or
667 wxPGProperty::SetHelpString() to set property's help text. Second, you
668 can use wxPGProperty::SetAttribute() to set property's "Hint" attribute.
669
670 Difference between hint and help string is that the hint is shown in an empty
671 property value cell, while help string is shown either in the description text
672 box, as a tool tip, or on the status bar, whichever of these is available.
673
674 To enable display of help string as tool tips, you must explicitly use
675 the wxPG_EX_HELP_AS_TOOLTIPS extra window style.
676
677 @section propgrid_validating Validating Property Values
678
679 There are various ways to make sure user enters only correct values. First, you
680 can use wxValidators similar to as you would with ordinary controls. Use
681 wxPropertyGridInterface::SetPropertyValidator() to assign wxValidator to
682 property.
683
684 Second, you can subclass a property and override wxPGProperty::ValidateValue(),
685 or handle wxEVT_PG_CHANGING for the same effect. Both of these ways do not
686 actually prevent user from temporarily entering invalid text, but they do give
687 you an opportunity to warn the user and block changed value from being committed
688 in a property.
689
690 Various validation failure options can be controlled globally with
691 wxPropertyGrid::SetValidationFailureBehavior(), or on an event basis by
692 calling wxEvent::SetValidationFailureBehavior(). Here's a code snippet of
693 how to handle wxEVT_PG_CHANGING, and to set custom failure behaviour and
694 message.
695
696 @code
697 void MyFrame::OnPropertyGridChanging(wxPropertyGridEvent& event)
698 {
699 wxPGProperty* property = event.GetProperty();
700
701 // You must use wxPropertyGridEvent::GetValue() to access
702 // the value to be validated.
703 wxVariant pendingValue = event.GetValue();
704
705 if ( property->GetName() == "Font" )
706 {
707 // Make sure value is not unspecified
708 if ( !pendingValue.IsNull() )
709 {
710 wxFont font;
711 font << pendingValue;
712
713 // Let's just allow Arial font
714 if ( font.GetFaceName() != "Arial" )
715 {
716 event.Veto();
717 event.SetValidationFailureBehavior(wxPG_VFB_STAY_IN_PROPERTY |
718 wxPG_VFB_BEEP |
719 wxPG_VFB_SHOW_MESSAGE);
720 }
721 }
722 }
723 }
724 @endcode
725
726
727 @section propgrid_cellrender Customizing Individual Cell Appearance
728
729 You can control text colour, background colour, and attached image of
730 each cell in the property grid. Use wxPropertyGridInterface::SetPropertyCell() or
731 wxPGProperty::SetCell() for this purpose.
732
733 In addition, it is possible to control these characteristics for
734 wxPGChoices list items. See wxPGChoices class reference for more info.
735
736
737 @section propgrid_customizing Customizing Properties (without sub-classing)
738
739 In this section are presented miscellaneous ways to have custom appearance
740 and behavior for your properties without all the necessary hassle
741 of sub-classing a property class etc.
742
743 @subsection propgrid_customimage Setting Value Image
744
745 Every property can have a small value image placed in front of the
746 actual value text. Built-in example of this can be seen with
747 wxColourProperty and wxImageFileProperty, but for others it can
748 be set using wxPropertyGrid::SetPropertyImage method.
749
750 @subsection propgrid_customeditor Setting Property's Editor Control(s)
751
752 You can set editor control (or controls, in case of a control and button),
753 of any property using wxPropertyGrid::SetPropertyEditor. Editors are passed
754 as wxPGEditor_EditorName, and valid built-in EditorNames are
755 TextCtrl, Choice, ComboBox, CheckBox, TextCtrlAndButton, ChoiceAndButton,
756 SpinCtrl, and DatePickerCtrl. Two last mentioned ones require call to
757 static member function wxPropertyGrid::RegisterAdditionalEditors().
758
759 Following example changes wxColourProperty's editor from default Choice
760 to TextCtrlAndButton. wxColourProperty has its internal event handling set
761 up so that button click events of the button will be used to trigger
762 colour selection dialog.
763
764 @code
765
766 wxPGProperty* colProp = new wxColourProperty("Text Colour");
767 pg->Append(colProp);
768 pg->SetPropertyEditor(colProp, wxPGEditor_TextCtrlAndButton);
769
770 @endcode
771
772 Naturally, creating and setting custom editor classes is a possibility as
773 well. For more information, see wxPGEditor class reference.
774
775 @subsection propgrid_editorattrs Property Attributes Recognized by Editors
776
777 <b>SpinCtrl</b> editor can make use of property's "Min", "Max", "Step" and
778 "Wrap" attributes.
779
780 @subsection propgrid_multiplebuttons Adding Multiple Buttons Next to an Editor
781
782 See wxPGMultiButton class reference.
783
784 @subsection propgrid_customeventhandling Handling Events Passed from Properties
785
786 <b>wxEVT_COMMAND_BUTTON_CLICKED </b>(corresponds to event table macro EVT_BUTTON):
787 Occurs when editor button click is not handled by the property itself
788 (as is the case, for example, if you set property's editor to TextCtrlAndButton
789 from the original TextCtrl).
790
791 @subsection propgrid_attributes Property Attributes
792
793 Miscellaneous values, often specific to a property type, can be set
794 using wxPropertyGridInterface::SetPropertyAttribute() and
795 wxPropertyGridInterface::SetPropertyAttributeAll() methods.
796
797 Attribute names are strings and values wxVariant. Arbitrary names are allowed
798 in order to store values that are relevant to application only and not
799 property grid. Constant equivalents of all attribute string names are
800 provided. Some of them are defined as cached strings, so using these constants
801 can provide for smaller binary size.
802
803 For complete list of attributes, see @ref propgrid_property_attributes.
804
805
806 @section propgrid_usage2 Using wxPropertyGridManager
807
808 wxPropertyGridManager is an efficient multi-page version of wxPropertyGrid,
809 which can optionally have tool bar for mode and page selection, and a help text
810 box. For more information, see wxPropertyGridManager class reference.
811
812 @subsection propgrid_propgridpage wxPropertyGridPage
813
814 wxPropertyGridPage is holder of properties for one page in manager. It is derived from
815 wxEvtHandler, so you can subclass it to process page-specific property grid events. Hand
816 over your page instance in wxPropertyGridManager::AddPage().
817
818 Please note that the wxPropertyGridPage itself only sports subset of wxPropertyGrid API
819 (but unlike manager, this include item iteration). Naturally it inherits from
820 wxPropertyGridInterface.
821
822 For more information, see wxPropertyGridPage class reference.
823
824
825 @section propgrid_subclassing Sub-classing wxPropertyGrid and wxPropertyGridManager
826
827 Few things to note:
828
829 - Only a small percentage of member functions are virtual. If you need more,
830 just e-mail to wx-dev mailing list.
831
832 - Data manipulation is done in wxPropertyGridPageState class. So, instead of
833 overriding wxPropertyGrid::Insert(), you'll probably want to override
834 wxPropertyGridPageState::DoInsert(). See header file for details.
835
836 - Override wxPropertyGrid::CreateState() to instantiate your derivate
837 wxPropertyGridPageState. For wxPropertyGridManager, you'll need to subclass
838 wxPropertyGridPage instead (since it is derived from wxPropertyGridPageState),
839 and hand over instances in wxPropertyGridManager::AddPage() calls.
840
841 - You can use a derivate wxPropertyGrid with manager by overriding
842 wxPropertyGridManager::CreatePropertyGrid() member function.
843
844
845 @section propgrid_misc Miscellaneous Topics
846
847 @subsection propgrid_namescope Property Name Scope
848
849 All properties which parent is category or root can be accessed
850 directly by their base name (ie. name given for property in its constructor).
851 Other properties can be accessed via "ParentsName.BaseName" notation,
852 Naturally, all property names should be unique.
853
854 @subsection propgrid_nonuniquelabels Non-unique Labels
855
856 It is possible to have properties with identical label under same parent.
857 However, care must be taken to ensure that each property still has
858 unique (base) name.
859
860 @subsection propgrid_boolproperty wxBoolProperty
861
862 There are few points about wxBoolProperty that require further discussion:
863 - wxBoolProperty can be shown as either normal combo box or as a check box.
864 Property attribute wxPG_BOOL_USE_CHECKBOX is used to change this.
865 For example, if you have a wxFlagsProperty, you can
866 set its all items to use check box using the following:
867 @code
868 pg->SetPropertyAttribute("MyFlagsProperty", wxPG_BOOL_USE_CHECKBOX, true, wxPG_RECURSE);
869 @endcode
870
871 Following will set all individual bool properties in your control to
872 use check box:
873
874 @code
875 pg->SetPropertyAttributeAll(wxPG_BOOL_USE_CHECKBOX, true);
876 @endcode
877
878 - Default item names for wxBoolProperty are ["False", "True"]. This can be
879 changed using static function wxPropertyGrid::SetBoolChoices(trueChoice,
880 falseChoice).
881
882 @subsection propgrid_textctrlupdates Updates from wxTextCtrl Based Editor
883
884 Changes from wxTextCtrl based property editors are committed (ie.
885 wxEVT_PG_CHANGED is sent etc.) *only* when (1) user presser enter, (2)
886 user moves to edit another property, or (3) when focus leaves
887 the grid.
888
889 Because of this, you may find it useful, in some apps, to call
890 wxPropertyGrid::CommitChangesFromEditor() just before you need to do any
891 computations based on property grid values. Note that CommitChangesFromEditor()
892 will dispatch wxEVT_PG_CHANGED with ProcessEvent, so any of your event handlers
893 will be called immediately.
894
895 @subsection propgrid_splittercentering Centering the Splitter
896
897 If you need to center the splitter, but only once when the program starts,
898 then do <b>not</b> use the wxPG_SPLITTER_AUTO_CENTER window style, but the
899 wxPropertyGrid::CenterSplitter() method. <b>However, be sure to call it after
900 the sizer setup and SetSize calls!</b> (ie. usually at the end of the
901 frame/dialog constructor)
902
903 Splitter centering behavior can be customized using
904 wxPropertyGridInterface::SetColumnProportion(). Usually it is used to set
905 non-equal column proportions, which in essence stops the splitter(s) from
906 being 'centered' as such, and instead just auto-resized.
907
908 @subsection propgrid_splittersetting Setting Splitter Position When Creating Property Grid
909
910 Splitter position cannot exceed grid size, and therefore setting it during
911 form creation may fail as initial grid size is often smaller than desired
912 splitter position, especially when sizers are being used.
913
914 @subsection propgrid_colourproperty wxColourProperty and wxSystemColourProperty
915
916 Through sub-classing, these two property classes provide substantial customization
917 features. Subclass wxSystemColourProperty if you want to use wxColourPropertyValue
918 (which features colour type in addition to wxColour), and wxColourProperty if plain
919 wxColour is enough.
920
921 Override wxSystemColourProperty::ColourToString() to redefine how colours are
922 printed as strings.
923
924 Override wxSystemColourProperty::GetCustomColourIndex() to redefine location of
925 the item that triggers colour picker dialog (default is last).
926
927 Override wxSystemColourProperty::GetColour() to determine which colour matches
928 which choice entry.
929
930 @section propgrid_proplist Property Class Descriptions
931
932 See @ref pgproperty_properties
933
934 @section propgrid_compat Changes from wxPropertyGrid 1.4
935
936 Version of wxPropertyGrid bundled with wxWidgets 2.9+ has various backward-
937 incompatible changes from version 1.4, which had a stable API and will remain
938 as the last separate branch.
939
940 Note that in general any behavior-breaking changes should not compile or run
941 without warnings or errors.
942
943 @subsection propgrid_compat_general General Changes
944
945 - Tab-traversal can no longer be used to travel between properties. Now
946 it only causes focus to move from main grid to editor of selected property.
947 Arrow keys are now your primary means of navigating between properties,
948 with keyboard. This change allowed fixing broken tab traversal on wxGTK
949 (which is open issue in wxPropertyGrid 1.4).
950
951 - A few member functions were removed from wxPropertyGridInterface.
952 Please use wxPGProperty's counterparts from now on.
953
954 - wxPGChoices now has proper Copy-On-Write behavior.
955
956 - wxPGChoices::SetExclusive() was renamed to AllocExclusive().
957
958 - wxPGProperty::SetPropertyChoicesExclusive() was removed. Instead, use
959 GetChoices().AllocExclusive().
960
961 - wxPGProperty::ClearModifiedStatus() is removed. Please use
962 SetModifiedStatus() instead.
963
964 - wxPropertyGridInterface::GetExpandedProperties() is removed. You should
965 now use wxPropertyGridInterface::GetEditableState() instead.
966
967 - wxPG_EX_DISABLE_TLP_TRACKING is now enabled by default. To get the old
968 behavior (recommended if you don't use a system that reparents the grid
969 on its own), use the wxPG_EX_ENABLE_TLP_TRACKING extra style.
970
971 - Extended window style wxPG_EX_LEGACY_VALIDATORS was removed.
972
973 - wxPropertyGridManager now has same Get/SetSelection() semantics as
974 wxPropertyGrid.
975
976 - Various wxPropertyGridManager page-related functions now return pointer
977 to the page object instead of index.
978
979 - Instead of calling wxPropertyGrid::SetButtonShortcut(), use
980 wxPropertyGrid::SetActionTrigger(wxPG_ACTION_PRESS_BUTTON).
981
982 - wxPGProperty::GetCell() now returns a reference. AcquireCell() was removed.
983
984 - wxPGMultiButton::FinalizePosition() has been renamed to Finalize(),
985 and it has slightly different argument list.
986
987 - wxPropertyGridEvent::HasProperty() is removed. You can use GetProperty()
988 as immediate replacement when checking if event has a property.
989
990 - "InlineHelp" property has been replaced with "Hint".
991
992 - wxPropertyGrid::CanClose() has been removed. Call
993 wxPropertyGridInterface::EditorValidate() instead.
994
995 @subsection propgrid_compat_propdev Property and Editor Sub-classing Changes
996
997 - Confusing custom property macros have been eliminated.
998
999 - Implement wxPGProperty::ValueToString() instead of GetValueAsString().
1000
1001 - wxPGProperty::ChildChanged() must now return the modified value of
1002 whole property instead of writing it back into 'thisValue' argument.
1003
1004 - Removed wxPropertyGrid::PrepareValueForDialogEditing(). Use
1005 wxPropertyGrid::GetPendingEditedValue() instead.
1006
1007 - wxPGProperty::GetChoiceInfo() is removed, as all properties now carry
1008 wxPGChoices instance (protected wxPGProperty::m_choices).
1009
1010 - Connect() should no longer be called in implementations of
1011 wxPGEditor::CreateControls(). wxPropertyGrid automatically passes all
1012 events from editor to wxPGEditor::OnEvent() and wxPGProperty::OnEvent(),
1013 as appropriate.
1014
1015 - wxPython: Previously some of the reimplemented member functions needed a
1016 'Py' prefix. This is no longer necessary. For instance, if you previously
1017 implemented PyStringToValue() for your custom property, you should now
1018 just implement StringToValue().
1019 */