LCOV - code coverage report
Current view: top level - libreoffice/vcl/source/app - vclevent.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 22 76 28.9 %
Date: 2012-12-27 Functions: 6 28 21.4 %
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 "vcl/vclevent.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           0 : TYPEINIT0(VclSimpleEvent);
      31     1261968 : TYPEINIT1(VclWindowEvent, VclSimpleEvent);
      32           0 : 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           0 : Reference<XAccessible> VclAccessibleEvent::GetAccessible() const
      45             : {
      46           0 :     return mxAccessible;
      47             : }
      48             : 
      49      393289 : void VclEventListeners::Call( VclSimpleEvent* pEvent ) const
      50             : {
      51      393289 :     if ( m_aListeners.empty() )
      52      393289 :         return;
      53             : 
      54             :     // Copy the list, because this can be destroyed when calling a Link...
      55      187171 :     std::list<Link> aCopy( m_aListeners );
      56      187171 :     std::list<Link>::iterator aIter( aCopy.begin() );
      57      187171 :     if( pEvent->IsA( VclWindowEvent::StaticType() ) )
      58             :     {
      59      187171 :         VclWindowEvent* pWinEvent = static_cast<VclWindowEvent*>(pEvent);
      60      187171 :         ImplDelData aDel( pWinEvent->GetWindow() );
      61     1967832 :         while ( aIter != aCopy.end() && ! aDel.IsDead() )
      62             :         {
      63     1593490 :             Link &rLink = *aIter;
      64             :             // check this hasn't been removed in some re-enterancy scenario fdo#47368
      65     1593490 :             if( std::find(m_aListeners.begin(), m_aListeners.end(), rLink) != m_aListeners.end() )
      66     1593490 :                 rLink.Call( pEvent );
      67     1593490 :             aIter++;
      68      187171 :         }
      69             :     }
      70             :     else
      71             :     {
      72           0 :         while ( aIter != aCopy.end() )
      73             :         {
      74           0 :             Link &rLink = *aIter;
      75           0 :             if( std::find(m_aListeners.begin(), m_aListeners.end(), rLink) != m_aListeners.end() )
      76           0 :                 rLink.Call( pEvent );
      77           0 :             aIter++;
      78             :         }
      79      187171 :     }
      80             : }
      81             : 
      82           0 : sal_Bool VclEventListeners::Process( VclSimpleEvent* pEvent ) const
      83             : {
      84           0 :     if ( m_aListeners.empty() )
      85           0 :         return sal_False;
      86             : 
      87           0 :     sal_Bool bProcessed = sal_False;
      88             :     // Copy the list, because this can be destroyed when calling a Link...
      89           0 :     std::list<Link> aCopy( m_aListeners );
      90           0 :     std::list<Link>::iterator aIter( aCopy.begin() );
      91           0 :     while ( aIter != aCopy.end() )
      92             :     {
      93           0 :         if( (*aIter).Call( pEvent ) != 0 )
      94             :         {
      95           0 :             bProcessed = sal_True;
      96           0 :             break;
      97             :         }
      98           0 :         aIter++;
      99             :     }
     100           0 :     return bProcessed;
     101             : }
     102             : 
     103        5248 : void VclEventListeners::addListener( const Link& rListener )
     104             : {
     105        5248 :     m_aListeners.push_back( rListener );
     106        5248 : }
     107             : 
     108        2605 : void VclEventListeners::removeListener( const Link& rListener )
     109             : {
     110        2605 :     m_aListeners.remove( rListener );
     111        2605 : }
     112             : 
     113           0 : VclEventListeners2::VclEventListeners2()
     114             : {
     115           0 : }
     116             : 
     117           0 : VclEventListeners2::~VclEventListeners2()
     118             : {
     119           0 : }
     120             : 
     121           0 : void VclEventListeners2::addListener( const Link& i_rLink )
     122             : {
     123             :     // ensure uniqueness
     124           0 :     for( std::list< Link >::const_iterator it = m_aListeners.begin(); it != m_aListeners.end(); ++it )
     125             :     {
     126           0 :         if( *it == i_rLink )
     127           0 :             return;
     128             :     }
     129           0 :     m_aListeners.push_back( i_rLink );
     130             : }
     131             : 
     132           0 : void VclEventListeners2::removeListener( const Link& i_rLink )
     133             : {
     134           0 :     size_t n = m_aIterators.size();
     135           0 :     for( size_t i = 0; i < n; i++ )
     136             :     {
     137           0 :         if( m_aIterators[i].m_aIt != m_aListeners.end() && *m_aIterators[i].m_aIt == i_rLink )
     138             :         {
     139           0 :             m_aIterators[i].m_bWasInvalidated = true;
     140           0 :             ++m_aIterators[i].m_aIt;
     141             :         }
     142             :     }
     143           0 :     m_aListeners.remove( i_rLink );
     144           0 : }
     145             : 
     146           0 : void VclEventListeners2::callListeners( VclSimpleEvent* i_pEvent )
     147             : {
     148           0 :     vcl::DeletionListener aDel( this );
     149             : 
     150           0 :     m_aIterators.push_back(ListenerIt(m_aListeners.begin()));
     151           0 :     size_t nIndex = m_aIterators.size() - 1;
     152           0 :     while( ! aDel.isDeleted() && m_aIterators[ nIndex ].m_aIt != m_aListeners.end() )
     153             :     {
     154           0 :         m_aIterators[ nIndex ].m_aIt->Call( i_pEvent );
     155           0 :         if( m_aIterators[ nIndex ].m_bWasInvalidated )
     156             :             // check if the current element was removed and the iterator increased in the meantime
     157           0 :             m_aIterators[ nIndex ].m_bWasInvalidated = false;
     158             :         else
     159           0 :             ++m_aIterators[ nIndex ].m_aIt;
     160             :     }
     161           0 :     m_aIterators.pop_back();
     162           0 : }
     163             : 
     164             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10