LCOV - code coverage report
Current view: top level - chart2/source/controller/main - CommandDispatch.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 46 67 68.7 %
Date: 2015-06-13 12:38:46 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 :         explicit 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          53 : CommandDispatch::~CommandDispatch()
      76          53 : {}
      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         442 : void SAL_CALL CommandDispatch::addStatusListener( const Reference< frame::XStatusListener >& Control, const util::URL& URL )
      95             :     throw (uno::RuntimeException, std::exception)
      96             : {
      97         442 :     tListenerMap::iterator aIt( m_aListeners.find( URL.Complete ));
      98         442 :     if( aIt == m_aListeners.end())
      99             :     {
     100             :         aIt = m_aListeners.insert(
     101         442 :             m_aListeners.begin(),
     102         884 :             tListenerMap::value_type( URL.Complete, new ::cppu::OInterfaceContainerHelper( m_aMutex )));
     103             :     }
     104             :     OSL_ASSERT( aIt != m_aListeners.end());
     105             : 
     106         442 :     aIt->second->addInterface( Control );
     107         442 :     fireStatusEvent( URL.Complete, Control );
     108         442 : }
     109             : 
     110         442 : void SAL_CALL CommandDispatch::removeStatusListener( const Reference< frame::XStatusListener >& Control, const util::URL& URL )
     111             :     throw (uno::RuntimeException, std::exception)
     112             : {
     113         442 :     tListenerMap::iterator aIt( m_aListeners.find( URL.Complete ));
     114         442 :     if( aIt != m_aListeners.end())
     115         442 :         (*aIt).second->removeInterface( Control );
     116         442 : }
     117             : 
     118             : // ____ XModifyListener ____
     119        1725 : void SAL_CALL CommandDispatch::modified( const lang::EventObject& /* aEvent */ )
     120             :     throw (uno::RuntimeException, std::exception)
     121             : {
     122        1725 :     fireAllStatusEvents( 0 );
     123        1725 : }
     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        1725 : void CommandDispatch::fireAllStatusEvents(
     131             :     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xSingleListener )
     132             : {
     133        1725 :     fireStatusEvent( OUString(), xSingleListener );
     134        1725 : }
     135             : 
     136       88207 : 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       88207 :     util::URL aURL;
     145       88207 :     aURL.Complete = rURL;
     146       88207 :     if( !m_xURLTransformer.is())
     147             :     {
     148          51 :         m_xURLTransformer.set( util::URLTransformer::create(m_xContext) );
     149             :     }
     150       88207 :     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      176414 :         );
     160             : 
     161             :     // send event either to single listener or all registered ones
     162       88207 :     if( xSingleListener.is())
     163         442 :         xSingleListener->statusChanged( aEventToSend );
     164             :     else
     165             :     {
     166       87765 :         tListenerMap::iterator aIt( m_aListeners.find( aURL.Complete ));
     167       87765 :         if( aIt != m_aListeners.end())
     168             :         {
     169       19510 :             if( aIt->second )
     170             :             {
     171       19510 :                 ::cppu::OInterfaceIteratorHelper aIntfIt( *((*aIt).second) );
     172             : 
     173       58530 :                 while( aIntfIt.hasMoreElements())
     174             :                 {
     175       19510 :                     Reference< frame::XStatusListener > xListener( aIntfIt.next(), uno::UNO_QUERY );
     176             :                     try
     177             :                     {
     178       19510 :                         if( xListener.is())
     179       19510 :                             xListener->statusChanged( aEventToSend );
     180             :                     }
     181           0 :                     catch( const uno::Exception & ex )
     182             :                     {
     183             :                         ASSERT_EXCEPTION( ex );
     184             :                     }
     185       39020 :                 }
     186             :             }
     187             :         }
     188       88207 :     }
     189       88207 : }
     190             : 
     191             : } //  namespace chart
     192             : 
     193             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11