LCOV - code coverage report
Current view: top level - forms/source/helper - controlfeatureinterception.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 38 49 77.6 %
Date: 2012-08-25 Functions: 6 7 85.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 32 110 29.1 %

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

Generated by: LCOV version 1.10