merge the formfield patch from ooo-build
[ooovba.git] / slideshow / source / inc / delayevent.hxx
blob9c3081dc7036010a9a41fd04f2618cd6e3d07ecd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: delayevent.hxx,v $
10 * $Revision: 1.10 $
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
33 #include <boost/function.hpp>
35 #include "event.hxx"
36 #include <boost/noncopyable.hpp>
38 namespace slideshow {
39 namespace internal {
41 /** Event, which delays the functor call the given amount of time
43 class Delay : public Event, private ::boost::noncopyable
45 public:
46 typedef ::boost::function0<void> FunctorT;
48 template <typename FuncT>
49 Delay( FuncT const& func, double nTimeout )
50 : mnTimeout(nTimeout), maFunc(func), mbWasFired(false) {}
52 #if defined(VERBOSE) && defined(DBG_UTIL)
53 Delay( const boost::function0<void>& func,
54 double nTimeout,
55 char const* const ) :
56 #else
57 Delay( const boost::function0<void>& func,
58 double nTimeout ) :
59 #endif
60 mnTimeout(nTimeout),
61 maFunc(func),
62 mbWasFired(false) {}
64 // Event:
65 virtual bool fire();
66 virtual bool isCharged() const;
67 virtual double getActivationTime( double nCurrentTime ) const;
68 // Disposable:
69 virtual void dispose();
71 private:
72 double const mnTimeout;
73 FunctorT maFunc;
74 bool mbWasFired;
77 #if OSL_DEBUG_LEVEL < 1
79 /** Generate delay event
81 @param func
82 Functor to call when the event fires.
84 @param nTimeout
85 Timeout in seconds, to wait until functor is called.
87 @return generated delay event
89 template <typename FuncT>
90 inline EventSharedPtr makeDelay( FuncT const& func, double nTimeout )
92 return EventSharedPtr( new Delay( func, nTimeout ) );
95 /** Generate immediate event
97 @param func
98 Functor to call when the event fires.
100 @return generated immediate event.
102 template <typename FuncT>
103 inline EventSharedPtr makeEvent( FuncT const& func )
105 return EventSharedPtr( new Delay( func, 0.0 ) );
108 #else // OSL_DEBUG_LEVEL > 1
110 class Delay_ : public Delay {
111 public:
112 template <typename FuncT>
113 Delay_( FuncT const& func, double nTimeout,
114 char const* from_function, char const* from_file, int from_line )
115 : Delay(func, nTimeout),
116 FROM_FUNCTION(from_function),
117 FROM_FILE(from_file), FROM_LINE(from_line) {}
119 char const* const FROM_FUNCTION;
120 char const* const FROM_FILE;
121 int const FROM_LINE;
124 template <typename FuncT>
125 inline EventSharedPtr makeDelay_(
126 FuncT const& func, double nTimeout,
127 char const* from_function, char const* from_file, int from_line )
129 return EventSharedPtr( new Delay_( func, nTimeout,
130 from_function, from_file, from_line ) );
133 #define makeDelay(f, t) makeDelay_(f, t, \
134 BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)
135 #define makeEvent(f) makeDelay_(f, 0.0, \
136 BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)
138 #endif // OSL_DEBUG_LEVEL < 1
140 } // namespace internal
141 } // namespace presentation
143 #endif /* INCLUDED_SLIDESHOW_DELAYEVENT_HXX */