LibreOffice Module svx (master) 1
formdispatchinterceptor.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 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21
22namespace svxform
23{
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;
35
37 const Reference< XDispatchProviderInterception >& _rxToIntercept, DispatchInterceptor* _pMaster )
38 :DispatchInterceptionMultiplexer_BASE(_pMaster && _pMaster->getInterceptorMutex() ? *_pMaster->getInterceptorMutex() : m_aFallback)
39 ,m_pMutex( _pMaster && _pMaster->getInterceptorMutex() ? _pMaster->getInterceptorMutex() : &m_aFallback )
40 ,m_xIntercepted(_rxToIntercept)
41 ,m_bListening(false)
42 ,m_pMaster(_pMaster)
43 {
44
45 ::osl::MutexGuard aGuard( *m_pMutex );
46 osl_atomic_increment(&m_refCount);
47 if (_rxToIntercept.is())
48 {
49 _rxToIntercept->registerDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor*>(this));
50 // this should make us the top-level dispatch-provider for the component, via a call to our
51 // setDispatchProvider we should have got a fallback for requests we (i.e. our master) cannot fulfill
52 Reference< XComponent> xInterceptedComponent(_rxToIntercept, UNO_QUERY);
53 if (xInterceptedComponent.is())
54 {
55 xInterceptedComponent->addEventListener(this);
56 m_bListening = true;
57 }
58 }
59 osl_atomic_decrement(&m_refCount);
60 }
61
62
64 {
65 if (!rBHelper.bDisposed)
66 dispose();
67
68 }
69
70
71 Reference< XDispatch > SAL_CALL DispatchInterceptionMultiplexer::queryDispatch( const URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags )
72 {
73 ::osl::MutexGuard aGuard( *m_pMutex );
74 Reference< XDispatch> xResult;
75 // ask our 'real' interceptor
76 if (m_pMaster)
77 xResult = m_pMaster->interceptedQueryDispatch( aURL, aTargetFrameName, nSearchFlags);
78
79 // ask our slave provider
80 if (!xResult.is() && m_xSlaveDispatcher.is())
81 xResult = m_xSlaveDispatcher->queryDispatch(aURL, aTargetFrameName, nSearchFlags);
82
83 return xResult;
84 }
85
86
87 Sequence< Reference< XDispatch > > SAL_CALL
88 DispatchInterceptionMultiplexer::queryDispatches( const Sequence< DispatchDescriptor >& aDescripts )
89 {
90 ::osl::MutexGuard aGuard( *m_pMutex );
91 Sequence< Reference< XDispatch> > aReturn(aDescripts.getLength());
92 std::transform(aDescripts.begin(), aDescripts.end(), aReturn.getArray(),
93 [this](const DispatchDescriptor& rDescript) -> Reference< XDispatch> {
94 return queryDispatch(rDescript.FeatureURL, rDescript.FrameName, rDescript.SearchFlags); });
95 return aReturn;
96 }
97
98
99 Reference< XDispatchProvider > SAL_CALL DispatchInterceptionMultiplexer::getSlaveDispatchProvider( )
100 {
101 ::osl::MutexGuard aGuard( *m_pMutex );
102 return m_xSlaveDispatcher;
103 }
104
105
106 void SAL_CALL DispatchInterceptionMultiplexer::setSlaveDispatchProvider(const Reference< XDispatchProvider>& xNewDispatchProvider)
107 {
108 ::osl::MutexGuard aGuard( *m_pMutex );
109 m_xSlaveDispatcher = xNewDispatchProvider;
110 }
111
112
113 Reference< XDispatchProvider> SAL_CALL DispatchInterceptionMultiplexer::getMasterDispatchProvider()
114 {
115 ::osl::MutexGuard aGuard( *m_pMutex );
116 return m_xMasterDispatcher;
117 }
118
119
120 void SAL_CALL DispatchInterceptionMultiplexer::setMasterDispatchProvider(const Reference< XDispatchProvider>& xNewSupplier)
121 {
122 ::osl::MutexGuard aGuard( *m_pMutex );
123 m_xMasterDispatcher = xNewSupplier;
124 }
125
126
127 void SAL_CALL DispatchInterceptionMultiplexer::disposing(const EventObject& Source)
128 {
129 if (m_bListening)
130 {
131 Reference< XDispatchProviderInterception > xIntercepted(m_xIntercepted.get(), UNO_QUERY);
132 if (Source.Source == xIntercepted)
133 ImplDetach();
134 }
135 }
136
137
139 {
140 ::osl::MutexGuard aGuard( *m_pMutex );
141 OSL_ENSURE(m_bListening, "DispatchInterceptionMultiplexer::ImplDetach: invalid call!");
142
143 // deregister ourself from the interception component
144 Reference< XDispatchProviderInterception > xIntercepted(m_xIntercepted.get(), UNO_QUERY);
145 if (xIntercepted.is())
146 xIntercepted->releaseDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor*>(this));
147
148 // m_xIntercepted.clear();
149 // Don't reset m_xIntercepted: It may be needed by our owner to check for which object we were
150 // responsible. As we hold the object with a weak reference only, this should be no problem.
151 // 88936 - 23.07.2001 - frank.schoenheit@sun.com
152 m_pMaster = nullptr;
154 m_bListening = false;
155 }
156
157
159 {
160 // remove ourself as event listener from the interception component
161 if (m_bListening)
162 {
163 Reference< XComponent> xInterceptedComponent(m_xIntercepted.get(), UNO_QUERY);
164 if (xInterceptedComponent.is())
165 xInterceptedComponent->removeEventListener(static_cast<XEventListener*>(this));
166
167 // detach from the interception component
168 ImplDetach();
169 }
170 }
171
172
173}
174
175
176/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(const css::util::URL &aURL, const OUString &aTargetFrameName, sal_Int32 nSearchFlags) override
virtual css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL getMasterDispatchProvider() override
virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches(const css::uno::Sequence< css::frame::DispatchDescriptor > &aDescripts) override
virtual void SAL_CALL setMasterDispatchProvider(const css::uno::Reference< css::frame::XDispatchProvider > &xNewSupplier) override
css::uno::Reference< css::frame::XDispatchProvider > m_xMasterDispatcher
css::uno::WeakReference< css::frame::XDispatchProviderInterception > m_xIntercepted
virtual void SAL_CALL setSlaveDispatchProvider(const css::uno::Reference< css::frame::XDispatchProvider > &xNewDispatchProvider) override
virtual css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL getSlaveDispatchProvider() override
css::uno::Reference< css::frame::XDispatchProvider > m_xSlaveDispatcher
DispatchInterceptionMultiplexer(const css::uno::Reference< css::frame::XDispatchProviderInterception > &_rToIntercept, DispatchInterceptor *_pMaster)
virtual css::uno::Reference< css::frame::XDispatch > interceptedQueryDispatch(const css::util::URL &aURL, const OUString &aTargetFrameName, sal_Int32 nSearchFlags)=0
URL aURL
ULONG m_refCount
class FmSearchEngine - Impl class for FmSearchDialog
::cppu::WeakComponentImplHelper< css::frame::XDispatchProviderInterceptor, css::lang::XEventListener > DispatchInterceptionMultiplexer_BASE
void dispose()
std::mutex * m_pMutex