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