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

Generated by: LCOV version 1.11