2004-11-26 18:16:22 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-07 20:11:43 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2004-11-26 18:16:22 +00:00
|
|
|
*
|
2005-09-07 20:11:43 +00:00
|
|
|
* $RCSfile: eventqueue.hxx,v $
|
2004-11-26 18:16:22 +00:00
|
|
|
*
|
2006-07-26 06:39:44 +00:00
|
|
|
* $Revision: 1.7 $
|
2004-11-26 18:16:22 +00:00
|
|
|
*
|
2006-07-26 06:39:44 +00:00
|
|
|
* last change: $Author: rt $ $Date: 2006-07-26 07:39:44 $
|
2004-11-26 18:16:22 +00:00
|
|
|
*
|
2005-09-07 20:11:43 +00:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2004-11-26 18:16:22 +00:00
|
|
|
*
|
|
|
|
*
|
2005-09-07 20:11:43 +00:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2004-11-26 18:16:22 +00:00
|
|
|
*
|
2005-09-07 20:11:43 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2004-11-26 18:16:22 +00:00
|
|
|
*
|
2005-09-07 20:11:43 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2004-11-26 18:16:22 +00:00
|
|
|
*
|
2005-09-07 20:11:43 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2004-11-26 18:16:22 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _SLIDESHOW_EVENTQUEUE_HXX
|
|
|
|
#define _SLIDESHOW_EVENTQUEUE_HXX
|
|
|
|
|
|
|
|
#ifndef _CANVAS_ELAPSEDTIME_HXX
|
|
|
|
#include <canvas/elapsedtime.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <queue>
|
2006-07-26 06:39:44 +00:00
|
|
|
#include <vector>
|
2004-11-26 18:16:22 +00:00
|
|
|
#include <event.hxx>
|
|
|
|
|
2005-03-30 07:15:11 +00:00
|
|
|
#include <boost/utility.hpp> // for boost::noncopyable
|
|
|
|
#include <functional>
|
2004-11-26 18:16:22 +00:00
|
|
|
|
|
|
|
/* Definition of ActivitiesQueue class */
|
|
|
|
|
|
|
|
namespace presentation
|
|
|
|
{
|
|
|
|
namespace internal
|
|
|
|
{
|
|
|
|
/** This class handles events in a presentation. Events are
|
|
|
|
time instants where e.g. effects start.
|
|
|
|
*/
|
2005-03-10 12:54:47 +00:00
|
|
|
class EventQueue : private ::boost::noncopyable
|
2004-11-26 18:16:22 +00:00
|
|
|
{
|
|
|
|
public:
|
2005-03-10 12:54:47 +00:00
|
|
|
EventQueue(
|
|
|
|
::boost::shared_ptr< ::canvas::tools::ElapsedTime >
|
|
|
|
const & pPresTimer );
|
2004-11-26 18:16:22 +00:00
|
|
|
|
|
|
|
~EventQueue();
|
|
|
|
|
|
|
|
/** Add the given event to the queue. The event is fired
|
|
|
|
at, or shortly after, its Event::getActivationTime instant.
|
|
|
|
*/
|
|
|
|
bool addEvent( const EventSharedPtr& event );
|
|
|
|
|
2006-07-26 06:39:44 +00:00
|
|
|
/** Add the given event to the queue. The event is fired
|
|
|
|
at, or shortly after, its Event::getActivationTime instant.
|
|
|
|
The difference to addEvent() is that events added during
|
|
|
|
process() are postponed to next process().
|
|
|
|
*/
|
|
|
|
bool addEventForNextRound( const EventSharedPtr& event );
|
|
|
|
|
2004-11-26 18:16:22 +00:00
|
|
|
/** Process the event queue.
|
|
|
|
|
2006-02-09 13:49:14 +00:00
|
|
|
This method executes all events whose timeout has
|
|
|
|
expired when calling this method (i.e. all events
|
|
|
|
whose scheduled time is less or equal the current
|
|
|
|
time).
|
2004-11-26 18:16:22 +00:00
|
|
|
|
2006-02-09 13:49:14 +00:00
|
|
|
Check for the next available event's timeout via
|
|
|
|
nextTimeout(), or whether the queue is empty
|
|
|
|
altogether via isEmpty().
|
2004-11-26 18:16:22 +00:00
|
|
|
*/
|
2006-02-09 13:49:14 +00:00
|
|
|
void process();
|
2004-11-26 18:16:22 +00:00
|
|
|
|
|
|
|
/** Query state of the queue
|
|
|
|
|
|
|
|
@return false, if queue is empty, true otherwise
|
|
|
|
*/
|
2006-02-09 13:49:14 +00:00
|
|
|
bool isEmpty() const;
|
|
|
|
|
|
|
|
/** Query timeout for the topmost event in the queue.
|
|
|
|
|
|
|
|
@return Timeout in seconds, until the next event is
|
|
|
|
ready. The time returned here is relative to the pres
|
|
|
|
timer (i.e. the timer specified at the EventQueue
|
|
|
|
constructor). When the queue is empty (i.e. isEmpty()
|
|
|
|
returns true), the returned value is the highest
|
|
|
|
representable double value
|
|
|
|
(::std::numeric_limits<double>::max()). If the topmost
|
|
|
|
event in the queue is already pending, the timeout
|
|
|
|
returned here will actually be negative.
|
|
|
|
*/
|
|
|
|
double nextTimeout() const;
|
2004-11-26 18:16:22 +00:00
|
|
|
|
|
|
|
/** Remove all pending events from the queue.
|
|
|
|
*/
|
|
|
|
void clear();
|
|
|
|
|
2006-07-26 06:39:44 +00:00
|
|
|
/** Forces an empty queue, firing all events immediately
|
|
|
|
without minding any times.
|
|
|
|
@attention do only call from event loop, this calls process_()!
|
|
|
|
*/
|
|
|
|
void forceEmpty();
|
|
|
|
|
2005-03-10 12:54:47 +00:00
|
|
|
/** Gets the queue's timer object.
|
|
|
|
*/
|
|
|
|
::boost::shared_ptr< ::canvas::tools::ElapsedTime > const &
|
|
|
|
getTimer() const { return mpTimer; }
|
2004-11-26 18:16:22 +00:00
|
|
|
|
2005-03-10 12:54:47 +00:00
|
|
|
private:
|
2005-03-30 07:15:11 +00:00
|
|
|
struct EventEntry : public ::std::unary_function<EventEntry, bool>
|
2004-11-26 18:16:22 +00:00
|
|
|
{
|
|
|
|
EventSharedPtr pEvent;
|
|
|
|
double nTime;
|
|
|
|
|
|
|
|
bool operator<( const EventEntry& ) const; // to leverage priority_queue's default compare
|
2006-07-26 06:39:44 +00:00
|
|
|
|
|
|
|
EventEntry( EventSharedPtr const& p, double t )
|
|
|
|
: pEvent(p), nTime(t) {}
|
2004-11-26 18:16:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef ::std::priority_queue< EventEntry > ImplQueueType;
|
|
|
|
ImplQueueType maEvents;
|
2006-07-26 06:39:44 +00:00
|
|
|
typedef ::std::vector<EventEntry> EventEntryVector;
|
|
|
|
EventEntryVector maNextEvents;
|
|
|
|
void process_( bool bFireAllEvents );
|
2005-03-10 12:54:47 +00:00
|
|
|
|
2004-11-26 18:16:22 +00:00
|
|
|
// perform timing of events via relative time
|
|
|
|
// measurements. The world time starts, when the
|
|
|
|
// EventQueue object is created
|
2005-03-10 12:54:47 +00:00
|
|
|
::boost::shared_ptr< ::canvas::tools::ElapsedTime > mpTimer;
|
2004-11-26 18:16:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* _SLIDESHOW_EVENTQUEUE_HXX */
|