Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : : #ifndef INCLUDED_SLIDESHOW_DELAYEVENT_HXX
20 : : #define INCLUDED_SLIDESHOW_DELAYEVENT_HXX
21 : :
22 : : #include <boost/function.hpp>
23 : :
24 : : #include "event.hxx"
25 : : #include <boost/noncopyable.hpp>
26 : :
27 : : namespace slideshow {
28 : : namespace internal {
29 : :
30 : : /** Event, which delays the functor call the given amount of time
31 : : */
32 : 0 : class Delay : public Event, private ::boost::noncopyable
33 : : {
34 : : public:
35 : : typedef ::boost::function0<void> FunctorT;
36 : :
37 : : template <typename FuncT>
38 : 0 : Delay( FuncT const& func,
39 : : double nTimeout
40 : : #if OSL_DEBUG_LEVEL > 1
41 : : , const ::rtl::OUString& rsDescription
42 : : ) : Event(rsDescription),
43 : : #else
44 : : ) :
45 : : #endif
46 : 0 : mnTimeout(nTimeout), maFunc(func), mbWasFired(false) {}
47 : :
48 : 0 : Delay( const boost::function0<void>& func,
49 : : double nTimeout
50 : : #if OSL_DEBUG_LEVEL > 1
51 : : , const ::rtl::OUString& rsDescription
52 : : ) : Event(rsDescription),
53 : : #else
54 : : ) :
55 : : #endif
56 : : mnTimeout(nTimeout),
57 : : maFunc(func),
58 : 0 : mbWasFired(false) {}
59 : :
60 : : // Event:
61 : : virtual bool fire();
62 : : virtual bool isCharged() const;
63 : : virtual double getActivationTime( double nCurrentTime ) const;
64 : : // Disposable:
65 : : virtual void dispose();
66 : :
67 : : private:
68 : : double const mnTimeout;
69 : : FunctorT maFunc;
70 : : bool mbWasFired;
71 : : };
72 : :
73 : : #if OSL_DEBUG_LEVEL <= 1
74 : :
75 : : /** Generate delay event
76 : :
77 : : @param func
78 : : Functor to call when the event fires.
79 : :
80 : : @param nTimeout
81 : : Timeout in seconds, to wait until functor is called.
82 : :
83 : : @return generated delay event
84 : : */
85 : : template <typename FuncT>
86 : 0 : inline EventSharedPtr makeDelay_( FuncT const& func, double nTimeout )
87 : : {
88 : 0 : return EventSharedPtr( new Delay( func, nTimeout ) );
89 : : }
90 : :
91 : : /** Generate immediate event
92 : :
93 : : @param func
94 : : Functor to call when the event fires.
95 : :
96 : : @return generated immediate event.
97 : : */
98 : : template <typename FuncT>
99 : 0 : inline EventSharedPtr makeEvent_( FuncT const& func )
100 : : {
101 : 0 : return EventSharedPtr( new Delay( func, 0.0 ) );
102 : : }
103 : :
104 : :
105 : : // Strip away description.
106 : : #define makeDelay(f, t, d) makeDelay_(f, t)
107 : : #define makeEvent(f, d) makeEvent_(f)
108 : :
109 : : #else // OSL_DEBUG_LEVEL > 1
110 : :
111 : : class Delay_ : public Delay {
112 : : public:
113 : : template <typename FuncT>
114 : : Delay_( FuncT const& func, double nTimeout,
115 : : char const* from_function, char const* from_file, int from_line,
116 : : const ::rtl::OUString& rsDescription)
117 : : : Delay(func, nTimeout, rsDescription),
118 : : FROM_FUNCTION(from_function),
119 : : FROM_FILE(from_file), FROM_LINE(from_line) {}
120 : :
121 : : char const* const FROM_FUNCTION;
122 : : char const* const FROM_FILE;
123 : : int const FROM_LINE;
124 : : };
125 : :
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,
130 : : const ::rtl::OUString& rsDescription)
131 : : {
132 : : return EventSharedPtr( new Delay_( func, nTimeout,
133 : : from_function, from_file, from_line, rsDescription) );
134 : : }
135 : :
136 : : #define makeDelay(f, t, d) makeDelay_(f, t, \
137 : : BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, \
138 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(d)))
139 : : #define makeEvent(f, d) makeDelay_(f, 0.0, \
140 : : BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, \
141 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(d)))
142 : :
143 : : #endif // OSL_DEBUG_LEVEL <= 1
144 : :
145 : : } // namespace internal
146 : : } // namespace presentation
147 : :
148 : : #endif /* INCLUDED_SLIDESHOW_DELAYEVENT_HXX */
149 : :
150 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|