LCOV - code coverage report
Current view: top level - libreoffice/sc/inc - refreshtimer.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 27 42 64.3 %
Date: 2012-12-27 Functions: 12 19 63.2 %
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             : #ifndef SC_REFRESHTIMER_HXX
      21             : #define SC_REFRESHTIMER_HXX
      22             : 
      23             : #include <vcl/timer.hxx>
      24             : #include <osl/mutex.hxx>
      25             : #include "scdllapi.h"
      26             : 
      27         108 : class ScRefreshTimerControl
      28             : {
      29             : private:
      30             :     ::osl::Mutex   aMutex;
      31             :     sal_uInt16         nBlockRefresh;
      32             : 
      33             : public:
      34         189 :     ScRefreshTimerControl() : nBlockRefresh(0) {}
      35             : 
      36        6066 :     void SetAllowRefresh( sal_Bool b )
      37             :     {
      38        6066 :         if ( b && nBlockRefresh )
      39        2979 :             --nBlockRefresh;
      40        3087 :         else if ( !b && nBlockRefresh < (sal_uInt16)(~0) )
      41        3087 :             ++nBlockRefresh;
      42        6066 :     }
      43             : 
      44           0 :     sal_Bool IsRefreshAllowed() const { return !nBlockRefresh; }
      45             : 
      46        3087 :     ::osl::Mutex& GetMutex() { return aMutex; }
      47             : };
      48             : 
      49             : class ScRefreshTimerProtector
      50             : {
      51             : private:
      52             :     ScRefreshTimerControl * const * ppControl;
      53             : 
      54             : public:
      55             :     ScRefreshTimerProtector( ScRefreshTimerControl * const * pp );
      56             : 
      57        3087 :     ~ScRefreshTimerProtector()
      58             :     {
      59        3087 :         if ( ppControl && *ppControl )
      60        2979 :             (*ppControl)->SetAllowRefresh( true );
      61        3087 :     }
      62             : };
      63             : 
      64             : class ScRefreshTimer : public AutoTimer
      65             : {
      66             : private:
      67             :     ScRefreshTimerControl * const * ppControl;
      68             : 
      69           8 :     void AppendToControl() {}
      70             : 
      71          28 :     void RemoveFromControl() {}
      72             : 
      73           0 :     void Start()
      74             :     {
      75           0 :         if ( GetTimeout() )
      76           0 :             AutoTimer::Start();
      77           0 :     }
      78             : 
      79             : public:
      80          13 :     ScRefreshTimer() : ppControl(0) { SetTimeout( 0 ); }
      81             : 
      82           0 :     ScRefreshTimer( sal_uLong nSeconds ) : ppControl(0)
      83             :     {
      84           0 :         SetTimeout( nSeconds * 1000 );
      85           0 :         Start();
      86           0 :     }
      87             : 
      88           8 :     ScRefreshTimer( const ScRefreshTimer& r ) : AutoTimer( r ), ppControl(0) {}
      89             : 
      90             :     virtual ~ScRefreshTimer();
      91             : 
      92           8 :     ScRefreshTimer& operator=( const ScRefreshTimer& r )
      93             :     {
      94           8 :         SetRefreshControl(0);
      95           8 :         AutoTimer::operator=( r );
      96           8 :         return *this;
      97             :     }
      98             : 
      99           0 :     sal_Bool operator==( const ScRefreshTimer& r ) const
     100           0 :         { return GetTimeout() == r.GetTimeout(); }
     101             : 
     102           0 :     sal_Bool operator!=( const ScRefreshTimer& r ) const
     103           0 :         { return !ScRefreshTimer::operator==( r ); }
     104             : 
     105             :     void StartRefreshTimer() { Start(); }
     106             : 
     107           8 :     void SetRefreshControl( ScRefreshTimerControl * const * pp )
     108             :     {
     109           8 :         RemoveFromControl();
     110           8 :         ppControl = pp;
     111           8 :         AppendToControl();
     112           8 :     }
     113             : 
     114           0 :     void SetRefreshHandler( const Link& rLink ) { SetTimeoutHdl( rLink ); }
     115             : 
     116           0 :     sal_uLong GetRefreshDelay() const { return GetTimeout() / 1000; }
     117             : 
     118          20 :     void StopRefreshTimer() { Stop(); }
     119             : 
     120             :     SC_DLLPUBLIC virtual void SetRefreshDelay( sal_uLong nSeconds );
     121             : 
     122             :     SC_DLLPUBLIC virtual void Timeout();
     123             : };
     124             : 
     125             : #endif // SC_REFRESHTIMER_HXX
     126             : 
     127             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10