LCOV - code coverage report
Current view: top level - vcl/source/app - idlemgr.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 54 57 94.7 %
Date: 2015-06-13 12:38:46 Functions: 7 7 100.0 %
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/svapp.hxx>
      21             : 
      22             : #include <idlemgr.hxx>
      23             : 
      24       87356 : struct ImplIdleData
      25             : {
      26             :     Link<>      maIdleHdl;
      27             :     sal_uInt16      mnPriority;
      28             :     bool        mbTimeout;
      29             : };
      30             : 
      31             : #define IMPL_IDLETIMEOUT         350
      32             : 
      33          90 : ImplIdleMgr::ImplIdleMgr():
      34          90 :     mbInDestruction(false)
      35             : {
      36          90 :     mpIdleList  = new ImplIdleList();
      37             : 
      38          90 :     maTimer.SetTimeout( IMPL_IDLETIMEOUT );
      39          90 :     maTimer.SetTimeoutHdl( LINK( this, ImplIdleMgr, TimeoutHdl ) );
      40          90 : }
      41             : 
      42         178 : ImplIdleMgr::~ImplIdleMgr()
      43             : {
      44          89 :     mbInDestruction = true;
      45             :     // Liste loeschen
      46        1181 :     for ( size_t i = 0, n = mpIdleList->size(); i < n; ++i ) {
      47        1092 :         ImplIdleData* pIdleData = (*mpIdleList)[ i ];
      48        1092 :         pIdleData->maIdleHdl.Call( GetpApp() );
      49        1092 :         delete pIdleData;
      50             :     }
      51          89 :     mpIdleList->clear();
      52          89 :     delete mpIdleList;
      53          89 : }
      54             : 
      55       87356 : bool ImplIdleMgr::InsertIdleHdl( const Link<>& rLink, sal_uInt16 nPriority )
      56             : {
      57       87356 :     size_t nPos = (size_t)-1;
      58       87356 :     size_t n = mpIdleList->size();
      59     5855792 :     for ( size_t i = 0; i < n; ++i ) {
      60             :         // we need to check each element to verify that rLink isn't in the array
      61     5768436 :         if ( (*mpIdleList)[ i ]->maIdleHdl == rLink ) {
      62           0 :             return false;
      63             :         }
      64     5768436 :         if ( nPriority <= (*mpIdleList)[ i ]->mnPriority ) {
      65     5768436 :             nPos = i;
      66             :         }
      67             :     }
      68             : 
      69       87356 :     ImplIdleData* pIdleData = new ImplIdleData;
      70       87356 :     pIdleData->maIdleHdl    = rLink;
      71       87356 :     pIdleData->mnPriority   = nPriority;
      72       87356 :     pIdleData->mbTimeout    = false;
      73             : 
      74       87356 :     if ( nPos < mpIdleList->size() ) {
      75       84908 :         ImplIdleList::iterator it = mpIdleList->begin();
      76       84908 :         ::std::advance( it, nPos );
      77       84908 :         mpIdleList->insert( it, pIdleData );
      78             :     } else {
      79        2448 :         mpIdleList->push_back( pIdleData );
      80             :     }
      81             : 
      82             :     // if Timer was not started already then start it now
      83       87356 :     if ( !maTimer.IsActive() )
      84        2448 :         maTimer.Start();
      85             : 
      86       87356 :     return true;
      87             : }
      88             : 
      89       87355 : void ImplIdleMgr::RemoveIdleHdl( const Link<>& rLink )
      90             : {
      91       87355 :     if (mbInDestruction)
      92       88447 :         return;
      93             : 
      94     1988152 :     for ( ImplIdleList::iterator it = mpIdleList->begin(); it != mpIdleList->end(); ++it ) {
      95     1988152 :         if ( (*it)->maIdleHdl == rLink ) {
      96       86263 :             delete *it;
      97       86263 :             mpIdleList->erase( it );
      98       86263 :             break;
      99             :         }
     100             :     }
     101             : 
     102             :     // there are no more handlers...
     103       86263 :     if ( mpIdleList->empty() )
     104        2368 :         maTimer.Stop();
     105             : }
     106             : 
     107       13440 : IMPL_LINK_NOARG_TYPED(ImplIdleMgr, TimeoutHdl, Timer *, void)
     108             : {
     109       92983 :     for ( size_t i = 0; i < mpIdleList->size(); ++i ) {
     110       86263 :         ImplIdleData* pIdleData = (*mpIdleList)[ i ];
     111       86263 :         if ( !pIdleData->mbTimeout ) {
     112       86263 :             pIdleData->mbTimeout = true;
     113       86263 :             pIdleData->maIdleHdl.Call( GetpApp() );
     114             :             // May have been removed in the handler
     115     5829948 :             for ( size_t j = 0; j < mpIdleList->size(); ++j ) {
     116     5743685 :                 if ( (*mpIdleList)[ j ] == pIdleData ) {
     117           0 :                     pIdleData->mbTimeout = false;
     118           0 :                     break;
     119             :                 }
     120             :             }
     121             :         }
     122             :     }
     123        6720 : }
     124             : 
     125             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11