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 :
22 :
23 3087 : ScRefreshTimerProtector::ScRefreshTimerProtector( ScRefreshTimerControl * const * pp )
24 : :
25 3087 : ppControl( pp )
26 : {
27 3087 : if ( ppControl && *ppControl )
28 : {
29 3087 : (*ppControl)->SetAllowRefresh( false );
30 : // wait for any running refresh in another thread to finnish
31 3087 : ::osl::MutexGuard aGuard( (*ppControl)->GetMutex() );
32 : }
33 3087 : }
34 :
35 :
36 40 : ScRefreshTimer::~ScRefreshTimer()
37 : {
38 20 : if ( IsActive() )
39 0 : Stop();
40 20 : RemoveFromControl();
41 20 : }
42 :
43 :
44 0 : void ScRefreshTimer::SetRefreshDelay( sal_uLong nSeconds )
45 : {
46 0 : sal_Bool bActive = IsActive();
47 0 : if ( bActive && !nSeconds )
48 0 : Stop();
49 0 : SetTimeout( nSeconds * 1000 );
50 0 : if ( !bActive && nSeconds )
51 0 : Start();
52 0 : }
53 :
54 :
55 0 : void ScRefreshTimer::Timeout()
56 : {
57 0 : if ( ppControl && *ppControl && (*ppControl)->IsRefreshAllowed() )
58 : {
59 : // now we COULD make the call in another thread ...
60 0 : ::osl::MutexGuard aGuard( (*ppControl)->GetMutex() );
61 0 : maTimeoutHdl.Call( this );
62 : // restart from now on, don't execute immediately again if timed out
63 : // a second time during refresh
64 0 : if ( IsActive() )
65 0 : Start();
66 : }
67 0 : }
68 :
69 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|