1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgeid/propgridiface.h
3 // Purpose: wxPropertyGridInterface class
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef __WX_PROPGRID_PROPGRIDIFACE_H__
13 #define __WX_PROPGRID_PROPGRIDIFACE_H__
15 #include "wx/propgrid/property.h"
16 #include "wx/propgrid/propgridpagestate.h"
18 // -----------------------------------------------------------------------
22 /** @section wxPGPropArgCls
24 Most property grid functions have this type as their argument, as it can
25 convey a property by either a pointer or name.
27 class WXDLLIMPEXP_PROPGRID wxPGPropArgCls
31 wxPGPropArgCls( const wxPGProperty
* property
)
33 m_ptr
.property
= (wxPGProperty
*) property
;
36 wxPGPropArgCls( const wxString
& str
)
38 m_ptr
.stringName
= &str
;
41 wxPGPropArgCls( const wxPGPropArgCls
& id
)
46 // This is only needed for wxPython bindings
47 wxPGPropArgCls( wxString
* str
, bool WXUNUSED(deallocPtr
) )
49 m_ptr
.stringName
= str
;
50 m_flags
= IsWxString
| OwnsWxString
;
54 if ( m_flags
& OwnsWxString
)
55 delete m_ptr
.stringName
;
57 wxPGProperty
* GetPtr() const
59 wxCHECK( m_flags
== IsProperty
, NULL
);
60 return m_ptr
.property
;
62 wxPGPropArgCls( const char* str
)
68 wxPGPropArgCls( const wchar_t* str
)
70 m_ptr
.wcharName
= str
;
74 /** This constructor is required for NULL. */
77 m_ptr
.property
= (wxPGProperty
*) NULL
;
80 wxPGProperty
* GetPtr( wxPropertyGridInterface
* iface
) const;
81 wxPGProperty
* GetPtr( const wxPropertyGridInterface
* iface
) const
83 return GetPtr((wxPropertyGridInterface
*)iface
);
85 wxPGProperty
* GetPtr0() const { return m_ptr
.property
; }
86 bool HasName() const { return (m_flags
!= IsProperty
); }
87 const wxString
& GetName() const { return *m_ptr
.stringName
; }
101 wxPGProperty
* property
;
102 const char* charName
;
104 const wchar_t* wcharName
;
106 const wxString
* stringName
;
108 unsigned char m_flags
;
113 typedef const wxPGPropArgCls
& wxPGPropArg
;
115 // -----------------------------------------------------------------------
118 void wxPGTypeOperationFailed( const wxPGProperty
* p
,
119 const wxString
& typestr
,
120 const wxString
& op
);
122 void wxPGGetFailed( const wxPGProperty
* p
, const wxString
& typestr
);
124 // -----------------------------------------------------------------------
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); \
132 #define wxPG_PROP_ARG_CALL_PROLOG_RETVAL_0(PROPERTY, RETVAL) \
133 PROPERTY *p = (PROPERTY*)id.GetPtr(this); \
134 if ( !p ) return RETVAL;
136 #define wxPG_PROP_ARG_CALL_PROLOG() \
137 wxPG_PROP_ARG_CALL_PROLOG_0(wxPGProperty)
139 #define wxPG_PROP_ARG_CALL_PROLOG_RETVAL(RVAL) \
140 wxPG_PROP_ARG_CALL_PROLOG_RETVAL_0(wxPGProperty, RVAL)
142 #define wxPG_PROP_ID_CONST_CALL_PROLOG() \
143 wxPG_PROP_ARG_CALL_PROLOG_0(const wxPGProperty)
145 #define wxPG_PROP_ID_CONST_CALL_PROLOG_RETVAL(RVAL) \
146 wxPG_PROP_ARG_CALL_PROLOG_RETVAL_0(const wxPGProperty, RVAL)
148 // -----------------------------------------------------------------------
151 /** @class wxPropertyGridInterface
153 Most of the shared property manipulation interface shared by wxPropertyGrid,
154 wxPropertyGridPage, and wxPropertyGridManager is defined in this class.
157 - In separate wxPropertyGrid component this class was known as
158 wxPropertyContainerMethods.
163 class WXDLLIMPEXP_PROPGRID wxPropertyGridInterface
168 virtual ~wxPropertyGridInterface() { }
170 /** Adds choice to a property that can accept one.
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
180 void AddPropertyChoice( wxPGPropArg id
,
181 const wxString
& label
,
182 int value
= wxPG_INVALID_VALUE
);
185 Appends property to the list.
187 wxPropertyGrid assumes ownership of the object.
188 Becomes child of most recently added category.
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
200 wxPGProperty
* Append( wxPGProperty
* property
);
202 wxPGProperty
* AppendIn( wxPGPropArg id
, wxPGProperty
* newproperty
);
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.
209 void BeginAddChildren( wxPGPropArg id
);
211 /** Deletes all properties.
213 virtual void Clear() = 0;
215 /** Deselect current selection, if any. Returns true if success
216 (ie. validator did not intercept). */
217 bool ClearSelection();
219 /** Resets modified status of all properties.
221 void ClearModifiedStatus()
223 SetPropertyModifiedStatus(m_pState
->m_properties
, false);
224 m_pState
->m_anyModified
= false;
227 /** Collapses given category or property with children.
228 Returns true if actually collapses.
230 bool Collapse( wxPGPropArg id
);
232 /** Collapses all items that can be collapsed.
235 Return false if failed (may fail if editor value cannot be validated).
237 bool CollapseAll() { return ExpandAll(false); }
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.
245 Returns true if value was successfully changed.
247 bool ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
);
249 /** Resets value of a property to its default. */
250 bool ClearPropertyValue( wxPGPropArg id
)
252 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
253 p
->SetValue(p
->GetDefaultValue());
259 Deletes a property by id. If category is deleted, all children are
260 automatically deleted as well.
262 void DeleteProperty( wxPGPropArg id
);
264 /** Deletes choice from a property.
266 If selected item is deleted, then the value is set to unspecified.
268 See AddPropertyChoice for more details.
270 void DeletePropertyChoice( wxPGPropArg id
, int index
);
272 /** Disables property. */
273 bool DisableProperty( wxPGPropArg id
) { return EnableProperty(id
,false); }
276 Returns true if all property grid data changes have been committed.
278 Usually only returns false if value in active editor has been
279 invalidated by a wxValidator.
281 bool EditorValidate();
284 Enables or disables property, depending on whether enable is true or
287 bool EnableProperty( wxPGPropArg id
, bool enable
= true );
289 /** Called after population of property with fixed children has finished.
291 void EndAddChildren( wxPGPropArg id
);
293 /** Expands given category or property with children.
294 Returns true if actually expands.
296 bool Expand( wxPGPropArg id
);
298 /** Expands all items that can be expanded.
300 bool ExpandAll( bool expand
= true );
302 /** Returns list of expanded properties.
304 wxArrayPGProperty
GetExpandedProperties() const
306 wxArrayPGProperty array
;
307 GetPropertiesWithFlag(&array
, wxPG_PROP_COLLAPSED
, true,
308 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
|wxPG_ITERATE_HIDDEN
);
312 /** Returns id of first child of given property.
314 Does not return sub-properties!
316 wxPGProperty
* GetFirstChild( wxPGPropArg id
)
318 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
320 if ( !p
->GetChildCount() || p
->HasFlag(wxPG_PROP_AGGREGATE
) )
321 return wxNullProperty
;
327 /** Returns iterator class instance.
329 See @ref propgrid_iterator_flags. Value wxPG_ITERATE_DEFAULT causes
330 iteration over everything except private child properties.
332 Property to start iteration from. If NULL, then first child of root
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.
339 wxPropertyGridIterator
GetIterator( int flags
= wxPG_ITERATE_DEFAULT
,
340 wxPGProperty
* firstProp
= NULL
)
342 return wxPropertyGridIterator( m_pState
, flags
, firstProp
);
345 wxPropertyGridConstIterator
346 GetIterator( int flags
= wxPG_ITERATE_DEFAULT
,
347 wxPGProperty
* firstProp
= NULL
) const
349 return wxPropertyGridConstIterator( m_pState
, flags
, firstProp
);
352 wxPropertyGridIterator
GetIterator( int flags
, int startPos
)
354 return wxPropertyGridIterator( m_pState
, flags
, startPos
);
357 wxPropertyGridConstIterator
GetIterator( int flags
, int startPos
) const
359 return wxPropertyGridConstIterator( m_pState
, flags
, startPos
);
363 /** Returns id of first item, whether it is a category or property.
365 @link iteratorflags List of iterator flags@endlink
367 wxPGProperty
* GetFirst( int flags
= wxPG_ITERATE_ALL
)
369 wxPropertyGridIterator
it( m_pState
, flags
, wxNullProperty
, 1 );
373 const wxPGProperty
* GetFirst( int flags
= wxPG_ITERATE_ALL
) const
375 return ((wxPropertyGridInterface
*)this)->GetFirst(flags
);
379 Returns id of property with given name (case-sensitive).
381 If there is no property with such name, returned property id is invalid
382 ( i.e. it will return false with IsOk method).
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>".
388 wxPGProperty
* GetProperty( const wxString
& name
) const
390 return GetPropertyByName(name
);
393 /** Returns map-like storage of property's attributes.
395 Note that if extra style wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES is set,
396 then builtin-attributes are not included in the storage.
398 const wxPGAttributeStorage
& GetPropertyAttributes( wxPGPropArg id
) const
400 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(*((const wxPGAttributeStorage
*)NULL
));
401 return p
->GetAttributes();
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.
408 Property flags to use.
410 Iterator flags to use. Default is everything expect private children.
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;
419 /** Returns value of given attribute. If none found, returns NULL-variant.
421 wxVariant
GetPropertyAttribute( wxPGPropArg id
,
422 const wxString
& attrName
) const
424 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullVariant
)
425 return p
->GetAttribute(attrName
);
428 /** Returns pointer of property's nearest parent category. If no category
431 wxPropertyCategory
* GetPropertyCategory( wxPGPropArg id
) const
433 wxPG_PROP_ID_CONST_CALL_PROLOG_RETVAL(NULL
)
434 return m_pState
->GetPropertyCategory(p
);
438 /** Returns client data (void*) of a property. */
439 void* GetPropertyClientData( wxPGPropArg id
) const
441 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(NULL
)
442 return p
->GetClientData();
447 Returns first property which label matches given string.
449 NULL if none found. Note that this operation is extremely slow when
450 compared to GetPropertyByName().
452 wxPGProperty
* GetPropertyByLabel( const wxString
& label
) const;
454 /** Returns property with given name. NULL if none found.
456 wxPGProperty
* GetPropertyByName( const wxString
& name
) const;
458 /** Returns child property 'subname' of property 'name'. Same as
459 calling GetPropertyByName("name.subname"), albeit slightly faster.
461 wxPGProperty
* GetPropertyByName( const wxString
& name
,
462 const wxString
& subname
) const;
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.
468 wxPGChoices
& GetPropertyChoices( wxPGPropArg id
);
470 /** Returns property's editor. */
471 const wxPGEditor
* GetPropertyEditor( wxPGPropArg id
) const
473 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(NULL
)
474 return p
->GetEditorClass();
477 /** Returns help string associated with a property. */
478 wxString
GetPropertyHelpString( wxPGPropArg id
) const
480 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(m_emptyString
)
481 return p
->GetHelpString();
484 /** Returns property's custom value image (NULL of none). */
485 wxBitmap
* GetPropertyImage( wxPGPropArg id
) const
487 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(NULL
)
488 return p
->GetValueImage();
491 /** Returns property's position under its parent. */
492 unsigned int GetPropertyIndex( wxPGPropArg id
)
494 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(INT_MAX
)
495 return p
->GetIndexInParent();
498 /** Returns label of a property. */
499 const wxString
& GetPropertyLabel( wxPGPropArg id
)
501 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(m_emptyString
)
502 return p
->GetLabel();
505 /** Returns name of a property, by which it is globally accessible. */
506 wxString
GetPropertyName( wxPGPropArg id
)
508 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(m_emptyString
)
512 /** Returns parent item of a property. */
513 wxPGProperty
* GetPropertyParent( wxPGPropArg id
)
515 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
516 return p
->GetParent();
520 /** Returns validator of a property as a reference, which you
521 can pass to any number of SetPropertyValidator.
523 wxValidator
* GetPropertyValidator( wxPGPropArg id
)
525 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(NULL
)
526 return p
->GetValidator();
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.
533 If property value is unspecified, Null variant is returned.
535 wxVariant
GetPropertyValue( wxPGPropArg id
)
537 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxVariant())
538 return p
->GetValue();
541 wxString
GetPropertyValueAsString( wxPGPropArg id
) const;
542 long GetPropertyValueAsLong( wxPGPropArg id
) const;
543 unsigned long GetPropertyValueAsULong( wxPGPropArg id
) const
545 return (unsigned long) GetPropertyValueAsLong(id
);
548 int GetPropertyValueAsInt( wxPGPropArg id
) const
549 { return (int)GetPropertyValueAsLong(id
); }
551 bool GetPropertyValueAsBool( wxPGPropArg id
) const;
552 double GetPropertyValueAsDouble( wxPGPropArg id
) const;
553 void* GetPropertyValueAsVoidPtr( wxPGPropArg id
) const;
555 #define wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(TYPENAME, DEFVAL) \
556 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFVAL) \
557 wxString typeName(wxS(TYPENAME)); \
558 wxVariant value = p->GetValue(); \
559 if ( value.GetType() != typeName ) \
561 wxPGGetFailed(p, typeName); \
565 #define wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK(TYPENAME, DEFVAL) \
566 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFVAL) \
567 wxVariant value = p->GetValue(); \
568 if ( value.GetType() != wxS(TYPENAME) ) \
571 wxArrayString GetPropertyValueAsArrayString( wxPGPropArg id ) const
573 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("arrstring",
575 return value
.GetArrayString();
578 wxPoint
GetPropertyValueAsPoint( wxPGPropArg id
) const
580 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("wxPoint", wxPoint())
586 wxSize
GetPropertyValueAsSize( wxPGPropArg id
) const
588 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("wxSize", wxSize())
594 wxLongLong_t
GetPropertyValueAsLongLong( wxPGPropArg id
) const
596 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK("wxLongLong",
597 (long) GetPropertyValueAsLong(id
))
600 return ll
.GetValue();
603 wxULongLong_t
GetPropertyValueAsULongLong( wxPGPropArg id
) const
605 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK("wxULongLong",
606 (unsigned long) GetPropertyValueAsULong(id
))
609 return ull
.GetValue();
612 wxArrayInt
GetPropertyValueAsArrayInt( wxPGPropArg id
) const
614 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("wxArrayInt",
622 wxDateTime
GetPropertyValueAsDateTime( wxPGPropArg id
) const
624 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("datetime",
626 return value
.GetDateTime();
631 /** Returns a wxVariant list containing wxVariant versions of all
632 property values. Order is not guaranteed.
634 Use wxPG_KEEP_STRUCTURE to retain category structure; each sub
635 category will be its own wxVariantList of wxVariant.
636 Use wxPG_INC_ATTRIBUTES to include property attributes as well.
637 Each attribute will be stored as list variant named
638 "@@<propname>@@attr."
641 wxVariant
GetPropertyValues( const wxString
& listname
= wxEmptyString
,
642 wxPGProperty
* baseparent
= NULL
, long flags
= 0 ) const
644 return m_pState
->DoGetPropertyValues(listname
, baseparent
, flags
);
648 wxString
GetPropertyValueType( wxPGPropArg id
)
650 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(m_emptyString
)
651 return p
->GetValueType();
654 /** Returns currently selected property. */
655 wxPGProperty
* GetSelection() const
657 return m_pState
->GetSelection();
661 wxPropertyGridPageState
* GetState() const { return m_pState
; }
664 /** Similar to GetIterator(), but instead returns wxPGVIterator instance,
665 which can be useful for forward-iterating through arbitrary property
669 See @ref propgrid_iterator_flags.
671 virtual wxPGVIterator
GetVIterator( int flags
) const;
673 /** Hides or reveals a property.
675 If true, hides property, otherwise reveals it.
677 By default changes are applied recursively. Set this paramter
678 wxPG_DONT_RECURSE to prevent this.
680 bool HideProperty( wxPGPropArg id
,
682 int flags
= wxPG_RECURSE
);
684 #if wxPG_INCLUDE_ADVPROPS
685 /** Initializes *all* property types. Causes references to most object
686 files in the library, so calling this may cause significant increase
687 in executable size when linking with static library.
689 static void InitAllTypeHandlers();
691 static void InitAllTypeHandlers() { }
695 /** Inserts property to the property container.
698 New property is inserted just prior to this. Available only
699 in the first variant. There are two versions of this function
700 to allow this parameter to be either an id or name to
704 Pointer to the inserted property. wxPropertyGrid will take
705 ownership of this object.
708 New property is inserted under this category. Available only
709 in the second variant. There are two versions of this function
710 to allow this parameter to be either an id or name to
714 Index under category. Available only in the second variant.
715 If index is < 0, property is appended in category.
718 Returns id for the property,
722 - wxPropertyGrid takes the ownership of the property pointer.
724 - While Append may be faster way to add items, make note that when
725 both types of data storage (categoric and
726 non-categoric) are active, Insert becomes even more slow. This is
727 especially true if current mode is non-categoric.
734 wxPGProperty* my_cat_id = propertygrid->Append(
735 new wxPropertyCategory("My Category") );
739 // insert into category - using second variant
740 wxPGProperty* my_item_id_1 = propertygrid->Insert(
741 my_cat_id, 0, new wxStringProperty("My String 1") );
743 // insert before to first item - using first variant
744 wxPGProperty* my_item_id_2 = propertygrid->Insert(
745 my_item_id, new wxStringProperty("My String 2") );
750 wxPGProperty
* Insert( wxPGPropArg priorThis
, wxPGProperty
* newproperty
);
751 wxPGProperty
* Insert( wxPGPropArg parent
,
753 wxPGProperty
* newproperty
);
756 /** Returns true if property is a category. */
757 bool IsPropertyCategory( wxPGPropArg id
) const
759 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
760 return p
->IsCategory();
763 /** Inserts choice to a property that can accept one.
765 See AddPropertyChoice for more details.
767 void InsertPropertyChoice( wxPGPropArg id
,
768 const wxString
& label
,
770 int value
= wxPG_INVALID_VALUE
);
772 /** Returns true if property is enabled. */
773 bool IsPropertyEnabled( wxPGPropArg id
) const
775 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
776 return (!(p
->GetFlags() & wxPG_PROP_DISABLED
))?true:false;
780 Returns true if given property is expanded.
782 Naturally, always returns false for properties that cannot be expanded.
784 bool IsPropertyExpanded( wxPGPropArg id
) const;
787 Returns true if property has been modified after value set or modify
788 flag clear by software.
790 bool IsPropertyModified( wxPGPropArg id
) const
792 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
793 return ( (p
->GetFlags() & wxPG_PROP_MODIFIED
) ? true : false );
797 Returns true if property is shown (ie hideproperty with true not
800 bool IsPropertyShown( wxPGPropArg id
) const
802 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
803 return (!(p
->GetFlags() & wxPG_PROP_HIDDEN
))?true:false;
806 /** Returns true if property value is set to unspecified.
808 bool IsPropertyValueUnspecified( wxPGPropArg id
) const
810 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
811 return p
->IsValueUnspecified();
815 Disables (limit = true) or enables (limit = false) wxTextCtrl editor of
816 a property, if it is not the sole mean to edit the value.
818 void LimitPropertyEditing( wxPGPropArg id
, bool limit
= true );
820 /** If state is shown in it's grid, refresh it now.
822 virtual void RefreshGrid( wxPropertyGridPageState
* state
= NULL
);
824 #if wxPG_INCLUDE_ADVPROPS
826 Initializes additional property editors (SpinCtrl etc.). Causes
827 references to most object files in the library, so calling this may
828 cause significant increase in executable size when linking with static
831 static void RegisterAdditionalEditors();
833 static void RegisterAdditionalEditors() { }
836 /** Replaces property with id with newly created property. For example,
837 this code replaces existing property named "Flags" with one that
838 will have different set of items:
840 pg->ReplaceProperty("Flags",
841 wxFlagsProperty("Flags", wxPG_LABEL, newItems))
843 For more info, see wxPropertyGrid::Insert.
845 wxPGProperty
* ReplaceProperty( wxPGPropArg id
, wxPGProperty
* property
);
847 /** @anchor propgridinterface_editablestate_flags
849 Flags for wxPropertyGridInterface::SaveEditableState() and
850 wxPropertyGridInterface::RestoreEditableState().
852 enum EditableStateFlags
854 /** Include selected property. */
855 SelectionState
= 0x01,
856 /** Include expanded/collapsed property information. */
857 ExpandedState
= 0x02,
858 /** Include scrolled position. */
859 ScrollPosState
= 0x04,
860 /** Include selected page information.
861 Only applies to wxPropertyGridManager. */
863 /** Include splitter position. Stored for each page. */
864 SplitterPosState
= 0x10,
867 Include all supported user editable state information.
868 This is usually the default value. */
869 AllStates
= SelectionState
|
877 Restores user-editable state.
879 See also wxPropertyGridInterface::SaveEditableState().
882 String generated by SaveEditableState.
885 Which parts to restore from source string. See @ref
886 propgridinterface_editablestate_flags "list of editable state
890 False if there was problem reading the string.
893 If some parts of state (such as scrolled or splitter position) fail to
894 restore correctly, please make sure that you call this function after
895 wxPropertyGrid size has been set (this may sometimes be tricky when
898 bool RestoreEditableState( const wxString
& src
,
899 int restoreStates
= AllStates
);
902 Used to acquire user-editable state (selected property, expanded
903 properties, scrolled position, splitter positions).
905 @param includedStates
906 Which parts of state to include. See @ref
907 propgridinterface_editablestate_flags "list of editable state flags".
909 wxString
SaveEditableState( int includedStates
= AllStates
) const;
912 Lets user to set the strings listed in the choice dropdown of a
913 wxBoolProperty. Defaults are "True" and "False", so changing them to,
914 say, "Yes" and "No" may be useful in some less technical applications.
916 static void SetBoolChoices( const wxString
& trueChoice
,
917 const wxString
& falseChoice
);
919 /** Sets or clears flag(s) of all properties in given array.
921 Property flags to set or clear.
923 Set to true if you want to clear flag instead of setting them.
925 void SetPropertiesFlag( const wxArrayPGProperty
& srcArr
,
926 wxPGProperty::FlagType flags
,
927 bool inverse
= false );
929 /** Sets an attribute for this property.
931 Text identifier of attribute. See @ref propgrid_property_attributes.
935 Optional. Use wxPG_RECURSE to set the attribute to child properties
938 void SetPropertyAttribute( wxPGPropArg id
,
939 const wxString
& attrName
,
943 DoSetPropertyAttribute(id
,attrName
,value
,argFlags
);
946 /** Sets attributes from a wxPGAttributeStorage.
948 void SetPropertyAttributes( wxPGPropArg id
,
949 const wxPGAttributeStorage
& attributes
)
951 wxPG_PROP_ARG_CALL_PROLOG()
952 p
->SetAttributes(attributes
);
955 /** Sets text, bitmap, and colours for given column's cell.
958 - You can set label cell by setting column to 0.
959 - You can use wxPG_LABEL as text to use default text for column.
961 void SetPropertyCell( wxPGPropArg id
,
963 const wxString
& text
= wxEmptyString
,
964 const wxBitmap
& bitmap
= wxNullBitmap
,
965 const wxColour
& fgCol
= wxNullColour
,
966 const wxColour
& bgCol
= wxNullColour
)
968 wxPG_PROP_ARG_CALL_PROLOG()
969 p
->SetCell( column
, new wxPGCell(text
, bitmap
, fgCol
, bgCol
) );
972 /** Set choices of a property to specified set of labels and values.
975 This operation clears the property value.
977 void SetPropertyChoices( wxPGPropArg id
, wxPGChoices
& choices
)
979 wxPG_PROP_ARG_CALL_PROLOG()
980 p
->SetChoices(choices
);
985 If property's set of choices is shared, then calling this method
986 converts it to private.
988 void SetPropertyChoicesExclusive( wxPGPropArg id
)
990 wxPG_PROP_ARG_CALL_PROLOG()
991 p
->SetChoicesExclusive();
995 /** Sets client data (void*) of a property.
997 This untyped client data has to be deleted manually.
999 void SetPropertyClientData( wxPGPropArg id
, void* clientData
)
1001 wxPG_PROP_ARG_CALL_PROLOG()
1002 p
->SetClientData(clientData
);
1005 /** Sets editor for a property.
1008 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1009 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full
1012 For custom editors, use pointer you received from
1013 wxPropertyGrid::RegisterEditorClass().
1015 void SetPropertyEditor( wxPGPropArg id
, const wxPGEditor
* editor
)
1017 wxPG_PROP_ARG_CALL_PROLOG()
1018 wxCHECK_RET( editor
, wxT("unknown/NULL editor") );
1019 p
->SetEditor(editor
);
1024 /** Sets editor control of a property. As editor argument, use
1025 editor name string, such as "TextCtrl" or "Choice".
1027 void SetPropertyEditor( wxPGPropArg id
, const wxString
& editorName
)
1029 SetPropertyEditor(id
,GetEditorByName(editorName
));
1032 /** Sets label of a property.
1034 void SetPropertyLabel( wxPGPropArg id
, const wxString
& newproplabel
);
1036 /** Set modified status of a property and all its children.
1038 void SetPropertyModifiedStatus( wxPGPropArg id
, bool modified
)
1040 wxPG_PROP_ARG_CALL_PROLOG()
1041 p
->SetModifiedStatus(modified
);
1045 Sets property (and, recursively, its children) to have read-only value.
1046 In other words, user cannot change the value in the editor, but they
1049 This is mainly for use with textctrl editor. Not all other editors fully
1052 By default changes are applied recursively. Set this paramter
1053 wxPG_DONT_RECURSE to prevent this.
1055 void SetPropertyReadOnly( wxPGPropArg id
,
1057 int flags
= wxPG_RECURSE
)
1059 wxPG_PROP_ARG_CALL_PROLOG()
1060 if ( flags
& wxPG_RECURSE
)
1061 p
->SetFlagRecursively(wxPG_PROP_READONLY
, set
);
1063 p
->SetFlag(wxPG_PROP_READONLY
);
1066 /** Sets property's value to unspecified.
1067 If it has children (it may be category), then the same thing is done to
1070 void SetPropertyValueUnspecified( wxPGPropArg id
);
1073 /** Sets various property values from a list of wxVariants. If property with
1074 name is missing from the grid, new property is created under given
1075 default category (or root if omitted).
1077 void SetPropertyValues( const wxVariantList
& list
,
1078 wxPGPropArg defaultCategory
= wxNullProperty
)
1081 if ( defaultCategory
.HasName() ) p
= defaultCategory
.GetPtr(this);
1082 else p
= defaultCategory
.GetPtr0();
1083 m_pState
->DoSetPropertyValues(list
, p
);
1086 void SetPropertyValues( const wxVariant
& list
,
1087 wxPGPropArg defaultCategory
= wxNullProperty
)
1089 SetPropertyValues(list
.GetList(),defaultCategory
);
1093 /** Associates the help string with property.
1095 By default, text is shown either in the manager's "description"
1096 text box or in the status bar. If extra window style
1097 wxPG_EX_HELP_AS_TOOLTIPS is used, then the text will appear as a
1100 void SetPropertyHelpString( wxPGPropArg id
, const wxString
& helpString
)
1102 wxPG_PROP_ARG_CALL_PROLOG()
1103 p
->SetHelpString(helpString
);
1106 /** Set wxBitmap in front of the value.
1108 - Bitmap will be scaled to a size returned by
1109 wxPropertyGrid::GetImageSize();
1111 void SetPropertyImage( wxPGPropArg id
, wxBitmap
& bmp
)
1113 wxPG_PROP_ARG_CALL_PROLOG()
1114 p
->SetValueImage(bmp
);
1118 /** Sets max length of property's text.
1120 bool SetPropertyMaxLength( wxPGPropArg id
, int maxLen
);
1122 #if wxUSE_VALIDATORS
1123 /** Sets validator of a property.
1125 void SetPropertyValidator( wxPGPropArg id
, const wxValidator
& validator
)
1127 wxPG_PROP_ARG_CALL_PROLOG()
1128 p
->SetValidator(validator
);
1133 /** Sets value (long integer) of a property.
1135 void SetPropertyValue( wxPGPropArg id
, long value
)
1138 SetPropVal( id
, v
);
1141 /** Sets value (integer) of a property.
1143 void SetPropertyValue( wxPGPropArg id
, int value
)
1145 wxVariant
v((long)value
);
1146 SetPropVal( id
, v
);
1148 /** Sets value (floating point) of a property.
1150 void SetPropertyValue( wxPGPropArg id
, double value
)
1153 SetPropVal( id
, v
);
1155 /** Sets value (bool) of a property.
1157 void SetPropertyValue( wxPGPropArg id
, bool value
)
1160 SetPropVal( id
, v
);
1162 void SetPropertyValue( wxPGPropArg id
, const wxChar
* value
)
1164 SetPropertyValueString( id
, wxString(value
) );
1166 void SetPropertyValue( wxPGPropArg id
, const wxString
& value
)
1168 SetPropertyValueString( id
, value
);
1171 /** Sets value (wxArrayString) of a property.
1173 void SetPropertyValue( wxPGPropArg id
, const wxArrayString
& value
)
1176 SetPropVal( id
, v
);
1180 void SetPropertyValue( wxPGPropArg id
, const wxDateTime
& value
)
1183 SetPropVal( id
, v
);
1187 /** Sets value (wxObject*) of a property.
1189 void SetPropertyValue( wxPGPropArg id
, wxObject
* value
)
1192 SetPropVal( id
, v
);
1195 void SetPropertyValue( wxPGPropArg id
, wxObject
& value
)
1197 wxVariant
v(&value
);
1198 SetPropVal( id
, v
);
1201 /** Sets value (wxPoint&) of a property.
1203 void SetPropertyValue( wxPGPropArg id
, const wxPoint
& value
)
1205 wxVariant v
= WXVARIANT(value
);
1206 SetPropVal( id
, v
);
1208 /** Sets value (wxSize&) of a property.
1210 void SetPropertyValue( wxPGPropArg id
, const wxSize
& value
)
1212 wxVariant v
= WXVARIANT(value
);
1213 SetPropVal( id
, v
);
1215 /** Sets value (wxLongLong&) of a property.
1217 void SetPropertyValue( wxPGPropArg id
, wxLongLong_t value
)
1219 wxVariant v
= WXVARIANT(wxLongLong(value
));
1220 SetPropVal( id
, v
);
1222 /** Sets value (wxULongLong&) of a property.
1224 void SetPropertyValue( wxPGPropArg id
, wxULongLong_t value
)
1226 wxVariant v
= WXVARIANT(wxULongLong(value
));
1227 SetPropVal( id
, v
);
1229 /** Sets value (wxArrayInt&) of a property.
1231 void SetPropertyValue( wxPGPropArg id
, const wxArrayInt
& value
)
1233 wxVariant v
= WXVARIANT(value
);
1234 SetPropVal( id
, v
);
1238 /** Sets value (wxString) of a property.
1241 This method uses wxPGProperty::SetValueFromString, which all properties
1242 should implement. This means that there should not be a type error,
1243 and instead the string is converted to property's actual value type.
1245 void SetPropertyValueString( wxPGPropArg id
, const wxString
& value
);
1247 /** Sets value (wxVariant&) of a property.
1250 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run
1251 through validation process and send property change event.
1253 void SetPropertyValue( wxPGPropArg id
, wxVariant value
)
1255 SetPropVal( id
, value
);
1259 /** Sets value (wxVariant&) of a property. Same as SetPropertyValue, but
1260 accepts reference. */
1261 void SetPropVal( wxPGPropArg id
, wxVariant
& value
);
1264 /** Adjusts how wxPropertyGrid behaves when invalid value is entered
1267 See @link vfbflags list of valid flags values@endlink
1269 void SetValidationFailureBehavior( int vfbFlags
);
1273 def
MapType(class_
,factory
):
1274 "Registers Python type/class to property mapping.\n\nfactory: Property builder function/class."
1275 global _type2property
1277 mappings
= _type2property
1279 raise
AssertionError("call only after a propertygrid or manager instance constructed")
1281 mappings
[class_
] = factory
1284 def
DoDefaultTypeMappings(self
):
1285 "Map built-in properties."
1286 global _type2property
1288 mappings
= _type2property
1293 _type2property
= mappings
1295 mappings
[str
] = StringProperty
1296 mappings
[unicode
] = StringProperty
1297 mappings
[int] = IntProperty
1298 mappings
[float] = FloatProperty
1299 mappings
[bool] = BoolProperty
1300 mappings
[list
] = ArrayStringProperty
1301 mappings
[tuple
] = ArrayStringProperty
1302 mappings
[wx
.Font
] = FontProperty
1303 mappings
[wx
.Colour
] = ColourProperty
1304 "mappings[wx.Size] = SizeProperty"
1305 "mappings[wx.Point] = PointProperty"
1306 "mappings[wx.FontData] = FontDataProperty"
1308 def
DoDefaultValueTypeMappings(self
):
1309 "Map pg value type ids to getter methods."
1312 vt2getter
= _vt2getter
1317 _vt2getter
= vt2getter
1319 def
GetPropertyValues(self
,dict_
=None
, as_strings
=False
, inc_attributes
=False
):
1320 "Returns values in the grid."
1322 "dict_: if not given, then a new one is created. dict_ can be"
1323 " object as well, in which case it's __dict__ is used."
1324 "as_strings: if True, then string representations of values"
1325 " are fetched instead of native types. Useful for config and such."
1326 "inc_attributes: if True, then property attributes are added"
1327 " as @<propname>@<attr>."
1329 "Return value: dictionary with values. It is always a dictionary,"
1330 "so if dict_ was object with __dict__ attribute, then that attribute"
1335 elif
hasattr(dict_
,'__dict__'):
1336 dict_
= dict_
.__dict__
1339 getter
= self
.GetPropertyValue
1341 getter
= self
.GetPropertyValueAsString
1343 it
= self
.GetVIterator(PG_ITERATE_PROPERTIES
)
1344 while not it
.AtEnd():
1345 p
= it
.GetProperty()
1348 dict_
[name
] = getter(p
)
1351 attrs
= p
.GetAttributes()
1352 if attrs
and len(attrs
):
1353 dict_
['@%s@attr'%name
] = attrs
1359 GetValues
= GetPropertyValues
1362 def
SetPropertyValues(self
,dict_
):
1363 "Sets property values from dict_, which can be either\ndictionary or an object with __dict__ attribute."
1365 "autofill: If true, keys with not relevant properties"
1366 " are auto-created. For more info, see AutoFill."
1369 " * Keys starting with underscore are ignored."
1370 " * Attributes can be set with entries named @<propname>@<attr>."
1377 elif
hasattr(dict_
,'__dict__'):
1378 dict_
= dict_
.__dict__
1382 def
set_sub_obj(k0
,dict_
):
1383 for k
,v in dict_
.iteritems():
1385 if k
.endswith('@attr'):
1386 attr_dicts
.append((k
[1:-5],v
))
1389 self
.SetPropertyValue(k
,v
)
1393 self
._AutoFillOne(k0
,k
,v
)
1396 if isinstance(v
,dict
):
1398 elif
hasattr(v
,'__dict__'):
1399 set_sub_obj(k
,v
.__dict__
)
1402 for k
,v in attr_dicts
:
1403 p
= GetPropertyByName(k
)
1405 raise
AssertionError("No such property: '%s'"%k
)
1406 for an
,av in v
.iteritems():
1407 p
.SetAttribute(an
, av
)
1411 is_manager
= isinstance(self
,PropertyGridManager
)
1414 set_sub_obj(self
.GetGrid().GetRoot(),dict_
)
1417 traceback
.print_exc()
1421 SetValues
= SetPropertyValues
1423 def
_AutoFillMany(self
,cat
,dict_
):
1424 for k
,v in dict_
.iteritems():
1425 self
._AutoFillOne(cat
,k
,v
)
1428 def
_AutoFillOne(self
,cat
,k
,v
):
1429 global _type2property
1431 factory
= _type2property
.get(v
.__class__
,None
)
1434 self
.AppendIn( cat
, factory(k
,k
,v
) )
1435 elif
hasattr(v
,'__dict__'):
1436 cat2
= self
.AppendIn( cat
, PropertyCategory(k
) )
1437 self
._AutoFillMany(cat2
,v
.__dict__
)
1438 elif
isinstance(v
,dict
):
1439 cat2
= self
.AppendIn( cat
, PropertyCategory(k
) )
1440 self
._AutoFillMany(cat2
,v
)
1441 elif
not k
.startswith('_'):
1442 raise
AssertionError("member '%s' is of unregisted type/class '%s'"%(k
,v
.__class__
))
1445 def
AutoFill(self
,obj
,parent
=None
):
1446 "Clears properties and re-fills to match members and\nvalues of given object or dictionary obj."
1448 self
.edited_objects
[parent
] = obj
1451 is_manager
= isinstance(self
,PropertyGridManager
)
1455 page
= self
.GetCurrentPage()
1457 parent
= page
.GetRoot()
1460 parent
= self
.GetGrid().GetRoot()
1462 it
= self
.GetIterator(PG_ITERATE_PROPERTIES
, parent
)
1463 it
.Next() # Skip the parent
1464 while not it
.AtEnd():
1465 p
= it
.GetProperty()
1466 if not p
.IsSomeParent(parent
):
1469 self
.DeleteProperty(p
)
1474 if not is_manager
or page
== self
.GetCurrentPage():
1479 self
._AutoFillMany(parent
,obj
.__dict__
)
1482 traceback
.print_exc()
1487 def
RegisterEditor(self
, editor
, editorName
=None
):
1488 "Transform class into instance, if necessary."
1489 if not isinstance(editor
, PGEditor
):
1492 editorName
= editor
.__class__
.__name__
1494 self
._editor_instances
.append(editor
)
1496 self
._editor_instances
= [editor
]
1497 RegisterEditor(editor
, editorName
)
1499 def
GetPropertyClientData(self
, p
):
1500 if isinstance(p
, basestring
):
1501 p
= self
.GetPropertyByName(p
)
1502 return p
.GetClientData()
1504 def
SetPropertyClientData(self
, p
, data
):
1505 if isinstance(p
, basestring
):
1506 p
= self
.GetPropertyByName(p
)
1507 return p
.SetClientData(data
)
1511 // GetPropertyByName With nice assertion error message.
1512 wxPGProperty
* GetPropertyByNameA( const wxString
& name
) const;
1514 static wxPGEditor
* GetEditorByName( const wxString
& editorName
);
1516 virtual void RefreshProperty( wxPGProperty
* p
) = 0;
1520 // Returns page state data for given (sub) page (-1 means current page).
1521 virtual wxPropertyGridPageState
* GetPageState( int pageIndex
) const
1523 if ( pageIndex
<= 0 )
1528 virtual bool DoSelectPage( int WXUNUSED(index
) ) { return true; }
1530 // Default call's m_pState's BaseGetPropertyByName
1531 virtual wxPGProperty
* DoGetPropertyByName( const wxString
& name
) const;
1535 // Deriving classes must set this (it must be only or current page).
1536 wxPropertyGridPageState
* m_pState
;
1538 // Intermediate version needed due to wxVariant copying inefficiency
1539 void DoSetPropertyAttribute( wxPGPropArg id
,
1540 const wxString
& name
,
1541 wxVariant
& value
, long argFlags
);
1543 // Empty string object to return from member functions returning const
1545 wxString m_emptyString
;
1548 // Cannot be GetGrid() due to ambiguity issues.
1549 wxPropertyGrid
* GetPropertyGrid()
1551 return m_pState
->GetGrid();
1554 // Cannot be GetGrid() due to ambiguity issues.
1555 const wxPropertyGrid
* GetPropertyGrid() const
1557 return (const wxPropertyGrid
*) m_pState
->GetGrid();
1559 #endif // #ifndef SWIG
1561 friend class wxPropertyGrid
;
1562 friend class wxPropertyGridManager
;
1565 #endif // __WX_PROPGRID_PROPGRIDIFACE_H__