]> git.lyx.org Git - lyx.git/commitdiff
Refactoring of renderer code to make inset code simpler.
authorAngus Leeming <leeming@lyx.org>
Tue, 13 Apr 2004 17:25:23 +0000 (17:25 +0000)
committerAngus Leeming <leeming@lyx.org>
Tue, 13 Apr 2004 17:25:23 +0000 (17:25 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8650 a592a061-630c-0410-9148-cb99ea01b6c8

13 files changed:
src/insets/ChangeLog
src/insets/insetexternal.C
src/insets/insetgraphics.C
src/insets/insetgraphics.h
src/insets/insetinclude.C
src/insets/insetinclude.h
src/insets/render_base.h
src/insets/render_button.C
src/insets/render_button.h
src/insets/render_graphic.C
src/insets/render_graphic.h
src/insets/render_preview.C
src/insets/render_preview.h

index 20102f68dc1450d9f53f5323da6b06fd4524ae26..460e0151704d9e20d221e0f802eb9e76410ea26f 100644 (file)
@@ -1,3 +1,22 @@
+2004-04-13  Angus Leeming  <angus@localhost.localdomain>
+
+       * 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  <Georg.Baum@post.rwth-aachen.de>
 
        * ExternalTemplate.[Ch]: remove editCommand
index 5dd6895c4dcbbaefd68edeea7921f48aba70f636..007100b8ea535771b0bb7ce816e5bbc6084b4893 100644 (file)
@@ -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<InsetBase> 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));
                }
index bdb569b48241957a6115fb3e1b360eb19a1b3272..2b40892f5ee8f077241397bba333ce606c5b258a 100644 (file)
@@ -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) {
index b4ac3d51710fce7449d6f45125c8dff0b7c8db70..6f781cd304efbc91e4dcfb11b15402834d08903c 100644 (file)
@@ -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);
 
index 675f80e7955e48341682a65fb2f61989dfe0a434..e816694043d0706653e4bf6187d748cc6970cd88 100644 (file)
@@ -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);
index 391940f0f71aaa71c6e6d7adf119647b60ed09bd..588d5eabe2844dba8f3e3ddc348737972745b568 100644 (file)
@@ -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.
         */
index e8a0468e0d5e093083715a53ea55a48b8897f6d8..23a5e9af4394dff47cf791e4bc51cbd6ce1ec43d 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <memory>
 
+class InsetBase;
 class MetricsInfo;
 class PainterInfo;
 
@@ -28,7 +29,7 @@ class RenderBase {
 public:
        virtual ~RenderBase() {}
 
-       virtual std::auto_ptr<RenderBase> clone() const = 0;
+       virtual std::auto_ptr<RenderBase> clone(InsetBase const *) const = 0;
 
        /// compute the size of the object returned in dim
        virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0;
index 55c001b3fdcb5b12003a86a7e1885540d3f1c7cc..9bff2efc1bad136341f2712884a8e3f803d58f7a 100644 (file)
@@ -27,7 +27,7 @@ RenderButton::RenderButton()
 {}
 
 
-auto_ptr<RenderBase> RenderButton::clone() const
+auto_ptr<RenderBase> RenderButton::clone(InsetBase const *) const
 {
        return auto_ptr<RenderBase>(new RenderButton(*this));
 }
index 770eae304c7eb30dc161fe3b88011cbb188e9797..4d805359d9e0264defd18976723bfa4efe4f82bc 100644 (file)
@@ -22,7 +22,7 @@ class RenderButton : public RenderBase
 public:
        RenderButton();
 
-       std::auto_ptr<RenderBase> clone() const;
+       std::auto_ptr<RenderBase> clone(InsetBase const *) const;
 
        /// compute the size of the object returned in dim
        virtual void metrics(MetricsInfo & mi, Dimension & dim) const;
index 72639def888fc6cd809a3552e895cb2c1c3f9e2e..44e8b7ef21d54682f9fef7c9e950a98191173875 100644 (file)
@@ -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 <boost/bind.hpp>
+
 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<RenderBase> RenderGraphic::clone() const
+auto_ptr<RenderBase> RenderGraphic::clone(InsetBase const * inset) const
 {
-       return auto_ptr<RenderBase>(new RenderGraphic(*this));
+       return auto_ptr<RenderBase>(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)
index 7ce10c3476477fcd3c040be0f48b06571f861181..a5d8e5155a979771b675d70e76dfd7a440d1c58a 100644 (file)
 #include "graphics/GraphicsLoader.h"
 #include "graphics/GraphicsParams.h"
 
-#include <boost/signals/signal0.hpp>
-
 
 class RenderGraphic : public RenderBase
 {
 public:
-       RenderGraphic();
-       RenderGraphic(RenderGraphic const &);
-       std::auto_ptr<RenderBase> clone() const;
+       RenderGraphic(InsetBase const *);
+       RenderGraphic(RenderGraphic const &, InsetBase const *);
+       std::auto_ptr<RenderBase> 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<void>::slot_type slot_type;
-       boost::signals::connection connect(slot_type const &) const;
-
        /// equivalent to dynamic_cast
        virtual RenderGraphic * asGraphic() { return this; }
 
index df24bf20c22d7c36973bfe9efa4f7ab79d0c61b4..40a54c908134a725d8e5fb289860fa14b5dd1481 100644 (file)
@@ -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<RenderBase> RenderPreview::clone() const
+auto_ptr<RenderBase> RenderPreview::clone(InsetBase const * inset) const
 {
-       return auto_ptr<RenderBase>(new RenderPreview(*this));
+       return auto_ptr<RenderBase>(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);
index 4e5f8a97fc17e3d49af6e076423fba0320ce0e78..5b0bd239171e7d9568d2a54cde5bd2762429a10c 100644 (file)
@@ -44,9 +44,9 @@ public:
        /// a wrapper for Previews::activated()
        static bool activated();
 
-       RenderPreview();
-       RenderPreview(RenderPreview const &);
-       std::auto_ptr<RenderBase> clone() const;
+       RenderPreview(InsetBase const *);
+       RenderPreview(RenderPreview const &, InsetBase const *);
+       std::auto_ptr<RenderBase> 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<void>::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<void> 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<void>::slot_type slot_type;
        boost::signals::connection fileChanged(slot_type const &);
 
        /// equivalent to dynamic_cast