Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef SC_REFRESHTIMER_HXX
30 : : #define SC_REFRESHTIMER_HXX
31 : :
32 : : #include <vcl/timer.hxx>
33 : : #include <osl/mutex.hxx>
34 : : #include "scdllapi.h"
35 : :
36 : 695 : class ScRefreshTimerControl
37 : : {
38 : : private:
39 : : ::osl::Mutex aMutex;
40 : : sal_uInt16 nBlockRefresh;
41 : :
42 : : public:
43 : 846 : ScRefreshTimerControl() : nBlockRefresh(0) {}
44 : :
45 : 32029 : void SetAllowRefresh( sal_Bool b )
46 : : {
47 [ + + ][ + - ]: 32029 : if ( b && nBlockRefresh )
48 : 15667 : --nBlockRefresh;
49 [ + - ][ + - ]: 16362 : else if ( !b && nBlockRefresh < (sal_uInt16)(~0) )
50 : 16362 : ++nBlockRefresh;
51 : 32029 : }
52 : :
53 : 0 : sal_Bool IsRefreshAllowed() const { return !nBlockRefresh; }
54 : :
55 : 21570 : ::osl::Mutex& GetMutex() { return aMutex; }
56 : : };
57 : :
58 : : class ScRefreshTimerProtector
59 : : {
60 : : private:
61 : : ScRefreshTimerControl * const * ppControl;
62 : :
63 : : public:
64 : : ScRefreshTimerProtector( ScRefreshTimerControl * const * pp );
65 : :
66 : 16362 : ~ScRefreshTimerProtector()
67 : : {
68 [ + - ][ + + ]: 16362 : if ( ppControl && *ppControl )
69 : 15667 : (*ppControl)->SetAllowRefresh( true );
70 : 16362 : }
71 : : };
72 : :
73 : : class ScRefreshTimer : public AutoTimer
74 : : {
75 : : private:
76 : : ScRefreshTimerControl * const * ppControl;
77 : :
78 : 67 : void AppendToControl() {}
79 : :
80 : 747 : void RemoveFromControl() {}
81 : :
82 : 21 : void Start()
83 : : {
84 [ + + ]: 21 : if ( GetTimeout() )
85 : 13 : AutoTimer::Start();
86 : 21 : }
87 : :
88 : : public:
89 [ + - ]: 63 : ScRefreshTimer() : ppControl(0) { SetTimeout( 0 ); }
90 : :
91 : 18 : ScRefreshTimer( sal_uLong nSeconds ) : ppControl(0)
92 : : {
93 [ + - ]: 18 : SetTimeout( nSeconds * 1000 );
94 [ + - ]: 18 : Start();
95 : 18 : }
96 : :
97 : 602 : ScRefreshTimer( const ScRefreshTimer& r ) : AutoTimer( r ), ppControl(0) {}
98 : :
99 : : virtual ~ScRefreshTimer();
100 : :
101 : 48 : ScRefreshTimer& operator=( const ScRefreshTimer& r )
102 : : {
103 : 48 : SetRefreshControl(0);
104 : 48 : AutoTimer::operator=( r );
105 : 48 : return *this;
106 : : }
107 : :
108 : 0 : sal_Bool operator==( const ScRefreshTimer& r ) const
109 : 0 : { return GetTimeout() == r.GetTimeout(); }
110 : :
111 : 0 : sal_Bool operator!=( const ScRefreshTimer& r ) const
112 : 0 : { return !ScRefreshTimer::operator==( r ); }
113 : :
114 : : void StartRefreshTimer() { Start(); }
115 : :
116 : 67 : void SetRefreshControl( ScRefreshTimerControl * const * pp )
117 : : {
118 : 67 : RemoveFromControl();
119 : 67 : ppControl = pp;
120 : 67 : AppendToControl();
121 : 67 : }
122 : :
123 : 19 : void SetRefreshHandler( const Link& rLink ) { SetTimeoutHdl( rLink ); }
124 : :
125 : 64 : sal_uLong GetRefreshDelay() const { return GetTimeout() / 1000; }
126 : :
127 : 680 : void StopRefreshTimer() { Stop(); }
128 : :
129 : : SC_DLLPUBLIC virtual void SetRefreshDelay( sal_uLong nSeconds );
130 : :
131 : : SC_DLLPUBLIC virtual void Timeout();
132 : : };
133 : :
134 : : #endif // SC_REFRESHTIMER_HXX
135 : :
136 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|