xref: /trunk/main/sc/source/core/tool/refreshtimer.cxx (revision b3f79822)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 
28 
29 #include "refreshtimer.hxx"
30 
31 
ScRefreshTimerProtector(ScRefreshTimerControl * const * pp)32 ScRefreshTimerProtector::ScRefreshTimerProtector( ScRefreshTimerControl * const * pp )
33 		:
34 		ppControl( pp )
35 {
36 	if ( ppControl && *ppControl )
37 	{
38 		(*ppControl)->SetAllowRefresh( sal_False );
39 		// wait for any running refresh in another thread to finnish
40 		::vos::OGuard aGuard( (*ppControl)->GetMutex() );
41 	}
42 }
43 
44 
~ScRefreshTimer()45 ScRefreshTimer::~ScRefreshTimer()
46 {
47 	if ( IsActive() )
48 		Stop();
49 	RemoveFromControl();
50 }
51 
52 
SetRefreshDelay(sal_uLong nSeconds)53 void ScRefreshTimer::SetRefreshDelay( sal_uLong nSeconds )
54 {
55 	sal_Bool bActive = IsActive();
56 	if ( bActive && !nSeconds )
57 		Stop();
58 	SetTimeout( nSeconds * 1000 );
59 	if ( !bActive && nSeconds )
60 		Start();
61 }
62 
63 
Timeout()64 void ScRefreshTimer::Timeout()
65 {
66 	if ( ppControl && *ppControl && (*ppControl)->IsRefreshAllowed() )
67 	{
68 		// now we COULD make the call in another thread ...
69 		::vos::OGuard aGuard( (*ppControl)->GetMutex() );
70 		maTimeoutHdl.Call( this );
71 		// restart from now on, don't execute immediately again if timed out
72 		// a second time during refresh
73 		if ( IsActive() )
74 			Start();
75 	}
76 }
77 
78