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/XFrame.hpp>
16 #include <com/sun/star/frame/DispatchDescriptor.hpp>
19 using namespace framework
;
21 DispatchDisabler::DispatchDisabler(const uno::Reference
< uno::XComponentContext
>& )
26 void SAL_CALL
DispatchDisabler::initialize( const uno::Sequence
< uno::Any
>& aArguments
)
27 throw (uno::Exception
, uno::RuntimeException
, ::std::exception
)
29 uno::Sequence
< OUString
> aDisabledURLs
;
30 if( aArguments
.getLength() > 0 &&
31 ( aArguments
[0] >>= aDisabledURLs
) )
33 for( sal_Int32 i
= 0; i
< aDisabledURLs
.getLength(); ++i
)
34 maDisabledURLs
.insert(aDisabledURLs
[i
]);
39 uno::Reference
< frame::XDispatch
> SAL_CALL
40 DispatchDisabler::queryDispatch( const util::URL
& rURL
,
41 const OUString
& rTargetFrameName
,
42 ::sal_Int32 nSearchFlags
)
43 throw (uno::RuntimeException
, ::std::exception
)
45 // If present - disabled.
46 if( maDisabledURLs
.find(rURL
.Complete
) != maDisabledURLs
.end() ||
48 return uno::Reference
< frame::XDispatch
>();
50 return mxSlave
->queryDispatch(rURL
, rTargetFrameName
, nSearchFlags
);
53 uno::Sequence
< uno::Reference
< frame::XDispatch
> > SAL_CALL
54 DispatchDisabler::queryDispatches( const uno::Sequence
< frame::DispatchDescriptor
>& rRequests
)
55 throw (uno::RuntimeException
, ::std::exception
)
57 uno::Sequence
< uno::Reference
< frame::XDispatch
> > aResult(rRequests
.getLength());
58 for( sal_Int32 i
= 0; i
< rRequests
.getLength(); ++i
)
59 aResult
[i
] = queryDispatch(rRequests
[i
].FeatureURL
,
60 rRequests
[i
].FrameName
,
61 rRequests
[i
].SearchFlags
);
65 // XDispatchProviderInterceptor
66 uno::Reference
< frame::XDispatchProvider
> SAL_CALL
67 DispatchDisabler::getSlaveDispatchProvider() throw (uno::RuntimeException
, ::std::exception
)
72 void SAL_CALL
DispatchDisabler::setSlaveDispatchProvider( const uno::Reference
< frame::XDispatchProvider
>& xNewDispatchProvider
)
73 throw (uno::RuntimeException
, ::std::exception
)
75 mxSlave
= xNewDispatchProvider
;
78 uno::Reference
< frame::XDispatchProvider
> SAL_CALL
79 DispatchDisabler::getMasterDispatchProvider() throw (uno::RuntimeException
, ::std::exception
)
84 DispatchDisabler::setMasterDispatchProvider( const uno::Reference
< frame::XDispatchProvider
>& xNewSupplier
)
85 throw (uno::RuntimeException
, ::std::exception
)
87 mxMaster
= xNewSupplier
;
91 uno::Sequence
< OUString
> SAL_CALL
92 DispatchDisabler::getInterceptedURLs()
93 throw (uno::RuntimeException
, ::std::exception
)
95 uno::Sequence
< OUString
> aDisabledURLs(maDisabledURLs
.size());
97 for (auto i
= maDisabledURLs
.begin(); i
!= maDisabledURLs
.end(); ++i
)
98 aDisabledURLs
[n
++] = *i
;
103 uno::Type SAL_CALL
DispatchDisabler::getElementType()
104 throw (uno::RuntimeException
, ::std::exception
)
106 uno::Type aModuleType
= cppu::UnoType
<OUString
>::get();
110 ::sal_Bool SAL_CALL
DispatchDisabler::hasElements()
111 throw (uno::RuntimeException
, ::std::exception
)
113 return maDisabledURLs
.size() > 0;
117 uno::Any SAL_CALL
DispatchDisabler::getByName( const OUString
& )
118 throw (container::NoSuchElementException
, lang::WrappedTargetException
,
119 uno::RuntimeException
, ::std::exception
)
124 uno::Sequence
< OUString
> SAL_CALL
DispatchDisabler::getElementNames()
125 throw (uno::RuntimeException
, ::std::exception
)
127 return getInterceptedURLs();
130 sal_Bool SAL_CALL
DispatchDisabler::hasByName( const OUString
& rName
)
131 throw (uno::RuntimeException
, ::std::exception
)
133 return maDisabledURLs
.find(rName
) != maDisabledURLs
.end();
137 void SAL_CALL
DispatchDisabler::replaceByName( const OUString
& rName
, const uno::Any
& aElement
)
138 throw (lang::IllegalArgumentException
, container::NoSuchElementException
,
139 lang::WrappedTargetException
, uno::RuntimeException
, ::std::exception
)
141 removeByName( rName
);
142 insertByName( rName
, aElement
);
146 void DispatchDisabler::insertByName( const OUString
& rName
, const uno::Any
& )
147 throw (lang::IllegalArgumentException
, container::ElementExistException
,
148 lang::WrappedTargetException
, uno::RuntimeException
, ::std::exception
)
150 maDisabledURLs
.insert(rName
);
153 void DispatchDisabler::removeByName( const OUString
& rName
)
154 throw (container::NoSuchElementException
, lang::WrappedTargetException
,
155 uno::RuntimeException
, ::std::exception
)
157 auto it
= maDisabledURLs
.find(rName
);
158 if( it
!= maDisabledURLs
.end() )
159 maDisabledURLs
.erase(it
);
162 DEFINE_INIT_SERVICE(DispatchDisabler
, {})
165 DEFINE_XSERVICEINFO_MULTISERVICE_2(DispatchDisabler
,
167 "com.sun.star.frame.DispatchDisabler",
168 IMPLEMENTATIONNAME_DISPATCHDISABLER
)
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */