[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.0' - 2 commits - framework/inc framework/Library_fwl.mk framework/source framework/util

Miklos Vajna vmiklos at collabora.co.uk
Fri May 13 09:32:44 UTC 2016


 framework/Library_fwl.mk                           |    1 
 framework/inc/services.h                           |    1 
 framework/source/dispatch/dispatchdisabler.cxx     |  171 +++++++++++++++++++++
 framework/source/dispatch/interceptionhelper.cxx   |    2 
 framework/source/inc/dispatch/dispatchdisabler.hxx |  117 ++++++++++++++
 framework/source/register/registertemp.cxx         |    6 
 framework/util/fwl.component                       |    3 
 7 files changed, 298 insertions(+), 3 deletions(-)

New commits:
commit 6f857ead2e530c5d570f035a39cdcd3765ad4660
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu May 12 20:32:34 2016 +0200

    framework: register DispatchDisabler service
    
    Change-Id: I72d9f8b00ba8b2e4e5dc70d7fd77e13ccf9d3bcc
    Reviewed-on: https://gerrit.libreoffice.org/24940
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit 1f041bf31e071611a15ffa1559d2f5df05a685f0)

diff --git a/framework/util/fwl.component b/framework/util/fwl.component
index b035083..83e513c 100644
--- a/framework/util/fwl.component
+++ b/framework/util/fwl.component
@@ -70,4 +70,7 @@
   <implementation name="com.sun.star.comp.framework.services.DispatchHelper">
     <service name="com.sun.star.frame.DispatchHelper"/>
   </implementation>
+  <implementation name="com.sun.star.comp.framework.services.DispatchDisabler">
+    <service name="com.sun.star.frame.DispatchDisabler"/>
+  </implementation>
 </component>
commit ef5ee52b19862322624ab216f7226b9b5e8f0966
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Thu Jan 7 19:24:41 2016 +0000

    framework: initial implementation of a dispatch disabler.
    
    This should allow remote, eg. URE dispatchers to trivially disable
    lots of the UI without requiring a large volume of round-trip IPC.
    
    Reviewed-on: https://gerrit.libreoffice.org/24938
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    (cherry picked from commit 02833c03ee856a62d7185829b7c47bc088e086cc)
    
    Conflicts:
    	framework/inc/services.h
    
    Change-Id: Ibd0681ac993196f826b4ed411da5ffedb7f85786

diff --git a/framework/Library_fwl.mk b/framework/Library_fwl.mk
index c5e1ad1..ea325e0 100644
--- a/framework/Library_fwl.mk
+++ b/framework/Library_fwl.mk
@@ -59,6 +59,7 @@ $(eval $(call gb_Library_add_exception_objects,fwl,\
     framework/source/recording/dispatchrecorder \
     framework/source/recording/dispatchrecordersupplier \
     framework/source/register/registertemp \
+    framework/source/dispatch/dispatchdisabler \
     framework/source/services/dispatchhelper \
     framework/source/services/mediatypedetectionhelper \
     framework/source/services/uriabbreviation \
diff --git a/framework/inc/services.h b/framework/inc/services.h
index e7f8573..1f19870 100644
--- a/framework/inc/services.h
+++ b/framework/inc/services.h
@@ -46,6 +46,7 @@ namespace framework{
 #define IMPLEMENTATIONNAME_MAILTODISPATCHER                     DECLARE_ASCII("com.sun.star.comp.framework.MailToDispatcher"        )
 #define IMPLEMENTATIONNAME_SERVICEHANDLER                       DECLARE_ASCII("com.sun.star.comp.framework.ServiceHandler"          )
 #define IMPLEMENTATIONNAME_DISPATCHHELPER                       DECLARE_ASCII("com.sun.star.comp.framework.services.DispatchHelper" )
+#define IMPLEMENTATIONNAME_DISPATCHDISABLER                     DECLARE_ASCII("com.sun.star.comp.framework.services.DispatchDisabler")
 #define IMPLEMENTATIONNAME_MACROSMENUCONTROLLER                 DECLARE_ASCII("com.sun.star.comp.framework.MacrosMenuController"      )
 #define IMPLEMENTATIONNAME_FONTMENUCONTROLLER                   DECLARE_ASCII("com.sun.star.comp.framework.FontMenuController"      )
 #define IMPLEMENTATIONNAME_FONTSIZEMENUCONTROLLER               DECLARE_ASCII("com.sun.star.comp.framework.FontSizeMenuController"  )
diff --git a/framework/source/dispatch/dispatchdisabler.cxx b/framework/source/dispatch/dispatchdisabler.cxx
new file mode 100644
index 0000000..608b18d
--- /dev/null
+++ b/framework/source/dispatch/dispatchdisabler.cxx
@@ -0,0 +1,171 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/config.h>
+
+#include "services.h"
+#include "dispatch/dispatchdisabler.hxx"
+
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/DispatchDescriptor.hpp>
+
+using namespace css;
+using namespace framework;
+
+DispatchDisabler::DispatchDisabler(const uno::Reference< uno::XComponentContext >& rxContext) :
+    mxContext( rxContext )
+{
+}
+
+// XInitialization
+void SAL_CALL DispatchDisabler::initialize( const uno::Sequence< uno::Any >& aArguments )
+        throw (uno::Exception, uno::RuntimeException, ::std::exception)
+{
+    uno::Sequence< OUString > aDisabledURLs;
+    if( aArguments.getLength() > 0 &&
+        ( aArguments[0] >>= aDisabledURLs ) )
+    {
+        for( sal_Int32 i = 0; i < aDisabledURLs.getLength(); ++i )
+            maDisabledURLs.insert(aDisabledURLs[i]);
+    }
+}
+
+// XDispatchProvider
+uno::Reference< frame::XDispatch > SAL_CALL
+DispatchDisabler::queryDispatch( const util::URL& rURL,
+                                 const OUString& rTargetFrameName,
+                                 ::sal_Int32 nSearchFlags )
+    throw (uno::RuntimeException, ::std::exception)
+{
+    // If present - disabled.
+    if( maDisabledURLs.find(rURL.Complete) != maDisabledURLs.end() ||
+        !mxSlave.is() )
+        return uno::Reference< frame::XDispatch >();
+    else
+        return mxSlave->queryDispatch(rURL, rTargetFrameName, nSearchFlags);
+}
+
+uno::Sequence< uno::Reference< frame::XDispatch > > SAL_CALL
+DispatchDisabler::queryDispatches( const uno::Sequence< frame::DispatchDescriptor >& rRequests )
+    throw (uno::RuntimeException, ::std::exception)
+{
+    uno::Sequence< uno::Reference< frame::XDispatch > > aResult(rRequests.getLength());
+    for( sal_Int32 i = 0; i < rRequests.getLength(); ++i )
+        aResult[i] = queryDispatch(rRequests[i].FeatureURL,
+                                   rRequests[i].FrameName,
+                                   rRequests[i].SearchFlags);
+    return aResult;
+}
+
+// XDispatchProviderInterceptor
+uno::Reference< frame::XDispatchProvider > SAL_CALL
+DispatchDisabler::getSlaveDispatchProvider() throw (uno::RuntimeException, ::std::exception)
+{
+    return mxSlave;
+}
+
+void SAL_CALL DispatchDisabler::setSlaveDispatchProvider( const uno::Reference< frame::XDispatchProvider >& xNewDispatchProvider )
+    throw (uno::RuntimeException, ::std::exception)
+{
+    mxSlave = xNewDispatchProvider;
+}
+
+uno::Reference< frame::XDispatchProvider > SAL_CALL
+DispatchDisabler::getMasterDispatchProvider() throw (uno::RuntimeException, ::std::exception)
+{
+    return mxMaster;
+}
+void SAL_CALL
+DispatchDisabler::setMasterDispatchProvider( const uno::Reference< frame::XDispatchProvider >& xNewSupplier )
+        throw (uno::RuntimeException, ::std::exception)
+{
+    mxMaster = xNewSupplier;
+}
+
+// XInterceptorInfo
+uno::Sequence< OUString > SAL_CALL
+    DispatchDisabler::getInterceptedURLs()
+    throw (uno::RuntimeException, ::std::exception)
+{
+    uno::Sequence< OUString > aDisabledURLs(maDisabledURLs.size());
+    sal_Int32 n = 0;
+    for (auto i = aDisabledURLs.begin(); i != aDisabledURLs.end(); ++i)
+        aDisabledURLs[n++] = *i;
+    return aDisabledURLs;
+}
+
+// XElementAccess
+uno::Type SAL_CALL DispatchDisabler::getElementType()
+    throw (uno::RuntimeException, ::std::exception)
+{
+    uno::Type aModuleType = cppu::UnoType<OUString>::get();
+    return aModuleType;
+}
+
+::sal_Bool SAL_CALL DispatchDisabler::hasElements()
+        throw (uno::RuntimeException, ::std::exception)
+{
+    return maDisabledURLs.size() > 0;
+}
+
+// XNameAccess
+uno::Any SAL_CALL DispatchDisabler::getByName( const OUString& )
+        throw (container::NoSuchElementException, lang::WrappedTargetException,
+               uno::RuntimeException, ::std::exception)
+{
+    return uno::Any();
+}
+
+uno::Sequence< OUString > SAL_CALL DispatchDisabler::getElementNames()
+        throw (uno::RuntimeException, ::std::exception)
+{
+    return getInterceptedURLs();
+}
+
+sal_Bool SAL_CALL DispatchDisabler::hasByName( const OUString& rName )
+        throw (uno::RuntimeException, ::std::exception)
+{
+    return maDisabledURLs.find(rName) != maDisabledURLs.end();
+}
+
+// XNameReplace
+void SAL_CALL DispatchDisabler::replaceByName( const OUString& rName, const uno::Any& aElement )
+        throw (lang::IllegalArgumentException, container::NoSuchElementException,
+               lang::WrappedTargetException, uno::RuntimeException, ::std::exception)
+{
+    removeByName( rName );
+    insertByName( rName, aElement );
+}
+
+// XNameContainer
+void DispatchDisabler::insertByName( const OUString& rName, const uno::Any& )
+    throw (lang::IllegalArgumentException, container::ElementExistException,
+           lang::WrappedTargetException, uno::RuntimeException, ::std::exception)
+{
+    maDisabledURLs.insert(rName);
+}
+
+void DispatchDisabler::removeByName( const OUString& rName )
+    throw (container::NoSuchElementException, lang::WrappedTargetException,
+           uno::RuntimeException, ::std::exception)
+{
+    auto it = maDisabledURLs.find(rName);
+    if( it != maDisabledURLs.end() )
+        maDisabledURLs.erase(it);
+}
+
+DEFINE_INIT_SERVICE(DispatchDisabler, {})
+
+// XServiceInfo
+DEFINE_XSERVICEINFO_MULTISERVICE_2(DispatchDisabler,
+                                   ::cppu::OWeakObject,
+                                   "com.sun.star.frame.DispatchDisabler",
+                                   IMPLEMENTATIONNAME_DISPATCHDISABLER)
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/framework/source/dispatch/interceptionhelper.cxx b/framework/source/dispatch/interceptionhelper.cxx
index 83d510d8..49ff66c 100644
--- a/framework/source/dispatch/interceptionhelper.cxx
+++ b/framework/source/dispatch/interceptionhelper.cxx
@@ -96,7 +96,7 @@ css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL Inte
 void SAL_CALL InterceptionHelper::registerDispatchProviderInterceptor(const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& xInterceptor)
     throw(css::uno::RuntimeException, std::exception)
 {
-    // reject wrong calling of this interface method
+    // reject incorrect calls of this interface method
     css::uno::Reference< css::frame::XDispatchProvider > xThis(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY);
     if (!xInterceptor.is())
         throw css::uno::RuntimeException("NULL references not allowed as in parameter", xThis);
diff --git a/framework/source/inc/dispatch/dispatchdisabler.hxx b/framework/source/inc/dispatch/dispatchdisabler.hxx
new file mode 100644
index 0000000..3d7a618
--- /dev/null
+++ b/framework/source/inc/dispatch/dispatchdisabler.hxx
@@ -0,0 +1,117 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+#ifndef INCLUDED_FRAMEWORK_INC_SERVICES_DISPATCH_DISABLER_HXX
+#define INCLUDED_FRAMEWORK_INC_SERVICES_DISPATCH_DISABLER_HXX
+
+#include <set>
+
+#include <cppuhelper/implbase.hxx>
+#include <cppuhelper/weakref.hxx>
+
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/container/XNameContainer.hpp>
+#include <com/sun/star/frame/XDispatch.hpp>
+#include <com/sun/star/frame/XInterceptorInfo.hpp>
+#include <com/sun/star/frame/XDispatchProvider.hpp>
+#include <com/sun/star/frame/XDispatchProviderInterceptor.hpp>
+
+#include <macros/xserviceinfo.hxx>
+
+namespace framework {
+
+/**
+ * Implementation of a service to make it easy to disable a whole
+ * suite of UNO commands in a batch - and have that act in-process.
+ *
+ * Often external re-use of LibreOffice wants a very cut-down set
+ * of functionality included, and disabling elements remotely one
+ * by one performs poorly.
+ */
+class DispatchDisabler : public ::cppu::WeakImplHelper<
+                                        css::lang::XInitialization,
+                                        css::container::XNameContainer,
+                                        css::frame::XDispatchProviderInterceptor,
+                                        css::frame::XInterceptorInfo,
+                                        css::lang::XServiceInfo >
+{
+    std::set<OUString> maDisabledURLs;
+    css::uno::Reference< css::frame::XDispatchProvider > mxSlave;
+    css::uno::Reference< css::frame::XDispatchProvider > mxMaster;
+    css::uno::Reference< css::uno::XComponentContext >   mxContext;
+public:
+             DispatchDisabler(const css::uno::Reference< css::uno::XComponentContext >& rxContext);
+    virtual ~DispatchDisabler() {}
+
+    // XInitialization
+    virtual void SAL_CALL initialize( const ::css::uno::Sequence< ::css::uno::Any >& aArguments )
+        throw (::css::uno::Exception, ::css::uno::RuntimeException, ::std::exception) override;
+
+    // XDispatchProvider
+    virtual ::css::uno::Reference< ::css::frame::XDispatch > SAL_CALL
+        queryDispatch( const ::css::util::URL& URL,
+               const OUString& TargetFrameName,
+               ::sal_Int32 SearchFlags )
+           throw (::css::uno::RuntimeException, ::std::exception) override;
+    virtual ::css::uno::Sequence< ::css::uno::Reference< ::css::frame::XDispatch > > SAL_CALL
+        queryDispatches( const ::css::uno::Sequence< ::css::frame::DispatchDescriptor >& Requests )
+           throw (::css::uno::RuntimeException, ::std::exception) override;
+
+    // XDispatchProviderInterceptor
+    virtual ::css::uno::Reference< ::css::frame::XDispatchProvider > SAL_CALL
+        getSlaveDispatchProvider() throw (::css::uno::RuntimeException, ::std::exception) override;
+    virtual void SAL_CALL
+        setSlaveDispatchProvider( const ::css::uno::Reference< ::css::frame::XDispatchProvider >& NewDispatchProvider )
+            throw (::css::uno::RuntimeException, ::std::exception) override;
+    virtual ::css::uno::Reference< ::css::frame::XDispatchProvider > SAL_CALL
+        getMasterDispatchProvider() throw (::css::uno::RuntimeException, ::std::exception) override;
+    virtual void SAL_CALL
+        setMasterDispatchProvider( const ::css::uno::Reference< ::css::frame::XDispatchProvider >& NewSupplier )
+            throw (::css::uno::RuntimeException, ::std::exception) override;
+
+    // XInterceptorInfo
+    virtual ::css::uno::Sequence< OUString > SAL_CALL
+        getInterceptedURLs() throw (::css::uno::RuntimeException, ::std::exception) override;
+
+    // XElementAccess
+    virtual ::css::uno::Type SAL_CALL getElementType()
+        throw (::css::uno::RuntimeException, ::std::exception) override;
+    virtual ::sal_Bool SAL_CALL hasElements()
+        throw (::css::uno::RuntimeException, ::std::exception) override;
+
+    // XNameAccess
+    virtual ::css::uno::Any SAL_CALL getByName( const OUString& aName )
+        throw (::css::container::NoSuchElementException, ::css::lang::WrappedTargetException,
+               ::css::uno::RuntimeException, ::std::exception) override;
+    virtual ::css::uno::Sequence< OUString > SAL_CALL getElementNames()
+        throw (::css::uno::RuntimeException, ::std::exception) override;
+    virtual sal_Bool SAL_CALL hasByName( const OUString& aName )
+        throw (::css::uno::RuntimeException, ::std::exception) override;
+
+    // XNameReplace
+    virtual void SAL_CALL replaceByName( const OUString& aName, const ::css::uno::Any& aElement )
+        throw (::css::lang::IllegalArgumentException, ::css::container::NoSuchElementException,
+               ::css::lang::WrappedTargetException, ::css::uno::RuntimeException, ::std::exception) override;
+
+    // XNameContainer
+    virtual void SAL_CALL insertByName( const OUString& aName, const ::css::uno::Any& aElement )
+        throw (::css::lang::IllegalArgumentException, ::css::container::ElementExistException,
+               ::css::lang::WrappedTargetException, ::css::uno::RuntimeException, ::std::exception) override;
+    virtual void SAL_CALL removeByName( const OUString& Name )
+        throw (::css::container::NoSuchElementException, ::css::lang::WrappedTargetException,
+               ::css::uno::RuntimeException, ::std::exception) override;
+
+    DECLARE_XSERVICEINFO
+};
+
+} // namespace framework
+
+#endif // INCLUDED_FRAMEWORK_INC_SERVICES_DISPATCH_DISABLER_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/framework/source/register/registertemp.cxx b/framework/source/register/registertemp.cxx
index e02195c..393c5bd 100644
--- a/framework/source/register/registertemp.cxx
+++ b/framework/source/register/registertemp.cxx
@@ -37,6 +37,7 @@
 #include <dispatch/oxt_handler.hxx>
 #include <dispatch/popupmenudispatcher.hxx>
 #include <dispatch/servicehandler.hxx>
+#include <dispatch/dispatchdisabler.hxx>
 #include <services/dispatchhelper.hxx>
 #include <recording/dispatchrecorder.hxx>
 #include <recording/dispatchrecordersupplier.hxx>
@@ -51,11 +52,12 @@
 #include <uielement/toolbarsmenucontroller.hxx>
 
 COMPONENTGETFACTORY ( fwl,
-                        IFFACTORY( ::framework::MediaTypeDetectionHelper        )
-                        IFFACTORY( ::framework::MailToDispatcher                        ) else
+                        IFFACTORY( ::framework::MediaTypeDetectionHelper                )
+                        IFFACTORY( ::framework::MailToDispatcher                        )   else
                         IFFACTORY( ::framework::ServiceHandler                          )   else
                         IFFACTORY( ::framework::PopupMenuDispatcher                     )   else
                         IFFACTORY( ::framework::DispatchHelper                          )   else
+                        IFFACTORY( ::framework::DispatchDisabler                        )   else
                         IFFACTORY( ::framework::DispatchRecorder                        )   else
                         IFFACTORY( ::framework::DispatchRecorderSupplier                )   else
                         IFFACTORY( ::framework::ToolbarsMenuController                  )   else


More information about the Libreoffice-commits mailing list