]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/xformsTimeout.C
Introduce LFUN_PRINT.
[lyx.git] / src / frontends / xforms / xformsTimeout.C
1 /**
2  * \file xformsTimeout.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author John Levon
8  * \author Angus Leeming
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "xformsTimeout.h"
16 #include "debug.h"
17
18 #include "lyx_forms.h"
19
20
21 Timeout::Timeout(unsigned int msec, Type t)
22         : pimpl_(new xformsTimeout(*this)), type(t), timeout_ms(msec)
23 {}
24
25
26 namespace {
27
28 extern "C"
29 void C_TimeoutCB(int, void * data)
30 {
31         xformsTimeout * to = static_cast<xformsTimeout *>(data);
32         to->emitCB();
33 }
34
35 } // namespace anon
36
37
38 xformsTimeout::xformsTimeout(Timeout & owner)
39         : Timeout::Impl(owner), timeout_id(-1)
40 {}
41
42
43 void xformsTimeout::emitCB()
44 {
45         emit();
46 }
47
48
49 bool xformsTimeout::running() const
50 {
51         return timeout_id != -1;
52 }
53
54
55 void xformsTimeout::start()
56 {
57         if (running()) {
58                 lyxerr << "Timeout::start: already running!" << std::endl;
59
60         } else {
61                 timeout_id = fl_add_timeout(timeout_ms(),
62                                             C_TimeoutCB, this);
63         }
64 }
65
66
67 void xformsTimeout::stop()
68 {
69         if (running()) {
70                 fl_remove_timeout(timeout_id);
71                 timeout_id = -1;
72         }
73 }
74
75
76 void xformsTimeout::reset()
77 {
78         timeout_id = -1;
79 }