1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <refreshtimer.hxx>
21 #include <refreshtimerprotector.hxx>
23 void ScRefreshTimerControl::SetAllowRefresh( bool b
)
25 if ( b
&& nBlockRefresh
)
27 else if ( !b
&& nBlockRefresh
< sal_uInt16(~0) )
31 ScRefreshTimerProtector::ScRefreshTimerProtector( std::unique_ptr
<ScRefreshTimerControl
> const & rp
)
37 m_rpControl
->SetAllowRefresh( false );
38 // wait for any running refresh in another thread to finish
39 std::scoped_lock
aGuard( m_rpControl
->GetMutex() );
43 ScRefreshTimerProtector::~ScRefreshTimerProtector()
46 m_rpControl
->SetAllowRefresh( true );
49 ScRefreshTimer::ScRefreshTimer() : AutoTimer("ScRefreshTimer"), ppControl(nullptr)
54 ScRefreshTimer::ScRefreshTimer( sal_Int32 nRefreshDelaySeconds
) : AutoTimer("ScRefreshTimer"), ppControl(nullptr)
56 SetTimeout( nRefreshDelaySeconds
* 1000 );
60 ScRefreshTimer::ScRefreshTimer( const ScRefreshTimer
& r
) : AutoTimer( r
), ppControl(nullptr)
64 ScRefreshTimer::~ScRefreshTimer()
70 ScRefreshTimer
& ScRefreshTimer::operator=( const ScRefreshTimer
& r
)
75 SetRefreshControl(nullptr);
76 AutoTimer::operator=( r
);
80 bool ScRefreshTimer::operator==( const ScRefreshTimer
& r
) const
82 return GetTimeout() == r
.GetTimeout();
85 bool ScRefreshTimer::operator!=( const ScRefreshTimer
& r
) const
87 return !ScRefreshTimer::operator==( r
);
90 void ScRefreshTimer::SetRefreshControl( std::unique_ptr
<ScRefreshTimerControl
> const * pp
)
95 void ScRefreshTimer::SetRefreshHandler( const Link
<Timer
*, void>& rLink
)
97 SetInvokeHandler( rLink
);
100 sal_Int32
ScRefreshTimer::GetRefreshDelaySeconds() const
102 return GetTimeout() / 1000;
105 void ScRefreshTimer::StopRefreshTimer()
110 void ScRefreshTimer::SetRefreshDelay( sal_Int32 nSeconds
)
112 bool bActive
= IsActive();
113 if ( bActive
&& !nSeconds
)
115 SetTimeout( nSeconds
* 1000 );
116 if ( !bActive
&& nSeconds
)
120 void ScRefreshTimer::Invoke()
122 if ( ppControl
&& *ppControl
&& (*ppControl
)->IsRefreshAllowed() )
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
134 void ScRefreshTimer::Launch()
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */