wxPropertyAccessorT( getter_t getter, const wxChar *g)
: m_setter_bool( NULL ) , m_setter_ref_bool( NULL ) , m_setter(NULL), m_setter_ref(NULL), m_getter(getter) ,m_getter_ref(NULL) {m_setterName = "";m_getterName=g ;}
+ wxPropertyAccessorT(WX_XTI_PARAM_FIX(GetByRef*,) getter_ref_t getter, const wxChar *g)
+ : m_setter_bool( NULL ) , m_setter_ref_bool( NULL ) , m_setter(NULL), m_setter_ref(NULL), m_getter(NULL) ,m_getter_ref(getter) {m_setterName = "";m_getterName=g ;}
+
wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetRetBool*,) setter_bool_t setter, getter_t getter, const wxChar *s, const wxChar *g)
: m_setter_bool( setter ) , m_setter_ref_bool( NULL ) , m_setter(NULL), m_setter_ref(NULL), m_getter(getter) , m_getter_ref(NULL){m_setterName = s;m_getterName=g ;}
public:
typedef void (Klass::*adder_t)(AddedElementType value);
- typedef const CollectionType& (Klass::*getter_t)() const ;
+ typedef CollectionType (Klass::*getter_t)() const;
+ typedef const CollectionType& (Klass::*getter_ref_t)() const;
wxPropertyCollectionAccessorT(adder_t adder, getter_t getter, const wxChar *a, const wxChar *g)
- : m_getter(getter), m_adder(adder) { m_adderName = a;m_getterName=g ;}
+ : m_getter(getter), m_adder(adder) , m_getter_ref( NULL ) { m_adderName = a;m_getterName=g ;}
+
+ wxPropertyCollectionAccessorT(adder_t adder, getter_ref_t getter, const wxChar *a, const wxChar *g)
+ : m_getter(NULL), m_adder(adder) , m_getter_ref( getter ) { m_adderName = a;m_getterName=g ;}
~wxPropertyCollectionAccessorT() {}
const Klass *obj = dynamic_cast<const Klass*>(o);
wxxVariantArray result ;
- CollectionType::compatibility_iterator current = (obj->*(m_getter))().GetFirst();
+ CollectionType::compatibility_iterator current = (obj->*(m_getter_ref))().GetFirst() ;
+
while (current)
{
result.Add( new wxxVariant(current->GetData()) ) ;
private :
getter_t m_getter;
+ getter_ref_t m_getter_ref ;
adder_t m_adder;
};
static wxPropertyCollectionAccessorT<class_t , colltype , addelemtype > _accessor##name( &adder , &getter , #adder , #getter ) ; \
static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name ) ;
+#define WX_READONLY_PROPERTY_COLLECTION( name , colltype , addelemtype , getter ) \
+ static wxPropertyCollectionAccessorT<class_t , colltype , addelemtype > _accessor##name( NULL , &getter , #adder , #getter ) ; \
+ static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name ) ;
+
#define WX_PROPERTY_SET_RET_BOOL( name , type , setter , getter ,defaultValue ) \
static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetRetBool*)NULL , &setter , &getter , #setter , #getter ) ; \
static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::SetAndGetByRefRetBool*)NULL, &setter , &getter , #setter , #getter ) ; \
static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
+#define WX_READONLY_PROPERTY( name , type , getter ,defaultValue ) \
+ static wxPropertyAccessorT<class_t , type> _accessor##name( &getter , #getter ) ; \
+ static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
+
+#define WX_READONLY_PROPERTY_GET_BY_REF( name , type , getter ,defaultValue ) \
+ static wxPropertyAccessorT<class_t , type> _accessor##name( (wxPropertyAccessor::GetByRef*)NULL , &getter , #getter ) ; \
+ static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
+
#else
#define WX_PROPERTY( name , type , setter , getter ,defaultValue ) \
static wxPropertyCollectionAccessorT<class_t , colltype , addelemtype > _accessor##name( &adder , &getter , #adder , #getter ) ; \
static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name ) ;
+#define WX_READONLY_PROPERTY_COLLECTION( name , colltype , addelemtype , getter ) \
+ static wxPropertyCollectionAccessorT<class_t , colltype , addelemtype > _accessor##name( NULL , &getter , "" , #getter ) ; \
+ static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (colltype*) NULL ) ,wxGetTypeInfo( (addelemtype*) NULL ) ,&_accessor##name ) ;
+
#define WX_PROPERTY_SET_RET_BOOL( name , type , setter , getter ,defaultValue ) \
WX_PROPERTY( name , type , setter , getter , defaultValue )
#define WX_PROPERTY_SET_AND_GET_BY_REF_RET_BOOL( name , type , setter , getter ,defaultValue ) \
WX_PROPERTY( name , type , setter , getter , defaultValue )
-#endif
-
#define WX_READONLY_PROPERTY( name , type , getter ,defaultValue ) \
static wxPropertyAccessorT<class_t , type> _accessor##name( &getter , #getter ) ; \
static wxPropertyInfo _propertyInfo##name( first , #name , wxGetTypeInfo( (type*) NULL ) ,&_accessor##name , wxxVariant(defaultValue) ) ;
+#define WX_READONLY_PROPERTY_GET_BY_REF( name , type , getter ,defaultValue ) \
+ WX_READONLY_PROPERTY( name , type , getter , defaultValue )
+
+#endif
+
+
#define WX_DELEGATE( name , eventType , eventClass ) \
static wxDelegateTypeInfo _typeInfo##name( eventType , CLASSINFO( eventClass ) ) ; \
static wxPropertyInfo _propertyInfo##name( first , #name , &_typeInfo##name , NULL , wxxVariant() ) ; \
// Runtime access to objects for collection properties by property name
virtual wxxVariantArray GetPropertyCollection(wxObject *object, const wxChar *propertyName) const ;
- virtual void AddPropertyCollection(wxObject *object, const wxChar *propertyName , const wxxVariant& value) const ;
+ virtual void AddToPropertyCollection(wxObject *object, const wxChar *propertyName , const wxxVariant& value) const ;
// we must be able to cast variants to wxObject pointers, templates seem not to be suitable
wxObject* VariantToInstance( wxxVariant &data ) const
{
public :
// allocate the new object on the heap, that object will have the passed in ID
- virtual void AllocateObject(int ObjectID, wxClassInfo *ClassInfo) = 0;
+ virtual void AllocateObject(int objectID, wxClassInfo *classInfo) = 0;
- // initialize the already allocated object having the ID ObjectID with the Create method
+ // initialize the already allocated object having the ID objectID with the Create method
// creation parameters which are objects are having their Ids passed in objectIDValues
// having objectId <> wxInvalidObjectID
- virtual void CreateObject(int ObjectID,
- const wxClassInfo *ClassInfo,
- int ParamCount,
+ virtual void CreateObject(int objectID,
+ const wxClassInfo *classInfo,
+ int paramCount,
wxxVariant *VariantValues ,
int *objectIDValues ,
const wxClassInfo **objectClassInfos
) = 0;
- // destroy the heap-allocated object having the ID ObjectID, this may be used if an object
+ // destroy the heap-allocated object having the ID objectID, this may be used if an object
// is embedded in another object and set via value semantics, so the intermediate
// object can be destroyed after safely
- virtual void DestroyObject(int ObjectID, wxClassInfo *ClassInfo) = 0;
+ virtual void DestroyObject(int objectID, wxClassInfo *classInfo) = 0;
// set the corresponding property
- virtual void SetProperty(int ObjectID,
- const wxClassInfo *ClassInfo,
- const wxPropertyInfo* PropertyInfo ,
+ virtual void SetProperty(int objectID,
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo ,
const wxxVariant &VariantValue) = 0;
// sets the corresponding property (value is an object)
- virtual void SetPropertyAsObject(int ObjectId,
- const wxClassInfo *ClassInfo,
- const wxPropertyInfo* PropertyInfo ,
+ virtual void SetPropertyAsObject(int objectID,
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo ,
int valueObjectId) = 0;
+ // adds an element to a property collection
+ virtual void AddToPropertyCollection( int objectID ,
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo ,
+ const wxxVariant &VariantValue) = 0;
+
+ // sets the corresponding property (value is an object)
+ virtual void AddToPropertyCollectionAsObject(int objectID,
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo ,
+ int valueObjectId) = 0;
// sets the corresponding event handler
virtual void SetConnect(int EventSourceObjectID,
// allocate the new object on the heap, that object will have the passed in ID
virtual void AllocateObject(int objectID, wxClassInfo *classInfo) ;
- // initialize the already allocated object having the ID ObjectID with the Create method
+ // initialize the already allocated object having the ID objectID with the Create method
// creation parameters which are objects are having their Ids passed in objectIDValues
// having objectId <> wxInvalidObjectID
- virtual void CreateObject(int ObjectID,
- const wxClassInfo *ClassInfo,
- int ParamCount,
+ virtual void CreateObject(int objectID,
+ const wxClassInfo *classInfo,
+ int paramCount,
wxxVariant *VariantValues ,
int *objectIDValues,
const wxClassInfo **objectClassInfos
) ;
- // destroy the heap-allocated object having the ID ObjectID, this may be used if an object
+ // destroy the heap-allocated object having the ID objectID, this may be used if an object
// is embedded in another object and set via value semantics, so the intermediate
// object can be destroyed after safely
virtual void DestroyObject(int objectID, wxClassInfo *classInfo) ;
const wxPropertyInfo* propertyInfo ,
int valueObjectId) ;
+ // adds an element to a property collection
+ virtual void AddToPropertyCollection( int objectID ,
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo ,
+ const wxxVariant &VariantValue) ;
+
+ // sets the corresponding property (value is an object)
+ virtual void AddToPropertyCollectionAsObject(int objectID,
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo ,
+ int valueObjectId) ;
// sets the corresponding event handler
virtual void SetConnect(int eventSourceObjectID,
// allocate the new object on the heap, that object will have the passed in ID
virtual void AllocateObject(int objectID, wxClassInfo *classInfo) ;
- // initialize the already allocated object having the ID ObjectID with the Create method
+ // initialize the already allocated object having the ID objectID with the Create method
// creation parameters which are objects are having their Ids passed in objectIDValues
// having objectId <> wxInvalidObjectID
const wxClassInfo **objectClassInfos
) ;
- // destroy the heap-allocated object having the ID ObjectID, this may be used if an object
+ // destroy the heap-allocated object having the ID objectID, this may be used if an object
// is embedded in another object and set via value semantics, so the intermediate
// object can be destroyed after safely
virtual void DestroyObject(int objectID, wxClassInfo *classInfo) ;
const wxPropertyInfo* propertyInfo ,
int valueObjectId) ;
+ // adds an element to a property collection
+ virtual void AddToPropertyCollection( int objectID ,
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo ,
+ const wxxVariant &VariantValue) ;
+
+ // sets the corresponding property (value is an object)
+ virtual void AddToPropertyCollectionAsObject(int objectID,
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo ,
+ int valueObjectId) ;
// sets the corresponding event handler
virtual void SetConnect(int eventSourceObjectID,
return accessor->GetPropertyCollection(object);
}
-void wxClassInfo::AddPropertyCollection(wxObject *object, const wxChar *propertyName , const wxxVariant& value) const
+void wxClassInfo::AddToPropertyCollection(wxObject *object, const wxChar *propertyName , const wxxVariant& value) const
{
const wxPropertyAccessor *accessor;
}
void wxWriter::WriteAllProperties( const wxObject * obj , const wxClassInfo* ci , wxPersister *persister, wxWriterInternalPropertiesData * data )
{
+ // in case this object is wxDynamic object we have to hand over the streaming
+ // of the properties of the superclasses to the real super class instance
+ {
+ const wxObject *iterobj = obj ;
+ const wxDynamicObject* dynobj = dynamic_cast< const wxDynamicObject* > (iterobj ) ;
+ if ( dynobj )
+ iterobj = dynobj->GetSuperClassInstance() ;
+ const wxClassInfo** parents = ci->GetParents() ;
+ for ( int i = 0 ; parents[i] ; ++ i )
+ {
+ WriteAllProperties( iterobj , parents[i] , persister , data ) ;
+ }
+ }
+
const wxPropertyInfo *pi = ci->GetFirstProperty() ;
while( pi )
{
// this property was not written yet in this object and we don't get a veto
- if ( data->m_writtenProperties.find( pi->GetName() ) == data->m_writtenProperties.end() )
+ // if ( data->m_writtenProperties.find( pi->GetName() ) == data->m_writtenProperties.end() )
+ // we will have to handle property overrides differently
{
data->m_writtenProperties[ pi->GetName() ] = 1 ;
DoBeginWriteProperty( pi ) ;
}
pi = pi->GetNext() ;
}
- // in case this object is wxDynamic object we have to hand over the streaming
- // of the properties of the superclasses to the real super class instance
- const wxDynamicObject* dynobj = dynamic_cast< const wxDynamicObject* > (obj ) ;
- if ( dynobj )
- obj = dynobj->GetSuperClassInstance() ;
- const wxClassInfo** parents = ci->GetParents() ;
- for ( int i = 0 ; parents[i] ; ++ i )
- {
- WriteAllProperties( obj , parents[i] , persister , data ) ;
- }
-}
+ }
int wxWriter::GetObjectID(const wxObject *obj)
{
}
// writes a delegate in the stream format
-void wxXmlWriter::DoWriteDelegate( const wxObject *WXUNUSED(object), const wxClassInfo* WXUNUSED(classInfo) , const wxPropertyInfo *pi ,
+void wxXmlWriter::DoWriteDelegate( const wxObject *WXUNUSED(object), const wxClassInfo* WXUNUSED(classInfo) , const wxPropertyInfo *WXUNUSED(pi) ,
const wxObject *eventSink, int sinkObjectID , const wxClassInfo* WXUNUSED(eventSinkClassInfo) , const wxHandlerInfo* handlerInfo )
{
if ( eventSink != NULL && handlerInfo != NULL )
int wxXmlReader::ReadComponent(wxXmlNode *node, wxDepersister *callbacks)
{
+ wxASSERT_MSG( callbacks , wxT("Does not support reading without a Depersistor") ) ;
wxString className;
wxClassInfo *classInfo;
const wxChar* paramName = classInfo->GetCreateParamName(i) ;
PropertyNodes::iterator propiter = propertyNodes.find( paramName ) ;
const wxPropertyInfo* pi = classInfo->FindPropertyInfo( paramName ) ;
+ wxASSERT_MSG(pi,wxString::Format("Unkown Property %s",paramName) ) ;
// if we don't have the value of a create param set in the xml
// we use the default value
if ( propiter != propertyNodes.end() )
const wxPropertyInfo* pi = classInfo->FindPropertyInfo( propertyNames[j].c_str() ) ;
if ( pi->GetTypeInfo()->GetKind() == wxT_COLLECTION )
{
- const wxTypeInfo * elementType = dynamic_cast< const wxCollectionTypeInfo* >( pi->GetTypeInfo() )->GetElementType() ;
+ const wxCollectionTypeInfo* collType = dynamic_cast< const wxCollectionTypeInfo* >( pi->GetTypeInfo() ) ;
+ const wxTypeInfo * elementType = collType->GetElementType() ;
while( prop )
{
wxASSERT_MSG(prop->GetName() == wxT("element") , wxT("A non empty collection must consist of 'element' nodes")) ;
if ( elementType->IsObjectType() )
{
int valueId = ReadComponent( elementContent , callbacks ) ;
- if ( callbacks )
+ if ( valueId != wxInvalidObjectID )
{
- if ( valueId != wxInvalidObjectID )
- {
- /*
- callbacks->SetPropertyAsObject( objectID , classInfo , pi , valueId ) ;
- */
- if ( elementType->GetKind() == wxT_OBJECT && valueId != wxNullObjectID )
- callbacks->DestroyObject( valueId , GetObjectClassInfo( valueId ) ) ;
- }
+ if ( pi->GetAccessor()->HasAdder() )
+ callbacks->AddToPropertyCollectionAsObject( objectID , classInfo , pi , valueId ) ;
+ // TODO for collections we must have a notation on taking over ownership or not
+ if ( elementType->GetKind() == wxT_OBJECT && valueId != wxNullObjectID )
+ callbacks->DestroyObject( valueId , GetObjectClassInfo( valueId ) ) ;
}
}
else
{
wxxVariant elementValue = ReadValue( prop , pi->GetAccessor() ) ;
- /*
- if ( callbacks )
- callbacks->SetProperty( objectID, classInfo ,pi , ) ;
- */
+ if ( pi->GetAccessor()->HasAdder() )
+ callbacks->AddToPropertyCollection( objectID , classInfo ,pi , elementValue ) ;
}
prop = prop->GetNext() ;
}
else if ( pi->GetTypeInfo()->IsObjectType() )
{
int valueId = ReadComponent( prop , callbacks ) ;
- if ( callbacks )
+ if ( valueId != wxInvalidObjectID )
{
- if ( valueId != wxInvalidObjectID )
- {
- callbacks->SetPropertyAsObject( objectID , classInfo , pi , valueId ) ;
- if ( pi->GetTypeInfo()->GetKind() == wxT_OBJECT && valueId != wxNullObjectID )
- callbacks->DestroyObject( valueId , GetObjectClassInfo( valueId ) ) ;
- }
+ callbacks->SetPropertyAsObject( objectID , classInfo , pi , valueId ) ;
+ if ( pi->GetTypeInfo()->GetKind() == wxT_OBJECT && valueId != wxNullObjectID )
+ callbacks->DestroyObject( valueId , GetObjectClassInfo( valueId ) ) ;
}
}
else if ( pi->GetTypeInfo()->IsDelegateType() )
wxString handlerName = resstring.Mid(pos+1) ;
wxClassInfo* sinkClassInfo = GetObjectClassInfo( sinkOid ) ;
- if (callbacks)
- callbacks->SetConnect( objectID , classInfo , dynamic_cast<const wxDelegateTypeInfo*>(pi->GetTypeInfo()) , sinkClassInfo ,
- sinkClassInfo->FindHandlerInfo(handlerName) , sinkOid ) ;
+ callbacks->SetConnect( objectID , classInfo , dynamic_cast<const wxDelegateTypeInfo*>(pi->GetTypeInfo()) , sinkClassInfo ,
+ sinkClassInfo->FindHandlerInfo(handlerName) , sinkOid ) ;
}
}
else
{
- if ( callbacks )
- callbacks->SetProperty( objectID, classInfo ,pi , ReadValue( prop , pi->GetAccessor() ) ) ;
+ callbacks->SetProperty( objectID, classInfo ,pi , ReadValue( prop , pi->GetAccessor() ) ) ;
}
}
}
wxObject *o;
o = m_data->GetObject(objectID);
classInfo->SetProperty( o , propertyInfo->GetName() , value ) ;
- // propertyInfo->GetAccessor()->SetProperty( o , value ) ;
}
void wxRuntimeDepersister::SetPropertyAsObject(int objectID,
}
classInfo->SetProperty( o , propertyInfo->GetName() , valClassInfo->InstanceToVariant(valo) ) ;
- // propertyInfo->GetAccessor()->SetProperty( o ,
- // (dynamic_cast<const wxClassTypeInfo*>(propertyInfo->GetTypeInfo()))->GetClassInfo()->InstanceToVariant(valo) ) ;
}
void wxRuntimeDepersister::SetConnect(int eventSourceObjectID,
return m_data->GetObject( objectID ) ;
}
+// adds an element to a property collection
+void wxRuntimeDepersister::AddToPropertyCollection( int objectID ,
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo ,
+ const wxxVariant &value)
+{
+ wxObject *o;
+ o = m_data->GetObject(objectID);
+ classInfo->AddToPropertyCollection( o , propertyInfo->GetName() , value ) ;
+}
+
+// sets the corresponding property (value is an object)
+void wxRuntimeDepersister::AddToPropertyCollectionAsObject(int objectID,
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo ,
+ int valueObjectId)
+{
+ wxObject *o, *valo;
+ o = m_data->GetObject(objectID);
+ valo = m_data->GetObject(valueObjectId);
+ const wxCollectionTypeInfo * collectionTypeInfo = dynamic_cast< const wxCollectionTypeInfo * >(propertyInfo->GetTypeInfo() ) ;
+ const wxClassInfo* valClassInfo = (dynamic_cast<const wxClassTypeInfo*>(collectionTypeInfo->GetElementType()))->GetClassInfo() ;
+ // if this is a dynamic object and we are asked for another class
+ // than wxDynamicObject we cast it down manually.
+ wxDynamicObject *dynvalo = dynamic_cast< wxDynamicObject * > (valo) ;
+ if ( dynvalo!=NULL && (valClassInfo != dynvalo->GetClassInfo()) )
+ {
+ valo = dynvalo->GetSuperClassInstance() ;
+ }
+
+ classInfo->AddToPropertyCollection( o , propertyInfo->GetName() , valClassInfo->InstanceToVariant(valo) ) ;
+}
// ----------------------------------------------------------------------------
// depersisting to code
m_data->GetObjectName( valueObjectId) ) );
}
+void wxCodeDepersister::AddToPropertyCollection( int objectID ,
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo ,
+ const wxxVariant &value)
+{
+ m_fp->WriteString( wxString::Format( "\t%s->%s(%s);\n",
+ m_data->GetObjectName(objectID),
+ propertyInfo->GetAccessor()->GetAdderName(),
+ ValueAsCode(value)) );
+}
+
+// sets the corresponding property (value is an object)
+void wxCodeDepersister::AddToPropertyCollectionAsObject(int objectID,
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo ,
+ int valueObjectId)
+{
+ // TODO
+}
+
void wxCodeDepersister::SetConnect(int eventSourceObjectID,
const wxClassInfo *WXUNUSED(eventSourceClassInfo),
const wxDelegateTypeInfo *delegateInfo ,