Branch data Line data Source code
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 : :
20 : : #include "formdispatchinterceptor.hxx"
21 : :
22 : : #include <tools/debug.hxx>
23 : :
24 : : //........................................................................
25 : : namespace svxform
26 : : {
27 : : //........................................................................
28 : :
29 : : /** === begin UNO using === **/
30 : : using ::com::sun::star::uno::Reference;
31 : : using ::com::sun::star::uno::XInterface;
32 : : using ::com::sun::star::uno::UNO_QUERY;
33 : : using ::com::sun::star::uno::UNO_QUERY_THROW;
34 : : using ::com::sun::star::uno::UNO_SET_THROW;
35 : : using ::com::sun::star::uno::Exception;
36 : : using ::com::sun::star::uno::RuntimeException;
37 : : using ::com::sun::star::uno::Any;
38 : : using ::com::sun::star::uno::makeAny;
39 : : using ::com::sun::star::uno::Sequence;
40 : : using ::com::sun::star::uno::Type;
41 : : using ::com::sun::star::frame::XDispatchProviderInterception;
42 : : using ::com::sun::star::frame::XDispatchProviderInterceptor;
43 : : using ::com::sun::star::lang::XComponent;
44 : : using ::com::sun::star::util::URL;
45 : : using ::com::sun::star::frame::XDispatch;
46 : : using ::com::sun::star::frame::DispatchDescriptor;
47 : : using ::com::sun::star::frame::XDispatchProvider;
48 : : using ::com::sun::star::lang::EventObject;
49 : : /** === end UNO using === **/
50 : :
51 : : //========================================================================
52 : : //= DispatchInterceptionMultiplexer
53 : : //========================================================================
54 : :
55 : : DBG_NAME(DispatchInterceptionMultiplexer)
56 : : //------------------------------------------------------------------------
57 : 18 : DispatchInterceptionMultiplexer::DispatchInterceptionMultiplexer(
58 : : const Reference< XDispatchProviderInterception >& _rxToIntercept, DispatchInterceptor* _pMaster )
59 : 18 : :DispatchInterceptionMultiplexer_BASE(_pMaster && _pMaster->getInterceptorMutex() ? *_pMaster->getInterceptorMutex() : m_aFallback)
60 : : ,m_aFallback()
61 [ + - ]: 18 : ,m_pMutex( _pMaster && _pMaster->getInterceptorMutex() ? _pMaster->getInterceptorMutex() : &m_aFallback )
62 : : ,m_xIntercepted(_rxToIntercept)
63 : : ,m_bListening(sal_False)
64 [ + - + - ]: 54 : ,m_pMaster(_pMaster)
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
65 : : {
66 : : DBG_CTOR(DispatchInterceptionMultiplexer,NULL);
67 : :
68 [ + - ]: 18 : ::osl::MutexGuard aGuard( *m_pMutex );
69 [ + - ]: 18 : ::comphelper::increment(m_refCount);
70 [ + - ]: 18 : if (_rxToIntercept.is())
71 : : {
72 [ + - ][ + - ]: 18 : _rxToIntercept->registerDispatchProviderInterceptor((XDispatchProviderInterceptor*)this);
[ + - ]
73 : : // this should make us the top-level dispatch-provider for the component, via a call to our
74 : : // setDispatchProvider we should have got an fallback for requests we (i.e. our master) cannot fullfill
75 [ + - ]: 18 : Reference< XComponent> xInterceptedComponent(_rxToIntercept, UNO_QUERY);
76 [ + - ]: 18 : if (xInterceptedComponent.is())
77 : : {
78 [ + - ][ + - ]: 18 : xInterceptedComponent->addEventListener(this);
[ + - ]
79 : 18 : m_bListening = sal_True;
80 : 18 : }
81 : : }
82 [ + - ][ + - ]: 18 : ::comphelper::decrement(m_refCount);
83 : 18 : }
84 : :
85 : : //------------------------------------------------------------------------
86 [ + - ][ + - ]: 18 : DispatchInterceptionMultiplexer::~DispatchInterceptionMultiplexer()
87 : : {
88 [ - + ]: 18 : if (!rBHelper.bDisposed)
89 [ # # ]: 0 : dispose();
90 : :
91 : : DBG_DTOR(DispatchInterceptionMultiplexer,NULL);
92 [ - + ]: 36 : }
93 : :
94 : : //------------------------------------------------------------------------------
95 : 0 : Reference< XDispatch > SAL_CALL DispatchInterceptionMultiplexer::queryDispatch( const URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags ) throw(RuntimeException)
96 : : {
97 [ # # ]: 0 : ::osl::MutexGuard aGuard( *m_pMutex );
98 : 0 : Reference< XDispatch> xResult;
99 : : // ask our 'real' interceptor
100 [ # # ]: 0 : if (m_pMaster)
101 [ # # ][ # # ]: 0 : xResult = m_pMaster->interceptedQueryDispatch( aURL, aTargetFrameName, nSearchFlags);
102 : :
103 : : // ask our slave provider
104 [ # # ][ # # ]: 0 : if (!xResult.is() && m_xSlaveDispatcher.is())
[ # # ]
105 [ # # ][ # # ]: 0 : xResult = m_xSlaveDispatcher->queryDispatch(aURL, aTargetFrameName, nSearchFlags);
[ # # ]
106 : :
107 [ # # ]: 0 : return xResult;
108 : : }
109 : :
110 : : //------------------------------------------------------------------------------
111 : : Sequence< Reference< XDispatch > > SAL_CALL
112 : 0 : DispatchInterceptionMultiplexer::queryDispatches( const Sequence< DispatchDescriptor >& aDescripts ) throw(RuntimeException)
113 : : {
114 [ # # ]: 0 : ::osl::MutexGuard aGuard( *m_pMutex );
115 [ # # ]: 0 : Sequence< Reference< XDispatch> > aReturn(aDescripts.getLength());
116 [ # # ]: 0 : Reference< XDispatch>* pReturn = aReturn.getArray();
117 : 0 : const DispatchDescriptor* pDescripts = aDescripts.getConstArray();
118 [ # # ]: 0 : for (sal_Int16 i=0; i<aDescripts.getLength(); ++i, ++pReturn, ++pDescripts)
119 : : {
120 [ # # ][ # # ]: 0 : *pReturn = queryDispatch(pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags);
121 : : }
122 [ # # ]: 0 : return aReturn;
123 : : }
124 : :
125 : : //------------------------------------------------------------------------------
126 : 72 : Reference< XDispatchProvider > SAL_CALL DispatchInterceptionMultiplexer::getSlaveDispatchProvider( ) throw(RuntimeException)
127 : : {
128 [ + - ]: 72 : ::osl::MutexGuard aGuard( *m_pMutex );
129 [ + - ]: 72 : return m_xSlaveDispatcher;
130 : : }
131 : :
132 : : //------------------------------------------------------------------------------
133 : 36 : void SAL_CALL DispatchInterceptionMultiplexer::setSlaveDispatchProvider(const Reference< XDispatchProvider>& xNewDispatchProvider) throw( RuntimeException )
134 : : {
135 [ + - ]: 36 : ::osl::MutexGuard aGuard( *m_pMutex );
136 [ + - ][ + - ]: 36 : m_xSlaveDispatcher = xNewDispatchProvider;
137 : 36 : }
138 : :
139 : : //------------------------------------------------------------------------------
140 : 36 : Reference< XDispatchProvider> SAL_CALL DispatchInterceptionMultiplexer::getMasterDispatchProvider(void) throw( RuntimeException )
141 : : {
142 [ + - ]: 36 : ::osl::MutexGuard aGuard( *m_pMutex );
143 [ + - ]: 36 : return m_xMasterDispatcher;
144 : : }
145 : :
146 : : //------------------------------------------------------------------------------
147 : 72 : void SAL_CALL DispatchInterceptionMultiplexer::setMasterDispatchProvider(const Reference< XDispatchProvider>& xNewSupplier) throw( RuntimeException )
148 : : {
149 [ + - ]: 72 : ::osl::MutexGuard aGuard( *m_pMutex );
150 [ + - ][ + - ]: 72 : m_xMasterDispatcher = xNewSupplier;
151 : 72 : }
152 : :
153 : : //------------------------------------------------------------------------------
154 : 0 : void SAL_CALL DispatchInterceptionMultiplexer::disposing(const EventObject& Source) throw( RuntimeException )
155 : : {
156 [ # # ]: 0 : if (m_bListening)
157 : : {
158 [ # # ][ # # ]: 0 : Reference< XDispatchProviderInterception > xIntercepted(m_xIntercepted.get(), UNO_QUERY);
159 [ # # ][ # # ]: 0 : if (Source.Source == xIntercepted)
160 [ # # ]: 0 : ImplDetach();
161 : : }
162 : 0 : }
163 : :
164 : : //------------------------------------------------------------------------------
165 : 18 : void DispatchInterceptionMultiplexer::ImplDetach()
166 : : {
167 [ + - ]: 18 : ::osl::MutexGuard aGuard( *m_pMutex );
168 : : OSL_ENSURE(m_bListening, "DispatchInterceptionMultiplexer::ImplDetach: invalid call!");
169 : :
170 : : // deregister ourself from the interception component
171 [ + - ][ + - ]: 18 : Reference< XDispatchProviderInterception > xIntercepted(m_xIntercepted.get(), UNO_QUERY);
172 [ + - ]: 18 : if (xIntercepted.is())
173 [ + - ][ + - ]: 18 : xIntercepted->releaseDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor*>(this));
[ + - ]
174 : :
175 : : // m_xIntercepted = Reference< XDispatchProviderInterception >();
176 : : // Don't reset m_xIntercepted: It may be needed by our owner to check for which object we were
177 : : // responsible. As we hold the object with a weak reference only, this should be no problem.
178 : : // 88936 - 23.07.2001 - frank.schoenheit@sun.com
179 : 18 : m_pMaster = NULL;
180 : 18 : m_pMutex = &m_aFallback;
181 [ + - ]: 18 : m_bListening = sal_False;
182 : 18 : }
183 : :
184 : : //------------------------------------------------------------------------------
185 : 18 : void DispatchInterceptionMultiplexer::disposing()
186 : : {
187 : : // remove ourself as event listener from the interception component
188 [ + - ]: 18 : if (m_bListening)
189 : : {
190 [ + - ][ + - ]: 18 : Reference< XComponent> xInterceptedComponent(m_xIntercepted.get(), UNO_QUERY);
191 [ + - ]: 18 : if (xInterceptedComponent.is())
192 [ + - ][ + - ]: 18 : xInterceptedComponent->removeEventListener(static_cast<XEventListener*>(this));
[ + - ]
193 : :
194 : : // detach from the interception component
195 [ + - ]: 18 : ImplDetach();
196 : : }
197 : 18 : }
198 : :
199 : : //........................................................................
200 : : } // namespace svxform
201 : : //........................................................................
202 : :
203 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|