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

Generated by: LCOV version 1.10