1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 #include "formdispatchinterceptor.hxx"
31 /** === begin UNO includes === **/
32 /** === end UNO includes === **/
34 #include <tools/debug.hxx>
36 //........................................................................
39 //........................................................................
41 /** === begin UNO using === **/
42 using ::com::sun::star::uno::Reference
;
43 using ::com::sun::star::uno::XInterface
;
44 using ::com::sun::star::uno::UNO_QUERY
;
45 using ::com::sun::star::uno::UNO_QUERY_THROW
;
46 using ::com::sun::star::uno::UNO_SET_THROW
;
47 using ::com::sun::star::uno::Exception
;
48 using ::com::sun::star::uno::RuntimeException
;
49 using ::com::sun::star::uno::Any
;
50 using ::com::sun::star::uno::makeAny
;
51 using ::com::sun::star::uno::Sequence
;
52 using ::com::sun::star::uno::Type
;
53 using ::com::sun::star::frame::XDispatchProviderInterception
;
54 using ::com::sun::star::frame::XDispatchProviderInterceptor
;
55 using ::com::sun::star::lang::XComponent
;
56 using ::com::sun::star::util::URL
;
57 using ::com::sun::star::frame::XDispatch
;
58 using ::com::sun::star::frame::DispatchDescriptor
;
59 using ::com::sun::star::frame::XDispatchProvider
;
60 using ::com::sun::star::lang::EventObject
;
61 /** === end UNO using === **/
63 //========================================================================
64 //= DispatchInterceptionMultiplexer
65 //========================================================================
67 DBG_NAME(DispatchInterceptionMultiplexer
)
68 //------------------------------------------------------------------------
69 DispatchInterceptionMultiplexer::DispatchInterceptionMultiplexer(
70 const Reference
< XDispatchProviderInterception
>& _rxToIntercept
, DispatchInterceptor
* _pMaster
)
71 :DispatchInterceptionMultiplexer_BASE(_pMaster
&& _pMaster
->getInterceptorMutex() ? *_pMaster
->getInterceptorMutex() : m_aFallback
)
73 ,m_pMutex( _pMaster
&& _pMaster
->getInterceptorMutex() ? _pMaster
->getInterceptorMutex() : &m_aFallback
)
74 ,m_xIntercepted(_rxToIntercept
)
75 ,m_bListening(sal_False
)
78 DBG_CTOR(DispatchInterceptionMultiplexer
,NULL
);
80 ::osl::MutexGuard
aGuard( *m_pMutex
);
81 ::comphelper::increment(m_refCount
);
82 if (_rxToIntercept
.is())
84 _rxToIntercept
->registerDispatchProviderInterceptor((XDispatchProviderInterceptor
*)this);
85 // this should make us the top-level dispatch-provider for the component, via a call to our
86 // setDispatchProvider we should have got an fallback for requests we (i.e. our master) cannot fullfill
87 Reference
< XComponent
> xInterceptedComponent(_rxToIntercept
, UNO_QUERY
);
88 if (xInterceptedComponent
.is())
90 xInterceptedComponent
->addEventListener(this);
91 m_bListening
= sal_True
;
94 ::comphelper::decrement(m_refCount
);
97 //------------------------------------------------------------------------
98 DispatchInterceptionMultiplexer::~DispatchInterceptionMultiplexer()
100 if (!rBHelper
.bDisposed
)
103 DBG_DTOR(DispatchInterceptionMultiplexer
,NULL
);
106 //------------------------------------------------------------------------------
107 Reference
< XDispatch
> SAL_CALL
DispatchInterceptionMultiplexer::queryDispatch( const URL
& aURL
, const ::rtl::OUString
& aTargetFrameName
, sal_Int32 nSearchFlags
) throw(RuntimeException
)
109 ::osl::MutexGuard
aGuard( *m_pMutex
);
110 Reference
< XDispatch
> xResult
;
111 // ask our 'real' interceptor
113 xResult
= m_pMaster
->interceptedQueryDispatch( aURL
, aTargetFrameName
, nSearchFlags
);
115 // ask our slave provider
116 if (!xResult
.is() && m_xSlaveDispatcher
.is())
117 xResult
= m_xSlaveDispatcher
->queryDispatch(aURL
, aTargetFrameName
, nSearchFlags
);
122 //------------------------------------------------------------------------------
123 Sequence
< Reference
< XDispatch
> > SAL_CALL
124 DispatchInterceptionMultiplexer::queryDispatches( const Sequence
< DispatchDescriptor
>& aDescripts
) throw(RuntimeException
)
126 ::osl::MutexGuard
aGuard( *m_pMutex
);
127 Sequence
< Reference
< XDispatch
> > aReturn(aDescripts
.getLength());
128 Reference
< XDispatch
>* pReturn
= aReturn
.getArray();
129 const DispatchDescriptor
* pDescripts
= aDescripts
.getConstArray();
130 for (sal_Int16 i
=0; i
<aDescripts
.getLength(); ++i
, ++pReturn
, ++pDescripts
)
132 *pReturn
= queryDispatch(pDescripts
->FeatureURL
, pDescripts
->FrameName
, pDescripts
->SearchFlags
);
137 //------------------------------------------------------------------------------
138 Reference
< XDispatchProvider
> SAL_CALL
DispatchInterceptionMultiplexer::getSlaveDispatchProvider( ) throw(RuntimeException
)
140 ::osl::MutexGuard
aGuard( *m_pMutex
);
141 return m_xSlaveDispatcher
;
144 //------------------------------------------------------------------------------
145 void SAL_CALL
DispatchInterceptionMultiplexer::setSlaveDispatchProvider(const Reference
< XDispatchProvider
>& xNewDispatchProvider
) throw( RuntimeException
)
147 ::osl::MutexGuard
aGuard( *m_pMutex
);
148 m_xSlaveDispatcher
= xNewDispatchProvider
;
151 //------------------------------------------------------------------------------
152 Reference
< XDispatchProvider
> SAL_CALL
DispatchInterceptionMultiplexer::getMasterDispatchProvider(void) throw( RuntimeException
)
154 ::osl::MutexGuard
aGuard( *m_pMutex
);
155 return m_xMasterDispatcher
;
158 //------------------------------------------------------------------------------
159 void SAL_CALL
DispatchInterceptionMultiplexer::setMasterDispatchProvider(const Reference
< XDispatchProvider
>& xNewSupplier
) throw( RuntimeException
)
161 ::osl::MutexGuard
aGuard( *m_pMutex
);
162 m_xMasterDispatcher
= xNewSupplier
;
165 //------------------------------------------------------------------------------
166 void SAL_CALL
DispatchInterceptionMultiplexer::disposing(const EventObject
& Source
) throw( RuntimeException
)
170 Reference
< XDispatchProviderInterception
> xIntercepted(m_xIntercepted
.get(), UNO_QUERY
);
171 if (Source
.Source
== xIntercepted
)
176 //------------------------------------------------------------------------------
177 void DispatchInterceptionMultiplexer::ImplDetach()
179 ::osl::MutexGuard
aGuard( *m_pMutex
);
180 OSL_ENSURE(m_bListening
, "DispatchInterceptionMultiplexer::ImplDetach: invalid call!");
182 // deregister ourself from the interception component
183 Reference
< XDispatchProviderInterception
> xIntercepted(m_xIntercepted
.get(), UNO_QUERY
);
184 if (xIntercepted
.is())
185 xIntercepted
->releaseDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor
*>(this));
187 // m_xIntercepted = Reference< XDispatchProviderInterception >();
188 // Don't reset m_xIntercepted: It may be needed by our owner to check for which object we were
189 // responsible. As we hold the object with a weak reference only, this should be no problem.
190 // 88936 - 23.07.2001 - frank.schoenheit@sun.com
192 m_pMutex
= &m_aFallback
;
193 m_bListening
= sal_False
;
196 //------------------------------------------------------------------------------
197 void DispatchInterceptionMultiplexer::disposing()
199 // remove ourself as event listener from the interception component
202 Reference
< XComponent
> xInterceptedComponent(m_xIntercepted
.get(), UNO_QUERY
);
203 if (xInterceptedComponent
.is())
204 xInterceptedComponent
->removeEventListener(static_cast<XEventListener
*>(this));
206 // detach from the interception component
211 //........................................................................
212 } // namespace svxform
213 //........................................................................
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */