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

Generated by: LCOV version 1.10