LCOV - code coverage report
Current view: top level - svx/source/form - formfeaturedispatcher.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 73 0.0 %
Date: 2012-08-25 Functions: 0 8 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 154 0.0 %

           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                 :            : 
      30                 :            : #include "formfeaturedispatcher.hxx"
      31                 :            : 
      32                 :            : #include <comphelper/namedvaluecollection.hxx>
      33                 :            : #include <tools/diagnose_ex.h>
      34                 :            : 
      35                 :            : //........................................................................
      36                 :            : namespace svx
      37                 :            : {
      38                 :            : //........................................................................
      39                 :            : 
      40                 :            :     using namespace ::com::sun::star::uno;
      41                 :            :     using namespace ::com::sun::star::lang;
      42                 :            :     using namespace ::com::sun::star::frame;
      43                 :            :     using namespace ::com::sun::star::beans;
      44                 :            :     using namespace ::com::sun::star::util;
      45                 :            :     using namespace ::com::sun::star::form::runtime;
      46                 :            : 
      47                 :            :     //====================================================================
      48                 :            :     //= OSingleFeatureDispatcher
      49                 :            :     //====================================================================
      50                 :            :     //--------------------------------------------------------------------
      51                 :          0 :     OSingleFeatureDispatcher::OSingleFeatureDispatcher( const URL& _rFeatureURL, const sal_Int16 _nFormFeature,
      52                 :            :             const Reference< XFormOperations >& _rxFormOperations, ::osl::Mutex& _rMutex )
      53                 :            :         :m_rMutex( _rMutex )
      54                 :            :         ,m_aStatusListeners( _rMutex )
      55                 :            :         ,m_xFormOperations( _rxFormOperations )
      56                 :            :         ,m_aFeatureURL( _rFeatureURL )
      57                 :            :         ,m_nFormFeature( _nFormFeature )
      58                 :            :         ,m_bLastKnownEnabled( sal_False )
      59         [ #  # ]:          0 :         ,m_bDisposed( sal_False )
      60                 :            :     {
      61                 :          0 :     }
      62                 :            : 
      63                 :            :     //--------------------------------------------------------------------
      64                 :          0 :     void OSingleFeatureDispatcher::getUnoState( FeatureStateEvent& /* [out] */ _rState ) const
      65                 :            :     {
      66 [ #  # ][ #  # ]:          0 :         _rState.Source = *const_cast< OSingleFeatureDispatcher* >( this );
      67                 :            : 
      68 [ #  # ][ #  # ]:          0 :         FeatureState aState( m_xFormOperations->getState( m_nFormFeature ) );
      69                 :            : 
      70                 :          0 :         _rState.FeatureURL = m_aFeatureURL;
      71                 :          0 :         _rState.IsEnabled = aState.Enabled;
      72                 :          0 :         _rState.Requery = sal_False;
      73                 :          0 :         _rState.State = aState.State;
      74                 :          0 :     }
      75                 :            : 
      76                 :            :     //--------------------------------------------------------------------
      77                 :          0 :     void OSingleFeatureDispatcher::updateAllListeners()
      78                 :            :     {
      79         [ #  # ]:          0 :         ::osl::ClearableMutexGuard aGuard( m_rMutex );
      80                 :            : 
      81         [ #  # ]:          0 :         FeatureStateEvent aUnoState;
      82         [ #  # ]:          0 :         getUnoState( aUnoState );
      83                 :            : 
      84 [ #  # ][ #  # ]:          0 :         if ( ( m_aLastKnownState == aUnoState.State ) && ( m_bLastKnownEnabled == aUnoState.IsEnabled ) )
                 [ #  # ]
      85                 :          0 :             return;
      86                 :            : 
      87                 :          0 :         m_aLastKnownState = aUnoState.State;
      88                 :          0 :         m_bLastKnownEnabled = aUnoState.IsEnabled;
      89                 :            : 
      90 [ #  # ][ #  # ]:          0 :         notifyStatus( NULL, aGuard );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      91                 :            :     }
      92                 :            : 
      93                 :            :     //--------------------------------------------------------------------
      94                 :          0 :     void OSingleFeatureDispatcher::notifyStatus( const Reference< XStatusListener >& _rxListener, ::osl::ClearableMutexGuard& _rFreeForNotification )
      95                 :            :     {
      96         [ #  # ]:          0 :         FeatureStateEvent aUnoState;
      97         [ #  # ]:          0 :         getUnoState( aUnoState );
      98                 :            : 
      99         [ #  # ]:          0 :         if ( _rxListener.is() )
     100                 :            :         {
     101                 :            :             try
     102                 :            :             {
     103         [ #  # ]:          0 :                 _rFreeForNotification.clear();
     104 [ #  # ][ #  # ]:          0 :                 _rxListener->statusChanged( aUnoState );
     105                 :            :             }
     106         [ #  # ]:          0 :             catch( const Exception& )
     107                 :            :             {
     108                 :            :                 OSL_FAIL( "OSingleFeatureDispatcher::notifyStatus: caught an exception!" );
     109                 :            :             }
     110                 :            :         }
     111                 :            :         else
     112                 :            :         {
     113         [ #  # ]:          0 :             ::cppu::OInterfaceIteratorHelper aIter( m_aStatusListeners );
     114         [ #  # ]:          0 :             _rFreeForNotification.clear();
     115                 :            : 
     116         [ #  # ]:          0 :             while ( aIter.hasMoreElements() )
     117                 :            :             {
     118                 :            :                 try
     119                 :            :                 {
     120 [ #  # ][ #  # ]:          0 :                     static_cast< XStatusListener* >( aIter.next() )->statusChanged( aUnoState );
     121                 :            :                 }
     122   [ #  #  #  #  :          0 :                 catch( const DisposedException& )
                      # ]
     123                 :            :                 {
     124                 :            :                     OSL_FAIL( "OSingleFeatureDispatcher::notifyStatus: caught a DisposedException - removing the listener!" );
     125         [ #  # ]:          0 :                     aIter.remove( );
     126                 :            :                 }
     127         [ #  # ]:          0 :                 catch( const Exception& )
     128                 :            :                 {
     129                 :            :                     OSL_FAIL( "OSingleFeatureDispatcher::notifyStatus: caught a generic exception while notifying a single listener!" );
     130                 :            :                 }
     131         [ #  # ]:          0 :             }
     132         [ #  # ]:          0 :         }
     133         [ #  # ]:          0 :     }
     134                 :            : 
     135                 :            :     //--------------------------------------------------------------------
     136                 :          0 :     void SAL_CALL OSingleFeatureDispatcher::dispatch( const URL& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (RuntimeException)
     137                 :            :     {
     138         [ #  # ]:          0 :         ::osl::ClearableMutexGuard aGuard( m_rMutex );
     139         [ #  # ]:          0 :         checkAlive();
     140                 :            : 
     141                 :            :         OSL_ENSURE( _rURL.Complete == m_aFeatureURL.Complete, "OSingleFeatureDispatcher::dispatch: not responsible for this URL!" );
     142                 :            :         (void)_rURL;
     143                 :            : 
     144 [ #  # ][ #  # ]:          0 :         if ( !m_xFormOperations->isEnabled( m_nFormFeature ) )
                 [ #  # ]
     145                 :          0 :             return;
     146                 :            : 
     147                 :            :         // release our mutex before executing the command
     148                 :          0 :         sal_Int16 nFormFeature( m_nFormFeature );
     149                 :          0 :         Reference< XFormOperations > xFormOperations( m_xFormOperations );
     150         [ #  # ]:          0 :         aGuard.clear();
     151                 :            : 
     152                 :            :         try
     153                 :            :         {
     154         [ #  # ]:          0 :             if ( !_rArguments.getLength() )
     155                 :            :             {
     156 [ #  # ][ #  # ]:          0 :                 xFormOperations->execute( nFormFeature );
     157                 :            :             }
     158                 :            :             else
     159                 :            :             {   // at the moment we only support one parameter
     160         [ #  # ]:          0 :                 ::comphelper::NamedValueCollection aArgs( _rArguments );
     161 [ #  # ][ #  # ]:          0 :                 xFormOperations->executeWithArguments( nFormFeature, aArgs.getNamedValues() );
         [ #  # ][ #  # ]
                 [ #  # ]
     162                 :            :             }
     163                 :            :         }
     164      [ #  #  # ]:          0 :         catch( const RuntimeException& )
     165                 :            :         {
     166                 :          0 :             throw;
     167                 :            :         }
     168         [ #  # ]:          0 :         catch( const Exception& )
     169                 :            :         {
     170                 :            :             DBG_UNHANDLED_EXCEPTION();
     171 [ #  # ][ #  # ]:          0 :         }
     172                 :            :     }
     173                 :            : 
     174                 :            :     //--------------------------------------------------------------------
     175                 :          0 :     void SAL_CALL OSingleFeatureDispatcher::addStatusListener( const Reference< XStatusListener >& _rxControl, const URL& _rURL ) throw (RuntimeException)
     176                 :            :     {
     177                 :            :         (void)_rURL;
     178                 :            :         OSL_ENSURE( _rURL.Complete == m_aFeatureURL.Complete, "OSingleFeatureDispatcher::addStatusListener: unexpected URL!" );
     179                 :            :         OSL_ENSURE( _rxControl.is(), "OSingleFeatureDispatcher::addStatusListener: senseless call!" );
     180         [ #  # ]:          0 :         if ( !_rxControl.is() )
     181                 :            :             return;
     182                 :            : 
     183         [ #  # ]:          0 :         ::osl::ClearableMutexGuard aGuard( m_rMutex );
     184         [ #  # ]:          0 :         if ( m_bDisposed )
     185                 :            :         {
     186 [ #  # ][ #  # ]:          0 :             EventObject aDisposeEvent( *this );
     187         [ #  # ]:          0 :             aGuard.clear();
     188 [ #  # ][ #  # ]:          0 :             _rxControl->disposing( aDisposeEvent );
     189         [ #  # ]:          0 :             return;
     190                 :            :         }
     191                 :            : 
     192         [ #  # ]:          0 :         m_aStatusListeners.addInterface( _rxControl );
     193                 :            : 
     194                 :            :         // initially update the status
     195 [ #  # ][ #  # ]:          0 :         notifyStatus( _rxControl, aGuard );
                 [ #  # ]
     196                 :            :     }
     197                 :            : 
     198                 :            :     //--------------------------------------------------------------------
     199                 :          0 :     void SAL_CALL OSingleFeatureDispatcher::removeStatusListener( const Reference< XStatusListener >& _rxControl, const URL& _rURL ) throw (RuntimeException)
     200                 :            :     {
     201                 :            :         (void)_rURL;
     202                 :            :         OSL_ENSURE( _rURL.Complete == m_aFeatureURL.Complete, "OSingleFeatureDispatcher::removeStatusListener: unexpected URL!" );
     203                 :            :         OSL_ENSURE( _rxControl.is(), "OSingleFeatureDispatcher::removeStatusListener: senseless call!" );
     204         [ #  # ]:          0 :         if ( !_rxControl.is() )
     205                 :          0 :             return;
     206                 :            : 
     207         [ #  # ]:          0 :         ::osl::MutexGuard aGuard( m_rMutex );
     208         [ #  # ]:          0 :         checkAlive();
     209                 :            : 
     210 [ #  # ][ #  # ]:          0 :         m_aStatusListeners.removeInterface( _rxControl );
     211                 :            :     }
     212                 :            : 
     213                 :            :     //--------------------------------------------------------------------
     214                 :          0 :     void OSingleFeatureDispatcher::checkAlive() const SAL_THROW((DisposedException))
     215                 :            :     {
     216         [ #  # ]:          0 :         if ( m_bDisposed )
     217 [ #  # ][ #  # ]:          0 :             throw DisposedException( ::rtl::OUString(), *const_cast< OSingleFeatureDispatcher* >( this ) );
     218                 :          0 :     }
     219                 :            : 
     220                 :            : //........................................................................
     221                 :            : }   // namespace svx
     222                 :            : //........................................................................
     223                 :            : 
     224                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10