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() { }
173 Appends property to the list.
175 wxPropertyGrid assumes ownership of the object.
176 Becomes child of most recently added category.
178 - wxPropertyGrid takes the ownership of the property pointer.
179 - If appending a category with name identical to a category already in
180 the wxPropertyGrid, then newly created category is deleted, and most
181 recently added category (under which properties are appended) is set
182 to the one with same name. This allows easier adding of items to same
183 categories in multiple passes.
184 - Does not automatically redraw the control, so you may need to call
185 Refresh when calling this function after control has been shown for
188 wxPGProperty
* Append( wxPGProperty
* property
);
190 wxPGProperty
* AppendIn( wxPGPropArg id
, wxPGProperty
* newproperty
);
193 In order to add new items into a property with fixed children (for
194 instance, wxFlagsProperty), you need to call this method. After
195 populating has been finished, you need to call EndAddChildren.
197 void BeginAddChildren( wxPGPropArg id
);
199 /** Deletes all properties.
201 virtual void Clear() = 0;
204 Clears current selection, if any.
207 If set to @false, deselecting the property will always work,
208 even if its editor had invalid value in it.
210 @return Returns @true if successful or if there was no selection. May
211 fail if validation was enabled and active editor had invalid
214 bool ClearSelection( bool validation
= false);
216 /** Resets modified status of all properties.
218 void ClearModifiedStatus();
220 /** Collapses given category or property with children.
221 Returns true if actually collapses.
223 bool Collapse( wxPGPropArg id
);
225 /** Collapses all items that can be collapsed.
228 Return false if failed (may fail if editor value cannot be validated).
230 bool CollapseAll() { return ExpandAll(false); }
233 Changes value of a property, as if from an editor.
234 Use this instead of SetPropertyValue() if you need the value to run
235 through validation process, and also send the property change event.
238 Returns true if value was successfully changed.
240 bool ChangePropertyValue( wxPGPropArg id
, wxVariant newValue
);
243 Deletes a property by id. If category is deleted, all children are
244 automatically deleted as well.
246 void DeleteProperty( wxPGPropArg id
);
248 /** Disables property. */
249 bool DisableProperty( wxPGPropArg id
) { return EnableProperty(id
,false); }
252 Returns true if all property grid data changes have been committed.
254 Usually only returns false if value in active editor has been
255 invalidated by a wxValidator.
257 bool EditorValidate();
260 Enables or disables property, depending on whether enable is true or
263 bool EnableProperty( wxPGPropArg id
, bool enable
= true );
265 /** Called after population of property with fixed children has finished.
267 void EndAddChildren( wxPGPropArg id
);
269 /** Expands given category or property with children.
270 Returns true if actually expands.
272 bool Expand( wxPGPropArg id
);
274 /** Expands all items that can be expanded.
276 bool ExpandAll( bool expand
= true );
278 /** Returns id of first child of given property.
280 Does not return sub-properties!
282 wxPGProperty
* GetFirstChild( wxPGPropArg id
)
284 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
286 if ( !p
->GetChildCount() || p
->HasFlag(wxPG_PROP_AGGREGATE
) )
287 return wxNullProperty
;
293 /** Returns iterator class instance.
295 See @ref propgrid_iterator_flags. Value wxPG_ITERATE_DEFAULT causes
296 iteration over everything except private child properties.
298 Property to start iteration from. If NULL, then first child of root
301 Either wxTOP or wxBOTTOM. wxTOP will indicate that iterations start
302 from the first property from the top, and wxBOTTOM means that the
303 iteration will instead begin from bottommost valid item.
305 wxPropertyGridIterator
GetIterator( int flags
= wxPG_ITERATE_DEFAULT
,
306 wxPGProperty
* firstProp
= NULL
)
308 return wxPropertyGridIterator( m_pState
, flags
, firstProp
);
311 wxPropertyGridConstIterator
312 GetIterator( int flags
= wxPG_ITERATE_DEFAULT
,
313 wxPGProperty
* firstProp
= NULL
) const
315 return wxPropertyGridConstIterator( m_pState
, flags
, firstProp
);
318 wxPropertyGridIterator
GetIterator( int flags
, int startPos
)
320 return wxPropertyGridIterator( m_pState
, flags
, startPos
);
323 wxPropertyGridConstIterator
GetIterator( int flags
, int startPos
) const
325 return wxPropertyGridConstIterator( m_pState
, flags
, startPos
);
329 /** Returns id of first item, whether it is a category or property.
331 @link iteratorflags List of iterator flags@endlink
333 wxPGProperty
* GetFirst( int flags
= wxPG_ITERATE_ALL
)
335 wxPropertyGridIterator
it( m_pState
, flags
, wxNullProperty
, 1 );
339 const wxPGProperty
* GetFirst( int flags
= wxPG_ITERATE_ALL
) const
341 return ((wxPropertyGridInterface
*)this)->GetFirst(flags
);
345 Returns id of property with given name (case-sensitive).
347 If there is no property with such name, returned property id is invalid
348 ( i.e. it will return false with IsOk method).
350 - Sub-properties (i.e. properties which have parent that is not
351 category or root) can not be accessed globally by their name.
352 Instead, use "<property>.<subproperty>" in place of "<subproperty>".
354 wxPGProperty
* GetProperty( const wxString
& name
) const
356 return GetPropertyByName(name
);
359 /** Returns map-like storage of property's attributes.
361 Note that if extra style wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES is set,
362 then builtin-attributes are not included in the storage.
364 const wxPGAttributeStorage
& GetPropertyAttributes( wxPGPropArg id
) const
366 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(*((const wxPGAttributeStorage
*)NULL
));
367 return p
->GetAttributes();
370 /** Adds to 'targetArr' pointers to properties that have given
371 flags 'flags' set. However, if 'inverse' is set to true, then
372 only properties without given flags are stored.
374 Property flags to use.
376 Iterator flags to use. Default is everything expect private children.
378 void GetPropertiesWithFlag( wxArrayPGProperty
* targetArr
,
379 wxPGProperty::FlagType flags
,
380 bool inverse
= false,
381 int iterFlags
= wxPG_ITERATE_PROPERTIES
|
382 wxPG_ITERATE_HIDDEN
|
383 wxPG_ITERATE_CATEGORIES
) const;
385 /** Returns value of given attribute. If none found, returns NULL-variant.
387 wxVariant
GetPropertyAttribute( wxPGPropArg id
,
388 const wxString
& attrName
) const
390 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullVariant
)
391 return p
->GetAttribute(attrName
);
394 /** Returns pointer of property's nearest parent category. If no category
397 wxPropertyCategory
* GetPropertyCategory( wxPGPropArg id
) const
399 wxPG_PROP_ID_CONST_CALL_PROLOG_RETVAL(NULL
)
400 return m_pState
->GetPropertyCategory(p
);
404 /** Returns client data (void*) of a property. */
405 void* GetPropertyClientData( wxPGPropArg id
) const
407 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(NULL
)
408 return p
->GetClientData();
413 Returns first property which label matches given string.
415 NULL if none found. Note that this operation is extremely slow when
416 compared to GetPropertyByName().
418 wxPGProperty
* GetPropertyByLabel( const wxString
& label
) const;
420 /** Returns property with given name. NULL if none found.
422 wxPGProperty
* GetPropertyByName( const wxString
& name
) const;
424 /** Returns child property 'subname' of property 'name'. Same as
425 calling GetPropertyByName("name.subname"), albeit slightly faster.
427 wxPGProperty
* GetPropertyByName( const wxString
& name
,
428 const wxString
& subname
) const;
430 /** Returns property's editor. */
431 const wxPGEditor
* GetPropertyEditor( wxPGPropArg id
) const
433 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(NULL
)
434 return p
->GetEditorClass();
437 /** Returns help string associated with a property. */
438 wxString
GetPropertyHelpString( wxPGPropArg id
) const
440 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(m_emptyString
)
441 return p
->GetHelpString();
444 /** Returns property's custom value image (NULL of none). */
445 wxBitmap
* GetPropertyImage( wxPGPropArg id
) const
447 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(NULL
)
448 return p
->GetValueImage();
451 /** Returns label of a property. */
452 const wxString
& GetPropertyLabel( wxPGPropArg id
)
454 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(m_emptyString
)
455 return p
->GetLabel();
458 /** Returns name of a property, by which it is globally accessible. */
459 wxString
GetPropertyName( wxPGProperty
* property
)
461 return property
->GetName();
464 /** Returns parent item of a property. */
465 wxPGProperty
* GetPropertyParent( wxPGPropArg id
)
467 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxNullProperty
)
468 return p
->GetParent();
472 /** Returns validator of a property as a reference, which you
473 can pass to any number of SetPropertyValidator.
475 wxValidator
* GetPropertyValidator( wxPGPropArg id
)
477 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(NULL
)
478 return p
->GetValidator();
482 /** Returns value as wxVariant. To get wxObject pointer from it,
483 you will have to use WX_PG_VARIANT_TO_WXOBJECT(VARIANT,CLASSNAME) macro.
485 If property value is unspecified, Null variant is returned.
487 wxVariant
GetPropertyValue( wxPGPropArg id
)
489 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxVariant())
490 return p
->GetValue();
493 wxString
GetPropertyValueAsString( wxPGPropArg id
) const;
494 long GetPropertyValueAsLong( wxPGPropArg id
) const;
495 unsigned long GetPropertyValueAsULong( wxPGPropArg id
) const
497 return (unsigned long) GetPropertyValueAsLong(id
);
500 int GetPropertyValueAsInt( wxPGPropArg id
) const
501 { return (int)GetPropertyValueAsLong(id
); }
503 bool GetPropertyValueAsBool( wxPGPropArg id
) const;
504 double GetPropertyValueAsDouble( wxPGPropArg id
) const;
506 #define wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(TYPENAME, DEFVAL) \
507 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFVAL) \
508 wxString typeName(wxS(TYPENAME)); \
509 wxVariant value = p->GetValue(); \
510 if ( value.GetType() != typeName ) \
512 wxPGGetFailed(p, typeName); \
516 #define wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK(TYPENAME, DEFVAL) \
517 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFVAL) \
518 wxVariant value = p->GetValue(); \
519 if ( value.GetType() != wxS(TYPENAME) ) \
522 wxArrayString GetPropertyValueAsArrayString( wxPGPropArg id ) const
524 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("arrstring",
526 return value
.GetArrayString();
529 #if wxUSE_LONGLONG_NATIVE
530 wxLongLong_t
GetPropertyValueAsLongLong( wxPGPropArg id
) const
532 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK("wxLongLong",
533 (long) GetPropertyValueAsLong(id
))
536 return ll
.GetValue();
539 wxULongLong_t
GetPropertyValueAsULongLong( wxPGPropArg id
) const
541 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK("wxULongLong",
542 (unsigned long) GetPropertyValueAsULong(id
))
545 return ull
.GetValue();
549 wxArrayInt
GetPropertyValueAsArrayInt( wxPGPropArg id
) const
551 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("wxArrayInt",
559 wxDateTime
GetPropertyValueAsDateTime( wxPGPropArg id
) const
561 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL("datetime",
563 return value
.GetDateTime();
568 /** Returns a wxVariant list containing wxVariant versions of all
569 property values. Order is not guaranteed.
571 Use wxPG_KEEP_STRUCTURE to retain category structure; each sub
572 category will be its own wxVariantList of wxVariant.
573 Use wxPG_INC_ATTRIBUTES to include property attributes as well.
574 Each attribute will be stored as list variant named
575 "@@<propname>@@attr."
578 wxVariant
GetPropertyValues( const wxString
& listname
= wxEmptyString
,
579 wxPGProperty
* baseparent
= NULL
, long flags
= 0 ) const
581 return m_pState
->DoGetPropertyValues(listname
, baseparent
, flags
);
585 /** Returns currently selected property. */
586 wxPGProperty
* GetSelection() const
588 return m_pState
->GetSelection();
592 wxPropertyGridPageState
* GetState() const { return m_pState
; }
595 /** Similar to GetIterator(), but instead returns wxPGVIterator instance,
596 which can be useful for forward-iterating through arbitrary property
600 See @ref propgrid_iterator_flags.
602 virtual wxPGVIterator
GetVIterator( int flags
) const;
604 /** Hides or reveals a property.
606 If true, hides property, otherwise reveals it.
608 By default changes are applied recursively. Set this paramter
609 wxPG_DONT_RECURSE to prevent this.
611 bool HideProperty( wxPGPropArg id
,
613 int flags
= wxPG_RECURSE
);
615 #if wxPG_INCLUDE_ADVPROPS
616 /** Initializes *all* property types. Causes references to most object
617 files in the library, so calling this may cause significant increase
618 in executable size when linking with static library.
620 static void InitAllTypeHandlers();
622 static void InitAllTypeHandlers() { }
626 /** Inserts property to the property container.
629 New property is inserted just prior to this. Available only
630 in the first variant. There are two versions of this function
631 to allow this parameter to be either an id or name to
635 Pointer to the inserted property. wxPropertyGrid will take
636 ownership of this object.
639 New property is inserted under this category. Available only
640 in the second variant. There are two versions of this function
641 to allow this parameter to be either an id or name to
645 Index under category. Available only in the second variant.
646 If index is < 0, property is appended in category.
649 Returns id for the property,
653 - wxPropertyGrid takes the ownership of the property pointer.
655 - While Append may be faster way to add items, make note that when
656 both types of data storage (categoric and
657 non-categoric) are active, Insert becomes even more slow. This is
658 especially true if current mode is non-categoric.
665 wxPGProperty* my_cat_id = propertygrid->Append(
666 new wxPropertyCategory("My Category") );
670 // insert into category - using second variant
671 wxPGProperty* my_item_id_1 = propertygrid->Insert(
672 my_cat_id, 0, new wxStringProperty("My String 1") );
674 // insert before to first item - using first variant
675 wxPGProperty* my_item_id_2 = propertygrid->Insert(
676 my_item_id, new wxStringProperty("My String 2") );
681 wxPGProperty
* Insert( wxPGPropArg priorThis
, wxPGProperty
* newproperty
);
682 wxPGProperty
* Insert( wxPGPropArg parent
,
684 wxPGProperty
* newproperty
);
687 /** Returns true if property is a category. */
688 bool IsPropertyCategory( wxPGPropArg id
) const
690 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
691 return p
->IsCategory();
694 /** Returns true if property is enabled. */
695 bool IsPropertyEnabled( wxPGPropArg id
) const
697 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
698 return (!(p
->GetFlags() & wxPG_PROP_DISABLED
))?true:false;
702 Returns true if given property is expanded.
704 Naturally, always returns false for properties that cannot be expanded.
706 bool IsPropertyExpanded( wxPGPropArg id
) const;
709 Returns true if property has been modified after value set or modify
710 flag clear by software.
712 bool IsPropertyModified( wxPGPropArg id
) const
714 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
715 return ( (p
->GetFlags() & wxPG_PROP_MODIFIED
) ? true : false );
719 Returns true if property is shown (ie hideproperty with true not
722 bool IsPropertyShown( wxPGPropArg id
) const
724 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
725 return (!(p
->GetFlags() & wxPG_PROP_HIDDEN
))?true:false;
728 /** Returns true if property value is set to unspecified.
730 bool IsPropertyValueUnspecified( wxPGPropArg id
) const
732 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
733 return p
->IsValueUnspecified();
737 Disables (limit = true) or enables (limit = false) wxTextCtrl editor of
738 a property, if it is not the sole mean to edit the value.
740 void LimitPropertyEditing( wxPGPropArg id
, bool limit
= true );
742 /** If state is shown in it's grid, refresh it now.
744 virtual void RefreshGrid( wxPropertyGridPageState
* state
= NULL
);
746 #if wxPG_INCLUDE_ADVPROPS
748 Initializes additional property editors (SpinCtrl etc.). Causes
749 references to most object files in the library, so calling this may
750 cause significant increase in executable size when linking with static
753 static void RegisterAdditionalEditors();
755 static void RegisterAdditionalEditors() { }
758 /** Replaces property with id with newly created property. For example,
759 this code replaces existing property named "Flags" with one that
760 will have different set of items:
762 pg->ReplaceProperty("Flags",
763 wxFlagsProperty("Flags", wxPG_LABEL, newItems))
765 For more info, see wxPropertyGrid::Insert.
767 wxPGProperty
* ReplaceProperty( wxPGPropArg id
, wxPGProperty
* property
);
769 /** @anchor propgridinterface_editablestate_flags
771 Flags for wxPropertyGridInterface::SaveEditableState() and
772 wxPropertyGridInterface::RestoreEditableState().
774 enum EditableStateFlags
776 /** Include selected property. */
777 SelectionState
= 0x01,
778 /** Include expanded/collapsed property information. */
779 ExpandedState
= 0x02,
780 /** Include scrolled position. */
781 ScrollPosState
= 0x04,
782 /** Include selected page information.
783 Only applies to wxPropertyGridManager. */
785 /** Include splitter position. Stored for each page. */
786 SplitterPosState
= 0x10,
787 /** Include description box size.
788 Only applies to wxPropertyGridManager. */
792 Include all supported user editable state information.
793 This is usually the default value. */
794 AllStates
= SelectionState
|
803 Restores user-editable state.
805 See also wxPropertyGridInterface::SaveEditableState().
808 String generated by SaveEditableState.
811 Which parts to restore from source string. See @ref
812 propgridinterface_editablestate_flags "list of editable state
816 False if there was problem reading the string.
819 If some parts of state (such as scrolled or splitter position) fail to
820 restore correctly, please make sure that you call this function after
821 wxPropertyGrid size has been set (this may sometimes be tricky when
824 bool RestoreEditableState( const wxString
& src
,
825 int restoreStates
= AllStates
);
828 Used to acquire user-editable state (selected property, expanded
829 properties, scrolled position, splitter positions).
831 @param includedStates
832 Which parts of state to include. See @ref
833 propgridinterface_editablestate_flags "list of editable state flags".
835 wxString
SaveEditableState( int includedStates
= AllStates
) const;
838 Lets user to set the strings listed in the choice dropdown of a
839 wxBoolProperty. Defaults are "True" and "False", so changing them to,
840 say, "Yes" and "No" may be useful in some less technical applications.
842 static void SetBoolChoices( const wxString
& trueChoice
,
843 const wxString
& falseChoice
);
845 /** Sets an attribute for this property.
847 Text identifier of attribute. See @ref propgrid_property_attributes.
851 Optional. Use wxPG_RECURSE to set the attribute to child properties
854 void SetPropertyAttribute( wxPGPropArg id
,
855 const wxString
& attrName
,
859 DoSetPropertyAttribute(id
,attrName
,value
,argFlags
);
862 /** Sets property attribute for all applicapple properties.
863 Be sure to use this method only after all properties have been
866 void SetPropertyAttributeAll( const wxString
& attrName
, wxVariant value
);
869 Sets background colour of a property.
872 Property name or pointer.
875 New background colour.
878 If True, child properties are affected recursively. Property
879 categories are skipped if this flag is used.
881 void SetPropertyBackgroundColour( wxPGPropArg id
,
882 const wxColour
& colour
,
883 bool recursively
= true );
885 /** Resets text and background colours of given property.
887 void SetPropertyColoursToDefault( wxPGPropArg id
);
890 Sets text colour of a property.
893 Property name or pointer.
896 New background colour.
899 If True, child properties are affected recursively. Property
900 categories are skipped if this flag is used.
902 void SetPropertyTextColour( wxPGPropArg id
,
904 bool recursively
= true );
907 Returns background colour of first cell of a property.
909 wxColour
GetPropertyBackgroundColour( wxPGPropArg id
) const
911 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
912 return p
->GetCell(0).GetBgCol();
916 Returns text colour of first cell of a property.
918 wxColour
GetPropertyTextColour( wxPGPropArg id
) const
920 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxColour())
921 return p
->GetCell(0).GetFgCol();
924 /** Sets text, bitmap, and colours for given column's cell.
927 - You can set label cell by setting column to 0.
928 - You can use wxPG_LABEL as text to use default text for column.
930 void SetPropertyCell( wxPGPropArg id
,
932 const wxString
& text
= wxEmptyString
,
933 const wxBitmap
& bitmap
= wxNullBitmap
,
934 const wxColour
& fgCol
= wxNullColour
,
935 const wxColour
& bgCol
= wxNullColour
);
938 /** Sets client data (void*) of a property.
940 This untyped client data has to be deleted manually.
942 void SetPropertyClientData( wxPGPropArg id
, void* clientData
)
944 wxPG_PROP_ARG_CALL_PROLOG()
945 p
->SetClientData(clientData
);
948 /** Sets editor for a property.
951 For builtin editors, use wxPGEditor_X, where X is builtin editor's
952 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full
955 For custom editors, use pointer you received from
956 wxPropertyGrid::RegisterEditorClass().
958 void SetPropertyEditor( wxPGPropArg id
, const wxPGEditor
* editor
)
960 wxPG_PROP_ARG_CALL_PROLOG()
961 wxCHECK_RET( editor
, wxT("unknown/NULL editor") );
962 p
->SetEditor(editor
);
967 /** Sets editor control of a property. As editor argument, use
968 editor name string, such as "TextCtrl" or "Choice".
970 void SetPropertyEditor( wxPGPropArg id
, const wxString
& editorName
)
972 SetPropertyEditor(id
,GetEditorByName(editorName
));
975 /** Sets label of a property.
977 void SetPropertyLabel( wxPGPropArg id
, const wxString
& newproplabel
);
980 Sets name of a property.
983 Name or pointer of property which name to change.
986 New name for property.
988 void SetPropertyName( wxPGPropArg id
, const wxString
& newName
)
990 wxPG_PROP_ARG_CALL_PROLOG()
991 m_pState
->DoSetPropertyName( p
, newName
);
995 Sets property (and, recursively, its children) to have read-only value.
996 In other words, user cannot change the value in the editor, but they
999 This is mainly for use with textctrl editor. Not all other editors fully
1002 By default changes are applied recursively. Set this paramter
1003 wxPG_DONT_RECURSE to prevent this.
1005 void SetPropertyReadOnly( wxPGPropArg id
,
1007 int flags
= wxPG_RECURSE
)
1009 wxPG_PROP_ARG_CALL_PROLOG()
1010 if ( flags
& wxPG_RECURSE
)
1011 p
->SetFlagRecursively(wxPG_PROP_READONLY
, set
);
1013 p
->SetFlag(wxPG_PROP_READONLY
);
1016 /** Sets property's value to unspecified.
1017 If it has children (it may be category), then the same thing is done to
1020 void SetPropertyValueUnspecified( wxPGPropArg id
);
1023 /** Sets various property values from a list of wxVariants. If property with
1024 name is missing from the grid, new property is created under given
1025 default category (or root if omitted).
1027 void SetPropertyValues( const wxVariantList
& list
,
1028 wxPGPropArg defaultCategory
= wxNullProperty
)
1031 if ( defaultCategory
.HasName() ) p
= defaultCategory
.GetPtr(this);
1032 else p
= defaultCategory
.GetPtr0();
1033 m_pState
->DoSetPropertyValues(list
, p
);
1036 void SetPropertyValues( const wxVariant
& list
,
1037 wxPGPropArg defaultCategory
= wxNullProperty
)
1039 SetPropertyValues(list
.GetList(),defaultCategory
);
1043 /** Associates the help string with property.
1045 By default, text is shown either in the manager's "description"
1046 text box or in the status bar. If extra window style
1047 wxPG_EX_HELP_AS_TOOLTIPS is used, then the text will appear as a
1050 void SetPropertyHelpString( wxPGPropArg id
, const wxString
& helpString
)
1052 wxPG_PROP_ARG_CALL_PROLOG()
1053 p
->SetHelpString(helpString
);
1056 /** Set wxBitmap in front of the value.
1058 - Bitmap will be scaled to a size returned by
1059 wxPropertyGrid::GetImageSize();
1061 void SetPropertyImage( wxPGPropArg id
, wxBitmap
& bmp
)
1063 wxPG_PROP_ARG_CALL_PROLOG()
1064 p
->SetValueImage(bmp
);
1068 /** Sets max length of property's text.
1070 bool SetPropertyMaxLength( wxPGPropArg id
, int maxLen
);
1072 #if wxUSE_VALIDATORS
1073 /** Sets validator of a property.
1075 void SetPropertyValidator( wxPGPropArg id
, const wxValidator
& validator
)
1077 wxPG_PROP_ARG_CALL_PROLOG()
1078 p
->SetValidator(validator
);
1083 /** Sets value (long integer) of a property.
1085 void SetPropertyValue( wxPGPropArg id
, long value
)
1088 SetPropVal( id
, v
);
1091 /** Sets value (integer) of a property.
1093 void SetPropertyValue( wxPGPropArg id
, int value
)
1095 wxVariant
v((long)value
);
1096 SetPropVal( id
, v
);
1098 /** Sets value (floating point) of a property.
1100 void SetPropertyValue( wxPGPropArg id
, double value
)
1103 SetPropVal( id
, v
);
1105 /** Sets value (bool) of a property.
1107 void SetPropertyValue( wxPGPropArg id
, bool value
)
1110 SetPropVal( id
, v
);
1113 void SetPropertyValue( wxPGPropArg id
, const wchar_t* value
)
1115 SetPropertyValueString( id
, wxString(value
) );
1118 void SetPropertyValue( wxPGPropArg id
, const char* value
)
1120 SetPropertyValueString( id
, wxString(value
) );
1122 void SetPropertyValue( wxPGPropArg id
, const wxString
& value
)
1124 SetPropertyValueString( id
, value
);
1127 /** Sets value (wxArrayString) of a property.
1129 void SetPropertyValue( wxPGPropArg id
, const wxArrayString
& value
)
1132 SetPropVal( id
, v
);
1136 void SetPropertyValue( wxPGPropArg id
, const wxDateTime
& value
)
1139 SetPropVal( id
, v
);
1143 /** Sets value (wxObject*) of a property.
1145 void SetPropertyValue( wxPGPropArg id
, wxObject
* value
)
1148 SetPropVal( id
, v
);
1151 void SetPropertyValue( wxPGPropArg id
, wxObject
& value
)
1153 wxVariant
v(&value
);
1154 SetPropVal( id
, v
);
1157 #if wxUSE_LONGLONG_NATIVE
1158 /** Sets value (wxLongLong&) of a property.
1160 void SetPropertyValue( wxPGPropArg id
, wxLongLong_t value
)
1162 wxVariant v
= WXVARIANT(wxLongLong(value
));
1163 SetPropVal( id
, v
);
1165 /** Sets value (wxULongLong&) of a property.
1167 void SetPropertyValue( wxPGPropArg id
, wxULongLong_t value
)
1169 wxVariant v
= WXVARIANT(wxULongLong(value
));
1170 SetPropVal( id
, v
);
1174 /** Sets value (wxArrayInt&) of a property.
1176 void SetPropertyValue( wxPGPropArg id
, const wxArrayInt
& value
)
1178 wxVariant v
= WXVARIANT(value
);
1179 SetPropVal( id
, v
);
1183 /** Sets value (wxString) of a property.
1186 This method uses wxPGProperty::SetValueFromString, which all properties
1187 should implement. This means that there should not be a type error,
1188 and instead the string is converted to property's actual value type.
1190 void SetPropertyValueString( wxPGPropArg id
, const wxString
& value
);
1192 /** Sets value (wxVariant&) of a property.
1195 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run
1196 through validation process and send property change event.
1198 void SetPropertyValue( wxPGPropArg id
, wxVariant value
)
1200 SetPropVal( id
, value
);
1204 /** Sets value (wxVariant&) of a property. Same as SetPropertyValue, but
1205 accepts reference. */
1206 void SetPropVal( wxPGPropArg id
, wxVariant
& value
);
1209 /** Adjusts how wxPropertyGrid behaves when invalid value is entered
1212 See @link vfbflags list of valid flags values@endlink
1214 void SetValidationFailureBehavior( int vfbFlags
);
1218 def
MapType(class_
,factory
):
1219 "Registers Python type/class to property mapping.\n\nfactory: Property builder function/class."
1220 global _type2property
1222 mappings
= _type2property
1224 raise
AssertionError("call only after a propertygrid or manager instance constructed")
1226 mappings
[class_
] = factory
1229 def
DoDefaultTypeMappings(self
):
1230 "Map built-in properties."
1231 global _type2property
1233 mappings
= _type2property
1238 _type2property
= mappings
1240 mappings
[str
] = StringProperty
1241 mappings
[unicode
] = StringProperty
1242 mappings
[int] = IntProperty
1243 mappings
[float] = FloatProperty
1244 mappings
[bool] = BoolProperty
1245 mappings
[list
] = ArrayStringProperty
1246 mappings
[tuple
] = ArrayStringProperty
1247 mappings
[wx
.Font
] = FontProperty
1248 mappings
[wx
.Colour
] = ColourProperty
1249 "mappings[wx.Size] = SizeProperty"
1250 "mappings[wx.Point] = PointProperty"
1251 "mappings[wx.FontData] = FontDataProperty"
1253 def
DoDefaultValueTypeMappings(self
):
1254 "Map pg value type ids to getter methods."
1257 vt2getter
= _vt2getter
1262 _vt2getter
= vt2getter
1264 def
GetPropertyValues(self
,dict_
=None
, as_strings
=False
, inc_attributes
=False
):
1265 "Returns values in the grid."
1267 "dict_: if not given, then a new one is created. dict_ can be"
1268 " object as well, in which case it's __dict__ is used."
1269 "as_strings: if True, then string representations of values"
1270 " are fetched instead of native types. Useful for config and such."
1271 "inc_attributes: if True, then property attributes are added"
1272 " as @<propname>@<attr>."
1274 "Return value: dictionary with values. It is always a dictionary,"
1275 "so if dict_ was object with __dict__ attribute, then that attribute"
1280 elif
hasattr(dict_
,'__dict__'):
1281 dict_
= dict_
.__dict__
1284 getter
= self
.GetPropertyValue
1286 getter
= self
.GetPropertyValueAsString
1288 it
= self
.GetVIterator(PG_ITERATE_PROPERTIES
)
1289 while not it
.AtEnd():
1290 p
= it
.GetProperty()
1293 dict_
[name
] = getter(p
)
1296 attrs
= p
.GetAttributes()
1297 if attrs
and len(attrs
):
1298 dict_
['@%s@attr'%name
] = attrs
1304 GetValues
= GetPropertyValues
1307 def
SetPropertyValues(self
,dict_
):
1308 "Sets property values from dict_, which can be either\ndictionary or an object with __dict__ attribute."
1310 "autofill: If true, keys with not relevant properties"
1311 " are auto-created. For more info, see AutoFill."
1314 " * Keys starting with underscore are ignored."
1315 " * Attributes can be set with entries named @<propname>@<attr>."
1322 elif
hasattr(dict_
,'__dict__'):
1323 dict_
= dict_
.__dict__
1327 def
set_sub_obj(k0
,dict_
):
1328 for k
,v in dict_
.iteritems():
1330 if k
.endswith('@attr'):
1331 attr_dicts
.append((k
[1:-5],v
))
1334 self
.SetPropertyValue(k
,v
)
1338 self
._AutoFillOne(k0
,k
,v
)
1341 if isinstance(v
,dict
):
1343 elif
hasattr(v
,'__dict__'):
1344 set_sub_obj(k
,v
.__dict__
)
1347 for k
,v in attr_dicts
:
1348 p
= GetPropertyByName(k
)
1350 raise
AssertionError("No such property: '%s'"%k
)
1351 for an
,av in v
.iteritems():
1352 p
.SetAttribute(an
, av
)
1356 is_manager
= isinstance(self
,PropertyGridManager
)
1359 set_sub_obj(self
.GetGrid().GetRoot(),dict_
)
1362 traceback
.print_exc()
1366 SetValues
= SetPropertyValues
1368 def
_AutoFillMany(self
,cat
,dict_
):
1369 for k
,v in dict_
.iteritems():
1370 self
._AutoFillOne(cat
,k
,v
)
1373 def
_AutoFillOne(self
,cat
,k
,v
):
1374 global _type2property
1376 factory
= _type2property
.get(v
.__class__
,None
)
1379 self
.AppendIn( cat
, factory(k
,k
,v
) )
1380 elif
hasattr(v
,'__dict__'):
1381 cat2
= self
.AppendIn( cat
, PropertyCategory(k
) )
1382 self
._AutoFillMany(cat2
,v
.__dict__
)
1383 elif
isinstance(v
,dict
):
1384 cat2
= self
.AppendIn( cat
, PropertyCategory(k
) )
1385 self
._AutoFillMany(cat2
,v
)
1386 elif
not k
.startswith('_'):
1387 raise
AssertionError("member '%s' is of unregisted type/class '%s'"%(k
,v
.__class__
))
1390 def
AutoFill(self
,obj
,parent
=None
):
1391 "Clears properties and re-fills to match members and\nvalues of given object or dictionary obj."
1393 self
.edited_objects
[parent
] = obj
1396 is_manager
= isinstance(self
,PropertyGridManager
)
1400 page
= self
.GetCurrentPage()
1402 parent
= page
.GetRoot()
1405 parent
= self
.GetGrid().GetRoot()
1407 it
= self
.GetIterator(PG_ITERATE_PROPERTIES
, parent
)
1408 it
.Next() # Skip the parent
1409 while not it
.AtEnd():
1410 p
= it
.GetProperty()
1411 if not p
.IsSomeParent(parent
):
1414 self
.DeleteProperty(p
)
1419 if not is_manager
or page
== self
.GetCurrentPage():
1424 self
._AutoFillMany(parent
,obj
.__dict__
)
1427 traceback
.print_exc()
1432 def
RegisterEditor(self
, editor
, editorName
=None
):
1433 "Transform class into instance, if necessary."
1434 if not isinstance(editor
, PGEditor
):
1437 editorName
= editor
.__class__
.__name__
1439 self
._editor_instances
.append(editor
)
1441 self
._editor_instances
= [editor
]
1442 RegisterEditor(editor
, editorName
)
1444 def
GetPropertyClientData(self
, p
):
1445 if isinstance(p
, basestring
):
1446 p
= self
.GetPropertyByName(p
)
1447 return p
.GetClientData()
1449 def
SetPropertyClientData(self
, p
, data
):
1450 if isinstance(p
, basestring
):
1451 p
= self
.GetPropertyByName(p
)
1452 return p
.SetClientData(data
)
1456 // GetPropertyByName With nice assertion error message.
1457 wxPGProperty
* GetPropertyByNameA( const wxString
& name
) const;
1459 static wxPGEditor
* GetEditorByName( const wxString
& editorName
);
1461 virtual void RefreshProperty( wxPGProperty
* p
) = 0;
1466 In derived class, implement to set editable state component with
1467 given name to given value.
1469 virtual bool SetEditableStateItem( const wxString
& name
, wxVariant value
)
1477 In derived class, implement to return editable state component with
1480 virtual wxVariant
GetEditableStateItem( const wxString
& name
) const
1483 return wxNullVariant
;
1486 // Returns page state data for given (sub) page (-1 means current page).
1487 virtual wxPropertyGridPageState
* GetPageState( int pageIndex
) const
1489 if ( pageIndex
<= 0 )
1494 virtual bool DoSelectPage( int WXUNUSED(index
) ) { return true; }
1496 // Default call's m_pState's BaseGetPropertyByName
1497 virtual wxPGProperty
* DoGetPropertyByName( const wxString
& name
) const;
1501 // Deriving classes must set this (it must be only or current page).
1502 wxPropertyGridPageState
* m_pState
;
1504 // Intermediate version needed due to wxVariant copying inefficiency
1505 void DoSetPropertyAttribute( wxPGPropArg id
,
1506 const wxString
& name
,
1507 wxVariant
& value
, long argFlags
);
1509 // Empty string object to return from member functions returning const
1511 wxString m_emptyString
;
1514 // Cannot be GetGrid() due to ambiguity issues.
1515 wxPropertyGrid
* GetPropertyGrid()
1517 return m_pState
->GetGrid();
1520 // Cannot be GetGrid() due to ambiguity issues.
1521 const wxPropertyGrid
* GetPropertyGrid() const
1523 return (const wxPropertyGrid
*) m_pState
->GetGrid();
1525 #endif // #ifndef SWIG
1527 friend class wxPropertyGrid
;
1528 friend class wxPropertyGridManager
;
1531 #endif // wxUSE_PROPGRID
1533 #endif // __WX_PROPGRID_PROPGRIDIFACE_H__