xref: /AOO41X/main/svx/inc/svx/sdr/animation/scheduler.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _SDR_ANIMATION_SCHEDULER_HXX
29 #define _SDR_ANIMATION_SCHEDULER_HXX
30 
31 #include <sal/types.h>
32 #include <vcl/timer.hxx>
33 #include <svx/svxdllapi.h>
34 
35 //////////////////////////////////////////////////////////////////////////////
36 // event class
37 
38 namespace sdr
39 {
40 	namespace animation
41 	{
42 		class Event
43 		{
44 			// time of event in ms
45 			sal_uInt32										mnTime;
46 
47 			// pointer for simply linked list
48 			Event*											mpNext;
49 
50 		public:
51 			// constructor/destructor
52 			Event(sal_uInt32 nTime);
53 			SVX_DLLPUBLIC virtual ~Event();
54 
55 			// access to mpNext
56 			Event* GetNext() const;
57 			void SetNext(Event* pNew);
58 
59 			// get/set time
60 			sal_uInt32 GetTime() const;
61 			void SetTime(sal_uInt32 nNew);
62 
63 			// execute event
64 			virtual void Trigger(sal_uInt32 nTime) = 0;
65 		};
66 	} // end of namespace animation
67 } // end of namespace sdr
68 
69 //////////////////////////////////////////////////////////////////////////////
70 // eventlist class
71 
72 namespace sdr
73 {
74 	namespace animation
75 	{
76 		class EventList
77 		{
78 			// pointer to first entry
79 			Event*											mpHead;
80 
81 		public:
82 			// constructor/destructor
83 			EventList();
84 			SVX_DLLPUBLIC virtual ~EventList();
85 
86 			// insert/remove time dependent
87 			void Insert(Event* pNew);
88 			void Remove(Event* pOld);
89 
90 			// clear list
91 			void Clear();
92 
93 			// get first
94 			Event* GetFirst();
95 		};
96 	} // end of namespace animation
97 } // end of namespace sdr
98 
99 //////////////////////////////////////////////////////////////////////////////
100 // scheduler class
101 
102 namespace sdr
103 {
104 	namespace animation
105 	{
106 		class Scheduler : public Timer
107 		{
108 			// time in ms
109 			sal_uInt32										mnTime;
110 
111 			// next delta time
112 			sal_uInt32										mnDeltaTime;
113 
114 			// list of events
115 			EventList										maList;
116 
117 			// Flag which remembers if this timer is paused. Default
118 			// is false.
119 			bool    										mbIsPaused;
120 
121 		public:
122 			// constructor/destructor
123 			Scheduler();
124 			SVX_DLLPUBLIC virtual ~Scheduler();
125 
126 			// From baseclass Timer, the timeout call
127 			SVX_DLLPUBLIC virtual void Timeout();
128 
129 			// get time
130 			sal_uInt32 GetTime();
131 
132 			// #i38135#
133 			void SetTime(sal_uInt32 nTime);
134 
135 			// reset
136 			void Reset(sal_uInt32 nTime);
137 
138 			// execute all ripe events, removes executed ones from the scheduler
139 			void triggerEvents();
140 
141 			// re-start or stop timer according to event list
142 			void checkTimeout();
143 
144 			// insert/remove events, wrapper to EventList methods
145 			void InsertEvent(Event* pNew);
146 			void RemoveEvent(Event* pOld);
147 
148 			// get/set pause
149 			bool IsPaused() const { return mbIsPaused; }
150 			void SetPaused(bool bNew);
151 		};
152 	} // end of namespace animation
153 } // end of namespace sdr
154 
155 //////////////////////////////////////////////////////////////////////////////
156 
157 #endif //_SDR_ANIMATION_SCHEDULER_HXX
158 
159 // eof
160