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 )
27 else if ( !b && nBlockRefresh < sal_uInt16(~0) )
29}
30
31ScRefreshTimerProtector::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 std::scoped_lock aGuard( m_rpControl->GetMutex() );
40 }
41}
42
44{
45 if ( m_rpControl )
46 m_rpControl->SetAllowRefresh( true );
47}
48
49ScRefreshTimer::ScRefreshTimer() : AutoTimer("ScRefreshTimer"), ppControl(nullptr)
50{
51 SetTimeout( 0 );
53
54ScRefreshTimer::ScRefreshTimer( sal_Int32 nRefreshDelaySeconds ) : AutoTimer("ScRefreshTimer"), ppControl(nullptr)
55{
56 SetTimeout( nRefreshDelaySeconds * 1000 );
57 Launch();
58}
59
60ScRefreshTimer::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
90void 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
110void ScRefreshTimer::SetRefreshDelay( sal_Int32 nSeconds )
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 std::scoped_lock aGuard( (*ppControl)->GetMutex() );
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: */
void SetAllowRefresh(bool b)
ScRefreshTimerProtector(std::unique_ptr< ScRefreshTimerControl > const &rp)
std::unique_ptr< ScRefreshTimerControl > const & m_rpControl
sal_Int32 GetRefreshDelaySeconds() const
void StopRefreshTimer()
bool operator!=(const ScRefreshTimer &r) const
void SetRefreshHandler(const Link< Timer *, void > &rLink)
void SetRefreshControl(std::unique_ptr< ScRefreshTimerControl > const *pp)
virtual SC_DLLPUBLIC void Invoke() override
void SetRefreshDelay(sal_Int32 nSeconds)
virtual ~ScRefreshTimer() override
ScRefreshTimer & operator=(const ScRefreshTimer &r)
std::unique_ptr< ScRefreshTimerControl > const * ppControl
bool operator==(const ScRefreshTimer &r) const
bool IsActive() const
void Stop()
void SetTimeout(sal_uInt64 nTimeoutMs)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
virtual void Start(bool bStartTimer=true) override
virtual void Invoke() override
Timer & operator=(const Timer &rTimer)
sal_uInt64 GetTimeout() const