unicode and linkage corrections

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23223 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor 2003-08-25 23:31:41 +00:00
parent 5b59fbdddf
commit ed45345eb1
2 changed files with 148 additions and 23 deletions

View File

@ -186,7 +186,6 @@ void wxWriter::WriteOneProperty( const wxObject *obj , const wxClassInfo* ci , c
if ( dynobj && (dynamic_cast<const wxDynamicClassInfo*>(ci) == NULL) ) if ( dynobj && (dynamic_cast<const wxDynamicClassInfo*>(ci) == NULL) )
obj = dynobj->GetSuperClassInstance() ; obj = dynobj->GetSuperClassInstance() ;
DoBeginWriteProperty( pi ) ;
if ( pi->GetTypeInfo()->GetKind() == wxT_COLLECTION ) if ( pi->GetTypeInfo()->GetKind() == wxT_COLLECTION )
{ {
wxxVariantArray data ; wxxVariantArray data ;
@ -194,6 +193,9 @@ void wxWriter::WriteOneProperty( const wxObject *obj , const wxClassInfo* ci , c
const wxTypeInfo * elementType = dynamic_cast< const wxCollectionTypeInfo* >( pi->GetTypeInfo() )->GetElementType() ; const wxTypeInfo * elementType = dynamic_cast< const wxCollectionTypeInfo* >( pi->GetTypeInfo() )->GetElementType() ;
for ( size_t i = 0 ; i < data.GetCount() ; ++i ) for ( size_t i = 0 ; i < data.GetCount() ; ++i )
{ {
if ( i == 0 )
DoBeginWriteProperty( pi ) ;
DoBeginWriteElement() ; DoBeginWriteElement() ;
wxxVariant value = data[i] ; wxxVariant value = data[i] ;
if ( persister->BeforeWriteProperty( this , pi , value ) ) if ( persister->BeforeWriteProperty( this , pi , value ) )
@ -212,8 +214,10 @@ void wxWriter::WriteOneProperty( const wxObject *obj , const wxClassInfo* ci , c
} }
} }
DoEndWriteElement() ; DoEndWriteElement() ;
} if ( i == data.GetCount() - 1 )
} DoEndWriteProperty( pi ) ;
}
}
else else
{ {
const wxDelegateTypeInfo* dti = dynamic_cast< const wxDelegateTypeInfo* > ( pi->GetTypeInfo() ) ; const wxDelegateTypeInfo* dti = dynamic_cast< const wxDelegateTypeInfo* > ( pi->GetTypeInfo() ) ;
@ -230,8 +234,10 @@ void wxWriter::WriteOneProperty( const wxObject *obj , const wxClassInfo* ci , c
{ {
if ( sink != NULL && handler != NULL ) if ( sink != NULL && handler != NULL )
{ {
DoBeginWriteProperty( pi ) ;
wxASSERT_MSG( IsObjectKnown( sink ) , wxT("Streaming delegates for not already streamed objects not yet supported") ) ; 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 ) ; DoWriteDelegate( obj , ci , pi , sink , GetObjectID( sink ) , sink->GetClassInfo() , handler ) ;
DoEndWriteProperty( pi ) ;
} }
} }
} }
@ -239,30 +245,59 @@ void wxWriter::WriteOneProperty( const wxObject *obj , const wxClassInfo* ci , c
{ {
wxxVariant value ; wxxVariant value ;
pi->GetAccessor()->GetProperty(obj, value) ; pi->GetAccessor()->GetProperty(obj, value) ;
// avoid streaming out void objects
if( value.IsEmpty() )
return ;
if ( pi->GetFlags() & wxPROP_ENUM_STORE_LONG )
{
const wxEnumTypeInfo *eti = dynamic_cast<const wxEnumTypeInfo*>( pi->GetTypeInfo() ) ;
wxASSERT_MSG( eti , wxT("Type must have enum - long conversion") ) ;
eti->ConvertFromLong( value.Get<long>() , value ) ;
}
// avoid streaming out default values
if ( pi->GetTypeInfo()->HasStringConverters() && !pi->GetDefaultValue().IsEmpty() )
{
if ( value.GetAsString() == pi->GetDefaultValue().GetAsString() )
return ;
}
// avoid streaming out null objects
const wxClassTypeInfo* cti = dynamic_cast< const wxClassTypeInfo* > ( pi->GetTypeInfo() ) ;
if ( cti && value.GetAsObject() == NULL )
return ;
if ( persister->BeforeWriteProperty( this , pi , value ) ) if ( persister->BeforeWriteProperty( this , pi , value ) )
{ {
const wxClassTypeInfo* cti = dynamic_cast< const wxClassTypeInfo* > ( pi->GetTypeInfo() ) ; DoBeginWriteProperty( pi ) ;
if ( cti ) if ( cti )
{ {
const wxClassInfo* pci = cti->GetClassInfo() ; const wxClassInfo* pci = cti->GetClassInfo() ;
wxObject *vobj = pci->VariantToInstance( value ) ; wxObject *vobj = pci->VariantToInstance( value ) ;
wxxVariantArray md ; if ( vobj && pi->GetTypeInfo()->HasStringConverters() )
WriteObject( vobj , (vobj ? vobj->GetClassInfo() : pci ) , persister , cti->GetKind()== wxT_OBJECT , md) ; {
wxString stringValue ;
cti->ConvertToString( value , stringValue ) ;
wxxVariant convertedValue(stringValue) ;
DoWriteSimpleType( convertedValue ) ;
}
else
{
wxxVariantArray md ;
WriteObject( vobj , (vobj ? vobj->GetClassInfo() : pci ) , persister , cti->GetKind()== wxT_OBJECT , md) ;
}
} }
else else
{ {
if ( pi->GetFlags() & wxPROP_ENUM_STORE_LONG )
{
const wxEnumTypeInfo *eti = dynamic_cast<const wxEnumTypeInfo*>( pi->GetTypeInfo() ) ;
wxASSERT_MSG( eti , wxT("Type must have enum - long conversion") ) ;
eti->ConvertFromLong( value.Get<long>() , value ) ;
}
DoWriteSimpleType( value ) ; DoWriteSimpleType( value ) ;
} }
DoEndWriteProperty( pi ) ;
} }
} }
} }
DoEndWriteProperty( pi ) ;
} }
int wxWriter::GetObjectID(const wxObject *obj) int wxWriter::GetObjectID(const wxObject *obj)
@ -397,6 +432,36 @@ void wxRuntimeDepersister::CreateObject(int objectID,
classInfo->Create(o, paramCount, params); classInfo->Create(o, paramCount, params);
} }
void wxRuntimeDepersister::ConstructObject(int objectID,
const wxClassInfo *classInfo,
int paramCount,
wxxVariant *params,
int *objectIdValues,
const wxClassInfo **objectClassInfos ,
wxxVariantArray &WXUNUSED(metadata))
{
wxObject *o;
for ( int i = 0 ; i < paramCount ; ++i )
{
if ( objectIdValues[i] != wxInvalidObjectID )
{
wxObject *o;
o = m_data->GetObject(objectIdValues[i]);
// if this is a dynamic object and we are asked for another class
// than wxDynamicObject we cast it down manually.
wxDynamicObject *dyno = dynamic_cast< wxDynamicObject * > (o) ;
if ( dyno!=NULL && (objectClassInfos[i] != dyno->GetClassInfo()) )
{
o = dyno->GetSuperClassInstance() ;
}
params[i] = objectClassInfos[i]->InstanceToVariant(o) ;
}
}
o = classInfo->ConstructObject(paramCount, params);
m_data->SetObject(objectID, o);
}
void wxRuntimeDepersister::DestroyObject(int objectID, wxClassInfo *WXUNUSED(classInfo)) void wxRuntimeDepersister::DestroyObject(int objectID, wxClassInfo *WXUNUSED(classInfo))
{ {
wxObject *o; wxObject *o;
@ -587,6 +652,37 @@ void wxCodeDepersister::CreateObject(int objectID,
m_fp->WriteString( ");\n"); m_fp->WriteString( ");\n");
} }
void wxCodeDepersister::ConstructObject(int objectID,
const wxClassInfo *classInfo,
int paramCount,
wxxVariant *params,
int *objectIDValues,
const wxClassInfo **WXUNUSED(objectClassInfos) ,
wxxVariantArray &WXUNUSED(metadata)
)
{
wxString objectName = wxString::Format( "LocalObject_%d" , objectID ) ;
m_fp->WriteString( wxString::Format( "\t%s *%s = new %s(",
classInfo->GetClassName(),
objectName.c_str(),
classInfo->GetClassName()) );
m_data->SetObjectName( objectID , objectName ) ;
int i;
for (i = 0; i < paramCount; i++)
{
if ( objectIDValues[i] != wxInvalidObjectID )
m_fp->WriteString( wxString::Format( "%s", m_data->GetObjectName( objectIDValues[i] ).c_str() ) );
else
{
m_fp->WriteString( wxString::Format( "%s", ValueAsCode(params[i]).c_str() ) );
}
if (i < paramCount - 1)
m_fp->WriteString( ", ");
}
m_fp->WriteString( ");\n");
}
void wxCodeDepersister::SetProperty(int objectID, void wxCodeDepersister::SetProperty(int objectID,
const wxClassInfo *WXUNUSED(classInfo), const wxClassInfo *WXUNUSED(classInfo),
const wxPropertyInfo* propertyInfo, const wxPropertyInfo* propertyInfo,

View File

@ -266,7 +266,8 @@ int wxXmlReader::ReadComponent(wxXmlNode *node, wxDepersister *callbacks)
} }
xp = xp->GetNext() ; xp = xp->GetNext() ;
} }
callbacks->AllocateObject(objectID, classInfo, metadata); if ( !classInfo->NeedsDirectConstruction() )
callbacks->AllocateObject(objectID, classInfo, metadata);
// //
// stream back the Create parameters first // stream back the Create parameters first
@ -332,14 +333,28 @@ int wxXmlReader::ReadComponent(wxXmlNode *node, wxDepersister *callbacks)
} }
else else
{ {
createParams[i] = pi->GetDefaultValue() ; if ( pi->GetTypeInfo()->IsObjectType() )
{
createParamOids[i] = wxNullObjectID ;
createClassInfos[i] = dynamic_cast<const wxClassTypeInfo*>(pi->GetTypeInfo())->GetClassInfo() ;
}
else
{
createParams[i] = pi->GetDefaultValue() ;
createParamOids[i] = wxInvalidObjectID ;
}
} }
} }
// got the parameters. Call the Create method // got the parameters. Call the Create method
callbacks->CreateObject(objectID, classInfo, if ( classInfo->NeedsDirectConstruction() )
classInfo->GetCreateParamCount(), callbacks->ConstructObject(objectID, classInfo,
createParams, createParamOids, createClassInfos, metadata ); classInfo->GetCreateParamCount(),
createParams, createParamOids, createClassInfos, metadata );
else
callbacks->CreateObject(objectID, classInfo,
classInfo->GetCreateParamCount(),
createParams, createParamOids, createClassInfos, metadata );
// now stream in the rest of the properties, in the sequence their properties were written in the xml // 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 ) for ( size_t j = 0 ; j < propertyNames.size() ; ++j )
@ -386,12 +401,26 @@ int wxXmlReader::ReadComponent(wxXmlNode *node, wxDepersister *callbacks)
} }
else if ( pi->GetTypeInfo()->IsObjectType() ) else if ( pi->GetTypeInfo()->IsObjectType() )
{ {
int valueId = ReadComponent( prop , callbacks ) ; // and object can either be streamed out a string or as an object
if ( valueId != wxInvalidObjectID ) // in case we have no node, then the object's streaming out has been vetoed
if ( prop )
{ {
callbacks->SetPropertyAsObject( objectID , classInfo , pi , valueId ) ; if ( prop->GetName() == wxT("object") )
if ( pi->GetTypeInfo()->GetKind() == wxT_OBJECT && valueId != wxNullObjectID ) {
callbacks->DestroyObject( valueId , GetObjectClassInfo( valueId ) ) ; int valueId = ReadComponent( prop , callbacks ) ;
if ( valueId != wxInvalidObjectID )
{
callbacks->SetPropertyAsObject( objectID , classInfo , pi , valueId ) ;
if ( pi->GetTypeInfo()->GetKind() == wxT_OBJECT && valueId != wxNullObjectID )
callbacks->DestroyObject( valueId , GetObjectClassInfo( valueId ) ) ;
}
}
else
{
wxASSERT( pi->GetTypeInfo()->HasStringConverters() ) ;
wxxVariant nodeval = ReadValue( prop , pi->GetTypeInfo() ) ;
callbacks->SetProperty( objectID, classInfo ,pi , nodeval ) ;
}
} }
} }
else if ( pi->GetTypeInfo()->IsDelegateType() ) else if ( pi->GetTypeInfo()->IsDelegateType() )