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 
22 namespace 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_aFallback()
40  ,m_pMutex( _pMaster && _pMaster->getInterceptorMutex() ? _pMaster->getInterceptorMutex() : &m_aFallback )
41  ,m_xIntercepted(_rxToIntercept)
42  ,m_bListening(false)
43  ,m_pMaster(_pMaster)
44  {
45 
46  ::osl::MutexGuard aGuard( *m_pMutex );
47  osl_atomic_increment(&m_refCount);
48  if (_rxToIntercept.is())
49  {
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())
55  {
56  xInterceptedComponent->addEventListener(this);
57  m_bListening = true;
58  }
59  }
60  osl_atomic_decrement(&m_refCount);
61  }
62 
63 
65  {
66  if (!rBHelper.bDisposed)
67  dispose();
68 
69  }
70 
71 
72  Reference< XDispatch > SAL_CALL DispatchInterceptionMultiplexer::queryDispatch( const URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags )
73  {
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);
79 
80  // ask our slave provider
81  if (!xResult.is() && m_xSlaveDispatcher.is())
82  xResult = m_xSlaveDispatcher->queryDispatch(aURL, aTargetFrameName, nSearchFlags);
83 
84  return xResult;
85  }
86 
87 
88  Sequence< Reference< XDispatch > > SAL_CALL
89  DispatchInterceptionMultiplexer::queryDispatches( const Sequence< DispatchDescriptor >& aDescripts )
90  {
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;
97  }
98 
99 
100  Reference< XDispatchProvider > SAL_CALL DispatchInterceptionMultiplexer::getSlaveDispatchProvider( )
101  {
102  ::osl::MutexGuard aGuard( *m_pMutex );
103  return m_xSlaveDispatcher;
104  }
105 
106 
107  void SAL_CALL DispatchInterceptionMultiplexer::setSlaveDispatchProvider(const Reference< XDispatchProvider>& xNewDispatchProvider)
108  {
109  ::osl::MutexGuard aGuard( *m_pMutex );
110  m_xSlaveDispatcher = xNewDispatchProvider;
111  }
112 
113 
114  Reference< XDispatchProvider> SAL_CALL DispatchInterceptionMultiplexer::getMasterDispatchProvider()
115  {
116  ::osl::MutexGuard aGuard( *m_pMutex );
117  return m_xMasterDispatcher;
118  }
119 
120 
121  void SAL_CALL DispatchInterceptionMultiplexer::setMasterDispatchProvider(const Reference< XDispatchProvider>& xNewSupplier)
122  {
123  ::osl::MutexGuard aGuard( *m_pMutex );
124  m_xMasterDispatcher = xNewSupplier;
125  }
126 
127 
128  void SAL_CALL DispatchInterceptionMultiplexer::disposing(const EventObject& Source)
129  {
130  if (m_bListening)
131  {
132  Reference< XDispatchProviderInterception > xIntercepted(m_xIntercepted.get(), UNO_QUERY);
133  if (Source.Source == xIntercepted)
134  ImplDetach();
135  }
136  }
137 
138 
140  {
141  ::osl::MutexGuard aGuard( *m_pMutex );
142  OSL_ENSURE(m_bListening, "DispatchInterceptionMultiplexer::ImplDetach: invalid call!");
143 
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));
148 
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;
155  m_bListening = false;
156  }
157 
158 
160  {
161  // remove ourself as event listener from the interception component
162  if (m_bListening)
163  {
164  Reference< XComponent> xInterceptedComponent(m_xIntercepted.get(), UNO_QUERY);
165  if (xInterceptedComponent.is())
166  xInterceptedComponent->removeEventListener(static_cast<XEventListener*>(this));
167 
168  // detach from the interception component
169  ImplDetach();
170  }
171  }
172 
173 
174 }
175 
176 
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::frame::XDispatchProvider > m_xMasterDispatcher
virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches(const css::uno::Sequence< css::frame::DispatchDescriptor > &aDescripts) override
virtual css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL getMasterDispatchProvider() override
ULONG m_refCount
css::uno::WeakReference< css::frame::XDispatchProviderInterception > m_xIntercepted
virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(const css::util::URL &aURL, const OUString &aTargetFrameName, sal_Int32 nSearchFlags) override
virtual void SAL_CALL setSlaveDispatchProvider(const css::uno::Reference< css::frame::XDispatchProvider > &xNewDispatchProvider) override
Mutex * m_pMutex
virtual css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL getSlaveDispatchProvider() override
virtual css::uno::Reference< css::frame::XDispatch > interceptedQueryDispatch(const css::util::URL &aURL, const OUString &aTargetFrameName, sal_Int32 nSearchFlags)=0
class FmSearchEngine - Impl class for FmSearchDialog
void dispose()
::cppu::WeakComponentImplHelper< css::frame::XDispatchProviderInterceptor, css::lang::XEventListener > DispatchInterceptionMultiplexer_BASE
DispatchInterceptionMultiplexer(const css::uno::Reference< css::frame::XDispatchProviderInterception > &_rToIntercept, DispatchInterceptor *_pMaster)
css::uno::Reference< css::frame::XDispatchProvider > m_xSlaveDispatcher
virtual void SAL_CALL setMasterDispatchProvider(const css::uno::Reference< css::frame::XDispatchProvider > &xNewSupplier) override