lok: Don't attempt to select the exact text after a failed search.
[LibreOffice.git] / svx / source / form / formdispatchinterceptor.cxx
blob2fae8dbac936e53c90195ed2a3ca33c3f5e8eb48
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::XInterface;
26 using ::com::sun::star::uno::UNO_QUERY;
27 using ::com::sun::star::uno::UNO_QUERY_THROW;
28 using ::com::sun::star::uno::UNO_SET_THROW;
29 using ::com::sun::star::uno::Exception;
30 using ::com::sun::star::uno::RuntimeException;
31 using ::com::sun::star::uno::Any;
32 using ::com::sun::star::uno::makeAny;
33 using ::com::sun::star::uno::Sequence;
34 using ::com::sun::star::uno::Type;
35 using ::com::sun::star::frame::XDispatchProviderInterception;
36 using ::com::sun::star::frame::XDispatchProviderInterceptor;
37 using ::com::sun::star::lang::XComponent;
38 using ::com::sun::star::util::URL;
39 using ::com::sun::star::frame::XDispatch;
40 using ::com::sun::star::frame::DispatchDescriptor;
41 using ::com::sun::star::frame::XDispatchProvider;
42 using ::com::sun::star::lang::EventObject;
44 DispatchInterceptionMultiplexer::DispatchInterceptionMultiplexer(
45 const Reference< XDispatchProviderInterception >& _rxToIntercept, DispatchInterceptor* _pMaster )
46 :DispatchInterceptionMultiplexer_BASE(_pMaster && _pMaster->getInterceptorMutex() ? *_pMaster->getInterceptorMutex() : m_aFallback)
47 ,m_aFallback()
48 ,m_pMutex( _pMaster && _pMaster->getInterceptorMutex() ? _pMaster->getInterceptorMutex() : &m_aFallback )
49 ,m_xIntercepted(_rxToIntercept)
50 ,m_bListening(false)
51 ,m_pMaster(_pMaster)
54 ::osl::MutexGuard aGuard( *m_pMutex );
55 osl_atomic_increment(&m_refCount);
56 if (_rxToIntercept.is())
58 _rxToIntercept->registerDispatchProviderInterceptor((XDispatchProviderInterceptor*)this);
59 // this should make us the top-level dispatch-provider for the component, via a call to our
60 // setDispatchProvider we should have got an fallback for requests we (i.e. our master) cannot fulfill
61 Reference< XComponent> xInterceptedComponent(_rxToIntercept, UNO_QUERY);
62 if (xInterceptedComponent.is())
64 xInterceptedComponent->addEventListener(this);
65 m_bListening = true;
68 osl_atomic_decrement(&m_refCount);
72 DispatchInterceptionMultiplexer::~DispatchInterceptionMultiplexer()
74 if (!rBHelper.bDisposed)
75 dispose();
80 Reference< XDispatch > SAL_CALL DispatchInterceptionMultiplexer::queryDispatch( const URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags ) throw(RuntimeException, std::exception)
82 ::osl::MutexGuard aGuard( *m_pMutex );
83 Reference< XDispatch> xResult;
84 // ask our 'real' interceptor
85 if (m_pMaster)
86 xResult = m_pMaster->interceptedQueryDispatch( aURL, aTargetFrameName, nSearchFlags);
88 // ask our slave provider
89 if (!xResult.is() && m_xSlaveDispatcher.is())
90 xResult = m_xSlaveDispatcher->queryDispatch(aURL, aTargetFrameName, nSearchFlags);
92 return xResult;
96 Sequence< Reference< XDispatch > > SAL_CALL
97 DispatchInterceptionMultiplexer::queryDispatches( const Sequence< DispatchDescriptor >& aDescripts ) throw(RuntimeException, std::exception)
99 ::osl::MutexGuard aGuard( *m_pMutex );
100 Sequence< Reference< XDispatch> > aReturn(aDescripts.getLength());
101 Reference< XDispatch>* pReturn = aReturn.getArray();
102 const DispatchDescriptor* pDescripts = aDescripts.getConstArray();
103 for (sal_Int16 i=0; i<aDescripts.getLength(); ++i, ++pReturn, ++pDescripts)
105 *pReturn = queryDispatch(pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags);
107 return aReturn;
111 Reference< XDispatchProvider > SAL_CALL DispatchInterceptionMultiplexer::getSlaveDispatchProvider( ) throw(RuntimeException, std::exception)
113 ::osl::MutexGuard aGuard( *m_pMutex );
114 return m_xSlaveDispatcher;
118 void SAL_CALL DispatchInterceptionMultiplexer::setSlaveDispatchProvider(const Reference< XDispatchProvider>& xNewDispatchProvider) throw( RuntimeException, std::exception )
120 ::osl::MutexGuard aGuard( *m_pMutex );
121 m_xSlaveDispatcher = xNewDispatchProvider;
125 Reference< XDispatchProvider> SAL_CALL DispatchInterceptionMultiplexer::getMasterDispatchProvider() throw( RuntimeException, std::exception )
127 ::osl::MutexGuard aGuard( *m_pMutex );
128 return m_xMasterDispatcher;
132 void SAL_CALL DispatchInterceptionMultiplexer::setMasterDispatchProvider(const Reference< XDispatchProvider>& xNewSupplier) throw( RuntimeException, std::exception )
134 ::osl::MutexGuard aGuard( *m_pMutex );
135 m_xMasterDispatcher = xNewSupplier;
139 void SAL_CALL DispatchInterceptionMultiplexer::disposing(const EventObject& Source) throw( RuntimeException, std::exception )
141 if (m_bListening)
143 Reference< XDispatchProviderInterception > xIntercepted(m_xIntercepted.get(), UNO_QUERY);
144 if (Source.Source == xIntercepted)
145 ImplDetach();
150 void DispatchInterceptionMultiplexer::ImplDetach()
152 ::osl::MutexGuard aGuard( *m_pMutex );
153 OSL_ENSURE(m_bListening, "DispatchInterceptionMultiplexer::ImplDetach: invalid call!");
155 // deregister ourself from the interception component
156 Reference< XDispatchProviderInterception > xIntercepted(m_xIntercepted.get(), UNO_QUERY);
157 if (xIntercepted.is())
158 xIntercepted->releaseDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor*>(this));
160 // m_xIntercepted = Reference< XDispatchProviderInterception >();
161 // Don't reset m_xIntercepted: It may be needed by our owner to check for which object we were
162 // responsible. As we hold the object with a weak reference only, this should be no problem.
163 // 88936 - 23.07.2001 - frank.schoenheit@sun.com
164 m_pMaster = NULL;
165 m_pMutex = &m_aFallback;
166 m_bListening = false;
170 void DispatchInterceptionMultiplexer::disposing()
172 // remove ourself as event listener from the interception component
173 if (m_bListening)
175 Reference< XComponent> xInterceptedComponent(m_xIntercepted.get(), UNO_QUERY);
176 if (xInterceptedComponent.is())
177 xInterceptedComponent->removeEventListener(static_cast<XEventListener*>(this));
179 // detach from the interception component
180 ImplDetach();
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */