+ bool ok = true;
+ if ( oleVariant.vt & VT_ARRAY )
+ {
+ // TODO: We currently return arrays as wxVariant of the list type
+ // containing the flattened form of array but we should allow
+ // getting it as wxVariantDataSafeArray instead. Doing this is
+ // simple, we'd just need to do something like this:
+ //
+ // if ( oleVariant.parray && SafeArrayGetDim(oleVariant.parray) > 1 )
+ // {
+ // variant.SetData(new wxVariantDataSafeArray(oleVariant.parray));
+ // }
+ //
+ // but currently we don't do it for compatibility reasons.
+ switch (oleVariant.vt & VT_TYPEMASK)
+ {
+ case VT_I2:
+ ok = wxSafeArray<VT_I2>::ConvertToVariant(oleVariant.parray, variant);
+ break;
+ case VT_I4:
+ ok = wxSafeArray<VT_I4>::ConvertToVariant(oleVariant.parray, variant);
+ break;
+ case VT_R4:
+ ok = wxSafeArray<VT_R4>::ConvertToVariant(oleVariant.parray, variant);
+ break;
+ case VT_R8:
+ ok = wxSafeArray<VT_R8>::ConvertToVariant(oleVariant.parray, variant);
+ break;
+ case VT_VARIANT:
+ ok = wxSafeArray<VT_VARIANT>::ConvertToVariant(oleVariant.parray, variant);
+ break;
+ case VT_BSTR:
+ {
+ wxArrayString strings;
+ if ( wxSafeArray<VT_BSTR>::ConvertToArrayString(oleVariant.parray, strings) )
+ variant = strings;
+ else
+ ok = false;
+ }
+ break;
+ default:
+ ok = false;
+ break;
+ }
+ if ( !ok )
+ {
+ wxLogDebug(wxT("unhandled VT_ARRAY type %x in wxConvertOleToVariant"),
+ oleVariant.vt & VT_TYPEMASK);
+ variant = wxVariant();
+ }
+ }
+ else if ( oleVariant.vt & VT_BYREF )
+ {
+ switch ( oleVariant.vt & VT_TYPEMASK )
+ {
+ case VT_VARIANT:
+ {
+ VARIANTARG& oleReference = *((LPVARIANT)oleVariant.byref);
+ if (!wxConvertOleToVariant(oleReference,variant))
+ return false;
+ break;
+ }
+
+ default:
+ wxLogError(wxT("wxAutomationObject::ConvertOleToVariant: [as yet] unhandled reference %X"),
+ oleVariant.vt);
+ return false;
+ }
+ }
+ else // simply type (not array or reference)
+ {
+ switch ( oleVariant.vt & VT_TYPEMASK )
+ {
+ case VT_ERROR:
+ variant.SetData(new wxVariantDataErrorCode(oleVariant.scode));
+ break;
+
+ case VT_CY:
+ variant.SetData(new wxVariantDataCurrency(oleVariant.cyVal));
+ break;
+
+ case VT_BSTR:
+ {
+ wxString str(wxConvertStringFromOle(oleVariant.bstrVal));
+ variant = str;
+ }
+ break;
+
+ case VT_DATE:
+#if wxUSE_DATETIME
+ {
+ SYSTEMTIME st;
+ VariantTimeToSystemTime(oleVariant.date, &st);
+
+ wxDateTime date;
+ date.SetFromMSWSysTime(st);
+ variant = date;
+ }
+#endif // wxUSE_DATETIME
+ break;
+
+ // See the comment before the __VISUALC6__ test above.
+#if wxUSE_LONGLONG && !defined(__VISUALC6__)
+ case VT_I8:
+ variant = wxLongLong(oleVariant.llVal);
+ break;
+#endif // wxUSE_LONGLONG
+
+ case VT_I4:
+ variant = (long) oleVariant.lVal;
+ break;
+
+ case VT_I2:
+ variant = (long) oleVariant.iVal;
+ break;
+
+ case VT_BOOL:
+ variant = oleVariant.boolVal != 0;
+ break;
+
+ case VT_R4:
+ variant = oleVariant.fltVal;
+ break;
+
+ case VT_R8:
+ variant = oleVariant.dblVal;
+ break;
+
+ case VT_DISPATCH:
+ variant = (void*) oleVariant.pdispVal;
+ break;
+
+ case VT_NULL:
+ variant.MakeNull();
+ break;
+
+ case VT_EMPTY:
+ break; // Ignore Empty Variant, used only during destruction of objects
+
+ default:
+ wxLogError(wxT("wxAutomationObject::ConvertOleToVariant: Unknown variant value type %X -> %X"),
+ oleVariant.vt,oleVariant.vt&VT_TYPEMASK);
+ return false;
+ }
+ }
+
+ return ok;