X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c90b8250d9d0d94e17beff3f74bd86ca2654958c..1e52188741389278cd99abf79218162c87024ba3:/src/common/xtistrm.cpp?ds=sidebyside diff --git a/src/common/xtistrm.cpp b/src/common/xtistrm.cpp index e826757586..372602c376 100644 --- a/src/common/xtistrm.cpp +++ b/src/common/xtistrm.cpp @@ -59,7 +59,7 @@ wxWriter::~wxWriter() struct wxWriter::wxWriterInternalPropertiesData { - map< string , int > m_writtenProperties ; + char nothing ; } ; void wxWriter::ClearObjectContext() @@ -69,14 +69,14 @@ void wxWriter::ClearObjectContext() m_data->m_nextId = 0 ; } -void wxWriter::WriteObject(const wxObject *object, const wxClassInfo *classInfo , wxPersister *persister , const wxString &name ) +void wxWriter::WriteObject(const wxObject *object, const wxClassInfo *classInfo , wxPersister *persister , const wxString &name , wxxVariantArray &metadata ) { DoBeginWriteTopLevelEntry( name ) ; - WriteObject( object , classInfo , persister , false ) ; + WriteObject( object , classInfo , persister , false , metadata) ; DoEndWriteTopLevelEntry( name ) ; } -void wxWriter::WriteObject(const wxObject *object, const wxClassInfo *classInfo , wxPersister *persister , bool isEmbedded) +void wxWriter::WriteObject(const wxObject *object, const wxClassInfo *classInfo , wxPersister *persister , bool isEmbedded, wxxVariantArray &metadata ) { // hack to avoid writing out embedded windows, these are windows that are constructed as part of other windows, they would // doubly constructed afterwards @@ -85,7 +85,7 @@ void wxWriter::WriteObject(const wxObject *object, const wxClassInfo *classInfo if ( win && win->GetId() < 0 ) return ; - if ( persister->BeforeWriteObject( this , object , classInfo ) ) + if ( persister->BeforeWriteObject( this , object , classInfo , metadata) ) { if ( object == NULL ) DoWriteNullObject() ; @@ -103,7 +103,7 @@ void wxWriter::WriteObject(const wxObject *object, const wxClassInfo *classInfo if ( !isEmbedded && dynobj ) m_data->m_writtenObjects[dynobj->GetSuperClassInstance()] = oid ; - DoBeginWriteObject( object , classInfo , oid ) ; + DoBeginWriteObject( object , classInfo , oid , metadata ) ; wxWriterInternalPropertiesData data ; WriteAllProperties( object , classInfo , persister , &data ) ; DoEndWriteObject( object , classInfo , oid ) ; @@ -152,101 +152,121 @@ void wxWriter::FindConnectEntry(const wxWindow * evSource,const wxDelegateTypeIn } 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 + wxPropertyInfoMap map ; + ci->GetProperties( map ) ; + for ( int i = 0 ; i < ci->GetCreateParamCount() ; ++i ) { - 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 ) + wxString name = ci->GetCreateParamName(i) ; + const wxPropertyInfo* prop = map.find(name)->second ; + wxASSERT_MSG( prop , wxT("Create Parameter not found in declared RTTI Parameters") ) ; + WriteOneProperty( obj , prop->GetDeclaringClass() , prop , persister , data ) ; + map.erase( name ) ; + } + + for( wxPropertyInfoMap::iterator iter = map.begin() ; iter != map.end() ; ++iter ) + { + const wxPropertyInfo* prop = iter->second ; + if ( prop->GetFlags() & wxPROP_OBJECT_GRAPH ) + { + WriteOneProperty( obj , prop->GetDeclaringClass() , prop , persister , data ) ; + } + } + + for( wxPropertyInfoMap::iterator iter = map.begin() ; iter != map.end() ; ++iter ) + { + const wxPropertyInfo* prop = iter->second ; + if ( !(prop->GetFlags() & wxPROP_OBJECT_GRAPH) ) { - WriteAllProperties( iterobj , parents[i] , persister , data ) ; + WriteOneProperty( obj , prop->GetDeclaringClass() , prop , persister , data ) ; } } +} + +void wxWriter::WriteOneProperty( const wxObject *obj , const wxClassInfo* ci , const wxPropertyInfo* pi , wxPersister *persister , wxWriterInternalPropertiesData *data ) +{ + // make sure that we are picking the correct object for accessing the property + const wxDynamicObject* dynobj = dynamic_cast< const wxDynamicObject* > (obj ) ; + if ( dynobj && (dynamic_cast(ci) == NULL) ) + obj = dynobj->GetSuperClassInstance() ; - const wxPropertyInfo *pi = ci->GetFirstProperty() ; - while( pi ) + DoBeginWriteProperty( pi ) ; + if ( pi->GetTypeInfo()->GetKind() == wxT_COLLECTION ) { - // 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() ) - // we will have to handle property overrides differently + wxxVariantArray data ; + pi->GetAccessor()->GetPropertyCollection(obj, data) ; + const wxTypeInfo * elementType = dynamic_cast< const wxCollectionTypeInfo* >( pi->GetTypeInfo() )->GetElementType() ; + for ( size_t i = 0 ; i < data.GetCount() ; ++i ) { - data->m_writtenProperties[ pi->GetName() ] = 1 ; - DoBeginWriteProperty( pi ) ; - if ( pi->GetTypeInfo()->GetKind() == wxT_COLLECTION ) + DoBeginWriteElement() ; + wxxVariant value = data[i] ; + if ( persister->BeforeWriteProperty( this , pi , value ) ) { - wxxVariantArray data ; - pi->GetAccessor()->GetPropertyCollection(obj, data) ; - const wxTypeInfo * elementType = dynamic_cast< const wxCollectionTypeInfo* >( pi->GetTypeInfo() )->GetElementType() ; - for ( size_t i = 0 ; i < data.GetCount() ; ++i ) + const wxClassTypeInfo* cti = dynamic_cast< const wxClassTypeInfo* > ( elementType ) ; + if ( cti ) { - DoBeginWriteElement() ; - wxxVariant value = data[i] ; - if ( persister->BeforeWriteProperty( this , pi , value ) ) - { - const wxClassTypeInfo* cti = dynamic_cast< const wxClassTypeInfo* > ( elementType ) ; - if ( cti ) - { - const wxClassInfo* pci = cti->GetClassInfo() ; - wxObject *vobj = pci->VariantToInstance( value ) ; - WriteObject( vobj , (vobj ? vobj->GetClassInfo() : pci ) , persister , cti->GetKind()== wxT_OBJECT ) ; - } - else - { - DoWriteSimpleType( value ) ; - } - } - DoEndWriteElement() ; + const wxClassInfo* pci = cti->GetClassInfo() ; + wxObject *vobj = pci->VariantToInstance( value ) ; + wxxVariantArray md ; + WriteObject( vobj , (vobj ? vobj->GetClassInfo() : pci ) , persister , cti->GetKind()== wxT_OBJECT , md ) ; } - } - else - { - const wxDelegateTypeInfo* dti = dynamic_cast< const wxDelegateTypeInfo* > ( pi->GetTypeInfo() ) ; - if ( dti ) + else { - const wxObject* sink = NULL ; - const wxHandlerInfo *handler = NULL ; + DoWriteSimpleType( value ) ; + } + } + DoEndWriteElement() ; + } + } + else + { + const wxDelegateTypeInfo* dti = dynamic_cast< const wxDelegateTypeInfo* > ( pi->GetTypeInfo() ) ; + if ( dti ) + { + const wxObject* sink = NULL ; + const wxHandlerInfo *handler = NULL ; - const wxWindow * evSource = dynamic_cast(obj) ; - wxASSERT_MSG( evSource , wxT("Illegal Object Class (Non-Window) as Event Source") ) ; + const wxWindow * evSource = dynamic_cast(obj) ; + wxASSERT_MSG( evSource , wxT("Illegal Object Class (Non-Window) as Event Source") ) ; - FindConnectEntry( evSource , dti , sink , handler ) ; - if ( persister->BeforeWriteDelegate( this , obj , ci , pi , sink , handler ) ) - { - if ( sink != NULL && handler != NULL ) - { - wxASSERT_MSG( IsObjectKnown( sink ) , wxT("Streaming delegates for not already streamed objects not yet supported") ) ; - DoWriteDelegate( obj , ci , pi , sink , GetObjectID( sink ) , sink->GetClassInfo() , handler ) ; - } - } + FindConnectEntry( evSource , dti , sink , handler ) ; + if ( persister->BeforeWriteDelegate( this , obj , ci , pi , sink , handler ) ) + { + if ( sink != NULL && handler != NULL ) + { + wxASSERT_MSG( IsObjectKnown( sink ) , wxT("Streaming delegates for not already streamed objects not yet supported") ) ; + DoWriteDelegate( obj , ci , pi , sink , GetObjectID( sink ) , sink->GetClassInfo() , handler ) ; } - else + } + } + else + { + wxxVariant value ; + pi->GetAccessor()->GetProperty(obj, value) ; + if ( persister->BeforeWriteProperty( this , pi , value ) ) + { + const wxClassTypeInfo* cti = dynamic_cast< const wxClassTypeInfo* > ( pi->GetTypeInfo() ) ; + if ( cti ) { - wxxVariant value ; - pi->GetAccessor()->GetProperty(obj, value) ; - if ( persister->BeforeWriteProperty( this , pi , value ) ) + const wxClassInfo* pci = cti->GetClassInfo() ; + wxObject *vobj = pci->VariantToInstance( value ) ; + wxxVariantArray md ; + WriteObject( vobj , (vobj ? vobj->GetClassInfo() : pci ) , persister , cti->GetKind()== wxT_OBJECT , md) ; + } + else + { + if ( pi->GetFlags() & wxPROP_ENUM_STORE_LONG ) { - const wxClassTypeInfo* cti = dynamic_cast< const wxClassTypeInfo* > ( pi->GetTypeInfo() ) ; - if ( cti ) - { - const wxClassInfo* pci = cti->GetClassInfo() ; - wxObject *vobj = pci->VariantToInstance( value ) ; - WriteObject( vobj , (vobj ? vobj->GetClassInfo() : pci ) , persister , cti->GetKind()== wxT_OBJECT ) ; - } - else - { - DoWriteSimpleType( value ) ; - } + const wxEnumTypeInfo *eti = dynamic_cast( pi->GetTypeInfo() ) ; + wxASSERT_MSG( eti , wxT("Type must have enum - long conversion") ) ; + eti->ConvertFromLong( value.Get() , value ) ; } + DoWriteSimpleType( value ) ; } } - DoEndWriteProperty( pi ) ; } - pi = pi->GetNext() ; } - } + DoEndWriteProperty( pi ) ; +} int wxWriter::GetObjectID(const wxObject *obj) { @@ -325,13 +345,17 @@ void wxXmlWriter::DoEndWriteTopLevelEntry( const wxString &WXUNUSED(name) ) m_data->Pop() ; } -void wxXmlWriter::DoBeginWriteObject(const wxObject *WXUNUSED(object), const wxClassInfo *classInfo, int objectID ) +void wxXmlWriter::DoBeginWriteObject(const wxObject *WXUNUSED(object), const wxClassInfo *classInfo, int objectID , wxxVariantArray &metadata ) { wxXmlNode *pnode; pnode = new wxXmlNode(wxXML_ELEMENT_NODE, wxT("object")); pnode->AddProperty(wxT("class"), wxString(classInfo->GetClassName())); pnode->AddProperty(wxT("id"), wxString::Format( "%d" , objectID ) ); + for ( size_t i = 0 ; i < metadata.GetCount() ; ++i ) + { + pnode->AddProperty( metadata[i].GetName() , metadata[i].GetAsString() ) ; + } m_data->m_current->AddChild(pnode) ; m_data->Push( pnode ) ; } @@ -501,7 +525,17 @@ int wxXmlReader::ReadComponent(wxXmlNode *node, wxDepersister *callbacks) // first make the object know to our internal registry SetObjectClassInfo( objectID , classInfo ) ; - callbacks->AllocateObject(objectID, classInfo); + wxxVariantArray metadata ; + wxXmlProperty *xp = node->GetProperties() ; + while ( xp ) + { + if ( xp->GetName() != wxString("class") && xp->GetName() != wxString("id") ) + { + metadata.Add( new wxxVariant( xp->GetValue() , xp->GetName() ) ) ; + } + xp = xp->GetNext() ; + } + callbacks->AllocateObject(objectID, classInfo, metadata); // // stream back the Create parameters first @@ -544,6 +578,15 @@ int wxXmlReader::ReadComponent(wxXmlNode *node, wxDepersister *callbacks) { createParamOids[i] = wxInvalidObjectID ; createParams[i] = ReadValue( prop , pi->GetTypeInfo() ) ; + if( pi->GetFlags() & wxPROP_ENUM_STORE_LONG ) + { + const wxEnumTypeInfo *eti = dynamic_cast( pi->GetTypeInfo() ) ; + wxASSERT_MSG( eti , wxT("Type must have enum - long conversion") ) ; + + long realval ; + eti->ConvertToLong( createParams[i] , realval ) ; + createParams[i] = wxxVariant( realval ) ; + } createClassInfos[i] = NULL ; } @@ -565,7 +608,7 @@ int wxXmlReader::ReadComponent(wxXmlNode *node, wxDepersister *callbacks) // got the parameters. Call the Create method callbacks->CreateObject(objectID, classInfo, classInfo->GetCreateParamCount(), - createParams, createParamOids, createClassInfos); + createParams, createParamOids, createClassInfos, metadata ); // now stream in the rest of the properties, in the sequence their properties were written in the xml for ( size_t j = 0 ; j < propertyNames.size() ; ++j ) @@ -632,7 +675,7 @@ int wxXmlReader::ReadComponent(wxXmlNode *node, wxDepersister *callbacks) wxClassInfo* sinkClassInfo = GetObjectClassInfo( sinkOid ) ; callbacks->SetConnect( objectID , classInfo , dynamic_cast(pi->GetTypeInfo()) , sinkClassInfo , - sinkClassInfo->FindHandlerInfo(handlerName) , sinkOid ) ; + sinkClassInfo->FindHandlerInfo(handlerName) , sinkOid ) ; } } @@ -712,7 +755,8 @@ wxRuntimeDepersister::~wxRuntimeDepersister() delete m_data ; } -void wxRuntimeDepersister::AllocateObject(int objectID, wxClassInfo *classInfo) +void wxRuntimeDepersister::AllocateObject(int objectID, wxClassInfo *classInfo , + wxxVariantArray &metadata) { wxObject *O; O = classInfo->CreateObject(); @@ -724,7 +768,8 @@ void wxRuntimeDepersister::CreateObject(int objectID, int paramCount, wxxVariant *params, int *objectIdValues, - const wxClassInfo **objectClassInfos) + const wxClassInfo **objectClassInfos , + wxxVariantArray &metadata) { wxObject *o; o = m_data->GetObject(objectID); @@ -809,9 +854,9 @@ wxObject *wxRuntimeDepersister::GetObject(int objectID) // adds an element to a property collection void wxRuntimeDepersister::AddToPropertyCollection( int objectID , - const wxClassInfo *classInfo, - const wxPropertyInfo* propertyInfo , - const wxxVariant &value) + const wxClassInfo *classInfo, + const wxPropertyInfo* propertyInfo , + const wxxVariant &value) { wxObject *o; o = m_data->GetObject(objectID); @@ -820,9 +865,9 @@ void wxRuntimeDepersister::AddToPropertyCollection( int objectID , // sets the corresponding property (value is an object) void wxRuntimeDepersister::AddToPropertyCollectionAsObject(int objectID, - const wxClassInfo *classInfo, - const wxPropertyInfo* propertyInfo , - int valueObjectId) + const wxClassInfo *classInfo, + const wxPropertyInfo* propertyInfo , + int valueObjectId) { wxObject *o, *valo; o = m_data->GetObject(objectID); @@ -874,7 +919,8 @@ wxCodeDepersister::~wxCodeDepersister() delete m_data ; } -void wxCodeDepersister::AllocateObject(int objectID, wxClassInfo *classInfo) +void wxCodeDepersister::AllocateObject(int objectID, wxClassInfo *classInfo , + wxxVariantArray &metadata) { wxString objectName = wxString::Format( "LocalObject_%d" , objectID ) ; m_fp->WriteString( wxString::Format( "\t%s *%s = new %s;\n", @@ -916,7 +962,8 @@ void wxCodeDepersister::CreateObject(int objectID, int paramCount, wxxVariant *params, int *objectIDValues, - const wxClassInfo **WXUNUSED(objectClassInfos) + const wxClassInfo **WXUNUSED(objectClassInfos) , + wxxVariantArray &metadata ) { int i; @@ -964,9 +1011,9 @@ void wxCodeDepersister::SetPropertyAsObject(int objectID, } void wxCodeDepersister::AddToPropertyCollection( int objectID , - const wxClassInfo *classInfo, - const wxPropertyInfo* propertyInfo , - const wxxVariant &value) + const wxClassInfo *classInfo, + const wxPropertyInfo* propertyInfo , + const wxxVariant &value) { m_fp->WriteString( wxString::Format( "\t%s->%s(%s);\n", m_data->GetObjectName(objectID), @@ -976,9 +1023,9 @@ void wxCodeDepersister::AddToPropertyCollection( int objectID , // sets the corresponding property (value is an object) void wxCodeDepersister::AddToPropertyCollectionAsObject(int objectID, - const wxClassInfo *classInfo, - const wxPropertyInfo* propertyInfo , - int valueObjectId) + const wxClassInfo *classInfo, + const wxPropertyInfo* propertyInfo , + int valueObjectId) { // TODO }