-// ----------------------------------------------------------------------------
-// depersisting to code
-// ----------------------------------------------------------------------------
-
-struct wxCodeDepersister::wxCodeDepersisterInternal
-{
-#if wxUSE_UNICODE
- map<int,wstring> m_objectNames ;
-#else
- map<int,string> m_objectNames ;
-#endif
-
- void SetObjectName(int objectID, const wxString &name )
- {
- assert( m_objectNames.find(objectID) == m_objectNames.end() ) ;
- m_objectNames[objectID] = (const wxChar *)name;
- }
- wxString GetObjectName( int objectID )
- {
- if ( objectID == wxNullObjectID )
- return wxT("NULL") ;
-
- assert( m_objectNames.find(objectID) != m_objectNames.end() ) ;
- return wxString( m_objectNames[objectID].c_str() ) ;
- }
-} ;
-
-wxCodeDepersister::wxCodeDepersister(wxTextOutputStream *out)
-: m_fp(out)
-{
- m_data = new wxCodeDepersisterInternal ;
-}
-
-wxCodeDepersister::~wxCodeDepersister()
-{
- delete m_data ;
-}
-
-void wxCodeDepersister::AllocateObject(int objectID, wxClassInfo *classInfo ,
- wxxVariantArray &WXUNUSED(metadata))
-{
- wxString objectName = wxString::Format( wxT("LocalObject_%d") , objectID ) ;
- m_fp->WriteString( wxString::Format( wxT("\t%s *%s = new %s;\n"),
- classInfo->GetClassName(),
- objectName.c_str(),
- classInfo->GetClassName()) );
- m_data->SetObjectName( objectID , objectName ) ;
-}
-
-void wxCodeDepersister::DestroyObject(int objectID, wxClassInfo *WXUNUSED(classInfo))
-{
- m_fp->WriteString( wxString::Format( wxT("\tdelete %s;\n"),
- m_data->GetObjectName( objectID).c_str() ) );
-}
-
-wxString wxCodeDepersister::ValueAsCode( const wxxVariant ¶m )
-{
- wxString value ;
- const wxTypeInfo* type = param.GetTypeInfo() ;
- if ( type->GetKind() == wxT_CUSTOM )
- {
- const wxCustomTypeInfo* cti = dynamic_cast<const wxCustomTypeInfo*>(type) ;
- wxASSERT_MSG( cti , wxT("Internal error, illegal wxCustomTypeInfo") ) ;
- value.Printf( wxT("%s(%s)"), cti->GetTypeName().c_str(),param.GetAsString().c_str() );
- }
- else if ( type->GetKind() == wxT_STRING )
- {
- value.Printf( wxT("\"%s\""),param.GetAsString().c_str() );
- }
- else
- {
- value.Printf( wxT("%s"), param.GetAsString().c_str() );
- }
- return value ;
-}
-
-void wxCodeDepersister::CreateObject(int objectID,
- const wxClassInfo *WXUNUSED(classInfo),
- int paramCount,
- wxxVariant *params,
- int *objectIDValues,
- const wxClassInfo **WXUNUSED(objectClassInfos) ,
- wxxVariantArray &WXUNUSED(metadata)
- )
-{
- int i;
- m_fp->WriteString( wxString::Format( wxT("\t%s->Create("), m_data->GetObjectName(objectID).c_str() ) );
- for (i = 0; i < paramCount; i++)
- {
- if ( objectIDValues[i] != wxInvalidObjectID )
- m_fp->WriteString( wxString::Format( wxT("%s"), m_data->GetObjectName( objectIDValues[i] ).c_str() ) );
- else
- {
- m_fp->WriteString( wxString::Format( wxT("%s"), ValueAsCode(params[i]).c_str() ) );
- }
- if (i < paramCount - 1)
- m_fp->WriteString( wxT(", "));
- }
- m_fp->WriteString( wxT(");\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( wxT("LocalObject_%d") , objectID ) ;
- m_fp->WriteString( wxString::Format( wxT("\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( wxT("%s"), m_data->GetObjectName( objectIDValues[i] ).c_str() ) );
- else
- {
- m_fp->WriteString( wxString::Format( wxT("%s"), ValueAsCode(params[i]).c_str() ) );
- }
- if (i < paramCount - 1)
- m_fp->WriteString( wxT(", ") );
- }
- m_fp->WriteString( wxT(");\n") );
-}
-
-void wxCodeDepersister::SetProperty(int objectID,
- const wxClassInfo *WXUNUSED(classInfo),
- const wxPropertyInfo* propertyInfo,
- const wxxVariant &value)
-{
- m_fp->WriteString( wxString::Format( wxT("\t%s->%s(%s);\n"),
- m_data->GetObjectName(objectID).c_str(),
- propertyInfo->GetAccessor()->GetSetterName().c_str(),
- ValueAsCode(value).c_str()) );
-}
-
-void wxCodeDepersister::SetPropertyAsObject(int objectID,
- const wxClassInfo *WXUNUSED(classInfo),
- const wxPropertyInfo* propertyInfo,
- int valueObjectId)
-{
- if ( propertyInfo->GetTypeInfo()->GetKind() == wxT_OBJECT )
- m_fp->WriteString( wxString::Format( wxT("\t%s->%s(*%s);\n"),
- m_data->GetObjectName(objectID).c_str(),
- propertyInfo->GetAccessor()->GetSetterName().c_str(),
- m_data->GetObjectName( valueObjectId).c_str() ) );
- else
- m_fp->WriteString( wxString::Format( wxT("\t%s->%s(%s);\n"),
- m_data->GetObjectName(objectID).c_str(),
- propertyInfo->GetAccessor()->GetSetterName().c_str(),
- m_data->GetObjectName( valueObjectId).c_str() ) );
-}
-
-void wxCodeDepersister::AddToPropertyCollection( int objectID ,
- const wxClassInfo *WXUNUSED(classInfo),
- const wxPropertyInfo* propertyInfo ,
- const wxxVariant &value)
-{
- m_fp->WriteString( wxString::Format( wxT("\t%s->%s(%s);\n"),
- m_data->GetObjectName(objectID).c_str(),
- propertyInfo->GetAccessor()->GetAdderName().c_str(),
- ValueAsCode(value).c_str()) );
-}
-
-// sets the corresponding property (value is an object)
-void wxCodeDepersister::AddToPropertyCollectionAsObject(int WXUNUSED(objectID),
- const wxClassInfo *WXUNUSED(classInfo),
- const wxPropertyInfo* WXUNUSED(propertyInfo) ,
- int WXUNUSED(valueObjectId))
-{
- // TODO
-}
-
-void wxCodeDepersister::SetConnect(int eventSourceObjectID,
- const wxClassInfo *WXUNUSED(eventSourceClassInfo),
- const wxPropertyInfo *delegateInfo ,
- const wxClassInfo *eventSinkClassInfo ,
- const wxHandlerInfo* handlerInfo ,
- int eventSinkObjectID )
-{
- wxString ehsource = m_data->GetObjectName( eventSourceObjectID ) ;
- wxString ehsink = m_data->GetObjectName(eventSinkObjectID) ;
- wxString ehsinkClass = eventSinkClassInfo->GetClassName() ;
- const wxDelegateTypeInfo *delegateTypeInfo = dynamic_cast<const wxDelegateTypeInfo*>(delegateInfo->GetTypeInfo());
- wxASSERT_MSG(delegateTypeInfo, "delegate has no type info");
- int eventType = delegateTypeInfo->GetEventType() ;
- wxString handlerName = handlerInfo->GetName() ;
-
- m_fp->WriteString( wxString::Format( wxT("\t%s->Connect( %s->GetId() , %d , (wxObjectEventFunction)(wxEventFunction) & %s::%s , NULL , %s ) ;") ,
- ehsource.c_str() , ehsource.c_str() , eventType , ehsinkClass.c_str() , handlerName.c_str() , ehsink.c_str() ) );
-}
-
-#include <wx/arrimpl.cpp>
-
-WX_DEFINE_OBJARRAY(wxxVariantArray);
-
-#endif