summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--framework/Library_fwl.mk1
-rw-r--r--framework/inc/services.h1
-rw-r--r--framework/source/dispatch/dispatchdisabler.cxx171
-rw-r--r--framework/source/dispatch/interceptionhelper.cxx2
-rw-r--r--framework/source/inc/dispatch/dispatchdisabler.hxx117
-rw-r--r--framework/source/register/registertemp.cxx6
6 files changed, 295 insertions, 3 deletions
diff --git a/framework/Library_fwl.mk b/framework/Library_fwl.mk
index c5e1ad165109..ea325e0cf537 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 522a9668652d..92643375c526 100644
--- a/framework/inc/services.h
+++ b/framework/inc/services.h
@@ -44,6 +44,7 @@ namespace framework{
#define IMPLEMENTATIONNAME_MAILTODISPATCHER "com.sun.star.comp.framework.MailToDispatcher"
#define IMPLEMENTATIONNAME_SERVICEHANDLER "com.sun.star.comp.framework.ServiceHandler"
#define IMPLEMENTATIONNAME_DISPATCHHELPER "com.sun.star.comp.framework.services.DispatchHelper"
+#define IMPLEMENTATIONNAME_DISPATCHDISABLER "com.sun.star.comp.framework.services.DispatchDisabler"
#define IMPLEMENTATIONNAME_MACROSMENUCONTROLLER "com.sun.star.comp.framework.MacrosMenuController"
#define IMPLEMENTATIONNAME_FONTMENUCONTROLLER "com.sun.star.comp.framework.FontMenuController"
#define IMPLEMENTATIONNAME_FONTSIZEMENUCONTROLLER "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 000000000000..608b18d70013
--- /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 c09e67210908..d205a53ba5f6 100644
--- a/framework/source/dispatch/interceptionhelper.cxx
+++ b/framework/source/dispatch/interceptionhelper.cxx
@@ -94,7 +94,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 000000000000..3d7a61811d98
--- /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 e02195c253f0..393c5bd42a34 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