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