LCOV - code coverage report
Current view: top level - libreoffice/svl/source/notify - listener.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 34 51 66.7 %
Date: 2012-12-27 Functions: 5 14 35.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             : 
      21             : #include <tools/debug.hxx>
      22             : #include <svl/broadcast.hxx>
      23             : #include <svl/listener.hxx>
      24             : #include "listenerbase.hxx"
      25             : #include <svl/listeneriter.hxx>
      26             : 
      27             : 
      28             : //====================================================================
      29           0 : TYPEINIT0(SvtListener);
      30             : 
      31             : //====================================================================
      32             : // simple ctor of class SvtListener
      33             : 
      34        3265 : SvtListener::SvtListener()
      35        3265 :     : pBrdCastLst( 0 )
      36             : {
      37        3265 : }
      38             : //--------------------------------------------------------------------
      39             : 
      40             : // copy ctor of class SvtListener
      41             : 
      42           0 : SvtListener::SvtListener( const SvtListener &rListener )
      43           0 :     : pBrdCastLst( 0 )
      44             : {
      45           0 :     SvtListenerBase* pLst = rListener.pBrdCastLst;
      46           0 :     while( pLst )
      47             :     {
      48           0 :         new SvtListenerBase( *this, *pLst->GetBroadcaster() );
      49           0 :         pLst = pLst->GetNext();
      50             :     }
      51           0 : }
      52             : //--------------------------------------------------------------------
      53             : 
      54             : // unregisteres the SvtListener from its SvtBroadcasters
      55             : 
      56        3125 : SvtListener::~SvtListener()
      57             : {
      58        3125 :     EndListeningAll();
      59        3125 : }
      60             : 
      61             : //--------------------------------------------------------------------
      62             : 
      63             : // registeres at a specific SvtBroadcaster
      64             : 
      65        7380 : sal_Bool SvtListener::StartListening( SvtBroadcaster& rBroadcaster )
      66             : {
      67        7380 :     const SvtListenerBase* pLst = pBrdCastLst;
      68       26898 :     while( pLst )
      69             :     {
      70       12499 :         if( &rBroadcaster == pLst->GetBroadcaster() )
      71             :         {
      72             :             // double, than return
      73         361 :             return sal_False;
      74             :         }
      75       12138 :         pLst = pLst->GetNext();
      76             :     }
      77        7019 :     new SvtListenerBase( *this, rBroadcaster );
      78        7019 :     return sal_True;
      79             : }
      80             : 
      81             : //--------------------------------------------------------------------
      82             : 
      83             : // unregisteres at a specific SvtBroadcaster
      84             : 
      85        3381 : sal_Bool SvtListener::EndListening( SvtBroadcaster& rBroadcaster )
      86             : {
      87        3381 :     SvtListenerBase *pLst = pBrdCastLst, *pPrev = pLst;
      88       12301 :     while( pLst )
      89             :     {
      90        8704 :         if( &rBroadcaster == pLst->GetBroadcaster() )
      91             :         {
      92        3165 :             if( pBrdCastLst == pLst )
      93        1278 :                 pBrdCastLst = pLst->GetNext();
      94             :             else
      95        1887 :                 pPrev->SetNext( pLst->GetNext() );
      96             : 
      97        3165 :             delete pLst;
      98        3165 :             return sal_True;
      99             :         }
     100        5539 :         pPrev = pLst;
     101        5539 :         pLst = pLst->GetNext();
     102             :     }
     103         216 :     return sal_False;
     104             : }
     105             : 
     106             : //--------------------------------------------------------------------
     107             : 
     108             : // unregisteres all Broadcasters
     109             : 
     110        3207 : void SvtListener::EndListeningAll()
     111             : {
     112        3207 :     SvtListenerBase *pLst = pBrdCastLst;
     113       10112 :     while( pLst )
     114             :     {
     115        3698 :         SvtListenerBase *pDel = pLst;
     116        3698 :         pLst = pLst->GetNext();
     117             : 
     118        3698 :         delete pDel;
     119             :     }
     120        3207 :     pBrdCastLst = 0;
     121        3207 : }
     122             : 
     123             : //--------------------------------------------------------------------
     124             : 
     125           0 : sal_Bool SvtListener::IsListening( SvtBroadcaster& rBroadcaster ) const
     126             : {
     127           0 :     const SvtListenerBase *pLst = pBrdCastLst;
     128           0 :     while( pLst )
     129             :     {
     130           0 :         if( &rBroadcaster == pLst->GetBroadcaster() )
     131           0 :             break;
     132           0 :         pLst = pLst->GetNext();
     133             :     }
     134           0 :     return 0 != pLst;
     135             : }
     136             : 
     137             : //--------------------------------------------------------------------
     138             : 
     139             : // base implementation of notification handler
     140             : 
     141           0 : void SvtListener::Notify( SvtBroadcaster&
     142             : #ifdef DBG_UTIL
     143             : rBC
     144             : #endif
     145             : , const SfxHint& )
     146             : {
     147             :     DBG_ASSERT( IsListening( rBC ),
     148             :                 "notification from unregistered broadcaster" );
     149           0 : }
     150             : 
     151             : 
     152             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10