LibreOffice Module framework (master) 1
dispatchdisabler.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10#include <sal/config.h>
11
12#include <services.h>
14
15#include <com/sun/star/frame/DispatchDescriptor.hpp>
17
18using namespace css;
19using namespace framework;
20
21DispatchDisabler::DispatchDisabler(const uno::Reference< uno::XComponentContext >& )
22{
23}
24
25// XInitialization
26void SAL_CALL DispatchDisabler::initialize( const uno::Sequence< uno::Any >& aArguments )
27{
28 uno::Sequence< OUString > aDisabledURLs;
29 if( aArguments.hasElements() &&
30 ( aArguments[0] >>= aDisabledURLs ) )
31 {
32 for( OUString const & url : std::as_const(aDisabledURLs) )
33 maDisabledURLs.insert(url);
34 }
35}
36
37// XDispatchProvider
38uno::Reference< frame::XDispatch > SAL_CALL
39DispatchDisabler::queryDispatch( const util::URL& rURL,
40 const OUString& rTargetFrameName,
41 ::sal_Int32 nSearchFlags )
42{
43 // If present - disabled.
44 if( maDisabledURLs.find(rURL.Complete) != maDisabledURLs.end() ||
45 !mxSlave.is() )
46 return uno::Reference< frame::XDispatch >();
47 else
48 return mxSlave->queryDispatch(rURL, rTargetFrameName, nSearchFlags);
49}
50
51uno::Sequence< uno::Reference< frame::XDispatch > > SAL_CALL
52DispatchDisabler::queryDispatches( const uno::Sequence< frame::DispatchDescriptor >& rRequests )
53{
54 uno::Sequence< uno::Reference< frame::XDispatch > > aResult(rRequests.getLength());
55 auto aResultRange = asNonConstRange(aResult);
56 for( sal_Int32 i = 0; i < rRequests.getLength(); ++i )
57 aResultRange[i] = queryDispatch(rRequests[i].FeatureURL,
58 rRequests[i].FrameName,
59 rRequests[i].SearchFlags);
60 return aResult;
61}
62
63// XDispatchProviderInterceptor
64uno::Reference< frame::XDispatchProvider > SAL_CALL
66{
67 return mxSlave;
68}
69
70void SAL_CALL DispatchDisabler::setSlaveDispatchProvider( const uno::Reference< frame::XDispatchProvider >& xNewDispatchProvider )
71{
72 mxSlave = xNewDispatchProvider;
73}
74
75uno::Reference< frame::XDispatchProvider > SAL_CALL
77{
78 return mxMaster;
79}
80void SAL_CALL
81DispatchDisabler::setMasterDispatchProvider( const uno::Reference< frame::XDispatchProvider >& xNewSupplier )
82{
83 mxMaster = xNewSupplier;
84}
85
86// XInterceptorInfo
87uno::Sequence< OUString > SAL_CALL
89{
90 uno::Sequence< OUString > aDisabledURLs(maDisabledURLs.size());
91 auto aDisabledURLsRange = asNonConstRange(aDisabledURLs);
92 sal_Int32 n = 0;
93 for (auto const& disabledURL : maDisabledURLs)
94 aDisabledURLsRange[n++] = disabledURL;
95 return aDisabledURLs;
96}
97
98// XElementAccess
100{
102 return aModuleType;
103}
104
106{
107 return !maDisabledURLs.empty();
108}
109
110// XNameAccess
111uno::Any SAL_CALL DispatchDisabler::getByName( const OUString& )
112{
113 return uno::Any();
114}
115
116uno::Sequence< OUString > SAL_CALL DispatchDisabler::getElementNames()
117{
118 return getInterceptedURLs();
119}
120
121sal_Bool SAL_CALL DispatchDisabler::hasByName( const OUString& rName )
122{
123 return maDisabledURLs.find(rName) != maDisabledURLs.end();
124}
125
126// XNameReplace
127void SAL_CALL DispatchDisabler::replaceByName( const OUString& rName, const uno::Any& aElement )
128{
129 removeByName( rName );
130 insertByName( rName, aElement );
131}
132
133// XNameContainer
134void DispatchDisabler::insertByName( const OUString& rName, const uno::Any& )
135{
136 maDisabledURLs.insert(rName);
137}
138
139void DispatchDisabler::removeByName( const OUString& rName )
140{
141 auto it = maDisabledURLs.find(rName);
142 if( it != maDisabledURLs.end() )
143 maDisabledURLs.erase(it);
144}
145
146// XInterface, XTypeProvider, XServiceInfo
147
149{
150 return "com.sun.star.comp.framework.services.DispatchDisabler";
151}
152
153sal_Bool SAL_CALL DispatchDisabler::supportsService( const OUString& sServiceName )
154{
156}
157
158css::uno::Sequence< OUString > SAL_CALL DispatchDisabler::getSupportedServiceNames()
159{
160 return { "com.sun.star.frame.DispatchDisabler" };
161}
162
163extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
165 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
166{
167 return cppu::acquire(new framework::DispatchDisabler(context));
168}
169
170/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral sServiceName
css::uno::Type const & get()
Implementation of a service to make it easy to disable a whole suite of UNO commands in a batch - and...
css::uno::Reference< css::frame::XDispatchProvider > mxMaster
virtual void SAL_CALL initialize(const ::css::uno::Sequence< ::css::uno::Any > &aArguments) override
virtual ::css::uno::Sequence< OUString > SAL_CALL getElementNames() override
virtual ::css::uno::Reference< ::css::frame::XDispatch > SAL_CALL queryDispatch(const ::css::util::URL &URL, const OUString &TargetFrameName, ::sal_Int32 SearchFlags) override
virtual ::css::uno::Any SAL_CALL getByName(const OUString &aName) override
virtual ::css::uno::Sequence< OUString > SAL_CALL getInterceptedURLs() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
virtual void SAL_CALL insertByName(const OUString &aName, const ::css::uno::Any &aElement) override
virtual void SAL_CALL removeByName(const OUString &Name) override
std::set< OUString > maDisabledURLs
virtual ::css::uno::Reference< ::css::frame::XDispatchProvider > SAL_CALL getSlaveDispatchProvider() override
virtual void SAL_CALL setSlaveDispatchProvider(const ::css::uno::Reference< ::css::frame::XDispatchProvider > &NewDispatchProvider) override
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
virtual void SAL_CALL replaceByName(const OUString &aName, const ::css::uno::Any &aElement) override
virtual OUString SAL_CALL getImplementationName() override
virtual ::sal_Bool SAL_CALL hasElements() override
css::uno::Reference< css::frame::XDispatchProvider > mxSlave
virtual ::css::uno::Reference< ::css::frame::XDispatchProvider > SAL_CALL getMasterDispatchProvider() override
virtual ::css::uno::Type SAL_CALL getElementType() override
virtual ::css::uno::Sequence< ::css::uno::Reference< ::css::frame::XDispatch > > SAL_CALL queryDispatches(const ::css::uno::Sequence< ::css::frame::DispatchDescriptor > &Requests) override
virtual void SAL_CALL setMasterDispatchProvider(const ::css::uno::Reference< ::css::frame::XDispatchProvider > &NewSupplier) override
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * framework_DispatchDisabler_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Sequence< PropertyValue > aArguments
sal_Int64 n
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
unsigned char sal_Bool