From: Angus Leeming Date: Tue, 13 Apr 2004 17:25:23 +0000 (+0000) Subject: Refactoring of renderer code to make inset code simpler. X-Git-Tag: 1.6.10~15316 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=fff7d8407c7f6b9ed10cd04f9356c3d56d89bf05;p=lyx.git Refactoring of renderer code to make inset code simpler. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8650 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 20102f68dc..460e015170 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,22 @@ +2004-04-13 Angus Leeming + + * render_base.[Ch] (clone): now takes an InsetBase ptr to enable + the renderer to inform LyX::updateInset that the inset's status + has changed and it should be redrawn. + + * render_button.[Ch] (clone): + * render_graphic.[Ch] (c-tors, clone): + * render_preview.[Ch] (c-tors, clone): ditto. + + * render_graphic.[Ch] (connect): + * render_preview.[Ch] (connect): removed, as connection is now + made in the constructors. + + * insetexternal.C: + * insetgraphics.C: + * insetinclude.C: ensuing simplification of the client code. + (statusChanged): now superfluous. Removed. + 2004-04-12 Georg Baum * ExternalTemplate.[Ch]: remove editCommand diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 5dd6895c4d..007100b8ea 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -410,18 +410,8 @@ InsetExternal::InsetExternal(InsetExternal const & other) : InsetOld(other), boost::signals::trackable(), params_(other.params_), - renderer_(other.renderer_->clone()) -{ - if (renderer_->asMonitoredPreview() != 0) { - RenderMonitoredPreview * const ptr = renderer_->asMonitoredPreview(); - ptr->connect(boost::bind(&InsetExternal::statusChanged, this)); - ptr->fileChanged(boost::bind(&InsetExternal::fileChanged, this)); - - } else if (renderer_->asGraphic() != 0 ) { - RenderGraphic * const ptr = renderer_->asGraphic(); - ptr->connect(boost::bind(&InsetExternal::statusChanged, this)); - } -} + renderer_(other.renderer_->clone(this)) +{} auto_ptr InsetExternal::clone() const @@ -611,10 +601,8 @@ void InsetExternal::setParams(InsetExternalParams const & p, } case RENDERGRAPHIC: { RenderGraphic * graphic_ptr = renderer_->asGraphic(); if (!graphic_ptr) { - renderer_.reset(new RenderGraphic); + renderer_.reset(new RenderGraphic(this)); graphic_ptr = renderer_->asGraphic(); - graphic_ptr->connect( - boost::bind(&InsetExternal::statusChanged, this)); } graphic_ptr->update(get_grfx_params(params_)); @@ -625,10 +613,8 @@ void InsetExternal::setParams(InsetExternalParams const & p, RenderMonitoredPreview * preview_ptr = renderer_->asMonitoredPreview(); if (!preview_ptr) { - renderer_.reset(new RenderMonitoredPreview); + renderer_.reset(new RenderMonitoredPreview(this)); preview_ptr = renderer_->asMonitoredPreview(); - preview_ptr->connect( - boost::bind(&InsetExternal::statusChanged, this)); preview_ptr->fileChanged( boost::bind(&InsetExternal::fileChanged, this)); } diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index bdb569b482..2b40892f5e 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -152,19 +152,16 @@ string findTargetFormat(string const & suffix, OutputParams const & runparams) InsetGraphics::InsetGraphics() : graphic_label(uniqueID()), - graphic_(new RenderGraphic) -{ - graphic_->connect(boost::bind(&InsetGraphics::statusChanged, this)); -} + graphic_(new RenderGraphic(this)) +{} InsetGraphics::InsetGraphics(InsetGraphics const & ig) : InsetOld(ig), boost::signals::trackable(), graphic_label(uniqueID()), - graphic_(new RenderGraphic(*ig.graphic_)) + graphic_(new RenderGraphic(*ig.graphic_, this)) { - graphic_->connect(boost::bind(&InsetGraphics::statusChanged, this)); setParams(ig.params()); } @@ -181,12 +178,6 @@ InsetGraphics::~InsetGraphics() } -void InsetGraphics::statusChanged() const -{ - LyX::cref().updateInset(this); -} - - void InsetGraphics::priv_dispatch(LCursor & cur, FuncRequest & cmd) { switch (cmd.action) { diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index b4ac3d5171..6f781cd304 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -88,11 +88,6 @@ private: /// friend class InsetGraphicsMailer; - /** This method is connected to the graphics loader, so we are - * informed when the image has been loaded. - */ - void statusChanged() const; - /// Read the inset native format void readInsetGraphics(LyXLex & lex, std::string const & bufpath); diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 675f80e795..e816694043 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -91,10 +91,9 @@ string const uniqueID() InsetInclude::InsetInclude(InsetCommandParams const & p) : params_(p), include_label(uniqueID()), - preview_(new RenderMonitoredPreview), + preview_(new RenderMonitoredPreview(this)), set_label_(false) { - preview_->connect(boost::bind(&InsetInclude::statusChanged, this)); preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this)); } @@ -103,10 +102,9 @@ InsetInclude::InsetInclude(InsetInclude const & other) : InsetOld(other), params_(other.params_), include_label(other.include_label), - preview_(new RenderMonitoredPreview), + preview_(new RenderMonitoredPreview(this)), set_label_(other.set_label_) { - preview_->connect(boost::bind(&InsetInclude::statusChanged, this)); preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this)); } @@ -607,12 +605,6 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const // preview stuff // -void InsetInclude::statusChanged() const -{ - LyX::cref().updateInset(this); -} - - void InsetInclude::fileChanged() const { Buffer const * const buffer_ptr = LyX::cref().updateInset(this); diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index 391940f0f7..588d5eabe2 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -85,8 +85,6 @@ protected: /// virtual void priv_dispatch(LCursor & cur, FuncRequest & cmd); private: - /// Slot receiving a signal that the preview is ready to display. - void statusChanged() const; /** Slot receiving a signal that the external file has changed * and the preview should be regenerated. */ diff --git a/src/insets/render_base.h b/src/insets/render_base.h index e8a0468e0d..23a5e9af43 100644 --- a/src/insets/render_base.h +++ b/src/insets/render_base.h @@ -16,6 +16,7 @@ #include +class InsetBase; class MetricsInfo; class PainterInfo; @@ -28,7 +29,7 @@ class RenderBase { public: virtual ~RenderBase() {} - virtual std::auto_ptr clone() const = 0; + virtual std::auto_ptr clone(InsetBase const *) const = 0; /// compute the size of the object returned in dim virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0; diff --git a/src/insets/render_button.C b/src/insets/render_button.C index 55c001b3fd..9bff2efc1b 100644 --- a/src/insets/render_button.C +++ b/src/insets/render_button.C @@ -27,7 +27,7 @@ RenderButton::RenderButton() {} -auto_ptr RenderButton::clone() const +auto_ptr RenderButton::clone(InsetBase const *) const { return auto_ptr(new RenderButton(*this)); } diff --git a/src/insets/render_button.h b/src/insets/render_button.h index 770eae304c..4d805359d9 100644 --- a/src/insets/render_button.h +++ b/src/insets/render_button.h @@ -22,7 +22,7 @@ class RenderButton : public RenderBase public: RenderButton(); - std::auto_ptr clone() const; + std::auto_ptr clone(InsetBase const *) const; /// compute the size of the object returned in dim virtual void metrics(MetricsInfo & mi, Dimension & dim) const; diff --git a/src/insets/render_graphic.C b/src/insets/render_graphic.C index 72639def88..44e8b7ef21 100644 --- a/src/insets/render_graphic.C +++ b/src/insets/render_graphic.C @@ -16,6 +16,7 @@ #include "gettext.h" #include "LColor.h" +#include "lyx_main.h" #include "lyxrc.h" #include "metricsinfo.h" @@ -26,6 +27,8 @@ #include "support/filetools.h" +#include + namespace graphics = lyx::graphics; using lyx::support::AbsolutePath; @@ -35,22 +38,29 @@ using std::string; using std::auto_ptr; -RenderGraphic::RenderGraphic() +RenderGraphic::RenderGraphic(InsetBase const * inset) : checksum_(0) -{} +{ + loader_.connect(boost::bind(&LyX::updateInset, + boost::cref(LyX::cref()), inset)); +} -RenderGraphic::RenderGraphic(RenderGraphic const & other) +RenderGraphic::RenderGraphic(RenderGraphic const & other, + InsetBase const * inset) : RenderBase(other), loader_(other.loader_), params_(other.params_), checksum_(0) -{} +{ + loader_.connect(boost::bind(&LyX::updateInset, + boost::cref(LyX::cref()), inset)); +} -auto_ptr RenderGraphic::clone() const +auto_ptr RenderGraphic::clone(InsetBase const * inset) const { - return auto_ptr(new RenderGraphic(*this)); + return auto_ptr(new RenderGraphic(*this, inset)); } @@ -75,12 +85,6 @@ bool RenderGraphic::hasFileChanged() const } -boost::signals::connection RenderGraphic::connect(slot_type const & slot) const -{ - return loader_.connect(slot); -} - - namespace { bool displayGraphic(graphics::Params const & params) diff --git a/src/insets/render_graphic.h b/src/insets/render_graphic.h index 7ce10c3476..a5d8e5155a 100644 --- a/src/insets/render_graphic.h +++ b/src/insets/render_graphic.h @@ -17,15 +17,13 @@ #include "graphics/GraphicsLoader.h" #include "graphics/GraphicsParams.h" -#include - class RenderGraphic : public RenderBase { public: - RenderGraphic(); - RenderGraphic(RenderGraphic const &); - std::auto_ptr clone() const; + RenderGraphic(InsetBase const *); + RenderGraphic(RenderGraphic const &, InsetBase const *); + std::auto_ptr clone(InsetBase const *) const; /// compute the size of the object returned in dim void metrics(MetricsInfo & mi, Dimension & dim) const; @@ -38,12 +36,6 @@ public: /// Is the stored checksum different to that of the graphics loader? bool hasFileChanged() const; - /** Connect and you'll be informed when the loading status of the image - * changes. - */ - typedef boost::signal0::slot_type slot_type; - boost::signals::connection connect(slot_type const &) const; - /// equivalent to dynamic_cast virtual RenderGraphic * asGraphic() { return this; } diff --git a/src/insets/render_preview.C b/src/insets/render_preview.C index df24bf20c2..40a54c9081 100644 --- a/src/insets/render_preview.C +++ b/src/insets/render_preview.C @@ -17,6 +17,7 @@ #include "dimension.h" #include "gettext.h" #include "LColor.h" +#include "lyx_main.h" #include "metricsinfo.h" #include "frontends/font_metrics.h" @@ -43,22 +44,25 @@ bool RenderPreview::activated() } -RenderPreview::RenderPreview() - : pimage_(0) +RenderPreview::RenderPreview(InsetBase const * inset) + : pimage_(0), + parent_(inset) {} -RenderPreview::RenderPreview(RenderPreview const & other) +RenderPreview::RenderPreview(RenderPreview const & other, + InsetBase const * inset) : RenderBase(other), boost::signals::trackable(), snippet_(other.snippet_), - pimage_(0) + pimage_(0), + parent_(inset) {} -auto_ptr RenderPreview::clone() const +auto_ptr RenderPreview::clone(InsetBase const * inset) const { - return auto_ptr(new RenderPreview(*this)); + return auto_ptr(new RenderPreview(*this, inset)); } @@ -142,12 +146,6 @@ void RenderPreview::draw(PainterInfo & pi, int x, int y) const } -boost::signals::connection RenderPreview::connect(slot_type const & slot) -{ - return preview_ready_signal_.connect(slot); -} - - void RenderPreview::startLoading(Buffer const & buffer) const { if (!activated() && !snippet_.empty()) @@ -224,10 +222,16 @@ void RenderPreview::imageReady(graphics::PreviewImage const & pimage) return; pimage_ = &pimage; - preview_ready_signal_(); + LyX::cref().updateInset(parent_); } +RenderMonitoredPreview::RenderMonitoredPreview(InsetBase const * inset) + : RenderPreview(inset), + monitor_(std::string(), 2000) +{} + + void RenderMonitoredPreview::setAbsFile(string const & file) { monitor_.reset(file); diff --git a/src/insets/render_preview.h b/src/insets/render_preview.h index 4e5f8a97fc..5b0bd23917 100644 --- a/src/insets/render_preview.h +++ b/src/insets/render_preview.h @@ -44,9 +44,9 @@ public: /// a wrapper for Previews::activated() static bool activated(); - RenderPreview(); - RenderPreview(RenderPreview const &); - std::auto_ptr clone() const; + RenderPreview(InsetBase const *); + RenderPreview(RenderPreview const &, InsetBase const *); + std::auto_ptr clone(InsetBase const *) const; /// Compute the size of the object, returned in dim void metrics(MetricsInfo &, Dimension & dim) const; @@ -75,10 +75,6 @@ public: /// The preview has been generated and is ready to use. bool previewReady() const; - /// Connect and you'll be informed when the preview is ready. - typedef boost::signal0::slot_type slot_type; - boost::signals::connection connect(slot_type const &); - /// equivalent to dynamic_cast virtual RenderPreview * asPreview() { return this; } @@ -100,14 +96,14 @@ private: */ boost::signals::connection ploader_connection_; - /// This signal is emitted when the preview is ready for display. - boost::signal0 preview_ready_signal_; + /// Inform the core that the inset has changed. + InsetBase const * parent_; }; class RenderMonitoredPreview : public RenderPreview { public: - RenderMonitoredPreview() : monitor_(std::string(), 2000) {} + RenderMonitoredPreview(InsetBase const *); /// void draw(PainterInfo & pi, int x, int y) const; /// @@ -117,7 +113,9 @@ public: void startMonitoring() const { monitor_.start(); } void stopMonitoring() const { monitor_.stop(); } + /// Connect and you'll be informed when the file changes. + typedef boost::signal0::slot_type slot_type; boost::signals::connection fileChanged(slot_type const &); /// equivalent to dynamic_cast