LCOV - code coverage report
Current view: top level - forms/source/helper - controlfeatureinterception.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 37 49 75.5 %
Date: 2015-06-13 12:38:46 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             : #include <osl/diagnose.h>
      23             : 
      24             : 
      25             : namespace frm
      26             : {
      27             : 
      28             : 
      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;
      33             : 
      34         274 :     ControlFeatureInterception::ControlFeatureInterception( const Reference< XComponentContext >& _rxORB )
      35         274 :         :m_pUrlTransformer( new UrlTransformer( _rxORB ) )
      36             :     {
      37         274 :     }
      38             : 
      39             : 
      40          62 :     void SAL_CALL ControlFeatureInterception::registerDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException )
      41             :     {
      42          62 :         if ( !_rxInterceptor.is() )
      43             :         {
      44             :             OSL_FAIL( "ControlFeatureInterception::registerDispatchProviderInterceptor: invalid interceptor!" );
      45          62 :             return;
      46             :         }
      47             : 
      48          62 :         if ( m_xFirstDispatchInterceptor.is() )
      49             :         {
      50             :             // there is already an interceptor; the new one will become its master
      51           0 :             Reference< XDispatchProvider > xFirstProvider( m_xFirstDispatchInterceptor, UNO_QUERY );
      52           0 :             _rxInterceptor->setSlaveDispatchProvider( xFirstProvider );
      53           0 :             m_xFirstDispatchInterceptor->setMasterDispatchProvider( xFirstProvider );
      54             :         }
      55             : 
      56             :         // we are the master of the chain's first interceptor
      57          62 :         m_xFirstDispatchInterceptor = _rxInterceptor;
      58          62 :         m_xFirstDispatchInterceptor->setMasterDispatchProvider( NULL );
      59             :             // it's the first of the interceptor chain
      60             :     }
      61             : 
      62             : 
      63          62 :     void SAL_CALL ControlFeatureInterception::releaseDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException )
      64             :     {
      65          62 :         if ( !_rxInterceptor.is() )
      66             :         {
      67             :             OSL_FAIL( "ControlFeatureInterception::releaseDispatchProviderInterceptor: invalid interceptor!" );
      68          62 :             return;
      69             :         }
      70             : 
      71          62 :         Reference< XDispatchProviderInterceptor >  xChainWalk( m_xFirstDispatchInterceptor );
      72             : 
      73          62 :         if ( m_xFirstDispatchInterceptor == _rxInterceptor )
      74             :         {   // our chain will have a new first element
      75          62 :             Reference< XDispatchProviderInterceptor >  xSlave( m_xFirstDispatchInterceptor->getSlaveDispatchProvider(), UNO_QUERY );
      76          62 :             m_xFirstDispatchInterceptor = xSlave;
      77             :         }
      78             :         // do this before removing the interceptor from the chain as we won't know it's slave afterwards)
      79             : 
      80         124 :         while ( xChainWalk.is() )
      81             :         {
      82             :             // walk along the chain of interceptors and look for the interceptor that has to be removed
      83          62 :             Reference< XDispatchProviderInterceptor >  xSlave( xChainWalk->getSlaveDispatchProvider(), UNO_QUERY );
      84             : 
      85          62 :             if ( xChainWalk == _rxInterceptor )
      86             :             {
      87             :                 // old master may be an interceptor too
      88          62 :                 Reference< XDispatchProviderInterceptor >  xMaster( xChainWalk->getMasterDispatchProvider(), UNO_QUERY );
      89             : 
      90             :                 // unchain the interceptor that has to be removed
      91          62 :                 xChainWalk->setSlaveDispatchProvider( NULL );
      92          62 :                 xChainWalk->setMasterDispatchProvider( NULL );
      93             : 
      94             :                 // reconnect the chain
      95          62 :                 if ( xMaster.is() )
      96             :                 {
      97           0 :                     xMaster->setSlaveDispatchProvider( Reference< XDispatchProvider >::query( xSlave ) );
      98             :                 }
      99             : 
     100             :                 // if somebody has registered the same interceptor twice, then we will remove
     101             :                 // it once per call ...
     102          62 :                 break;
     103             :             }
     104             : 
     105           0 :             xChainWalk = xSlave;
     106          62 :         }
     107             :     }
     108             : 
     109             : 
     110         276 :     void ControlFeatureInterception::dispose()
     111             :     {
     112             :         // release all interceptors
     113         276 :         Reference< XDispatchProviderInterceptor > xInterceptor( m_xFirstDispatchInterceptor );
     114         276 :         m_xFirstDispatchInterceptor.clear();
     115         552 :         while ( xInterceptor.is() )
     116             :         {
     117             :             // tell the interceptor it has a new (means no) predecessor
     118           0 :             xInterceptor->setMasterDispatchProvider( NULL );
     119             : 
     120             :             // ask for it's successor
     121           0 :             Reference< XDispatchProvider > xSlave = xInterceptor->getSlaveDispatchProvider();
     122             :             // and give it the new (means no) successoert
     123           0 :             xInterceptor->setSlaveDispatchProvider( NULL );
     124             : 
     125             :             // start over with the next chain element
     126           0 :             xInterceptor.set(xSlave, css::uno::UNO_QUERY);
     127         276 :         }
     128         276 :     }
     129             : 
     130          19 :     Reference< XDispatch > ControlFeatureInterception::queryDispatch( const URL& _rURL, const OUString& _rTargetFrameName, ::sal_Int32 _nSearchFlags )
     131             :     {
     132          19 :         Reference< XDispatch > xDispatcher;
     133          19 :         if ( m_xFirstDispatchInterceptor.is() )
     134           0 :             xDispatcher = m_xFirstDispatchInterceptor->queryDispatch( _rURL, _rTargetFrameName, _nSearchFlags );
     135          19 :         return xDispatcher;
     136             :     }
     137             : 
     138             : 
     139          19 :     Reference< XDispatch > ControlFeatureInterception::queryDispatch( const URL& _rURL )
     140             :     {
     141          19 :         return queryDispatch( _rURL, OUString(), 0 );
     142             :     }
     143             : 
     144             : 
     145           0 :     Reference< XDispatch > ControlFeatureInterception::queryDispatch( const sal_Char* _pAsciiURL )
     146             :     {
     147           0 :         return queryDispatch( m_pUrlTransformer->getStrictURLFromAscii( _pAsciiURL ) );
     148             :     }
     149             : 
     150             : 
     151             : } // namespace frm
     152             : 
     153             : 
     154             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11