mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-01 05:25:55 +00:00
a0911c75d0
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@812 a592a061-630c-0410-9148-cb99ea01b6c8
88 lines
1.1 KiB
C
88 lines
1.1 KiB
C
#include <config.h>
|
|
|
|
#include FORMS_H_LOCATION
|
|
|
|
#include "Timeout.h"
|
|
#include "debug.h"
|
|
|
|
using std::endl;
|
|
|
|
extern "C" {
|
|
static
|
|
void C_intern_timeout_cb(int, void * data)
|
|
{
|
|
Timeout * to = static_cast<Timeout*>(data);
|
|
to->callback();
|
|
}
|
|
}
|
|
|
|
|
|
Timeout::Timeout()
|
|
: type(ONETIME), timeout(0), timeout_id(-1),
|
|
callback_(0), data_(0) {}
|
|
|
|
|
|
Timeout::Timeout(int msec, Type t)
|
|
: type(t), timeout(msec), timeout_id(-1),
|
|
callback_(0), data_(0) {}
|
|
|
|
|
|
Timeout::~Timeout()
|
|
{
|
|
stop();
|
|
}
|
|
|
|
|
|
void Timeout::restart()
|
|
{
|
|
stop();
|
|
start();
|
|
}
|
|
|
|
|
|
void Timeout::start()
|
|
{
|
|
if (timeout_id != -1)
|
|
lyxerr << "Timeout::start: already running!" << endl;
|
|
timeout_id = fl_add_timeout(timeout,
|
|
C_intern_timeout_cb, this);
|
|
}
|
|
|
|
|
|
void Timeout::stop()
|
|
{
|
|
if (timeout_id != -1) {
|
|
fl_remove_timeout(timeout_id);
|
|
timeout_id = -1;
|
|
}
|
|
}
|
|
|
|
|
|
void Timeout::callback(TimeoutCallback cb, void * data)
|
|
{
|
|
callback_ = cb;
|
|
data_ = data;
|
|
}
|
|
|
|
|
|
void Timeout::callback()
|
|
{
|
|
timeout_id = -1;
|
|
if (callback_)
|
|
callback_(data_);
|
|
if (type == CONTINOUS)
|
|
start();
|
|
}
|
|
|
|
|
|
void Timeout::setType(Type t)
|
|
{
|
|
type = t;
|
|
}
|
|
|
|
|
|
void Timeout::setTimeout(int msec)
|
|
{
|
|
timeout = msec;
|
|
}
|