]> git.saurik.com Git - wxWidgets.git/commitdiff
Add support for CURRENCY and SCODE to MSW OLE helpers.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 14 Jul 2012 20:10:58 +0000 (20:10 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 14 Jul 2012 20:10:58 +0000 (20:10 +0000)
This allows to call OLE Automation methods taking parameters or returning
values of these types.

Closes #14225.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72081 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/msw/ole/oleutils.h
src/msw/ole/oleutils.cpp

index 8d1c48a56db594e8d09750e7b993b1486c20b022..003df61d6dda198c7412a610c4d79f3b26668642 100644 (file)
@@ -525,6 +525,7 @@ Major new features in this release
 
 
 2.9.5: (released ????-??-??)
+----------------------------
 
 All (GUI):
 
@@ -535,6 +536,10 @@ wxGTK:
 
 - Allow building wxGTK3 with Broadway backend (Kolya Kosenko).
 
+wxMSW:
+
+- Add support for CURRENCY and SCODE types to OLE Automation helpers (PB).
+
 
 2.9.4: (released 2012-07-09)
 ------
index 973bbb9982172b0683dca9368b317607fefaff36..257025d7fbf4d4053af6b95ad7c47b4559e7fefc 100644 (file)
@@ -237,6 +237,58 @@ private:
 // Convert variants
 class WXDLLIMPEXP_FWD_BASE wxVariant;
 
+// wrapper for CURRENCY type used in VARIANT (VARIANT.vt == VT_CY)
+class WXDLLIMPEXP_CORE wxVariantDataCurrency : public wxVariantData
+{
+public:
+    wxVariantDataCurrency() { VarCyFromR8(0.0, &m_value); }
+    wxVariantDataCurrency(CURRENCY value) { m_value = value; }
+
+    CURRENCY GetValue() const { return m_value; }
+    void SetValue(CURRENCY value) { m_value = value; }
+
+    virtual bool Eq(wxVariantData& data) const;
+
+#if wxUSE_STD_IOSTREAM
+    virtual bool Write(wxSTD ostream& str) const;
+#endif
+    virtual bool Write(wxString& str) const;
+
+    wxVariantData* Clone() const { return new wxVariantDataCurrency(m_value); }
+    virtual wxString GetType() const { return wxS("currency"); }
+
+    DECLARE_WXANY_CONVERSION()
+
+private:
+    CURRENCY m_value;
+};
+
+
+// wrapper for SCODE type used in VARIANT (VARIANT.vt == VT_ERROR)
+class WXDLLIMPEXP_CORE wxVariantDataErrorCode : public wxVariantData
+{
+public:
+    wxVariantDataErrorCode(SCODE value = S_OK) { m_value = value; }
+
+    SCODE GetValue() const { return m_value; }
+    void SetValue(SCODE value) { m_value = value; }
+
+    virtual bool Eq(wxVariantData& data) const;
+
+#if wxUSE_STD_IOSTREAM
+    virtual bool Write(wxSTD ostream& str) const;
+#endif
+    virtual bool Write(wxString& str) const;
+
+    wxVariantData* Clone() const { return new wxVariantDataErrorCode(m_value); }
+    virtual wxString GetType() const { return wxS("errorcode"); }
+
+    DECLARE_WXANY_CONVERSION()
+
+private:
+    SCODE m_value;
+};
+
 WXDLLIMPEXP_CORE bool wxConvertVariantToOle(const wxVariant& variant, VARIANTARG& oleVariant);
 WXDLLIMPEXP_CORE bool wxConvertOleToVariant(const VARIANTARG& oleVariant, wxVariant& variant);
 #endif // wxUSE_VARIANT
index c5f1f053c93eabea933be0450f17591b1323cd26..f6ec69f5f6004b5a9a9c05d246e547cc7ff65a00 100644 (file)
@@ -221,6 +221,109 @@ void wxSafeArrayHelper::Unlock()
 } // unnamed namespace
 
 
+// ----------------------------------------------------------------------------
+// wxVariantDataCurrency
+// ----------------------------------------------------------------------------
+
+
+#if wxUSE_ANY
+
+bool wxVariantDataCurrency::GetAsAny(wxAny* any) const
+{
+    *any = m_value;
+    return true;
+}
+
+wxVariantData* wxVariantDataCurrency::VariantDataFactory(const wxAny& any)
+{
+    return new wxVariantDataCurrency(wxANY_AS(any, CURRENCY));
+}
+
+REGISTER_WXANY_CONVERSION(CURRENCY, wxVariantDataCurrency)
+
+#endif // wxUSE_ANY
+
+bool wxVariantDataCurrency::Eq(wxVariantData& data) const
+{
+    wxASSERT_MSG( (data.GetType() == wxS("currency")),
+                  "wxVariantDataCurrency::Eq: argument mismatch" );
+
+    wxVariantDataCurrency& otherData = (wxVariantDataCurrency&) data;
+
+    return otherData.m_value.int64 == m_value.int64;
+}
+
+#if wxUSE_STD_IOSTREAM
+bool wxVariantDataCurrency::Write(wxSTD ostream& str) const
+{
+    wxString s;
+    Write(s);
+    str << s;
+    return true;
+}
+#endif
+
+bool wxVariantDataCurrency::Write(wxString& str) const
+{
+    BSTR bStr = NULL;
+    if ( SUCCEEDED(VarBstrFromCy(m_value, LOCALE_USER_DEFAULT, 0, &bStr)) )
+    {
+        str = wxConvertStringFromOle(bStr);
+        SysFreeString(bStr);
+        return true;
+    }
+    return false;
+}
+
+// ----------------------------------------------------------------------------
+// wxVariantDataErrorCode
+// ----------------------------------------------------------------------------
+
+#if wxUSE_ANY
+
+bool wxVariantDataErrorCode::GetAsAny(wxAny* any) const
+{
+    *any = m_value;
+    return true;
+}
+
+wxVariantData* wxVariantDataErrorCode::VariantDataFactory(const wxAny& any)
+{
+    return new wxVariantDataErrorCode(wxANY_AS(any, SCODE));
+}
+
+REGISTER_WXANY_CONVERSION(SCODE, wxVariantDataErrorCode)
+
+#endif // wxUSE_ANY
+
+bool wxVariantDataErrorCode::Eq(wxVariantData& data) const
+{
+    wxASSERT_MSG( (data.GetType() == wxS("errorcode")),
+                  "wxVariantDataErrorCode::Eq: argument mismatch" );
+
+    wxVariantDataErrorCode& otherData = (wxVariantDataErrorCode&) data;
+
+    return otherData.m_value == m_value;
+}
+
+#if wxUSE_STD_IOSTREAM
+bool wxVariantDataErrorCode::Write(wxSTD ostream& str) const
+{
+    wxString s;
+    Write(s);
+    str << s;
+    return true;
+}
+#endif
+
+bool wxVariantDataErrorCode::Write(wxString& str) const
+{
+    str << m_value;
+    return true;
+}
+
+
+
 WXDLLEXPORT bool wxConvertVariantToOle(const wxVariant& variant, VARIANTARG& oleVariant)
 {
     VariantInit(&oleVariant);
@@ -232,8 +335,23 @@ WXDLLEXPORT bool wxConvertVariantToOle(const wxVariant& variant, VARIANTARG& ole
 
     wxString type(variant.GetType());
 
-
-    if (type == wxT("long"))
+    if (type == wxT("errorcode"))
+    {
+        wxVariantDataErrorCode* const
+            ec = wxDynamicCastVariantData(variant.GetData(),
+                                          wxVariantDataErrorCode);
+        oleVariant.vt = VT_ERROR;
+        oleVariant.scode = ec->GetValue();
+    }
+    else if (type == wxT("currency"))
+    {
+        wxVariantDataCurrency* const
+            c = wxDynamicCastVariantData(variant.GetData(),
+                                         wxVariantDataCurrency);
+        oleVariant.vt = VT_CY;
+        oleVariant.cyVal = c->GetValue();
+    }
+    else if (type == wxT("long"))
     {
         oleVariant.vt = VT_I4;
         oleVariant.lVal = variant.GetLong() ;
@@ -420,6 +538,14 @@ wxConvertOleToVariant(const VARIANTARG& oleVariant, wxVariant& variant)
     {
         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));