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 wxChar
* typestr
,
122 void wxPGGetFailed( const wxPGProperty
* p
, const wxChar
* 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 wxObject
* GetPropertyValueAsWxObjectPtr( wxPGPropArg id
) const;
554 void* GetPropertyValueAsVoidPtr( wxPGPropArg id
) const;
556 #define wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(TYPENAME, DEFVAL) \
557 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFVAL) \
558 if ( p->m_value.GetType() != TYPENAME ) \
560 wxPGGetFailed(p, TYPENAME); \
564 #define wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK(TYPENAME, DEFVAL) \
565 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(DEFVAL) \
566 if ( p->m_value.GetType() != TYPENAME ) \
569 wxArrayString GetPropertyValueAsArrayString( wxPGPropArg id ) const
571 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(wxT("arrstring"),
573 return p
->m_value
.GetArrayString();
576 wxPoint
GetPropertyValueAsPoint( wxPGPropArg id
) const
578 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(wxT("wxPoint"), wxPoint())
579 return WX_PG_VARIANT_GETVALUEREF(p
->GetValue(), wxPoint
);
582 wxSize
GetPropertyValueAsSize( wxPGPropArg id
) const
584 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(wxT("wxSize"), wxSize())
585 return WX_PG_VARIANT_GETVALUEREF(p
->GetValue(), wxSize
);
588 wxLongLong_t
GetPropertyValueAsLongLong( wxPGPropArg id
) const
590 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK(wxT("wxLongLong"),
591 (long) GetPropertyValueAsLong(id
))
592 return WX_PG_VARIANT_GETVALUEREF(p
->GetValue(), wxLongLong
).GetValue();
595 wxULongLong_t
GetPropertyValueAsULongLong( wxPGPropArg id
) const
597 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL_WFALLBACK(wxT("wxULongLong"),
598 (unsigned long) GetPropertyValueAsULong(id
))
599 return WX_PG_VARIANT_GETVALUEREF(p
->GetValue(), wxULongLong
).GetValue();
602 wxArrayInt
GetPropertyValueAsArrayInt( wxPGPropArg id
) const
604 wxPG_PROP_ID_GETPROPVAL_CALL_PROLOG_RETVAL(wxT("wxArrayInt"),
606 wxArrayInt arr
= WX_PG_VARIANT_GETVALUEREF(p
->GetValue(), wxArrayInt
);
611 wxDateTime
GetPropertyValueAsDateTime( wxPGPropArg id
) const
613 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(wxDateTime())
615 if ( wxStrcmp(p
->m_value
.GetType(), wxT("datetime")) != 0 )
617 wxPGGetFailed(p
, wxT("datetime"));
620 return p
->m_value
.GetDateTime();
625 /** Returns a wxVariant list containing wxVariant versions of all
626 property values. Order is not guaranteed.
628 Use wxPG_KEEP_STRUCTURE to retain category structure; each sub
629 category will be its own wxVariantList of wxVariant.
630 Use wxPG_INC_ATTRIBUTES to include property attributes as well.
631 Each attribute will be stored as list variant named
632 "@@<propname>@@attr."
635 wxVariant
GetPropertyValues( const wxString
& listname
= wxEmptyString
,
636 wxPGProperty
* baseparent
= NULL
, long flags
= 0 ) const
638 return m_pState
->DoGetPropertyValues(listname
, baseparent
, flags
);
642 wxString
GetPropertyValueType( wxPGPropArg id
)
644 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(m_emptyString
)
645 return p
->GetValueType();
648 /** Returns currently selected property. */
649 wxPGProperty
* GetSelection() const
651 return m_pState
->GetSelection();
655 wxPropertyGridPageState
* GetState() const { return m_pState
; }
658 /** Similar to GetIterator(), but instead returns wxPGVIterator instance,
659 which can be useful for forward-iterating through arbitrary property
663 See @ref propgrid_iterator_flags.
665 virtual wxPGVIterator
GetVIterator( int flags
) const;
667 /** Hides or reveals a property.
669 If true, hides property, otherwise reveals it.
671 By default changes are applied recursively. Set this paramter
672 wxPG_DONT_RECURSE to prevent this.
674 bool HideProperty( wxPGPropArg id
,
676 int flags
= wxPG_RECURSE
);
678 #if wxPG_INCLUDE_ADVPROPS
679 /** Initializes *all* property types. Causes references to most object
680 files in the library, so calling this may cause significant increase
681 in executable size when linking with static library.
683 static void InitAllTypeHandlers();
685 static void InitAllTypeHandlers() { }
689 /** Inserts property to the property container.
692 New property is inserted just prior to this. Available only
693 in the first variant. There are two versions of this function
694 to allow this parameter to be either an id or name to
698 Pointer to the inserted property. wxPropertyGrid will take
699 ownership of this object.
702 New property is inserted under this category. Available only
703 in the second variant. There are two versions of this function
704 to allow this parameter to be either an id or name to
708 Index under category. Available only in the second variant.
709 If index is < 0, property is appended in category.
712 Returns id for the property,
716 - wxPropertyGrid takes the ownership of the property pointer.
718 - While Append may be faster way to add items, make note that when
719 both types of data storage (categoric and
720 non-categoric) are active, Insert becomes even more slow. This is
721 especially true if current mode is non-categoric.
728 wxPGProperty* my_cat_id = propertygrid->Append(
729 new wxPropertyCategory("My Category") );
733 // insert into category - using second variant
734 wxPGProperty* my_item_id_1 = propertygrid->Insert(
735 my_cat_id, 0, new wxStringProperty("My String 1") );
737 // insert before to first item - using first variant
738 wxPGProperty* my_item_id_2 = propertygrid->Insert(
739 my_item_id, new wxStringProperty("My String 2") );
744 wxPGProperty
* Insert( wxPGPropArg priorThis
, wxPGProperty
* newproperty
);
745 wxPGProperty
* Insert( wxPGPropArg parent
,
747 wxPGProperty
* newproperty
);
750 /** Returns true if property is a category. */
751 bool IsPropertyCategory( wxPGPropArg id
) const
753 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
754 return p
->IsCategory();
757 /** Inserts choice to a property that can accept one.
759 See AddPropertyChoice for more details.
761 void InsertPropertyChoice( wxPGPropArg id
,
762 const wxString
& label
,
764 int value
= wxPG_INVALID_VALUE
);
766 /** Returns true if property is enabled. */
767 bool IsPropertyEnabled( wxPGPropArg id
) const
769 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
770 return (!(p
->GetFlags() & wxPG_PROP_DISABLED
))?true:false;
774 Returns true if given property is expanded.
776 Naturally, always returns false for properties that cannot be expanded.
778 bool IsPropertyExpanded( wxPGPropArg id
) const;
781 Returns true if property has been modified after value set or modify
782 flag clear by software.
784 bool IsPropertyModified( wxPGPropArg id
) const
786 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
787 return ( (p
->GetFlags() & wxPG_PROP_MODIFIED
) ? true : false );
791 Returns true if property is shown (ie hideproperty with true not
794 bool IsPropertyShown( wxPGPropArg id
) const
796 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
797 return (!(p
->GetFlags() & wxPG_PROP_HIDDEN
))?true:false;
800 /** Returns true if property value is set to unspecified.
802 bool IsPropertyValueUnspecified( wxPGPropArg id
) const
804 wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
805 return p
->IsValueUnspecified();
809 Disables (limit = true) or enables (limit = false) wxTextCtrl editor of
810 a property, if it is not the sole mean to edit the value.
812 void LimitPropertyEditing( wxPGPropArg id
, bool limit
= true );
814 /** If state is shown in it's grid, refresh it now.
816 virtual void RefreshGrid( wxPropertyGridPageState
* state
= NULL
);
818 #if wxPG_INCLUDE_ADVPROPS
820 Initializes additional property editors (SpinCtrl etc.). Causes
821 references to most object files in the library, so calling this may
822 cause significant increase in executable size when linking with static
825 static void RegisterAdditionalEditors();
827 static void RegisterAdditionalEditors() { }
830 /** Replaces property with id with newly created property. For example,
831 this code replaces existing property named "Flags" with one that
832 will have different set of items:
834 pg->ReplaceProperty("Flags",
835 wxFlagsProperty("Flags", wxPG_LABEL, newItems))
837 For more info, see wxPropertyGrid::Insert.
839 wxPGProperty
* ReplaceProperty( wxPGPropArg id
, wxPGProperty
* property
);
841 /** @anchor propgridinterface_editablestate_flags
843 Flags for wxPropertyGridInterface::SaveEditableState() and
844 wxPropertyGridInterface::RestoreEditableState().
846 enum EditableStateFlags
848 /** Include selected property. */
849 SelectionState
= 0x01,
850 /** Include expanded/collapsed property information. */
851 ExpandedState
= 0x02,
852 /** Include scrolled position. */
853 ScrollPosState
= 0x04,
854 /** Include selected page information.
855 Only applies to wxPropertyGridManager. */
857 /** Include splitter position. Stored for each page. */
858 SplitterPosState
= 0x10,
861 Include all supported user editable state information.
862 This is usually the default value. */
863 AllStates
= SelectionState
|
871 Restores user-editable state.
873 See also wxPropertyGridInterface::SaveEditableState().
876 String generated by SaveEditableState.
879 Which parts to restore from source string. See @ref
880 propgridinterface_editablestate_flags "list of editable state
884 False if there was problem reading the string.
887 If some parts of state (such as scrolled or splitter position) fail to
888 restore correctly, please make sure that you call this function after
889 wxPropertyGrid size has been set (this may sometimes be tricky when
892 bool RestoreEditableState( const wxString
& src
,
893 int restoreStates
= AllStates
);
896 Used to acquire user-editable state (selected property, expanded
897 properties, scrolled position, splitter positions).
899 @param includedStates
900 Which parts of state to include. See @ref
901 propgridinterface_editablestate_flags "list of editable state flags".
903 wxString
SaveEditableState( int includedStates
= AllStates
) const;
906 Lets user to set the strings listed in the choice dropdown of a
907 wxBoolProperty. Defaults are "True" and "False", so changing them to,
908 say, "Yes" and "No" may be useful in some less technical applications.
910 static void SetBoolChoices( const wxString
& trueChoice
,
911 const wxString
& falseChoice
);
913 /** Sets or clears flag(s) of all properties in given array.
915 Property flags to set or clear.
917 Set to true if you want to clear flag instead of setting them.
919 void SetPropertiesFlag( const wxArrayPGProperty
& srcArr
,
920 wxPGProperty::FlagType flags
,
921 bool inverse
= false );
923 /** Sets an attribute for this property.
925 Text identifier of attribute. See @ref propgrid_property_attributes.
929 Optional. Use wxPG_RECURSE to set the attribute to child properties
932 void SetPropertyAttribute( wxPGPropArg id
,
933 const wxString
& attrName
,
937 DoSetPropertyAttribute(id
,attrName
,value
,argFlags
);
940 /** Sets attributes from a wxPGAttributeStorage.
942 void SetPropertyAttributes( wxPGPropArg id
,
943 const wxPGAttributeStorage
& attributes
)
945 wxPG_PROP_ARG_CALL_PROLOG()
946 p
->SetAttributes(attributes
);
949 /** Sets text, bitmap, and colours for given column's cell.
952 - You can set label cell by setting column to 0.
953 - You can use wxPG_LABEL as text to use default text for column.
955 void SetPropertyCell( wxPGPropArg id
,
957 const wxString
& text
= wxEmptyString
,
958 const wxBitmap
& bitmap
= wxNullBitmap
,
959 const wxColour
& fgCol
= wxNullColour
,
960 const wxColour
& bgCol
= wxNullColour
)
962 wxPG_PROP_ARG_CALL_PROLOG()
963 p
->SetCell( column
, new wxPGCell(text
, bitmap
, fgCol
, bgCol
) );
966 /** Set choices of a property to specified set of labels and values.
969 This operation clears the property value.
971 void SetPropertyChoices( wxPGPropArg id
, wxPGChoices
& choices
)
973 wxPG_PROP_ARG_CALL_PROLOG()
974 p
->SetChoices(choices
);
979 If property's set of choices is shared, then calling this method
980 converts it to private.
982 void SetPropertyChoicesExclusive( wxPGPropArg id
)
984 wxPG_PROP_ARG_CALL_PROLOG()
985 p
->SetChoicesExclusive();
989 /** Sets client data (void*) of a property.
991 This untyped client data has to be deleted manually.
993 void SetPropertyClientData( wxPGPropArg id
, void* clientData
)
995 wxPG_PROP_ARG_CALL_PROLOG()
996 p
->SetClientData(clientData
);
999 /** Sets editor for a property.
1002 For builtin editors, use wxPGEditor_X, where X is builtin editor's
1003 name (TextCtrl, Choice, etc. see wxPGEditor documentation for full
1006 For custom editors, use pointer you received from
1007 wxPropertyGrid::RegisterEditorClass().
1009 void SetPropertyEditor( wxPGPropArg id
, const wxPGEditor
* editor
)
1011 wxPG_PROP_ARG_CALL_PROLOG()
1012 wxCHECK_RET( editor
, wxT("unknown/NULL editor") );
1013 p
->SetEditor(editor
);
1018 /** Sets editor control of a property. As editor argument, use
1019 editor name string, such as "TextCtrl" or "Choice".
1021 void SetPropertyEditor( wxPGPropArg id
, const wxString
& editorName
)
1023 SetPropertyEditor(id
,GetEditorByName(editorName
));
1026 /** Sets label of a property.
1028 void SetPropertyLabel( wxPGPropArg id
, const wxString
& newproplabel
);
1030 /** Set modified status of a property and all its children.
1032 void SetPropertyModifiedStatus( wxPGPropArg id
, bool modified
)
1034 wxPG_PROP_ARG_CALL_PROLOG()
1035 p
->SetModifiedStatus(modified
);
1039 Sets property (and, recursively, its children) to have read-only value.
1040 In other words, user cannot change the value in the editor, but they
1043 This is mainly for use with textctrl editor. Not all other editors fully
1046 By default changes are applied recursively. Set this paramter
1047 wxPG_DONT_RECURSE to prevent this.
1049 void SetPropertyReadOnly( wxPGPropArg id
,
1051 int flags
= wxPG_RECURSE
)
1053 wxPG_PROP_ARG_CALL_PROLOG()
1054 if ( flags
& wxPG_RECURSE
)
1055 p
->SetFlagRecursively(wxPG_PROP_READONLY
, set
);
1057 p
->SetFlag(wxPG_PROP_READONLY
);
1060 /** Sets property's value to unspecified.
1061 If it has children (it may be category), then the same thing is done to
1064 void SetPropertyValueUnspecified( wxPGPropArg id
);
1067 /** Sets various property values from a list of wxVariants. If property with
1068 name is missing from the grid, new property is created under given
1069 default category (or root if omitted).
1071 void SetPropertyValues( const wxVariantList
& list
,
1072 wxPGPropArg defaultCategory
= wxNullProperty
)
1075 if ( defaultCategory
.HasName() ) p
= defaultCategory
.GetPtr(this);
1076 else p
= defaultCategory
.GetPtr0();
1077 m_pState
->DoSetPropertyValues(list
, p
);
1080 void SetPropertyValues( const wxVariant
& list
,
1081 wxPGPropArg defaultCategory
= wxNullProperty
)
1083 SetPropertyValues(list
.GetList(),defaultCategory
);
1087 /** Associates the help string with property.
1089 By default, text is shown either in the manager's "description"
1090 text box or in the status bar. If extra window style
1091 wxPG_EX_HELP_AS_TOOLTIPS is used, then the text will appear as a
1094 void SetPropertyHelpString( wxPGPropArg id
, const wxString
& helpString
)
1096 wxPG_PROP_ARG_CALL_PROLOG()
1097 p
->SetHelpString(helpString
);
1100 /** Set wxBitmap in front of the value.
1102 - Bitmap will be scaled to a size returned by
1103 wxPropertyGrid::GetImageSize();
1105 void SetPropertyImage( wxPGPropArg id
, wxBitmap
& bmp
)
1107 wxPG_PROP_ARG_CALL_PROLOG()
1108 p
->SetValueImage(bmp
);
1112 /** Sets max length of property's text.
1114 bool SetPropertyMaxLength( wxPGPropArg id
, int maxLen
);
1116 #if wxUSE_VALIDATORS
1117 /** Sets validator of a property.
1119 void SetPropertyValidator( wxPGPropArg id
, const wxValidator
& validator
)
1121 wxPG_PROP_ARG_CALL_PROLOG()
1122 p
->SetValidator(validator
);
1127 /** Sets value (long integer) of a property.
1129 void SetPropertyValue( wxPGPropArg id
, long value
)
1132 SetPropVal( id
, v
);
1135 /** Sets value (integer) of a property.
1137 void SetPropertyValue( wxPGPropArg id
, int value
)
1139 wxVariant
v((long)value
);
1140 SetPropVal( id
, v
);
1142 /** Sets value (floating point) of a property.
1144 void SetPropertyValue( wxPGPropArg id
, double value
)
1147 SetPropVal( id
, v
);
1149 /** Sets value (bool) of a property.
1151 void SetPropertyValue( wxPGPropArg id
, bool value
)
1154 SetPropVal( id
, v
);
1156 void SetPropertyValue( wxPGPropArg id
, const wxChar
* value
)
1158 SetPropertyValueString( id
, wxString(value
) );
1160 void SetPropertyValue( wxPGPropArg id
, const wxString
& value
)
1162 SetPropertyValueString( id
, value
);
1165 /** Sets value (wxArrayString) of a property.
1167 void SetPropertyValue( wxPGPropArg id
, const wxArrayString
& value
)
1170 SetPropVal( id
, v
);
1174 void SetPropertyValue( wxPGPropArg id
, const wxDateTime
& value
)
1177 SetPropVal( id
, v
);
1181 /** Sets value (wxObject*) of a property.
1183 void SetPropertyValue( wxPGPropArg id
, wxObject
* value
)
1186 SetPropVal( id
, v
);
1189 void SetPropertyValue( wxPGPropArg id
, wxObject
& value
)
1191 wxVariant
v(&value
);
1192 SetPropVal( id
, v
);
1195 /** Sets value (wxPoint&) of a property.
1197 void SetPropertyValue( wxPGPropArg id
, const wxPoint
& value
)
1199 wxVariant v
= WXVARIANT(value
);
1200 SetPropVal( id
, v
);
1202 /** Sets value (wxSize&) of a property.
1204 void SetPropertyValue( wxPGPropArg id
, const wxSize
& value
)
1206 wxVariant v
= WXVARIANT(value
);
1207 SetPropVal( id
, v
);
1209 /** Sets value (wxLongLong&) of a property.
1211 void SetPropertyValue( wxPGPropArg id
, wxLongLong_t value
)
1213 wxVariant v
= WXVARIANT(wxLongLong(value
));
1214 SetPropVal( id
, v
);
1216 /** Sets value (wxULongLong&) of a property.
1218 void SetPropertyValue( wxPGPropArg id
, wxULongLong_t value
)
1220 wxVariant v
= WXVARIANT(wxULongLong(value
));
1221 SetPropVal( id
, v
);
1223 /** Sets value (wxArrayInt&) of a property.
1225 void SetPropertyValue( wxPGPropArg id
, const wxArrayInt
& value
)
1227 wxVariant v
= WXVARIANT(value
);
1228 SetPropVal( id
, v
);
1232 /** Sets value (wxString) of a property.
1235 This method uses wxPGProperty::SetValueFromString, which all properties
1236 should implement. This means that there should not be a type error,
1237 and instead the string is converted to property's actual value type.
1239 void SetPropertyValueString( wxPGPropArg id
, const wxString
& value
);
1241 /** Sets value (wxVariant&) of a property.
1244 Use wxPropertyGrid::ChangePropertyValue() instead if you need to run
1245 through validation process and send property change event.
1247 void SetPropertyValue( wxPGPropArg id
, wxVariant value
)
1249 SetPropVal( id
, value
);
1253 /** Sets value (wxVariant&) of a property. Same as SetPropertyValue, but
1254 accepts reference. */
1255 void SetPropVal( wxPGPropArg id
, wxVariant
& value
);
1258 /** Adjusts how wxPropertyGrid behaves when invalid value is entered
1261 See @link vfbflags list of valid flags values@endlink
1263 void SetValidationFailureBehavior( int vfbFlags
);
1267 def
MapType(class_
,factory
):
1268 "Registers Python type/class to property mapping.\n\nfactory: Property builder function/class."
1269 global _type2property
1271 mappings
= _type2property
1273 raise
AssertionError("call only after a propertygrid or manager instance constructed")
1275 mappings
[class_
] = factory
1278 def
DoDefaultTypeMappings(self
):
1279 "Map built-in properties."
1280 global _type2property
1282 mappings
= _type2property
1287 _type2property
= mappings
1289 mappings
[str
] = StringProperty
1290 mappings
[unicode
] = StringProperty
1291 mappings
[int] = IntProperty
1292 mappings
[float] = FloatProperty
1293 mappings
[bool] = BoolProperty
1294 mappings
[list
] = ArrayStringProperty
1295 mappings
[tuple
] = ArrayStringProperty
1296 mappings
[wx
.Font
] = FontProperty
1297 mappings
[wx
.Colour
] = ColourProperty
1298 "mappings[wx.Size] = SizeProperty"
1299 "mappings[wx.Point] = PointProperty"
1300 "mappings[wx.FontData] = FontDataProperty"
1302 def
DoDefaultValueTypeMappings(self
):
1303 "Map pg value type ids to getter methods."
1306 vt2getter
= _vt2getter
1311 _vt2getter
= vt2getter
1313 def
GetPropertyValues(self
,dict_
=None
, as_strings
=False
, inc_attributes
=False
):
1314 "Returns values in the grid."
1316 "dict_: if not given, then a new one is created. dict_ can be"
1317 " object as well, in which case it's __dict__ is used."
1318 "as_strings: if True, then string representations of values"
1319 " are fetched instead of native types. Useful for config and such."
1320 "inc_attributes: if True, then property attributes are added"
1321 " as @<propname>@<attr>."
1323 "Return value: dictionary with values. It is always a dictionary,"
1324 "so if dict_ was object with __dict__ attribute, then that attribute"
1329 elif
hasattr(dict_
,'__dict__'):
1330 dict_
= dict_
.__dict__
1333 getter
= self
.GetPropertyValue
1335 getter
= self
.GetPropertyValueAsString
1337 it
= self
.GetVIterator(PG_ITERATE_PROPERTIES
)
1338 while not it
.AtEnd():
1339 p
= it
.GetProperty()
1342 dict_
[name
] = getter(p
)
1345 attrs
= p
.GetAttributes()
1346 if attrs
and len(attrs
):
1347 dict_
['@%s@attr'%name
] = attrs
1353 GetValues
= GetPropertyValues
1356 def
SetPropertyValues(self
,dict_
):
1357 "Sets property values from dict_, which can be either\ndictionary or an object with __dict__ attribute."
1359 "autofill: If true, keys with not relevant properties"
1360 " are auto-created. For more info, see AutoFill."
1363 " * Keys starting with underscore are ignored."
1364 " * Attributes can be set with entries named @<propname>@<attr>."
1371 elif
hasattr(dict_
,'__dict__'):
1372 dict_
= dict_
.__dict__
1376 def
set_sub_obj(k0
,dict_
):
1377 for k
,v in dict_
.iteritems():
1379 if k
.endswith('@attr'):
1380 attr_dicts
.append((k
[1:-5],v
))
1383 self
.SetPropertyValue(k
,v
)
1387 self
._AutoFillOne(k0
,k
,v
)
1390 if isinstance(v
,dict
):
1392 elif
hasattr(v
,'__dict__'):
1393 set_sub_obj(k
,v
.__dict__
)
1396 for k
,v in attr_dicts
:
1397 p
= GetPropertyByName(k
)
1399 raise
AssertionError("No such property: '%s'"%k
)
1400 for an
,av in v
.iteritems():
1401 p
.SetAttribute(an
, av
)
1405 is_manager
= isinstance(self
,PropertyGridManager
)
1408 set_sub_obj(self
.GetGrid().GetRoot(),dict_
)
1411 traceback
.print_exc()
1415 SetValues
= SetPropertyValues
1417 def
_AutoFillMany(self
,cat
,dict_
):
1418 for k
,v in dict_
.iteritems():
1419 self
._AutoFillOne(cat
,k
,v
)
1422 def
_AutoFillOne(self
,cat
,k
,v
):
1423 global _type2property
1425 factory
= _type2property
.get(v
.__class__
,None
)
1428 self
.AppendIn( cat
, factory(k
,k
,v
) )
1429 elif
hasattr(v
,'__dict__'):
1430 cat2
= self
.AppendIn( cat
, PropertyCategory(k
) )
1431 self
._AutoFillMany(cat2
,v
.__dict__
)
1432 elif
isinstance(v
,dict
):
1433 cat2
= self
.AppendIn( cat
, PropertyCategory(k
) )
1434 self
._AutoFillMany(cat2
,v
)
1435 elif
not k
.startswith('_'):
1436 raise
AssertionError("member '%s' is of unregisted type/class '%s'"%(k
,v
.__class__
))
1439 def
AutoFill(self
,obj
,parent
=None
):
1440 "Clears properties and re-fills to match members and\nvalues of given object or dictionary obj."
1442 self
.edited_objects
[parent
] = obj
1445 is_manager
= isinstance(self
,PropertyGridManager
)
1449 page
= self
.GetCurrentPage()
1451 parent
= page
.GetRoot()
1454 parent
= self
.GetGrid().GetRoot()
1456 it
= self
.GetIterator(PG_ITERATE_PROPERTIES
, parent
)
1457 it
.Next() # Skip the parent
1458 while not it
.AtEnd():
1459 p
= it
.GetProperty()
1460 if not p
.IsSomeParent(parent
):
1463 self
.DeleteProperty(p
)
1468 if not is_manager
or page
== self
.GetCurrentPage():
1473 self
._AutoFillMany(parent
,obj
.__dict__
)
1476 traceback
.print_exc()
1481 def
RegisterEditor(self
, editor
, editorName
=None
):
1482 "Transform class into instance, if necessary."
1483 if not isinstance(editor
, PGEditor
):
1486 editorName
= editor
.__class__
.__name__
1488 self
._editor_instances
.append(editor
)
1490 self
._editor_instances
= [editor
]
1491 RegisterEditor(editor
, editorName
)
1493 def
GetPropertyClientData(self
, p
):
1494 if isinstance(p
, basestring
):
1495 p
= self
.GetPropertyByName(p
)
1496 return p
.GetClientData()
1498 def
SetPropertyClientData(self
, p
, data
):
1499 if isinstance(p
, basestring
):
1500 p
= self
.GetPropertyByName(p
)
1501 return p
.SetClientData(data
)
1505 // GetPropertyByName With nice assertion error message.
1506 wxPGProperty
* GetPropertyByNameA( const wxString
& name
) const;
1508 static wxPGEditor
* GetEditorByName( const wxString
& editorName
);
1510 virtual void RefreshProperty( wxPGProperty
* p
) = 0;
1514 // Returns page state data for given (sub) page (-1 means current page).
1515 virtual wxPropertyGridPageState
* GetPageState( int pageIndex
) const
1517 if ( pageIndex
<= 0 )
1522 virtual bool DoSelectPage( int WXUNUSED(index
) ) { return true; }
1524 // Default call's m_pState's BaseGetPropertyByName
1525 virtual wxPGProperty
* DoGetPropertyByName( const wxString
& name
) const;
1529 // Deriving classes must set this (it must be only or current page).
1530 wxPropertyGridPageState
* m_pState
;
1532 // Intermediate version needed due to wxVariant copying inefficiency
1533 void DoSetPropertyAttribute( wxPGPropArg id
,
1534 const wxString
& name
,
1535 wxVariant
& value
, long argFlags
);
1537 // Empty string object to return from member functions returning const
1539 wxString m_emptyString
;
1542 // Cannot be GetGrid() due to ambiguity issues.
1543 wxPropertyGrid
* GetPropertyGrid()
1545 return m_pState
->GetGrid();
1548 // Cannot be GetGrid() due to ambiguity issues.
1549 const wxPropertyGrid
* GetPropertyGrid() const
1551 return (const wxPropertyGrid
*) m_pState
->GetGrid();
1553 #endif // #ifndef SWIG
1555 friend class wxPropertyGrid
;
1556 friend class wxPropertyGridManager
;
1559 #endif // __WX_PROPGRID_PROPGRIDIFACE_H__