-/////////////////////////////////////////////////////////////////////////////\r
-// Name: wx/xtiprop.h\r
-// Purpose: XTI properties\r
-// Author: Stefan Csomor\r
-// Modified by: Francesco Montorsi\r
-// Created: 27/07/03\r
-// RCS-ID: $Id: xti.h 47299 2007-07-10 15:58:27Z FM $\r
-// Copyright: (c) 1997 Julian Smart\r
-// (c) 2003 Stefan Csomor\r
-// Licence: wxWindows licence\r
-/////////////////////////////////////////////////////////////////////////////\r
-\r
-#ifndef _XTIPROP_H_\r
-#define _XTIPROP_H_\r
-\r
-#include "wx/defs.h"\r
-\r
-#if wxUSE_EXTENDED_RTTI\r
-\r
-#include "wx/string.h"\r
-#include "wx/variant.h"\r
-#include "wx/intl.h"\r
-#include "wx/log.h"\r
-#include "wx/xtitypes.h"\r
-\r
-class WXDLLIMPEXP_BASE wxObject;\r
-class WXDLLIMPEXP_BASE wxClassInfo;\r
-class WXDLLIMPEXP_BASE wxDynamicClassInfo;\r
-class WXDLLIMPEXP_BASE wxHashTable;\r
-class WXDLLIMPEXP_BASE wxHashTable_Node;\r
-class WXDLLIMPEXP_BASE wxObjectRefData;\r
-class WXDLLIMPEXP_BASE wxEvent;\r
-class WXDLLIMPEXP_BASE wxEvtHandler;\r
-\r
-// ----------------------------------------------------------------------------\r
-// Property Accessors\r
-//\r
-// wxPropertySetter/Getter/CollectionGetter/CollectionAdder are all property\r
-// accessors which are managed by wxPropertyAccessor class which in turn is\r
-// handled by wxPropertyInfo.\r
-// ----------------------------------------------------------------------------\r
-\r
-class WXDLLIMPEXP_BASE wxPropertySetter\r
-{\r
-public:\r
- wxPropertySetter( const wxString name ) { m_name = name; }\r
- virtual ~wxPropertySetter() {}\r
-\r
- virtual void Set( wxObject *object, const wxVariantBase &variantValue ) const = 0;\r
- const wxString& GetName() const { return m_name; }\r
-\r
-private:\r
- wxString m_name;\r
-};\r
-\r
-class WXDLLIMPEXP_BASE wxPropertyGetter\r
-{\r
-public:\r
- wxPropertyGetter( const wxString name ) { m_name = name; }\r
- virtual ~wxPropertyGetter() {}\r
-\r
- virtual void Get( const wxObject *object, wxVariantBase& result) const = 0;\r
- const wxString& GetName() const { return m_name; }\r
-\r
-private:\r
- wxString m_name;\r
-};\r
-\r
-class WXDLLIMPEXP_BASE wxPropertyCollectionGetter\r
-{\r
-public:\r
- wxPropertyCollectionGetter( const wxString name ) { m_name = name; }\r
- virtual ~wxPropertyCollectionGetter() {}\r
-\r
- virtual void Get( const wxObject *object, wxVariantBaseArray& result) const = 0;\r
- const wxString& GetName() const { return m_name; }\r
-\r
-private:\r
- wxString m_name;\r
-};\r
-\r
-template<typename coll_t> void WXDLLIMPEXP_BASE \\r
- wxCollectionToVariantArray( const coll_t& coll, wxVariantBaseArray& result );\r
-\r
-class WXDLLIMPEXP_BASE wxPropertyCollectionAdder\r
-{\r
-public:\r
- wxPropertyCollectionAdder( const wxString name ) { m_name = name; }\r
- virtual ~wxPropertyCollectionAdder() {}\r
-\r
- virtual void Add( wxObject *object, const wxVariantBase &variantValue ) const= 0;\r
- const wxString& GetName() const { return m_name; }\r
-\r
-private:\r
- wxString m_name;\r
-};\r
-\r
-#define wxPROPERTY_SETTER( property, Klass, valueType, setterMethod ) \\r
-class wxPropertySetter##property : public wxPropertySetter \\r
-{ \\r
-public: \\r
- wxINFUNC_CLASS_TYPE_FIX(Klass) \\r
- wxPropertySetter##property() : wxPropertySetter( wxT(#setterMethod) ) {} \\r
- virtual ~wxPropertySetter##property() {} \\r
- \\r
- void Set( wxObject *object, const wxVariantBase &variantValue ) const \\r
- { \\r
- Klass *obj = dynamic_cast<Klass*>(object); \\r
- if ( variantValue.wxTEMPLATED_MEMBER_CALL(HasData, valueType) ) \\r
- obj->setterMethod(variantValue.wxTEMPLATED_MEMBER_CALL(Get, valueType)); \\r
- else \\r
- obj->setterMethod(*variantValue.wxTEMPLATED_MEMBER_CALL(Get, valueType*)); \\r
- } \\r
-};\r
-\r
-#define wxPROPERTY_GETTER( property, Klass, valueType, gettermethod ) \\r
-class wxPropertyGetter##property : public wxPropertyGetter \\r
-{ \\r
-public: \\r
- wxINFUNC_CLASS_TYPE_FIX(Klass) \\r
- wxPropertyGetter##property() : wxPropertyGetter( wxT(#gettermethod) ) {} \\r
- virtual ~wxPropertyGetter##property() {} \\r
- \\r
- void Get( const wxObject *object, wxVariantBase &result) const \\r
- { \\r
- const Klass *obj = dynamic_cast<const Klass*>(object); \\r
- result = wxVariantBase( obj->gettermethod() ); \\r
- } \\r
-};\r
-\r
-#define wxPROPERTY_COLLECTION_ADDER( property, Klass, valueType, addermethod ) \\r
-class wxPropertyCollectionAdder##property : public wxPropertyCollectionAdder \\r
-{ \\r
-public: \\r
- wxINFUNC_CLASS_TYPE_FIX(Klass) \\r
- wxPropertyCollectionAdder##property() : wxPropertyCollectionAdder( wxT(#addermethod) ) {} \\r
- virtual ~wxPropertyCollectionAdder##property() {} \\r
- \\r
- void Add( wxObject *object, const wxVariantBase &variantValue ) const \\r
- { \\r
- Klass *obj = dynamic_cast<Klass*>(object); \\r
- if ( variantValue.wxTEMPLATED_MEMBER_CALL(HasData, valueType) ) \\r
- obj->addermethod(variantValue.wxTEMPLATED_MEMBER_CALL(Get, valueType)); \\r
- else \\r
- obj->addermethod(*variantValue.wxTEMPLATED_MEMBER_CALL(Get, valueType*)); \\r
- } \\r
-};\r
-\r
-#define wxPROPERTY_COLLECTION_GETTER( property, Klass, valueType, gettermethod ) \\r
-class wxPropertyCollectionGetter##property : public wxPropertyCollectionGetter \\r
-{ \\r
-public: \\r
- wxINFUNC_CLASS_TYPE_FIX(Klass) \\r
- wxPropertyCollectionGetter##property() : wxPropertyCollectionGetter( wxT(#gettermethod) ) {} \\r
- virtual ~wxPropertyCollectionGetter##property() {} \\r
- \\r
- void Get( const wxObject *object, wxVariantBaseArray &result) const \\r
- { \\r
- const Klass *obj = dynamic_cast<const Klass*>(object); \\r
- wxCollectionToVariantArray( obj->gettermethod(), result ); \\r
- } \\r
-};\r
-\r
-class WXDLLIMPEXP_BASE wxPropertyAccessor\r
-{\r
-public:\r
- wxPropertyAccessor( wxPropertySetter *setter, wxPropertyGetter *getter, \r
- wxPropertyCollectionAdder *adder, wxPropertyCollectionGetter *collectionGetter )\r
- { m_setter = setter; m_getter = getter; m_adder = adder; \r
- m_collectionGetter = collectionGetter; }\r
-\r
- virtual ~wxPropertyAccessor() {}\r
-\r
- // Setting a simple property (non-collection)\r
- virtual void SetProperty(wxObject *object, const wxVariantBase &value) const\r
- { \r
- if ( m_setter ) \r
- m_setter->Set( object, value ); \r
- else \r
- wxLogError( _("SetProperty called w/o valid setter") ); \r
- }\r
-\r
- // Getting a simple property (non-collection)\r
- virtual void GetProperty(const wxObject *object, wxVariantBase &result) const\r
- { \r
- if ( m_getter ) \r
- m_getter->Get( object, result ); \r
- else \r
- wxLogError( _("GetProperty called w/o valid getter") ); \r
- }\r
-\r
- // Adding an element to a collection property\r
- virtual void AddToPropertyCollection(wxObject *object, const wxVariantBase &value) const\r
- { \r
- if ( m_adder ) \r
- m_adder->Add( object, value ); \r
- else \r
- wxLogError( _("AddToPropertyCollection called w/o valid adder") ); \r
- }\r
-\r
- // Getting a collection property\r
- virtual void GetPropertyCollection( const wxObject *obj, wxVariantBaseArray &result) const\r
- { \r
- if ( m_collectionGetter ) \r
- m_collectionGetter->Get( obj, result); \r
- else \r
- wxLogError( _("GetPropertyCollection called w/o valid collection getter") ); \r
- }\r
-\r
- virtual bool HasSetter() const { return m_setter != NULL; }\r
- virtual bool HasCollectionGetter() const { return m_collectionGetter != NULL; }\r
- virtual bool HasGetter() const { return m_getter != NULL; }\r
- virtual bool HasAdder() const { return m_adder != NULL; }\r
-\r
- virtual const wxString& GetCollectionGetterName() const\r
- { return m_collectionGetter->GetName(); }\r
- virtual const wxString& GetGetterName() const\r
- { return m_getter->GetName(); }\r
- virtual const wxString& GetSetterName() const\r
- { return m_setter->GetName(); }\r
- virtual const wxString& GetAdderName() const\r
- { return m_adder->GetName(); }\r
-\r
-protected:\r
- wxPropertySetter *m_setter;\r
- wxPropertyCollectionAdder *m_adder;\r
- wxPropertyGetter *m_getter;\r
- wxPropertyCollectionGetter* m_collectionGetter;\r
-};\r
-\r
-class WXDLLIMPEXP_BASE wxGenericPropertyAccessor : public wxPropertyAccessor\r
-{\r
-public:\r
- wxGenericPropertyAccessor( const wxString &propName );\r
- virtual ~wxGenericPropertyAccessor();\r
-\r
- void RenameProperty( const wxString& WXUNUSED_UNLESS_DEBUG(oldName),\r
- const wxString& newName )\r
- {\r
- wxASSERT( oldName == m_propertyName ); m_propertyName = newName;\r
- }\r
-\r
- virtual bool HasSetter() const { return true; }\r
- virtual bool HasGetter() const { return true; }\r
- virtual bool HasAdder() const { return false; }\r
- virtual bool HasCollectionGetter() const { return false; }\r
-\r
- virtual const wxString& GetGetterName() const\r
- { return m_getterName; }\r
- virtual const wxString& GetSetterName() const\r
- { return m_setterName; }\r
-\r
- virtual void SetProperty(wxObject *object, const wxVariantBase &value) const;\r
- virtual void GetProperty(const wxObject *object, wxVariantBase &value) const;\r
-\r
- // Adding an element to a collection property\r
- virtual void AddToPropertyCollection(wxObject *WXUNUSED(object), \r
- const wxVariantBase &WXUNUSED(value)) const\r
- { \r
- wxLogError( _("AddToPropertyCollection called on a generic accessor") ); \r
- }\r
-\r
- // Getting a collection property\r
- virtual void GetPropertyCollection( const wxObject *WXUNUSED(obj), \r
- wxVariantBaseArray &WXUNUSED(result)) const\r
- { \r
- wxLogError ( _("GetPropertyCollection called on a generic accessor") ); \r
- }\r
-\r
-private:\r
- struct wxGenericPropertyAccessorInternal;\r
- wxGenericPropertyAccessorInternal* m_data;\r
- wxString m_propertyName;\r
- wxString m_setterName;\r
- wxString m_getterName;\r
-};\r
-\r
-typedef long wxPropertyInfoFlags;\r
-enum \r
-{\r
- // will be removed in future releases\r
- wxPROP_DEPRECATED = 0x00000001,\r
-\r
- // object graph property, will be streamed with priority (after constructor properties)\r
- wxPROP_OBJECT_GRAPH = 0x00000002,\r
-\r
- // this will only be streamed out and in as enum/set, the internal representation \r
- // is still a long\r
- wxPROP_ENUM_STORE_LONG = 0x00000004,\r
-\r
- // don't stream out this property, needed eg to avoid streaming out children \r
- // that are always created by their parents\r
- wxPROP_DONT_STREAM = 0x00000008\r
-};\r
-\r
-\r
-// ----------------------------------------------------------------------------\r
-// Property Support\r
-//\r
-// wxPropertyInfo is used to inquire of the property by name. It doesn't\r
-// provide access to the property, only information about it. If you\r
-// want access, look at wxPropertyAccessor.\r
-// ----------------------------------------------------------------------------\r
-\r
-class WXDLLIMPEXP_BASE wxPropertyInfo\r
-{\r
- friend class WXDLLIMPEXP_BASE wxDynamicClassInfo;\r
-\r
-public:\r
- wxPropertyInfo(wxPropertyInfo* &iter,\r
- wxClassInfo* itsClass,\r
- const wxString& name,\r
- const wxString& typeName,\r
- wxPropertyAccessor *accessor,\r
- wxVariantBase dv,\r
- wxPropertyInfoFlags flags = 0,\r
- const wxString& helpString = wxEmptyString,\r
- const wxString& groupString = wxEmptyString) :\r
- m_itsClass(itsClass),\r
- m_name(name),\r
- m_typeInfo(NULL),\r
- m_typeName(typeName),\r
- m_collectionElementTypeInfo(NULL),\r
- m_accessor(accessor),\r
- m_defaultValue(dv),\r
- m_flags(flags),\r
- m_helpString(helpString),\r
- m_groupString(groupString)\r
- {\r
- Insert(iter);\r
- }\r
-\r
-#if wxUSE_UNICODE\r
- wxPropertyInfo(wxPropertyInfo* &iter,\r
- wxClassInfo* itsClass,\r
- const wxString& name,\r
- const char* typeName,\r
- wxPropertyAccessor *accessor,\r
- wxVariantBase dv,\r
- wxPropertyInfoFlags flags = 0,\r
- const wxString& helpString = wxEmptyString,\r
- const wxString& groupString = wxEmptyString) :\r
- m_itsClass(itsClass),\r
- m_name(name),\r
- m_typeInfo(NULL),\r
- m_typeName(wxString::FromAscii(typeName)),\r
- m_collectionElementTypeInfo(NULL),\r
- m_accessor(accessor),\r
- m_defaultValue(dv),\r
- m_flags(flags),\r
- m_helpString(helpString),\r
- m_groupString(groupString)\r
- {\r
- Insert(iter);\r
- }\r
-#endif\r
- wxPropertyInfo(wxPropertyInfo* &iter,\r
- wxClassInfo* itsClass,\r
- const wxString& name,\r
- wxEventSourceTypeInfo* type,\r
- wxPropertyAccessor *accessor,\r
- wxVariantBase dv,\r
- wxPropertyInfoFlags flags = 0,\r
- const wxString& helpString = wxEmptyString,\r
- const wxString& groupString = wxEmptyString) :\r
- m_itsClass(itsClass),\r
- m_name(name),\r
- m_typeInfo(type),\r
- m_collectionElementTypeInfo(NULL),\r
- m_accessor(accessor),\r
- m_defaultValue(dv),\r
- m_flags(flags),\r
- m_helpString(helpString),\r
- m_groupString(groupString)\r
- {\r
- Insert(iter);\r
- }\r
-\r
- wxPropertyInfo(wxPropertyInfo* &iter,\r
- wxClassInfo* itsClass, const wxString& name,\r
- const wxString& collectionTypeName,\r
- const wxString& elementTypeName,\r
- wxPropertyAccessor *accessor,\r
- wxPropertyInfoFlags flags = 0,\r
- const wxString& helpString = wxEmptyString,\r
- const wxString& groupString = wxEmptyString) :\r
- m_itsClass(itsClass),\r
- m_name(name),\r
- m_typeInfo(NULL),\r
- m_typeName(collectionTypeName),\r
- m_collectionElementTypeInfo(NULL),\r
- m_collectionElementTypeName(elementTypeName),\r
- m_accessor(accessor),\r
- m_flags(flags),\r
- m_helpString(helpString),\r
- m_groupString(groupString)\r
- {\r
- Insert(iter);\r
- }\r
-\r
-#if wxUSE_UNICODE\r
- wxPropertyInfo(wxPropertyInfo* &iter,\r
- wxClassInfo* itsClass, const wxString& name,\r
- const char* collectionTypeName,\r
- const char* elementTypeName,\r
- wxPropertyAccessor *accessor,\r
- wxPropertyInfoFlags flags = 0,\r
- const wxString& helpString = wxEmptyString,\r
- const wxString& groupString = wxEmptyString) :\r
- m_itsClass(itsClass),\r
- m_name(name),\r
- m_typeInfo(NULL),\r
- m_typeName(wxString::FromAscii(collectionTypeName)),\r
- m_collectionElementTypeInfo(NULL),\r
- m_collectionElementTypeName(wxString::FromAscii(elementTypeName)),\r
- m_accessor(accessor),\r
- m_flags(flags),\r
- m_helpString(helpString),\r
- m_groupString(groupString)\r
- {\r
- Insert(iter);\r
- }\r
-#endif\r
- ~wxPropertyInfo()\r
- { Remove(); }\r
-\r
- // return the class this property is declared in\r
- const wxClassInfo* GetDeclaringClass() const { return m_itsClass; }\r
-\r
- // return the name of this property\r
- const wxString& GetName() const { return m_name; }\r
-\r
- // returns the flags of this property\r
- wxPropertyInfoFlags GetFlags() const { return m_flags; }\r
-\r
- // returns the short help string of this property\r
- const wxString& GetHelpString() const { return m_helpString; }\r
-\r
- // returns the group string of this property\r
- const wxString& GetGroupString() const { return m_groupString; }\r
-\r
- // return the element type info of this property (for collections, otherwise NULL)\r
- const wxTypeInfo * GetCollectionElementTypeInfo() const\r
- {\r
- if ( m_collectionElementTypeInfo == NULL )\r
- m_collectionElementTypeInfo = wxTypeInfo::FindType(m_collectionElementTypeName);\r
- return m_collectionElementTypeInfo;\r
- }\r
-\r
- // return the type info of this property\r
- const wxTypeInfo * GetTypeInfo() const\r
- {\r
- if ( m_typeInfo == NULL )\r
- m_typeInfo = wxTypeInfo::FindType(m_typeName);\r
- return m_typeInfo;\r
- }\r
-\r
- // return the accessor for this property\r
- wxPropertyAccessor* GetAccessor() const { return m_accessor; }\r
-\r
- // returns NULL if this is the last property of this class\r
- wxPropertyInfo* GetNext() const { return m_next; }\r
-\r
- // returns the default value of this property, its kind may be wxT_VOID if it is not valid\r
- wxVariantBase GetDefaultValue() const { return m_defaultValue; }\r
-\r
-private:\r
-\r
- // inserts this property at the end of the linked chain which begins\r
- // with "iter" property.\r
- void Insert(wxPropertyInfo* &iter);\r
-\r
- // removes this property from the linked chain of the m_itsClass properties.\r
- void Remove();\r
-\r
- wxClassInfo* m_itsClass;\r
- wxString m_name;\r
- mutable wxTypeInfo* m_typeInfo;\r
- wxString m_typeName;\r
- mutable wxTypeInfo* m_collectionElementTypeInfo;\r
- wxString m_collectionElementTypeName;\r
- wxPropertyAccessor* m_accessor;\r
- wxVariantBase m_defaultValue;\r
- wxPropertyInfoFlags m_flags;\r
- wxString m_helpString;\r
- wxString m_groupString;\r
- wxPropertyInfo* m_next;\r
-\r
- // FIXME: what's this comment about??\r
- // string representation of the default value\r
- // to be assigned by the designer to the property\r
- // when the component is dropped on the container.\r
-};\r
-\r
-WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxPropertyInfo*, wxPropertyInfoMap, \r
- class WXDLLIMPEXP_BASE );\r
-\r
-#define wxBEGIN_PROPERTIES_TABLE(theClass) \\r
- wxPropertyInfo *theClass::GetPropertiesStatic() \\r
- { \\r
- typedef theClass class_t; \\r
- static wxPropertyInfo* first = NULL;\r
-\r
-#define wxEND_PROPERTIES_TABLE() \\r
- return first; }\r
-\r
-#define wxHIDE_PROPERTY( pname ) \\r
- static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \\r
- wxT(#pname), typeid(void).name(), NULL, wxVariantBase(), wxPROP_DONT_STREAM, \\r
- wxEmptyString, wxEmptyString );\r
-\r
-#define wxPROPERTY( pname, type, setter, getter, defaultValue, flags, help, group) \\r
- wxPROPERTY_SETTER( pname, class_t, type, setter ) \\r
- static wxPropertySetter##pname _setter##pname; \\r
- wxPROPERTY_GETTER( pname, class_t, type, getter ) \\r
- static wxPropertyGetter##pname _getter##pname; \\r
- static wxPropertyAccessor _accessor##pname( &_setter##pname, \\r
- &_getter##pname, NULL, NULL ); \\r
- static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \\r
- wxT(#pname), typeid(type).name(), &_accessor##pname, \\r
- wxVariantBase(defaultValue), flags, group, help );\r
-\r
-#define wxPROPERTY_FLAGS( pname, flags, type, setter, getter,defaultValue, \\r
- pflags, help, group) \\r
- wxPROPERTY_SETTER( pname, class_t, type, setter ) \\r
- static wxPropertySetter##pname _setter##pname; \\r
- wxPROPERTY_GETTER( pname, class_t, type, getter ) \\r
- static wxPropertyGetter##pname _getter##pname; \\r
- static wxPropertyAccessor _accessor##pname( &_setter##pname, \\r
- &_getter##pname, NULL, NULL ); \\r
- static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \\r
- wxT(#pname), typeid(flags).name(), &_accessor##pname, \\r
- wxVariantBase(defaultValue), wxPROP_ENUM_STORE_LONG | pflags, help, group );\r
-\r
-#define wxREADONLY_PROPERTY( pname, type, getter,defaultValue, flags, help, group) \\r
- wxPROPERTY_GETTER( pname, class_t, type, getter ) \\r
- static wxPropertyGetter##pname _getter##pname; \\r
- static wxPropertyAccessor _accessor##pname( NULL, &_getter##pname, NULL, NULL ); \\r
- static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \\r
- wxT(#pname), typeid(type).name(),&_accessor##pname, \\r
- wxVariantBase(defaultValue), flags, help, group );\r
-\r
-#define wxREADONLY_PROPERTY_FLAGS( pname, flags, type, getter,defaultValue, \\r
- pflags, help, group) \\r
- wxPROPERTY_GETTER( pname, class_t, type, getter ) \\r
- static wxPropertyGetter##pname _getter##pname; \\r
- static wxPropertyAccessor _accessor##pname( NULL, &_getter##pname, NULL, NULL ); \\r
- static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \\r
- wxT(#pname), typeid(flags).name(),&_accessor##pname, \\r
- wxVariantBase(defaultValue), wxPROP_ENUM_STORE_LONG | pflags, help, group );\r
-\r
-#define wxPROPERTY_COLLECTION( pname, colltype, addelemtype, adder, getter, \\r
- flags, help, group ) \\r
- wxPROPERTY_COLLECTION_ADDER( pname, class_t, addelemtype, adder ) \\r
- static wxPropertyCollectionAdder##pname _adder##pname; \\r
- wxPROPERTY_COLLECTION_GETTER( pname, class_t, colltype, getter ) \\r
- static wxPropertyCollectionGetter##pname _collectionGetter##pname; \\r
- static wxPropertyAccessor _accessor##pname( NULL, NULL,&_adder##pname, \\r
- &_collectionGetter##pname ); \\r
- static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \\r
- wxT(#pname), typeid(colltype).name(),typeid(addelemtype).name(), \\r
- &_accessor##pname, flags, help, group );\r
-\r
-#define wxREADONLY_PROPERTY_COLLECTION( pname, colltype, addelemtype, getter, \\r
- flags, help, group) \\r
- wxPROPERTY_COLLECTION_GETTER( pname, class_t, colltype, getter ) \\r
- static wxPropertyCollectionGetter##pname _collectionGetter##pname; \\r
- static wxPropertyAccessor _accessor##pname( NULL, NULL, NULL, \\r
- &_collectionGetter##pname ); \\r
- static wxPropertyInfo _propertyInfo##pname( first,class_t::GetClassInfoStatic(), \\r
- wxT(#pname), typeid(colltype).name(),typeid(addelemtype).name(), \\r
- &_accessor##pname, flags, help, group );\r
-\r
-#define wxEVENT_PROPERTY( name, eventType, eventClass ) \\r
- static wxEventSourceTypeInfo _typeInfo##name( eventType, CLASSINFO( eventClass ) ); \\r
- static wxPropertyInfo _propertyInfo##name( first,class_t::GetClassInfoStatic(), \\r
- wxT(#name), &_typeInfo##name, NULL, wxVariantBase() );\r
-\r
-#define wxEVENT_RANGE_PROPERTY( name, eventType, lastEventType, eventClass ) \\r
- static wxEventSourceTypeInfo _typeInfo##name( eventType, lastEventType, \\r
- CLASSINFO( eventClass ) ); \\r
- static wxPropertyInfo _propertyInfo##name( first, class_t::GetClassInfoStatic(), \\r
- wxT(#name), &_typeInfo##name, NULL, wxVariantBase() );\r
-\r
-// ----------------------------------------------------------------------------\r
-// Implementation Helper for Simple Properties\r
-// ----------------------------------------------------------------------------\r
-\r
-#define wxIMPLEMENT_PROPERTY(name, type) \\r
-private: \\r
- type m_##name; \\r
-public: \\r
- void Set##name( type const & p) { m_##name = p; } \\r
- type const & Get##name() const { return m_##name; }\r
-\r
-#endif // wxUSE_EXTENDED_RTTI\r
-#endif // _XTIPROP_H_\r
+/////////////////////////////////////////////////////////////////////////////
+// Name: wx/xtiprop.h
+// Purpose: XTI properties
+// Author: Stefan Csomor
+// Modified by: Francesco Montorsi
+// Created: 27/07/03
+// RCS-ID: $Id$
+// Copyright: (c) 1997 Julian Smart
+// (c) 2003 Stefan Csomor
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _XTIPROP_H_
+#define _XTIPROP_H_
+
+#include "wx/defs.h"
+
+#if wxUSE_EXTENDED_RTTI
+
+#include "wx/xti.h"
+#include "wx/any.h"
+
+class WXDLLIMPEXP_BASE wxObject;
+class WXDLLIMPEXP_BASE wxClassInfo;
+class WXDLLIMPEXP_BASE wxDynamicClassInfo;
+class WXDLLIMPEXP_BASE wxHashTable;
+class WXDLLIMPEXP_BASE wxHashTable_Node;
+class WXDLLIMPEXP_BASE wxEvent;
+class WXDLLIMPEXP_BASE wxEvtHandler;
+
+// ----------------------------------------------------------------------------
+// Property Accessors
+//
+// wxPropertySetter/Getter/CollectionGetter/CollectionAdder are all property
+// accessors which are managed by wxPropertyAccessor class which in turn is
+// handled by wxPropertyInfo.
+// ----------------------------------------------------------------------------
+
+class WXDLLIMPEXP_BASE wxPropertySetter
+{
+public:
+ wxPropertySetter( const wxString name ) { m_name = name; }
+ virtual ~wxPropertySetter() {}
+
+ virtual void Set( wxObject *object, const wxAny &variantValue ) const = 0;
+ const wxString& GetName() const { return m_name; }
+
+private:
+ wxString m_name;
+};
+
+class WXDLLIMPEXP_BASE wxPropertyGetter
+{
+public:
+ wxPropertyGetter( const wxString name ) { m_name = name; }
+ virtual ~wxPropertyGetter() {}
+
+ virtual void Get( const wxObject *object, wxAny& result) const = 0;
+ const wxString& GetName() const { return m_name; }
+
+private:
+ wxString m_name;
+};
+
+class WXDLLIMPEXP_BASE wxPropertyCollectionGetter
+{
+public:
+ wxPropertyCollectionGetter( const wxString name ) { m_name = name; }
+ virtual ~wxPropertyCollectionGetter() {}
+
+ virtual void Get( const wxObject *object, wxAnyList& result) const = 0;
+ const wxString& GetName() const { return m_name; }
+
+private:
+ wxString m_name;
+};
+
+template<typename coll_t> void WXDLLIMPEXP_BASE \
+ wxCollectionToVariantArray( const coll_t& coll, wxAnyList& result );
+
+class WXDLLIMPEXP_BASE wxPropertyCollectionAdder
+{
+public:
+ wxPropertyCollectionAdder( const wxString name ) { m_name = name; }
+ virtual ~wxPropertyCollectionAdder() {}
+
+ virtual void Add( wxObject *object, const wxAny &variantValue ) const= 0;
+ const wxString& GetName() const { return m_name; }
+
+private:
+ wxString m_name;
+};
+
+#define wxPROPERTY_SETTER( property, Klass, valueType, setterMethod ) \
+class wxPropertySetter##property : public wxPropertySetter \
+{ \
+public: \
+ wxINFUNC_CLASS_TYPE_FIX(Klass) \
+ wxPropertySetter##property() : wxPropertySetter( wxT(#setterMethod) ) {} \
+ virtual ~wxPropertySetter##property() {} \
+ \
+ void Set( wxObject *object, const wxAny &variantValue ) const \
+ { \
+ Klass *obj = dynamic_cast<Klass*>(object); \
+ valueType tempobj; \
+ if ( variantValue.GetAs(&tempobj) ) \
+ obj->setterMethod(tempobj); \
+ else \
+ obj->setterMethod(*wxANY_AS(variantValue, valueType*)); \
+ } \
+};
+
+#define wxPROPERTY_GETTER( property, Klass, valueType, gettermethod ) \
+class wxPropertyGetter##property : public wxPropertyGetter \
+{ \
+public: \
+ wxINFUNC_CLASS_TYPE_FIX(Klass) \
+ wxPropertyGetter##property() : wxPropertyGetter( wxT(#gettermethod) ) {} \
+ virtual ~wxPropertyGetter##property() {} \
+ \
+ void Get( const wxObject *object, wxAny &result) const \
+ { \
+ const Klass *obj = dynamic_cast<const Klass*>(object); \
+ result = wxAny( obj->gettermethod() ); \
+ } \
+};
+
+#define wxPROPERTY_COLLECTION_ADDER( property, Klass, valueType, addermethod ) \
+class wxPropertyCollectionAdder##property : public wxPropertyCollectionAdder \
+{ \
+public: \
+ wxINFUNC_CLASS_TYPE_FIX(Klass) \
+ wxPropertyCollectionAdder##property() : wxPropertyCollectionAdder( wxT(#addermethod) ) {} \
+ virtual ~wxPropertyCollectionAdder##property() {} \
+ \
+ void Add( wxObject *object, const wxAny &variantValue ) const \
+ { \
+ Klass *obj = dynamic_cast<Klass*>(object); \
+ valueType tempobj; \
+ if ( variantValue.GetAs(&tempobj) ) \
+ obj->addermethod(tempobj); \
+ else \
+ obj->addermethod(*wxANY_AS(variantValue, valueType*)); \
+ } \
+};
+
+#define wxPROPERTY_COLLECTION_GETTER( property, Klass, valueType, gettermethod ) \
+class wxPropertyCollectionGetter##property : public wxPropertyCollectionGetter \
+{ \
+public: \
+ wxINFUNC_CLASS_TYPE_FIX(Klass) \
+ wxPropertyCollectionGetter##property() : wxPropertyCollectionGetter( wxT(#gettermethod) ) {} \
+ virtual ~wxPropertyCollectionGetter##property() {} \
+ \
+ void Get( const wxObject *object, wxAnyList &result) const \
+ { \
+ const Klass *obj = dynamic_cast<const Klass*>(object); \
+ wxCollectionToVariantArray( obj->gettermethod(), result ); \
+ } \
+};
+
+class WXDLLIMPEXP_BASE wxPropertyAccessor
+{
+public:
+ wxPropertyAccessor( wxPropertySetter *setter, wxPropertyGetter *getter,
+ wxPropertyCollectionAdder *adder, wxPropertyCollectionGetter *collectionGetter )
+ { m_setter = setter; m_getter = getter; m_adder = adder;
+ m_collectionGetter = collectionGetter; }
+
+ virtual ~wxPropertyAccessor() {}
+
+ // Setting a simple property (non-collection)
+ virtual void SetProperty(wxObject *object, const wxAny &value) const
+ {
+ if ( m_setter )
+ m_setter->Set( object, value );
+ else
+ wxLogError( _("SetProperty called w/o valid setter") );
+ }
+
+ // Getting a simple property (non-collection)
+ virtual void GetProperty(const wxObject *object, wxAny &result) const
+ {
+ if ( m_getter )
+ m_getter->Get( object, result );
+ else
+ wxLogError( _("GetProperty called w/o valid getter") );
+ }
+
+ // Adding an element to a collection property
+ virtual void AddToPropertyCollection(wxObject *object, const wxAny &value) const
+ {
+ if ( m_adder )
+ m_adder->Add( object, value );
+ else
+ wxLogError( _("AddToPropertyCollection called w/o valid adder") );
+ }
+
+ // Getting a collection property
+ virtual void GetPropertyCollection( const wxObject *obj, wxAnyList &result) const
+ {
+ if ( m_collectionGetter )
+ m_collectionGetter->Get( obj, result);
+ else
+ wxLogError( _("GetPropertyCollection called w/o valid collection getter") );
+ }
+
+ virtual bool HasSetter() const { return m_setter != NULL; }
+ virtual bool HasCollectionGetter() const { return m_collectionGetter != NULL; }
+ virtual bool HasGetter() const { return m_getter != NULL; }
+ virtual bool HasAdder() const { return m_adder != NULL; }
+
+ virtual const wxString& GetCollectionGetterName() const
+ { return m_collectionGetter->GetName(); }
+ virtual const wxString& GetGetterName() const
+ { return m_getter->GetName(); }
+ virtual const wxString& GetSetterName() const
+ { return m_setter->GetName(); }
+ virtual const wxString& GetAdderName() const
+ { return m_adder->GetName(); }
+
+protected:
+ wxPropertySetter *m_setter;
+ wxPropertyCollectionAdder *m_adder;
+ wxPropertyGetter *m_getter;
+ wxPropertyCollectionGetter* m_collectionGetter;
+};
+
+class WXDLLIMPEXP_BASE wxGenericPropertyAccessor : public wxPropertyAccessor
+{
+public:
+ wxGenericPropertyAccessor( const wxString &propName );
+ virtual ~wxGenericPropertyAccessor();
+
+ void RenameProperty( const wxString& WXUNUSED_UNLESS_DEBUG(oldName),
+ const wxString& newName )
+ {
+ wxASSERT( oldName == m_propertyName ); m_propertyName = newName;
+ }
+
+ virtual bool HasSetter() const { return true; }
+ virtual bool HasGetter() const { return true; }
+ virtual bool HasAdder() const { return false; }
+ virtual bool HasCollectionGetter() const { return false; }
+
+ virtual const wxString& GetGetterName() const
+ { return m_getterName; }
+ virtual const wxString& GetSetterName() const
+ { return m_setterName; }
+
+ virtual void SetProperty(wxObject *object, const wxAny &value) const;
+ virtual void GetProperty(const wxObject *object, wxAny &value) const;
+
+ // Adding an element to a collection property
+ virtual void AddToPropertyCollection(wxObject *WXUNUSED(object),
+ const wxAny &WXUNUSED(value)) const
+ {
+ wxLogError( _("AddToPropertyCollection called on a generic accessor") );
+ }
+
+ // Getting a collection property
+ virtual void GetPropertyCollection( const wxObject *WXUNUSED(obj),
+ wxAnyList &WXUNUSED(result)) const
+ {
+ wxLogError ( _("GetPropertyCollection called on a generic accessor") );
+ }
+
+private:
+ struct wxGenericPropertyAccessorInternal;
+ wxGenericPropertyAccessorInternal* m_data;
+ wxString m_propertyName;
+ wxString m_setterName;
+ wxString m_getterName;
+};
+
+typedef long wxPropertyInfoFlags;
+enum
+{
+ // will be removed in future releases
+ wxPROP_DEPRECATED = 0x00000001,
+
+ // object graph property, will be streamed with priority (after constructor properties)
+ wxPROP_OBJECT_GRAPH = 0x00000002,
+
+ // this will only be streamed out and in as enum/set, the internal representation
+ // is still a long
+ wxPROP_ENUM_STORE_LONG = 0x00000004,
+
+ // don't stream out this property, needed eg to avoid streaming out children
+ // that are always created by their parents
+ wxPROP_DONT_STREAM = 0x00000008
+};
+
+
+// ----------------------------------------------------------------------------
+// Property Support
+//
+// wxPropertyInfo is used to inquire of the property by name. It doesn't
+// provide access to the property, only information about it. If you
+// want access, look at wxPropertyAccessor.
+// ----------------------------------------------------------------------------
+
+class WXDLLIMPEXP_BASE wxPropertyInfo
+{
+ friend class WXDLLIMPEXP_BASE wxDynamicClassInfo;
+
+public:
+ wxPropertyInfo(wxPropertyInfo* &iter,
+ wxClassInfo* itsClass,
+ const wxString& name,
+ const wxString& typeName,
+ wxPropertyAccessor *accessor,
+ wxAny dv,
+ wxPropertyInfoFlags flags = 0,
+ const wxString& helpString = wxEmptyString,
+ const wxString& groupString = wxEmptyString) :
+ m_itsClass(itsClass),
+ m_name(name),
+ m_typeInfo(NULL),
+ m_typeName(typeName),
+ m_collectionElementTypeInfo(NULL),
+ m_accessor(accessor),
+ m_defaultValue(dv),
+ m_flags(flags),
+ m_helpString(helpString),
+ m_groupString(groupString)
+ {
+ Insert(iter);
+ }
+
+ wxPropertyInfo(wxPropertyInfo* &iter,
+ wxClassInfo* itsClass,
+ const wxString& name,
+ wxEventSourceTypeInfo* type,
+ wxPropertyAccessor *accessor,
+ wxAny dv,
+ wxPropertyInfoFlags flags = 0,
+ const wxString& helpString = wxEmptyString,
+ const wxString& groupString = wxEmptyString) :
+ m_itsClass(itsClass),
+ m_name(name),
+ m_typeInfo(type),
+ m_collectionElementTypeInfo(NULL),
+ m_accessor(accessor),
+ m_defaultValue(dv),
+ m_flags(flags),
+ m_helpString(helpString),
+ m_groupString(groupString)
+ {
+ Insert(iter);
+ }
+
+ wxPropertyInfo(wxPropertyInfo* &iter,
+ wxClassInfo* itsClass, const wxString& name,
+ const wxString& collectionTypeName,
+ const wxString& elementTypeName,
+ wxPropertyAccessor *accessor,
+ wxPropertyInfoFlags flags = 0,
+ const wxString& helpString = wxEmptyString,
+ const wxString& groupString = wxEmptyString) :
+ m_itsClass(itsClass),
+ m_name(name),
+ m_typeInfo(NULL),
+ m_typeName(collectionTypeName),
+ m_collectionElementTypeInfo(NULL),
+ m_collectionElementTypeName(elementTypeName),
+ m_accessor(accessor),
+ m_flags(flags),
+ m_helpString(helpString),
+ m_groupString(groupString)
+ {
+ Insert(iter);
+ }
+
+ ~wxPropertyInfo()
+ { Remove(); }
+
+ // return the class this property is declared in
+ const wxClassInfo* GetDeclaringClass() const { return m_itsClass; }
+
+ // return the name of this property
+ const wxString& GetName() const { return m_name; }
+
+ // returns the flags of this property
+ wxPropertyInfoFlags GetFlags() const { return m_flags; }
+
+ // returns the short help string of this property
+ const wxString& GetHelpString() const { return m_helpString; }
+
+ // returns the group string of this property
+ const wxString& GetGroupString() const { return m_groupString; }
+
+ // return the element type info of this property (for collections, otherwise NULL)
+ const wxTypeInfo * GetCollectionElementTypeInfo() const
+ {
+ if ( m_collectionElementTypeInfo == NULL )
+ m_collectionElementTypeInfo = wxTypeInfo::FindType(m_collectionElementTypeName);
+ return m_collectionElementTypeInfo;
+ }
+
+ // return the type info of this property
+ const wxTypeInfo * GetTypeInfo() const
+ {
+ if ( m_typeInfo == NULL )
+ m_typeInfo = wxTypeInfo::FindType(m_typeName);
+ return m_typeInfo;
+ }
+
+ // return the accessor for this property
+ wxPropertyAccessor* GetAccessor() const { return m_accessor; }
+
+ // returns NULL if this is the last property of this class
+ wxPropertyInfo* GetNext() const { return m_next; }
+
+ // returns the default value of this property, its kind may be wxT_VOID if it is not valid
+ wxAny GetDefaultValue() const { return m_defaultValue; }
+
+private:
+
+ // inserts this property at the end of the linked chain which begins
+ // with "iter" property.
+ void Insert(wxPropertyInfo* &iter);
+
+ // removes this property from the linked chain of the m_itsClass properties.
+ void Remove();
+
+ wxClassInfo* m_itsClass;
+ wxString m_name;
+ mutable wxTypeInfo* m_typeInfo;
+ wxString m_typeName;
+ mutable wxTypeInfo* m_collectionElementTypeInfo;
+ wxString m_collectionElementTypeName;
+ wxPropertyAccessor* m_accessor;
+ wxAny m_defaultValue;
+ wxPropertyInfoFlags m_flags;
+ wxString m_helpString;
+ wxString m_groupString;
+ wxPropertyInfo* m_next;
+
+ // FIXME: what's this comment about??
+ // string representation of the default value
+ // to be assigned by the designer to the property
+ // when the component is dropped on the container.
+};
+
+WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxPropertyInfo*, wxPropertyInfoMap,
+ class WXDLLIMPEXP_BASE );
+
+#define wxBEGIN_PROPERTIES_TABLE(theClass) \
+ wxPropertyInfo *theClass::GetPropertiesStatic() \
+ { \
+ typedef theClass class_t; \
+ static wxPropertyInfo* first = NULL;
+
+#define wxEND_PROPERTIES_TABLE() \
+ return first; }
+
+#define wxHIDE_PROPERTY( pname ) \
+ static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
+ wxT(#pname), typeid(void).name(), NULL, wxAny(), wxPROP_DONT_STREAM, \
+ wxEmptyString, wxEmptyString );
+
+#define wxPROPERTY( pname, type, setter, getter, defaultValue, flags, help, group) \
+ wxPROPERTY_SETTER( pname, class_t, type, setter ) \
+ static wxPropertySetter##pname _setter##pname; \
+ wxPROPERTY_GETTER( pname, class_t, type, getter ) \
+ static wxPropertyGetter##pname _getter##pname; \
+ static wxPropertyAccessor _accessor##pname( &_setter##pname, \
+ &_getter##pname, NULL, NULL ); \
+ static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
+ wxT(#pname), typeid(type).name(), &_accessor##pname, \
+ wxAny(defaultValue), flags, group, help );
+
+#define wxPROPERTY_FLAGS( pname, flags, type, setter, getter,defaultValue, \
+ pflags, help, group) \
+ wxPROPERTY_SETTER( pname, class_t, type, setter ) \
+ static wxPropertySetter##pname _setter##pname; \
+ wxPROPERTY_GETTER( pname, class_t, type, getter ) \
+ static wxPropertyGetter##pname _getter##pname; \
+ static wxPropertyAccessor _accessor##pname( &_setter##pname, \
+ &_getter##pname, NULL, NULL ); \
+ static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
+ wxT(#pname), typeid(flags).name(), &_accessor##pname, \
+ wxAny(defaultValue), wxPROP_ENUM_STORE_LONG | pflags, help, group );
+
+#define wxREADONLY_PROPERTY( pname, type, getter,defaultValue, flags, help, group) \
+ wxPROPERTY_GETTER( pname, class_t, type, getter ) \
+ static wxPropertyGetter##pname _getter##pname; \
+ static wxPropertyAccessor _accessor##pname( NULL, &_getter##pname, NULL, NULL ); \
+ static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
+ wxT(#pname), typeid(type).name(),&_accessor##pname, \
+ wxAny(defaultValue), flags, help, group );
+
+#define wxREADONLY_PROPERTY_FLAGS( pname, flags, type, getter,defaultValue, \
+ pflags, help, group) \
+ wxPROPERTY_GETTER( pname, class_t, type, getter ) \
+ static wxPropertyGetter##pname _getter##pname; \
+ static wxPropertyAccessor _accessor##pname( NULL, &_getter##pname, NULL, NULL ); \
+ static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
+ wxT(#pname), typeid(flags).name(),&_accessor##pname, \
+ wxAny(defaultValue), wxPROP_ENUM_STORE_LONG | pflags, help, group );
+
+#define wxPROPERTY_COLLECTION( pname, colltype, addelemtype, adder, getter, \
+ flags, help, group ) \
+ wxPROPERTY_COLLECTION_ADDER( pname, class_t, addelemtype, adder ) \
+ static wxPropertyCollectionAdder##pname _adder##pname; \
+ wxPROPERTY_COLLECTION_GETTER( pname, class_t, colltype, getter ) \
+ static wxPropertyCollectionGetter##pname _collectionGetter##pname; \
+ static wxPropertyAccessor _accessor##pname( NULL, NULL,&_adder##pname, \
+ &_collectionGetter##pname ); \
+ static wxPropertyInfo _propertyInfo##pname( first, class_t::GetClassInfoStatic(), \
+ wxT(#pname), typeid(colltype).name(),typeid(addelemtype).name(), \
+ &_accessor##pname, flags, help, group );
+
+#define wxREADONLY_PROPERTY_COLLECTION( pname, colltype, addelemtype, getter, \
+ flags, help, group) \
+ wxPROPERTY_COLLECTION_GETTER( pname, class_t, colltype, getter ) \
+ static wxPropertyCollectionGetter##pname _collectionGetter##pname; \
+ static wxPropertyAccessor _accessor##pname( NULL, NULL, NULL, \
+ &_collectionGetter##pname ); \
+ static wxPropertyInfo _propertyInfo##pname( first,class_t::GetClassInfoStatic(), \
+ wxT(#pname), typeid(colltype).name(),typeid(addelemtype).name(), \
+ &_accessor##pname, flags, help, group );
+
+#define wxEVENT_PROPERTY( name, eventType, eventClass ) \
+ static wxEventSourceTypeInfo _typeInfo##name( eventType, CLASSINFO( eventClass ) ); \
+ static wxPropertyInfo _propertyInfo##name( first,class_t::GetClassInfoStatic(), \
+ wxT(#name), &_typeInfo##name, NULL, wxAny() );
+
+#define wxEVENT_RANGE_PROPERTY( name, eventType, lastEventType, eventClass ) \
+ static wxEventSourceTypeInfo _typeInfo##name( eventType, lastEventType, \
+ CLASSINFO( eventClass ) ); \
+ static wxPropertyInfo _propertyInfo##name( first, class_t::GetClassInfoStatic(), \
+ wxT(#name), &_typeInfo##name, NULL, wxAny() );
+
+// ----------------------------------------------------------------------------
+// Implementation Helper for Simple Properties
+// ----------------------------------------------------------------------------
+
+#define wxIMPLEMENT_PROPERTY(name, type) \
+private: \
+ type m_##name; \
+public: \
+ void Set##name( type const & p) { m_##name = p; } \
+ type const & Get##name() const { return m_##name; }
+
+WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxAny, wxStringToAnyHashMap,
+ class WXDLLIMPEXP_BASE );
+
+#endif // wxUSE_EXTENDED_RTTI
+#endif // _XTIPROP_H_