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