From e765d7ee7309149e8be24e29466a2b2c8ff7b3ae Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Fri, 7 Jan 2011 17:49:18 +0000 Subject: [PATCH] xti changes git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66630 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/any.cpp | 8 ++ src/common/bmpbase.cpp | 5 ++ src/common/colourcmn.cpp | 2 +- src/common/fontcmn.cpp | 36 ++++---- src/common/ipcbase.cpp | 6 +- src/common/menucmn.cpp | 44 +++++++--- src/common/module.cpp | 2 +- src/common/nbkbase.cpp | 7 +- src/common/object.cpp | 17 ++-- src/common/spinctrlcmn.cpp | 2 +- src/common/wincmn.cpp | 11 +-- src/common/xti.cpp | 149 +++++++++++++++++++++++++------- src/common/xtistrm.cpp | 170 ++++++++++++++++++++----------------- src/common/xtixml.cpp | 57 +++++++------ 14 files changed, 328 insertions(+), 188 deletions(-) diff --git a/src/common/any.cpp b/src/common/any.cpp index 9a2953bca2..451d8395b4 100644 --- a/src/common/any.cpp +++ b/src/common/any.cpp @@ -516,6 +516,14 @@ public: return false; } +#if wxUSE_EXTENDED_RTTI + virtual const wxTypeInfo* GetTypeInfo() const + { + wxFAIL_MSG("Null Type Info not available"); + return NULL; + } +#endif + private: }; diff --git a/src/common/bmpbase.cpp b/src/common/bmpbase.cpp index e80091dada..bae77c18ce 100644 --- a/src/common/bmpbase.cpp +++ b/src/common/bmpbase.cpp @@ -32,6 +32,11 @@ IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxBitmap,WXDLLEXPORT) IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxIcon,WXDLLEXPORT) #endif +#if wxUSE_EXTENDED_RTTI +//WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl) +//WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl) +#endif + // ---------------------------------------------------------------------------- // wxBitmapBase // ---------------------------------------------------------------------------- diff --git a/src/common/colourcmn.cpp b/src/common/colourcmn.cpp index 182d654f24..d2e5bc16f0 100644 --- a/src/common/colourcmn.cpp +++ b/src/common/colourcmn.cpp @@ -59,7 +59,7 @@ wxFROM_STRING_IMP( wxColour ) wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( wxColour, wxObject, \ "wx/colour.h", &wxTO_STRING( wxColour ), &wxFROM_STRING( wxColour )) - +//WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl) wxBEGIN_PROPERTIES_TABLE(wxColour) wxREADONLY_PROPERTY( Red, unsigned char, Red, wxEMPTY_PARAMETER_VALUE, \ 0 /*flags*/, wxT("Helpstring"), wxT("group")) diff --git a/src/common/fontcmn.cpp b/src/common/fontcmn.cpp index c6f2c50c6a..01587a796f 100644 --- a/src/common/fontcmn.cpp +++ b/src/common/fontcmn.cpp @@ -76,37 +76,39 @@ extern const char *wxDumpFont(const wxFont *font) // ---------------------------------------------------------------------------- wxBEGIN_ENUM( wxFontFamily ) -wxENUM_MEMBER( wxDEFAULT ) -wxENUM_MEMBER( wxDECORATIVE ) -wxENUM_MEMBER( wxROMAN ) -wxENUM_MEMBER( wxSCRIPT ) -wxENUM_MEMBER( wxSWISS ) -wxENUM_MEMBER( wxMODERN ) -wxENUM_MEMBER( wxTELETYPE ) +wxENUM_MEMBER( wxFONTFAMILY_DEFAULT ) +wxENUM_MEMBER( wxFONTFAMILY_DECORATIVE ) +wxENUM_MEMBER( wxFONTFAMILY_ROMAN ) +wxENUM_MEMBER( wxFONTFAMILY_SCRIPT ) +wxENUM_MEMBER( wxFONTFAMILY_SWISS ) +wxENUM_MEMBER( wxFONTFAMILY_MODERN ) +wxENUM_MEMBER( wxFONTFAMILY_TELETYPE ) wxEND_ENUM( wxFontFamily ) wxBEGIN_ENUM( wxFontStyle ) -wxENUM_MEMBER( wxNORMAL ) -wxENUM_MEMBER( wxITALIC ) -wxENUM_MEMBER( wxSLANT ) +wxENUM_MEMBER( wxFONTSTYLE_NORMAL ) +wxENUM_MEMBER( wxFONTSTYLE_ITALIC ) +wxENUM_MEMBER( wxFONTSTYLE_SLANT ) wxEND_ENUM( wxFontStyle ) wxBEGIN_ENUM( wxFontWeight ) -wxENUM_MEMBER( wxNORMAL ) -wxENUM_MEMBER( wxLIGHT ) -wxENUM_MEMBER( wxBOLD ) +wxENUM_MEMBER( wxFONTWEIGHT_NORMAL ) +wxENUM_MEMBER( wxFONTWEIGHT_LIGHT ) +wxENUM_MEMBER( wxFONTWEIGHT_BOLD ) wxEND_ENUM( wxFontWeight ) wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI(wxFont, wxGDIObject, "wx/font.h") +//WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl) + wxBEGIN_PROPERTIES_TABLE(wxFont) wxPROPERTY( Size,int, SetPointSize, GetPointSize, 12, 0 /*flags*/, \ wxT("Helpstring"), wxT("group")) -wxPROPERTY( Family, int , SetFamily, GetFamily, (int)wxDEFAULT, \ +wxPROPERTY( Family, wxFontFamily , SetFamily, GetFamily, (wxFontFamily)wxDEFAULT, \ 0 /*flags*/, wxT("Helpstring"), wxT("group")) // wxFontFamily -wxPROPERTY( Style, int, SetStyle, GetStyle, (int)wxNORMAL, 0 /*flags*/, \ +wxPROPERTY( Style, wxFontStyle, SetStyle, GetStyle, (wxFontStyle)wxNORMAL, 0 /*flags*/, \ wxT("Helpstring"), wxT("group")) // wxFontStyle -wxPROPERTY( Weight, int, SetWeight, GetWeight, (int)wxNORMAL, 0 /*flags*/, \ +wxPROPERTY( Weight, wxFontWeight, SetWeight, GetWeight, (wxFontWeight)wxNORMAL, 0 /*flags*/, \ wxT("Helpstring"), wxT("group")) // wxFontWeight wxPROPERTY( Underlined, bool, SetUnderlined, GetUnderlined, false, 0 /*flags*/, \ wxT("Helpstring"), wxT("group")) @@ -116,7 +118,7 @@ wxPROPERTY( Encoding, wxFontEncoding, SetEncoding, GetEncoding, \ wxFONTENCODING_DEFAULT, 0 /*flags*/, wxT("Helpstring"), wxT("group")) wxEND_PROPERTIES_TABLE() -wxCONSTRUCTOR_6( wxFont, int, Size, int, Family, int, Style, int, Weight, \ +wxCONSTRUCTOR_6( wxFont, int, Size, wxFontFamily, Family, wxFontStyle, Style, wxFontWeight, Weight, \ bool, Underlined, wxString, Face ) wxEMPTY_HANDLERS_TABLE(wxFont) diff --git a/src/common/ipcbase.cpp b/src/common/ipcbase.cpp index 2f6a30ab75..6f6c8c1629 100644 --- a/src/common/ipcbase.cpp +++ b/src/common/ipcbase.cpp @@ -21,9 +21,9 @@ #include "wx/ipcbase.h" -IMPLEMENT_CLASS(wxServerBase, wxObject) -IMPLEMENT_CLASS(wxClientBase, wxObject) -IMPLEMENT_CLASS(wxConnectionBase, wxObject) +wxIMPLEMENT_ABSTRACT_CLASS(wxServerBase, wxObject) +wxIMPLEMENT_ABSTRACT_CLASS(wxClientBase, wxObject) +wxIMPLEMENT_ABSTRACT_CLASS(wxConnectionBase, wxObject) wxConnectionBase::wxConnectionBase(void *buffer, size_t bytes) : m_buffer((char *)buffer), diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index c556c59c2d..f69b78b893 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -65,9 +65,9 @@ wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxMenu, wxEvtHandler, "wx/menu.h") wxCOLLECTION_TYPE_INFO( wxMenuItem *, wxMenuItemList ) ; template<> void wxCollectionToVariantArray( wxMenuItemList const &theList, - wxVariantBaseArray &value) + wxAnyList &value) { - wxListCollectionToVariantArray( theList, value ) ; + wxListCollectionToAnyList( theList, value ) ; } wxBEGIN_PROPERTIES_TABLE(wxMenu) @@ -97,7 +97,7 @@ wxEND_FLAGS( wxMenuBarStyle ) // the negative id would lead the window (its superclass !) to // vetoe streaming out otherwise bool wxMenuBarStreamingCallback( const wxObject *WXUNUSED(object), wxObjectWriter *, - wxObjectReaderCallback *, wxVariantBaseArray & ) + wxObjectWriterCallback *, const wxStringToAnyHashMap & ) { return true; } @@ -122,9 +122,9 @@ wxCONSTRUCTOR_2( wxMenuInfo, wxMenu*, Menu, wxString, Title ) wxCOLLECTION_TYPE_INFO( wxMenuInfo *, wxMenuInfoList ) ; template<> void wxCollectionToVariantArray( wxMenuInfoList const &theList, - wxVariantBaseArray &value) + wxAnyList &value) { - wxListCollectionToVariantArray( theList, value ) ; + wxListCollectionToAnyList( theList, value ) ; } wxBEGIN_PROPERTIES_TABLE(wxMenuBar) @@ -136,6 +136,25 @@ wxEMPTY_HANDLERS_TABLE(wxMenuBar) wxCONSTRUCTOR_DUMMY( wxMenuBar ) +const wxMenuInfoList& wxMenuBarBase::GetMenuInfos() const +{ + wxMenuInfoList* list = const_cast< wxMenuInfoList* > (& m_menuInfos); + WX_CLEAR_LIST( wxMenuInfoList, *list); + for (size_t i = 0 ; i < GetMenuCount(); ++i) + { + wxMenuInfo* info = new wxMenuInfo(); + info->Create( GetMenu(i), GetMenuLabel(i)); + list->Append(info); + } + return m_menuInfos; +} + +/* +WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl) +WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl) +WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl) +WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl) +*/ #else // IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler) // IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxWindow) @@ -150,7 +169,7 @@ wxCONSTRUCTOR_DUMMY( wxMenuBar ) #if wxUSE_EXTENDED_RTTI bool wxMenuItemStreamingCallback( const wxObject *object, wxObjectWriter *, - wxObjectReaderCallback *, wxVariantBaseArray & ) + wxObjectWriterCallback *, const wxStringToAnyHashMap & ) { const wxMenuItem * mitem = wx_dynamic_cast(const wxMenuItem*, object); if ( mitem->GetMenu() && !mitem->GetMenu()->GetTitle().empty() ) @@ -164,6 +183,8 @@ bool wxMenuItemStreamingCallback( const wxObject *object, wxObjectWriter *, return true; } +#endif + wxBEGIN_ENUM( wxItemKind ) wxENUM_MEMBER( wxITEM_SEPARATOR ) wxENUM_MEMBER( wxITEM_NORMAL ) @@ -179,7 +200,7 @@ wxPROPERTY( Parent, wxMenu*, SetMenu, GetMenu, wxEMPTY_PARAMETER_VALUE, \ 0 /*flags*/, wxT("Helpstring"), wxT("group") ) wxPROPERTY( Id, int, SetId, GetId, wxEMPTY_PARAMETER_VALUE, \ 0 /*flags*/, wxT("Helpstring"), wxT("group") ) -wxPROPERTY( Text, wxString, SetText, GetText, wxString(), \ +wxPROPERTY( ItemLabel, wxString, SetItemLabel, GetItemLabel, wxString(), \ 0 /*flags*/, wxT("Helpstring"), wxT("group") ) wxPROPERTY( Help, wxString, SetHelp, GetHelp, wxString(), \ 0 /*flags*/, wxT("Helpstring"), wxT("group") ) @@ -187,11 +208,11 @@ wxREADONLY_PROPERTY( Kind, wxItemKind, GetKind, wxEMPTY_PARAMETER_VALUE, \ 0 /*flags*/, wxT("Helpstring"), wxT("group") ) wxPROPERTY( SubMenu, wxMenu*, SetSubMenu, GetSubMenu, wxEMPTY_PARAMETER_VALUE, \ 0 /*flags*/, wxT("Helpstring"), wxT("group") ) -wxPROPERTY( Enabled, bool, Enable, IsEnabled, wxVariantBase((bool)true), \ +wxPROPERTY( Enabled, bool, Enable, IsEnabled, wxAny((bool)true), \ 0 /*flags*/, wxT("Helpstring"), wxT("group") ) -wxPROPERTY( Checked, bool, Check, IsChecked, wxVariantBase((bool)false), \ +wxPROPERTY( Checked, bool, Check, IsChecked, wxAny((bool)false), \ 0 /*flags*/, wxT("Helpstring"), wxT("group") ) -wxPROPERTY( Checkable, bool, SetCheckable, IsCheckable, wxVariantBase((bool)false), \ +wxPROPERTY( Checkable, bool, SetCheckable, IsCheckable, wxAny((bool)false), \ 0 /*flags*/, wxT("Helpstring"), wxT("group") ) wxEND_PROPERTIES_TABLE() @@ -199,9 +220,6 @@ wxEMPTY_HANDLERS_TABLE(wxMenuItem) wxDIRECT_CONSTRUCTOR_6( wxMenuItem, wxMenu*, Parent, int, Id, wxString, \ Text, wxString, Help, wxItemKind, Kind, wxMenu*, SubMenu ) -#else -//IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject) -#endif // ---------------------------------------------------------------------------- // wxMenuItemBase diff --git a/src/common/module.cpp b/src/common/module.cpp index 4f61711b48..3532ceb149 100644 --- a/src/common/module.cpp +++ b/src/common/module.cpp @@ -30,7 +30,7 @@ WX_DEFINE_LIST(wxModuleList) -IMPLEMENT_CLASS(wxModule, wxObject) +wxIMPLEMENT_ABSTRACT_CLASS(wxModule, wxObject) wxModuleList wxModule::m_modules; diff --git a/src/common/nbkbase.cpp b/src/common/nbkbase.cpp index 25f336f0b7..f191f9adfd 100644 --- a/src/common/nbkbase.cpp +++ b/src/common/nbkbase.cpp @@ -93,13 +93,11 @@ wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebookPageInfo, wxObject, "wx/notebook.h" ) wxCOLLECTION_TYPE_INFO( wxNotebookPageInfo *, wxNotebookPageInfoList ); -#if wxUSE_EXTENDED_RTTI template<> void wxCollectionToVariantArray( wxNotebookPageInfoList const &theList, - wxVariantBaseArray &value) + wxAnyList &value) { - wxListCollectionToVariantArray( theList, value ); + wxListCollectionToAnyList( theList, value ); } -#endif wxBEGIN_PROPERTIES_TABLE(wxNotebook) wxEVENT_PROPERTY( PageChanging, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, wxNotebookEvent ) @@ -134,6 +132,7 @@ wxEMPTY_HANDLERS_TABLE(wxNotebookPageInfo) wxCONSTRUCTOR_4( wxNotebookPageInfo, wxNotebookPage*, Page, \ wxString, Text, bool, Selected, int, ImageId ) +WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl) // XTI accessors: void wxNotebookBase::AddPageInfo( wxNotebookPageInfo* info ) diff --git a/src/common/object.cpp b/src/common/object.cpp index 05d4dd13b7..fbcd2766b5 100644 --- a/src/common/object.cpp +++ b/src/common/object.cpp @@ -44,21 +44,20 @@ #if wxUSE_EXTENDED_RTTI const wxClassInfo* wxObject::ms_classParents[] = { NULL } ; - wxObject* wxVariantToObjectConverterwxObject ( wxxVariant &data ) -{ return data.wxTEMPLATED_MEMBER_CALL(Get , wxObject*) ; } - wxObject* wxVariantOfPtrToObjectConverterwxObject ( wxxVariant &data ) -{ return &data.wxTEMPLATED_MEMBER_CALL(Get , wxObject) ; } - wxxVariant wxObjectToVariantConverterwxObject ( wxObject *data ) - { return wxxVariant( dynamic_cast (data) ) ; } +wxObject* wxVariantOfPtrToObjectConverterwxObject ( const wxAny &data ) +{ return wxANY_AS(data, wxObject*); } + wxAny wxObjectToVariantConverterwxObject ( wxObject *data ) + { return wxAny( dynamic_cast (data) ) ; } + wxClassInfo wxObject::ms_classInfo(ms_classParents , wxEmptyString , wxT("wxObject"), (int) sizeof(wxObject), \ (wxObjectConstructorFn) 0 , NULL,NULL,0 , 0 , - 0 , wxVariantOfPtrToObjectConverterwxObject , wxVariantToObjectConverterwxObject , wxObjectToVariantConverterwxObject); - template<> void wxStringReadValue(const wxString & , wxObject * & ){ wxFAIL_MSG("unreachable"); } + 0 , wxVariantOfPtrToObjectConverterwxObject , 0 , wxObjectToVariantConverterwxObject); + template<> void wxStringWriteValue(wxString & , wxObject* const & ){ wxFAIL_MSG("unreachable"); } - template<> void wxStringReadValue(const wxString & , wxObject & ){ wxFAIL_MSG("unreachable"); } template<> void wxStringWriteValue(wxString & , wxObject const & ){ wxFAIL_MSG("unreachable"); } + wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &wxObject::ms_classInfo , NULL , NULL , typeid(wxObject*).name() ) ; wxClassTypeInfo s_typeInfowxObject(wxT_OBJECT , &wxObject::ms_classInfo , NULL , NULL , typeid(wxObject).name() ) ; #else diff --git a/src/common/spinctrlcmn.cpp b/src/common/spinctrlcmn.cpp index a412181416..9ed3f6c3db 100644 --- a/src/common/spinctrlcmn.cpp +++ b/src/common/spinctrlcmn.cpp @@ -70,7 +70,7 @@ wxFLAGS_MEMBER(wxSP_ARROW_KEYS) wxFLAGS_MEMBER(wxSP_WRAP) wxEND_FLAGS( wxSpinCtrlStyle ) -wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxSpinCtrl, wxControl, "wx/spinbut.h") +wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxSpinCtrl, wxControl, "wx/spinctrl.h") wxBEGIN_PROPERTIES_TABLE(wxSpinCtrl) wxEVENT_RANGE_PROPERTY( Spin, wxEVT_SCROLL_TOP, wxEVT_SCROLL_CHANGED, wxSpinEvent ) diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 337f86e330..e458f80cda 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -127,8 +127,9 @@ END_EVENT_TABLE() // separately otherwise chaos occurs. Right now easiest is to test for negative ids, // as windows with negative ids never can be recreated anyway + bool wxWindowStreamingCallback( const wxObject *object, wxObjectWriter *, - wxObjectReaderCallback *, wxVariantBaseArray & ) + wxObjectWriterCallback *, const wxStringToAnyHashMap & ) { const wxWindow * win = wx_dynamic_cast(const wxWindow*, object); if ( win && win->GetId() < 0 ) @@ -144,9 +145,9 @@ wxIMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow, wxWindowBase, "wx/window.h", \ wxCOLLECTION_TYPE_INFO( wxWindow*, wxWindowList ); template<> void wxCollectionToVariantArray( wxWindowList const &theList, - wxVariantBaseArray &value) + wxAnyList &value) { - wxListCollectionToVariantArray( theList, value ); + wxListCollectionToAnyList( theList, value ); } wxDEFINE_FLAGS( wxWindowStyle ) @@ -215,9 +216,9 @@ wxPROPERTY( BackgroundColour, wxColour, SetBackgroundColour, GetBackgroundColour wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, wxT("Helpstring"), wxT("group")) // bg wxPROPERTY( ForegroundColour, wxColour, SetForegroundColour, GetForegroundColour, \ wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, wxT("Helpstring"), wxT("group")) // fg -wxPROPERTY( Enabled, bool, Enable, IsEnabled, wxVariantBase((bool)true), 0 /*flags*/, \ +wxPROPERTY( Enabled, bool, Enable, IsEnabled, wxAny((bool)true), 0 /*flags*/, \ wxT("Helpstring"), wxT("group")) -wxPROPERTY( Shown, bool, Show, IsShown, wxVariantBase((bool)true), 0 /*flags*/, \ +wxPROPERTY( Shown, bool, Show, IsShown, wxAny((bool)true), 0 /*flags*/, \ wxT("Helpstring"), wxT("group")) #if 0 diff --git a/src/common/xti.cpp b/src/common/xti.cpp index 419726db5c..bd9fd18cca 100644 --- a/src/common/xti.cpp +++ b/src/common/xti.cpp @@ -28,6 +28,8 @@ #include "wx/xti.h" #include "wx/xml/xml.h" #include "wx/tokenzr.h" +#include "wx/range.h" + #include #include "wx/beforestd.h" @@ -200,6 +202,27 @@ template<> void wxStringWriteValue(wxString &s, const unsigned long &data ) s = wxString::Format(_T("%ld"), data ); } +#ifdef wxLongLong_t +template<> void wxStringReadValue(const wxString &s, wxLongLong_t &data ) +{ + wxSscanf(s, _T("%lld"), &data ); +} + +template<> void wxStringWriteValue(wxString &s, const wxLongLong_t &data ) +{ + s = wxString::Format(_T("%lld"), data ); +} + +template<> void wxStringReadValue(const wxString &s, wxULongLong_t &data ) +{ + wxSscanf(s, _T("%lld"), &data ); +} + +template<> void wxStringWriteValue(wxString &s, const wxULongLong_t &data ) +{ + s = wxString::Format(_T("%lld"), data ); +} +#endif // float template<> void wxStringReadValue(const wxString &s, float &data ) @@ -247,9 +270,9 @@ template<> void wxStringWriteValue(wxString &s, const wxString &data ) &wxFromStringConverter, typeid(type).name()); #else #define wxBUILTIN_TYPE_INFO( element, type ) \ - void _toString##element( const wxVariantBase& data, wxString &result ) \ + void _toString##element( const wxAny& data, wxString &result ) \ { wxToStringConverter void wxStringReadValue(const wxString &s , wxRange &data) +{ + int minValue, maxValue; + wxSscanf(s, wxT("%d,%d"), &minValue , &maxValue); + data = wxRange(minValue, maxValue); +} + +template<> void wxStringWriteValue(wxString &s , const wxRange &data) +{ + s = wxString::Format(wxT("%d,%d"), data.GetMin() , data.GetMax()); +} + +wxCUSTOM_TYPE_INFO(wxRange, wxToStringConverter , wxFromStringConverter) + +// other types + wxCOLLECTION_TYPE_INFO( wxString, wxArrayString ); template<> void wxCollectionToVariantArray( wxArrayString const &theArray, - wxVariantBaseArray &value) + wxAnyList &value) { wxArrayCollectionToVariantArray( theArray, value ); } wxTypeInfoMap *wxTypeInfo::ms_typeTable = NULL; -wxTypeInfo *wxTypeInfo::FindType(const wxChar *typeName) +wxTypeInfo *wxTypeInfo::FindType(const wxString& typeName) { wxTypeInfoMap::iterator iter = ms_typeTable->find(typeName); @@ -418,6 +463,7 @@ void wxPropertyInfo::Remove() info = info->m_next; } } + } // ---------------------------------------------------------------------------- @@ -466,7 +512,7 @@ void wxHandlerInfo::Remove() // wxClassInfo // ---------------------------------------------------------------------------- -bool wxClassInfo::Create(wxObject *object, int ParamCount, wxVariantBase *Params) const +bool wxClassInfo::Create(wxObject *object, int ParamCount, wxAny *Params) const { if ( ParamCount != m_constructorPropertiesCount ) { @@ -478,7 +524,7 @@ bool wxClassInfo::Create(wxObject *object, int ParamCount, wxVariantBase *Params return m_constructor->Create( object, Params ); } -wxObject *wxClassInfo::ConstructObject(int ParamCount, wxVariantBase *Params) const +wxObject *wxClassInfo::ConstructObject(int ParamCount, wxAny *Params) const { if ( ParamCount != m_constructorPropertiesCount ) { @@ -521,7 +567,7 @@ const wxPropertyAccessor *wxClassInfo::FindAccessor(const wxChar *PropertyName) wxPropertyInfo *wxClassInfo::FindPropertyInfoInThisClass (const wxChar *PropertyName) const { - wxPropertyInfo* info = m_firstProperty; + wxPropertyInfo* info = GetFirstProperty(); while( info ) { @@ -551,7 +597,7 @@ const wxPropertyInfo *wxClassInfo::FindPropertyInfo (const wxChar *PropertyName) wxHandlerInfo *wxClassInfo::FindHandlerInfoInThisClass (const wxChar *PropertyName) const { - wxHandlerInfo* info = m_firstHandler; + wxHandlerInfo* info = GetFirstHandler(); while( info ) { @@ -595,17 +641,17 @@ wxObjectStreamingCallback wxClassInfo::GetStreamingCallback() const } bool wxClassInfo::BeforeWriteObject( const wxObject *obj, wxObjectWriter *streamer, - wxObjectReaderCallback *persister, wxVariantBaseArray &metadata) const + wxObjectWriterCallback *writercallback, const wxStringToAnyHashMap &metadata) const { wxObjectStreamingCallback sb = GetStreamingCallback(); if ( sb ) - return (*sb)(obj, streamer, persister, metadata ); + return (*sb)(obj, streamer, writercallback, metadata ); return true; } void wxClassInfo::SetProperty(wxObject *object, const wxChar *propertyName, - const wxVariantBase &value) const + const wxAny &value) const { const wxPropertyAccessor *accessor; @@ -614,31 +660,31 @@ void wxClassInfo::SetProperty(wxObject *object, const wxChar *propertyName, accessor->SetProperty( object, value ); } -wxVariantBase wxClassInfo::GetProperty(wxObject *object, const wxChar *propertyName) const +wxAny wxClassInfo::GetProperty(wxObject *object, const wxChar *propertyName) const { const wxPropertyAccessor *accessor; accessor = FindAccessor(propertyName); wxASSERT(accessor->HasGetter()); - wxVariantBase result; + wxAny result; accessor->GetProperty(object,result); return result; } -wxVariantBaseArray wxClassInfo::GetPropertyCollection(wxObject *object, +wxAnyList wxClassInfo::GetPropertyCollection(wxObject *object, const wxChar *propertyName) const { const wxPropertyAccessor *accessor; accessor = FindAccessor(propertyName); wxASSERT(accessor->HasGetter()); - wxVariantBaseArray result; + wxAnyList result; accessor->GetPropertyCollection(object,result); return result; } void wxClassInfo::AddToPropertyCollection(wxObject *object, const wxChar *propertyName, - const wxVariantBase& value) const + const wxAny& value) const { const wxPropertyAccessor *accessor; @@ -668,6 +714,23 @@ void wxClassInfo::GetProperties( wxPropertyInfoMap &infomap ) const } } +wxObject* wxClassInfo::AnyToObjectPtr( const wxAny &data) const +{ + return m_variantOfPtrToObjectConverter(data); +} + +void wxClassInfo::CallOnAny( const wxAny &data, wxObjectFunctor* functor ) const +{ + if ( data.GetTypeInfo()->GetKind() == wxT_OBJECT ) + return m_variantToObjectConverter(data, functor); + else + return (*functor)(m_variantOfPtrToObjectConverter(data)); +} + +wxAny wxClassInfo::ObjectPtrToAny( wxObject* obj) const +{ + return m_objectToVariantConverter(obj); +} // ---------------------------------------------------------------------------- // wxDynamicObject support @@ -681,11 +744,7 @@ struct wxDynamicObject::wxDynamicObjectInternal { wxDynamicObjectInternal() {} -#if wxUSE_UNICODE - map m_properties; -#else - map m_properties; -#endif + wxStringToAnyHashMap m_properties; }; typedef list< wxDynamicObject* > wxDynamicObjectList; @@ -711,14 +770,14 @@ wxDynamicObject::~wxDynamicObject() delete m_superClassInstance; } -void wxDynamicObject::SetProperty (const wxChar *propertyName, const wxVariantBase &value) +void wxDynamicObject::SetProperty (const wxChar *propertyName, const wxAny &value) { wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(propertyName), wxT("Accessing Unknown Property in a Dynamic Object") ); m_data->m_properties[propertyName] = value; } -wxVariantBase wxDynamicObject::GetProperty (const wxChar *propertyName) const +wxAny wxDynamicObject::GetProperty (const wxChar *propertyName) const { wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(propertyName), wxT("Accessing Unknown Property in a Dynamic Object") ); @@ -738,7 +797,7 @@ void wxDynamicObject::RenameProperty( const wxChar *oldPropertyName, wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(oldPropertyName), wxT("Renaming Unknown Property in a Dynamic Object") ); - wxVariantBase value = m_data->m_properties[oldPropertyName]; + wxAny value = m_data->m_properties[oldPropertyName]; m_data->m_properties.erase( oldPropertyName ); m_data->m_properties[newPropertyName] = value; } @@ -772,7 +831,7 @@ wxObject *wxDynamicClassInfo::AllocateObject() const return obj; } -bool wxDynamicClassInfo::Create (wxObject *object, int paramCount, wxVariantBase *params) const +bool wxDynamicClassInfo::Create (wxObject *object, int paramCount, wxAny *params) const { wxDynamicObject *dynobj = wx_dynamic_cast( wxDynamicObject *, object ); wxASSERT_MSG( dynobj, @@ -794,7 +853,7 @@ const wxChar* wxDynamicClassInfo::GetCreateParamName(int i) const return GetParents()[0]->GetCreateParamName( i ); } -void wxDynamicClassInfo::SetProperty(wxObject *object, const wxChar *propertyName, const wxVariantBase &value) const +void wxDynamicClassInfo::SetProperty(wxObject *object, const wxChar *propertyName, const wxAny &value) const { wxDynamicObject* dynobj = wx_dynamic_cast(wxDynamicObject*, object); wxASSERT_MSG( dynobj, wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ); @@ -804,7 +863,7 @@ void wxDynamicClassInfo::SetProperty(wxObject *object, const wxChar *propertyNam GetParents()[0]->SetProperty( dynobj->GetSuperClassInstance(), propertyName, value ); } -wxVariantBase wxDynamicClassInfo::GetProperty(wxObject *object, const wxChar *propertyName) const +wxAny wxDynamicClassInfo::GetProperty(wxObject *object, const wxChar *propertyName) const { wxDynamicObject* dynobj = wx_dynamic_cast(wxDynamicObject*, object); wxASSERT_MSG( dynobj, wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ); @@ -816,11 +875,13 @@ wxVariantBase wxDynamicClassInfo::GetProperty(wxObject *object, const wxChar *pr void wxDynamicClassInfo::AddProperty( const wxChar *propertyName, const wxTypeInfo* typeInfo ) { - new wxPropertyInfo( m_firstProperty, this, propertyName, typeInfo->GetTypeName(), new wxGenericPropertyAccessor( propertyName ), wxVariantBase() ); + EnsureInfosInited(); + new wxPropertyInfo( m_firstProperty, this, propertyName, typeInfo->GetTypeName(), new wxGenericPropertyAccessor( propertyName ), wxAny() ); } void wxDynamicClassInfo::AddHandler( const wxChar *handlerName, wxObjectEventFunction address, const wxClassInfo* eventClassInfo ) { + EnsureInfosInited(); new wxHandlerInfo( m_firstHandler, this, handlerName, address, eventClassInfo ); } @@ -879,18 +940,46 @@ wxGenericPropertyAccessor::~wxGenericPropertyAccessor() delete m_data; } -void wxGenericPropertyAccessor::SetProperty(wxObject *object, const wxVariantBase &value) const +void wxGenericPropertyAccessor::SetProperty(wxObject *object, const wxAny &value) const { wxDynamicObject* dynobj = wx_dynamic_cast(wxDynamicObject*, object); wxASSERT_MSG( dynobj, wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ); dynobj->SetProperty(m_propertyName, value ); } -void wxGenericPropertyAccessor::GetProperty(const wxObject *object, wxVariantBase& value) const +void wxGenericPropertyAccessor::GetProperty(const wxObject *object, wxAny& value) const { const wxDynamicObject* dynobj = wx_dynamic_cast( const wxDynamicObject * , object ); wxASSERT_MSG( dynobj, wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ); value = dynobj->GetProperty( m_propertyName ); } +// ---------------------------------------------------------------------------- +// wxGenericPropertyAccessor +// ---------------------------------------------------------------------------- + +wxString wxAnyGetAsString( const wxAny& data) +{ + if ( data.IsNull() || data.GetTypeInfo()==NULL ) + return wxEmptyString; + + wxString s; + data.GetTypeInfo()->ConvertToString(data,s); + return s; +} + +const wxObject* wxAnyGetAsObjectPtr( const wxAny& data) +{ + if ( !data.IsNull() ) + { + const wxClassTypeInfo* ti = wx_dynamic_cast(const wxClassTypeInfo*, data.GetTypeInfo()); + if( ti ) + return ti->GetClassInfo()->AnyToObjectPtr(data); + } + return NULL; +} + +wxObjectFunctor::~wxObjectFunctor() +{}; + #endif // wxUSE_EXTENDED_RTTI diff --git a/src/common/xtistrm.cpp b/src/common/xtistrm.cpp index 0691af6242..a366c64d96 100644 --- a/src/common/xtistrm.cpp +++ b/src/common/xtistrm.cpp @@ -73,22 +73,22 @@ void wxObjectWriter::ClearObjectContext() } void wxObjectWriter::WriteObject(const wxObject *object, const wxClassInfo *classInfo, - wxObjectReaderCallback *persister, const wxString &name, - wxVariantBaseArray &metadata ) + wxObjectWriterCallback *writercallback, const wxString &name, + const wxStringToAnyHashMap &metadata ) { DoBeginWriteTopLevelEntry( name ); - WriteObject( object, classInfo, persister, false, metadata); + WriteObject( object, classInfo, writercallback, false, metadata); DoEndWriteTopLevelEntry( name ); } void wxObjectWriter::WriteObject(const wxObject *object, const wxClassInfo *classInfo, - wxObjectReaderCallback *persister, bool isEmbedded, - wxVariantBaseArray &metadata ) + wxObjectWriterCallback *writercallback, bool isEmbedded, + const wxStringToAnyHashMap &metadata ) { - if ( !classInfo->BeforeWriteObject( object, this, persister, metadata) ) + if ( !classInfo->BeforeWriteObject( object, this, writercallback, metadata) ) return; - if ( persister->BeforeWriteObject( this, object, classInfo, metadata) ) + if ( writercallback->BeforeWriteObject( this, object, classInfo, metadata) ) { if ( object == NULL ) DoWriteNullObject(); @@ -108,10 +108,10 @@ void wxObjectWriter::WriteObject(const wxObject *object, const wxClassInfo *clas DoBeginWriteObject( object, classInfo, oid, metadata ); wxObjectWriterInternalPropertiesData data; - WriteAllProperties( object, classInfo, persister, &data ); + WriteAllProperties( object, classInfo, writercallback, &data ); DoEndWriteObject( object, classInfo, oid ); } - persister->AfterWriteObject( this,object, classInfo ); + writercallback->AfterWriteObject( this,object, classInfo ); } } @@ -124,23 +124,22 @@ void wxObjectWriter::FindConnectEntry(const wxEvtHandler * evSource, if ( dynamicEvents ) { - wxList::compatibility_iterator node = dynamicEvents->GetFirst(); - while (node) + for ( wxList::const_iterator node = dynamicEvents->begin(); node != dynamicEvents->end(); ++node ) { - wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData(); + wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)(*node); // find the match if ( entry->m_fn && (dti->GetEventType() == entry->m_eventType) && (entry->m_id == -1 ) && - (entry->m_eventSink != NULL ) ) + (entry->m_fn->GetEvtHandler() != NULL ) ) { - sink = entry->m_eventSink; + sink = entry->m_fn->GetEvtHandler(); const wxClassInfo* sinkClassInfo = sink->GetClassInfo(); const wxHandlerInfo* sinkHandler = sinkClassInfo->GetFirstHandler(); while ( sinkHandler ) { - if ( sinkHandler->GetEventFunction() == entry->m_fn ) + if ( sinkHandler->GetEventFunction() == entry->m_fn->GetEvtMethod() ) { handler = sinkHandler; break; @@ -149,12 +148,11 @@ void wxObjectWriter::FindConnectEntry(const wxEvtHandler * evSource, } break; } - node = node->GetNext(); } } } void wxObjectWriter::WriteAllProperties( const wxObject * obj, const wxClassInfo* ci, - wxObjectReaderCallback *persister, + wxObjectWriterCallback *writercallback, wxObjectWriterInternalPropertiesData * data ) { wxPropertyInfoMap map; @@ -166,7 +164,7 @@ void wxObjectWriter::WriteAllProperties( const wxObject * obj, const wxClassInfo const wxPropertyInfo* prop = iter == map.end() ? NULL : iter->second; if ( prop ) { - WriteOneProperty( obj, prop->GetDeclaringClass(), prop, persister, data ); + WriteOneProperty( obj, prop->GetDeclaringClass(), prop, writercallback, data ); } else { @@ -180,7 +178,7 @@ void wxObjectWriter::WriteAllProperties( const wxObject * obj, const wxClassInfo const wxPropertyInfo* prop = iter->second; if ( prop->GetFlags() & wxPROP_OBJECT_GRAPH ) { - WriteOneProperty( obj, prop->GetDeclaringClass(), prop, persister, data ); + WriteOneProperty( obj, prop->GetDeclaringClass(), prop, writercallback, data ); } } } @@ -190,14 +188,36 @@ void wxObjectWriter::WriteAllProperties( const wxObject * obj, const wxClassInfo const wxPropertyInfo* prop = iter->second; if ( !(prop->GetFlags() & wxPROP_OBJECT_GRAPH) ) { - WriteOneProperty( obj, prop->GetDeclaringClass(), prop, persister, data ); + WriteOneProperty( obj, prop->GetDeclaringClass(), prop, writercallback, data ); } } } } +class WXDLLIMPEXP_BASE wxObjectPropertyWriter: public wxObjectWriterFunctor +{ +public: + wxObjectPropertyWriter(const wxClassTypeInfo* cti, + wxObjectWriterCallback *writercallback, + wxObjectWriter* writer, + wxStringToAnyHashMap &props) : + m_cti(cti),m_persister(writercallback),m_writer(writer),m_props(props) + {} + + virtual void operator()(const wxObject *vobj) + { + m_writer->WriteObject( vobj, (vobj ? vobj->GetClassInfo() : m_cti->GetClassInfo() ), + m_persister, m_cti->GetKind()== wxT_OBJECT, m_props ); + } +private: + const wxClassTypeInfo* m_cti; + wxObjectWriterCallback *m_persister; + wxObjectWriter* m_writer; + wxStringToAnyHashMap& m_props; +}; + void wxObjectWriter::WriteOneProperty( const wxObject *obj, const wxClassInfo* ci, - const wxPropertyInfo* pi, wxObjectReaderCallback *persister, + const wxPropertyInfo* pi, wxObjectWriterCallback *writercallback, wxObjectWriterInternalPropertiesData *WXUNUSED(data) ) { if ( pi->GetFlags() & wxPROP_DONT_STREAM ) @@ -210,39 +230,39 @@ void wxObjectWriter::WriteOneProperty( const wxObject *obj, const wxClassInfo* c if ( pi->GetTypeInfo()->GetKind() == wxT_COLLECTION ) { - wxVariantBaseArray data; + wxAnyList data; pi->GetAccessor()->GetPropertyCollection(obj, data); const wxTypeInfo * elementType = wx_dynamic_cast( const wxCollectionTypeInfo*, pi->GetTypeInfo() )->GetElementType(); - for ( size_t i = 0; i < data.GetCount(); ++i ) + if ( !data.empty() ) { - if ( i == 0 ) - DoBeginWriteProperty( pi ); - - DoBeginWriteElement(); - wxVariantBase value = data[i]; - if ( persister->BeforeWriteProperty( this, obj, pi, value ) ) + DoBeginWriteProperty( pi ); + for ( wxAnyList::const_iterator iter = data.begin(); iter != data.end(); ++iter ) { - const wxClassTypeInfo* cti = - wx_dynamic_cast( const wxClassTypeInfo*, elementType ); - if ( cti ) - { - const wxClassInfo* pci = cti->GetClassInfo(); - wxObject *vobj = pci->VariantToInstance( value ); - wxVariantBaseArray md; - WriteObject( vobj, (vobj ? vobj->GetClassInfo() : pci ), - persister, cti->GetKind()== wxT_OBJECT, md ); - } - else + DoBeginWriteElement(); + const wxAny* valptr = *iter; + if ( writercallback->BeforeWriteProperty( this, obj, pi, *valptr ) ) { - DoWriteSimpleType( value ); + const wxClassTypeInfo* cti = + wx_dynamic_cast( const wxClassTypeInfo*, elementType ); + if ( cti ) + { + wxStringToAnyHashMap md; + wxObjectPropertyWriter pw(cti,writercallback,this, md); + + const wxClassInfo* pci = cti->GetClassInfo(); + pci->CallOnAny( *valptr, &pw); + } + else + { + DoWriteSimpleType( *valptr ); + } } + DoEndWriteElement(); } - DoEndWriteElement(); - if ( i == data.GetCount() - 1 ) - DoEndWriteProperty( pi ); - } - } + DoEndWriteProperty( pi ); + } + } else { const wxEventSourceTypeInfo* dti = @@ -256,7 +276,7 @@ void wxObjectWriter::WriteOneProperty( const wxObject *obj, const wxClassInfo* c if ( evSource ) { FindConnectEntry( evSource, dti, sink, handler ); - if ( persister->BeforeWriteDelegate( this, obj, ci, pi, sink, handler ) ) + if ( writercallback->BeforeWriteDelegate( this, obj, ci, pi, sink, handler ) ) { if ( sink != NULL && handler != NULL ) { @@ -282,11 +302,12 @@ void wxObjectWriter::WriteOneProperty( const wxObject *obj, const wxClassInfo* c } else { - wxVariantBase value; + wxAny value; pi->GetAccessor()->GetProperty(obj, value); // avoid streaming out void objects - if( value.IsEmpty() ) + // TODO Verify + if( value.IsNull() ) return; if ( pi->GetFlags() & wxPROP_ENUM_STORE_LONG ) @@ -295,7 +316,7 @@ void wxObjectWriter::WriteOneProperty( const wxObject *obj, const wxClassInfo* c wx_dynamic_cast(const wxEnumTypeInfo*, pi->GetTypeInfo() ); if ( eti ) { - eti->ConvertFromLong( value.wxTEMPLATED_MEMBER_CALL(Get, long), value ); + eti->ConvertFromLong( wxANY_AS(value, long ), value ); } else { @@ -305,9 +326,9 @@ void wxObjectWriter::WriteOneProperty( const wxObject *obj, const wxClassInfo* c // avoid streaming out default values if ( pi->GetTypeInfo()->HasStringConverters() && - !pi->GetDefaultValue().IsEmpty() ) + !pi->GetDefaultValue().IsNull() ) // TODO Verify { - if ( value.GetAsString() == pi->GetDefaultValue().GetAsString() ) + if ( wxAnyGetAsString(value) == wxAnyGetAsString(pi->GetDefaultValue()) ) return; } @@ -315,28 +336,28 @@ void wxObjectWriter::WriteOneProperty( const wxObject *obj, const wxClassInfo* c const wxClassTypeInfo* cti = wx_dynamic_cast( const wxClassTypeInfo* , pi->GetTypeInfo() ); - if ( cti && value.GetAsObject() == NULL ) + if ( cti && cti->GetKind() == wxT_OBJECT_PTR && wxAnyGetAsObjectPtr(value) == NULL ) return; - if ( persister->BeforeWriteProperty( this, obj, pi, value ) ) + if ( writercallback->BeforeWriteProperty( this, obj, pi, value ) ) { DoBeginWriteProperty( pi ); if ( cti ) { - const wxClassInfo* pci = cti->GetClassInfo(); - wxObject *vobj = pci->VariantToInstance( value ); - if ( vobj && pi->GetTypeInfo()->HasStringConverters() ) + if ( cti->HasStringConverters() ) { wxString stringValue; cti->ConvertToString( value, stringValue ); - wxVariantBase convertedValue(stringValue); + wxAny convertedValue(stringValue); DoWriteSimpleType( convertedValue ); } else { - wxVariantBaseArray md; - WriteObject( vobj, (vobj ? vobj->GetClassInfo() : pci ), - persister, cti->GetKind()== wxT_OBJECT, md); + wxStringToAnyHashMap md; + wxObjectPropertyWriter pw(cti,writercallback,this, md); + + const wxClassInfo* pci = cti->GetClassInfo(); + pci->CallOnAny(value, &pw); } } else @@ -476,7 +497,7 @@ wxObjectRuntimeReaderCallback::~wxObjectRuntimeReaderCallback() } void wxObjectRuntimeReaderCallback::AllocateObject(int objectID, wxClassInfo *classInfo, - wxVariantBaseArray &WXUNUSED(metadata)) + wxStringToAnyHashMap &WXUNUSED(metadata)) { wxObject *O; O = classInfo->CreateObject(); @@ -486,10 +507,10 @@ void wxObjectRuntimeReaderCallback::AllocateObject(int objectID, wxClassInfo *cl void wxObjectRuntimeReaderCallback::CreateObject(int objectID, const wxClassInfo *classInfo, int paramCount, - wxVariantBase *params, + wxAny *params, int *objectIdValues, const wxClassInfo **objectClassInfos, - wxVariantBaseArray &WXUNUSED(metadata)) + wxStringToAnyHashMap &WXUNUSED(metadata)) { wxObject *o; o = m_data->GetObject(objectID); @@ -506,7 +527,7 @@ void wxObjectRuntimeReaderCallback::CreateObject(int objectID, { o = dyno->GetSuperClassInstance(); } - params[i] = objectClassInfos[i]->InstanceToVariant(o); + params[i] = objectClassInfos[i]->ObjectPtrToAny(o); } } classInfo->Create(o, paramCount, params); @@ -515,10 +536,10 @@ void wxObjectRuntimeReaderCallback::CreateObject(int objectID, void wxObjectRuntimeReaderCallback::ConstructObject(int objectID, const wxClassInfo *classInfo, int paramCount, - wxVariantBase *params, + wxAny *params, int *objectIdValues, const wxClassInfo **objectClassInfos, - wxVariantBaseArray &WXUNUSED(metadata)) + wxStringToAnyHashMap &WXUNUSED(metadata)) { wxObject *o; for ( int i = 0; i < paramCount; ++i ) @@ -534,7 +555,7 @@ void wxObjectRuntimeReaderCallback::ConstructObject(int objectID, { o = dyno->GetSuperClassInstance(); } - params[i] = objectClassInfos[i]->InstanceToVariant(o); + params[i] = objectClassInfos[i]->ObjectPtrToAny(o); } } o = classInfo->ConstructObject(paramCount, params); @@ -552,7 +573,7 @@ void wxObjectRuntimeReaderCallback::DestroyObject(int objectID, wxClassInfo *WXU void wxObjectRuntimeReaderCallback::SetProperty(int objectID, const wxClassInfo *classInfo, const wxPropertyInfo* propertyInfo, - const wxVariantBase &value) + const wxAny &value) { wxObject *o; o = m_data->GetObject(objectID); @@ -579,7 +600,7 @@ void wxObjectRuntimeReaderCallback::SetPropertyAsObject(int objectID, } classInfo->SetProperty( o, propertyInfo->GetName(), - valClassInfo->InstanceToVariant(valo) ); + valClassInfo->ObjectPtrToAny(valo) ); } void wxObjectRuntimeReaderCallback::SetConnect(int eventSourceObjectID, @@ -625,7 +646,7 @@ wxObject *wxObjectRuntimeReaderCallback::GetObject(int objectID) void wxObjectRuntimeReaderCallback::AddToPropertyCollection( int objectID, const wxClassInfo *classInfo, const wxPropertyInfo* propertyInfo, - const wxVariantBase &value) + const wxAny &value) { wxObject *o; o = m_data->GetObject(objectID); @@ -654,12 +675,7 @@ void wxObjectRuntimeReaderCallback::AddToPropertyCollectionAsObject(int objectID } classInfo->AddToPropertyCollection( o, propertyInfo->GetName(), - valClassInfo->InstanceToVariant(valo) ); + valClassInfo->ObjectPtrToAny(valo) ); } -#if TEST_XVARIANT -#include "wx/arrimpl.cpp" -WX_DEFINE_OBJARRAY(wxVariantBaseArray); -#endif - #endif // wxUSE_EXTENDED_RTTI diff --git a/src/common/xtixml.cpp b/src/common/xtixml.cpp index c0c6e3b5be..f6f2da545f 100644 --- a/src/common/xtixml.cpp +++ b/src/common/xtixml.cpp @@ -13,12 +13,12 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ - #pragma hdrstop +#pragma hdrstop #endif #if wxUSE_EXTENDED_RTTI -#include "wx/xtixml.h" +#include "wx/xtistrm.h" #ifndef WX_PRECOMP #include "wx/object.h" @@ -30,6 +30,7 @@ #include "wx/tokenzr.h" #include "wx/txtstrm.h" #include "wx/xtistrm.h" +#include "wx/xtixml.h" // STL headers @@ -110,17 +111,19 @@ void wxObjectXmlWriter::DoEndWriteTopLevelEntry( const wxString &WXUNUSED(name) void wxObjectXmlWriter::DoBeginWriteObject(const wxObject *WXUNUSED(object), const wxClassInfo *classInfo, - int objectID, wxVariantBaseArray &metadata ) + int objectID, const wxStringToAnyHashMap &metadata ) { wxXmlNode *pnode; pnode = new wxXmlNode(wxXML_ELEMENT_NODE, wxT("object")); pnode->AddProperty(wxT("class"), wxString(classInfo->GetClassName())); pnode->AddProperty(wxT("id"), wxString::Format( wxT("%d"), objectID ) ); - for ( size_t i = 0; i < metadata.GetCount(); ++i ) + wxStringToAnyHashMap::const_iterator it, en; + for( it = metadata.begin(), en = metadata.end(); it != en; ++it ) { - pnode->AddProperty( metadata[i].GetName(), metadata[i].GetAsString() ); + pnode->AddProperty( it->first, wxAnyGetAsString(it->second) ); } + m_data->m_current->AddChild(pnode); m_data->Push( pnode ); } @@ -132,9 +135,9 @@ void wxObjectXmlWriter::DoEndWriteObject(const wxObject *WXUNUSED(object), m_data->Pop(); } -void wxObjectXmlWriter::DoWriteSimpleType( wxVariantBase &value ) +void wxObjectXmlWriter::DoWriteSimpleType( const wxAny &value ) { - wxXmlAddContentToNode( m_data->m_current,value.GetAsString() ); + wxXmlAddContentToNode( m_data->m_current,wxAnyGetAsString(value) ); } void wxObjectXmlWriter::DoBeginWriteElement() @@ -204,13 +207,13 @@ as properties are always sought by typeinfo over all levels and create params are always toplevel class only */ -int wxObjectXmlReader::ReadComponent(wxXmlNode *node, wxObjectWriterCallback *callbacks) +int wxObjectXmlReader::ReadComponent(wxXmlNode *node, wxObjectReaderCallback *callbacks) { wxASSERT_MSG( callbacks, wxT("Does not support reading without a Depersistor") ); wxString className; wxClassInfo *classInfo; - wxVariantBase *createParams; + wxAny *createParams; int *createParamOids; const wxClassInfo** createClassInfos; wxXmlNode *children; @@ -221,7 +224,7 @@ int wxObjectXmlReader::ReadComponent(wxXmlNode *node, wxObjectWriterCallback *ca if (!children) { // check for a null object or href - if (node->GetPropVal(wxT("href"), &ObjectIdString ) ) + if (node->GetAttribute(wxT("href"), &ObjectIdString ) ) { objectID = atoi( ObjectIdString.ToAscii() ); if ( HasObjectClassInfo( objectID ) ) @@ -234,12 +237,12 @@ int wxObjectXmlReader::ReadComponent(wxXmlNode *node, wxObjectWriterCallback *ca return wxInvalidObjectID; } } - if ( !node->GetPropVal(wxT("id"), &ObjectIdString ) ) + if ( !node->GetAttribute(wxT("id"), &ObjectIdString ) ) { return wxNullObjectID; } } - if (!node->GetPropVal(wxT("class"), &className)) + if (!node->GetAttribute(wxT("class"), &className)) { // No class name. Eek. FIXME: error handling return wxInvalidObjectID; @@ -257,7 +260,7 @@ int wxObjectXmlReader::ReadComponent(wxXmlNode *node, wxObjectWriterCallback *ca wxLogError(_("objects cannot have XML Text Nodes") ); return wxInvalidObjectID; } - if (!node->GetPropVal(wxT("id"), &ObjectIdString)) + if (!node->GetAttribute(wxT("id"), &ObjectIdString)) { wxLogError(_("Objects must have an id attribute") ); // No object id. Eek. FIXME: error handling @@ -276,14 +279,14 @@ int wxObjectXmlReader::ReadComponent(wxXmlNode *node, wxObjectWriterCallback *ca // first make the object know to our internal registry SetObjectClassInfo( objectID, classInfo ); - wxVariantBaseArray metadata; - wxXmlProperty *xp = node->GetProperties(); + wxStringToAnyHashMap metadata; + wxXmlProperty *xp = node->GetAttributes(); while ( xp ) { if ( xp->GetName() != wxString(wxT("class")) && xp->GetName() != wxString(wxT("id")) ) { - metadata.Add( new wxVariantBase( xp->GetValue(), xp->GetName() ) ); + metadata[xp->GetName()] = wxAny( xp->GetValue() ); } xp = xp->GetNext(); } @@ -292,7 +295,7 @@ int wxObjectXmlReader::ReadComponent(wxXmlNode *node, wxObjectWriterCallback *ca // // stream back the Create parameters first - createParams = new wxVariantBase[ classInfo->GetCreateParamCount() ]; + createParams = new wxAny[ classInfo->GetCreateParamCount() ]; createParamOids = new int[classInfo->GetCreateParamCount() ]; createClassInfos = new const wxClassInfo*[classInfo->GetCreateParamCount() ]; @@ -309,7 +312,7 @@ int wxObjectXmlReader::ReadComponent(wxXmlNode *node, wxObjectWriterCallback *ca while( children ) { wxString name; - children->GetPropVal( wxT("name"), &name ); + children->GetAttribute( wxT("name"), &name ); propertyNames.push_back( (const wxChar*)name.c_str() ); propertyNodes[(const wxChar*)name.c_str()] = children->GetChildren(); children = children->GetNext(); @@ -347,7 +350,7 @@ int wxObjectXmlReader::ReadComponent(wxXmlNode *node, wxObjectWriterCallback *ca { long realval; eti->ConvertToLong( createParams[i], realval ); - createParams[i] = wxVariantBase( realval ); + createParams[i] = wxAny( realval ); } else { @@ -435,7 +438,7 @@ int wxObjectXmlReader::ReadComponent(wxXmlNode *node, wxObjectWriterCallback *ca } else { - wxVariantBase elementValue = ReadValue( elementContent, elementType ); + wxAny elementValue = ReadValue( elementContent, elementType ); if ( pi->GetAccessor()->HasAdder() ) callbacks->AddToPropertyCollection( objectID, classInfo,pi, elementValue ); } @@ -462,7 +465,7 @@ int wxObjectXmlReader::ReadComponent(wxXmlNode *node, wxObjectWriterCallback *ca else { wxASSERT( pi->GetTypeInfo()->HasStringConverters() ); - wxVariantBase nodeval = ReadValue( prop, pi->GetTypeInfo() ); + wxAny nodeval = ReadValue( prop, pi->GetTypeInfo() ); callbacks->SetProperty( objectID, classInfo,pi, nodeval ); } } @@ -491,7 +494,7 @@ int wxObjectXmlReader::ReadComponent(wxXmlNode *node, wxObjectWriterCallback *ca } else { - wxVariantBase nodeval = ReadValue( prop, pi->GetTypeInfo() ); + wxAny nodeval = ReadValue( prop, pi->GetTypeInfo() ); if( pi->GetFlags() & wxPROP_ENUM_STORE_LONG ) { const wxEnumTypeInfo *eti = @@ -500,7 +503,7 @@ int wxObjectXmlReader::ReadComponent(wxXmlNode *node, wxObjectWriterCallback *ca { long realval; eti->ConvertToLong( nodeval, realval ); - nodeval = wxVariantBase( realval ); + nodeval = wxAny( realval ); } else { @@ -520,24 +523,24 @@ int wxObjectXmlReader::ReadComponent(wxXmlNode *node, wxObjectWriterCallback *ca return objectID; } -wxVariantBase wxObjectXmlReader::ReadValue(wxXmlNode *node, +wxAny wxObjectXmlReader::ReadValue(wxXmlNode *node, const wxTypeInfo *type ) { wxString content; if ( node ) content = node->GetContent(); - wxVariantBase result; + wxAny result; type->ConvertFromString( content, result ); return result; } -int wxObjectXmlReader::ReadObject( const wxString &name, wxObjectWriterCallback *callbacks) +int wxObjectXmlReader::ReadObject( const wxString &name, wxObjectReaderCallback *callbacks) { wxXmlNode *iter = m_parent->GetChildren(); while ( iter ) { wxString entryName; - if ( iter->GetPropVal(wxT("name"), &entryName) ) + if ( iter->GetAttribute(wxT("name"), &entryName) ) { if ( entryName == name ) return ReadComponent( iter->GetChildren(), callbacks ); -- 2.45.2