lyx_mirror/src/Timeout.C
Jean-Marc Lasgouttes 4b2a999762 GUI-indep toolbar and menus mostly work !
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@913 a592a061-630c-0410-9148-cb99ea01b6c8
2000-07-24 13:53:19 +00:00

94 lines
1.3 KiB
C

/* This file is part of
* ======================================================
*
* LyX, The Document Processor
*
* Copyright 1995 Matthias Ettrich
* Copyright 1995-2000 The LyX Team.
*
* ====================================================== */
#ifdef __GNUG__
#pragma implementation
#endif
#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->emit();
}
}
Timeout::Timeout()
: type(ONETIME), timeout_ms(0), timeout_id(-1)
{}
Timeout::Timeout(int msec, Type t)
: type(t), timeout_ms(msec), timeout_id(-1)
{}
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_ms,
C_intern_timeout_cb, this);
}
void Timeout::stop()
{
if (timeout_id != -1) {
fl_remove_timeout(timeout_id);
timeout_id = -1;
}
}
void Timeout::emit()
{
timeout_id = -1;
timeout.emit();
if (type == CONTINOUS)
start();
}
void Timeout::setType(Type t)
{
type = t;
}
void Timeout::setTimeout(int msec)
{
timeout_ms = msec;
}