Bump version to 6.4-15
[LibreOffice.git] / svx / source / form / formdispatchinterceptor.cxx
blob84396d02cf647e92c78c859fd95b886b3bd30994
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <formdispatchinterceptor.hxx>
22 namespace svxform
24 using ::com::sun::star::uno::Reference;
25 using ::com::sun::star::uno::UNO_QUERY;
26 using ::com::sun::star::uno::RuntimeException;
27 using ::com::sun::star::uno::Sequence;
28 using ::com::sun::star::frame::XDispatchProviderInterception;
29 using ::com::sun::star::frame::XDispatchProviderInterceptor;
30 using ::com::sun::star::lang::XComponent;
31 using ::com::sun::star::util::URL;
32 using ::com::sun::star::frame::XDispatch;
33 using ::com::sun::star::frame::DispatchDescriptor;
34 using ::com::sun::star::frame::XDispatchProvider;
35 using ::com::sun::star::lang::EventObject;
37 DispatchInterceptionMultiplexer::DispatchInterceptionMultiplexer(
38 const Reference< XDispatchProviderInterception >& _rxToIntercept, DispatchInterceptor* _pMaster )
39 :DispatchInterceptionMultiplexer_BASE(_pMaster && _pMaster->getInterceptorMutex() ? *_pMaster->getInterceptorMutex() : m_aFallback)
40 ,m_aFallback()
41 ,m_pMutex( _pMaster && _pMaster->getInterceptorMutex() ? _pMaster->getInterceptorMutex() : &m_aFallback )
42 ,m_xIntercepted(_rxToIntercept)
43 ,m_bListening(false)
44 ,m_pMaster(_pMaster)
47 ::osl::MutexGuard aGuard( *m_pMutex );
48 osl_atomic_increment(&m_refCount);
49 if (_rxToIntercept.is())
51 _rxToIntercept->registerDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor*>(this));
52 // this should make us the top-level dispatch-provider for the component, via a call to our
53 // setDispatchProvider we should have got a fallback for requests we (i.e. our master) cannot fulfill
54 Reference< XComponent> xInterceptedComponent(_rxToIntercept, UNO_QUERY);
55 if (xInterceptedComponent.is())
57 xInterceptedComponent->addEventListener(this);
58 m_bListening = true;
61 osl_atomic_decrement(&m_refCount);
65 DispatchInterceptionMultiplexer::~DispatchInterceptionMultiplexer()
67 if (!rBHelper.bDisposed)
68 dispose();
73 Reference< XDispatch > SAL_CALL DispatchInterceptionMultiplexer::queryDispatch( const URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags )
75 ::osl::MutexGuard aGuard( *m_pMutex );
76 Reference< XDispatch> xResult;
77 // ask our 'real' interceptor
78 if (m_pMaster)
79 xResult = m_pMaster->interceptedQueryDispatch( aURL, aTargetFrameName, nSearchFlags);
81 // ask our slave provider
82 if (!xResult.is() && m_xSlaveDispatcher.is())
83 xResult = m_xSlaveDispatcher->queryDispatch(aURL, aTargetFrameName, nSearchFlags);
85 return xResult;
89 Sequence< Reference< XDispatch > > SAL_CALL
90 DispatchInterceptionMultiplexer::queryDispatches( const Sequence< DispatchDescriptor >& aDescripts )
92 ::osl::MutexGuard aGuard( *m_pMutex );
93 Sequence< Reference< XDispatch> > aReturn(aDescripts.getLength());
94 std::transform(aDescripts.begin(), aDescripts.end(), aReturn.begin(),
95 [this](const DispatchDescriptor& rDescript) -> Reference< XDispatch> {
96 return queryDispatch(rDescript.FeatureURL, rDescript.FrameName, rDescript.SearchFlags); });
97 return aReturn;
101 Reference< XDispatchProvider > SAL_CALL DispatchInterceptionMultiplexer::getSlaveDispatchProvider( )
103 ::osl::MutexGuard aGuard( *m_pMutex );
104 return m_xSlaveDispatcher;
108 void SAL_CALL DispatchInterceptionMultiplexer::setSlaveDispatchProvider(const Reference< XDispatchProvider>& xNewDispatchProvider)
110 ::osl::MutexGuard aGuard( *m_pMutex );
111 m_xSlaveDispatcher = xNewDispatchProvider;
115 Reference< XDispatchProvider> SAL_CALL DispatchInterceptionMultiplexer::getMasterDispatchProvider()
117 ::osl::MutexGuard aGuard( *m_pMutex );
118 return m_xMasterDispatcher;
122 void SAL_CALL DispatchInterceptionMultiplexer::setMasterDispatchProvider(const Reference< XDispatchProvider>& xNewSupplier)
124 ::osl::MutexGuard aGuard( *m_pMutex );
125 m_xMasterDispatcher = xNewSupplier;
129 void SAL_CALL DispatchInterceptionMultiplexer::disposing(const EventObject& Source)
131 if (m_bListening)
133 Reference< XDispatchProviderInterception > xIntercepted(m_xIntercepted.get(), UNO_QUERY);
134 if (Source.Source == xIntercepted)
135 ImplDetach();
140 void DispatchInterceptionMultiplexer::ImplDetach()
142 ::osl::MutexGuard aGuard( *m_pMutex );
143 OSL_ENSURE(m_bListening, "DispatchInterceptionMultiplexer::ImplDetach: invalid call!");
145 // deregister ourself from the interception component
146 Reference< XDispatchProviderInterception > xIntercepted(m_xIntercepted.get(), UNO_QUERY);
147 if (xIntercepted.is())
148 xIntercepted->releaseDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor*>(this));
150 // m_xIntercepted.clear();
151 // Don't reset m_xIntercepted: It may be needed by our owner to check for which object we were
152 // responsible. As we hold the object with a weak reference only, this should be no problem.
153 // 88936 - 23.07.2001 - frank.schoenheit@sun.com
154 m_pMaster = nullptr;
155 m_pMutex = &m_aFallback;
156 m_bListening = false;
160 void DispatchInterceptionMultiplexer::disposing()
162 // remove ourself as event listener from the interception component
163 if (m_bListening)
165 Reference< XComponent> xInterceptedComponent(m_xIntercepted.get(), UNO_QUERY);
166 if (xInterceptedComponent.is())
167 xInterceptedComponent->removeEventListener(static_cast<XEventListener*>(this));
169 // detach from the interception component
170 ImplDetach();
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */