sw a11y: clang-format SidebarWinAccessible code
[LibreOffice.git] / slideshow / source / inc / delayevent.hxx
blobfa2ebe253682f1a4dc70142246dd0b0be3de1284
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SLIDESHOW_SOURCE_INC_DELAYEVENT_HXX
20 #define INCLUDED_SLIDESHOW_SOURCE_INC_DELAYEVENT_HXX
22 #include "event.hxx"
24 #include <functional>
25 #include <utility>
27 namespace slideshow::internal {
29 /** Event, which delays the functor call the given amount of time
31 class Delay : public Event
33 public:
34 typedef ::std::function<void ()> FunctorT;
36 template <typename FuncT>
37 Delay( FuncT const& func,
38 double nTimeout
39 , const OUString& rsDescription
40 ) : Event(rsDescription),
41 mnTimeout(nTimeout), maFunc(func), mbWasFired(false) {}
43 Delay( std::function<void ()> func,
44 double nTimeout
45 , const OUString& rsDescription
46 ) : Event(rsDescription),
47 mnTimeout(nTimeout),
48 maFunc(std::move(func)),
49 mbWasFired(false) {}
50 Delay(const Delay&) = delete;
51 Delay& operator=(const Delay&) = delete;
53 // Event:
54 virtual bool fire() override;
55 virtual bool isCharged() const override;
56 virtual double getActivationTime( double nCurrentTime ) const override;
57 // Disposable:
58 virtual void dispose() override;
60 private:
61 double const mnTimeout;
62 FunctorT maFunc;
63 bool mbWasFired;
66 #if OSL_DEBUG_LEVEL <= 1
68 /** Generate delay event
70 @param func
71 Functor to call when the event fires.
73 @param nTimeout
74 Timeout in seconds, to wait until functor is called.
76 @return generated delay event
78 template <typename FuncT>
79 inline EventSharedPtr makeDelay_( FuncT const& func, double nTimeout, OUString const& rsDescription )
81 return std::make_shared<Delay>( func, nTimeout, rsDescription );
84 /** Generate immediate event
86 @param func
87 Functor to call when the event fires.
89 @return generated immediate event.
91 template <typename FuncT>
92 inline EventSharedPtr makeEvent_( FuncT const& func, OUString const& rsDescription)
94 return std::make_shared<Delay>( func, 0.0, rsDescription );
98 #define makeDelay(f, t, d) makeDelay_(f, t, d)
99 #define makeEvent(f, d) makeEvent_(f, d)
101 #else // OSL_DEBUG_LEVEL > 0
103 class Delay_ : public Delay {
104 public:
105 template <typename FuncT>
106 Delay_( FuncT const& func, double nTimeout,
107 char const* from_function, char const* from_file, int from_line,
108 const OUString& rsDescription)
109 : Delay(func, nTimeout, rsDescription),
110 FROM_FUNCTION(from_function),
111 FROM_FILE(from_file), FROM_LINE(from_line) {}
113 char const* const FROM_FUNCTION;
114 char const* const FROM_FILE;
115 int const FROM_LINE;
118 template <typename FuncT>
119 inline EventSharedPtr makeDelay_(
120 FuncT const& func, double nTimeout,
121 char const* from_function, char const* from_file, int from_line,
122 const OUString& rsDescription)
124 return EventSharedPtr( new Delay_( func, nTimeout,
125 from_function, from_file, from_line, rsDescription) );
128 #define makeDelay(f, t, d) makeDelay_(f, t, \
129 __func__, __FILE__, __LINE__, \
131 #define makeEvent(f, d) makeDelay_(f, 0.0, \
132 __func__, __FILE__, __LINE__, \
135 #endif // OSL_DEBUG_LEVEL <= 1
137 } // namespace presentation::internal
139 #endif // INCLUDED_SLIDESHOW_SOURCE_INC_DELAYEVENT_HXX
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */