2000-07-24 13:53:19 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-2000 The LyX Team.
|
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
#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);
|
2000-06-21 12:41:18 +00:00
|
|
|
to->emit();
|
2000-06-08 23:16:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Timeout::Timeout()
|
2000-06-21 12:41:18 +00:00
|
|
|
: type(ONETIME), timeout_ms(0), timeout_id(-1)
|
|
|
|
{}
|
2000-06-08 23:16:16 +00:00
|
|
|
|
|
|
|
|
2000-06-13 10:33:57 +00:00
|
|
|
Timeout::Timeout(int msec, Type t)
|
2000-06-21 12:41:18 +00:00
|
|
|
: type(t), timeout_ms(msec), timeout_id(-1)
|
|
|
|
{}
|
2000-06-08 23:16:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
Timeout::~Timeout()
|
|
|
|
{
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Timeout::restart()
|
|
|
|
{
|
|
|
|
stop();
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Timeout::start()
|
|
|
|
{
|
|
|
|
if (timeout_id != -1)
|
|
|
|
lyxerr << "Timeout::start: already running!" << endl;
|
2000-06-21 12:41:18 +00:00
|
|
|
timeout_id = fl_add_timeout(timeout_ms,
|
2000-06-08 23:16:16 +00:00
|
|
|
C_intern_timeout_cb, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Timeout::stop()
|
|
|
|
{
|
|
|
|
if (timeout_id != -1) {
|
|
|
|
fl_remove_timeout(timeout_id);
|
|
|
|
timeout_id = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-21 12:41:18 +00:00
|
|
|
void Timeout::emit()
|
2000-06-08 23:16:16 +00:00
|
|
|
{
|
|
|
|
timeout_id = -1;
|
2000-06-21 12:41:18 +00:00
|
|
|
timeout.emit();
|
2000-06-08 23:16:16 +00:00
|
|
|
if (type == CONTINOUS)
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Timeout::setType(Type t)
|
|
|
|
{
|
|
|
|
type = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Timeout::setTimeout(int msec)
|
|
|
|
{
|
2000-06-21 12:41:18 +00:00
|
|
|
timeout_ms = msec;
|
2000-06-08 23:16:16 +00:00
|
|
|
}
|