X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0bf14ab8b14d3a999fe1159d2bec33740e066a53..2e14066008229145e2da7b9f05a478ce38631f83:/src/common/variant.cpp diff --git a/src/common/variant.cpp b/src/common/variant.cpp index 81117ab99b..5f7daabe9a 100644 --- a/src/common/variant.cpp +++ b/src/common/variant.cpp @@ -206,6 +206,10 @@ wxAnyToVariantRegistration:: wxPreRegisterAnyToVariant(this); } +wxAnyToVariantRegistration::~wxAnyToVariantRegistration() +{ +} + wxVariant::wxVariant(const wxAny& any) : wxObject() { @@ -224,8 +228,8 @@ wxAny wxVariant::GetAny() const if ( IsNull() ) return wxAny(); - wxVariantData* data = GetData(); wxAny any; + wxVariantData* data = GetData(); if ( data->GetAsAny(&any) ) return any; @@ -266,18 +270,20 @@ public: virtual wxString GetType() const { return wxT("long"); } +#if wxUSE_ANY // Since wxAny does not have separate type for integers shorter than // longlong, we do not usually implement wxVariant->wxAny conversion // here (but in wxVariantDataLongLong instead). -#ifndef wxLongLong_t + #ifndef wxLongLong_t DECLARE_WXANY_CONVERSION() -#else + #else bool GetAsAny(wxAny* any) const { *any = m_value; return true; } -#endif + #endif +#endif // wxUSE_ANY protected: long m_value; @@ -875,6 +881,26 @@ protected: IMPLEMENT_TRIVIAL_WXANY_CONVERSION(wxString, wxVariantDataString) +#if wxUSE_ANY +// This allows converting string literal wxAnys to string variants +wxVariantData* wxVariantDataFromConstCharPAny(const wxAny& any) +{ + return new wxVariantDataString(wxANY_AS(any, const char*)); +} + +wxVariantData* wxVariantDataFromConstWchar_tPAny(const wxAny& any) +{ + return new wxVariantDataString(wxANY_AS(any, const wchar_t*)); +} + +_REGISTER_WXANY_CONVERSION(const char*, + ConstCharP, + wxVariantDataFromConstCharPAny) +_REGISTER_WXANY_CONVERSION(const wchar_t*, + ConstWchar_tP, + wxVariantDataFromConstWchar_tPAny) +#endif + bool wxVariantDataString::Eq(wxVariantData& data) const { wxASSERT_MSG( (data.GetType() == wxT("string")), wxT("wxVariantDataString::Eq: argument mismatch") ); @@ -960,6 +986,20 @@ wxVariant::wxVariant(const wxScopedWCharBuffer& val, const wxString& name) m_name = name; } +#if wxUSE_STD_STRING +wxVariant::wxVariant(const std::string& val, const wxString& name) +{ + m_refData = new wxVariantDataString(wxString(val)); + m_name = name; +} + +wxVariant::wxVariant(const wxStdWideString& val, const wxString& name) +{ + m_refData = new wxVariantDataString(wxString(val)); + m_name = name; +} +#endif // wxUSE_STD_STRING + bool wxVariant::operator== (const wxString& value) const { wxString thisValue; @@ -1937,8 +1977,6 @@ protected: // Convert to/from list of wxAnys // -WX_DEFINE_LIST(wxAnyList) - bool wxVariantDataList::GetAsAny(wxAny* any) const { wxAnyList dst; @@ -1946,7 +1984,7 @@ bool wxVariantDataList::GetAsAny(wxAny* any) const while (node) { wxVariant* pVar = node->GetData(); - dst.push_back(new wxAny(*pVar)); + dst.push_back(new wxAny(((const wxVariant&)*pVar))); node = node->GetNext(); } @@ -2320,6 +2358,15 @@ bool wxVariant::Convert(wxUniChar* value) const *value = (char) (((wxVariantDataLong*)GetData())->GetValue()); else if (type == wxT("bool")) *value = (char) (((wxVariantDataBool*)GetData())->GetValue()); + else if (type == wxS("string")) + { + // Also accept strings of length 1 + const wxString& str = (((wxVariantDataString*)GetData())->GetValue()); + if ( str.length() == 1 ) + *value = str[0]; + else + return false; + } else return false;