]> git.lyx.org Git - features.git/commitdiff
Remove the inset and view member functions from PreviewedInset.
authorAngus Leeming <leeming@lyx.org>
Thu, 9 Oct 2003 19:27:07 +0000 (19:27 +0000)
committerAngus Leeming <leeming@lyx.org>
Thu, 9 Oct 2003 19:27:07 +0000 (19:27 +0000)
Ensuing changes elsewhere.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7887 a592a061-630c-0410-9148-cb99ea01b6c8

13 files changed:
src/graphics/ChangeLog
src/graphics/PreviewedInset.C
src/graphics/PreviewedInset.h
src/insets/ChangeLog
src/insets/insetexternal.C
src/insets/insetexternal.h
src/insets/insetgraphics.C
src/insets/insetgraphics.h
src/insets/insetinclude.C
src/insets/insetinclude.h
src/mathed/ChangeLog
src/mathed/formula.C
src/mathed/formula.h

index 7234e7f4169284bfcc80ffab79461627495ee4e5..9841e1049ebfe25aa68d2a07370c7de175872c2d 100644 (file)
@@ -1,3 +1,11 @@
+2003-10-09  Angus Leeming  <leeming@lyx.org>
+
+       * PreviewedInset.[Ch]: move PreviewedInset out of namespace lyx::graphics.
+       Remove the inset and view member functions.
+       Add a new connect member function and preview_ready_signal_ member
+       variable, to enable the class to tell an arbirary connectee that the
+       preview is ready.
+
 2003-10-09  Angus Leeming  <leeming@lyx.org>
 
        * PreviewedInset.[Ch] (removePreview, previewReady): these functions
index e2ca9a98296f22dfefa60e38bf1ff7264fd96fbf..39a078cf8efb530fc9c06c8733abc176a4234ac0 100644 (file)
 #include "PreviewLoader.h"
 #include "Previews.h"
 
-#include "BufferView.h"
-
-#include "insets/inset.h"
-
 #include "support/lstrings.h"
 
 #include <boost/bind.hpp>
 
-namespace support = lyx::support;
-
+namespace graphics = lyx::graphics;
+namespace support  = lyx::support;
 
-namespace lyx {
-namespace graphics {
 
 bool PreviewedInset::activated()
 {
-       return Previews::activated();
+       return graphics::Previews::activated();
 }
 
 
-PreviewedInset::PreviewedInset(InsetOld & inset)
-       : inset_(inset), pimage_(0)
+PreviewedInset::PreviewedInset()
+       : pimage_(0)
 {}
 
 
-BufferView * PreviewedInset::view() const
+boost::signals::connection PreviewedInset::connect(slot_type const & slot)
 {
-       return inset_.view();
+       return preview_ready_signal_.connect(slot);
 }
 
 
 void PreviewedInset::generatePreview(Buffer const & buffer)
 {
-       if (!Previews::activated() || !previewWanted(buffer))
+       if (!activated() || !previewWanted(buffer))
                return;
 
-       Previews & previews = Previews::get();
-       PreviewLoader & loader = previews.loader(buffer);
+       graphics::Previews & previews = graphics::Previews::get();
+       graphics::PreviewLoader & loader = previews.loader(buffer);
        addPreview(loader);
        if (!snippet_.empty())
                loader.startLoading();
 }
 
 
-void PreviewedInset::addPreview(PreviewLoader & ploader)
+void PreviewedInset::addPreview(graphics::PreviewLoader & ploader)
 {
-       if (!Previews::activated() || !previewWanted(ploader.buffer()))
+       if (!activated() || !previewWanted(ploader.buffer()))
                return;
 
        snippet_ = support::trim(latexString(ploader.buffer()));
@@ -89,8 +83,8 @@ void PreviewedInset::removePreview(Buffer const & buffer)
        if (snippet_.empty())
                return;
 
-       Previews & previews = Previews::get();
-       PreviewLoader & loader = previews.loader(buffer);
+       graphics::Previews & previews = graphics::Previews::get();
+       graphics::PreviewLoader & loader = previews.loader(buffer);
        loader.remove(snippet_);
        snippet_.erase();
        pimage_ = 0;
@@ -99,11 +93,12 @@ void PreviewedInset::removePreview(Buffer const & buffer)
 
 bool PreviewedInset::previewReady(Buffer const & buffer) const
 {
-       if (!Previews::activated() || !previewWanted(buffer))
+       if (!activated() || !previewWanted(buffer))
                return false;
 
        if (!pimage_ || snippet_ != pimage_->snippet()) {
-               PreviewLoader & ploader = Previews::get().loader(buffer);
+               graphics::PreviewLoader & ploader =
+                       graphics::Previews::get().loader(buffer);
                pimage_ = ploader.preview(snippet_);
        }
 
@@ -111,17 +106,12 @@ bool PreviewedInset::previewReady(Buffer const & buffer) const
 }
 
 
-void PreviewedInset::imageReady(PreviewImage const & pimage) const
+void PreviewedInset::imageReady(graphics::PreviewImage const & pimage) const
 {
        // Check the current snippet is the same as that previewed.
        if (snippet_ != pimage.snippet())
                return;
 
        pimage_ = &pimage;
-
-       if (view())
-               view()->updateInset(&inset());
+       preview_ready_signal_();
 }
-
-} // namespace graphics
-} // namespace lyx
index 03e7df730d3da62d98ba623e2d6f47acd797b5cf..ee05138b63788e630db873e182df2b4b529a2190 100644 (file)
 #ifndef PREVIEWEDINSET_H
 #define PREVIEWEDINSET_H
 
+#include <boost/signals/signal0.hpp>
 #include <boost/signals/trackable.hpp>
 #include <boost/signals/connection.hpp>
 
 class Buffer;
 class BufferView;
-class InsetOld;
 
 
 namespace lyx {
@@ -30,13 +30,16 @@ namespace graphics {
 class PreviewImage;
 class PreviewLoader;
 
+} // namespace graphics
+} // namespace lyx
+
 class PreviewedInset : public boost::signals::trackable {
 public:
        /// a wrapper for Previews::activated()
        static bool activated();
 
        ///
-       PreviewedInset(InsetOld & inset);
+       PreviewedInset();
 
        /** Find the PreviewLoader, add a LaTeX snippet to it and
         *  start the loading process.
@@ -46,7 +49,7 @@ public:
        /** Add a LaTeX snippet to the PreviewLoader but do not start the
         *  loading process.
         */
-       void addPreview(PreviewLoader & ploader);
+       void addPreview(lyx::graphics::PreviewLoader & ploader);
 
        /** Remove a snippet from the cache of previews.
         *  Useful if previewing the contents of a file that has changed.
@@ -56,54 +59,39 @@ public:
        /// The preview has been generated and is ready to use.
        bool previewReady(Buffer const &) const;
 
-       /// If !previewReady() returns 0.
-       PreviewImage const * pimage() const;
+       /// If the preview is not ready, returns 0.
+       lyx::graphics::PreviewImage const * const pimage() const { return pimage_; }
+
+       /// 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 &);
 
 protected:
        ///
        virtual ~PreviewedInset() {}
-       /// Allow the daughter classes to cast up to the parent inset.
-       InsetOld const & inset() const;
-       ///
-       BufferView * view() const;
 
 private:
        /// This method is connected to the PreviewLoader::imageReady signal.
-       void imageReady(PreviewImage const &) const;
+       void imageReady(lyx::graphics::PreviewImage const &) const;
 
        /// Does the owning inset want a preview?
        virtual bool previewWanted(Buffer const &) const = 0;
        /// a wrapper to Inset::latex
        virtual std::string const latexString(Buffer const &) const = 0;
 
-       ///
-       InsetOld & inset_;
-       ///
+       /// The thing that we're trying to generate a preview of.
        std::string snippet_;
 
        /// We don't own this. Cached for efficiency reasons.
-       mutable PreviewImage const * pimage_;
+       mutable lyx::graphics::PreviewImage const * pimage_;
+
        /** Store the connection to the preview loader so that we connect
         *  only once.
         */
        boost::signals::connection ploader_connection_;
-};
-
-
-inline
-PreviewImage const * PreviewedInset::pimage() const
-{
-       return pimage_;
-}
-
 
-inline
-InsetOld const & PreviewedInset::inset() const
-{
-       return inset_;
-}
-
-} // namespace graphics
-} // namespace lyx
+       /// This signal is emitted when the preview is ready for display.
+       boost::signal0<void> preview_ready_signal_;
+};
 
 #endif // PREVIEWEDINSET_H
index f1f984b539c24225138a1367c152716c819dbd7b..32ebf45e50129200a47a82513c1a76cfaba7b621 100644 (file)
@@ -1,3 +1,11 @@
+2003-10-09  Angus Leeming  <leeming@lyx.org>
+
+       * insetexternal.[Ch] (statusChanged):
+       * insetgraphics.[Ch] (statusChanged): make a const member function.
+
+       * insetinclude.[Ch]: mods to PreviewImpl due to the changes to
+       PreviewedInset.
+       
 2003-10-09  Angus Leeming  <leeming@lyx.org>
 
        * insetinclude.C (metrics, draw, restartLoading): pass a buffer arg
index 08f4a4f2406646d71121c93f4231aa7b53db8e1b..89e2ca9c6108067cee3914dc1ea99ae329a722e7 100644 (file)
@@ -387,7 +387,7 @@ InsetExternal::~InsetExternal()
 }
 
 
-void InsetExternal::statusChanged()
+void InsetExternal::statusChanged() const
 {
        BufferView * const bv = renderer_->view();
        if (bv)
index 0c700b30f4d43110d05e45b3c9d377503bcd1d80..408848132f4e0e1754541d6ab4496a3239e6cce4 100644 (file)
@@ -131,7 +131,7 @@ private:
        /** This method is connected to the graphics loader, so we are
         *  informed when the image has been loaded.
         */
-       void statusChanged();
+       void statusChanged() const;
 
        /// The current params
        InsetExternalParams params_;
index 5c1164c254aeff4ae83749ab5c64b7354ab6e70e..db63aaba09893bb1e210c225fb518519efe21c6c 100644 (file)
@@ -181,7 +181,7 @@ InsetGraphics::~InsetGraphics()
 }
 
 
-void InsetGraphics::statusChanged()
+void InsetGraphics::statusChanged() const
 {
        BufferView * bv = graphic_->view();
        if (bv)
index 6ac5f21424e8aa62e9d98875aeef0bf76f7ff2c4..e9de865a1904a57b8546e9bedd5c94af4d68f8a5 100644 (file)
@@ -85,7 +85,7 @@ private:
        /** This method is connected to the graphics loader, so we are
         *  informed when the image has been loaded.
         */
-       void statusChanged();
+       void statusChanged() const;
 
        /// Read the inset native format
        void readInsetGraphics(LyXLex & lex, std::string const & bufpath);
index c27daa8a51944e78aab9ac2868d7c1d4f129914d..24e75ddfc7e6fac7831ae1cd77da0c7ac43002f4 100644 (file)
@@ -65,20 +65,16 @@ using std::ostringstream;
 extern BufferList bufferlist;
 
 
-class InsetInclude::PreviewImpl : public lyx::graphics::PreviewedInset {
+class InsetInclude::PreviewImpl : public PreviewedInset {
 public:
        ///
-       PreviewImpl(InsetInclude & p) : PreviewedInset(p) {}
+       PreviewImpl(InsetInclude const & p) : parent_(p) {}
 
        ///
        bool previewWanted(Buffer const &) const;
        ///
        string const latexString(Buffer const &) const;
        ///
-       InsetInclude const & parent() const {
-               return dynamic_cast<InsetInclude const &>(inset());
-       }
-
        ///
        bool monitoring() const { return monitor_.get(); }
        ///
@@ -91,6 +87,8 @@ private:
        void restartLoading();
        ///
        boost::scoped_ptr<FileMonitor> monitor_;
+       ///
+       InsetInclude const & parent_;
 };
 
 
@@ -109,7 +107,9 @@ InsetInclude::InsetInclude(InsetCommandParams const & p)
        : params_(p), include_label(uniqueID()),
          preview_(new PreviewImpl(*this)),
          set_label_(false)
-{}
+{
+       preview_->connect(boost::bind(&InsetInclude::statusChanged, this));
+}
 
 
 InsetInclude::InsetInclude(InsetInclude const & other)
@@ -118,7 +118,9 @@ InsetInclude::InsetInclude(InsetInclude const & other)
          include_label(other.include_label),
          preview_(new PreviewImpl(*this)),
          set_label_(other.set_label_)
-{}
+{
+       preview_->connect(boost::bind(&InsetInclude::statusChanged, this));
+}
 
 
 InsetInclude::~InsetInclude()
@@ -195,7 +197,7 @@ Types type(InsetCommandParams const & params)
 bool isVerbatim(InsetCommandParams const & params)
 {
        string const command_name = params.getCmdName();
-       return command_name == "verbatiminput" ||
+       return command_name == "verbatiminput" || 
                command_name == "verbatiminput*";
 }
 
@@ -210,8 +212,7 @@ void InsetInclude::set(InsetCommandParams const & p, Buffer const & buffer)
        if (preview_->monitoring())
                preview_->stopMonitoring();
 
-       if (lyx::graphics::PreviewedInset::activated() &&
-           type(params_) == INPUT)
+       if (PreviewedInset::activated() && type(params_) == INPUT)
                preview_->generatePreview(buffer);
 }
 
@@ -593,6 +594,13 @@ BufferView * InsetInclude::view() const
 // preview stuff
 //
 
+void InsetInclude::statusChanged() const
+{
+       if (view())
+               view()->updateInset(this);
+}
+
+
 void InsetInclude::addPreview(lyx::graphics::PreviewLoader & ploader) const
 {
        preview_->addPreview(ploader);
@@ -601,10 +609,10 @@ void InsetInclude::addPreview(lyx::graphics::PreviewLoader & ploader) const
 
 bool InsetInclude::PreviewImpl::previewWanted(Buffer const & buffer) const
 {
-       string const included_file = includedFilename(buffer, parent().params());
+       string const included_file = includedFilename(buffer, parent_.params());
 
-       return type(parent().params_) == INPUT &&
-               parent().params_.preview() &&
+       return type(parent_.params_) == INPUT &&
+               parent_.params_.preview() &&
                IsFileReadable(included_file);
 }
 
@@ -614,7 +622,7 @@ string const InsetInclude::PreviewImpl::latexString(Buffer const & buffer) const
        ostringstream os;
        LatexRunParams runparams;
        runparams.flavor = LatexRunParams::LATEX;
-       parent().latex(buffer, os, runparams);
+       parent_.latex(buffer, os, runparams);
 
        return os.str();
 }
@@ -630,11 +638,12 @@ void InsetInclude::PreviewImpl::startMonitoring(string const & file)
 
 void InsetInclude::PreviewImpl::restartLoading()
 {
-       if (!view())
+       BufferView * const view = parent_.view();
+       if (!view)
                return;
-       view()->updateInset(&parent());
-       if (view()->buffer()) {
-               Buffer const & buffer = *view()->buffer();
+       view->updateInset(&parent_);
+       if (view->buffer()) {
+               Buffer const & buffer = *view->buffer();
                removePreview(buffer);
                generatePreview(buffer);
        }
index 27b4a551ac42719545d4ec11f59fdfce2ff7c394..127babff59c8332fd1bef24ed99b6d8813e490b1 100644 (file)
@@ -83,6 +83,9 @@ public:
        void addPreview(lyx::graphics::PreviewLoader &) const;
 
 private:
+       /// Slot receiving a signal that the preview is ready to display.
+       void statusChanged() const;
+       
        friend class InsetIncludeMailer;
 
        /// set the parameters
index 7c0637f8c13993d89b33a418ba4efaa6c804bdfb..eecd49f19ccd78425a94c5b24234cb72a30dee32 100644 (file)
@@ -1,3 +1,8 @@
+2003-10-09  Angus Leeming  <leeming@lyx.org>
+
+       * formula.[Ch]: mods to PreviewImpl due to the changes to
+       PreviewedInset.
+       
 2003-10-09  Angus Leeming  <leeming@lyx.org>
 
        * formula.C (metrics, draw): pass a buffer arg to PreviewedInset's
index 47e0a8233780720e32a6a035cc5eb3715c768252..e739e16d7b80016f3352c215ecaef997a0ccfbdb 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "support/std_sstream.h"
 
+#include <boost/bind.hpp>
 
 using std::string;
 using std::ostream;
@@ -39,10 +40,10 @@ using std::auto_ptr;
 using std::endl;
 
 
-class InsetFormula::PreviewImpl : public lyx::graphics::PreviewedInset {
+class InsetFormula::PreviewImpl : public PreviewedInset {
 public:
        ///
-       PreviewImpl(InsetFormula & p) : PreviewedInset(p) {}
+       PreviewImpl(InsetFormula const & p) : parent_(p) {}
 
 private:
        ///
@@ -50,18 +51,15 @@ private:
        ///
        string const latexString(Buffer const &) const;
        ///
-       InsetFormula const & parent() const
-       {
-               return dynamic_cast<InsetFormula const &>(inset());
-       }
+       InsetFormula const & parent_;
 };
 
 
-
 InsetFormula::InsetFormula(bool chemistry)
        : par_(MathAtom(new MathHullInset)),
          preview_(new PreviewImpl(*this))
 {
+       preview_->connect(boost::bind(&InsetFormula::statusChanged, this));
        if (chemistry)
                mutate("chemistry");
 }
@@ -71,14 +69,16 @@ InsetFormula::InsetFormula(InsetFormula const & other)
        : InsetFormulaBase(other),
          par_(other.par_),
          preview_(new PreviewImpl(*this))
-{}
+{
+       preview_->connect(boost::bind(&InsetFormula::statusChanged, this));
+}
 
 
 InsetFormula::InsetFormula(BufferView *)
        : par_(MathAtom(new MathHullInset)),
          preview_(new PreviewImpl(*this))
 {
-       //view_ = bv->owner()->view();
+       preview_->connect(boost::bind(&InsetFormula::statusChanged, this));
 }
 
 
@@ -86,6 +86,7 @@ InsetFormula::InsetFormula(string const & data)
        : par_(MathAtom(new MathHullInset)),
          preview_(new PreviewImpl(*this))
 {
+       preview_->connect(boost::bind(&InsetFormula::statusChanged, this));
        if (!data.size())
                return;
        if (!mathed_parse_normal(par_, data))
@@ -93,7 +94,6 @@ InsetFormula::InsetFormula(string const & data)
 }
 
 
-
 InsetFormula::~InsetFormula()
 {}
 
@@ -300,6 +300,13 @@ void InsetFormula::mutate(string const & type)
 // preview stuff
 //
 
+void InsetFormula::statusChanged() const
+{
+       if (view())
+               view()->updateInset(this);
+}
+
+
 void InsetFormula::addPreview(lyx::graphics::PreviewLoader & ploader) const
 {
        preview_->addPreview(ploader);
@@ -314,7 +321,7 @@ void InsetFormula::generatePreview(Buffer const & buffer) const
 
 bool InsetFormula::PreviewImpl::previewWanted(Buffer const &) const
 {
-       return !parent().par_->asNestInset()->editing();
+       return !parent_.par_->asNestInset()->editing();
 }
 
 
@@ -322,6 +329,6 @@ string const InsetFormula::PreviewImpl::latexString(Buffer const &) const
 {
        ostringstream ls;
        WriteStream wi(ls, false, false);
-       parent().par_->write(wi);
+       parent_.par_->write(wi);
        return ls.str();
 }
index 14c650e301d63f1d83b50c7b65a86dfa8062b3c7..927d3512c3f312d2fe30d178bdd0fbe1d44325be 100644 (file)
@@ -74,6 +74,8 @@ public:
        void mutate(std::string const & type);
 
 private:
+       /// Slot receiving a signal that the preview is ready to display.
+       void statusChanged() const;
        /// available in AMS only?
        bool ams() const;