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__
17 #include "wx/propgrid/property.h"
18 #include "wx/propgrid/propgridpagestate.h"
20 // -----------------------------------------------------------------------
24 /** @section wxPGPropArgCls
26 Most property grid functions have this type as their argument, as it can
27 convey a property by either a pointer or name.
29 class WXDLLIMPEXP_PROPGRID wxPGPropArgCls
33 wxPGPropArgCls( const wxPGProperty
* property
)
35 m_ptr
.property
= (wxPGProperty
*) property
;
38 wxPGPropArgCls( const wxString
& str
)
40 m_ptr
.stringName
= &str
;
43 wxPGPropArgCls( const wxPGPropArgCls
& id
)
48 // This is only needed for wxPython bindings
49 wxPGPropArgCls( wxString
* str
, bool WXUNUSED(deallocPtr
) )
51 m_ptr
.stringName
= str
;
52 m_flags
= IsWxString
| OwnsWxString
;
56 if ( m_flags
& OwnsWxString
)
57 delete m_ptr
.stringName
;
59 wxPGProperty
* GetPtr() const
61 wxCHECK( m_flags
== IsProperty
, NULL
);
62 return m_ptr
.property
;
64 wxPGPropArgCls( const char* str
)
70 wxPGPropArgCls( const wchar_t* str
)
72 m_ptr
.wcharName
= str
;
76 /** This constructor is required for NULL. */
79 m_ptr
.property
= (wxPGProperty
*) NULL
;
82 wxPGProperty
* GetPtr( wxPropertyGridInterface
* iface
) const;
83 wxPGProperty
* GetPtr( const wxPropertyGridInterface
* iface
) const
85 return GetPtr((wxPropertyGridInterface
*)iface
);
87 wxPGProperty
* GetPtr0() const { return m_ptr
.property
; }
88 bool HasName() const { return (m_flags
!= IsProperty
); }
89 const wxString
& GetName() const { return *m_ptr
.stringName
; }
103 wxPGProperty
* property
;
104 const char* charName
;
106 const wchar_t* wcharName
;
108 const wxString
* stringName
;
110 unsigned char m_flags
;
115 typedef const wxPGPropArgCls
& wxPGPropArg
;
117 // -----------------------------------------------------------------------
120 void wxPGTypeOperationFailed( const wxPGProperty
* p
,
121 const wxString
& typestr
,
122 const wxString
& op
);
124 void wxPGGetFailed( const wxPGProperty
* p
, const wxString
& typestr
);
126 // -----------------------------------------------------------------------
128 // Helper macro that does necessary preparations when calling
129 // some wxPGProperty's member function.
130 #define wxPG_PROP_ARG_CALL_PROLOG_0(PROPERTY) \
131 PROPERTY *p = (PROPERTY*)id.GetPtr(this); \
134 #define wxPG_PROP_ARG_CALL_PROLOG_RETVAL_0(PROPERTY, RETVAL) \
135 PROPERTY *p = (PROPERTY*)id.GetPtr(this); \
136 if ( !p ) return RETVAL;
138 #define wxPG_PROP_ARG_CALL_PROLOG() \
139 wxPG_PROP_ARG_CALL_PROLOG_0(wxPGProperty)
141 #define wxPG_PROP_ARG_CALL_PROLOG_RETVAL(RVAL) \
142 wxPG_PROP_ARG_CALL_PROLOG_RETVAL_0(wxPGProperty, RVAL)
144 #define wxPG_PROP_ID_CONST_CALL_PROLOG() \
145 wxPG_PROP_ARG_CALL_PROLOG_0(const wxPGProperty)
147 #define wxPG_PROP_ID_CONST_CALL_PROLOG_RETVAL(RVAL) \
148 wxPG_PROP_ARG_CALL_PROLOG_RETVAL_0(const wxPGProperty, RVAL)
150 // -----------------------------------------------------------------------
153 /** @class wxPropertyGridInterface
155 Most of the shared property manipulation interface shared by wxPropertyGrid,
156 wxPropertyGridPage, and wxPropertyGridManager is defined in this class.
159 - In separate wxPropertyGrid component this class was known as
160 wxPropertyContainerMethods.
165 class WXDLLIMPEXP_PROPGRID wxPropertyGridInterface
170 virtual ~wxPropertyGridInterface() { }
172 /** Adds choice to a property that can accept one.
174 - If you need to make sure that you modify only the set of choices of
175 a single property (and not also choices of other properties with
176 initially identical set), call
177 wxPropertyGrid::SetPropertyChoicesPrivate.
178 - This usually only works for wxEnumProperty and derivatives
179 (wxFlagsProperty can get accept new items but its items may not get
182 void AddPropertyChoice( wxPGPropArg id
,
183 const wxString
& label
,
184 int value
= wxPG_INVALID_VALUE
);
187 Appends property to the list.
189 wxPropertyGrid assumes ownership of the object.
190 Becomes child of most recently added category.
192 - wxPropertyGrid takes the ownership of the property pointer.
193 - If appending a category with name identical to a category already in
194 the wxPropertyGrid, then newly created category is deleted, and most
195 recently added category (under which properties are appended) is set
196 to the one with same name. This allows easier adding of items to same
197 categories in multiple passes.
198 - Does not automatically redraw the control, so you may need to call
199 Refresh when calling this function after control has been shown for
202 wxPGProperty
* Append( wxPGProperty
* property
);
204 wxPGProperty
* AppendIn( wxPGPropArg id
, wxPGProperty
* newproperty
);
207 In order to add new items into a property with fixed children (for
208 instance, wxFlagsProperty), you need to call this method. After
209 populating has been finished, you need to call EndAddChildren.
211 void BeginAddChildren( wxPGPropArg id
);
213 /** Deletes all properties.
215 virtual void Clear() = 0;
217 /** Deselect current selection, if any. Returns true if success
218 (ie. validator did not intercept). */
219 bool ClearSelection();
221 /** Resets modified status of all properties.
223 void ClearModifiedStatus()
225 SetPropertyModifiedStatus(m_pState
->m_properties
, false);
226 m_pState
->m_anyModified
= false;
229 /** Collapses given category or property with children.
230 Returns true if actually collapses.
232 bool Collapse( wxPGPropArg id
);
234 /** Collapses all items that can be collapsed.
237 Return false if failed (may fail if editor value cannot be validated).
239 bool CollapseAll() { return ExpandAll(false); }
242 Changes value of a property, as if from an editor.
243 Use this instead of SetPropertyValue() if you need the value to run
244 through validation process, and also send the property change event.
247 Returns true if value was successfully changed.
249 bool ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
);
251 /** Resets value of a property to its default. */
252 bool ClearPropertyValue( wxPGPropArg id
)
254 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
255 p
->SetValue(p
->GetDefaultValue());
261 Deletes a property by id. If category is deleted, all children are
262 automatically deleted as well.
264 void DeleteProperty( wxPGPropArg id
);
266 /** Deletes choice from a property.
268 If selected item is deleted, then the value is set to unspecified.
270 See AddPropertyChoice for more details.
272 void DeletePropertyChoice( wxPGPropArg id
, int index
);
274 /** Disables property. */
275 bool DisableProperty( wxPGPropArg id
) { return EnableProperty(id
,false); }
278 Returns true if all property grid data changes have been committed.
280 Usually only returns false if value in active editor has been
281 invalidated by a wxValidator.
283 bool EditorValidate();
286 Enables or disables property, depending on whether enable is true or
289 bool EnableProperty( wxPGPropArg id
, bool enable
= true );
291 /** Called after population of property with fixed children has finished.
293 void EndAddChildren( wxPGPropArg id
);
295 /** Expands given category or property with children.
296 Returns true if actually expands.
298 bool Expand( wxPGPropArg id
);
300 /** Expands all items that can be expanded.
302 bool ExpandAll( bool expand
= true );
304 /** Returns list of expanded properties.
306 wxArrayPGProperty
GetExpandedProperties() const
308 wxArrayPGProperty array
;
309 GetPropertiesWithFlag(&array
, wxPG_PROP_COLLAPSED
, true,
310 wxPG_ITERATE_ALL_PARENTS_RECURSIVELY
|wxPG_ITERATE_HIDDEN
);
314 /** Returns id of first child of given property.
316 Does not return sub-properties!
318 wxPGProperty
* GetFirstChild( wxPGPropArg id
)
320 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
322 if ( !p
->GetChildCount() || p
->HasFlag(wxPG_PROP_AGGREGATE
) )
323 return wxNullProperty
;
329 /** Returns iterator class instance.
331 See @ref propgrid_iterator_flags. Value wxPG_ITERATE_DEFAULT causes
332 iteration over everything except private child properties.
334 Property to start iteration from. If NULL, then first child of root
337 Either wxTOP or wxBOTTOM. wxTOP will indicate that iterations start
338 from the first property from the top, and wxBOTTOM means that the
339 iteration will instead begin from bottommost valid item.
341 wxPropertyGridIterator
GetIterator( int flags
= wxPG_ITERATE_DEFAULT
,
342 wxPGProperty
* firstProp
= NULL
)
344 return wxPropertyGridIterator( m_pState
, flags
, firstProp
);
347 wxPropertyGridConstIterator
348 GetIterator( int flags
= wxPG_ITERATE_DEFAULT
,
349 wxPGProperty
* firstProp
= NULL
) const
351 return wxPropertyGridConstIterator( m_pState
, flags
, firstProp
);
354 wxPropertyGridIterator
GetIterator( int flags
, int startPos
)
356 return wxPropertyGridIterator( m_pState
, flags
, startPos
);
359 wxPropertyGridConstIterator
GetIterator( int flags
, int startPos
) const
361 return wxPropertyGridConstIterator( m_pState
, flags
, startPos
);
365 /** Returns id of first item, whether it is a category or property.
367 @link iteratorflags List of iterator flags@endlink
369 wxPGProperty
* GetFirst( int flags
= wxPG_ITERATE_ALL
)
371 wxPropertyGridIterator
it( m_pState
, flags
, wxNullProperty
, 1 );
375 const wxPGProperty
* GetFirst( int flags
= wxPG_ITERATE_ALL
) const
377 return ((wxPropertyGridInterface
*)this)->GetFirst(flags
);
381 Returns id of property with given name (case-sensitive).
383 If there is no property with such name, returned property id is invalid
384 ( i.e. it will return false with IsOk method).
386 - Sub-properties (i.e. properties which have parent that is not
387 category or root) can not be accessed globally by their name.
388 Instead, use "<property>.<subproperty>" in place of "<subproperty>".
390 wxPGProperty
* GetProperty( const wxString
& name
) const
392 return GetPropertyByName(name
);
395 /** Returns map-like storage of property's attributes.
397 Note that if extra style wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES is set,
398 then builtin-attributes are not included in the storage.
400 const wxPGAttributeStorage
& GetPropertyAttributes( wxPGPropArg id
) const
402 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(*((const wxPGAttributeStorage
*)NULL
));
403 return p
->GetAttributes();
406 /** Adds to 'targetArr' pointers to properties that have given
407 flags 'flags' set. However, if 'inverse' is set to true, then
408 only properties without given flags are stored.
410 Property flags to use.
412 Iterator flags to use. Default is everything expect private children.
414 void GetPropertiesWithFlag( wxArrayPGProperty
* targetArr
,
415 wxPGProperty::FlagType flags
,
416 bool inverse
= false,
417 int iterFlags
= wxPG_ITERATE_PROPERTIES
|
418 wxPG_ITERATE_HIDDEN
|
419 wxPG_ITERATE_CATEGORIES
) const;
421 /** Returns value of given attribute. If none found, returns NULL-variant.
423 wxVariant
GetPropertyAttribute( wxPGPropArg id
,
424 const wxString
& attrName
) const
426 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullVariant
)
427 return p
->GetAttribute(attrName
);
430 /** Returns pointer of property's nearest parent category. If no category
433 wxPropertyCategory
* GetPropertyCategory( wxPGPropArg id
) const
435 wxPG_PROP_ID_CONST_CALL_PROLOG_RETVAL(NULL
)
436 return m_pState
->GetPropertyCategory(p
);
440 /** Returns client data (void*) of a property. */
441 void* GetPropertyClientData( wxPGPropArg id
) const
443 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(NULL
)
444 return p
->GetClientData();
449 Returns first property which label matches given string.
451 NULL if none found. Note that this operation is extremely slow when
452 compared to GetPropertyByName().
454 wxPGProperty
* GetPropertyByLabel( const wxString
& label
) const;
456 /** Returns property with given name. NULL if none found.
458 wxPGProperty
* GetPropertyByName( const wxString
& name
) const;
460 /** Returns child property 'subname' of property 'name'. Same as
461 calling GetPropertyByName("name.subname"), albeit slightly faster.
463 wxPGProperty
* GetPropertyByName( const wxString
& name
,
464 const wxString
& subname
) const;
466 /** Returns writable reference to property's list of choices (and relevant
467 values). If property does not have any choices, will return reference
468 to an invalid set of choices that will return false on IsOk call.
470 wxPGChoices
& GetPropertyChoices( wxPGPropArg id
);
472 /** Returns property's editor. */
473 const wxPGEditor
* GetPropertyEditor( wxPGPropArg id
) const
475 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(NULL
)
476 return p
->GetEditorClass();
479 /** Returns help string associated with a property. */
480 wxString
GetPropertyHelpString( wxPGPropArg id
) const
482 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(m_emptyString
)
483 return p
->GetHelpString();
486 /** Returns property's custom value image (NULL of none). */
487 wxBitmap
* GetPropertyImage( wxPGPropArg id
) const
489 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(NULL
)
490 return p
->GetValueImage();
493 /** Returns property's position under its parent. */
494 unsigned int GetPropertyIndex( wxPGPropArg id
)
496 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(INT_MAX
)
497 return p
->GetIndexInParent();
500 /** Returns label of a property. */
501 const wxString
& GetPropertyLabel( wxPGPropArg id
)
503 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(m_emptyString
)
504 return p
->GetLabel();
507 /** Returns name of a property, by which it is globally accessible. */
508 wxString
GetPropertyName( wxPGPropArg id
)
510 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(m_emptyString
)
514 /** Returns parent item of a property. */
515 wxPGProperty
* GetPropertyParent( wxPGPropArg id
)
517 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
518 return p
->GetParent();
522 /** Returns validator of a property as a reference, which you
523 can pass to any number of SetPropertyValidator.
525 wxValidator
* GetPropertyValidator( wxPGPropArg id
)
527 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(NULL
)
528 return p
->GetValidator();
532 /** Returns value as wxVariant. To get wxObject pointer from it,
533 you will have to use WX_PG_VARIANT_TO_WXOBJECT(VARIANT,CLASSNAME) macro.
535 If property value is unspecified, Null variant is returned.
537 wxVariant
GetPropertyValue( wxPGPropArg id
)
539 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxVariant())
540 return p
->GetValue();
543 wxString
GetPropertyValueAsString( wxPGPropArg id
) const;
544 long GetPropertyValueAsLong( wxPGPropArg id
) const;
545 unsigned long GetPropertyValueAsULong( wxPGPropArg id
) const
547 return (unsigned long) GetPropertyValueAsLong(id
);
550 int GetPropertyValueAsInt( wxPGPropArg id
) const
551 { return (int)GetPropertyValueAsLong(id
); }
553 bool GetPropertyValueAsBool( wxPGPropArg id
) const;
554 double GetPropertyValueAsDouble( wxPGPropArg id
) const;
555 void* GetPropertyValueAsVoidPtr( wxPGPropArg id
) const;
557 #define wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(TYPENAME, DEFVAL) \
558 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFVAL) \
559 wxString typeName(wxS(TYPENAME)); \
560 wxVariant value = p->GetValue(); \
561 if ( value.GetType() != typeName ) \
563 wxPGGetFailed(p, typeName); \
567 #define wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK(TYPENAME, DEFVAL) \
568 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFVAL) \
569 wxVariant value = p->GetValue(); \
570 if ( value.GetType() != wxS(TYPENAME) ) \
573 wxArrayString GetPropertyValueAsArrayString( wxPGPropArg id ) const
575 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("arrstring",
577 return value
.GetArrayString();
580 wxPoint
GetPropertyValueAsPoint( wxPGPropArg id
) const
582 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("wxPoint", wxPoint())
588 wxSize
GetPropertyValueAsSize( wxPGPropArg id
) const
590 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("wxSize", wxSize())
596 wxLongLong_t
GetPropertyValueAsLongLong( wxPGPropArg id
) const
598 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK("wxLongLong",
599 (long) GetPropertyValueAsLong(id
))
602 return ll
.GetValue();
605 wxULongLong_t
GetPropertyValueAsULongLong( wxPGPropArg id
) const
607 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK("wxULongLong",
608 (unsigned long) GetPropertyValueAsULong(id
))
611 return ull
.GetValue();
614 wxArrayInt
GetPropertyValueAsArrayInt( wxPGPropArg id
) const
616 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("wxArrayInt",
624 wxDateTime
GetPropertyValueAsDateTime( wxPGPropArg id
) const
626 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("datetime",
628 return value
.GetDateTime();
633 /** Returns a wxVariant list containing wxVariant versions of all
634 property values. Order is not guaranteed.
636 Use wxPG_KEEP_STRUCTURE to retain category structure; each sub
637 category will be its own wxVariantList of wxVariant.
638 Use wxPG_INC_ATTRIBUTES to include property attributes as well.
639 Each attribute will be stored as list variant named
640 "@@<propname>@@attr."
643 wxVariant
GetPropertyValues( const wxString
& listname
= wxEmptyString
,
644 wxPGProperty
* baseparent
= NULL
, long flags
= 0 ) const
646 return m_pState
->DoGetPropertyValues(listname
, baseparent
, flags
);
650 wxString
GetPropertyValueType( wxPGPropArg id
)
652 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(m_emptyString
)
653 return p
->GetValueType();
656 /** Returns currently selected property. */
657 wxPGProperty
* GetSelection() const
659 return m_pState
->GetSelection();
663 wxPropertyGridPageState
* GetState() const { return m_pState
; }
666 /** Similar to GetIterator(), but instead returns wxPGVIterator instance,
667 which can be useful for forward-iterating through arbitrary property
671 See @ref propgrid_iterator_flags.
673 virtual wxPGVIterator
GetVIterator( int flags
) const;
675 /** Hides or reveals a property.
677 If true, hides property, otherwise reveals it.
679 By default changes are applied recursively. Set this paramter
680 wxPG_DONT_RECURSE to prevent this.
682 bool HideProperty( wxPGPropArg id
,
684 int flags
= wxPG_RECURSE
);
686 #if wxPG_INCLUDE_ADVPROPS
687 /** Initializes *all* property types. Causes references to most object
688 files in the library, so calling this may cause significant increase
689 in executable size when linking with static library.
691 static void InitAllTypeHandlers();
693 static void InitAllTypeHandlers() { }
697 /** Inserts property to the property container.
700 New property is inserted just prior to this. Available only
701 in the first variant. There are two versions of this function
702 to allow this parameter to be either an id or name to
706 Pointer to the inserted property. wxPropertyGrid will take
707 ownership of this object.
710 New property is inserted under this category. Available only
711 in the second variant. There are two versions of this function
712 to allow this parameter to be either an id or name to
716 Index under category. Available only in the second variant.
717 If index is < 0, property is appended in category.
720 Returns id for the property,
724 - wxPropertyGrid takes the ownership of the property pointer.
726 - While Append may be faster way to add items, make note that when
727 both types of data storage (categoric and
728 non-categoric) are active, Insert becomes even more slow. This is
729 especially true if current mode is non-categoric.
736 wxPGProperty* my_cat_id = propertygrid->Append(
737 new wxPropertyCategory("My Category") );
741 // insert into category - using second variant
742 wxPGProperty* my_item_id_1 = propertygrid->Insert(
743 my_cat_id, 0, new wxStringProperty("My String 1") );
745 // insert before to first item - using first variant
746 wxPGProperty* my_item_id_2 = propertygrid->Insert(
747 my_item_id, new wxStringProperty("My String 2") );
752 wxPGProperty
* Insert( wxPGPropArg priorThis
, wxPGProperty
* newproperty
);
753 wxPGProperty
* Insert( wxPGPropArg parent
,
755 wxPGProperty
* newproperty
);
758 /** Returns true if property is a category. */
759 bool IsPropertyCategory( wxPGPropArg id
) const
761 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
762 return p
->IsCategory();
765 /** Inserts choice to a property that can accept one.
767 See AddPropertyChoice for more details.
769 void InsertPropertyChoice( wxPGPropArg id
,
770 const wxString
& label
,
772 int value
= wxPG_INVALID_VALUE
);
774 /** Returns true if property is enabled. */
775 bool IsPropertyEnabled( wxPGPropArg id
) const
777 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
778 return (!(p
->GetFlags() & wxPG_PROP_DISABLED
))?true:false;
782 Returns true if given property is expanded.
784 Naturally, always returns false for properties that cannot be expanded.
786 bool IsPropertyExpanded( wxPGPropArg id
) const;
789 Returns true if property has been modified after value set or modify
790 flag clear by software.
792 bool IsPropertyModified( wxPGPropArg id
) const
794 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
795 return ( (p
->GetFlags() & wxPG_PROP_MODIFIED
) ? true : false );
799 Returns true if property is shown (ie hideproperty with true not
802 bool IsPropertyShown( wxPGPropArg id
) const
804 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
805 return (!(p
->GetFlags() & wxPG_PROP_HIDDEN
))?true:false;
808 /** Returns true if property value is set to unspecified.
810 bool IsPropertyValueUnspecified( wxPGPropArg id
) const
812 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
813 return p
->IsValueUnspecified();
817 Disables (limit = true) or enables (limit = false) wxTextCtrl editor of
818 a property, if it is not the sole mean to edit the value.
820 void LimitPropertyEditing( wxPGPropArg id
, bool limit
= true );
822 /** If state is shown in it's grid, refresh it now.
824 virtual void RefreshGrid( wxPropertyGridPageState
* state
= NULL
);
826 #if wxPG_INCLUDE_ADVPROPS
828 Initializes additional property editors (SpinCtrl etc.). Causes
829 references to most object files in the library, so calling this may
830 cause significant increase in executable size when linking with static
833 static void RegisterAdditionalEditors();
835 static void RegisterAdditionalEditors() { }
838 /** Replaces property with id with newly created property. For example,
839 this code replaces existing property named "Flags" with one that
840 will have different set of items:
842 pg->ReplaceProperty("Flags",
843 wxFlagsProperty("Flags", wxPG_LABEL, newItems))
845 For more info, see wxPropertyGrid::Insert.
847 wxPGProperty
* ReplaceProperty( wxPGPropArg id
, wxPGProperty
* property
);
849 /** @anchor propgridinterface_editablestate_flags
851 Flags for wxPropertyGridInterface::SaveEditableState() and
852 wxPropertyGridInterface::RestoreEditableState().
854 enum EditableStateFlags
856 /** Include selected property. */
857 SelectionState
= 0x01,
858 /** Include expanded/collapsed property information. */
859 ExpandedState
= 0x02,
860 /** Include scrolled position. */
861 ScrollPosState
= 0x04,
862 /** Include selected page information.
863 Only applies to wxPropertyGridManager. */
865 /** Include splitter position. Stored for each page. */
866 SplitterPosState
= 0x10,
869 Include all supported user editable state information.
870 This is usually the default value. */
871 AllStates
= SelectionState
|
879 Restores user-editable state.
881 See also wxPropertyGridInterface::SaveEditableState().
884 String generated by SaveEditableState.
887 Which parts to restore from source string. See @ref
888 propgridinterface_editablestate_flags "list of editable state
892 False if there was problem reading the string.
895 If some parts of state (such as scrolled or splitter position) fail to
896 restore correctly, please make sure that you call this function after
897 wxPropertyGrid size has been set (this may sometimes be tricky when
900 bool RestoreEditableState( const wxString
& src
,
901 int restoreStates
= AllStates
);
904 Used to acquire user-editable state (selected property, expanded
905 properties, scrolled position, splitter positions).
907 @param includedStates
908 Which parts of state to include. See @ref
909 propgridinterface_editablestate_flags "list of editable state flags".
911 wxString
SaveEditableState( int includedStates
= AllStates
) const;
914 Lets user to set the strings listed in the choice dropdown of a
915 wxBoolProperty. Defaults are "True" and "False", so changing them to,
916 say, "Yes" and "No" may be useful in some less technical applications.
918 static void SetBoolChoices( const wxString
& trueChoice
,
919 const wxString
& falseChoice
);
921 /** Sets or clears flag(s) of all properties in given array.
923 Property flags to set or clear.
925 Set to true if you want to clear flag instead of setting them.
927 void SetPropertiesFlag( const wxArrayPGProperty
& srcArr
,
928 wxPGProperty::FlagType flags
,
929 bool inverse
= false );
931 /** Sets an attribute for this property.
933 Text identifier of attribute. See @ref propgrid_property_attributes.
937 Optional. Use wxPG_RECURSE to set the attribute to child properties
940 void SetPropertyAttribute( wxPGPropArg id
,
941 const wxString
& attrName
,
945 DoSetPropertyAttribute(id
,attrName
,value
,argFlags
);
948 /** Sets attributes from a wxPGAttributeStorage.
950 void SetPropertyAttributes( wxPGPropArg id
,
951 const wxPGAttributeStorage
& attributes
)
953 wxPG_PROP_ARG_CALL_PROLOG()
954 p
->SetAttributes(attributes
);
957 /** Sets text, bitmap, and colours for given column's cell.
960 - You can set label cell by setting column to 0.
961 - You can use wxPG_LABEL as text to use default text for column.
963 void SetPropertyCell( wxPGPropArg id
,
965 const wxString
& text
= wxEmptyString
,
966 const wxBitmap
& bitmap
= wxNullBitmap
,
967 const wxColour
& fgCol
= wxNullColour
,
968 const wxColour
& bgCol
= wxNullColour
)
970 wxPG_PROP_ARG_CALL_PROLOG()
971 p
->SetCell( column
, new wxPGCell(text
, bitmap
, fgCol
, bgCol
) );
974 /** Set choices of a property to specified set of labels and values.
977 This operation clears the property value.
979 void SetPropertyChoices( wxPGPropArg id
, wxPGChoices
& choices
)
981 wxPG_PROP_ARG_CALL_PROLOG()
982 p
->SetChoices(choices
);
987 If property's set of choices is shared, then calling this method
988 converts it to private.
990 void SetPropertyChoicesExclusive( wxPGPropArg id
)
992 wxPG_PROP_ARG_CALL_PROLOG()
993 p
->SetChoicesExclusive();
997 /** Sets client data (void*) of a property.
999 This untyped client data has to be deleted manually.
1001 void SetPropertyClientData( wxPGPropArg id
, void* clientData
)
1003 wxPG_PROP_ARG_CALL_PROLOG()
1004 p
->SetClientData(clientData
);
1007 /** Sets editor for a property.
1010 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1011 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full
1014 For custom editors, use pointer you received from
1015 wxPropertyGrid::RegisterEditorClass().
1017 void SetPropertyEditor( wxPGPropArg id
, const wxPGEditor
* editor
)
1019 wxPG_PROP_ARG_CALL_PROLOG()
1020 wxCHECK_RET( editor
, wxT("unknown/NULL editor") );
1021 p
->SetEditor(editor
);
1026 /** Sets editor control of a property. As editor argument, use
1027 editor name string, such as "TextCtrl" or "Choice".
1029 void SetPropertyEditor( wxPGPropArg id
, const wxString
& editorName
)
1031 SetPropertyEditor(id
,GetEditorByName(editorName
));
1034 /** Sets label of a property.
1036 void SetPropertyLabel( wxPGPropArg id
, const wxString
& newproplabel
);
1038 /** Set modified status of a property and all its children.
1040 void SetPropertyModifiedStatus( wxPGPropArg id
, bool modified
)
1042 wxPG_PROP_ARG_CALL_PROLOG()
1043 p
->SetModifiedStatus(modified
);
1047 Sets property (and, recursively, its children) to have read-only value.
1048 In other words, user cannot change the value in the editor, but they
1051 This is mainly for use with textctrl editor. Not all other editors fully
1054 By default changes are applied recursively. Set this paramter
1055 wxPG_DONT_RECURSE to prevent this.
1057 void SetPropertyReadOnly( wxPGPropArg id
,
1059 int flags
= wxPG_RECURSE
)
1061 wxPG_PROP_ARG_CALL_PROLOG()
1062 if ( flags
& wxPG_RECURSE
)
1063 p
->SetFlagRecursively(wxPG_PROP_READONLY
, set
);
1065 p
->SetFlag(wxPG_PROP_READONLY
);
1068 /** Sets property's value to unspecified.
1069 If it has children (it may be category), then the same thing is done to
1072 void SetPropertyValueUnspecified( wxPGPropArg id
);
1075 /** Sets various property values from a list of wxVariants. If property with
1076 name is missing from the grid, new property is created under given
1077 default category (or root if omitted).
1079 void SetPropertyValues( const wxVariantList
& list
,
1080 wxPGPropArg defaultCategory
= wxNullProperty
)
1083 if ( defaultCategory
.HasName() ) p
= defaultCategory
.GetPtr(this);
1084 else p
= defaultCategory
.GetPtr0();
1085 m_pState
->DoSetPropertyValues(list
, p
);
1088 void SetPropertyValues( const wxVariant
& list
,
1089 wxPGPropArg defaultCategory
= wxNullProperty
)
1091 SetPropertyValues(list
.GetList(),defaultCategory
);
1095 /** Associates the help string with property.
1097 By default, text is shown either in the manager's "description"
1098 text box or in the status bar. If extra window style
1099 wxPG_EX_HELP_AS_TOOLTIPS is used, then the text will appear as a
1102 void SetPropertyHelpString( wxPGPropArg id
, const wxString
& helpString
)
1104 wxPG_PROP_ARG_CALL_PROLOG()
1105 p
->SetHelpString(helpString
);
1108 /** Set wxBitmap in front of the value.
1110 - Bitmap will be scaled to a size returned by
1111 wxPropertyGrid::GetImageSize();
1113 void SetPropertyImage( wxPGPropArg id
, wxBitmap
& bmp
)
1115 wxPG_PROP_ARG_CALL_PROLOG()
1116 p
->SetValueImage(bmp
);
1120 /** Sets max length of property's text.
1122 bool SetPropertyMaxLength( wxPGPropArg id
, int maxLen
);
1124 #if wxUSE_VALIDATORS
1125 /** Sets validator of a property.
1127 void SetPropertyValidator( wxPGPropArg id
, const wxValidator
& validator
)
1129 wxPG_PROP_ARG_CALL_PROLOG()
1130 p
->SetValidator(validator
);
1135 /** Sets value (long integer) of a property.
1137 void SetPropertyValue( wxPGPropArg id
, long value
)
1140 SetPropVal( id
, v
);
1143 /** Sets value (integer) of a property.
1145 void SetPropertyValue( wxPGPropArg id
, int value
)
1147 wxVariant
v((long)value
);
1148 SetPropVal( id
, v
);
1150 /** Sets value (floating point) of a property.
1152 void SetPropertyValue( wxPGPropArg id
, double value
)
1155 SetPropVal( id
, v
);
1157 /** Sets value (bool) of a property.
1159 void SetPropertyValue( wxPGPropArg id
, bool value
)
1162 SetPropVal( id
, v
);
1164 void SetPropertyValue( wxPGPropArg id
, const wxChar
* value
)
1166 SetPropertyValueString( id
, wxString(value
) );
1168 void SetPropertyValue( wxPGPropArg id
, const wxString
& value
)
1170 SetPropertyValueString( id
, value
);
1173 /** Sets value (wxArrayString) of a property.
1175 void SetPropertyValue( wxPGPropArg id
, const wxArrayString
& value
)
1178 SetPropVal( id
, v
);
1182 void SetPropertyValue( wxPGPropArg id
, const wxDateTime
& value
)
1185 SetPropVal( id
, v
);
1189 /** Sets value (wxObject*) of a property.
1191 void SetPropertyValue( wxPGPropArg id
, wxObject
* value
)
1194 SetPropVal( id
, v
);
1197 void SetPropertyValue( wxPGPropArg id
, wxObject
& value
)
1199 wxVariant
v(&value
);
1200 SetPropVal( id
, v
);
1203 /** Sets value (wxPoint&) of a property.
1205 void SetPropertyValue( wxPGPropArg id
, const wxPoint
& value
)
1207 wxVariant v
= WXVARIANT(value
);
1208 SetPropVal( id
, v
);
1210 /** Sets value (wxSize&) of a property.
1212 void SetPropertyValue( wxPGPropArg id
, const wxSize
& value
)
1214 wxVariant v
= WXVARIANT(value
);
1215 SetPropVal( id
, v
);
1217 /** Sets value (wxLongLong&) of a property.
1219 void SetPropertyValue( wxPGPropArg id
, wxLongLong_t value
)
1221 wxVariant v
= WXVARIANT(wxLongLong(value
));
1222 SetPropVal( id
, v
);
1224 /** Sets value (wxULongLong&) of a property.
1226 void SetPropertyValue( wxPGPropArg id
, wxULongLong_t value
)
1228 wxVariant v
= WXVARIANT(wxULongLong(value
));
1229 SetPropVal( id
, v
);
1231 /** Sets value (wxArrayInt&) of a property.
1233 void SetPropertyValue( wxPGPropArg id
, const wxArrayInt
& value
)
1235 wxVariant v
= WXVARIANT(value
);
1236 SetPropVal( id
, v
);
1240 /** Sets value (wxString) of a property.
1243 This method uses wxPGProperty::SetValueFromString, which all properties
1244 should implement. This means that there should not be a type error,
1245 and instead the string is converted to property's actual value type.
1247 void SetPropertyValueString( wxPGPropArg id
, const wxString
& value
);
1249 /** Sets value (wxVariant&) of a property.
1252 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run
1253 through validation process and send property change event.
1255 void SetPropertyValue( wxPGPropArg id
, wxVariant value
)
1257 SetPropVal( id
, value
);
1261 /** Sets value (wxVariant&) of a property. Same as SetPropertyValue, but
1262 accepts reference. */
1263 void SetPropVal( wxPGPropArg id
, wxVariant
& value
);
1266 /** Adjusts how wxPropertyGrid behaves when invalid value is entered
1269 See @link vfbflags list of valid flags values@endlink
1271 void SetValidationFailureBehavior( int vfbFlags
);
1275 def
MapType(class_
,factory
):
1276 "Registers Python type/class to property mapping.\n\nfactory: Property builder function/class."
1277 global _type2property
1279 mappings
= _type2property
1281 raise
AssertionError("call only after a propertygrid or manager instance constructed")
1283 mappings
[class_
] = factory
1286 def
DoDefaultTypeMappings(self
):
1287 "Map built-in properties."
1288 global _type2property
1290 mappings
= _type2property
1295 _type2property
= mappings
1297 mappings
[str
] = StringProperty
1298 mappings
[unicode
] = StringProperty
1299 mappings
[int] = IntProperty
1300 mappings
[float] = FloatProperty
1301 mappings
[bool] = BoolProperty
1302 mappings
[list
] = ArrayStringProperty
1303 mappings
[tuple
] = ArrayStringProperty
1304 mappings
[wx
.Font
] = FontProperty
1305 mappings
[wx
.Colour
] = ColourProperty
1306 "mappings[wx.Size] = SizeProperty"
1307 "mappings[wx.Point] = PointProperty"
1308 "mappings[wx.FontData] = FontDataProperty"
1310 def
DoDefaultValueTypeMappings(self
):
1311 "Map pg value type ids to getter methods."
1314 vt2getter
= _vt2getter
1319 _vt2getter
= vt2getter
1321 def
GetPropertyValues(self
,dict_
=None
, as_strings
=False
, inc_attributes
=False
):
1322 "Returns values in the grid."
1324 "dict_: if not given, then a new one is created. dict_ can be"
1325 " object as well, in which case it's __dict__ is used."
1326 "as_strings: if True, then string representations of values"
1327 " are fetched instead of native types. Useful for config and such."
1328 "inc_attributes: if True, then property attributes are added"
1329 " as @<propname>@<attr>."
1331 "Return value: dictionary with values. It is always a dictionary,"
1332 "so if dict_ was object with __dict__ attribute, then that attribute"
1337 elif
hasattr(dict_
,'__dict__'):
1338 dict_
= dict_
.__dict__
1341 getter
= self
.GetPropertyValue
1343 getter
= self
.GetPropertyValueAsString
1345 it
= self
.GetVIterator(PG_ITERATE_PROPERTIES
)
1346 while not it
.AtEnd():
1347 p
= it
.GetProperty()
1350 dict_
[name
] = getter(p
)
1353 attrs
= p
.GetAttributes()
1354 if attrs
and len(attrs
):
1355 dict_
['@%s@attr'%name
] = attrs
1361 GetValues
= GetPropertyValues
1364 def
SetPropertyValues(self
,dict_
):
1365 "Sets property values from dict_, which can be either\ndictionary or an object with __dict__ attribute."
1367 "autofill: If true, keys with not relevant properties"
1368 " are auto-created. For more info, see AutoFill."
1371 " * Keys starting with underscore are ignored."
1372 " * Attributes can be set with entries named @<propname>@<attr>."
1379 elif
hasattr(dict_
,'__dict__'):
1380 dict_
= dict_
.__dict__
1384 def
set_sub_obj(k0
,dict_
):
1385 for k
,v in dict_
.iteritems():
1387 if k
.endswith('@attr'):
1388 attr_dicts
.append((k
[1:-5],v
))
1391 self
.SetPropertyValue(k
,v
)
1395 self
._AutoFillOne(k0
,k
,v
)
1398 if isinstance(v
,dict
):
1400 elif
hasattr(v
,'__dict__'):
1401 set_sub_obj(k
,v
.__dict__
)
1404 for k
,v in attr_dicts
:
1405 p
= GetPropertyByName(k
)
1407 raise
AssertionError("No such property: '%s'"%k
)
1408 for an
,av in v
.iteritems():
1409 p
.SetAttribute(an
, av
)
1413 is_manager
= isinstance(self
,PropertyGridManager
)
1416 set_sub_obj(self
.GetGrid().GetRoot(),dict_
)
1419 traceback
.print_exc()
1423 SetValues
= SetPropertyValues
1425 def
_AutoFillMany(self
,cat
,dict_
):
1426 for k
,v in dict_
.iteritems():
1427 self
._AutoFillOne(cat
,k
,v
)
1430 def
_AutoFillOne(self
,cat
,k
,v
):
1431 global _type2property
1433 factory
= _type2property
.get(v
.__class__
,None
)
1436 self
.AppendIn( cat
, factory(k
,k
,v
) )
1437 elif
hasattr(v
,'__dict__'):
1438 cat2
= self
.AppendIn( cat
, PropertyCategory(k
) )
1439 self
._AutoFillMany(cat2
,v
.__dict__
)
1440 elif
isinstance(v
,dict
):
1441 cat2
= self
.AppendIn( cat
, PropertyCategory(k
) )
1442 self
._AutoFillMany(cat2
,v
)
1443 elif
not k
.startswith('_'):
1444 raise
AssertionError("member '%s' is of unregisted type/class '%s'"%(k
,v
.__class__
))
1447 def
AutoFill(self
,obj
,parent
=None
):
1448 "Clears properties and re-fills to match members and\nvalues of given object or dictionary obj."
1450 self
.edited_objects
[parent
] = obj
1453 is_manager
= isinstance(self
,PropertyGridManager
)
1457 page
= self
.GetCurrentPage()
1459 parent
= page
.GetRoot()
1462 parent
= self
.GetGrid().GetRoot()
1464 it
= self
.GetIterator(PG_ITERATE_PROPERTIES
, parent
)
1465 it
.Next() # Skip the parent
1466 while not it
.AtEnd():
1467 p
= it
.GetProperty()
1468 if not p
.IsSomeParent(parent
):
1471 self
.DeleteProperty(p
)
1476 if not is_manager
or page
== self
.GetCurrentPage():
1481 self
._AutoFillMany(parent
,obj
.__dict__
)
1484 traceback
.print_exc()
1489 def
RegisterEditor(self
, editor
, editorName
=None
):
1490 "Transform class into instance, if necessary."
1491 if not isinstance(editor
, PGEditor
):
1494 editorName
= editor
.__class__
.__name__
1496 self
._editor_instances
.append(editor
)
1498 self
._editor_instances
= [editor
]
1499 RegisterEditor(editor
, editorName
)
1501 def
GetPropertyClientData(self
, p
):
1502 if isinstance(p
, basestring
):
1503 p
= self
.GetPropertyByName(p
)
1504 return p
.GetClientData()
1506 def
SetPropertyClientData(self
, p
, data
):
1507 if isinstance(p
, basestring
):
1508 p
= self
.GetPropertyByName(p
)
1509 return p
.SetClientData(data
)
1513 // GetPropertyByName With nice assertion error message.
1514 wxPGProperty
* GetPropertyByNameA( const wxString
& name
) const;
1516 static wxPGEditor
* GetEditorByName( const wxString
& editorName
);
1518 virtual void RefreshProperty( wxPGProperty
* p
) = 0;
1522 // Returns page state data for given (sub) page (-1 means current page).
1523 virtual wxPropertyGridPageState
* GetPageState( int pageIndex
) const
1525 if ( pageIndex
<= 0 )
1530 virtual bool DoSelectPage( int WXUNUSED(index
) ) { return true; }
1532 // Default call's m_pState's BaseGetPropertyByName
1533 virtual wxPGProperty
* DoGetPropertyByName( const wxString
& name
) const;
1537 // Deriving classes must set this (it must be only or current page).
1538 wxPropertyGridPageState
* m_pState
;
1540 // Intermediate version needed due to wxVariant copying inefficiency
1541 void DoSetPropertyAttribute( wxPGPropArg id
,
1542 const wxString
& name
,
1543 wxVariant
& value
, long argFlags
);
1545 // Empty string object to return from member functions returning const
1547 wxString m_emptyString
;
1550 // Cannot be GetGrid() due to ambiguity issues.
1551 wxPropertyGrid
* GetPropertyGrid()
1553 return m_pState
->GetGrid();
1556 // Cannot be GetGrid() due to ambiguity issues.
1557 const wxPropertyGrid
* GetPropertyGrid() const
1559 return (const wxPropertyGrid
*) m_pState
->GetGrid();
1561 #endif // #ifndef SWIG
1563 friend class wxPropertyGrid
;
1564 friend class wxPropertyGridManager
;
1567 #endif // wxUSE_PROPGRID
1569 #endif // __WX_PROPGRID_PROPGRIDIFACE_H__