1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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_pMutex( _pMaster
&& _pMaster
->getInterceptorMutex() ? _pMaster
->getInterceptorMutex() : &m_aFallback
)
40 ,m_xIntercepted(_rxToIntercept
)
45 ::osl::MutexGuard
aGuard( *m_pMutex
);
46 osl_atomic_increment(&m_refCount
);
47 if (_rxToIntercept
.is())
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())
55 xInterceptedComponent
->addEventListener(this);
59 osl_atomic_decrement(&m_refCount
);
63 DispatchInterceptionMultiplexer::~DispatchInterceptionMultiplexer()
65 if (!rBHelper
.bDisposed
)
71 Reference
< XDispatch
> SAL_CALL
DispatchInterceptionMultiplexer::queryDispatch( const URL
& aURL
, const OUString
& aTargetFrameName
, sal_Int32 nSearchFlags
)
73 ::osl::MutexGuard
aGuard( *m_pMutex
);
74 Reference
< XDispatch
> xResult
;
75 // ask our 'real' interceptor
77 xResult
= m_pMaster
->interceptedQueryDispatch( aURL
, aTargetFrameName
, nSearchFlags
);
79 // ask our slave provider
80 if (!xResult
.is() && m_xSlaveDispatcher
.is())
81 xResult
= m_xSlaveDispatcher
->queryDispatch(aURL
, aTargetFrameName
, nSearchFlags
);
87 Sequence
< Reference
< XDispatch
> > SAL_CALL
88 DispatchInterceptionMultiplexer::queryDispatches( const Sequence
< DispatchDescriptor
>& aDescripts
)
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
); });
99 Reference
< XDispatchProvider
> SAL_CALL
DispatchInterceptionMultiplexer::getSlaveDispatchProvider( )
101 ::osl::MutexGuard
aGuard( *m_pMutex
);
102 return m_xSlaveDispatcher
;
106 void SAL_CALL
DispatchInterceptionMultiplexer::setSlaveDispatchProvider(const Reference
< XDispatchProvider
>& xNewDispatchProvider
)
108 ::osl::MutexGuard
aGuard( *m_pMutex
);
109 m_xSlaveDispatcher
= xNewDispatchProvider
;
113 Reference
< XDispatchProvider
> SAL_CALL
DispatchInterceptionMultiplexer::getMasterDispatchProvider()
115 ::osl::MutexGuard
aGuard( *m_pMutex
);
116 return m_xMasterDispatcher
;
120 void SAL_CALL
DispatchInterceptionMultiplexer::setMasterDispatchProvider(const Reference
< XDispatchProvider
>& xNewSupplier
)
122 ::osl::MutexGuard
aGuard( *m_pMutex
);
123 m_xMasterDispatcher
= xNewSupplier
;
127 void SAL_CALL
DispatchInterceptionMultiplexer::disposing(const EventObject
& Source
)
131 Reference
< XDispatchProviderInterception
> xIntercepted(m_xIntercepted
.get(), UNO_QUERY
);
132 if (Source
.Source
== xIntercepted
)
138 void DispatchInterceptionMultiplexer::ImplDetach()
140 ::osl::MutexGuard
aGuard( *m_pMutex
);
141 OSL_ENSURE(m_bListening
, "DispatchInterceptionMultiplexer::ImplDetach: invalid call!");
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));
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
153 m_pMutex
= &m_aFallback
;
154 m_bListening
= false;
158 void DispatchInterceptionMultiplexer::disposing()
160 // remove ourself as event listener from the interception component
163 Reference
< XComponent
> xInterceptedComponent(m_xIntercepted
.get(), UNO_QUERY
);
164 if (xInterceptedComponent
.is())
165 xInterceptedComponent
->removeEventListener(static_cast<XEventListener
*>(this));
167 // detach from the interception component
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */