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: delayevent.hxx,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 ************************************************************************/
30 #ifndef INCLUDED_SLIDESHOW_DELAYEVENT_HXX
31 #define INCLUDED_SLIDESHOW_DELAYEVENT_HXX
34 #include <boost/noncopyable.hpp>
35 #include <boost/function.hpp>
36 #if defined(VERBOSE) && defined(DBG_UTIL)
37 #include "boost/current_function.hpp"
43 /** Event, which delays the functor call the given amount of time
45 class Delay
: public Event
, private ::boost::noncopyable
48 typedef ::boost::function0
<void> FunctorT
;
50 template <typename FuncT
>
51 Delay( FuncT
const& func
, double nTimeout
)
52 : mnTimeout(nTimeout
), maFunc(func
), mbWasFired(false) {}
54 #if defined(VERBOSE) && defined(DBG_UTIL)
55 Delay( const boost::function0
<void>& func
,
59 Delay( const boost::function0
<void>& func
,
68 virtual bool isCharged() const;
69 virtual double getActivationTime( double nCurrentTime
) const;
71 virtual void dispose();
74 double const mnTimeout
;
79 #if OSL_DEBUG_LEVEL < 1
81 /** Generate delay event
84 Functor to call when the event fires.
87 Timeout in seconds, to wait until functor is called.
89 @return generated delay event
91 template <typename FuncT
>
92 inline EventSharedPtr
makeDelay( FuncT
const& func
, double nTimeout
)
94 return EventSharedPtr( new Delay( func
, nTimeout
) );
97 /** Generate immediate event
100 Functor to call when the event fires.
102 @return generated immediate event.
104 template <typename FuncT
>
105 inline EventSharedPtr
makeEvent( FuncT
const& func
)
107 return EventSharedPtr( new Delay( func
, 0.0 ) );
110 #else // OSL_DEBUG_LEVEL > 1
112 class Delay_
: public Delay
{
114 template <typename FuncT
>
115 Delay_( FuncT
const& func
, double nTimeout
,
116 char const* from_function
, char const* from_file
, int from_line
)
117 : Delay(func
, nTimeout
),
118 FROM_FUNCTION(from_function
),
119 FROM_FILE(from_file
), FROM_LINE(from_line
) {}
121 char const* const FROM_FUNCTION
;
122 char const* const FROM_FILE
;
126 template <typename FuncT
>
127 inline EventSharedPtr
makeDelay_(
128 FuncT
const& func
, double nTimeout
,
129 char const* from_function
, char const* from_file
, int from_line
)
131 return EventSharedPtr( new Delay_( func
, nTimeout
,
132 from_function
, from_file
, from_line
) );
135 #define makeDelay(f, t) makeDelay_(f, t, \
136 BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)
137 #define makeEvent(f) makeDelay_(f, 0.0, \
138 BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)
140 #endif // OSL_DEBUG_LEVEL < 1
142 } // namespace internal
143 } // namespace presentation
145 #endif /* INCLUDED_SLIDESHOW_DELAYEVENT_HXX */