LCOV - code coverage report
Current view: top level - forms/source/helper - controlfeatureinterception.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 37 49 75.5 %
Date: 2014-11-03 Functions: 6 7 85.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include "controlfeatureinterception.hxx"
      21             : #include "urltransformer.hxx"
      22             : 
      23             : 
      24             : namespace frm
      25             : {
      26             : 
      27             : 
      28             :     using namespace ::com::sun::star::uno;
      29             :     using namespace ::com::sun::star::frame;
      30             :     using namespace ::com::sun::star::util;
      31             :     using namespace ::com::sun::star::lang;
      32             : 
      33         522 :     ControlFeatureInterception::ControlFeatureInterception( const Reference< XComponentContext >& _rxORB )
      34         522 :         :m_pUrlTransformer( new UrlTransformer( _rxORB ) )
      35             :     {
      36         522 :     }
      37             : 
      38             : 
      39         120 :     void SAL_CALL ControlFeatureInterception::registerDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException )
      40             :     {
      41         120 :         if ( !_rxInterceptor.is() )
      42             :         {
      43             :             OSL_FAIL( "ControlFeatureInterception::registerDispatchProviderInterceptor: invalid interceptor!" );
      44         120 :             return;
      45             :         }
      46             : 
      47         120 :         if ( m_xFirstDispatchInterceptor.is() )
      48             :         {
      49             :             // there is already an interceptor; the new one will become its master
      50           0 :             Reference< XDispatchProvider > xFirstProvider( m_xFirstDispatchInterceptor, UNO_QUERY );
      51           0 :             _rxInterceptor->setSlaveDispatchProvider( xFirstProvider );
      52           0 :             m_xFirstDispatchInterceptor->setMasterDispatchProvider( xFirstProvider );
      53             :         }
      54             : 
      55             :         // we are the master of the chain's first interceptor
      56         120 :         m_xFirstDispatchInterceptor = _rxInterceptor;
      57         120 :         m_xFirstDispatchInterceptor->setMasterDispatchProvider( NULL );
      58             :             // it's the first of the interceptor chain
      59             :     }
      60             : 
      61             : 
      62         120 :     void SAL_CALL ControlFeatureInterception::releaseDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException )
      63             :     {
      64         120 :         if ( !_rxInterceptor.is() )
      65             :         {
      66             :             OSL_FAIL( "ControlFeatureInterception::releaseDispatchProviderInterceptor: invalid interceptor!" );
      67         120 :             return;
      68             :         }
      69             : 
      70         120 :         Reference< XDispatchProviderInterceptor >  xChainWalk( m_xFirstDispatchInterceptor );
      71             : 
      72         120 :         if ( m_xFirstDispatchInterceptor == _rxInterceptor )
      73             :         {   // our chain will have a new first element
      74         120 :             Reference< XDispatchProviderInterceptor >  xSlave( m_xFirstDispatchInterceptor->getSlaveDispatchProvider(), UNO_QUERY );
      75         120 :             m_xFirstDispatchInterceptor = xSlave;
      76             :         }
      77             :         // do this before removing the interceptor from the chain as we won't know it's slave afterwards)
      78             : 
      79         240 :         while ( xChainWalk.is() )
      80             :         {
      81             :             // walk along the chain of interceptors and look for the interceptor that has to be removed
      82         120 :             Reference< XDispatchProviderInterceptor >  xSlave( xChainWalk->getSlaveDispatchProvider(), UNO_QUERY );
      83             : 
      84         120 :             if ( xChainWalk == _rxInterceptor )
      85             :             {
      86             :                 // old master may be an interceptor too
      87         120 :                 Reference< XDispatchProviderInterceptor >  xMaster( xChainWalk->getMasterDispatchProvider(), UNO_QUERY );
      88             : 
      89             :                 // unchain the interceptor that has to be removed
      90         120 :                 xChainWalk->setSlaveDispatchProvider( NULL );
      91         120 :                 xChainWalk->setMasterDispatchProvider( NULL );
      92             : 
      93             :                 // reconnect the chain
      94         120 :                 if ( xMaster.is() )
      95             :                 {
      96           0 :                     xMaster->setSlaveDispatchProvider( Reference< XDispatchProvider >::query( xSlave ) );
      97             :                 }
      98             : 
      99             :                 // if somebody has registered the same interceptor twice, then we will remove
     100             :                 // it once per call ...
     101         120 :                 break;
     102             :             }
     103             : 
     104           0 :             xChainWalk = xSlave;
     105         120 :         }
     106             :     }
     107             : 
     108             : 
     109         526 :     void ControlFeatureInterception::dispose()
     110             :     {
     111             :         // release all interceptors
     112         526 :         Reference< XDispatchProviderInterceptor > xInterceptor( m_xFirstDispatchInterceptor );
     113         526 :         m_xFirstDispatchInterceptor.clear();
     114        1052 :         while ( xInterceptor.is() )
     115             :         {
     116             :             // tell the interceptor it has a new (means no) predecessor
     117           0 :             xInterceptor->setMasterDispatchProvider( NULL );
     118             : 
     119             :             // ask for it's successor
     120           0 :             Reference< XDispatchProvider > xSlave = xInterceptor->getSlaveDispatchProvider();
     121             :             // and give it the new (means no) successoert
     122           0 :             xInterceptor->setSlaveDispatchProvider( NULL );
     123             : 
     124             :             // start over with the next chain element
     125           0 :             xInterceptor.set(xSlave, css::uno::UNO_QUERY);
     126         526 :         }
     127         526 :     }
     128             : 
     129          38 :     Reference< XDispatch > ControlFeatureInterception::queryDispatch( const URL& _rURL, const OUString& _rTargetFrameName, ::sal_Int32 _nSearchFlags )
     130             :     {
     131          38 :         Reference< XDispatch > xDispatcher;
     132          38 :         if ( m_xFirstDispatchInterceptor.is() )
     133           0 :             xDispatcher = m_xFirstDispatchInterceptor->queryDispatch( _rURL, _rTargetFrameName, _nSearchFlags );
     134          38 :         return xDispatcher;
     135             :     }
     136             : 
     137             : 
     138          38 :     Reference< XDispatch > ControlFeatureInterception::queryDispatch( const URL& _rURL )
     139             :     {
     140          38 :         return queryDispatch( _rURL, OUString(), 0 );
     141             :     }
     142             : 
     143             : 
     144           0 :     Reference< XDispatch > ControlFeatureInterception::queryDispatch( const sal_Char* _pAsciiURL )
     145             :     {
     146           0 :         return queryDispatch( m_pUrlTransformer->getStrictURLFromAscii( _pAsciiURL ) );
     147             :     }
     148             : 
     149             : 
     150             : } // namespace frm
     151             : 
     152             : 
     153             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10