[Libreoffice-commits] core.git: extensions/Library_oleautobridge.mk extensions/source

Tor Lillqvist tml at collabora.com
Tue May 29 14:36:11 UTC 2018


 extensions/Library_oleautobridge.mk |    6 +++++-
 extensions/source/ole/servprov.cxx  |   36 +++++++++++++++++++++++++++++-------
 extensions/source/ole/servprov.hxx  |    8 +++++---
 3 files changed, 39 insertions(+), 11 deletions(-)

New commits:
commit 0667df70dc749ae50ce29713308f14d624f2a683
Author: Tor Lillqvist <tml at collabora.com>
Date:   Tue Feb 13 18:41:24 2018 +0200

    Provide also an ooo.vba.word.XApplication object
    
    Create the objects on offer to Automation clients lazily
    
    It would be silly to create the ooo.vba.word.XApplication in every
    LibreOffice instance, even if no Writer functionality was going to be
    used at all in that process.
    
    I did not have to do what the old FIXME said, "make Application a
    proper service", whatever that means.
    
    Change-Id: I02a0ceb6290012b4bb6afacadc03871feaf57406
    Reviewed-on: https://gerrit.libreoffice.org/55005
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tor Lillqvist <tml at collabora.com>

diff --git a/extensions/Library_oleautobridge.mk b/extensions/Library_oleautobridge.mk
index 70b518c50d41..ec59f715c504 100644
--- a/extensions/Library_oleautobridge.mk
+++ b/extensions/Library_oleautobridge.mk
@@ -13,7 +13,11 @@ $(eval $(call gb_Library_Library,oleautobridge))
 
 $(eval $(call gb_Library_set_componentfile,oleautobridge,extensions/source/ole/oleautobridge))
 
-$(eval $(call gb_Library_use_sdk_api,oleautobridge))
+$(eval $(call gb_Library_use_api,oleautobridge,\
+    offapi \
+    oovbaapi \
+    udkapi \
+))
 
 $(eval $(call gb_Library_set_include,oleautobridge,\
 	$(foreach inc,$(ATL_INCLUDE),-I$(inc)) \
diff --git a/extensions/source/ole/servprov.cxx b/extensions/source/ole/servprov.cxx
index 72e5944fb5ba..220ced0bc2fd 100644
--- a/extensions/source/ole/servprov.cxx
+++ b/extensions/source/ole/servprov.cxx
@@ -29,6 +29,7 @@
 #include <cppuhelper/supportsservice.hxx>
 #include <o3tl/any.hxx>
 #include <o3tl/char16_t2wchar_t.hxx>
+#include <ooo/vba/XHelperInterface.hpp>
 
 using namespace cppu;
 using namespace osl;
@@ -43,10 +44,14 @@ using namespace com::sun::star::bridge::ModelDependent;
 // {82154420-0FBF-11d4-8313-005004526AB4}
 DEFINE_GUID(OID_ServiceManager, 0x82154420, 0xfbf, 0x11d4, 0x83, 0x13, 0x0, 0x50, 0x4, 0x52, 0x6a, 0xb4);
 
+// FIXME: This GUID is just the above with the initial part bumped by one. Is that good enough?
+// {82154421-0FBF-11d4-8313-005004526AB4}
+DEFINE_GUID(OID_LibreOfficeWriterApplication, 0x82154421, 0xfbf, 0x11d4, 0x83, 0x13, 0x0, 0x50, 0x4, 0x52, 0x6a, 0xb4);
+
 OneInstanceOleWrapper::OneInstanceOleWrapper(  const Reference<XMultiServiceFactory>& smgr,
-                                               const Reference<XInterface>& xInst )
+                                               std::function<const Reference<XInterface>()> xInstFunction )
     : m_refCount(0)
-    , m_xInst(xInst)
+    , m_xInstFunction(xInstFunction)
     , m_factoryHandle(0)
     , m_smgr(smgr)
 {
@@ -127,9 +132,10 @@ STDMETHODIMP OneInstanceOleWrapper::CreateInstance(IUnknown FAR* punkOuter,
     HRESULT ret = ResultFromScode(E_UNEXPECTED);
     punkOuter = nullptr;
 
-    if (m_xInst.is())
+    const Reference<XInterface>& xInst = m_xInstFunction();
+    if (xInst.is())
     {
-        Any usrAny(&m_xInst, cppu::UnoType<decltype(m_xInst)>::get());
+        Any usrAny(&xInst, cppu::UnoType<decltype(xInst)>::get());
         sal_uInt8 arId[16];
         rtl_getGlobalProcessId( arId);
         Any oleAny = m_bridgeSupplier->createBridge(usrAny,
@@ -456,7 +462,23 @@ OleServer::OleServer( const Reference<XMultiServiceFactory>& smgr):
         a >>= m_bridgeSupplier;
     }
 
-    (void) provideInstance( m_smgr, &OID_ServiceManager );
+    (void) provideInstance( [&]
+                            {
+                                return m_smgr;
+                            },
+                            &OID_ServiceManager );
+
+    (void) provideInstance( [&]
+                            {
+                                const Reference<XInterface> xWordGlobals = m_smgr->createInstance("ooo.vba.word.Globals");
+                                xWordGlobals->acquire();
+                                const Reference<ooo::vba::XHelperInterface> xHelperInterface(xWordGlobals, UNO_QUERY);
+                                Any aApplication = xHelperInterface->Application();
+                                Reference<XInterface> xApplication;
+                                aApplication >>= xApplication;
+                                return xApplication;
+                            },
+                            &OID_LibreOfficeWriterApplication );
 }
 
 OleServer::~OleServer()
@@ -486,9 +508,9 @@ css::uno::Sequence<OUString> OleServer::getSupportedServiceNames()
         "com.sun.star.bridge.oleautomation.ApplicationRegistration"};
 }
 
-bool OleServer::provideInstance(const Reference<XInterface>& xInst, GUID const * guid)
+bool OleServer::provideInstance(std::function<const Reference<XInterface>()> xInstFunction, GUID const * guid)
 {
-    OneInstanceOleWrapper* pWrapper = new OneInstanceOleWrapper( m_smgr, xInst );
+    OneInstanceOleWrapper* pWrapper = new OneInstanceOleWrapper( m_smgr, xInstFunction );
 
     pWrapper->AddRef();
     m_wrapperList.push_back(pWrapper);
diff --git a/extensions/source/ole/servprov.hxx b/extensions/source/ole/servprov.hxx
index d5fd30f889fd..873c5e62146c 100644
--- a/extensions/source/ole/servprov.hxx
+++ b/extensions/source/ole/servprov.hxx
@@ -20,6 +20,8 @@
 #ifndef INCLUDED_EXTENSIONS_SOURCE_OLE_SERVPROV_HXX
 #define INCLUDED_EXTENSIONS_SOURCE_OLE_SERVPROV_HXX
 
+#include <functional>
+
 #include <com/sun/star/lang/XInitialization.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <cppuhelper/implbase.hxx>
@@ -56,7 +58,7 @@ class OneInstanceOleWrapper : public IClassFactory
 public:
 
     OneInstanceOleWrapper( const Reference<XMultiServiceFactory>& smgr,
-                           const Reference<XInterface>& xInst );
+                           std::function<const Reference<XInterface>()> xInstFunction );
     virtual ~OneInstanceOleWrapper();
 
     bool registerClass(GUID const * pGuid);
@@ -73,7 +75,7 @@ public:
 
 protected:
     oslInterlockedCount m_refCount;
-    Reference<XInterface>       m_xInst;
+    std::function<const Reference<XInterface>()> m_xInstFunction;
     DWORD               m_factoryHandle;
     Reference<XBridgeSupplier2> m_bridgeSupplier;
     Reference<XMultiServiceFactory> m_smgr;
@@ -173,7 +175,7 @@ public:
     css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
 
 protected:
-    bool provideInstance(const Reference<XInterface>& xInst, GUID const * guid);
+    bool provideInstance(std::function<const Reference<XInterface>()> xInstFunction, GUID const * guid);
 
     list< OneInstanceOleWrapper* > m_wrapperList;
     Reference< XBridgeSupplier2 >   m_bridgeSupplier;


More information about the Libreoffice-commits mailing list