LibreOffice Module sc (master)  1
refreshtimer.cxx
Go to the documentation of this file.
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>
22 
24 {
25  if ( b && nBlockRefresh )
26  --nBlockRefresh;
27  else if ( !b && nBlockRefresh < sal_uInt16(~0) )
28  ++nBlockRefresh;
29 }
30 
31 ScRefreshTimerProtector::ScRefreshTimerProtector( std::unique_ptr<ScRefreshTimerControl> const & rp )
32  :
33  m_rpControl( rp )
34 {
35  if ( m_rpControl )
36  {
37  m_rpControl->SetAllowRefresh( false );
38  // wait for any running refresh in another thread to finish
39  ::osl::MutexGuard aGuard( m_rpControl->GetMutex() );
40  }
41 }
42 
44 {
45  if ( m_rpControl )
46  m_rpControl->SetAllowRefresh( true );
47 }
48 
49 ScRefreshTimer::ScRefreshTimer() : ppControl(nullptr)
50 {
51  SetTimeout( 0 );
52 }
53 
54 ScRefreshTimer::ScRefreshTimer( sal_uLong nSeconds ) : ppControl(nullptr)
55 {
56  SetTimeout( nSeconds * 1000 );
57  Launch();
58 }
59 
60 ScRefreshTimer::ScRefreshTimer( const ScRefreshTimer& r ) : AutoTimer( r ), ppControl(nullptr)
61 {
62 }
63 
65 {
66  if ( IsActive() )
67  Stop();
68 }
69 
71 {
72  if(this == &r)
73  return *this;
74 
75  SetRefreshControl(nullptr);
77  return *this;
78 }
79 
81 {
82  return GetTimeout() == r.GetTimeout();
83 }
84 
86 {
87  return !ScRefreshTimer::operator==( r );
88 }
89 
90 void ScRefreshTimer::SetRefreshControl( std::unique_ptr<ScRefreshTimerControl> const * pp )
91 {
92  ppControl = pp;
93 }
94 
96 {
97  SetInvokeHandler( rLink );
98 }
99 
101 {
102  return GetTimeout() / 1000;
103 }
104 
106 {
107  Stop();
108 }
109 
111 {
112  bool bActive = IsActive();
113  if ( bActive && !nSeconds )
114  Stop();
115  SetTimeout( nSeconds * 1000 );
116  if ( !bActive && nSeconds )
117  Launch();
118 }
119 
121 {
122  if ( ppControl && *ppControl && (*ppControl)->IsRefreshAllowed() )
123  {
124  // now we COULD make the call in another thread ...
125  ::osl::MutexGuard aGuard( (*ppControl)->GetMutex() );
126  Timer::Invoke();
127  // restart from now on, don't execute immediately again if timed out
128  // a second time during refresh
129  if ( IsActive() )
130  Launch();
131  }
132 }
133 
135 {
136  if ( GetTimeout() )
138 }
139 
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScRefreshTimer & operator=(const ScRefreshTimer &r)
ScRefreshTimerProtector(std::unique_ptr< ScRefreshTimerControl > const &rp)
void SetRefreshDelay(sal_uLong nSeconds)
sal_uIntPtr sal_uLong
bool IsActive() const
std::unique_ptr< ScRefreshTimerControl > const & m_rpControl
bool operator!=(const ScRefreshTimer &r) const
void SetAllowRefresh(bool b)
void SetRefreshHandler(const Link< Timer *, void > &rLink)
sal_uInt64 GetTimeout() const
virtual ~ScRefreshTimer() override
virtual void Start() override
virtual void Invoke() override
virtual SC_DLLPUBLIC void Invoke() override
void SetTimeout(sal_uInt64 nTimeoutMs)
void StopRefreshTimer()
void Stop()
void SetRefreshControl(std::unique_ptr< ScRefreshTimerControl > const *pp)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
sal_uLong GetRefreshDelay() const
std::unique_ptr< ScRefreshTimerControl > const * ppControl
bool operator==(const ScRefreshTimer &r) const
Timer & operator=(const Timer &rTimer)