Update ooo320-m1
[ooovba.git] / forms / source / helper / controlfeatureinterception.cxx
blobddb14d364392b89ee9b875cace70ec3bd0598f37
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: controlfeatureinterception.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_forms.hxx"
33 #include "controlfeatureinterception.hxx"
34 #include "urltransformer.hxx"
36 /** === begin UNO includes === **/
37 /** === end UNO includes === **/
38 #include <tools/debug.hxx>
40 //........................................................................
41 namespace frm
43 //........................................................................
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::frame;
47 using namespace ::com::sun::star::util;
48 using namespace ::com::sun::star::lang;
50 //====================================================================
51 //= ControlFeatureInterception
52 //====================================================================
53 //--------------------------------------------------------------------
54 ControlFeatureInterception::ControlFeatureInterception( const Reference< XMultiServiceFactory >& _rxORB )
55 :m_pUrlTransformer( new UrlTransformer( _rxORB ) )
59 //--------------------------------------------------------------------
60 void SAL_CALL ControlFeatureInterception::registerDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException )
62 if ( !_rxInterceptor.is() )
64 DBG_ERROR( "ControlFeatureInterception::registerDispatchProviderInterceptor: invalid interceptor!" );
65 return;
68 if ( m_xFirstDispatchInterceptor.is() )
70 // there is already an interceptor; the new one will become its master
71 Reference< XDispatchProvider > xFirstProvider( m_xFirstDispatchInterceptor, UNO_QUERY );
72 _rxInterceptor->setSlaveDispatchProvider( xFirstProvider );
73 m_xFirstDispatchInterceptor->setMasterDispatchProvider( xFirstProvider );
76 // we are the master of the chain's first interceptor
77 m_xFirstDispatchInterceptor = _rxInterceptor;
78 m_xFirstDispatchInterceptor->setMasterDispatchProvider( NULL );
79 // it's the first of the interceptor chain
82 //--------------------------------------------------------------------
83 void SAL_CALL ControlFeatureInterception::releaseDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException )
85 if ( !_rxInterceptor.is() )
87 DBG_ERROR( "ControlFeatureInterception::releaseDispatchProviderInterceptor: invalid interceptor!" );
88 return;
91 Reference< XDispatchProviderInterceptor > xChainWalk( m_xFirstDispatchInterceptor );
93 if ( m_xFirstDispatchInterceptor == _rxInterceptor )
94 { // our chain will have a new first element
95 Reference< XDispatchProviderInterceptor > xSlave( m_xFirstDispatchInterceptor->getSlaveDispatchProvider(), UNO_QUERY );
96 m_xFirstDispatchInterceptor = xSlave;
98 // do this before removing the interceptor from the chain as we won't know it's slave afterwards)
100 while ( xChainWalk.is() )
102 // walk along the chain of interceptors and look for the interceptor that has to be removed
103 Reference< XDispatchProviderInterceptor > xSlave( xChainWalk->getSlaveDispatchProvider(), UNO_QUERY );
105 if ( xChainWalk == _rxInterceptor )
107 // old master may be an interceptor too
108 Reference< XDispatchProviderInterceptor > xMaster( xChainWalk->getMasterDispatchProvider(), UNO_QUERY );
110 // unchain the interceptor that has to be removed
111 xChainWalk->setSlaveDispatchProvider( NULL );
112 xChainWalk->setMasterDispatchProvider( NULL );
114 // reconnect the chain
115 if ( xMaster.is() )
117 xMaster->setSlaveDispatchProvider( Reference< XDispatchProvider >::query( xSlave ) );
120 // if somebody has registered the same interceptor twice, then we will remove
121 // it once per call ...
122 break;
125 xChainWalk = xSlave;
129 //--------------------------------------------------------------------
130 void ControlFeatureInterception::dispose()
132 // release all interceptors
133 Reference< XDispatchProviderInterceptor > xInterceptor( m_xFirstDispatchInterceptor );
134 m_xFirstDispatchInterceptor.clear();
135 while ( xInterceptor.is() )
137 // tell the interceptor it has a new (means no) predecessor
138 xInterceptor->setMasterDispatchProvider( NULL );
140 // ask for it's successor
141 Reference< XDispatchProvider > xSlave = xInterceptor->getSlaveDispatchProvider();
142 // and give it the new (means no) successoert
143 xInterceptor->setSlaveDispatchProvider( NULL );
145 // start over with the next chain element
146 xInterceptor = xInterceptor.query( xSlave );
149 //--------------------------------------------------------------------
150 Reference< XDispatch > ControlFeatureInterception::queryDispatch( const URL& _rURL, const ::rtl::OUString& _rTargetFrameName, ::sal_Int32 _nSearchFlags ) SAL_THROW((RuntimeException))
152 Reference< XDispatch > xDispatcher;
153 if ( m_xFirstDispatchInterceptor.is() )
154 xDispatcher = m_xFirstDispatchInterceptor->queryDispatch( _rURL, _rTargetFrameName, _nSearchFlags );
155 return xDispatcher;
158 //--------------------------------------------------------------------
159 Reference< XDispatch > ControlFeatureInterception::queryDispatch( const URL& _rURL ) SAL_THROW((RuntimeException))
161 return queryDispatch( _rURL, ::rtl::OUString(), 0 );
164 //--------------------------------------------------------------------
165 Reference< XDispatch > ControlFeatureInterception::queryDispatch( const sal_Char* _pAsciiURL ) SAL_THROW((RuntimeException))
167 return queryDispatch( m_pUrlTransformer->getStrictURLFromAscii( _pAsciiURL ) );
170 //........................................................................
171 } // namespace frm
172 //........................................................................