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