1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include <sal/config.h>
13 #include <dispatch/dispatchdisabler.hxx>
15 #include <com/sun/star/frame/DispatchDescriptor.hpp>
16 #include <cppuhelper/supportsservice.hxx>
19 using namespace framework
;
21 DispatchDisabler::DispatchDisabler(const uno::Reference
< uno::XComponentContext
>& )
26 void SAL_CALL
DispatchDisabler::initialize( const uno::Sequence
< uno::Any
>& aArguments
)
28 uno::Sequence
< OUString
> aDisabledURLs
;
29 if( aArguments
.hasElements() &&
30 ( aArguments
[0] >>= aDisabledURLs
) )
32 for (OUString
const& url
: aDisabledURLs
)
33 maDisabledURLs
.insert(url
);
38 uno::Reference
< frame::XDispatch
> SAL_CALL
39 DispatchDisabler::queryDispatch( const util::URL
& rURL
,
40 const OUString
& rTargetFrameName
,
41 ::sal_Int32 nSearchFlags
)
43 // If present - disabled.
44 if( maDisabledURLs
.find(rURL
.Complete
) != maDisabledURLs
.end() ||
46 return uno::Reference
< frame::XDispatch
>();
48 return mxSlave
->queryDispatch(rURL
, rTargetFrameName
, nSearchFlags
);
51 uno::Sequence
< uno::Reference
< frame::XDispatch
> > SAL_CALL
52 DispatchDisabler::queryDispatches( const uno::Sequence
< frame::DispatchDescriptor
>& rRequests
)
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
);
63 // XDispatchProviderInterceptor
64 uno::Reference
< frame::XDispatchProvider
> SAL_CALL
65 DispatchDisabler::getSlaveDispatchProvider()
70 void SAL_CALL
DispatchDisabler::setSlaveDispatchProvider( const uno::Reference
< frame::XDispatchProvider
>& xNewDispatchProvider
)
72 mxSlave
= xNewDispatchProvider
;
75 uno::Reference
< frame::XDispatchProvider
> SAL_CALL
76 DispatchDisabler::getMasterDispatchProvider()
81 DispatchDisabler::setMasterDispatchProvider( const uno::Reference
< frame::XDispatchProvider
>& xNewSupplier
)
83 mxMaster
= xNewSupplier
;
87 uno::Sequence
< OUString
> SAL_CALL
88 DispatchDisabler::getInterceptedURLs()
90 uno::Sequence
< OUString
> aDisabledURLs(maDisabledURLs
.size());
91 auto aDisabledURLsRange
= asNonConstRange(aDisabledURLs
);
93 for (auto const& disabledURL
: maDisabledURLs
)
94 aDisabledURLsRange
[n
++] = disabledURL
;
99 uno::Type SAL_CALL
DispatchDisabler::getElementType()
101 uno::Type aModuleType
= cppu::UnoType
<OUString
>::get();
105 ::sal_Bool SAL_CALL
DispatchDisabler::hasElements()
107 return !maDisabledURLs
.empty();
111 uno::Any SAL_CALL
DispatchDisabler::getByName( const OUString
& )
116 uno::Sequence
< OUString
> SAL_CALL
DispatchDisabler::getElementNames()
118 return getInterceptedURLs();
121 sal_Bool SAL_CALL
DispatchDisabler::hasByName( const OUString
& rName
)
123 return maDisabledURLs
.find(rName
) != maDisabledURLs
.end();
127 void SAL_CALL
DispatchDisabler::replaceByName( const OUString
& rName
, const uno::Any
& aElement
)
129 removeByName( rName
);
130 insertByName( rName
, aElement
);
134 void DispatchDisabler::insertByName( const OUString
& rName
, const uno::Any
& )
136 maDisabledURLs
.insert(rName
);
139 void DispatchDisabler::removeByName( const OUString
& rName
)
141 auto it
= maDisabledURLs
.find(rName
);
142 if( it
!= maDisabledURLs
.end() )
143 maDisabledURLs
.erase(it
);
146 // XInterface, XTypeProvider, XServiceInfo
148 OUString SAL_CALL
DispatchDisabler::getImplementationName()
150 return "com.sun.star.comp.framework.services.DispatchDisabler";
153 sal_Bool SAL_CALL
DispatchDisabler::supportsService( const OUString
& sServiceName
)
155 return cppu::supportsService(this, sServiceName
);
158 css::uno::Sequence
< OUString
> SAL_CALL
DispatchDisabler::getSupportedServiceNames()
160 return { "com.sun.star.frame.DispatchDisabler" };
163 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
164 framework_DispatchDisabler_get_implementation(
165 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const& )
167 return cppu::acquire(new framework::DispatchDisabler(context
));
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */