LCOV - code coverage report
Current view: top level - vcl/source/app - vclevent.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 29 76 38.2 %
Date: 2012-08-25 Functions: 11 28 39.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 36 162 22.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "vcl/vclevent.hxx"
      31                 :            : 
      32                 :            : #include "svdata.hxx"
      33                 :            : 
      34                 :            : #include <com/sun/star/accessibility/XAccessible.hpp>
      35                 :            : 
      36                 :            : using ::com::sun::star::uno::Reference;
      37                 :            : using ::com::sun::star::accessibility::XAccessible;
      38                 :            : 
      39         [ -  + ]:       2302 : TYPEINIT0(VclSimpleEvent);
      40 [ +  - ][ #  # ]:   32371703 : TYPEINIT1(VclWindowEvent, VclSimpleEvent);
      41 [ +  + ][ -  + ]:       7849 : TYPEINIT1(VclMenuEvent, VclSimpleEvent);
      42                 :            : 
      43                 :          0 : VclAccessibleEvent::VclAccessibleEvent( sal_uLong n, const Reference<XAccessible>& rxAccessible ) :
      44                 :            :     VclSimpleEvent(n),
      45                 :          0 :     mxAccessible(rxAccessible)
      46                 :            : {
      47                 :          0 : }
      48                 :            : 
      49                 :          0 : VclAccessibleEvent::~VclAccessibleEvent()
      50                 :            : {
      51         [ #  # ]:          0 : }
      52                 :            : 
      53                 :          0 : Reference<XAccessible> VclAccessibleEvent::GetAccessible() const
      54                 :            : {
      55                 :          0 :     return mxAccessible;
      56                 :            : }
      57                 :            : 
      58                 :   12052507 : void VclEventListeners::Call( VclSimpleEvent* pEvent ) const
      59                 :            : {
      60         [ +  + ]:   12052507 :     if ( m_aListeners.empty() )
      61                 :   12052507 :         return;
      62                 :            : 
      63                 :            :     // Copy the list, because this can be destroyed when calling a Link...
      64         [ +  - ]:    4600585 :     std::list<Link> aCopy( m_aListeners );
      65                 :    4600585 :     std::list<Link>::iterator aIter( aCopy.begin() );
      66 [ +  - ][ +  + ]:    4600585 :     if( pEvent->IsA( VclWindowEvent::StaticType() ) )
                 [ +  - ]
      67                 :            :     {
      68                 :    4599434 :         VclWindowEvent* pWinEvent = static_cast<VclWindowEvent*>(pEvent);
      69         [ +  - ]:    4599434 :         ImplDelData aDel( pWinEvent->GetWindow() );
      70 [ +  - ][ +  + ]:   12298235 :         while ( aIter != aCopy.end() && ! aDel.IsDead() )
         [ +  - ][ +  - ]
           [ +  +  #  # ]
      71                 :            :         {
      72         [ +  - ]:    7698801 :             Link &rLink = *aIter;
      73                 :            :             // check this hasn't been removed in some re-enterancy scenario fdo#47368
      74 [ +  - ][ +  - ]:    7698801 :             if( std::find(m_aListeners.begin(), m_aListeners.end(), rLink) != m_aListeners.end() )
                 [ +  - ]
      75         [ +  - ]:    7698801 :                 rLink.Call( pEvent );
      76         [ +  - ]:    7698801 :             aIter++;
      77         [ +  - ]:    4599434 :         }
      78                 :            :     }
      79                 :            :     else
      80                 :            :     {
      81 [ +  - ][ +  + ]:       2354 :         while ( aIter != aCopy.end() )
      82                 :            :         {
      83         [ +  - ]:       1203 :             Link &rLink = *aIter;
      84 [ +  - ][ +  - ]:       1203 :             if( std::find(m_aListeners.begin(), m_aListeners.end(), rLink) != m_aListeners.end() )
                 [ +  - ]
      85         [ +  - ]:       1203 :                 rLink.Call( pEvent );
      86         [ +  - ]:       1203 :             aIter++;
      87                 :            :         }
      88                 :   12052507 :     }
      89                 :            : }
      90                 :            : 
      91                 :          0 : sal_Bool VclEventListeners::Process( VclSimpleEvent* pEvent ) const
      92                 :            : {
      93         [ #  # ]:          0 :     if ( m_aListeners.empty() )
      94                 :          0 :         return sal_False;
      95                 :            : 
      96                 :          0 :     sal_Bool bProcessed = sal_False;
      97                 :            :     // Copy the list, because this can be destroyed when calling a Link...
      98         [ #  # ]:          0 :     std::list<Link> aCopy( m_aListeners );
      99                 :          0 :     std::list<Link>::iterator aIter( aCopy.begin() );
     100 [ #  # ][ #  # ]:          0 :     while ( aIter != aCopy.end() )
     101                 :            :     {
     102 [ #  # ][ #  # ]:          0 :         if( (*aIter).Call( pEvent ) != 0 )
                 [ #  # ]
     103                 :            :         {
     104                 :          0 :             bProcessed = sal_True;
     105                 :          0 :             break;
     106                 :            :         }
     107         [ #  # ]:          0 :         aIter++;
     108                 :            :     }
     109                 :          0 :     return bProcessed;
     110                 :            : }
     111                 :            : 
     112                 :      63927 : void VclEventListeners::addListener( const Link& rListener )
     113                 :            : {
     114                 :      63927 :     m_aListeners.push_back( rListener );
     115                 :      63927 : }
     116                 :            : 
     117                 :      84383 : void VclEventListeners::removeListener( const Link& rListener )
     118                 :            : {
     119                 :      84383 :     m_aListeners.remove( rListener );
     120                 :      84383 : }
     121                 :            : 
     122 [ #  # ][ #  # ]:          0 : VclEventListeners2::VclEventListeners2()
     123                 :            : {
     124                 :          0 : }
     125                 :            : 
     126                 :          0 : VclEventListeners2::~VclEventListeners2()
     127                 :            : {
     128                 :          0 : }
     129                 :            : 
     130                 :          0 : void VclEventListeners2::addListener( const Link& i_rLink )
     131                 :            : {
     132                 :            :     // ensure uniqueness
     133 [ #  # ][ #  # ]:          0 :     for( std::list< Link >::const_iterator it = m_aListeners.begin(); it != m_aListeners.end(); ++it )
         [ #  # ][ #  # ]
                 [ #  # ]
     134                 :            :     {
     135 [ #  # ][ #  # ]:          0 :         if( *it == i_rLink )
                 [ #  # ]
     136                 :          0 :             return;
     137                 :            :     }
     138                 :          0 :     m_aListeners.push_back( i_rLink );
     139                 :            : }
     140                 :            : 
     141                 :          0 : void VclEventListeners2::removeListener( const Link& i_rLink )
     142                 :            : {
     143                 :          0 :     size_t n = m_aIterators.size();
     144         [ #  # ]:          0 :     for( size_t i = 0; i < n; i++ )
     145                 :            :     {
     146 [ #  # ][ #  # ]:          0 :         if( m_aIterators[i].m_aIt != m_aListeners.end() && *m_aIterators[i].m_aIt == i_rLink )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     147                 :            :         {
     148                 :          0 :             m_aIterators[i].m_bWasInvalidated = true;
     149                 :          0 :             ++m_aIterators[i].m_aIt;
     150                 :            :         }
     151                 :            :     }
     152                 :          0 :     m_aListeners.remove( i_rLink );
     153                 :          0 : }
     154                 :            : 
     155                 :          0 : void VclEventListeners2::callListeners( VclSimpleEvent* i_pEvent )
     156                 :            : {
     157         [ #  # ]:          0 :     vcl::DeletionListener aDel( this );
     158                 :            : 
     159         [ #  # ]:          0 :     m_aIterators.push_back(ListenerIt(m_aListeners.begin()));
     160                 :          0 :     size_t nIndex = m_aIterators.size() - 1;
     161 [ #  # ][ #  # ]:          0 :     while( ! aDel.isDeleted() && m_aIterators[ nIndex ].m_aIt != m_aListeners.end() )
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
     162                 :            :     {
     163 [ #  # ][ #  # ]:          0 :         m_aIterators[ nIndex ].m_aIt->Call( i_pEvent );
                 [ #  # ]
     164 [ #  # ][ #  # ]:          0 :         if( m_aIterators[ nIndex ].m_bWasInvalidated )
     165                 :            :             // check if the current element was removed and the iterator increased in the meantime
     166         [ #  # ]:          0 :             m_aIterators[ nIndex ].m_bWasInvalidated = false;
     167                 :            :         else
     168 [ #  # ][ #  # ]:          0 :             ++m_aIterators[ nIndex ].m_aIt;
     169                 :            :     }
     170 [ #  # ][ #  # ]:          0 :     m_aIterators.pop_back();
     171                 :          0 : }
     172                 :            : 
     173                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10