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,6 +214,8 @@ void wxWriter::WriteOneProperty( const wxObject *obj , const wxClassInfo* ci , c
} }
} }
DoEndWriteElement() ; DoEndWriteElement() ;
if ( i == data.GetCount() - 1 )
DoEndWriteProperty( pi ) ;
} }
} }
else else
@ -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) ;
if ( persister->BeforeWriteProperty( this , pi , value ) )
{ // avoid streaming out void objects
const wxClassTypeInfo* cti = dynamic_cast< const wxClassTypeInfo* > ( pi->GetTypeInfo() ) ; if( value.IsEmpty() )
if ( cti ) return ;
{
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 ) if ( pi->GetFlags() & wxPROP_ENUM_STORE_LONG )
{ {
const wxEnumTypeInfo *eti = dynamic_cast<const wxEnumTypeInfo*>( pi->GetTypeInfo() ) ; const wxEnumTypeInfo *eti = dynamic_cast<const wxEnumTypeInfo*>( pi->GetTypeInfo() ) ;
wxASSERT_MSG( eti , wxT("Type must have enum - long conversion") ) ; wxASSERT_MSG( eti , wxT("Type must have enum - long conversion") ) ;
eti->ConvertFromLong( value.Get<long>() , value ) ; 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 ) )
{
DoBeginWriteProperty( pi ) ;
if ( cti )
{
const wxClassInfo* pci = cti->GetClassInfo() ;
wxObject *vobj = pci->VariantToInstance( value ) ;
if ( vobj && pi->GetTypeInfo()->HasStringConverters() )
{
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
{
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,6 +266,7 @@ int wxXmlReader::ReadComponent(wxXmlNode *node, wxDepersister *callbacks)
} }
xp = xp->GetNext() ; xp = xp->GetNext() ;
} }
if ( !classInfo->NeedsDirectConstruction() )
callbacks->AllocateObject(objectID, classInfo, metadata); callbacks->AllocateObject(objectID, classInfo, metadata);
// //
@ -331,12 +332,26 @@ int wxXmlReader::ReadComponent(wxXmlNode *node, wxDepersister *callbacks)
} }
} }
else else
{
if ( pi->GetTypeInfo()->IsObjectType() )
{
createParamOids[i] = wxNullObjectID ;
createClassInfos[i] = dynamic_cast<const wxClassTypeInfo*>(pi->GetTypeInfo())->GetClassInfo() ;
}
else
{ {
createParams[i] = pi->GetDefaultValue() ; createParams[i] = pi->GetDefaultValue() ;
createParamOids[i] = wxInvalidObjectID ;
}
} }
} }
// got the parameters. Call the Create method // got the parameters. Call the Create method
if ( classInfo->NeedsDirectConstruction() )
callbacks->ConstructObject(objectID, classInfo,
classInfo->GetCreateParamCount(),
createParams, createParamOids, createClassInfos, metadata );
else
callbacks->CreateObject(objectID, classInfo, callbacks->CreateObject(objectID, classInfo,
classInfo->GetCreateParamCount(), classInfo->GetCreateParamCount(),
createParams, createParamOids, createClassInfos, metadata ); createParams, createParamOids, createClassInfos, metadata );
@ -385,6 +400,12 @@ int wxXmlReader::ReadComponent(wxXmlNode *node, wxDepersister *callbacks)
} }
} }
else if ( pi->GetTypeInfo()->IsObjectType() ) else if ( pi->GetTypeInfo()->IsObjectType() )
{
// and object can either be streamed out a string or as an object
// in case we have no node, then the object's streaming out has been vetoed
if ( prop )
{
if ( prop->GetName() == wxT("object") )
{ {
int valueId = ReadComponent( prop , callbacks ) ; int valueId = ReadComponent( prop , callbacks ) ;
if ( valueId != wxInvalidObjectID ) if ( valueId != wxInvalidObjectID )
@ -394,6 +415,14 @@ int wxXmlReader::ReadComponent(wxXmlNode *node, wxDepersister *callbacks)
callbacks->DestroyObject( valueId , GetObjectClassInfo( valueId ) ) ; 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() )
{ {
if ( prop ) if ( prop )