LCOV - code coverage report
Current view: top level - chart2/source/controller/main - CommandDispatch.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 46 67 68.7 %
Date: 2014-04-11 Functions: 8 17 47.1 %
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 "CommandDispatch.hxx"
      21             : #include "CommonFunctors.hxx"
      22             : #include "macros.hxx"
      23             : #include <com/sun/star/util/URLTransformer.hpp>
      24             : 
      25             : #include <algorithm>
      26             : #include <functional>
      27             : 
      28             : using namespace ::com::sun::star;
      29             : 
      30             : using ::com::sun::star::uno::Reference;
      31             : using ::com::sun::star::uno::Sequence;
      32             : 
      33             : namespace
      34             : {
      35             : template< class Map >
      36           0 :     struct lcl_DisposeAndClearAndDeleteMapElement :
      37             :         public ::std::unary_function< typename Map::value_type, void >
      38             :     {
      39           0 :         lcl_DisposeAndClearAndDeleteMapElement( const Reference< uno::XInterface > & xEventSource ) :
      40           0 :                 m_aEvent( xEventSource )
      41           0 :         {}
      42           0 :         void operator() ( typename Map::value_type & rElement )
      43             :         {
      44           0 :             if( rElement.second )
      45             :             {
      46           0 :                 rElement.second->disposeAndClear( m_aEvent );
      47           0 :                 delete rElement.second;
      48             :             }
      49           0 :         }
      50             :     private:
      51             :         lang::EventObject m_aEvent;
      52             :     };
      53             : 
      54             : template< class Map >
      55           0 :     void lcl_DisposeAndClearAndDeleteAllMapElements(
      56             :         Map & rMap,
      57             :         const Reference< uno::XInterface > & xEventSource )
      58             : {
      59           0 :     ::std::for_each( rMap.begin(), rMap.end(),
      60             :                      lcl_DisposeAndClearAndDeleteMapElement< Map >( xEventSource ));
      61           0 : }
      62             : 
      63             : } // anonymous namespace
      64             : 
      65             : namespace chart
      66             : {
      67             : 
      68          85 : CommandDispatch::CommandDispatch(
      69             :     const Reference< uno::XComponentContext > & xContext ) :
      70             :         impl::CommandDispatch_Base( m_aMutex ),
      71          85 :         m_xContext( xContext )
      72             : {
      73          85 : }
      74             : 
      75          85 : CommandDispatch::~CommandDispatch()
      76          85 : {}
      77             : 
      78          34 : void CommandDispatch::initialize()
      79          34 : {}
      80             : 
      81             : // ____ WeakComponentImplHelperBase ____
      82             : /// is called when this is disposed
      83           0 : void SAL_CALL CommandDispatch::disposing()
      84             : {
      85           0 :     lcl_DisposeAndClearAndDeleteAllMapElements( m_aListeners, static_cast< cppu::OWeakObject* >( this ));
      86           0 :     m_aListeners.clear();
      87           0 : }
      88             : 
      89             : // ____ XDispatch ____
      90           0 : void SAL_CALL CommandDispatch::dispatch( const util::URL& /* URL */, const Sequence< beans::PropertyValue >& /* Arguments */ )
      91             :     throw (uno::RuntimeException, std::exception)
      92           0 : {}
      93             : 
      94         510 : void SAL_CALL CommandDispatch::addStatusListener( const Reference< frame::XStatusListener >& Control, const util::URL& URL )
      95             :     throw (uno::RuntimeException, std::exception)
      96             : {
      97         510 :     tListenerMap::iterator aIt( m_aListeners.find( URL.Complete ));
      98         510 :     if( aIt == m_aListeners.end())
      99             :     {
     100             :         aIt = m_aListeners.insert(
     101         510 :             m_aListeners.begin(),
     102        1020 :             tListenerMap::value_type( URL.Complete, new ::cppu::OInterfaceContainerHelper( m_aMutex )));
     103             :     }
     104             :     OSL_ASSERT( aIt != m_aListeners.end());
     105             : 
     106         510 :     aIt->second->addInterface( Control );
     107         510 :     fireStatusEvent( URL.Complete, Control );
     108         510 : }
     109             : 
     110         510 : void SAL_CALL CommandDispatch::removeStatusListener( const Reference< frame::XStatusListener >& Control, const util::URL& URL )
     111             :     throw (uno::RuntimeException, std::exception)
     112             : {
     113         510 :     tListenerMap::iterator aIt( m_aListeners.find( URL.Complete ));
     114         510 :     if( aIt != m_aListeners.end())
     115         510 :         (*aIt).second->removeInterface( Control );
     116         510 : }
     117             : 
     118             : // ____ XModifyListener ____
     119        1665 : void SAL_CALL CommandDispatch::modified( const lang::EventObject& /* aEvent */ )
     120             :     throw (uno::RuntimeException, std::exception)
     121             : {
     122        1665 :     fireAllStatusEvents( 0 );
     123        1665 : }
     124             : 
     125             : // ____ XEventListener (base of XModifyListener) ____
     126           0 : void SAL_CALL CommandDispatch::disposing( const lang::EventObject& /* Source */ )
     127             :     throw (uno::RuntimeException, std::exception)
     128           0 : {}
     129             : 
     130        1665 : void CommandDispatch::fireAllStatusEvents(
     131             :     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xSingleListener )
     132             : {
     133        1665 :     fireStatusEvent( OUString(), xSingleListener );
     134        1665 : }
     135             : 
     136       85005 : void CommandDispatch::fireStatusEventForURL(
     137             :     const OUString & rURL,
     138             :     const uno::Any & rState,
     139             :     bool bEnabled,
     140             :     const Reference< frame::XStatusListener > & xSingleListener, /* = 0 */
     141             :     const OUString & rFeatureDescriptor /* = OUString() */ )
     142             : {
     143             :     // prepare event to send
     144       85005 :     util::URL aURL;
     145       85005 :     aURL.Complete = rURL;
     146       85005 :     if( !m_xURLTransformer.is())
     147             :     {
     148          68 :         m_xURLTransformer.set( util::URLTransformer::create(m_xContext) );
     149             :     }
     150       85005 :     m_xURLTransformer->parseStrict( aURL );
     151             : 
     152             :     frame::FeatureStateEvent aEventToSend(
     153             :         static_cast< cppu::OWeakObject* >( this ), // Source
     154             :         aURL,                                      // FeatureURL
     155             :         rFeatureDescriptor,                        // FeatureDescriptor
     156             :         bEnabled,                                  // IsEnabled
     157             :         false,                                     // Requery
     158             :         rState                                     // State
     159      170010 :         );
     160             : 
     161             :     // send event either to single listener or all registered ones
     162       85005 :     if( xSingleListener.is())
     163         510 :         xSingleListener->statusChanged( aEventToSend );
     164             :     else
     165             :     {
     166       84495 :         tListenerMap::iterator aIt( m_aListeners.find( aURL.Complete ));
     167       84495 :         if( aIt != m_aListeners.end())
     168             :         {
     169       10945 :             if( aIt->second )
     170             :             {
     171       10945 :                 ::cppu::OInterfaceIteratorHelper aIntfIt( *((*aIt).second) );
     172             : 
     173       32835 :                 while( aIntfIt.hasMoreElements())
     174             :                 {
     175       10945 :                     Reference< frame::XStatusListener > xListener( aIntfIt.next(), uno::UNO_QUERY );
     176             :                     try
     177             :                     {
     178       10945 :                         if( xListener.is())
     179       10945 :                             xListener->statusChanged( aEventToSend );
     180             :                     }
     181           0 :                     catch( const uno::Exception & ex )
     182             :                     {
     183             :                         ASSERT_EXCEPTION( ex );
     184             :                     }
     185       21890 :                 }
     186             :             }
     187             :         }
     188       85005 :     }
     189       85005 : }
     190             : 
     191             : } //  namespace chart
     192             : 
     193             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10