1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: scheduler.cxx,v $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <svx/sdr/animation/scheduler.hxx>
37 //////////////////////////////////////////////////////////////////////////////
44 Event::Event(sal_uInt32 nTime
)
54 Event
* Event::GetNext() const
59 void Event::SetNext(Event
* pNew
)
67 sal_uInt32
Event::GetTime() const
72 void Event::SetTime(sal_uInt32 nNew
)
79 } // end of namespace animation
80 } // end of namespace sdr
82 //////////////////////////////////////////////////////////////////////////////
89 EventList::EventList()
94 EventList::~EventList()
99 void EventList::Insert(Event
* pNew
)
103 Event
* pCurrent
= mpHead
;
106 while(pCurrent
&& pCurrent
->GetTime() < pNew
->GetTime())
109 pCurrent
= pCurrent
->GetNext();
114 pNew
->SetNext(pPrev
->GetNext());
115 pPrev
->SetNext(pNew
);
119 pNew
->SetNext(mpHead
);
125 void EventList::Remove(Event
* pOld
)
129 Event
* pCurrent
= mpHead
;
132 while(pCurrent
&& pCurrent
!= pOld
)
135 pCurrent
= pCurrent
->GetNext();
140 pPrev
->SetNext(pOld
->GetNext());
144 mpHead
= pOld
->GetNext();
151 void EventList::Clear()
155 Event
* pNext
= mpHead
->GetNext();
161 Event
* EventList::GetFirst()
165 } // end of namespace animation
166 } // end of namespace sdr
168 //////////////////////////////////////////////////////////////////////////////
175 Scheduler::Scheduler()
182 Scheduler::~Scheduler()
187 void Scheduler::Timeout()
189 // stop timer and add time
191 mnTime
+= mnDeltaTime
;
196 // re-start or stop timer according to event list
200 void Scheduler::triggerEvents()
202 Event
* pNextEvent
= maList
.GetFirst();
206 // copy events which need to be executed to a vector. Remove them from
208 ::std::vector
< Event
* > EventPointerVector
;
210 while(pNextEvent
&& pNextEvent
->GetTime() <= mnTime
)
212 maList
.Remove(pNextEvent
);
213 EventPointerVector
.push_back(pNextEvent
);
214 pNextEvent
= maList
.GetFirst();
217 // execute events from the vector
218 for(::std::vector
< Event
* >::iterator aCandidate
= EventPointerVector
.begin();
219 aCandidate
!= EventPointerVector
.end(); aCandidate
++)
221 // trigger event. This may re-insert the event to the scheduler again
222 (*aCandidate
)->Trigger(mnTime
);
227 void Scheduler::checkTimeout()
229 // re-start or stop timer according to event list
230 if(!IsPaused() && maList
.GetFirst())
232 mnDeltaTime
= maList
.GetFirst()->GetTime() - mnTime
;
234 if(0L != mnDeltaTime
)
236 SetTimeout(mnDeltaTime
);
246 sal_uInt32
Scheduler::GetTime()
252 void Scheduler::SetTime(sal_uInt32 nTime
)
259 Event
* pEvent
= maList
.GetFirst();
263 // retet event time points
266 pEvent
->SetTime(nTime
);
267 pEvent
= pEvent
->GetNext();
272 // without delta time, init events by triggering them. This will invalidate
273 // painted objects and add them to the scheduler again
281 void Scheduler::Reset(sal_uInt32 nTime
)
288 void Scheduler::InsertEvent(Event
* pNew
)
297 void Scheduler::RemoveEvent(Event
* pOld
)
299 if(pOld
&& maList
.GetFirst())
306 void Scheduler::SetPaused(bool bNew
)
308 if(bNew
!= mbIsPaused
)
314 } // end of namespace animation
315 } // end of namespace sdr
317 //////////////////////////////////////////////////////////////////////////////