X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/13830d6ff8c668c85f12721f1fdbc98b6add83a7..77c8efc8c37da6d6a5e2e8022d21d1cd7d76371d:/src/common/xti.cpp diff --git a/src/common/xti.cpp b/src/common/xti.cpp index 419726db5c..ab4796ff3f 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" @@ -115,13 +117,13 @@ const wxChar * wxEnumData::GetEnumMemberNameByIndex( int idx ) const template<> void wxStringReadValue(const wxString &s, bool &data ) { int intdata; - wxSscanf(s, _T("%d"), &intdata ); + wxSscanf(s, wxT("%d"), &intdata ); data = (bool)(intdata != 0); } template<> void wxStringWriteValue(wxString &s, const bool &data ) { - s = wxString::Format(_T("%d"), data ); + s = wxString::Format(wxT("%d"), data ); } // char @@ -129,13 +131,13 @@ template<> void wxStringWriteValue(wxString &s, const bool &data ) template<> void wxStringReadValue(const wxString &s, char &data ) { int intdata; - wxSscanf(s, _T("%d"), &intdata ); + wxSscanf(s, wxT("%d"), &intdata ); data = char(intdata); } template<> void wxStringWriteValue(wxString &s, const char &data ) { - s = wxString::Format(_T("%d"), data ); + s = wxString::Format(wxT("%d"), data ); } // unsigned char @@ -143,85 +145,106 @@ template<> void wxStringWriteValue(wxString &s, const char &data ) template<> void wxStringReadValue(const wxString &s, unsigned char &data ) { int intdata; - wxSscanf(s, _T("%d"), &intdata ); + wxSscanf(s, wxT("%d"), &intdata ); data = (unsigned char)(intdata); } template<> void wxStringWriteValue(wxString &s, const unsigned char &data ) { - s = wxString::Format(_T("%d"), data ); + s = wxString::Format(wxT("%d"), data ); } // int template<> void wxStringReadValue(const wxString &s, int &data ) { - wxSscanf(s, _T("%d"), &data ); + wxSscanf(s, wxT("%d"), &data ); } template<> void wxStringWriteValue(wxString &s, const int &data ) { - s = wxString::Format(_T("%d"), data ); + s = wxString::Format(wxT("%d"), data ); } // unsigned int template<> void wxStringReadValue(const wxString &s, unsigned int &data ) { - wxSscanf(s, _T("%d"), &data ); + wxSscanf(s, wxT("%d"), &data ); } template<> void wxStringWriteValue(wxString &s, const unsigned int &data ) { - s = wxString::Format(_T("%d"), data ); + s = wxString::Format(wxT("%d"), data ); } // long template<> void wxStringReadValue(const wxString &s, long &data ) { - wxSscanf(s, _T("%ld"), &data ); + wxSscanf(s, wxT("%ld"), &data ); } template<> void wxStringWriteValue(wxString &s, const long &data ) { - s = wxString::Format(_T("%ld"), data ); + s = wxString::Format(wxT("%ld"), data ); } // unsigned long template<> void wxStringReadValue(const wxString &s, unsigned long &data ) { - wxSscanf(s, _T("%ld"), &data ); + wxSscanf(s, wxT("%ld"), &data ); } template<> void wxStringWriteValue(wxString &s, const unsigned long &data ) { - s = wxString::Format(_T("%ld"), data ); + s = wxString::Format(wxT("%ld"), data ); +} + +#ifdef wxLongLong_t +template<> void wxStringReadValue(const wxString &s, wxLongLong_t &data ) +{ + wxSscanf(s, wxT("%lld"), &data ); +} + +template<> void wxStringWriteValue(wxString &s, const wxLongLong_t &data ) +{ + s = wxString::Format(wxT("%lld"), data ); +} + +template<> void wxStringReadValue(const wxString &s, wxULongLong_t &data ) +{ + wxSscanf(s, wxT("%lld"), &data ); } +template<> void wxStringWriteValue(wxString &s, const wxULongLong_t &data ) +{ + s = wxString::Format(wxT("%lld"), data ); +} +#endif // float template<> void wxStringReadValue(const wxString &s, float &data ) { - wxSscanf(s, _T("%f"), &data ); + wxSscanf(s, wxT("%f"), &data ); } template<> void wxStringWriteValue(wxString &s, const float &data ) { - s = wxString::Format(_T("%f"), data ); + s = wxString::Format(wxT("%f"), data ); } // double template<> void wxStringReadValue(const wxString &s, double &data ) { - wxSscanf(s, _T("%lf"), &data ); + wxSscanf(s, wxT("%lf"), &data ); } template<> void wxStringWriteValue(wxString &s, const double &data ) { - s = wxString::Format(_T("%lf"), data ); + s = wxString::Format(wxT("%lf"), data ); } // wxString @@ -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); - //wxASSERT_MSG( iter != ms_typeTable->end(), - // wxT("lookup for a non-existent type-info") ); - // FM 3/6/2007 - disabled because otherwise - // wxPropertyInfo::GetCollectionElementTypeInfo - // may easily crash if (iter == ms_typeTable->end()) return NULL; return (wxTypeInfo *)iter->second; } -#if wxUSE_UNICODE -wxClassTypeInfo::wxClassTypeInfo( wxTypeKind kind, wxClassInfo* classInfo, - wxVariant2StringFnc to, - wxString2VariantFnc from, - const char *name) : - wxTypeInfo( kind, to, from, name) -{ - wxASSERT_MSG( kind == wxT_OBJECT_PTR || - kind == wxT_OBJECT, - wxT("Illegal Kind for Enum Type")); m_classInfo = classInfo; -} -#endif - wxClassTypeInfo::wxClassTypeInfo( wxTypeKind kind, wxClassInfo* classInfo, wxVariant2StringFnc to, wxString2VariantFnc from, @@ -366,7 +393,7 @@ void wxTypeInfo::Unregister() ms_typeTable->erase(m_name); } -// removing header dependancy on string tokenizer +// removing header dependency on string tokenizer void wxSetStringToArray( const wxString &s, wxArrayString &array ) { @@ -418,6 +445,7 @@ void wxPropertyInfo::Remove() info = info->m_next; } } + } // ---------------------------------------------------------------------------- @@ -466,7 +494,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 +506,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 +549,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 +579,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 +623,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 +642,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 +696,28 @@ 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); +} + +bool wxClassInfo::NeedsDirectConstruction() const +{ + return wx_dynamic_cast(wxObjectAllocator*, m_constructor) != NULL; +} // ---------------------------------------------------------------------------- // wxDynamicObject support @@ -681,11 +731,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 +757,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 +784,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 +818,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 +840,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 +850,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 +862,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 +927,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 ); + dynobj->SetProperty(m_propertyName.c_str(), 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 ); + value = dynobj->GetProperty( m_propertyName.c_str() ); } +// ---------------------------------------------------------------------------- +// 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