fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / sdr / animation / scheduler.cxx
blob9e306dd06e62c3584b7694a9324bd3350ec1eb5a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/sdr/animation/scheduler.hxx>
22 #include <vector>
24 //////////////////////////////////////////////////////////////////////////////
25 // event class
27 namespace sdr
29 namespace animation
31 Event::Event(sal_uInt32 nTime)
32 : mnTime(nTime),
33 mpNext(0L)
37 Event::~Event()
41 Event* Event::GetNext() const
43 return mpNext;
46 void Event::SetNext(Event* pNew)
48 if(pNew != mpNext)
50 mpNext = pNew;
54 sal_uInt32 Event::GetTime() const
56 return mnTime;
59 void Event::SetTime(sal_uInt32 nNew)
61 if(mnTime != nNew)
63 mnTime = nNew;
66 } // end of namespace animation
67 } // end of namespace sdr
69 //////////////////////////////////////////////////////////////////////////////
70 // eventlist class
72 namespace sdr
74 namespace animation
76 EventList::EventList()
77 : mpHead(0L)
81 EventList::~EventList()
83 Clear();
86 void EventList::Insert(Event* pNew)
88 if(pNew)
90 Event* pCurrent = mpHead;
91 Event* pPrev = 0L;
93 while(pCurrent && pCurrent->GetTime() < pNew->GetTime())
95 pPrev = pCurrent;
96 pCurrent = pCurrent->GetNext();
99 if(pPrev)
101 pNew->SetNext(pPrev->GetNext());
102 pPrev->SetNext(pNew);
104 else
106 pNew->SetNext(mpHead);
107 mpHead = pNew;
112 void EventList::Remove(Event* pOld)
114 if(pOld && mpHead)
116 Event* pCurrent = mpHead;
117 Event* pPrev = 0L;
119 while(pCurrent && pCurrent != pOld)
121 pPrev = pCurrent;
122 pCurrent = pCurrent->GetNext();
125 if(pPrev)
127 pPrev->SetNext(pOld->GetNext());
129 else
131 mpHead = pOld->GetNext();
134 pOld->SetNext(0L);
138 void EventList::Clear()
140 while(mpHead)
142 Event* pNext = mpHead->GetNext();
143 mpHead->SetNext(0L);
144 mpHead = pNext;
148 Event* EventList::GetFirst()
150 return mpHead;
152 } // end of namespace animation
153 } // end of namespace sdr
155 //////////////////////////////////////////////////////////////////////////////
156 // scheduler class
158 namespace sdr
160 namespace animation
162 Scheduler::Scheduler()
163 : mnTime(0L),
164 mnDeltaTime(0L),
165 mbIsPaused(false)
169 Scheduler::~Scheduler()
171 Stop();
174 void Scheduler::Timeout()
176 // stop timer and add time
177 Stop();
178 mnTime += mnDeltaTime;
180 // execute events
181 triggerEvents();
183 // re-start or stop timer according to event list
184 checkTimeout();
187 void Scheduler::triggerEvents()
189 Event* pNextEvent = maList.GetFirst();
191 if(pNextEvent)
193 // copy events which need to be executed to a vector. Remove them from
194 // the scheduler
195 ::std::vector< Event* > EventPointerVector;
197 while(pNextEvent && pNextEvent->GetTime() <= mnTime)
199 maList.Remove(pNextEvent);
200 EventPointerVector.push_back(pNextEvent);
201 pNextEvent = maList.GetFirst();
204 // execute events from the vector
205 for(::std::vector< Event* >::iterator aCandidate = EventPointerVector.begin();
206 aCandidate != EventPointerVector.end(); ++aCandidate)
208 // trigger event. This may re-insert the event to the scheduler again
209 (*aCandidate)->Trigger(mnTime);
214 void Scheduler::checkTimeout()
216 // re-start or stop timer according to event list
217 if(!IsPaused() && maList.GetFirst())
219 mnDeltaTime = maList.GetFirst()->GetTime() - mnTime;
221 if(0L != mnDeltaTime)
223 SetTimeout(mnDeltaTime);
224 Start();
227 else
229 Stop();
233 sal_uInt32 Scheduler::GetTime()
235 return mnTime;
238 // #i38135#
239 void Scheduler::SetTime(sal_uInt32 nTime)
241 // reset time
242 Stop();
243 mnTime = nTime;
245 // get event pointer
246 Event* pEvent = maList.GetFirst();
248 if(pEvent)
250 // retet event time points
251 while(pEvent)
253 pEvent->SetTime(nTime);
254 pEvent = pEvent->GetNext();
257 if(!IsPaused())
259 // without delta time, init events by triggering them. This will invalidate
260 // painted objects and add them to the scheduler again
261 mnDeltaTime = 0L;
262 triggerEvents();
263 checkTimeout();
268 void Scheduler::InsertEvent(Event* pNew)
270 if(pNew)
272 maList.Insert(pNew);
273 checkTimeout();
277 void Scheduler::RemoveEvent(Event* pOld)
279 if(pOld && maList.GetFirst())
281 maList.Remove(pOld);
282 checkTimeout();
286 void Scheduler::SetPaused(bool bNew)
288 if(bNew != mbIsPaused)
290 mbIsPaused = bNew;
291 checkTimeout();
294 } // end of namespace animation
295 } // end of namespace sdr
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */