1*24acc546SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*24acc546SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*24acc546SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*24acc546SAndrew Rist * distributed with this work for additional information 6*24acc546SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*24acc546SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*24acc546SAndrew Rist * "License"); you may not use this file except in compliance 9*24acc546SAndrew Rist * with the License. You may obtain a copy of the License at 10*24acc546SAndrew Rist * 11*24acc546SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*24acc546SAndrew Rist * 13*24acc546SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*24acc546SAndrew Rist * software distributed under the License is distributed on an 15*24acc546SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*24acc546SAndrew Rist * KIND, either express or implied. See the License for the 17*24acc546SAndrew Rist * specific language governing permissions and limitations 18*24acc546SAndrew Rist * under the License. 19*24acc546SAndrew Rist * 20*24acc546SAndrew Rist *************************************************************/ 21*24acc546SAndrew Rist 22*24acc546SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_forms.hxx" 26cdf0e10cSrcweir #include "controlfeatureinterception.hxx" 27cdf0e10cSrcweir #include "urltransformer.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir /** === begin UNO includes === **/ 30cdf0e10cSrcweir /** === end UNO includes === **/ 31cdf0e10cSrcweir #include <tools/debug.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir //........................................................................ 34cdf0e10cSrcweir namespace frm 35cdf0e10cSrcweir { 36cdf0e10cSrcweir //........................................................................ 37cdf0e10cSrcweir 38cdf0e10cSrcweir using namespace ::com::sun::star::uno; 39cdf0e10cSrcweir using namespace ::com::sun::star::frame; 40cdf0e10cSrcweir using namespace ::com::sun::star::util; 41cdf0e10cSrcweir using namespace ::com::sun::star::lang; 42cdf0e10cSrcweir 43cdf0e10cSrcweir //==================================================================== 44cdf0e10cSrcweir //= ControlFeatureInterception 45cdf0e10cSrcweir //==================================================================== 46cdf0e10cSrcweir //-------------------------------------------------------------------- ControlFeatureInterception(const Reference<XMultiServiceFactory> & _rxORB)47cdf0e10cSrcweir ControlFeatureInterception::ControlFeatureInterception( const Reference< XMultiServiceFactory >& _rxORB ) 48cdf0e10cSrcweir :m_pUrlTransformer( new UrlTransformer( _rxORB ) ) 49cdf0e10cSrcweir { 50cdf0e10cSrcweir } 51cdf0e10cSrcweir 52cdf0e10cSrcweir //-------------------------------------------------------------------- registerDispatchProviderInterceptor(const Reference<XDispatchProviderInterceptor> & _rxInterceptor)53cdf0e10cSrcweir void SAL_CALL ControlFeatureInterception::registerDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException ) 54cdf0e10cSrcweir { 55cdf0e10cSrcweir if ( !_rxInterceptor.is() ) 56cdf0e10cSrcweir { 57cdf0e10cSrcweir DBG_ERROR( "ControlFeatureInterception::registerDispatchProviderInterceptor: invalid interceptor!" ); 58cdf0e10cSrcweir return; 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir if ( m_xFirstDispatchInterceptor.is() ) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir // there is already an interceptor; the new one will become its master 64cdf0e10cSrcweir Reference< XDispatchProvider > xFirstProvider( m_xFirstDispatchInterceptor, UNO_QUERY ); 65cdf0e10cSrcweir _rxInterceptor->setSlaveDispatchProvider( xFirstProvider ); 66cdf0e10cSrcweir m_xFirstDispatchInterceptor->setMasterDispatchProvider( xFirstProvider ); 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir // we are the master of the chain's first interceptor 70cdf0e10cSrcweir m_xFirstDispatchInterceptor = _rxInterceptor; 71cdf0e10cSrcweir m_xFirstDispatchInterceptor->setMasterDispatchProvider( NULL ); 72cdf0e10cSrcweir // it's the first of the interceptor chain 73cdf0e10cSrcweir } 74cdf0e10cSrcweir 75cdf0e10cSrcweir //-------------------------------------------------------------------- releaseDispatchProviderInterceptor(const Reference<XDispatchProviderInterceptor> & _rxInterceptor)76cdf0e10cSrcweir void SAL_CALL ControlFeatureInterception::releaseDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException ) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir if ( !_rxInterceptor.is() ) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir DBG_ERROR( "ControlFeatureInterception::releaseDispatchProviderInterceptor: invalid interceptor!" ); 81cdf0e10cSrcweir return; 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir Reference< XDispatchProviderInterceptor > xChainWalk( m_xFirstDispatchInterceptor ); 85cdf0e10cSrcweir 86cdf0e10cSrcweir if ( m_xFirstDispatchInterceptor == _rxInterceptor ) 87cdf0e10cSrcweir { // our chain will have a new first element 88cdf0e10cSrcweir Reference< XDispatchProviderInterceptor > xSlave( m_xFirstDispatchInterceptor->getSlaveDispatchProvider(), UNO_QUERY ); 89cdf0e10cSrcweir m_xFirstDispatchInterceptor = xSlave; 90cdf0e10cSrcweir } 91cdf0e10cSrcweir // do this before removing the interceptor from the chain as we won't know it's slave afterwards) 92cdf0e10cSrcweir 93cdf0e10cSrcweir while ( xChainWalk.is() ) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir // walk along the chain of interceptors and look for the interceptor that has to be removed 96cdf0e10cSrcweir Reference< XDispatchProviderInterceptor > xSlave( xChainWalk->getSlaveDispatchProvider(), UNO_QUERY ); 97cdf0e10cSrcweir 98cdf0e10cSrcweir if ( xChainWalk == _rxInterceptor ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir // old master may be an interceptor too 101cdf0e10cSrcweir Reference< XDispatchProviderInterceptor > xMaster( xChainWalk->getMasterDispatchProvider(), UNO_QUERY ); 102cdf0e10cSrcweir 103cdf0e10cSrcweir // unchain the interceptor that has to be removed 104cdf0e10cSrcweir xChainWalk->setSlaveDispatchProvider( NULL ); 105cdf0e10cSrcweir xChainWalk->setMasterDispatchProvider( NULL ); 106cdf0e10cSrcweir 107cdf0e10cSrcweir // reconnect the chain 108cdf0e10cSrcweir if ( xMaster.is() ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir xMaster->setSlaveDispatchProvider( Reference< XDispatchProvider >::query( xSlave ) ); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir // if somebody has registered the same interceptor twice, then we will remove 114cdf0e10cSrcweir // it once per call ... 115cdf0e10cSrcweir break; 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir xChainWalk = xSlave; 119cdf0e10cSrcweir } 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir //-------------------------------------------------------------------- dispose()123cdf0e10cSrcweir void ControlFeatureInterception::dispose() 124cdf0e10cSrcweir { 125cdf0e10cSrcweir // release all interceptors 126cdf0e10cSrcweir Reference< XDispatchProviderInterceptor > xInterceptor( m_xFirstDispatchInterceptor ); 127cdf0e10cSrcweir m_xFirstDispatchInterceptor.clear(); 128cdf0e10cSrcweir while ( xInterceptor.is() ) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir // tell the interceptor it has a new (means no) predecessor 131cdf0e10cSrcweir xInterceptor->setMasterDispatchProvider( NULL ); 132cdf0e10cSrcweir 133cdf0e10cSrcweir // ask for it's successor 134cdf0e10cSrcweir Reference< XDispatchProvider > xSlave = xInterceptor->getSlaveDispatchProvider(); 135cdf0e10cSrcweir // and give it the new (means no) successoert 136cdf0e10cSrcweir xInterceptor->setSlaveDispatchProvider( NULL ); 137cdf0e10cSrcweir 138cdf0e10cSrcweir // start over with the next chain element 139cdf0e10cSrcweir xInterceptor = xInterceptor.query( xSlave ); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir } 142cdf0e10cSrcweir //-------------------------------------------------------------------- queryDispatch(const URL & _rURL,const::rtl::OUString & _rTargetFrameName,::sal_Int32 _nSearchFlags)143cdf0e10cSrcweir Reference< XDispatch > ControlFeatureInterception::queryDispatch( const URL& _rURL, const ::rtl::OUString& _rTargetFrameName, ::sal_Int32 _nSearchFlags ) SAL_THROW((RuntimeException)) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir Reference< XDispatch > xDispatcher; 146cdf0e10cSrcweir if ( m_xFirstDispatchInterceptor.is() ) 147cdf0e10cSrcweir xDispatcher = m_xFirstDispatchInterceptor->queryDispatch( _rURL, _rTargetFrameName, _nSearchFlags ); 148cdf0e10cSrcweir return xDispatcher; 149cdf0e10cSrcweir } 150cdf0e10cSrcweir 151cdf0e10cSrcweir //-------------------------------------------------------------------- queryDispatch(const URL & _rURL)152cdf0e10cSrcweir Reference< XDispatch > ControlFeatureInterception::queryDispatch( const URL& _rURL ) SAL_THROW((RuntimeException)) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir return queryDispatch( _rURL, ::rtl::OUString(), 0 ); 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir //-------------------------------------------------------------------- queryDispatch(const sal_Char * _pAsciiURL)158cdf0e10cSrcweir Reference< XDispatch > ControlFeatureInterception::queryDispatch( const sal_Char* _pAsciiURL ) SAL_THROW((RuntimeException)) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir return queryDispatch( m_pUrlTransformer->getStrictURLFromAscii( _pAsciiURL ) ); 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir //........................................................................ 164cdf0e10cSrcweir } // namespace frm 165cdf0e10cSrcweir //........................................................................ 166cdf0e10cSrcweir 167