From a4276f27f72014f03dbedd841e5686a7036389a0 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Sat, 22 Feb 2003 18:01:16 +0000 Subject: [PATCH] Make the GUI instantiation invisible to Timeout. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6230 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/ChangeLog | 7 ++ src/frontends/Timeout.C | 19 ++--- src/frontends/Timeout.h | 41 ++++++++-- src/frontends/gnome/ChangeLog | 6 ++ src/frontends/gnome/Makefile.am | 4 +- .../gnome/{Timeout_pimpl.C => gnomeTimeout.C} | 35 +++++---- .../gnome/{Timeout_pimpl.h => gnomeTimeout.h} | 14 ++-- src/frontends/qt2/ChangeLog | 6 ++ src/frontends/qt2/Makefile.am | 2 +- src/frontends/qt2/Timeout_pimpl.C | 56 -------------- src/frontends/qt2/qtTimeout.C | 58 ++++++++++++++ .../qt2/{Timeout_pimpl.h => qtTimeout.h} | 31 ++++---- src/frontends/xforms/ChangeLog | 6 ++ src/frontends/xforms/Makefile.am | 10 +-- src/frontends/xforms/Timeout_pimpl.C | 71 ----------------- src/frontends/xforms/xformsTimeout.C | 77 +++++++++++++++++++ .../{Timeout_pimpl.h => xformsTimeout.h} | 38 ++++----- 17 files changed, 272 insertions(+), 209 deletions(-) rename src/frontends/gnome/{Timeout_pimpl.C => gnomeTimeout.C} (60%) rename src/frontends/gnome/{Timeout_pimpl.h => gnomeTimeout.h} (80%) delete mode 100644 src/frontends/qt2/Timeout_pimpl.C create mode 100644 src/frontends/qt2/qtTimeout.C rename src/frontends/qt2/{Timeout_pimpl.h => qtTimeout.h} (62%) delete mode 100644 src/frontends/xforms/Timeout_pimpl.C create mode 100644 src/frontends/xforms/xformsTimeout.C rename src/frontends/xforms/{Timeout_pimpl.h => xformsTimeout.h} (50%) diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index 10084e0146..05aed79c94 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,10 @@ +2003-02-21 Angus Leeming + + * 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 * Dialogs.h: remove forward declarations of InsetBibKey, InsetBibtex. diff --git a/src/frontends/Timeout.C b/src/frontends/Timeout.C index 2ecb0442df..0cef024ee9 100644 --- a/src/frontends/Timeout.C +++ b/src/frontends/Timeout.C @@ -12,22 +12,12 @@ #include #include "Timeout.h" -#include "debug.h" - -#include "Timeout_pimpl.h" - - -Timeout::Timeout(unsigned int msec, Type t) - : type(t), timeout_ms(msec) -{ - pimpl_ = new Pimpl(this); -} +#include "support/LAssert.h" Timeout::~Timeout() { pimpl_->stop(); - delete pimpl_; } @@ -42,17 +32,20 @@ void Timeout::start() pimpl_->start(); } + void Timeout::stop() { pimpl_->stop(); } + void Timeout::restart() { pimpl_->stop(); pimpl_->start(); } + void Timeout::emit() { pimpl_->reset(); @@ -61,6 +54,7 @@ void Timeout::emit() pimpl_->start(); } + Timeout & Timeout::setType(Type t) { type = t; @@ -70,6 +64,9 @@ Timeout & Timeout::setType(Type t) Timeout & Timeout::setTimeout(unsigned int msec) { + // Can't have a timeout of zero! + lyx::Assert(msec); + timeout_ms = msec; return * this; } diff --git a/src/frontends/Timeout.h b/src/frontends/Timeout.h index afa331decc..4d602e475b 100644 --- a/src/frontends/Timeout.h +++ b/src/frontends/Timeout.h @@ -13,9 +13,9 @@ #ifndef TIMEOUT_H #define TIMEOUT_H - #include + /** * This class executes the callback when the timeout expires. */ @@ -26,7 +26,7 @@ public: ONETIME, //< one-shot timer CONTINUOUS //< repeating }; - /// + /// Note that the c-tor is implemented in the GUI-specific frontends Timeout(unsigned int msec, Type = ONETIME); /// ~Timeout(); @@ -47,13 +47,42 @@ public: /// set the timeout value 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: /// - struct Pimpl; + friend class Impl; /// - friend struct Pimpl; - /// implementation - Pimpl * pimpl_; + boost::scoped_ptr const pimpl_; /// one-shot or repeating Type type; /// timeout value in milliseconds diff --git a/src/frontends/gnome/ChangeLog b/src/frontends/gnome/ChangeLog index 9b33c9939f..3924ef2b1c 100644 --- a/src/frontends/gnome/ChangeLog +++ b/src/frontends/gnome/ChangeLog @@ -1,3 +1,9 @@ +2003-02-21 Angus Leeming + + * Timeout_pimpl.[Ch]: removed. + * gnomeTimeout.[Ch]: new files, replacing the above. + The gnomeTimeout class derives from Timeout::Impl. + 2003-02-21 Angus Leeming * FileDialog.C (FileDialog): no need for LyXView *. diff --git a/src/frontends/gnome/Makefile.am b/src/frontends/gnome/Makefile.am index 37859adb26..aacdb81fbc 100644 --- a/src/frontends/gnome/Makefile.am +++ b/src/frontends/gnome/Makefile.am @@ -152,8 +152,8 @@ libgnome_la_SOURCES = \ gnomeBC.C \ gnomeBC.h \ lyx_gui.C \ - Timeout_pimpl.C \ - Timeout_pimpl.h \ + gnomeTimeout.C \ + gnomeTimeout.h \ pixbutton.h libgnome.la: xforms.lo $(libgnome_la_OBJECTS) $(libgnome_la_DEPENDENCIES) diff --git a/src/frontends/gnome/Timeout_pimpl.C b/src/frontends/gnome/gnomeTimeout.C similarity index 60% rename from src/frontends/gnome/Timeout_pimpl.C rename to src/frontends/gnome/gnomeTimeout.C index 92af7e6b20..0d53b5a000 100644 --- a/src/frontends/gnome/Timeout_pimpl.C +++ b/src/frontends/gnome/gnomeTimeout.C @@ -1,5 +1,5 @@ /** - * \file gnome/Timeout_pimpl.C + * \file gnomeTimeout.C * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * @@ -11,27 +11,34 @@ #include - #include -#include "Timeout_pimpl.h" +#include "gnomeTimeout.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(); } -bool Timeout::Pimpl::running() const + +bool gnomeTimeout::running() const { return running_; } -void Timeout::Pimpl::start() + +void gnomeTimeout::start() { if (conn_.connected()) { lyxerr << "Timeout::start: already running!" << std::endl; @@ -40,21 +47,21 @@ void Timeout::Pimpl::start() conn_ = Glib::signal_timeout().connect( SigC::slot(*this, &Timeout::Pimpl::timeoutEvent), - owner_->timeout_ms + timeout_ms() ); running_ = true; } -void Timeout::Pimpl::stop() +void gnomeTimeout::stop() { conn_.disconnect(); running_ = false; } -bool Timeout::Pimpl::timeoutEvent() +bool gnomeTimeout::timeoutEvent() { - owner_->emit(); + emit(); return false; // discontinue emitting timeouts. } diff --git a/src/frontends/gnome/Timeout_pimpl.h b/src/frontends/gnome/gnomeTimeout.h similarity index 80% rename from src/frontends/gnome/Timeout_pimpl.h rename to src/frontends/gnome/gnomeTimeout.h index 8dfb26c75b..8f28674159 100644 --- a/src/frontends/gnome/Timeout_pimpl.h +++ b/src/frontends/gnome/gnomeTimeout.h @@ -1,6 +1,6 @@ // -*- C++ -*- /** - * \file gnome/Timeout_pimpl.h + * \file gnomeTimeout.h * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * @@ -8,8 +8,8 @@ * * Full author contact details are available in file CREDITS */ -#ifndef TIMEOUTPIMPL_H -#define TIMEOUTPIMPL_H +#ifndef GNOMETIMEOUT_H +#define GNOMETIMEOUT_H #include "frontends/Timeout.h" #include "glib.h" // for gint @@ -21,10 +21,10 @@ * This class executes the callback when the timeout expires * using Gnome mechanisms */ -struct Timeout::Pimpl : public SigC::Object { +struct gnomeTimeout : public SigC::Object, public Timeout::Impl { public: /// - Pimpl(Timeout * owner_); + gnomeTimeout(Timeout * owner_); /// start the timer void start(); /// stop the timer @@ -39,12 +39,10 @@ public: /// The timeout signal, this gets called when the timeout passed. bool timeoutEvent(); private: - /// the owning timer - Timeout * owner_; /// Timer connection SigC::Connection conn_; /// Used for running as SigC::Connection::connected() isn't const bool running_; }; -#endif +#endif // GNOMETIMEOUT diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index c9e919385d..3a7e57061d 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,9 @@ +2003-02-21 Angus Leeming + + * Timeout_pimpl.[Ch]: removed. + * qtTimeout.[Ch]: new files, replacing the above. + The qtTimeout class derives from Timeout::Impl. + 2003-02-21 Jean-Marc Lasgouttes * qfont_loader.C (addFontPath): make debug messages quieter diff --git a/src/frontends/qt2/Makefile.am b/src/frontends/qt2/Makefile.am index 29a6b77964..5b4155514c 100644 --- a/src/frontends/qt2/Makefile.am +++ b/src/frontends/qt2/Makefile.am @@ -24,7 +24,7 @@ libqt2_la_SOURCES = \ LyXKeySymFactory.C \ LyXScreenFactory.C \ Menubar_pimpl.C Menubar_pimpl.h \ - Timeout_pimpl.C Timeout_pimpl.h \ + qtTimeout.C qtTimeout.h \ QAbout.C QAbout.h \ QBibitem.C QBibitem.h \ QBibtex.C QBibtex.h \ diff --git a/src/frontends/qt2/Timeout_pimpl.C b/src/frontends/qt2/Timeout_pimpl.C deleted file mode 100644 index 3edad5fb57..0000000000 --- a/src/frontends/qt2/Timeout_pimpl.C +++ /dev/null @@ -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 - - -#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(); -} diff --git a/src/frontends/qt2/qtTimeout.C b/src/frontends/qt2/qtTimeout.C new file mode 100644 index 0000000000..36bfb4b915 --- /dev/null +++ b/src/frontends/qt2/qtTimeout.C @@ -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 + +#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(); +} diff --git a/src/frontends/qt2/Timeout_pimpl.h b/src/frontends/qt2/qtTimeout.h similarity index 62% rename from src/frontends/qt2/Timeout_pimpl.h rename to src/frontends/qt2/qtTimeout.h index f8b5f7da31..649df71d40 100644 --- a/src/frontends/qt2/Timeout_pimpl.h +++ b/src/frontends/qt2/qtTimeout.h @@ -1,6 +1,6 @@ // -*- C++ -*- /** - * \file qt2/Timeout_pimpl.h + * \file qtTimeout.h * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * @@ -9,12 +9,11 @@ * Full author contact details are available in file CREDITS */ -#ifndef TIMEOUTPIMPL_H -#define TIMEOUTPIMPL_H - +#ifndef QTTIMEOUT_H +#define QTTIMEOUT_H #include "frontends/Timeout.h" -#include +#include // stupid Qt #undef emit @@ -23,26 +22,26 @@ * This class executes the callback when the timeout expires * using Qt mechanisms */ -struct Timeout::Pimpl : QObject { +struct qtTimeout : QObject, public Timeout::Impl { public: /// - Pimpl(Timeout * owner_); + qtTimeout(Timeout & owner_); + /// + virtual bool running() const; /// start the timer - void start(); + virtual void start(); /// stop the timer - void stop(); + virtual void stop(); /// reset - void reset(); - /// is the timer running ? - bool running() const; + virtual void reset(); + protected: /// slot virtual void timerEvent(QTimerEvent *); + private: - /// the owning timer - Timeout * owner_; - /// QTimer id + /// timout id int timeout_id; }; -#endif +#endif // QTTIMEOUT_H diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 214806be65..404c0145c3 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,9 @@ +2003-02-21 Angus Leeming + + * Timeout_pimpl.[Ch]: removed. + * xformsTimeout.[Ch]: new files, replacing the above. + The xformsTimeout class derives from Timeout::Impl. + 2003-02-21 Jean-Marc Lasgouttes * xfont_loader.C (addFontPath): make debug messages quieter diff --git a/src/frontends/xforms/Makefile.am b/src/frontends/xforms/Makefile.am index be6da8f9bf..a67ac6279a 100644 --- a/src/frontends/xforms/Makefile.am +++ b/src/frontends/xforms/Makefile.am @@ -9,8 +9,6 @@ INCLUDES = -I$(top_srcdir)/images -I$(top_srcdir)/src \ SUBDIRS = forms -EXTRA_DIST = xformsImage.C xformsImage.h - # Alphabetical order please. It makes it easier to figure out what's missing. libxforms_la_SOURCES = \ forms_fwd.h \ @@ -35,10 +33,12 @@ libxforms_la_SOURCES = \ xforms_helpers.h \ xforms_resize.C \ xforms_resize.h \ - xformsImage.C \ - xformsImage.h \ xformsBC.C \ xformsBC.h \ + xformsImage.C \ + xformsImage.h \ + xformsTimeout.C \ + xformsTimeout.h \ xscreen.C \ xscreen.h \ Alert_pimpl.C \ @@ -146,8 +146,6 @@ libxforms_la_SOURCES = \ Menubar_pimpl.h \ RadioButtonGroup.C \ RadioButtonGroup.h \ - Timeout_pimpl.C \ - Timeout_pimpl.h \ Toolbar_pimpl.C \ Toolbar_pimpl.h \ Tooltips.C \ diff --git a/src/frontends/xforms/Timeout_pimpl.C b/src/frontends/xforms/Timeout_pimpl.C deleted file mode 100644 index ca08385d45..0000000000 --- a/src/frontends/xforms/Timeout_pimpl.C +++ /dev/null @@ -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 - -#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(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; - } -} diff --git a/src/frontends/xforms/xformsTimeout.C b/src/frontends/xforms/xformsTimeout.C new file mode 100644 index 0000000000..658ae9bb34 --- /dev/null +++ b/src/frontends/xforms/xformsTimeout.C @@ -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 + +#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(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; +} diff --git a/src/frontends/xforms/Timeout_pimpl.h b/src/frontends/xforms/xformsTimeout.h similarity index 50% rename from src/frontends/xforms/Timeout_pimpl.h rename to src/frontends/xforms/xformsTimeout.h index df5b8588c7..c5273ca040 100644 --- a/src/frontends/xforms/Timeout_pimpl.h +++ b/src/frontends/xforms/xformsTimeout.h @@ -1,42 +1,44 @@ // -*- C++ -*- /** - * \file xforms/Timeout_pimpl.h + * \file xformsTimeout.h * 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 + * \author Angus Leeming * * 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" /** * This class executes the callback when the timeout expires - * using XForms mechanisms + * using xforms mechanisms */ -struct Timeout::Pimpl { +class xformsTimeout : public Timeout::Impl { public: /// - Pimpl(Timeout * owner_); - /// Is the timer running? - bool running() const; - /// start the timer - void start(); - /// stop the timer - void stop(); - /// reset - void reset(); + xformsTimeout(Timeout &); + /// + virtual bool running() const; + /// + virtual void start(); + /// + virtual void stop(); + /// + virtual void reset(); + /// xforms callback function + void emitCB(); private: - /// the owning timer - Timeout * owner_; - /// xforms id + /// int timeout_id; }; -#endif +#endif // XFORMSTIMEOUT_H