LCOV - code coverage report
Current view: top level - vcl/source/app - vclevent.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 39 76 51.3 %
Date: 2014-11-03 Functions: 15 29 51.7 %
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 "vcl/vclevent.hxx"
      21             : 
      22             : #include "svdata.hxx"
      23             : 
      24             : #include <com/sun/star/accessibility/XAccessible.hpp>
      25             : 
      26             : using ::com::sun::star::uno::Reference;
      27             : using ::com::sun::star::accessibility::XAccessible;
      28             : 
      29       47180 : TYPEINIT0(VclSimpleEvent);
      30    89514990 : TYPEINIT1(VclWindowEvent, VclSimpleEvent);
      31      164922 : TYPEINIT1(VclMenuEvent, VclSimpleEvent);
      32             : 
      33           0 : VclAccessibleEvent::VclAccessibleEvent( sal_uLong n, const Reference<XAccessible>& rxAccessible ) :
      34             :     VclSimpleEvent(n),
      35           0 :     mxAccessible(rxAccessible)
      36             : {
      37           0 : }
      38             : 
      39           0 : VclAccessibleEvent::~VclAccessibleEvent()
      40             : {
      41           0 : }
      42             : 
      43             : 
      44    44250613 : void VclEventListeners::Call( VclSimpleEvent* pEvent ) const
      45             : {
      46    44250613 :     if ( m_aListeners.empty() )
      47    75309935 :         return;
      48             : 
      49             :     // Copy the list, because this can be destroyed when calling a Link...
      50    13191291 :     std::list<Link> aCopy( m_aListeners );
      51    13191291 :     std::list<Link>::iterator aIter( aCopy.begin() );
      52    13191291 :     std::list<Link>::const_iterator aEnd( aCopy.end() );
      53    13191291 :     if( pEvent->IsA( VclWindowEvent::StaticType() ) )
      54             :     {
      55    13167701 :         VclWindowEvent* pWinEvent = static_cast<VclWindowEvent*>(pEvent);
      56    13167701 :         ImplDelData aDel( pWinEvent->GetWindow() );
      57    46163894 :         while ( aIter != aEnd && ! aDel.IsDead() )
      58             :         {
      59    19828492 :             Link &rLink = *aIter;
      60             :             // check this hasn't been removed in some re-enterancy scenario fdo#47368
      61    19828492 :             if( std::find(m_aListeners.begin(), m_aListeners.end(), rLink) != m_aListeners.end() )
      62    19828492 :                 rLink.Call( pEvent );
      63    19828492 :             ++aIter;
      64    13167701 :         }
      65             :     }
      66             :     else
      67             :     {
      68       70822 :         while ( aIter != aEnd )
      69             :         {
      70       23642 :             Link &rLink = *aIter;
      71       23642 :             if( std::find(m_aListeners.begin(), m_aListeners.end(), rLink) != m_aListeners.end() )
      72       23642 :                 rLink.Call( pEvent );
      73       23642 :             ++aIter;
      74             :         }
      75    13191291 :     }
      76             : }
      77             : 
      78           0 : bool VclEventListeners::Process( VclSimpleEvent* pEvent ) const
      79             : {
      80           0 :     if ( m_aListeners.empty() )
      81           0 :         return false;
      82             : 
      83           0 :     bool bProcessed = false;
      84             :     // Copy the list, because this can be destroyed when calling a Link...
      85           0 :     std::list<Link> aCopy( m_aListeners );
      86           0 :     std::list<Link>::iterator aIter( aCopy.begin() );
      87           0 :     std::list<Link>::const_iterator aEnd( aCopy.end() );
      88           0 :     while ( aIter != aEnd )
      89             :     {
      90           0 :         if( (*aIter).Call( pEvent ) != 0 )
      91             :         {
      92           0 :             bProcessed = true;
      93           0 :             break;
      94             :         }
      95           0 :         ++aIter;
      96             :     }
      97           0 :     return bProcessed;
      98             : }
      99             : 
     100      239807 : void VclEventListeners::addListener( const Link& rListener )
     101             : {
     102      239807 :     m_aListeners.push_back( rListener );
     103      239807 : }
     104             : 
     105      317670 : void VclEventListeners::removeListener( const Link& rListener )
     106             : {
     107      317670 :     m_aListeners.remove( rListener );
     108      317670 : }
     109             : 
     110           2 : VclEventListeners2::VclEventListeners2()
     111             : {
     112           2 : }
     113             : 
     114           0 : VclEventListeners2::~VclEventListeners2()
     115             : {
     116           0 : }
     117             : 
     118           0 : void VclEventListeners2::addListener( const Link& i_rLink )
     119             : {
     120             :     // ensure uniqueness
     121           0 :     for( std::list< Link >::const_iterator it = m_aListeners.begin(); it != m_aListeners.end(); ++it )
     122             :     {
     123           0 :         if( *it == i_rLink )
     124           0 :             return;
     125             :     }
     126           0 :     m_aListeners.push_back( i_rLink );
     127             : }
     128             : 
     129           0 : void VclEventListeners2::removeListener( const Link& i_rLink )
     130             : {
     131           0 :     size_t n = m_aIterators.size();
     132           0 :     for( size_t i = 0; i < n; i++ )
     133             :     {
     134           0 :         if( m_aIterators[i].m_aIt != m_aListeners.end() && *m_aIterators[i].m_aIt == i_rLink )
     135             :         {
     136           0 :             m_aIterators[i].m_bWasInvalidated = true;
     137           0 :             ++m_aIterators[i].m_aIt;
     138             :         }
     139             :     }
     140           0 :     m_aListeners.remove( i_rLink );
     141           0 : }
     142             : 
     143         556 : void VclEventListeners2::callListeners( VclSimpleEvent* i_pEvent )
     144             : {
     145         556 :     vcl::DeletionListener aDel( this );
     146             : 
     147         556 :     m_aIterators.push_back(ListenerIt(m_aListeners.begin()));
     148         556 :     size_t nIndex = m_aIterators.size() - 1;
     149        1112 :     while( ! aDel.isDeleted() && m_aIterators[ nIndex ].m_aIt != m_aListeners.end() )
     150             :     {
     151           0 :         m_aIterators[ nIndex ].m_aIt->Call( i_pEvent );
     152           0 :         if( m_aIterators[ nIndex ].m_bWasInvalidated )
     153             :             // check if the current element was removed and the iterator increased in the meantime
     154           0 :             m_aIterators[ nIndex ].m_bWasInvalidated = false;
     155             :         else
     156           0 :             ++m_aIterators[ nIndex ].m_aIt;
     157             :     }
     158         556 :     m_aIterators.pop_back();
     159        1789 : }
     160             : 
     161             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10