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

Generated by: LCOV version 1.10