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 : #ifndef SC_REFRESHTIMER_HXX
21 : #define SC_REFRESHTIMER_HXX
22 :
23 : #include <vcl/timer.hxx>
24 : #include <osl/mutex.hxx>
25 : #include "scdllapi.h"
26 :
27 469 : class ScRefreshTimerControl
28 : {
29 : private:
30 : ::osl::Mutex aMutex;
31 : sal_uInt16 nBlockRefresh;
32 :
33 : public:
34 578 : ScRefreshTimerControl() : nBlockRefresh(0) {}
35 :
36 44583 : void SetAllowRefresh( sal_Bool b )
37 : {
38 44583 : if ( b && nBlockRefresh )
39 22057 : --nBlockRefresh;
40 22526 : else if ( !b && nBlockRefresh < (sal_uInt16)(~0) )
41 22526 : ++nBlockRefresh;
42 44583 : }
43 :
44 0 : sal_Bool IsRefreshAllowed() const { return !nBlockRefresh; }
45 :
46 22526 : ::osl::Mutex& GetMutex() { return aMutex; }
47 : };
48 :
49 : class ScRefreshTimerProtector
50 : {
51 : private:
52 : ScRefreshTimerControl * const * ppControl;
53 :
54 : public:
55 : ScRefreshTimerProtector( ScRefreshTimerControl * const * pp );
56 :
57 22526 : ~ScRefreshTimerProtector()
58 : {
59 22526 : if ( ppControl && *ppControl )
60 22057 : (*ppControl)->SetAllowRefresh( true );
61 22526 : }
62 : };
63 :
64 : class ScRefreshTimer : public AutoTimer
65 : {
66 : private:
67 : ScRefreshTimerControl * const * ppControl;
68 :
69 68 : void AppendToControl() {}
70 :
71 533 : void RemoveFromControl() {}
72 :
73 21 : void Start()
74 : {
75 21 : if ( GetTimeout() )
76 13 : AutoTimer::Start();
77 21 : }
78 :
79 : public:
80 31 : ScRefreshTimer() : ppControl(0) { SetTimeout( 0 ); }
81 :
82 18 : ScRefreshTimer( sal_uLong nSeconds ) : ppControl(0)
83 : {
84 18 : SetTimeout( nSeconds * 1000 );
85 18 : Start();
86 18 : }
87 :
88 417 : ScRefreshTimer( const ScRefreshTimer& r ) : AutoTimer( r ), ppControl(0) {}
89 :
90 : virtual ~ScRefreshTimer();
91 :
92 49 : ScRefreshTimer& operator=( const ScRefreshTimer& r )
93 : {
94 49 : SetRefreshControl(0);
95 49 : AutoTimer::operator=( r );
96 49 : return *this;
97 : }
98 :
99 0 : sal_Bool operator==( const ScRefreshTimer& r ) const
100 0 : { return GetTimeout() == r.GetTimeout(); }
101 :
102 0 : sal_Bool operator!=( const ScRefreshTimer& r ) const
103 0 : { return !ScRefreshTimer::operator==( r ); }
104 :
105 : void StartRefreshTimer() { Start(); }
106 :
107 68 : void SetRefreshControl( ScRefreshTimerControl * const * pp )
108 : {
109 68 : RemoveFromControl();
110 68 : ppControl = pp;
111 68 : AppendToControl();
112 68 : }
113 :
114 19 : void SetRefreshHandler( const Link& rLink ) { SetTimeoutHdl( rLink ); }
115 :
116 64 : sal_uLong GetRefreshDelay() const { return GetTimeout() / 1000; }
117 :
118 465 : void StopRefreshTimer() { Stop(); }
119 :
120 : SC_DLLPUBLIC virtual void SetRefreshDelay( sal_uLong nSeconds );
121 :
122 : SC_DLLPUBLIC virtual void Timeout();
123 : };
124 :
125 : #endif // SC_REFRESHTIMER_HXX
126 :
127 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|