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