1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: refreshtimer.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_REFRESHTIMER_HXX
32 #define SC_REFRESHTIMER_HXX
34 #include <tools/list.hxx>
35 #include <vcl/timer.hxx>
36 #include <vos/mutex.hxx>
39 #define SC_REFRESHTIMER_CONTROL_LIST 0
40 #if SC_REFRESHTIMER_CONTROL_LIST
42 DECLARE_LIST( ScRefreshTimerList
, ScRefreshTimer
* )
45 class ScRefreshTimerControl
52 #if SC_REFRESHTIMER_CONTROL_LIST
53 ScRefreshTimerList aList
;
56 ScRefreshTimerControl() : nBlockRefresh(0) {}
58 void SetAllowRefresh( BOOL b
)
60 if ( b
&& nBlockRefresh
)
62 else if ( !b
&& nBlockRefresh
< (USHORT
)(~0) )
65 BOOL
IsRefreshAllowed() const { return !nBlockRefresh
; }
66 ::vos::OMutex
& GetMutex() { return aMutex
; }
70 class ScRefreshTimerProtector
73 ScRefreshTimerControl
* const * ppControl
;
75 ScRefreshTimerProtector( ScRefreshTimerControl
* const * pp
);
76 ~ScRefreshTimerProtector()
78 if ( ppControl
&& *ppControl
)
79 (*ppControl
)->SetAllowRefresh( TRUE
);
84 class ScRefreshTimer
: public AutoTimer
87 ScRefreshTimerControl
* const * ppControl
;
89 void AppendToControl()
91 #if SC_REFRESHTIMER_CONTROL_LIST
92 if ( ppControl
&& *ppControl
)
93 (*ppControl
)->aList
.Insert( this, LIST_APPEND
);
96 void RemoveFromControl()
98 #if SC_REFRESHTIMER_CONTROL_LIST
99 if ( ppControl
&& *ppControl
)
100 (*ppControl
)->aList
.Remove( this );
111 ScRefreshTimer() : ppControl(0)
113 ScRefreshTimer( ULONG nSeconds
) : ppControl(0)
115 SetTimeout( nSeconds
* 1000 );
118 ScRefreshTimer( const ScRefreshTimer
& r
)
119 : AutoTimer( r
), ppControl(0)
121 virtual ~ScRefreshTimer();
123 ScRefreshTimer
& operator=( const ScRefreshTimer
& r
)
125 SetRefreshControl(0);
126 AutoTimer::operator=( r
);
130 BOOL
operator==( const ScRefreshTimer
& r
) const
131 { return GetTimeout() == r
.GetTimeout(); }
133 BOOL
operator!=( const ScRefreshTimer
& r
) const
134 { return !ScRefreshTimer::operator==( r
); }
136 void StartRefreshTimer()
139 void SetRefreshControl( ScRefreshTimerControl
* const * pp
)
146 void SetRefreshHandler( const Link
& rLink
)
147 { SetTimeoutHdl( rLink
); }
149 ULONG
GetRefreshDelay() const
150 { return GetTimeout() / 1000; }
152 void StopRefreshTimer()
155 SC_DLLPUBLIC
virtual void SetRefreshDelay( ULONG nSeconds
);
156 SC_DLLPUBLIC
virtual void Timeout();
160 #endif // SC_REFRESHTIMER_HXX