LCOV - code coverage report
Current view: top level - vcl/source/app - idlemgr.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 55 58 94.8 %
Date: 2014-11-03 Functions: 9 9 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      137959 : struct ImplIdleData
      25             : {
      26             :     Link        maIdleHdl;
      27             :     sal_uInt16      mnPriority;
      28             :     bool        mbTimeout;
      29             : };
      30             : 
      31             : #define IMPL_IDLETIMEOUT         350
      32             : 
      33         108 : ImplIdleMgr::ImplIdleMgr():
      34         108 :     mbInDestruction(false)
      35             : {
      36         108 :     mpIdleList  = new ImplIdleList();
      37             : 
      38         108 :     maTimer.SetTimeout( IMPL_IDLETIMEOUT );
      39         108 :     maTimer.SetTimeoutHdl( LINK( this, ImplIdleMgr, TimeoutHdl ) );
      40         108 : }
      41             : 
      42         212 : ImplIdleMgr::~ImplIdleMgr()
      43             : {
      44         106 :     mbInDestruction = true;
      45             :     // Liste loeschen
      46        9106 :     for ( size_t i = 0, n = mpIdleList->size(); i < n; ++i ) {
      47        9000 :         ImplIdleData* pIdleData = (*mpIdleList)[ i ];
      48        9000 :         pIdleData->maIdleHdl.Call( GetpApp() );
      49        9000 :         delete pIdleData;
      50             :     }
      51         106 :     mpIdleList->clear();
      52         106 :     delete mpIdleList;
      53         106 : }
      54             : 
      55      137959 : bool ImplIdleMgr::InsertIdleHdl( const Link& rLink, sal_uInt16 nPriority )
      56             : {
      57      137959 :     size_t nPos = (size_t)-1;
      58      137959 :     size_t n = mpIdleList->size();
      59    15674530 :     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    15536571 :         if ( (*mpIdleList)[ i ]->maIdleHdl == rLink ) {
      62           0 :             return false;
      63             :         }
      64    15536571 :         if ( nPriority <= (*mpIdleList)[ i ]->mnPriority ) {
      65    15536571 :             nPos = i;
      66             :         }
      67             :     }
      68             : 
      69      137959 :     ImplIdleData* pIdleData = new ImplIdleData;
      70      137959 :     pIdleData->maIdleHdl    = rLink;
      71      137959 :     pIdleData->mnPriority   = nPriority;
      72      137959 :     pIdleData->mbTimeout    = false;
      73             : 
      74      137959 :     if ( nPos < mpIdleList->size() ) {
      75      137140 :         ImplIdleList::iterator it = mpIdleList->begin();
      76      137140 :         ::std::advance( it, nPos );
      77      137140 :         mpIdleList->insert( it, pIdleData );
      78             :     } else {
      79         819 :         mpIdleList->push_back( pIdleData );
      80             :     }
      81             : 
      82             :     // if Timer was not started already then start it now
      83      137959 :     if ( !maTimer.IsActive() )
      84         819 :         maTimer.Start();
      85             : 
      86      137959 :     return true;
      87             : }
      88             : 
      89      137957 : void ImplIdleMgr::RemoveIdleHdl( const Link& rLink )
      90             : {
      91      137957 :     if (mbInDestruction)
      92      146957 :         return;
      93             : 
      94     4200687 :     for ( ImplIdleList::iterator it = mpIdleList->begin(); it != mpIdleList->end(); ++it ) {
      95     4200687 :         if ( (*it)->maIdleHdl == rLink ) {
      96      128957 :             delete *it;
      97      128957 :             mpIdleList->erase( it );
      98      128957 :             break;
      99             :         }
     100             :     }
     101             : 
     102             :     // there are no more handlers...
     103      128957 :     if ( mpIdleList->empty() )
     104         715 :         maTimer.Stop();
     105             : }
     106             : 
     107       16242 : IMPL_LINK_NOARG(ImplIdleMgr, TimeoutHdl)
     108             : {
     109      137078 :     for ( size_t i = 0; i < mpIdleList->size(); ++i ) {
     110      128957 :         ImplIdleData* pIdleData = (*mpIdleList)[ i ];
     111      128957 :         if ( !pIdleData->mbTimeout ) {
     112      128957 :             pIdleData->mbTimeout = true;
     113      128957 :             pIdleData->maIdleHdl.Call( GetpApp() );
     114             :             // May have been removed in the handler
     115    12419750 :             for ( size_t j = 0; j < mpIdleList->size(); ++j ) {
     116    12290793 :                 if ( (*mpIdleList)[ j ] == pIdleData ) {
     117           0 :                     pIdleData->mbTimeout = false;
     118           0 :                     break;
     119             :                 }
     120             :             }
     121             :         }
     122             :     }
     123             : 
     124        8121 :     return 0;
     125        1233 : }
     126             : 
     127             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10