]> git.saurik.com Git - wxWidgets.git/blame - include/wx/propgrid/propgridiface.h
move the grid-specific workaround for scrollbar hysteresis to wxScrollHelper itself...
[wxWidgets.git] / include / wx / propgrid / propgridiface.h
CommitLineData
1c4293cb
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/propgeid/propgridiface.h
3// Purpose: wxPropertyGridInterface class
4// Author: Jaakko Salli
5// Modified by:
6// Created: 2008-08-24
7// RCS-ID: $Id:
8// Copyright: (c) Jaakko Salli
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef __WX_PROPGRID_PROPGRIDIFACE_H__
13#define __WX_PROPGRID_PROPGRIDIFACE_H__
14
15#include "wx/propgrid/property.h"
16#include "wx/propgrid/propgridpagestate.h"
17
18// -----------------------------------------------------------------------
19
20#ifndef SWIG
21
22/** @section wxPGPropArgCls
23
24 Most property grid functions have this type as their argument, as it can
25 convey a property by either a pointer or name.
26*/
27class WXDLLIMPEXP_PROPGRID wxPGPropArgCls
28{
29public:
30 wxPGPropArgCls() { }
31 wxPGPropArgCls( const wxPGProperty* property )
32 {
33 m_ptr.property = (wxPGProperty*) property;
f3793429 34 m_flags = IsProperty;
1c4293cb
VZ
35 }
36 wxPGPropArgCls( const wxString& str )
37 {
f3793429
JS
38 m_ptr.stringName = &str;
39 m_flags = IsWxString;
1c4293cb
VZ
40 }
41 wxPGPropArgCls( const wxPGPropArgCls& id )
42 {
43 m_ptr = id.m_ptr;
f3793429 44 m_flags = id.m_flags;
1c4293cb
VZ
45 }
46 // This is only needed for wxPython bindings
47 wxPGPropArgCls( wxString* str, bool WXUNUSED(deallocPtr) )
48 {
f3793429
JS
49 m_ptr.stringName = str;
50 m_flags = IsWxString | OwnsWxString;
1c4293cb
VZ
51 }
52 ~wxPGPropArgCls()
53 {
f3793429
JS
54 if ( m_flags & OwnsWxString )
55 delete m_ptr.stringName;
1c4293cb
VZ
56 }
57 wxPGProperty* GetPtr() const
58 {
f3793429 59 wxCHECK( m_flags == IsProperty, NULL );
1c4293cb
VZ
60 return m_ptr.property;
61 }
f3793429 62 wxPGPropArgCls( const char* str )
1c4293cb 63 {
f3793429
JS
64 m_ptr.charName = str;
65 m_flags = IsCharPtr;
1c4293cb 66 }
f3793429
JS
67#if wxUSE_WCHAR_T
68 wxPGPropArgCls( const wchar_t* str )
69 {
70 m_ptr.wcharName = str;
71 m_flags = IsWCharPtr;
72 }
73#endif
1c4293cb
VZ
74 /** This constructor is required for NULL. */
75 wxPGPropArgCls( int )
76 {
77 m_ptr.property = (wxPGProperty*) NULL;
f3793429 78 m_flags = IsProperty;
1c4293cb 79 }
f3793429
JS
80 wxPGProperty* GetPtr( wxPropertyGridInterface* iface ) const;
81 wxPGProperty* GetPtr( const wxPropertyGridInterface* iface ) const
1c4293cb 82 {
f3793429 83 return GetPtr((wxPropertyGridInterface*)iface);
1c4293cb
VZ
84 }
85 wxPGProperty* GetPtr0() const { return m_ptr.property; }
f3793429
JS
86 bool HasName() const { return (m_flags != IsProperty); }
87 const wxString& GetName() const { return *m_ptr.stringName; }
1c4293cb 88private:
f3793429
JS
89
90 enum
91 {
92 IsProperty = 0x00,
93 IsWxString = 0x01,
94 IsCharPtr = 0x02,
95 IsWCharPtr = 0x04,
96 OwnsWxString = 0x10,
97 };
98
1c4293cb
VZ
99 union
100 {
101 wxPGProperty* property;
f3793429
JS
102 const char* charName;
103#if wxUSE_WCHAR_T
104 const wchar_t* wcharName;
105#endif
106 const wxString* stringName;
1c4293cb 107 } m_ptr;
f3793429 108 unsigned char m_flags;
1c4293cb
VZ
109};
110
111#endif
112
113typedef const wxPGPropArgCls& wxPGPropArg;
114
115// -----------------------------------------------------------------------
116
117WXDLLIMPEXP_PROPGRID
118void wxPGTypeOperationFailed( const wxPGProperty* p,
119 const wxChar* typestr,
120 const wxChar* op );
121WXDLLIMPEXP_PROPGRID
122void wxPGGetFailed( const wxPGProperty* p, const wxChar* typestr );
123
124// -----------------------------------------------------------------------
125
126// Helper macro that does necessary preparations when calling
127// some wxPGProperty's member function.
128#define wxPG_PROP_ARG_CALL_PROLOG_0(PROPERTY) \
129 PROPERTY *p = (PROPERTY*)id.GetPtr(this); \
130 if ( !p ) return;
131
132#define wxPG_PROP_ARG_CALL_PROLOG_RETVAL_0(PROPERTY, RETVAL) \
133 PROPERTY *p = (PROPERTY*)id.GetPtr(this); \
134 if ( !p ) return RETVAL;
135
136#define wxPG_PROP_ARG_CALL_PROLOG() \
137 wxPG_PROP_ARG_CALL_PROLOG_0(wxPGProperty)
138
139#define wxPG_PROP_ARG_CALL_PROLOG_RETVAL(RVAL) \
140 wxPG_PROP_ARG_CALL_PROLOG_RETVAL_0(wxPGProperty, RVAL)
141
142#define wxPG_PROP_ID_CONST_CALL_PROLOG() \
143 wxPG_PROP_ARG_CALL_PROLOG_0(const wxPGProperty)
144
145#define wxPG_PROP_ID_CONST_CALL_PROLOG_RETVAL(RVAL) \
146 wxPG_PROP_ARG_CALL_PROLOG_RETVAL_0(const wxPGProperty, RVAL)
147
148// -----------------------------------------------------------------------
149
150
151/** @class wxPropertyGridInterface
152
153 Most of the shared property manipulation interface shared by wxPropertyGrid,
154 wxPropertyGridPage, and wxPropertyGridManager is defined in this class.
155
156 @remarks
157 - In separate wxPropertyGrid component this class was known as
158 wxPropertyContainerMethods.
159
160 @library{wxpropgrid}
161 @category{propgrid}
162*/
163class WXDLLIMPEXP_PROPGRID wxPropertyGridInterface
164{
165public:
166
167 /** Destructor */
168 virtual ~wxPropertyGridInterface() { }
169
170 /** Adds choice to a property that can accept one.
171 @remarks
172 - If you need to make sure that you modify only the set of choices of
173 a single property (and not also choices of other properties with
174 initially identical set), call
175 wxPropertyGrid::SetPropertyChoicesPrivate.
176 - This usually only works for wxEnumProperty and derivatives
177 (wxFlagsProperty can get accept new items but its items may not get
178 updated).
179 */
180 void AddPropertyChoice( wxPGPropArg id,
181 const wxString& label,
182 int value = wxPG_INVALID_VALUE );
183
184 /**
185 Appends property to the list.
186
187 wxPropertyGrid assumes ownership of the object.
188 Becomes child of most recently added category.
189 @remarks
190 - wxPropertyGrid takes the ownership of the property pointer.
191 - If appending a category with name identical to a category already in
192 the wxPropertyGrid, then newly created category is deleted, and most
193 recently added category (under which properties are appended) is set
194 to the one with same name. This allows easier adding of items to same
195 categories in multiple passes.
196 - Does not automatically redraw the control, so you may need to call
197 Refresh when calling this function after control has been shown for
198 the first time.
199 */
200 wxPGProperty* Append( wxPGProperty* property );
201
202 wxPGProperty* AppendIn( wxPGPropArg id, wxPGProperty* newproperty );
203
204 /**
205 In order to add new items into a property with fixed children (for
206 instance, wxFlagsProperty), you need to call this method. After
207 populating has been finished, you need to call EndAddChildren.
208 */
209 void BeginAddChildren( wxPGPropArg id );
210
211 /** Deletes all properties.
212 */
213 virtual void Clear() = 0;
214
215 /** Deselect current selection, if any. Returns true if success
216 (ie. validator did not intercept). */
217 bool ClearSelection();
218
219 /** Resets modified status of all properties.
220 */
221 void ClearModifiedStatus()
222 {
223 SetPropertyModifiedStatus(m_pState->m_properties, false);
224 m_pState->m_anyModified = false;
225 }
226
227 /** Collapses given category or property with children.
228 Returns true if actually collapses.
229 */
230 bool Collapse( wxPGPropArg id );
231
232 /** Collapses all items that can be collapsed.
233
234 @return
235 Return false if failed (may fail if editor value cannot be validated).
236 */
237 bool CollapseAll() { return ExpandAll(false); }
238
239 /**
240 Changes value of a property, as if from an editor.
241 Use this instead of SetPropertyValue() if you need the value to run
242 through validation process, and also send the property change event.
243
244 @return
245 Returns true if value was successfully changed.
246 */
247 bool ChangePropertyValue( wxPGPropArg id, wxVariant newValue );
248
249 /** Resets value of a property to its default. */
250 bool ClearPropertyValue( wxPGPropArg id )
251 {
252 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
253 p->SetValue(p->GetDefaultValue());
254 RefreshProperty(p);
255 return true;
256 }
257
258 /**
259 Deletes a property by id. If category is deleted, all children are
260 automatically deleted as well.
261 */
262 void DeleteProperty( wxPGPropArg id );
263
264 /** Deletes choice from a property.
265
266 If selected item is deleted, then the value is set to unspecified.
267
268 See AddPropertyChoice for more details.
269 */
270 void DeletePropertyChoice( wxPGPropArg id, int index );
271
272 /** Disables property. */
273 bool DisableProperty( wxPGPropArg id ) { return EnableProperty(id,false); }
274
275 /**
276 Returns true if all property grid data changes have been committed.
277
278 Usually only returns false if value in active editor has been
279 invalidated by a wxValidator.
280 */
281 bool EditorValidate();
282
283 /**
284 Enables or disables property, depending on whether enable is true or
285 false.
286 */
287 bool EnableProperty( wxPGPropArg id, bool enable = true );
288
289 /** Called after population of property with fixed children has finished.
290 */
291 void EndAddChildren( wxPGPropArg id );
292
293 /** Expands given category or property with children.
294 Returns true if actually expands.
295 */
296 bool Expand( wxPGPropArg id );
297
298 /** Expands all items that can be expanded.
299 */
300 bool ExpandAll( bool expand = true );
301
302 /** Returns list of expanded properties.
303 */
304 wxArrayPGProperty GetExpandedProperties() const
305 {
306 wxArrayPGProperty array;
307 GetPropertiesWithFlag(&array, wxPG_PROP_COLLAPSED, true,
308 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY|wxPG_ITERATE_HIDDEN);
309 return array;
310 }
311
312 /** Returns id of first child of given property.
313 @remarks
314 Does not return sub-properties!
315 */
316 wxPGProperty* GetFirstChild( wxPGPropArg id )
317 {
318 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty)
319
320 if ( !p->GetChildCount() || p->HasFlag(wxPG_PROP_AGGREGATE) )
321 return wxNullProperty;
322
323 return p->Item(0);
324 }
325
326 //@{
327 /** Returns iterator class instance.
328 @param flags
329 See @ref propgrid_iterator_flags. Value wxPG_ITERATE_DEFAULT causes
330 iteration over everything except private child properties.
331 @param firstProp
332 Property to start iteration from. If NULL, then first child of root
333 is used.
334 @param startPos
335 Either wxTOP or wxBOTTOM. wxTOP will indicate that iterations start
336 from the first property from the top, and wxBOTTOM means that the
337 iteration will instead begin from bottommost valid item.
338 */
339 wxPropertyGridIterator GetIterator( int flags = wxPG_ITERATE_DEFAULT,
340 wxPGProperty* firstProp = NULL )
341 {
342 return wxPropertyGridIterator( m_pState, flags, firstProp );
343 }
344
345 wxPropertyGridConstIterator
346 GetIterator( int flags = wxPG_ITERATE_DEFAULT,
347 wxPGProperty* firstProp = NULL ) const
348 {
349 return wxPropertyGridConstIterator( m_pState, flags, firstProp );
350 }
351
352 wxPropertyGridIterator GetIterator( int flags, int startPos )
353 {
354 return wxPropertyGridIterator( m_pState, flags, startPos );
355 }
356
357 wxPropertyGridConstIterator GetIterator( int flags, int startPos ) const
358 {
359 return wxPropertyGridConstIterator( m_pState, flags, startPos );
360 }
361 //@}
362
363 /** Returns id of first item, whether it is a category or property.
364 @param flags
365 @link iteratorflags List of iterator flags@endlink
366 */
367 wxPGProperty* GetFirst( int flags = wxPG_ITERATE_ALL )
368 {
369 wxPropertyGridIterator it( m_pState, flags, wxNullProperty, 1 );
370 return *it;
371 }
372
373 const wxPGProperty* GetFirst( int flags = wxPG_ITERATE_ALL ) const
374 {
375 return ((wxPropertyGridInterface*)this)->GetFirst(flags);
376 }
377
378 /**
379 Returns id of property with given name (case-sensitive).
380
381 If there is no property with such name, returned property id is invalid
382 ( i.e. it will return false with IsOk method).
383 @remarks
384 - Sub-properties (i.e. properties which have parent that is not
385 category or root) can not be accessed globally by their name.
386 Instead, use "<property>.<subproperty>" in place of "<subproperty>".
387 */
388 wxPGProperty* GetProperty( const wxString& name ) const
389 {
390 return GetPropertyByName(name);
391 }
392
393 /** Returns map-like storage of property's attributes.
394 @remarks
395 Note that if extra style wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES is set,
396 then builtin-attributes are not included in the storage.
397 */
398 const wxPGAttributeStorage& GetPropertyAttributes( wxPGPropArg id ) const
399 {
400 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(*((const wxPGAttributeStorage*)NULL));
401 return p->GetAttributes();
402 }
403
404 /** Adds to 'targetArr' pointers to properties that have given
405 flags 'flags' set. However, if 'inverse' is set to true, then
406 only properties without given flags are stored.
407 @param flags
408 Property flags to use.
409 @param iterFlags
410 Iterator flags to use. Default is everything expect private children.
411 */
412 void GetPropertiesWithFlag( wxArrayPGProperty* targetArr,
413 wxPGProperty::FlagType flags,
414 bool inverse = false,
415 int iterFlags = wxPG_ITERATE_PROPERTIES |
416 wxPG_ITERATE_HIDDEN |
417 wxPG_ITERATE_CATEGORIES) const;
418
419 /** Returns value of given attribute. If none found, returns NULL-variant.
420 */
421 wxVariant GetPropertyAttribute( wxPGPropArg id,
422 const wxString& attrName ) const
423 {
424 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullVariant)
425 return p->GetAttribute(attrName);
426 }
427
428 /** Returns pointer of property's nearest parent category. If no category
429 found, returns NULL.
430 */
431 wxPropertyCategory* GetPropertyCategory( wxPGPropArg id ) const
432 {
433 wxPG_PROP_ID_CONST_CALL_PROLOG_RETVAL(NULL)
434 return m_pState->GetPropertyCategory(p);
435 }
436
437#ifndef SWIG
438 /** Returns client data (void*) of a property. */
439 void* GetPropertyClientData( wxPGPropArg id ) const
440 {
441 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(NULL)
442 return p->GetClientData();
443 }
444#endif
445
446 /**
447 Returns first property which label matches given string.
448
449 NULL if none found. Note that this operation is extremely slow when
450 compared to GetPropertyByName().
451 */
452 wxPGProperty* GetPropertyByLabel( const wxString& label ) const;
453
454 /** Returns property with given name. NULL if none found.
455 */
456 wxPGProperty* GetPropertyByName( const wxString& name ) const;
457
458 /** Returns child property 'subname' of property 'name'. Same as
459 calling GetPropertyByName("name.subname"), albeit slightly faster.
460 */
461 wxPGProperty* GetPropertyByName( const wxString& name,
462 const wxString& subname ) const;
463
464 /** Returns writable reference to property's list of choices (and relevant
465 values). If property does not have any choices, will return reference
466 to an invalid set of choices that will return false on IsOk call.
467 */
468 wxPGChoices& GetPropertyChoices( wxPGPropArg id );
469
470 /** Returns property's editor. */
471 const wxPGEditor* GetPropertyEditor( wxPGPropArg id ) const
472 {
473 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(NULL)
474 return p->GetEditorClass();
475 }
476
477 /** Returns help string associated with a property. */
478 wxString GetPropertyHelpString( wxPGPropArg id ) const
479 {
480 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(m_emptyString)
481 return p->GetHelpString();
482 }
483
484 /** Returns property's custom value image (NULL of none). */
485 wxBitmap* GetPropertyImage( wxPGPropArg id ) const
486 {
487 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(NULL)
488 return p->GetValueImage();
489 }
490
491 /** Returns property's position under its parent. */
492 unsigned int GetPropertyIndex( wxPGPropArg id )
493 {
494 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(INT_MAX)
495 return p->GetIndexInParent();
496 }
497
498 /** Returns label of a property. */
499 const wxString& GetPropertyLabel( wxPGPropArg id )
500 {
501 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(m_emptyString)
502 return p->GetLabel();
503 }
504
505 /** Returns name of a property, by which it is globally accessible. */
506 wxString GetPropertyName( wxPGPropArg id )
507 {
508 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(m_emptyString)
509 return p->GetName();
510 }
511
512 /** Returns parent item of a property. */
513 wxPGProperty* GetPropertyParent( wxPGPropArg id )
514 {
515 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty)
516 return p->GetParent();
517 }
518
519#if wxUSE_VALIDATORS
520 /** Returns validator of a property as a reference, which you
521 can pass to any number of SetPropertyValidator.
522 */
523 wxValidator* GetPropertyValidator( wxPGPropArg id )
524 {
525 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(NULL)
526 return p->GetValidator();
527 }
528#endif
529
530 /** Returns value as wxVariant. To get wxObject pointer from it,
531 you will have to use WX_PG_VARIANT_TO_WXOBJECT(VARIANT,CLASSNAME) macro.
532
533 If property value is unspecified, Null variant is returned.
534 */
535 wxVariant GetPropertyValue( wxPGPropArg id )
536 {
537 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxVariant())
538 return p->GetValue();
539 }
540
541 wxString GetPropertyValueAsString( wxPGPropArg id ) const;
542 long GetPropertyValueAsLong( wxPGPropArg id ) const;
543 unsigned long GetPropertyValueAsULong( wxPGPropArg id ) const
544 {
545 return (unsigned long) GetPropertyValueAsLong(id);
546 }
547#ifndef SWIG
548 int GetPropertyValueAsInt( wxPGPropArg id ) const
549 { return (int)GetPropertyValueAsLong(id); }
550#endif
551 bool GetPropertyValueAsBool( wxPGPropArg id ) const;
552 double GetPropertyValueAsDouble( wxPGPropArg id ) const;
553 wxObject* GetPropertyValueAsWxObjectPtr( wxPGPropArg id ) const;
554 void* GetPropertyValueAsVoidPtr( wxPGPropArg id ) const;
555
556#define wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(TYPENAME, DEFVAL) \
557 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFVAL) \
558 if ( p->m_value.GetType() != TYPENAME ) \
559 { \
560 wxPGGetFailed(p, TYPENAME); \
561 return DEFVAL; \
562 }
563
564#define wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK(TYPENAME, DEFVAL) \
565 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFVAL) \
566 if ( p->m_value.GetType() != TYPENAME ) \
567 return DEFVAL; \
568
569 wxArrayString GetPropertyValueAsArrayString( wxPGPropArg id ) const
570 {
571 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(wxT("arrstring"),
572 wxArrayString())
573 return p->m_value.GetArrayString();
574 }
575
576 wxPoint GetPropertyValueAsPoint( wxPGPropArg id ) const
577 {
578 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(wxT("wxPoint"), wxPoint())
579 return WX_PG_VARIANT_GETVALUEREF(p->GetValue(), wxPoint);
580 }
581
582 wxSize GetPropertyValueAsSize( wxPGPropArg id ) const
583 {
584 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(wxT("wxSize"), wxSize())
585 return WX_PG_VARIANT_GETVALUEREF(p->GetValue(), wxSize);
586 }
587
588 wxLongLong_t GetPropertyValueAsLongLong( wxPGPropArg id ) const
589 {
590 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK(wxT("wxLongLong"),
591 (long) GetPropertyValueAsLong(id))
592 return WX_PG_VARIANT_GETVALUEREF(p->GetValue(), wxLongLong).GetValue();
593 }
594
595 wxULongLong_t GetPropertyValueAsULongLong( wxPGPropArg id ) const
596 {
597 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK(wxT("wxULongLong"),
598 (unsigned long) GetPropertyValueAsULong(id))
599 return WX_PG_VARIANT_GETVALUEREF(p->GetValue(), wxULongLong).GetValue();
600 }
601
602 wxArrayInt GetPropertyValueAsArrayInt( wxPGPropArg id ) const
603 {
604 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(wxT("wxArrayInt"),
605 wxArrayInt())
606 wxArrayInt arr = WX_PG_VARIANT_GETVALUEREF(p->GetValue(), wxArrayInt);
607 return arr;
608 }
609
610#if wxUSE_DATETIME
611 wxDateTime GetPropertyValueAsDateTime( wxPGPropArg id ) const
612 {
613 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxDateTime())
614
615 if ( wxStrcmp(p->m_value.GetType(), wxT("datetime")) != 0 )
616 {
617 wxPGGetFailed(p, wxT("datetime"));
618 return wxDateTime();
619 }
620 return p->m_value.GetDateTime();
621 }
622#endif
623
624#ifndef SWIG
625 /** Returns a wxVariant list containing wxVariant versions of all
626 property values. Order is not guaranteed.
627 @param flags
628 Use wxPG_KEEP_STRUCTURE to retain category structure; each sub
629 category will be its own wxVariantList of wxVariant.
630 Use wxPG_INC_ATTRIBUTES to include property attributes as well.
631 Each attribute will be stored as list variant named
632 "@@<propname>@@attr."
633 @remarks
634 */
635 wxVariant GetPropertyValues( const wxString& listname = wxEmptyString,
636 wxPGProperty* baseparent = NULL, long flags = 0 ) const
637 {
638 return m_pState->DoGetPropertyValues(listname, baseparent, flags);
639 }
640#endif
641
642 wxString GetPropertyValueType( wxPGPropArg id )
643 {
644 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(m_emptyString)
645 return p->GetValueType();
646 }
647
648 /** Returns currently selected property. */
649 wxPGProperty* GetSelection() const
650 {
651 return m_pState->GetSelection();
652 }
653
654#ifndef SWIG
655 wxPropertyGridPageState* GetState() const { return m_pState; }
656#endif
657
658 /** Similar to GetIterator(), but instead returns wxPGVIterator instance,
659 which can be useful for forward-iterating through arbitrary property
660 containers.
661
662 @param flags
663 See @ref propgrid_iterator_flags.
664 */
665 virtual wxPGVIterator GetVIterator( int flags ) const;
666
667 /** Hides or reveals a property.
668 @param hide
669 If true, hides property, otherwise reveals it.
670 @param flags
671 By default changes are applied recursively. Set this paramter
672 wxPG_DONT_RECURSE to prevent this.
673 */
674 bool HideProperty( wxPGPropArg id,
675 bool hide = true,
676 int flags = wxPG_RECURSE );
677
678#if wxPG_INCLUDE_ADVPROPS
679 /** Initializes *all* property types. Causes references to most object
680 files in the library, so calling this may cause significant increase
681 in executable size when linking with static library.
682 */
683 static void InitAllTypeHandlers();
684#else
685 static void InitAllTypeHandlers() { }
686#endif
687
688 //@{
689 /** Inserts property to the property container.
690
691 @param priorThis
692 New property is inserted just prior to this. Available only
693 in the first variant. There are two versions of this function
694 to allow this parameter to be either an id or name to
695 a property.
696
697 @param newproperty
698 Pointer to the inserted property. wxPropertyGrid will take
699 ownership of this object.
700
701 @param parent
702 New property is inserted under this category. Available only
703 in the second variant. There are two versions of this function
704 to allow this parameter to be either an id or name to
705 a property.
706
707 @param index
708 Index under category. Available only in the second variant.
709 If index is < 0, property is appended in category.
710
711 @return
712 Returns id for the property,
713
714 @remarks
715
716 - wxPropertyGrid takes the ownership of the property pointer.
717
718 - While Append may be faster way to add items, make note that when
719 both types of data storage (categoric and
720 non-categoric) are active, Insert becomes even more slow. This is
721 especially true if current mode is non-categoric.
722
723 Example of use:
724
725 @code
726
727 // append category
728 wxPGProperty* my_cat_id = propertygrid->Append(
729 new wxPropertyCategory("My Category") );
730
731 ...
732
733 // insert into category - using second variant
734 wxPGProperty* my_item_id_1 = propertygrid->Insert(
735 my_cat_id, 0, new wxStringProperty("My String 1") );
736
737 // insert before to first item - using first variant
738 wxPGProperty* my_item_id_2 = propertygrid->Insert(
739 my_item_id, new wxStringProperty("My String 2") );
740
741 @endcode
742
743 */
744 wxPGProperty* Insert( wxPGPropArg priorThis, wxPGProperty* newproperty );
745 wxPGProperty* Insert( wxPGPropArg parent,
746 int index,
747 wxPGProperty* newproperty );
748 //@}
749
750 /** Returns true if property is a category. */
751 bool IsPropertyCategory( wxPGPropArg id ) const
752 {
753 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
754 return p->IsCategory();
755 }
756
757 /** Inserts choice to a property that can accept one.
758
759 See AddPropertyChoice for more details.
760 */
761 void InsertPropertyChoice( wxPGPropArg id,
762 const wxString& label,
763 int index,
764 int value = wxPG_INVALID_VALUE );
765
766 /** Returns true if property is enabled. */
767 bool IsPropertyEnabled( wxPGPropArg id ) const
768 {
769 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
770 return (!(p->GetFlags() & wxPG_PROP_DISABLED))?true:false;
771 }
772
773 /**
774 Returns true if given property is expanded.
775
776 Naturally, always returns false for properties that cannot be expanded.
777 */
778 bool IsPropertyExpanded( wxPGPropArg id ) const;
779
780 /**
781 Returns true if property has been modified after value set or modify
782 flag clear by software.
783 */
784 bool IsPropertyModified( wxPGPropArg id ) const
785 {
786 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
787 return ( (p->GetFlags() & wxPG_PROP_MODIFIED) ? true : false );
788 }
789
790 /**
791 Returns true if property is shown (ie hideproperty with true not
792 called for it).
793 */
794 bool IsPropertyShown( wxPGPropArg id ) const
795 {
796 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
797 return (!(p->GetFlags() & wxPG_PROP_HIDDEN))?true:false;
798 }
799
800 /** Returns true if property value is set to unspecified.
801 */
802 bool IsPropertyValueUnspecified( wxPGPropArg id ) const
803 {
804 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
805 return p->IsValueUnspecified();
806 }
807
808 /**
809 Disables (limit = true) or enables (limit = false) wxTextCtrl editor of
810 a property, if it is not the sole mean to edit the value.
811 */
812 void LimitPropertyEditing( wxPGPropArg id, bool limit = true );
813
814 /** If state is shown in it's grid, refresh it now.
815 */
816 virtual void RefreshGrid( wxPropertyGridPageState* state = NULL );
817
818#if wxPG_INCLUDE_ADVPROPS
819 /**
820 Initializes additional property editors (SpinCtrl etc.). Causes
821 references to most object files in the library, so calling this may
822 cause significant increase in executable size when linking with static
823 library.
824 */
825 static void RegisterAdditionalEditors();
826#else
827 static void RegisterAdditionalEditors() { }
828#endif
829
830 /** Replaces property with id with newly created property. For example,
831 this code replaces existing property named "Flags" with one that
832 will have different set of items:
833 @code
834 pg->ReplaceProperty("Flags",
835 wxFlagsProperty("Flags", wxPG_LABEL, newItems))
836 @endcode
837 For more info, see wxPropertyGrid::Insert.
838 */
839 wxPGProperty* ReplaceProperty( wxPGPropArg id, wxPGProperty* property );
840
841 /** @anchor propgridinterface_editablestate_flags
842
843 Flags for wxPropertyGridInterface::SaveEditableState() and
844 wxPropertyGridInterface::RestoreEditableState().
845 */
846 enum EditableStateFlags
847 {
848 /** Include selected property. */
849 SelectionState = 0x01,
850 /** Include expanded/collapsed property information. */
851 ExpandedState = 0x02,
852 /** Include scrolled position. */
853 ScrollPosState = 0x04,
854 /** Include selected page information.
855 Only applies to wxPropertyGridManager. */
856 PageState = 0x08,
857 /** Include splitter position. Stored for each page. */
858 SplitterPosState = 0x10,
859
860 /**
861 Include all supported user editable state information.
862 This is usually the default value. */
863 AllStates = SelectionState |
864 ExpandedState |
865 ScrollPosState |
866 PageState |
867 SplitterPosState
868 };
869
870 /**
871 Restores user-editable state.
872
873 See also wxPropertyGridInterface::SaveEditableState().
874
875 @param src
876 String generated by SaveEditableState.
877
878 @param restoreStates
879 Which parts to restore from source string. See @ref
880 propgridinterface_editablestate_flags "list of editable state
881 flags".
882
883 @return
884 False if there was problem reading the string.
885
886 @remarks
887 If some parts of state (such as scrolled or splitter position) fail to
888 restore correctly, please make sure that you call this function after
889 wxPropertyGrid size has been set (this may sometimes be tricky when
890 sizers are used).
891 */
892 bool RestoreEditableState( const wxString& src,
893 int restoreStates = AllStates );
894
895 /**
896 Used to acquire user-editable state (selected property, expanded
897 properties, scrolled position, splitter positions).
898
899 @param includedStates
900 Which parts of state to include. See @ref
901 propgridinterface_editablestate_flags "list of editable state flags".
902 */
903 wxString SaveEditableState( int includedStates = AllStates ) const;
904
905 /**
906 Lets user to set the strings listed in the choice dropdown of a
907 wxBoolProperty. Defaults are "True" and "False", so changing them to,
908 say, "Yes" and "No" may be useful in some less technical applications.
909 */
910 static void SetBoolChoices( const wxString& trueChoice,
911 const wxString& falseChoice );
912
913 /** Sets or clears flag(s) of all properties in given array.
914 @param flags
915 Property flags to set or clear.
916 @param inverse
917 Set to true if you want to clear flag instead of setting them.
918 */
919 void SetPropertiesFlag( const wxArrayPGProperty& srcArr,
920 wxPGProperty::FlagType flags,
921 bool inverse = false );
922
923 /** Sets an attribute for this property.
924 @param name
925 Text identifier of attribute. See @ref propgrid_property_attributes.
926 @param value
927 Value of attribute.
928 @param argFlags
929 Optional. Use wxPG_RECURSE to set the attribute to child properties
930 recursively.
931 */
932 void SetPropertyAttribute( wxPGPropArg id,
933 const wxString& attrName,
934 wxVariant value,
935 long argFlags = 0 )
936 {
937 DoSetPropertyAttribute(id,attrName,value,argFlags);
938 }
939
940 /** Sets attributes from a wxPGAttributeStorage.
941 */
942 void SetPropertyAttributes( wxPGPropArg id,
943 const wxPGAttributeStorage& attributes )
944 {
945 wxPG_PROP_ARG_CALL_PROLOG()
946 p->SetAttributes(attributes);
947 }
948
949 /** Sets text, bitmap, and colours for given column's cell.
950
951 @remarks
952 - You can set label cell by setting column to 0.
953 - You can use wxPG_LABEL as text to use default text for column.
954 */
955 void SetPropertyCell( wxPGPropArg id,
956 int column,
957 const wxString& text = wxEmptyString,
958 const wxBitmap& bitmap = wxNullBitmap,
959 const wxColour& fgCol = wxNullColour,
960 const wxColour& bgCol = wxNullColour )
961 {
962 wxPG_PROP_ARG_CALL_PROLOG()
963 p->SetCell( column, new wxPGCell(text, bitmap, fgCol, bgCol) );
964 }
965
966 /** Set choices of a property to specified set of labels and values.
967
968 @remarks
969 This operation clears the property value.
970 */
971 void SetPropertyChoices( wxPGPropArg id, wxPGChoices& choices)
972 {
973 wxPG_PROP_ARG_CALL_PROLOG()
974 p->SetChoices(choices);
975 }
976
977
978 /**
979 If property's set of choices is shared, then calling this method
980 converts it to private.
981 */
982 void SetPropertyChoicesExclusive( wxPGPropArg id )
983 {
984 wxPG_PROP_ARG_CALL_PROLOG()
985 p->SetChoicesExclusive();
986 }
987
988#ifndef SWIG
989 /** Sets client data (void*) of a property.
990 @remarks
991 This untyped client data has to be deleted manually.
992 */
993 void SetPropertyClientData( wxPGPropArg id, void* clientData )
994 {
995 wxPG_PROP_ARG_CALL_PROLOG()
996 p->SetClientData(clientData);
997 }
998
999 /** Sets editor for a property.
1000
1001 @param editor
1002 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1003 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full
1004 list).
1005
1006 For custom editors, use pointer you received from
1007 wxPropertyGrid::RegisterEditorClass().
1008 */
1009 void SetPropertyEditor( wxPGPropArg id, const wxPGEditor* editor )
1010 {
1011 wxPG_PROP_ARG_CALL_PROLOG()
1012 wxCHECK_RET( editor, wxT("unknown/NULL editor") );
1013 p->SetEditor(editor);
1014 RefreshProperty(p);
1015 }
1016#endif
1017
1018 /** Sets editor control of a property. As editor argument, use
1019 editor name string, such as "TextCtrl" or "Choice".
1020 */
1021 void SetPropertyEditor( wxPGPropArg id, const wxString& editorName )
1022 {
1023 SetPropertyEditor(id,GetEditorByName(editorName));
1024 }
1025
1026 /** Sets label of a property.
1c4293cb
VZ
1027 */
1028 void SetPropertyLabel( wxPGPropArg id, const wxString& newproplabel );
1029
1030 /** Set modified status of a property and all its children.
1031 */
1032 void SetPropertyModifiedStatus( wxPGPropArg id, bool modified )
1033 {
1034 wxPG_PROP_ARG_CALL_PROLOG()
1035 p->SetModifiedStatus(modified);
1036 }
1037
1038 /**
1039 Sets property (and, recursively, its children) to have read-only value.
1040 In other words, user cannot change the value in the editor, but they
1041 can still copy it.
1042 @remarks
1043 This is mainly for use with textctrl editor. Not all other editors fully
1044 support it.
1045 @param flags
1046 By default changes are applied recursively. Set this paramter
1047 wxPG_DONT_RECURSE to prevent this.
1048 */
1049 void SetPropertyReadOnly( wxPGPropArg id,
1050 bool set = true,
1051 int flags = wxPG_RECURSE )
1052 {
1053 wxPG_PROP_ARG_CALL_PROLOG()
1054 if ( flags & wxPG_RECURSE )
1055 p->SetFlagRecursively(wxPG_PROP_READONLY, set);
1056 else
1057 p->SetFlag(wxPG_PROP_READONLY);
1058 }
1059
1060 /** Sets property's value to unspecified.
1061 If it has children (it may be category), then the same thing is done to
1062 them.
1063 */
1064 void SetPropertyValueUnspecified( wxPGPropArg id );
1065
1066#ifndef SWIG
1067 /** Sets various property values from a list of wxVariants. If property with
1068 name is missing from the grid, new property is created under given
1069 default category (or root if omitted).
1070 */
1071 void SetPropertyValues( const wxVariantList& list,
1072 wxPGPropArg defaultCategory = wxNullProperty )
1073 {
1074 wxPGProperty *p;
1075 if ( defaultCategory.HasName() ) p = defaultCategory.GetPtr(this);
1076 else p = defaultCategory.GetPtr0();
1077 m_pState->DoSetPropertyValues(list, p);
1078 }
1079
1080 void SetPropertyValues( const wxVariant& list,
1081 wxPGPropArg defaultCategory = wxNullProperty )
1082 {
1083 SetPropertyValues(list.GetList(),defaultCategory);
1084 }
1085#endif
1086
1087 /** Associates the help string with property.
1088 @remarks
1089 By default, text is shown either in the manager's "description"
1090 text box or in the status bar. If extra window style
1091 wxPG_EX_HELP_AS_TOOLTIPS is used, then the text will appear as a
1092 tooltip.
1093 */
1094 void SetPropertyHelpString( wxPGPropArg id, const wxString& helpString )
1095 {
1096 wxPG_PROP_ARG_CALL_PROLOG()
1097 p->SetHelpString(helpString);
1098 }
1099
1100 /** Set wxBitmap in front of the value.
1101 @remarks
1102 - Bitmap will be scaled to a size returned by
1103 wxPropertyGrid::GetImageSize();
1104 */
1105 void SetPropertyImage( wxPGPropArg id, wxBitmap& bmp )
1106 {
1107 wxPG_PROP_ARG_CALL_PROLOG()
1108 p->SetValueImage(bmp);
1109 RefreshProperty(p);
1110 }
1111
1112 /** Sets max length of property's text.
1113 */
1114 bool SetPropertyMaxLength( wxPGPropArg id, int maxLen );
1115
1116#if wxUSE_VALIDATORS
1117 /** Sets validator of a property.
1118 */
1119 void SetPropertyValidator( wxPGPropArg id, const wxValidator& validator )
1120 {
1121 wxPG_PROP_ARG_CALL_PROLOG()
1122 p->SetValidator(validator);
1123 }
1124#endif
1125
1126#ifndef SWIG
1127 /** Sets value (long integer) of a property.
1128 */
1129 void SetPropertyValue( wxPGPropArg id, long value )
1130 {
1131 wxVariant v(value);
1132 SetPropVal( id, v );
1133 }
1134
1135 /** Sets value (integer) of a property.
1136 */
1137 void SetPropertyValue( wxPGPropArg id, int value )
1138 {
1139 wxVariant v((long)value);
1140 SetPropVal( id, v );
1141 }
1142 /** Sets value (floating point) of a property.
1143 */
1144 void SetPropertyValue( wxPGPropArg id, double value )
1145 {
1146 wxVariant v(value);
1147 SetPropVal( id, v );
1148 }
1149 /** Sets value (bool) of a property.
1150 */
1151 void SetPropertyValue( wxPGPropArg id, bool value )
1152 {
1153 wxVariant v(value);
1154 SetPropVal( id, v );
1155 }
1156 void SetPropertyValue( wxPGPropArg id, const wxChar* value )
1157 {
1158 SetPropertyValueString( id, wxString(value) );
1159 }
1160 void SetPropertyValue( wxPGPropArg id, const wxString& value )
1161 {
1162 SetPropertyValueString( id, value );
1163 }
1164
1165 /** Sets value (wxArrayString) of a property.
1166 */
1167 void SetPropertyValue( wxPGPropArg id, const wxArrayString& value )
1168 {
1169 wxVariant v(value);
1170 SetPropVal( id, v );
1171 }
1172
1173#if wxUSE_DATETIME
1174 void SetPropertyValue( wxPGPropArg id, const wxDateTime& value )
1175 {
1176 wxVariant v(value);
1177 SetPropVal( id, v );
1178 }
1179#endif
1180
1181 /** Sets value (wxObject*) of a property.
1182 */
1183 void SetPropertyValue( wxPGPropArg id, wxObject* value )
1184 {
1185 wxVariant v(value);
1186 SetPropVal( id, v );
1187 }
1188
1189 void SetPropertyValue( wxPGPropArg id, wxObject& value )
1190 {
1191 wxVariant v(&value);
1192 SetPropVal( id, v );
1193 }
1194
1195 /** Sets value (wxPoint&) of a property.
1196 */
1197 void SetPropertyValue( wxPGPropArg id, const wxPoint& value )
1198 {
1199 wxVariant v = WXVARIANT(value);
1200 SetPropVal( id, v );
1201 }
1202 /** Sets value (wxSize&) of a property.
1203 */
1204 void SetPropertyValue( wxPGPropArg id, const wxSize& value )
1205 {
1206 wxVariant v = WXVARIANT(value);
1207 SetPropVal( id, v );
1208 }
1209 /** Sets value (wxLongLong&) of a property.
1210 */
1211 void SetPropertyValue( wxPGPropArg id, wxLongLong_t value )
1212 {
1213 wxVariant v = WXVARIANT(wxLongLong(value));
1214 SetPropVal( id, v );
1215 }
1216 /** Sets value (wxULongLong&) of a property.
1217 */
1218 void SetPropertyValue( wxPGPropArg id, wxULongLong_t value )
1219 {
1220 wxVariant v = WXVARIANT(wxULongLong(value));
1221 SetPropVal( id, v );
1222 }
1223 /** Sets value (wxArrayInt&) of a property.
1224 */
1225 void SetPropertyValue( wxPGPropArg id, const wxArrayInt& value )
1226 {
1227 wxVariant v = WXVARIANT(value);
1228 SetPropVal( id, v );
1229 }
1230#endif // !SWIG
1231
1232 /** Sets value (wxString) of a property.
1233
1234 @remarks
1235 This method uses wxPGProperty::SetValueFromString, which all properties
1236 should implement. This means that there should not be a type error,
1237 and instead the string is converted to property's actual value type.
1238 */
1239 void SetPropertyValueString( wxPGPropArg id, const wxString& value );
1240
1241 /** Sets value (wxVariant&) of a property.
1242
1243 @remarks
1244 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run
1245 through validation process and send property change event.
1246 */
1247 void SetPropertyValue( wxPGPropArg id, wxVariant value )
1248 {
1249 SetPropVal( id, value );
1250 }
1251
1252#ifndef SWIG
1253 /** Sets value (wxVariant&) of a property. Same as SetPropertyValue, but
1254 accepts reference. */
1255 void SetPropVal( wxPGPropArg id, wxVariant& value );
1256#endif
1257
1258 /** Adjusts how wxPropertyGrid behaves when invalid value is entered
1259 in a property.
1260 @param vfbFlags
1261 See @link vfbflags list of valid flags values@endlink
1262 */
1263 void SetValidationFailureBehavior( int vfbFlags );
1264
1265#ifdef SWIG
1266 %pythoncode {
1267 def MapType(class_,factory):
1268 "Registers Python type/class to property mapping.\n\nfactory: Property builder function/class."
1269 global _type2property
1270 try:
1271 mappings = _type2property
1272 except NameError:
1273 raise AssertionError("call only after a propertygrid or manager instance constructed")
1274
1275 mappings[class_] = factory
1276
1277
1278 def DoDefaultTypeMappings(self):
1279 "Map built-in properties."
1280 global _type2property
1281 try:
1282 mappings = _type2property
1283
1284 return
1285 except NameError:
1286 mappings = {}
1287 _type2property = mappings
1288
1289 mappings[str] = StringProperty
1290 mappings[unicode] = StringProperty
1291 mappings[int] = IntProperty
1292 mappings[float] = FloatProperty
1293 mappings[bool] = BoolProperty
1294 mappings[list] = ArrayStringProperty
1295 mappings[tuple] = ArrayStringProperty
1296 mappings[wx.Font] = FontProperty
1297 mappings[wx.Colour] = ColourProperty
1298 "mappings[wx.Size] = SizeProperty"
1299 "mappings[wx.Point] = PointProperty"
1300 "mappings[wx.FontData] = FontDataProperty"
1301
1302 def DoDefaultValueTypeMappings(self):
1303 "Map pg value type ids to getter methods."
1304 global _vt2getter
1305 try:
1306 vt2getter = _vt2getter
1307
1308 return
1309 except NameError:
1310 vt2getter = {}
1311 _vt2getter = vt2getter
1312
1313 def GetPropertyValues(self,dict_=None, as_strings=False, inc_attributes=False):
1314 "Returns values in the grid."
1315 ""
1316 "dict_: if not given, then a new one is created. dict_ can be"
1317 " object as well, in which case it's __dict__ is used."
1318 "as_strings: if True, then string representations of values"
1319 " are fetched instead of native types. Useful for config and such."
1320 "inc_attributes: if True, then property attributes are added"
1321 " as @<propname>@<attr>."
1322 ""
1323 "Return value: dictionary with values. It is always a dictionary,"
1324 "so if dict_ was object with __dict__ attribute, then that attribute"
1325 "is returned."
1326
1327 if dict_ is None:
1328 dict_ = {}
1329 elif hasattr(dict_,'__dict__'):
1330 dict_ = dict_.__dict__
1331
1332 if not as_strings:
1333 getter = self.GetPropertyValue
1334 else:
1335 getter = self.GetPropertyValueAsString
1336
1337 it = self.GetVIterator(PG_ITERATE_PROPERTIES)
1338 while not it.AtEnd():
1339 p = it.GetProperty()
1340 name = p.GetName()
1341
1342 dict_[name] = getter(p)
1343
1344 if inc_attributes:
1345 attrs = p.GetAttributes()
1346 if attrs and len(attrs):
1347 dict_['@%s@attr'%name] = attrs
1348
1349 it.Next()
1350
1351 return dict_
1352
1353 GetValues = GetPropertyValues
1354
1355
1356 def SetPropertyValues(self,dict_):
1357 "Sets property values from dict_, which can be either\ndictionary or an object with __dict__ attribute."
1358 ""
1359 "autofill: If true, keys with not relevant properties"
1360 " are auto-created. For more info, see AutoFill."
1361 ""
1362 "Notes:"
1363 " * Keys starting with underscore are ignored."
1364 " * Attributes can be set with entries named @<propname>@<attr>."
1365 ""
1366
1367 autofill = False
1368
1369 if dict_ is None:
1370 dict_ = {}
1371 elif hasattr(dict_,'__dict__'):
1372 dict_ = dict_.__dict__
1373
1374 attr_dicts = []
1375
1376 def set_sub_obj(k0,dict_):
1377 for k,v in dict_.iteritems():
1378 if k[0] != '_':
1379 if k.endswith('@attr'):
1380 attr_dicts.append((k[1:-5],v))
1381 else:
1382 try:
1383 self.SetPropertyValue(k,v)
1384 except:
1385 try:
1386 if autofill:
1387 self._AutoFillOne(k0,k,v)
1388 continue
1389 except:
1390 if isinstance(v,dict):
1391 set_sub_obj(k,v)
1392 elif hasattr(v,'__dict__'):
1393 set_sub_obj(k,v.__dict__)
1394
1395
1396 for k,v in attr_dicts:
1397 p = GetPropertyByName(k)
1398 if not p:
1399 raise AssertionError("No such property: '%s'"%k)
1400 for an,av in v.iteritems():
1401 p.SetAttribute(an, av)
1402
1403
1404 cur_page = False
1405 is_manager = isinstance(self,PropertyGridManager)
1406
1407 try:
1408 set_sub_obj(self.GetGrid().GetRoot(),dict_)
1409 except:
1410 import traceback
1411 traceback.print_exc()
1412
1413 self.Refresh()
1414
1415 SetValues = SetPropertyValues
1416
1417 def _AutoFillMany(self,cat,dict_):
1418 for k,v in dict_.iteritems():
1419 self._AutoFillOne(cat,k,v)
1420
1421
1422 def _AutoFillOne(self,cat,k,v):
1423 global _type2property
1424
1425 factory = _type2property.get(v.__class__,None)
1426
1427 if factory:
1428 self.AppendIn( cat, factory(k,k,v) )
1429 elif hasattr(v,'__dict__'):
1430 cat2 = self.AppendIn( cat, PropertyCategory(k) )
1431 self._AutoFillMany(cat2,v.__dict__)
1432 elif isinstance(v,dict):
1433 cat2 = self.AppendIn( cat, PropertyCategory(k) )
1434 self._AutoFillMany(cat2,v)
1435 elif not k.startswith('_'):
1436 raise AssertionError("member '%s' is of unregisted type/class '%s'"%(k,v.__class__))
1437
1438
1439 def AutoFill(self,obj,parent=None):
1440 "Clears properties and re-fills to match members and\nvalues of given object or dictionary obj."
1441
1442 self.edited_objects[parent] = obj
1443
1444 cur_page = False
1445 is_manager = isinstance(self,PropertyGridManager)
1446
1447 if not parent:
1448 if is_manager:
1449 page = self.GetCurrentPage()
1450 page.Clear()
1451 parent = page.GetRoot()
1452 else:
1453 self.Clear()
1454 parent = self.GetGrid().GetRoot()
1455 else:
1456 it = self.GetIterator(PG_ITERATE_PROPERTIES, parent)
1457 it.Next() # Skip the parent
1458 while not it.AtEnd():
1459 p = it.GetProperty()
1460 if not p.IsSomeParent(parent):
1461 break
1462
1463 self.DeleteProperty(p)
1464
1465 name = p.GetName()
1466 it.Next()
1467
1468 if not is_manager or page == self.GetCurrentPage():
1469 self.Freeze()
1470 cur_page = True
1471
1472 try:
1473 self._AutoFillMany(parent,obj.__dict__)
1474 except:
1475 import traceback
1476 traceback.print_exc()
1477
1478 if cur_page:
1479 self.Thaw()
1480
1481 def RegisterEditor(self, editor, editorName=None):
1482 "Transform class into instance, if necessary."
1483 if not isinstance(editor, PGEditor):
1484 editor = editor()
1485 if not editorName:
1486 editorName = editor.__class__.__name__
1487 try:
1488 self._editor_instances.append(editor)
1489 except:
1490 self._editor_instances = [editor]
1491 RegisterEditor(editor, editorName)
1492
1493 def GetPropertyClientData(self, p):
1494 if isinstance(p, basestring):
1495 p = self.GetPropertyByName(p)
1496 return p.GetClientData()
1497
1498 def SetPropertyClientData(self, p, data):
1499 if isinstance(p, basestring):
1500 p = self.GetPropertyByName(p)
1501 return p.SetClientData(data)
1502 }
1503#endif
1504
1505 // GetPropertyByName With nice assertion error message.
1506 wxPGProperty* GetPropertyByNameA( const wxString& name ) const;
1507
1508 static wxPGEditor* GetEditorByName( const wxString& editorName );
1509
1510 virtual void RefreshProperty( wxPGProperty* p ) = 0;
1511
1512protected:
1513
1514 // Returns page state data for given (sub) page (-1 means current page).
1515 virtual wxPropertyGridPageState* GetPageState( int pageIndex ) const
1516 {
1517 if ( pageIndex <= 0 )
1518 return m_pState;
1519 return NULL;
1520 }
1521
1522 virtual bool DoSelectPage( int WXUNUSED(index) ) { return true; }
1523
1524 // Default call's m_pState's BaseGetPropertyByName
1525 virtual wxPGProperty* DoGetPropertyByName( const wxString& name ) const;
1526
1527#ifndef SWIG
1528
1529 // Deriving classes must set this (it must be only or current page).
1530 wxPropertyGridPageState* m_pState;
1531
1532 // Intermediate version needed due to wxVariant copying inefficiency
1533 void DoSetPropertyAttribute( wxPGPropArg id,
1534 const wxString& name,
1535 wxVariant& value, long argFlags );
1536
1537 // Empty string object to return from member functions returning const
1538 // wxString&.
1539 wxString m_emptyString;
1540
1541private:
1542 // Cannot be GetGrid() due to ambiguity issues.
1543 wxPropertyGrid* GetPropertyGrid()
1544 {
1545 return m_pState->GetGrid();
1546 }
1547
1548 // Cannot be GetGrid() due to ambiguity issues.
1549 const wxPropertyGrid* GetPropertyGrid() const
1550 {
1551 return (const wxPropertyGrid*) m_pState->GetGrid();
1552 }
1553#endif // #ifndef SWIG
1554
1555 friend class wxPropertyGrid;
1556 friend class wxPropertyGridManager;
1557};
1558
1559#endif // __WX_PROPGRID_PROPGRIDIFACE_H__