Make the GUI instantiation invisible to Timeout.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6230 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-02-22 18:01:16 +00:00
parent 7f006d50db
commit a4276f27f7
17 changed files with 272 additions and 209 deletions

View File

@ -1,3 +1,10 @@
2003-02-21 Angus Leeming <leeming@lyx.org>
* Timeout.[Ch]: define a Timeout::Impl abstract base class from
which the GUIs will derive their implementations. Means that
we no longer have to look into the GUIs to write the class.
Store the implementation in a boost::scoped_ptr, not a raw pointer.
2003-02-21 Angus Leeming <leeming@lyx.org> 2003-02-21 Angus Leeming <leeming@lyx.org>
* Dialogs.h: remove forward declarations of InsetBibKey, InsetBibtex. * Dialogs.h: remove forward declarations of InsetBibKey, InsetBibtex.

View File

@ -12,22 +12,12 @@
#include <config.h> #include <config.h>
#include "Timeout.h" #include "Timeout.h"
#include "debug.h" #include "support/LAssert.h"
#include "Timeout_pimpl.h"
Timeout::Timeout(unsigned int msec, Type t)
: type(t), timeout_ms(msec)
{
pimpl_ = new Pimpl(this);
}
Timeout::~Timeout() Timeout::~Timeout()
{ {
pimpl_->stop(); pimpl_->stop();
delete pimpl_;
} }
@ -42,17 +32,20 @@ void Timeout::start()
pimpl_->start(); pimpl_->start();
} }
void Timeout::stop() void Timeout::stop()
{ {
pimpl_->stop(); pimpl_->stop();
} }
void Timeout::restart() void Timeout::restart()
{ {
pimpl_->stop(); pimpl_->stop();
pimpl_->start(); pimpl_->start();
} }
void Timeout::emit() void Timeout::emit()
{ {
pimpl_->reset(); pimpl_->reset();
@ -61,6 +54,7 @@ void Timeout::emit()
pimpl_->start(); pimpl_->start();
} }
Timeout & Timeout::setType(Type t) Timeout & Timeout::setType(Type t)
{ {
type = t; type = t;
@ -70,6 +64,9 @@ Timeout & Timeout::setType(Type t)
Timeout & Timeout::setTimeout(unsigned int msec) Timeout & Timeout::setTimeout(unsigned int msec)
{ {
// Can't have a timeout of zero!
lyx::Assert(msec);
timeout_ms = msec; timeout_ms = msec;
return * this; return * this;
} }

View File

@ -13,9 +13,9 @@
#ifndef TIMEOUT_H #ifndef TIMEOUT_H
#define TIMEOUT_H #define TIMEOUT_H
#include <boost/signals/signal0.hpp> #include <boost/signals/signal0.hpp>
/** /**
* This class executes the callback when the timeout expires. * This class executes the callback when the timeout expires.
*/ */
@ -26,7 +26,7 @@ public:
ONETIME, //< one-shot timer ONETIME, //< one-shot timer
CONTINUOUS //< repeating CONTINUOUS //< repeating
}; };
/// /// Note that the c-tor is implemented in the GUI-specific frontends
Timeout(unsigned int msec, Type = ONETIME); Timeout(unsigned int msec, Type = ONETIME);
/// ///
~Timeout(); ~Timeout();
@ -47,13 +47,42 @@ public:
/// set the timeout value /// set the timeout value
Timeout & setTimeout(unsigned int msec); Timeout & setTimeout(unsigned int msec);
/** Base class for the GUI implementation.
It must be public so that C callback functions can access its
daughter classes.
*/
class Impl
{
public:
///
Impl(Timeout & owner) : owner_(owner) {}
///
virtual ~Impl() {}
/// Is the timer running?
virtual bool running() const = 0;
/// start the timer
virtual void start() = 0;
/// stop the timer
virtual void stop() = 0;
/// reset
virtual void reset() = 0;
protected:
///
void emit() { owner_.emit(); }
///
unsigned int timeout_ms() const { return owner_.timeout_ms; }
private:
///
Timeout & owner_;
};
private: private:
/// ///
struct Pimpl; friend class Impl;
/// ///
friend struct Pimpl; boost::scoped_ptr<Impl> const pimpl_;
/// implementation
Pimpl * pimpl_;
/// one-shot or repeating /// one-shot or repeating
Type type; Type type;
/// timeout value in milliseconds /// timeout value in milliseconds

View File

@ -1,3 +1,9 @@
2003-02-21 Angus Leeming <leeming@lyx.org>
* Timeout_pimpl.[Ch]: removed.
* gnomeTimeout.[Ch]: new files, replacing the above.
The gnomeTimeout class derives from Timeout::Impl.
2003-02-21 Angus Leeming <leeming@lyx.org> 2003-02-21 Angus Leeming <leeming@lyx.org>
* FileDialog.C (FileDialog): no need for LyXView *. * FileDialog.C (FileDialog): no need for LyXView *.

View File

@ -152,8 +152,8 @@ libgnome_la_SOURCES = \
gnomeBC.C \ gnomeBC.C \
gnomeBC.h \ gnomeBC.h \
lyx_gui.C \ lyx_gui.C \
Timeout_pimpl.C \ gnomeTimeout.C \
Timeout_pimpl.h \ gnomeTimeout.h \
pixbutton.h pixbutton.h
libgnome.la: xforms.lo $(libgnome_la_OBJECTS) $(libgnome_la_DEPENDENCIES) libgnome.la: xforms.lo $(libgnome_la_OBJECTS) $(libgnome_la_DEPENDENCIES)

View File

@ -1,5 +1,5 @@
/** /**
* \file gnome/Timeout_pimpl.C * \file gnomeTimeout.C
* This file is part of LyX, the document processor. * This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
@ -11,27 +11,34 @@
#include <config.h> #include <config.h>
#include <glibmm/main.h> #include <glibmm/main.h>
#include "Timeout_pimpl.h" #include "gnomeTimeout.h"
#include "debug.h" #include "debug.h"
Timeout::Pimpl::Pimpl(Timeout * owner)
: owner_(owner)
{
}
void Timeout::Pimpl::reset() Timeout::Timeout(unsigned int msec, Type t)
: pimpl_(new gnomeTimeout(*this)), type(t), timeout_ms(msec)
{}
gnomeTimeout::(gnomeTimeoutTimeout * owner)
: Timeout::Impl(owner), timeout_id(-1)
{}
void gnomeTimeout::reset()
{ {
stop(); stop();
} }
bool Timeout::Pimpl::running() const
bool gnomeTimeout::running() const
{ {
return running_; return running_;
} }
void Timeout::Pimpl::start()
void gnomeTimeout::start()
{ {
if (conn_.connected()) { if (conn_.connected()) {
lyxerr << "Timeout::start: already running!" << std::endl; lyxerr << "Timeout::start: already running!" << std::endl;
@ -40,21 +47,21 @@ void Timeout::Pimpl::start()
conn_ = Glib::signal_timeout().connect( conn_ = Glib::signal_timeout().connect(
SigC::slot(*this, &Timeout::Pimpl::timeoutEvent), SigC::slot(*this, &Timeout::Pimpl::timeoutEvent),
owner_->timeout_ms timeout_ms()
); );
running_ = true; running_ = true;
} }
void Timeout::Pimpl::stop() void gnomeTimeout::stop()
{ {
conn_.disconnect(); conn_.disconnect();
running_ = false; running_ = false;
} }
bool Timeout::Pimpl::timeoutEvent() bool gnomeTimeout::timeoutEvent()
{ {
owner_->emit(); emit();
return false; // discontinue emitting timeouts. return false; // discontinue emitting timeouts.
} }

View File

@ -1,6 +1,6 @@
// -*- C++ -*- // -*- C++ -*-
/** /**
* \file gnome/Timeout_pimpl.h * \file gnomeTimeout.h
* This file is part of LyX, the document processor. * This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
@ -8,8 +8,8 @@
* *
* Full author contact details are available in file CREDITS * Full author contact details are available in file CREDITS
*/ */
#ifndef TIMEOUTPIMPL_H #ifndef GNOMETIMEOUT_H
#define TIMEOUTPIMPL_H #define GNOMETIMEOUT_H
#include "frontends/Timeout.h" #include "frontends/Timeout.h"
#include "glib.h" // for gint #include "glib.h" // for gint
@ -21,10 +21,10 @@
* This class executes the callback when the timeout expires * This class executes the callback when the timeout expires
* using Gnome mechanisms * using Gnome mechanisms
*/ */
struct Timeout::Pimpl : public SigC::Object { struct gnomeTimeout : public SigC::Object, public Timeout::Impl {
public: public:
/// ///
Pimpl(Timeout * owner_); gnomeTimeout(Timeout * owner_);
/// start the timer /// start the timer
void start(); void start();
/// stop the timer /// stop the timer
@ -39,12 +39,10 @@ public:
/// The timeout signal, this gets called when the timeout passed. /// The timeout signal, this gets called when the timeout passed.
bool timeoutEvent(); bool timeoutEvent();
private: private:
/// the owning timer
Timeout * owner_;
/// Timer connection /// Timer connection
SigC::Connection conn_; SigC::Connection conn_;
/// Used for running as SigC::Connection::connected() isn't const /// Used for running as SigC::Connection::connected() isn't const
bool running_; bool running_;
}; };
#endif #endif // GNOMETIMEOUT

View File

@ -1,3 +1,9 @@
2003-02-21 Angus Leeming <leeming@lyx.org>
* Timeout_pimpl.[Ch]: removed.
* qtTimeout.[Ch]: new files, replacing the above.
The qtTimeout class derives from Timeout::Impl.
2003-02-21 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr> 2003-02-21 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* qfont_loader.C (addFontPath): make debug messages quieter * qfont_loader.C (addFontPath): make debug messages quieter

View File

@ -24,7 +24,7 @@ libqt2_la_SOURCES = \
LyXKeySymFactory.C \ LyXKeySymFactory.C \
LyXScreenFactory.C \ LyXScreenFactory.C \
Menubar_pimpl.C Menubar_pimpl.h \ Menubar_pimpl.C Menubar_pimpl.h \
Timeout_pimpl.C Timeout_pimpl.h \ qtTimeout.C qtTimeout.h \
QAbout.C QAbout.h \ QAbout.C QAbout.h \
QBibitem.C QBibitem.h \ QBibitem.C QBibitem.h \
QBibtex.C QBibtex.h \ QBibtex.C QBibtex.h \

View File

@ -1,56 +0,0 @@
/**
* \file qt2/Timeout_pimpl.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author John Levon
*
* Full author contact details are available in file CREDITS
*/
#include <config.h>
#include "Timeout_pimpl.h"
#include "debug.h"
using std::endl;
Timeout::Pimpl::Pimpl(Timeout * owner)
: owner_(owner), timeout_id(-1)
{
}
void Timeout::Pimpl::timerEvent(QTimerEvent *)
{
owner_->emit();
}
void Timeout::Pimpl::reset()
{
killTimers();
timeout_id = -1;
}
bool Timeout::Pimpl::running() const
{
return timeout_id != -1;
}
void Timeout::Pimpl::start()
{
if (running())
lyxerr << "Timeout::start: already running!" << endl;
timeout_id = startTimer(owner_->timeout_ms);
}
void Timeout::Pimpl::stop()
{
if (running())
reset();
}

View File

@ -0,0 +1,58 @@
/**
* \file qtTimeout.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author John Levon
*
* Full author contact details are available in file CREDITS
*/
#include <config.h>
#include "qtTimeout.h"
#include "debug.h"
Timeout::Timeout(unsigned int msec, Type t)
: pimpl_(new qtTimeout(*this)), type(t), timeout_ms(msec)
{}
qtTimeout::qtTimeout(Timeout & owner)
: Timeout::Impl(owner), timeout_id(-1)
{}
void qtTimeout::timerEvent(QTimerEvent *)
{
emit();
}
void qtTimeout::reset()
{
killTimers();
timeout_id = -1;
}
bool qtTimeout::running() const
{
return timeout_id != -1;
}
void qtTimeout::start()
{
if (running())
lyxerr << "Timeout::start: already running!" << std::endl;
timeout_id = startTimer(timeout_ms());
}
void qtTimeout::stop()
{
if (running())
reset();
}

View File

@ -1,6 +1,6 @@
// -*- C++ -*- // -*- C++ -*-
/** /**
* \file qt2/Timeout_pimpl.h * \file qtTimeout.h
* This file is part of LyX, the document processor. * This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
@ -9,12 +9,11 @@
* Full author contact details are available in file CREDITS * Full author contact details are available in file CREDITS
*/ */
#ifndef TIMEOUTPIMPL_H #ifndef QTTIMEOUT_H
#define TIMEOUTPIMPL_H #define QTTIMEOUT_H
#include "frontends/Timeout.h" #include "frontends/Timeout.h"
#include <qobject.h> #include <qobject.h>
// stupid Qt // stupid Qt
#undef emit #undef emit
@ -23,26 +22,26 @@
* This class executes the callback when the timeout expires * This class executes the callback when the timeout expires
* using Qt mechanisms * using Qt mechanisms
*/ */
struct Timeout::Pimpl : QObject { struct qtTimeout : QObject, public Timeout::Impl {
public: public:
/// ///
Pimpl(Timeout * owner_); qtTimeout(Timeout & owner_);
///
virtual bool running() const;
/// start the timer /// start the timer
void start(); virtual void start();
/// stop the timer /// stop the timer
void stop(); virtual void stop();
/// reset /// reset
void reset(); virtual void reset();
/// is the timer running ?
bool running() const;
protected: protected:
/// slot /// slot
virtual void timerEvent(QTimerEvent *); virtual void timerEvent(QTimerEvent *);
private: private:
/// the owning timer /// timout id
Timeout * owner_;
/// QTimer id
int timeout_id; int timeout_id;
}; };
#endif #endif // QTTIMEOUT_H

View File

@ -1,3 +1,9 @@
2003-02-21 Angus Leeming <leeming@lyx.org>
* Timeout_pimpl.[Ch]: removed.
* xformsTimeout.[Ch]: new files, replacing the above.
The xformsTimeout class derives from Timeout::Impl.
2003-02-21 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr> 2003-02-21 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* xfont_loader.C (addFontPath): make debug messages quieter * xfont_loader.C (addFontPath): make debug messages quieter

View File

@ -9,8 +9,6 @@ INCLUDES = -I$(top_srcdir)/images -I$(top_srcdir)/src \
SUBDIRS = forms SUBDIRS = forms
EXTRA_DIST = xformsImage.C xformsImage.h
# Alphabetical order please. It makes it easier to figure out what's missing. # Alphabetical order please. It makes it easier to figure out what's missing.
libxforms_la_SOURCES = \ libxforms_la_SOURCES = \
forms_fwd.h \ forms_fwd.h \
@ -35,10 +33,12 @@ libxforms_la_SOURCES = \
xforms_helpers.h \ xforms_helpers.h \
xforms_resize.C \ xforms_resize.C \
xforms_resize.h \ xforms_resize.h \
xformsImage.C \
xformsImage.h \
xformsBC.C \ xformsBC.C \
xformsBC.h \ xformsBC.h \
xformsImage.C \
xformsImage.h \
xformsTimeout.C \
xformsTimeout.h \
xscreen.C \ xscreen.C \
xscreen.h \ xscreen.h \
Alert_pimpl.C \ Alert_pimpl.C \
@ -146,8 +146,6 @@ libxforms_la_SOURCES = \
Menubar_pimpl.h \ Menubar_pimpl.h \
RadioButtonGroup.C \ RadioButtonGroup.C \
RadioButtonGroup.h \ RadioButtonGroup.h \
Timeout_pimpl.C \
Timeout_pimpl.h \
Toolbar_pimpl.C \ Toolbar_pimpl.C \
Toolbar_pimpl.h \ Toolbar_pimpl.h \
Tooltips.C \ Tooltips.C \

View File

@ -1,71 +0,0 @@
/**
* \file xforms/Timeout_pimpl.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Lars Gullik Bjønnes
* \author John Levon
*
* Full author contact details are available in file CREDITS
*/
#include <config.h>
#include FORMS_H_LOCATION
#include "Timeout_pimpl.h"
#include "debug.h"
using std::endl;
namespace {
extern "C" {
static
void C_intern_timeout_cb(int, void * data)
{
Timeout * to = static_cast<Timeout *>(data);
to->emit();
}
}
} // namespace anon
Timeout::Pimpl::Pimpl(Timeout * owner)
: owner_(owner), timeout_id(-1)
{
}
void Timeout::Pimpl::reset()
{
timeout_id = -1;
}
bool Timeout::Pimpl::running() const
{
return timeout_id != -1;
}
void Timeout::Pimpl::start()
{
if (timeout_id != -1)
lyxerr << "Timeout::start: already running!" << endl;
timeout_id = fl_add_timeout(owner_->timeout_ms,
C_intern_timeout_cb, owner_);
}
void Timeout::Pimpl::stop()
{
if (timeout_id != -1) {
fl_remove_timeout(timeout_id);
timeout_id = -1;
}
}

View File

@ -0,0 +1,77 @@
/**
* \file xformsTimeout.C
* Copyright 2001 LyX Team
* Read COPYING
*
* \author Lars Gullik Bjønnes
* \author John Levon
* \author Angus Leeming
*/
#include <config.h>
#include "xformsTimeout.h"
#include "debug.h"
#include FORMS_H_LOCATION
Timeout::Timeout(unsigned int msec, Type t)
: pimpl_(new xformsTimeout(*this)), type(t), timeout_ms(msec)
{}
namespace {
extern "C"
void C_TimeoutCB(int, void * data)
{
xformsTimeout * to = static_cast<xformsTimeout *>(data);
to->emitCB();
}
} // namespace anon
xformsTimeout::xformsTimeout(Timeout & owner)
: Timeout::Impl(owner), timeout_id(-1)
{}
void xformsTimeout::emitCB()
{
emit();
}
bool xformsTimeout::running() const
{
return timeout_id != -1;
}
void xformsTimeout::start()
{
if (running()) {
lyxerr << "Timeout::start: already running!" << std::endl;
} else {
timeout_id = fl_add_timeout(timeout_ms(),
C_TimeoutCB, this);
}
}
void xformsTimeout::stop()
{
if (running()) {
fl_remove_timeout(timeout_id);
timeout_id = -1;
}
}
void xformsTimeout::reset()
{
timeout_id = -1;
}

View File

@ -1,42 +1,44 @@
// -*- C++ -*- // -*- C++ -*-
/** /**
* \file xforms/Timeout_pimpl.h * \file xformsTimeout.h
* This file is part of LyX, the document processor. * This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
* \author Lars Gullik Bjønnes * \author Lars Gullik Bjønnes
* \author John Levon * \author John Levon
* \author Angus Leeming
* *
* Full author contact details are available in file CREDITS * Full author contact details are available in file CREDITS
*/ */
#ifndef TIMEOUTPIMPL_H
#define TIMEOUTPIMPL_H #ifndef XFORMSTIMEOUT_H
#define XFORMSTIMEOUT_H
#include "frontends/Timeout.h" #include "frontends/Timeout.h"
/** /**
* This class executes the callback when the timeout expires * This class executes the callback when the timeout expires
* using XForms mechanisms * using xforms mechanisms
*/ */
struct Timeout::Pimpl { class xformsTimeout : public Timeout::Impl {
public: public:
/// ///
Pimpl(Timeout * owner_); xformsTimeout(Timeout &);
/// Is the timer running? ///
bool running() const; virtual bool running() const;
/// start the timer ///
void start(); virtual void start();
/// stop the timer ///
void stop(); virtual void stop();
/// reset ///
void reset(); virtual void reset();
/// xforms callback function
void emitCB();
private: private:
/// the owning timer ///
Timeout * owner_;
/// xforms id
int timeout_id; int timeout_id;
}; };
#endif #endif // XFORMSTIMEOUT_H