Kaydet (Commit) 8015cd21 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

tdf#118026: Use ooo::vba::XCollection instead of css::container::XEnumeration

An object returned by XCollection::Item() is of the right "VBA" kind
that we want. One returned by XEnumeration::nextElement() is not.

Change-Id: I26132a7d0f2638a61f2711b941386a889fabea72
Reviewed-on: https://gerrit.libreoffice.org/55392Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTor Lillqvist <tml@collabora.com>
üst 13328a36
...@@ -71,6 +71,7 @@ ...@@ -71,6 +71,7 @@
#include <com/sun/star/script/XInvocation2.hpp> #include <com/sun/star/script/XInvocation2.hpp>
#include <com/sun/star/script/MemberType.hpp> #include <com/sun/star/script/MemberType.hpp>
#include <com/sun/star/reflection/XIdlReflection.hpp> #include <com/sun/star/reflection/XIdlReflection.hpp>
#include <ooo/vba/XCollection.hpp>
#include <ooo/vba/XConnectable.hpp> #include <ooo/vba/XConnectable.hpp>
#include <ooo/vba/XConnectionPoint.hpp> #include <ooo/vba/XConnectionPoint.hpp>
#include <ooo/vba/XSink.hpp> #include <ooo/vba/XSink.hpp>
...@@ -1150,6 +1151,7 @@ STDMETHODIMP InterfaceOleWrapper::GetIDsOfNames(REFIID /*riid*/, ...@@ -1150,6 +1151,7 @@ STDMETHODIMP InterfaceOleWrapper::GetIDsOfNames(REFIID /*riid*/,
if (iter == m_nameToDispIdMap.end()) if (iter == m_nameToDispIdMap.end())
{ {
ret = DISP_E_UNKNOWNNAME; ret = DISP_E_UNKNOWNNAME;
SAL_INFO("extensions.olebridge", " " << name << ": UNKNOWN");
} }
else else
{ {
...@@ -1995,6 +1997,7 @@ class CXEnumVariant : public IEnumVARIANT, ...@@ -1995,6 +1997,7 @@ class CXEnumVariant : public IEnumVARIANT,
{ {
public: public:
CXEnumVariant() CXEnumVariant()
: mnIndex(1) // ooo::vba::XCollection index starts at one
{ {
} }
...@@ -2025,10 +2028,10 @@ public: ...@@ -2025,10 +2028,10 @@ public:
// Creates and initializes the enumerator // Creates and initializes the enumerator
void Init(InterfaceOleWrapper* pInterfaceOleWrapper, void Init(InterfaceOleWrapper* pInterfaceOleWrapper,
const Reference< XEnumeration > xEnumeration) const Reference<ooo::vba::XCollection > xCollection)
{ {
mpInterfaceOleWrapper = pInterfaceOleWrapper; mpInterfaceOleWrapper = pInterfaceOleWrapper;
mxEnumeration = xEnumeration; mxCollection = xCollection;
} }
// IEnumVARIANT // IEnumVARIANT
...@@ -2057,14 +2060,18 @@ public: ...@@ -2057,14 +2060,18 @@ public:
while (celt > 0) while (celt > 0)
{ {
if (!mxEnumeration->hasMoreElements()) if (mnIndex >= mxCollection->getCount())
return S_FALSE; return S_FALSE;
Any aElement = mxEnumeration->nextElement();
Any aIndex;
aIndex <<= mnIndex;
Any aElement = mxCollection->Item(aIndex, Any());
mpInterfaceOleWrapper->anyToVariant(rgVar, aElement); mpInterfaceOleWrapper->anyToVariant(rgVar, aElement);
// rgVar->pdispVal->AddRef(); ?? // rgVar->pdispVal->AddRef(); ??
if (pCeltFetched) if (pCeltFetched)
(*pCeltFetched)++; (*pCeltFetched)++;
rgVar++; rgVar++;
mnIndex++;
celt--; celt--;
} }
return S_OK; return S_OK;
...@@ -2072,7 +2079,8 @@ public: ...@@ -2072,7 +2079,8 @@ public:
virtual HRESULT STDMETHODCALLTYPE Reset() override virtual HRESULT STDMETHODCALLTYPE Reset() override
{ {
return E_NOTIMPL; mnIndex = 1;
return S_OK;
} }
virtual HRESULT STDMETHODCALLTYPE STDMETHODCALLTYPE Skip(ULONG celt) override virtual HRESULT STDMETHODCALLTYPE STDMETHODCALLTYPE Skip(ULONG celt) override
...@@ -2081,9 +2089,9 @@ public: ...@@ -2081,9 +2089,9 @@ public:
while (celt > 0) while (celt > 0)
{ {
if (!mxEnumeration->hasMoreElements()) if (mnIndex >= mxCollection->getCount())
return S_FALSE; return S_FALSE;
mxEnumeration->nextElement(); mnIndex++;
celt--; celt--;
} }
return S_OK; return S_OK;
...@@ -2091,7 +2099,8 @@ public: ...@@ -2091,7 +2099,8 @@ public:
private: private:
InterfaceOleWrapper* mpInterfaceOleWrapper; InterfaceOleWrapper* mpInterfaceOleWrapper;
Reference<XEnumeration> mxEnumeration; Reference<ooo::vba::XCollection> mxCollection;
sal_Int32 mnIndex;
}; };
class Sink : public cppu::WeakImplHelper<ooo::vba::XSink> class Sink : public cppu::WeakImplHelper<ooo::vba::XSink>
...@@ -2663,12 +2672,10 @@ HRESULT InterfaceOleWrapper::InvokeGeneral( DISPID dispidMember, unsigned short ...@@ -2663,12 +2672,10 @@ HRESULT InterfaceOleWrapper::InvokeGeneral( DISPID dispidMember, unsigned short
if( !pvarResult) if( !pvarResult)
return E_POINTER; return E_POINTER;
Reference< XEnumerationAccess > xEnumerationAccess(m_xOrigin, UNO_QUERY_THROW); Reference< ooo::vba::XCollection> xCollection(m_xOrigin, UNO_QUERY);
if (!xEnumerationAccess.is()) if (!xCollection.is())
return DISP_E_MEMBERNOTFOUND; return DISP_E_MEMBERNOTFOUND;
Reference< XEnumeration > xEnumeration = xEnumerationAccess->createEnumeration();
CComObject<CXEnumVariant>* pEnumVar; CComObject<CXEnumVariant>* pEnumVar;
ret = CComObject<CXEnumVariant>::CreateInstance(&pEnumVar); ret = CComObject<CXEnumVariant>::CreateInstance(&pEnumVar);
...@@ -2677,7 +2684,7 @@ HRESULT InterfaceOleWrapper::InvokeGeneral( DISPID dispidMember, unsigned short ...@@ -2677,7 +2684,7 @@ HRESULT InterfaceOleWrapper::InvokeGeneral( DISPID dispidMember, unsigned short
pEnumVar->AddRef(); pEnumVar->AddRef();
pEnumVar->Init(this, xEnumeration); pEnumVar->Init(this, xCollection);
pvarResult->vt = VT_UNKNOWN; pvarResult->vt = VT_UNKNOWN;
pvarResult->punkVal = nullptr; pvarResult->punkVal = nullptr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment