bump product version to 7.2.5.1
[LibreOffice.git] / svx / source / form / formdispatchinterceptor.cxx
blob5bc0834cfa65f7fc6c792961c06af9fb01c27ccc
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::Sequence;
27 using ::com::sun::star::frame::XDispatchProviderInterception;
28 using ::com::sun::star::frame::XDispatchProviderInterceptor;
29 using ::com::sun::star::lang::XComponent;
30 using ::com::sun::star::util::URL;
31 using ::com::sun::star::frame::XDispatch;
32 using ::com::sun::star::frame::DispatchDescriptor;
33 using ::com::sun::star::frame::XDispatchProvider;
34 using ::com::sun::star::lang::EventObject;
36 DispatchInterceptionMultiplexer::DispatchInterceptionMultiplexer(
37 const Reference< XDispatchProviderInterception >& _rxToIntercept, DispatchInterceptor* _pMaster )
38 :DispatchInterceptionMultiplexer_BASE(_pMaster && _pMaster->getInterceptorMutex() ? *_pMaster->getInterceptorMutex() : m_aFallback)
39 ,m_aFallback()
40 ,m_pMutex( _pMaster && _pMaster->getInterceptorMutex() ? _pMaster->getInterceptorMutex() : &m_aFallback )
41 ,m_xIntercepted(_rxToIntercept)
42 ,m_bListening(false)
43 ,m_pMaster(_pMaster)
46 ::osl::MutexGuard aGuard( *m_pMutex );
47 osl_atomic_increment(&m_refCount);
48 if (_rxToIntercept.is())
50 _rxToIntercept->registerDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor*>(this));
51 // this should make us the top-level dispatch-provider for the component, via a call to our
52 // setDispatchProvider we should have got a fallback for requests we (i.e. our master) cannot fulfill
53 Reference< XComponent> xInterceptedComponent(_rxToIntercept, UNO_QUERY);
54 if (xInterceptedComponent.is())
56 xInterceptedComponent->addEventListener(this);
57 m_bListening = true;
60 osl_atomic_decrement(&m_refCount);
64 DispatchInterceptionMultiplexer::~DispatchInterceptionMultiplexer()
66 if (!rBHelper.bDisposed)
67 dispose();
72 Reference< XDispatch > SAL_CALL DispatchInterceptionMultiplexer::queryDispatch( const URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags )
74 ::osl::MutexGuard aGuard( *m_pMutex );
75 Reference< XDispatch> xResult;
76 // ask our 'real' interceptor
77 if (m_pMaster)
78 xResult = m_pMaster->interceptedQueryDispatch( aURL, aTargetFrameName, nSearchFlags);
80 // ask our slave provider
81 if (!xResult.is() && m_xSlaveDispatcher.is())
82 xResult = m_xSlaveDispatcher->queryDispatch(aURL, aTargetFrameName, nSearchFlags);
84 return xResult;
88 Sequence< Reference< XDispatch > > SAL_CALL
89 DispatchInterceptionMultiplexer::queryDispatches( const Sequence< DispatchDescriptor >& aDescripts )
91 ::osl::MutexGuard aGuard( *m_pMutex );
92 Sequence< Reference< XDispatch> > aReturn(aDescripts.getLength());
93 std::transform(aDescripts.begin(), aDescripts.end(), aReturn.begin(),
94 [this](const DispatchDescriptor& rDescript) -> Reference< XDispatch> {
95 return queryDispatch(rDescript.FeatureURL, rDescript.FrameName, rDescript.SearchFlags); });
96 return aReturn;
100 Reference< XDispatchProvider > SAL_CALL DispatchInterceptionMultiplexer::getSlaveDispatchProvider( )
102 ::osl::MutexGuard aGuard( *m_pMutex );
103 return m_xSlaveDispatcher;
107 void SAL_CALL DispatchInterceptionMultiplexer::setSlaveDispatchProvider(const Reference< XDispatchProvider>& xNewDispatchProvider)
109 ::osl::MutexGuard aGuard( *m_pMutex );
110 m_xSlaveDispatcher = xNewDispatchProvider;
114 Reference< XDispatchProvider> SAL_CALL DispatchInterceptionMultiplexer::getMasterDispatchProvider()
116 ::osl::MutexGuard aGuard( *m_pMutex );
117 return m_xMasterDispatcher;
121 void SAL_CALL DispatchInterceptionMultiplexer::setMasterDispatchProvider(const Reference< XDispatchProvider>& xNewSupplier)
123 ::osl::MutexGuard aGuard( *m_pMutex );
124 m_xMasterDispatcher = xNewSupplier;
128 void SAL_CALL DispatchInterceptionMultiplexer::disposing(const EventObject& Source)
130 if (m_bListening)
132 Reference< XDispatchProviderInterception > xIntercepted(m_xIntercepted.get(), UNO_QUERY);
133 if (Source.Source == xIntercepted)
134 ImplDetach();
139 void DispatchInterceptionMultiplexer::ImplDetach()
141 ::osl::MutexGuard aGuard( *m_pMutex );
142 OSL_ENSURE(m_bListening, "DispatchInterceptionMultiplexer::ImplDetach: invalid call!");
144 // deregister ourself from the interception component
145 Reference< XDispatchProviderInterception > xIntercepted(m_xIntercepted.get(), UNO_QUERY);
146 if (xIntercepted.is())
147 xIntercepted->releaseDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor*>(this));
149 // m_xIntercepted.clear();
150 // Don't reset m_xIntercepted: It may be needed by our owner to check for which object we were
151 // responsible. As we hold the object with a weak reference only, this should be no problem.
152 // 88936 - 23.07.2001 - frank.schoenheit@sun.com
153 m_pMaster = nullptr;
154 m_pMutex = &m_aFallback;
155 m_bListening = false;
159 void DispatchInterceptionMultiplexer::disposing()
161 // remove ourself as event listener from the interception component
162 if (m_bListening)
164 Reference< XComponent> xInterceptedComponent(m_xIntercepted.get(), UNO_QUERY);
165 if (xInterceptedComponent.is())
166 xInterceptedComponent->removeEventListener(static_cast<XEventListener*>(this));
168 // detach from the interception component
169 ImplDetach();
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */