LCOV - code coverage report
Current view: top level - sc/source/core/tool - refreshtimer.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 67 0.0 %
Date: 2014-04-14 Functions: 0 18 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 "refreshtimer.hxx"
      21             : #include "refreshtimerprotector.hxx"
      22             : 
      23           0 : void ScRefreshTimerControl::SetAllowRefresh( bool b )
      24             : {
      25           0 :     if ( b && nBlockRefresh )
      26           0 :         --nBlockRefresh;
      27           0 :     else if ( !b && nBlockRefresh < (sal_uInt16)(~0) )
      28           0 :         ++nBlockRefresh;
      29           0 : }
      30             : 
      31           0 : ScRefreshTimerProtector::ScRefreshTimerProtector( ScRefreshTimerControl * const * pp )
      32             :         :
      33           0 :         ppControl( pp )
      34             : {
      35           0 :     if ( ppControl && *ppControl )
      36             :     {
      37           0 :         (*ppControl)->SetAllowRefresh( false );
      38             :         // wait for any running refresh in another thread to finnish
      39           0 :         ::osl::MutexGuard aGuard( (*ppControl)->GetMutex() );
      40             :     }
      41           0 : }
      42             : 
      43           0 : ScRefreshTimerProtector::~ScRefreshTimerProtector()
      44             : {
      45           0 :     if ( ppControl && *ppControl )
      46           0 :         (*ppControl)->SetAllowRefresh( true );
      47           0 : }
      48             : 
      49           0 : ScRefreshTimer::ScRefreshTimer() : ppControl(0)
      50             : {
      51           0 :     SetTimeout( 0 );
      52           0 : }
      53             : 
      54           0 : ScRefreshTimer::ScRefreshTimer( sal_uLong nSeconds ) : ppControl(0)
      55             : {
      56           0 :     SetTimeout( nSeconds * 1000 );
      57           0 :     Start();
      58           0 : }
      59             : 
      60           0 : ScRefreshTimer::ScRefreshTimer( const ScRefreshTimer& r ) : AutoTimer( r ), ppControl(0)
      61             : {
      62           0 : }
      63             : 
      64           0 : ScRefreshTimer::~ScRefreshTimer()
      65             : {
      66           0 :     if ( IsActive() )
      67           0 :         Stop();
      68           0 : }
      69             : 
      70           0 : ScRefreshTimer& ScRefreshTimer::operator=( const ScRefreshTimer& r )
      71             : {
      72           0 :     SetRefreshControl(0);
      73           0 :     AutoTimer::operator=( r );
      74           0 :     return *this;
      75             : }
      76             : 
      77           0 : bool ScRefreshTimer::operator==( const ScRefreshTimer& r ) const
      78             : {
      79           0 :     return GetTimeout() == r.GetTimeout();
      80             : }
      81             : 
      82           0 : bool ScRefreshTimer::operator!=( const ScRefreshTimer& r ) const
      83             : {
      84           0 :     return !ScRefreshTimer::operator==( r );
      85             : }
      86             : 
      87           0 : void ScRefreshTimer::SetRefreshControl( ScRefreshTimerControl * const * pp )
      88             : {
      89           0 :     ppControl = pp;
      90           0 : }
      91             : 
      92           0 : void ScRefreshTimer::SetRefreshHandler( const Link& rLink )
      93             : {
      94           0 :     SetTimeoutHdl( rLink );
      95           0 : }
      96             : 
      97           0 : sal_uLong ScRefreshTimer::GetRefreshDelay() const
      98             : {
      99           0 :     return GetTimeout() / 1000;
     100             : }
     101             : 
     102           0 : void ScRefreshTimer::StopRefreshTimer()
     103             : {
     104           0 :     Stop();
     105           0 : }
     106             : 
     107           0 : void ScRefreshTimer::SetRefreshDelay( sal_uLong nSeconds )
     108             : {
     109           0 :     sal_Bool bActive = IsActive();
     110           0 :     if ( bActive && !nSeconds )
     111           0 :         Stop();
     112           0 :     SetTimeout( nSeconds * 1000 );
     113           0 :     if ( !bActive && nSeconds )
     114           0 :         Start();
     115           0 : }
     116             : 
     117           0 : void ScRefreshTimer::Timeout()
     118             : {
     119           0 :     if ( ppControl && *ppControl && (*ppControl)->IsRefreshAllowed() )
     120             :     {
     121             :         // now we COULD make the call in another thread ...
     122           0 :         ::osl::MutexGuard aGuard( (*ppControl)->GetMutex() );
     123           0 :         maTimeoutHdl.Call( this );
     124             :         // restart from now on, don't execute immediately again if timed out
     125             :         // a second time during refresh
     126           0 :         if ( IsActive() )
     127           0 :             Start();
     128             :     }
     129           0 : }
     130             : 
     131           0 : void ScRefreshTimer::Start()
     132             : {
     133           0 :     if ( GetTimeout() )
     134           0 :         AutoTimer::Start();
     135           0 : }
     136             : 
     137             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10