bump product version to 5.0.4.1
[LibreOffice.git] / forms / source / helper / controlfeatureinterception.cxx
bloba341316574ba1672fd1122635067db3dda380828
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "controlfeatureinterception.hxx"
21 #include "urltransformer.hxx"
22 #include <osl/diagnose.h>
25 namespace frm
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::frame;
31 using namespace ::com::sun::star::util;
32 using namespace ::com::sun::star::lang;
34 ControlFeatureInterception::ControlFeatureInterception( const Reference< XComponentContext >& _rxORB )
35 :m_pUrlTransformer( new UrlTransformer( _rxORB ) )
40 void SAL_CALL ControlFeatureInterception::registerDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException )
42 if ( !_rxInterceptor.is() )
44 OSL_FAIL( "ControlFeatureInterception::registerDispatchProviderInterceptor: invalid interceptor!" );
45 return;
48 if ( m_xFirstDispatchInterceptor.is() )
50 // there is already an interceptor; the new one will become its master
51 Reference< XDispatchProvider > xFirstProvider( m_xFirstDispatchInterceptor, UNO_QUERY );
52 _rxInterceptor->setSlaveDispatchProvider( xFirstProvider );
53 m_xFirstDispatchInterceptor->setMasterDispatchProvider( xFirstProvider );
56 // we are the master of the chain's first interceptor
57 m_xFirstDispatchInterceptor = _rxInterceptor;
58 m_xFirstDispatchInterceptor->setMasterDispatchProvider( NULL );
59 // it's the first of the interceptor chain
63 void SAL_CALL ControlFeatureInterception::releaseDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException )
65 if ( !_rxInterceptor.is() )
67 OSL_FAIL( "ControlFeatureInterception::releaseDispatchProviderInterceptor: invalid interceptor!" );
68 return;
71 Reference< XDispatchProviderInterceptor > xChainWalk( m_xFirstDispatchInterceptor );
73 if ( m_xFirstDispatchInterceptor == _rxInterceptor )
74 { // our chain will have a new first element
75 Reference< XDispatchProviderInterceptor > xSlave( m_xFirstDispatchInterceptor->getSlaveDispatchProvider(), UNO_QUERY );
76 m_xFirstDispatchInterceptor = xSlave;
78 // do this before removing the interceptor from the chain as we won't know it's slave afterwards)
80 while ( xChainWalk.is() )
82 // walk along the chain of interceptors and look for the interceptor that has to be removed
83 Reference< XDispatchProviderInterceptor > xSlave( xChainWalk->getSlaveDispatchProvider(), UNO_QUERY );
85 if ( xChainWalk == _rxInterceptor )
87 // old master may be an interceptor too
88 Reference< XDispatchProviderInterceptor > xMaster( xChainWalk->getMasterDispatchProvider(), UNO_QUERY );
90 // unchain the interceptor that has to be removed
91 xChainWalk->setSlaveDispatchProvider( NULL );
92 xChainWalk->setMasterDispatchProvider( NULL );
94 // reconnect the chain
95 if ( xMaster.is() )
97 xMaster->setSlaveDispatchProvider( Reference< XDispatchProvider >::query( xSlave ) );
100 // if somebody has registered the same interceptor twice, then we will remove
101 // it once per call ...
102 break;
105 xChainWalk = xSlave;
110 void ControlFeatureInterception::dispose()
112 // release all interceptors
113 Reference< XDispatchProviderInterceptor > xInterceptor( m_xFirstDispatchInterceptor );
114 m_xFirstDispatchInterceptor.clear();
115 while ( xInterceptor.is() )
117 // tell the interceptor it has a new (means no) predecessor
118 xInterceptor->setMasterDispatchProvider( NULL );
120 // ask for it's successor
121 Reference< XDispatchProvider > xSlave = xInterceptor->getSlaveDispatchProvider();
122 // and give it the new (means no) successoert
123 xInterceptor->setSlaveDispatchProvider( NULL );
125 // start over with the next chain element
126 xInterceptor.set(xSlave, css::uno::UNO_QUERY);
130 Reference< XDispatch > ControlFeatureInterception::queryDispatch( const URL& _rURL, const OUString& _rTargetFrameName, ::sal_Int32 _nSearchFlags )
132 Reference< XDispatch > xDispatcher;
133 if ( m_xFirstDispatchInterceptor.is() )
134 xDispatcher = m_xFirstDispatchInterceptor->queryDispatch( _rURL, _rTargetFrameName, _nSearchFlags );
135 return xDispatcher;
139 Reference< XDispatch > ControlFeatureInterception::queryDispatch( const URL& _rURL )
141 return queryDispatch( _rURL, OUString(), 0 );
145 Reference< XDispatch > ControlFeatureInterception::queryDispatch( const sal_Char* _pAsciiURL )
147 return queryDispatch( m_pUrlTransformer->getStrictURLFromAscii( _pAsciiURL ) );
151 } // namespace frm
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */