merge the formfield patch from ooo-build
[ooovba.git] / sc / inc / refreshtimer.hxx
blob069b103180ee1308e33c4d535706327fef32210d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: refreshtimer.hxx,v $
10 * $Revision: 1.4 $
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>
37 #include <scdllapi.h>
39 #define SC_REFRESHTIMER_CONTROL_LIST 0
40 #if SC_REFRESHTIMER_CONTROL_LIST
41 class ScRefreshTimer;
42 DECLARE_LIST( ScRefreshTimerList, ScRefreshTimer* )
43 #endif
45 class ScRefreshTimerControl
47 private:
48 ::vos::OMutex aMutex;
49 USHORT nBlockRefresh;
51 public:
52 #if SC_REFRESHTIMER_CONTROL_LIST
53 ScRefreshTimerList aList;
54 #endif
56 ScRefreshTimerControl() : nBlockRefresh(0) {}
58 void SetAllowRefresh( BOOL b )
60 if ( b && nBlockRefresh )
61 --nBlockRefresh;
62 else if ( !b && nBlockRefresh < (USHORT)(~0) )
63 ++nBlockRefresh;
65 BOOL IsRefreshAllowed() const { return !nBlockRefresh; }
66 ::vos::OMutex& GetMutex() { return aMutex; }
70 class ScRefreshTimerProtector
72 private:
73 ScRefreshTimerControl * const * ppControl;
74 public:
75 ScRefreshTimerProtector( ScRefreshTimerControl * const * pp );
76 ~ScRefreshTimerProtector()
78 if ( ppControl && *ppControl )
79 (*ppControl)->SetAllowRefresh( TRUE );
84 class ScRefreshTimer : public AutoTimer
86 private:
87 ScRefreshTimerControl * const * ppControl;
89 void AppendToControl()
91 #if SC_REFRESHTIMER_CONTROL_LIST
92 if ( ppControl && *ppControl )
93 (*ppControl)->aList.Insert( this, LIST_APPEND );
94 #endif
96 void RemoveFromControl()
98 #if SC_REFRESHTIMER_CONTROL_LIST
99 if ( ppControl && *ppControl )
100 (*ppControl)->aList.Remove( this );
101 #endif
104 void Start()
106 if ( GetTimeout() )
107 AutoTimer::Start();
110 public:
111 ScRefreshTimer() : ppControl(0)
112 { SetTimeout( 0 ); }
113 ScRefreshTimer( ULONG nSeconds ) : ppControl(0)
115 SetTimeout( nSeconds * 1000 );
116 Start();
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 );
127 return *this;
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()
137 { Start(); }
139 void SetRefreshControl( ScRefreshTimerControl * const * pp )
141 RemoveFromControl();
142 ppControl = pp;
143 AppendToControl();
146 void SetRefreshHandler( const Link& rLink )
147 { SetTimeoutHdl( rLink ); }
149 ULONG GetRefreshDelay() const
150 { return GetTimeout() / 1000; }
152 void StopRefreshTimer()
153 { Stop(); }
155 SC_DLLPUBLIC virtual void SetRefreshDelay( ULONG nSeconds );
156 SC_DLLPUBLIC virtual void Timeout();
160 #endif // SC_REFRESHTIMER_HXX