+
+WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImplVariantData)
+
+void wxPreRegisterAnyToVariant(wxAnyToVariantRegistration* reg)
+{
+ if ( !g_wxAnyValueTypeGlobals )
+ g_wxAnyValueTypeGlobals = new wxAnyValueTypeGlobals();
+ g_wxAnyValueTypeGlobals->PreRegisterAnyToVariant(reg);
+}
+
+bool wxConvertAnyToVariant(const wxAny& any, wxVariant* variant)
+{
+ if ( any.IsNull() )
+ {
+ variant->MakeNull();
+ return true;
+ }
+
+ // (signed) integer is a special case, because there is only one type
+ // in wxAny, and two ("long" and "longlong") in wxVariant. For better
+ // backwards compatibility, convert all values that fit in "long",
+ // and others to "longlong".
+ if ( wxANY_CHECK_TYPE(any, signed int) )
+ {
+#ifdef wxLongLong_t
+ wxLongLong_t ll = 0;
+ if ( any.GetAs(&ll) )
+ {
+ // NB: Do not use LONG_MAX here. Explicitly using 32-bit
+ // integer constraint yields more consistent behavior across
+ // builds.
+ if ( ll > wxINT32_MAX || ll < wxINT32_MIN )
+ *variant = wxLongLong(ll);
+ else
+ *variant = (long) wxLongLong(ll).GetLo();
+ }
+ else
+ {
+ return false;
+ }
+#else
+ long l;
+ if ( any.GetAs(&l) )
+ *variant = l;
+ else
+ return false;
+#endif
+ return true;
+ }
+
+ // Find matching factory function
+ wxVariantDataFactory f =
+ g_wxAnyValueTypeGlobals->FindVariantDataFactory(any.GetType());
+
+ wxVariantData* data = NULL;
+
+ if ( f )
+ {
+ data = f(any);
+ }
+ else
+ {
+ // Check if wxAny wrapped wxVariantData*
+ if ( !any.GetAs(&data) )
+ {
+ // Ok, one last chance: while unlikely, it is possible that the
+ // wxAny actually contains wxVariant.
+ if ( wxANY_CHECK_TYPE(any, wxVariant) )
+ *variant = wxANY_AS(any, wxVariant);
+ return false;
+ }
+
+ // Wrapper's GetValue() does not increase reference
+ // count, se have to do it before the data gets passed
+ // to a new variant.
+ data->IncRef();
+ }
+
+ variant->SetData(data);
+ return true;
+}
+