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

Generated by: LCOV version 1.10