]> git.lyx.org Git - features.git/commitdiff
* Mathed now caches the BufferView as a weak_ptr.
authorAngus Leeming <leeming@lyx.org>
Fri, 2 Aug 2002 12:38:20 +0000 (12:38 +0000)
committerAngus Leeming <leeming@lyx.org>
Fri, 2 Aug 2002 12:38:20 +0000 (12:38 +0000)
* PreviewedInset caches the LaTeX snippet.
* Further clean-up of mathed's preview code.

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

src/graphics/ChangeLog
src/graphics/PreviewedInset.C
src/graphics/PreviewedInset.h
src/mathed/ChangeLog
src/mathed/formula.C
src/mathed/formulabase.C
src/mathed/formulabase.h
src/mathed/math_metricsinfo.C
src/mathed/math_metricsinfo.h
src/mathed/math_nestinset.C

index f32a45eb877851f47e7b17d08a341a1fff653c84..df1936d610826c3fe50d2a14aca9fcb294b9d8f3 100644 (file)
@@ -1,3 +1,7 @@
+2002-08-02  Angus Leeming  <leeming@lyx.org>
+
+       * PreviewedInset.[Ch]: cache the LaTeX snippet.
+
 2002-08-01  Angus Leeming  <leeming@lyx.org>
 
        * PreviewedInset.[Ch]: new files. An abstract base class that can help
index a5ccfa2ca24f9fdf17b9a21f0bab05540777ea17..1350396f6f03278dce53ad834ca207298405da44 100644 (file)
@@ -33,7 +33,7 @@ bool PreviewedInset::activated()
 }
 
 
-void PreviewedInset::generatePreview() const
+void PreviewedInset::generatePreview()
 {
        if (!Previews::activated() || !previewWanted() ||
            !view() || !view()->buffer())
@@ -46,15 +46,14 @@ void PreviewedInset::generatePreview() const
 }
 
 
-void PreviewedInset::addPreview(grfx::PreviewLoader & ploader) const
+void PreviewedInset::addPreview(grfx::PreviewLoader & ploader)
 {
        if (!Previews::activated() || !previewWanted())
                return;
 
-       // Generate the LaTeX snippet.
-       string const snippet = latexString();
+       snippet_ = latexString();
 
-       pimage_ = ploader.preview(snippet);
+       pimage_ = ploader.preview(snippet_);
        if (pimage_)
                return;
 
@@ -66,7 +65,7 @@ void PreviewedInset::addPreview(grfx::PreviewLoader & ploader) const
                        boost::bind(&PreviewedInset::imageReady, this, _1));
        }
 
-       ploader.add(snippet);
+       ploader.add(snippet_);
 }
 
 
@@ -76,13 +75,10 @@ bool PreviewedInset::previewReady() const
            !view() || !view()->buffer())
                return false;
 
-       // If the cached grfx::PreviewImage is invalid, update it.
-       string const snippet = latexString();
-
-       if (!pimage_ || snippet != pimage_->snippet()) {
+       if (!pimage_ || snippet_ != pimage_->snippet()) {
                grfx::PreviewLoader & ploader =
                        grfx::Previews::get().loader(view()->buffer());
-               pimage_ = ploader.preview(snippet);
+               pimage_ = ploader.preview(snippet_);
        }
 
        if (!pimage_)
@@ -95,7 +91,7 @@ bool PreviewedInset::previewReady() const
 void PreviewedInset::imageReady(grfx::PreviewImage const & pimage) const
 {
        // Check snippet against the Inset's current contents
-       if (latexString() != pimage.snippet())
+       if (snippet_ != pimage.snippet())
                return;
 
        pimage_ = &pimage;
index 4ab1ecda9a11d5723e2e3103057997dfd18ff994..87baa3b9d978cc6cb2c9c046d6d0ec114995dd66 100644 (file)
@@ -41,12 +41,12 @@ public:
        /** Find the PreviewLoader, add a LaTeX snippet to it and
         *  start the loading process.
         */
-       void generatePreview() const;
+       void generatePreview();
 
        /** Add a LaTeX snippet to the PreviewLoader but do not start the
         *  loading process.
         */
-       void addPreview(PreviewLoader & ploader) const;
+       void addPreview(PreviewLoader & ploader);
 
        /// The preview has been generated and is ready to use.
        bool previewReady() const;
@@ -73,10 +73,12 @@ private:
 
        ///
        Inset & inset_;
-       /// We don't own this
+       ///
+       string snippet_;
+       /// We don't own this. Cached for efficiency reasons.
        mutable PreviewImage const * pimage_;
        ///
-       mutable boost::signals::connection connection_;
+       boost::signals::connection connection_;
 };
 
 } // namespace grfx
index b3ffc3a4359e0a1fff5014b1bc05feee990b0da5..c17805e5d40766bcead0b1afff6c893d16ae273c 100644 (file)
@@ -1,3 +1,18 @@
+2002-08-02  Angus Leeming  <leeming@lyx.org>
+
+       * formulabase.[Ch]: store the BufferView as a weak_ptr.
+       (updatePreview): removed.
+       (insetUnlock): invoke generatePreview().
+
+       * formula.C (InsetFormula): pass the shared_ptr to view_, not the raw
+       BufferView.
+       (read, localDispatch): remove those calls to updatePreview().
+
+       * math_metricsinfo.[Ch]: store the BufferView as a weak_ptr.
+
+       * math_nestinset.C (notifyCursorLeaves): empty, because
+       generatePreview() is now called from InsetFormulaBase::insetUnlock.
+
 2002-08-01  Angus Leeming  <leeming@lyx.org>
 
        * formula.C: move code into the new PreviewedInset class.
index 34ff4820aabadb6c6b56da4a7d773009e82037f2..9d71398d28bef001e3e9daa682e242be74c0497e 100644 (file)
@@ -103,7 +103,7 @@ InsetFormula::InsetFormula(BufferView * bv)
        : par_(MathAtom(new MathHullInset)),
          preview_(new PreviewImpl(*this))
 {
-       view_ = bv;
+       view_ = bv->owner()->view();
 }
 
 
@@ -191,7 +191,6 @@ void InsetFormula::read(Buffer const *, LyXLex & lex)
 {
        mathed_parse_normal(par_, lex);
        metrics();
-       updatePreview();
 }
 
 
@@ -207,6 +206,7 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & font,
 {
        // This initiates the loading of the preview, so should come
        // before the metrics are computed.
+       view_ = bv->owner()->view();
        bool const use_preview = preview_->previewReady();
 
        int const x = int(xx);
@@ -390,8 +390,6 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
                        result = InsetFormulaBase::localDispatch(bv, action, arg);
        }
 
-       //updatePreview();
-
        return result;
 }
 
index 1fc4ff5a75c81492ee9763e33706bc35ffe2ad6e..4d7c4ab61bccde875a6add9dbb96c9e34ef9a2c7 100644 (file)
@@ -89,7 +89,7 @@ bool openNewInset(BufferView * bv, UpdatableInset * new_inset)
 
 
 InsetFormulaBase::InsetFormulaBase()
-       : view_(0), font_(), xo_(0), yo_(0)
+       : font_(), xo_(0), yo_(0)
 {
        // This is needed as long the math parser is not re-entrant
        initMath();
@@ -151,7 +151,7 @@ void InsetFormulaBase::metrics(BufferView * bv, LyXFont const & f) const
 void InsetFormulaBase::metrics(BufferView * bv) const
 {
        if (bv)
-               view_ = bv;
+               view_ = bv->owner()->view();
        MathMetricsInfo mi;
        mi.view       = view_;
        //mi.base.style = display() ? LM_ST_DISPLAY : LM_ST_TEXT;
@@ -204,6 +204,7 @@ void InsetFormulaBase::insetUnlock(BufferView * bv)
                }
                releaseMathCursor(bv);
        }
+       generatePreview();
        bv->updateInset(this, false);
 }
 
@@ -836,13 +837,13 @@ Inset::Code InsetFormulaBase::lyxCode() const
 
 int InsetFormulaBase::ylow() const
 {
-       return yo_ - ascent(view_, font_);
+       return yo_ - ascent(view(), font_);
 }
 
 
 int InsetFormulaBase::yhigh() const
 {
-       return yo_ + descent(view_, font_);
+       return yo_ + descent(view(), font_);
 }
 
 
@@ -854,7 +855,7 @@ int InsetFormulaBase::xlow() const
 
 int InsetFormulaBase::xhigh() const
 {
-       return xo_ + width(view_, font_);
+       return xo_ + width(view(), font_);
 }
 
 
index 02366a13e15b4af5dc20b7d45f4d25dc0133c682..205f894ed0703a0c90bf5f43b9cd9969df542210 100644 (file)
@@ -23,6 +23,8 @@
 #include "frontends/mouse_state.h"
 #include "lyxfont.h"
 
+#include <boost/weak_ptr.hpp>
+
 #include <iosfwd>
 
 class Buffer;
@@ -99,7 +101,7 @@ public:
        ///
        virtual void updateLocal(BufferView * bv, bool mark_dirty);
        ///
-       BufferView * view() const { return view_; }
+       BufferView * view() const { return view_.get(); }
 
        ///
        virtual bool searchForward(BufferView *, string const &,
@@ -115,9 +117,6 @@ public:
        virtual void revealCodes(BufferView *) const;
        ///
        virtual Inset::EDITABLE editable() const { return HIGHLY_EDITABLE; }
-       ///
-       virtual void updatePreview() {}
-
 
 private:
        /// unimplemented
@@ -127,7 +126,7 @@ private:
 
 protected:
        ///
-       mutable BufferView * view_;
+       mutable boost::weak_ptr<BufferView> view_;
        ///
        mutable LyXFont font_;
 
index 90d553c6f08c83299c917bd18407453bb1e9da7f..10e2e195f98923a9e7df4e0eb91f7312682f7cf6 100644 (file)
@@ -16,7 +16,7 @@ MathMetricsBase::MathMetricsBase()
 
 
 MathMetricsInfo::MathMetricsInfo()
-       : view(0), fullredraw(false)
+       : fullredraw(false)
 {}
 
 
index f4d6ab6275d06a309d7e5548ad891935ff11058d..54202829fed721ad051364d0bb5be08db6107286 100644 (file)
@@ -4,6 +4,8 @@
 #include "lyxfont.h"
 #include "LString.h"
 
+#include <boost/weak_ptr.hpp>
+
 class BufferView;
 class Painter;
 class MathNestInset;
@@ -46,7 +48,7 @@ struct MathMetricsInfo {
        ///
        MathMetricsBase base;
        ///
-       BufferView * view;
+       boost::weak_ptr<BufferView> view;
        ///
        bool fullredraw;
 };
index 9a90a9462ce074b819b6d90ea1da5e104adef943..91d84fd674da98ba8fd8ff4bf3640c10f25ec36e 100644 (file)
@@ -319,11 +319,4 @@ void MathNestInset::normalize(NormalStream & os) const
 
 
 void MathNestInset::notifyCursorLeaves()
-{
-       // Generate a preview only if we are leaving the InsetFormula itself
-       if (!mathcursor || mathcursor->depth() != 1)
-               return;
-
-       InsetFormulaBase * inset = mathcursor->formula();
-       inset->generatePreview();
-}
+{}