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