]> git.lyx.org Git - features.git/commitdiff
Put mathed on a diet: transfer dimension cache from inset to BufferView.
authorAbdelrazak Younes <younes@lyx.org>
Sun, 23 Sep 2007 22:39:49 +0000 (22:39 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sun, 23 Sep 2007 22:39:49 +0000 (22:39 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20457 a592a061-630c-0410-9148-cb99ea01b6c8

62 files changed:
src/CoordCache.cpp
src/CoordCache.h
src/Cursor.cpp
src/insets/Inset.cpp
src/insets/Inset.h
src/insets/InsetSpecialChar.cpp
src/mathed/CommandInset.cpp
src/mathed/InsetMathAMSArray.cpp
src/mathed/InsetMathAMSArray.h
src/mathed/InsetMathArray.cpp
src/mathed/InsetMathArray.h
src/mathed/InsetMathBig.h
src/mathed/InsetMathBinom.cpp
src/mathed/InsetMathBinom.h
src/mathed/InsetMathBoldSymbol.cpp
src/mathed/InsetMathBox.cpp
src/mathed/InsetMathBoxed.cpp
src/mathed/InsetMathBrace.cpp
src/mathed/InsetMathCases.cpp
src/mathed/InsetMathCases.h
src/mathed/InsetMathChar.cpp
src/mathed/InsetMathChar.h
src/mathed/InsetMathColor.cpp
src/mathed/InsetMathComment.cpp
src/mathed/InsetMathDFrac.cpp
src/mathed/InsetMathDecoration.cpp
src/mathed/InsetMathDelim.cpp
src/mathed/InsetMathDots.cpp
src/mathed/InsetMathDots.h
src/mathed/InsetMathEnv.cpp
src/mathed/InsetMathExFunc.cpp
src/mathed/InsetMathFBox.cpp
src/mathed/InsetMathFont.cpp
src/mathed/InsetMathFontOld.cpp
src/mathed/InsetMathFrac.cpp
src/mathed/InsetMathFrameBox.cpp
src/mathed/InsetMathGrid.cpp
src/mathed/InsetMathGrid.h
src/mathed/InsetMathHull.cpp
src/mathed/InsetMathLefteqn.cpp
src/mathed/InsetMathMakebox.cpp
src/mathed/InsetMathNest.h
src/mathed/InsetMathOverset.cpp
src/mathed/InsetMathPar.cpp
src/mathed/InsetMathPhantom.cpp
src/mathed/InsetMathRoot.cpp
src/mathed/InsetMathScript.cpp
src/mathed/InsetMathScript.h
src/mathed/InsetMathSize.cpp
src/mathed/InsetMathSqrt.cpp
src/mathed/InsetMathStackrel.cpp
src/mathed/InsetMathSubstack.cpp
src/mathed/InsetMathSymbol.cpp
src/mathed/InsetMathSymbol.h
src/mathed/InsetMathTFrac.cpp
src/mathed/InsetMathTabular.cpp
src/mathed/InsetMathTabular.h
src/mathed/InsetMathUnderset.cpp
src/mathed/InsetMathXArrow.cpp
src/mathed/InsetMathXYMatrix.cpp
src/mathed/MathMacro.cpp
src/mathed/MathMacroTemplate.cpp

index 38baabf80581dac1f6a90966441b4344f08447d2..5be3a50f0696343ba8ecc2a0ddce0afa5bdba6b4 100644 (file)
@@ -43,8 +43,6 @@ void CoordCache::clear()
 {
        arrays_.clear();
        insets_.clear();
 {
        arrays_.clear();
        insets_.clear();
-       slices0_.clear();
-       slices1_.clear();
 }
 
 
 }
 
 
@@ -53,7 +51,7 @@ void CoordCache::dump() const
        lyxerr << "InsetCache contains:" << std::endl;
        for (CoordCacheBase<Inset>::cache_type::const_iterator it = getInsets().getData().begin(); it != getInsets().getData().end(); ++it) {
                Inset const * inset = it->first;
        lyxerr << "InsetCache contains:" << std::endl;
        for (CoordCacheBase<Inset>::cache_type::const_iterator it = getInsets().getData().begin(); it != getInsets().getData().end(); ++it) {
                Inset const * inset = it->first;
-               Point const p = it->second;
+               Point const p = it->second.pos;
                lyxerr << "Inset " << inset << "(" << to_utf8(inset->name())
                        << ") has point " << p.x_ << "," << p.y_ << std::endl;
        }
                lyxerr << "Inset " << inset << "(" << to_utf8(inset->name())
                        << ") has point " << p.x_ << "," << p.y_ << std::endl;
        }
index 296de324e94b61b74a877f054913f69be11ec90a..a93696df1e7a9dd0cbd4021b82957d5722ad9985 100644 (file)
@@ -14,6 +14,8 @@
 // It seems that MacOSX define the check macro.
 #undef check
 
 // It seems that MacOSX define the check macro.
 #undef check
 
+#include "Dimension.h"
+
 #include "support/types.h"
 
 #include <map>
 #include "support/types.h"
 
 #include <map>
@@ -38,6 +40,13 @@ public:
        int x_, y_;
 };
 
        int x_, y_;
 };
 
+
+struct Geometry {
+       Point pos;
+       Dimension dim;
+};
+
+
 template <class T> class CoordCacheBase {
 public:
        void clear()
 template <class T> class CoordCacheBase {
 public:
        void clear()
@@ -52,25 +61,36 @@ public:
 
        void add(T const * thing, int x, int y)
        {
 
        void add(T const * thing, int x, int y)
        {
-               data_[thing] = Point(x, y);
+               data_[thing].pos = Point(x, y);
+       }
+
+       void add(T const * thing, Dimension const & dim)
+       {
+               data_[thing].dim = dim;
+       }
+
+       Dimension const & dim(T const * thing) const
+       {
+               //check(thing, "dim");
+               return data_.find(thing)->second.dim;
        }
 
        int x(T const * thing) const
        {
                check(thing, "x");
        }
 
        int x(T const * thing) const
        {
                check(thing, "x");
-               return data_.find(thing)->second.x_;
+               return data_.find(thing)->second.pos.x_;
        }
 
        int y(T const * thing) const
        {
                check(thing, "y");
        }
 
        int y(T const * thing) const
        {
                check(thing, "y");
-               return data_.find(thing)->second.y_;
+               return data_.find(thing)->second.pos.y_;
        }
 
        Point xy(T const * thing) const
        {
                check(thing, "xy");
        }
 
        Point xy(T const * thing) const
        {
                check(thing, "xy");
-               return data_.find(thing)->second;
+               return data_.find(thing)->second.pos;
        }
 
        bool has(T const * thing) const
        }
 
        bool has(T const * thing) const
@@ -93,7 +113,7 @@ private:
                        lyxbreaker(thing, hint, data_.size());
        }
 
                        lyxbreaker(thing, hint, data_.size());
        }
 
-       typedef std::map<T const *, Point> cache_type;
+       typedef std::map<T const *, Geometry> cache_type;
        cache_type data_;
 
 public:
        cache_type data_;
 
 public:
@@ -114,26 +134,12 @@ class CoordCache {
 public:
        void clear();
 
 public:
        void clear();
 
-       /// A map from paragraph index number to screen point
-       typedef std::map<pit_type, Point> InnerParPosCache;
-       /// A map from a CursorSlice to screen points
-       typedef std::map<Text const *, InnerParPosCache> SliceCache;
-
        /// A map from MathData to position on the screen
        CoordCacheBase<MathData> & arrays() { return arrays_; }
        CoordCacheBase<MathData> const & getArrays() const { return arrays_; }
        /// A map from insets to positions on the screen
        CoordCacheBase<Inset> & insets() { return insets_; }
        CoordCacheBase<Inset> const & getInsets() const { return insets_; }
        /// A map from MathData to position on the screen
        CoordCacheBase<MathData> & arrays() { return arrays_; }
        CoordCacheBase<MathData> const & getArrays() const { return arrays_; }
        /// A map from insets to positions on the screen
        CoordCacheBase<Inset> & insets() { return insets_; }
        CoordCacheBase<Inset> const & getInsets() const { return insets_; }
-       ///
-       SliceCache & slice(bool boundary)
-       {
-               return boundary ? slices1_ : slices0_;
-       }
-       SliceCache const & getSlice(bool boundary) const
-       {
-               return boundary ? slices1_ : slices0_;
-       }
 
        /// Dump the contents of the cache to lyxerr in debugging form
        void dump() const;
 
        /// Dump the contents of the cache to lyxerr in debugging form
        void dump() const;
@@ -142,10 +148,6 @@ private:
        CoordCacheBase<MathData> arrays_;
        // All insets
        CoordCacheBase<Inset> insets_;
        CoordCacheBase<MathData> arrays_;
        // All insets
        CoordCacheBase<Inset> insets_;
-       /// Used with boundary == 0
-       SliceCache slices0_;
-       /// Used with boundary == 1
-       SliceCache slices1_;
 };
 
 } // namespace lyx
 };
 
 } // namespace lyx
index 60598573d6432c6f4cebbbb1914f311a180b6a42..285a370b0ef282fd34241e46967faf6b4d81feb5 100644 (file)
@@ -97,9 +97,9 @@ namespace {
                        int xo;
                        int yo;
                        Inset const * inset = &it.inset();
                        int xo;
                        int yo;
                        Inset const * inset = &it.inset();
-                       std::map<Inset const *, Point> const & data =
+                       std::map<Inset const *, Geometry> const & data =
                                c.bv().coordCache().getInsets().getData();
                                c.bv().coordCache().getInsets().getData();
-                       std::map<Inset const *, Point>::const_iterator I = data.find(inset);
+                       std::map<Inset const *, Geometry>::const_iterator I = data.find(inset);
 
                        // FIXME: in the case where the inset is not in the cache, this
                        // means that no part of it is visible on screen. In this case
 
                        // FIXME: in the case where the inset is not in the cache, this
                        // means that no part of it is visible on screen. In this case
@@ -110,7 +110,7 @@ namespace {
                                return it;
                        }
 
                                return it;
                        }
 
-                       Point o = I->second;
+                       Point o = I->second.pos;
                        inset->cursorPos(c.bv(), it.top(), c.boundary(), xo, yo);
                        // Convert to absolute
                        xo += o.x_;
                        inset->cursorPos(c.bv(), it.top(), c.boundary(), xo, yo);
                        // Convert to absolute
                        xo += o.x_;
index 40c3c52bd3e39ce1c9cbbd61038f9c9b3b0ba554..252e399e826ef3e922198f8e078945696caa0c4d 100644 (file)
@@ -36,7 +36,6 @@
 #include "frontends/Painter.h"
 
 #include "support/convert.h"
 #include "frontends/Painter.h"
 
 #include "support/convert.h"
-#include "support/ExceptionMessage.h"
 
 #include <boost/current_function.hpp>
 
 
 #include <boost/current_function.hpp>
 
@@ -123,11 +122,9 @@ Inset::Inset()
 {}
 
 
 {}
 
 
-Dimension const Inset::dimension(BufferView const &) const
+Dimension const Inset::dimension(BufferView const & bv) const
 {
 {
-       docstring const id = convert<docstring>(int(lyxCode())) + " " + name();
-       throw support::ExceptionMessage(support::ErrorException,
-               _("Inset::dimension(): unimplemented method"), id);
+       return bv.coordCache().getInsets().dim(this);
 }
 
 
 }
 
 
@@ -378,6 +375,13 @@ void Inset::setPosCache(PainterInfo const & pi, int x, int y) const
 }
 
 
 }
 
 
+void Inset::setDimCache(MetricsInfo const & mi, Dimension const & dim) const
+{
+       mi.base.bv->coordCache().insets().add(this, dim);
+}
+
+
+
 /////////////////////////////////////////
 
 bool isEditableInset(Inset const * inset)
 /////////////////////////////////////////
 
 bool isEditableInset(Inset const * inset)
index b8b068acfa288d27f5e10ca946edb8724ae52f6d..2090a7e369ae0600a21f1c6d79a28c4d20f5a5e6 100644 (file)
@@ -147,6 +147,8 @@ public:
        int yo(BufferView const & bv) const;
        /// set x/y drawing position cache if available
        virtual void setPosCache(PainterInfo const &, int, int) const;
        int yo(BufferView const & bv) const;
        /// set x/y drawing position cache if available
        virtual void setPosCache(PainterInfo const &, int, int) const;
+       ///
+       void setDimCache(MetricsInfo const &, Dimension const &) const;
        /// do we cover screen position x/y?
        virtual bool covers(BufferView const & bv, int x, int y) const;
        /// get the screen positions of the cursor (see note in Cursor.cpp)
        /// do we cover screen position x/y?
        virtual bool covers(BufferView const & bv, int x, int y) const;
        /// get the screen positions of the cursor (see note in Cursor.cpp)
index 6ced90c05d047332076983b338a544a491af2d21..e1d176638f172d8adfa0ebad4432243ddbcfae82 100644 (file)
@@ -60,6 +60,8 @@ void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.wid = fm.width(ds);
        if (kind_ == HYPHENATION && dim.wid > 5)
                dim.wid -= 2; // to make it look shorter
        dim.wid = fm.width(ds);
        if (kind_ == HYPHENATION && dim.wid > 5)
                dim.wid -= 2; // to make it look shorter
+       
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
index a7d90fb0c2a2618546408382cb4feeb39cdb4056..01337c595f40a5422a0007ea2ee20255af48ca01 100644 (file)
@@ -43,7 +43,8 @@ void CommandInset::metrics(MetricsInfo & mi, Dimension & dim) const
                button_.update(screenLabel(), true);
        }
        button_.metrics(mi, dim);
                button_.update(screenLabel(), true);
        }
        button_.metrics(mi, dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
index b3894e9322f8e215de185a827df1ecccccad9036..4ec493f03fcf7eb5156c3bf3916a2e4531d485ea 100644 (file)
@@ -83,16 +83,24 @@ void InsetMathAMSArray::metrics(MetricsInfo & mi, Dimension & dim) const
        ArrayChanger dummy(mi.base);
        InsetMathGrid::metrics(mi, dim);
        dim.wid += 14;
        ArrayChanger dummy(mi.base);
        InsetMathGrid::metrics(mi, dim);
        dim.wid += 14;
-       dim_ = dim;
+}
+
+
+Dimension const InsetMathAMSArray::dimension(BufferView const & bv) const
+{
+       Dimension dim = InsetMathGrid::dimension(bv);
+       dim.wid += 14;
+       return dim;
 }
 
 
 void InsetMathAMSArray::draw(PainterInfo & pi, int x, int y) const
 {
 }
 
 
 void InsetMathAMSArray::draw(PainterInfo & pi, int x, int y) const
 {
-       int const yy = y - dim_.ascent();
+       Dimension const dim = dimension(*pi.base.bv);
+       int const yy = y - dim.ascent();
        // Drawing the deco after an ArrayChanger does not work
        // Drawing the deco after an ArrayChanger does not work
-       mathed_draw_deco(pi, x + 1, yy, 5, dim_.height(), from_ascii(name_left()));
-       mathed_draw_deco(pi, x + dim_.width() - 8, yy, 5, dim_.height(), from_ascii(name_right()));
+       mathed_draw_deco(pi, x + 1, yy, 5, dim.height(), from_ascii(name_left()));
+       mathed_draw_deco(pi, x + dim.width() - 8, yy, 5, dim.height(), from_ascii(name_right()));
        ArrayChanger dummy(pi.base);
        InsetMathGrid::drawWithMargin(pi, x, y, 6, 8);
 }
        ArrayChanger dummy(pi.base);
        InsetMathGrid::drawWithMargin(pi, x, y, 6, 8);
 }
index 6555c5914bacc068d8b19e92ec8f10da50ce16a9..2b5491fe37e7b2da5bf05d586f6a9ed6a827123c 100644 (file)
@@ -27,6 +27,8 @@ public:
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
+       Dimension const dimension(BufferView const &) const;
+       ///
        void draw(PainterInfo & pain, int x, int y) const;
        ///
        InsetMathAMSArray * asAMSArrayInset() { return this; }
        void draw(PainterInfo & pain, int x, int y) const;
        ///
        InsetMathAMSArray * asAMSArrayInset() { return this; }
index cee277b7385fd7ecc4fdeba4108d537ef646214e..8ce2b8f676758bab948de7553bc1fead6610f8a4 100644 (file)
@@ -83,7 +83,14 @@ void InsetMathArray::metrics(MetricsInfo & mi, Dimension & dim) const
        ArrayChanger dummy(mi.base);
        InsetMathGrid::metrics(mi, dim);
        dim.wid += 6;
        ArrayChanger dummy(mi.base);
        InsetMathGrid::metrics(mi, dim);
        dim.wid += 6;
-       dim_ = dim;
+}
+
+
+Dimension const InsetMathArray::dimension(BufferView const & bv) const
+{
+       Dimension dim = InsetMathGrid::dimension(bv);
+       dim.wid += 6;
+       return dim;
 }
 
 
 }
 
 
index 94ea543436287a5bd72f5462ab9921f4980bacf6..f59d9e7304a9090cbad15a03722009359ed071d5 100644 (file)
@@ -33,6 +33,8 @@ public:
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
+       Dimension const dimension(BufferView const &) const;
+       ///
        void draw(PainterInfo & pi, int x, int y) const;
        ///
        InsetMathArray * asArrayInset() { return this; }
        void draw(PainterInfo & pi, int x, int y) const;
        ///
        InsetMathArray * asArrayInset() { return this; }
index 1c2ca3f739fc6eeeda9a8c1d3b228089e7388b60..ec590a094d7ee55a2624c389630876c00f599d3d 100644 (file)
@@ -29,8 +29,6 @@ public:
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
-       Dimension const dimension(BufferView const &) const { return dim_; };
-       ///
        void draw(PainterInfo & pi, int x, int y) const;
        ///
        void write(WriteStream & os) const;
        void draw(PainterInfo & pi, int x, int y) const;
        ///
        void write(WriteStream & os) const;
index fe948c14b26cf50ca1bb5bd48c6e9dcd16484888..325dfdd509239c4acf82e949f0077ae4e6f585ee 100644 (file)
@@ -29,9 +29,9 @@ Inset * InsetMathBinom::clone() const
 }
 
 
 }
 
 
-int InsetMathBinom::dw() const
+int InsetMathBinom::dw(int height) const
 {
 {
-       int w = dim_.height() / 5;
+       int w = height / 5;
        if (w > 15)
                w = 15;
        if (w < 6)
        if (w > 15)
                w = 15;
        if (w < 6)
@@ -47,21 +47,23 @@ void InsetMathBinom::metrics(MetricsInfo & mi, Dimension & dim) const
        cell(1).metrics(mi);
        dim.asc = cell(0).height() + 4 + 5;
        dim.des = cell(1).height() + 4 - 5;
        cell(1).metrics(mi);
        dim.asc = cell(0).height() + 4 + 5;
        dim.des = cell(1).height() + 4 - 5;
-       dim.wid = std::max(cell(0).width(), cell(1).width()) + 2 * dw() + 4;
+       dim.wid = std::max(cell(0).width(), cell(1).width()) + 2 * dw(dim.height()) + 4;
        metricsMarkers2(dim);
        metricsMarkers2(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 void InsetMathBinom::draw(PainterInfo & pi, int x, int y) const
 {
 }
 
 
 void InsetMathBinom::draw(PainterInfo & pi, int x, int y) const
 {
-       int m = x + dim_.width() / 2;
+       Dimension const dim = dimension(*pi.base.bv);
+       int m = x + dim.width() / 2;
        ScriptChanger dummy(pi.base);
        cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 3 - 5);
        cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent()  + 3 - 5);
        ScriptChanger dummy(pi.base);
        cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 3 - 5);
        cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent()  + 3 - 5);
-       mathed_draw_deco(pi, x, y - dim_.ascent(), dw(), dim_.height(), from_ascii("("));
-       mathed_draw_deco(pi, x + dim_.width() - dw(), y - dim_.ascent(),
-               dw(), dim_.height(), from_ascii(")"));
+       mathed_draw_deco(pi, x, y - dim.ascent(), dw(dim.height()), dim.height(), from_ascii("("));
+       mathed_draw_deco(pi, x + dim.width() - dw(dim.height()), y - dim.ascent(),
+               dw(dim.height()), dim.height(), from_ascii(")"));
        drawMarkers2(pi, x, y);
 }
 
        drawMarkers2(pi, x, y);
 }
 
index de29985d4b72cfce9dee0061cd9a577e9bc69bb1..0f89a0706f31c36e32d006efd8e9ab6de8b63a23 100644 (file)
@@ -39,7 +39,7 @@ public:
 private:
        virtual Inset * clone() const;
        ///
 private:
        virtual Inset * clone() const;
        ///
-       int dw() const;
+       int dw(int height) const;
        ///
        bool choose_;
 };
        ///
        bool choose_;
 };
index 0b0e9afc44222515a37663e167e96f886d5da624..27ee877c28ad0b8afbde8ce89163927247541f8d 100644 (file)
@@ -36,7 +36,8 @@ void InsetMathBoldSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
        cell(0).metrics(mi, dim);
        metricsMarkers(dim);
        ++dim.wid;  // for 'double stroke'
        cell(0).metrics(mi, dim);
        metricsMarkers(dim);
        ++dim.wid;  // for 'double stroke'
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
@@ -51,7 +52,9 @@ void InsetMathBoldSymbol::draw(PainterInfo & pi, int x, int y) const
 
 void InsetMathBoldSymbol::metricsT(TextMetricsInfo const & mi, Dimension & /*dim*/) const
 {
 
 void InsetMathBoldSymbol::metricsT(TextMetricsInfo const & mi, Dimension & /*dim*/) const
 {
-       cell(0).metricsT(mi, dim_);
+       // FIXME: BROKEN!
+       Dimension dim;
+       cell(0).metricsT(mi, dim);
 }
 
 
 }
 
 
index efbfd4a43393986e99e4d5c760ca3e3c560e65e5..36c1c163506fbda5defb4a6e9f34c8500572380a 100644 (file)
@@ -49,7 +49,8 @@ void InsetMathBox::metrics(MetricsInfo & mi, Dimension & dim) const
        FontSetChanger dummy(mi.base, "textnormal");
        cell(0).metrics(mi, dim);
        metricsMarkers(dim);
        FontSetChanger dummy(mi.base, "textnormal");
        cell(0).metrics(mi, dim);
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
index 9f2a7ed59180b8cf7c97ed5154fc63873a463681..d9e52c3e1fe4047178274676a162a9b474642870 100644 (file)
@@ -37,14 +37,16 @@ void InsetMathBoxed::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        cell(0).metrics(mi, dim);
        metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
 {
        cell(0).metrics(mi, dim);
        metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 void InsetMathBoxed::draw(PainterInfo & pi, int x, int y) const
 {
 }
 
 
 void InsetMathBoxed::draw(PainterInfo & pi, int x, int y) const
 {
-       pi.pain.rectangle(x + 1, y - dim_.ascent() + 1,
-               dim_.width() - 2, dim_.height() - 2, Color::foreground);
+       Dimension const dim = dimension(*pi.base.bv);
+       pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
+               dim.width() - 2, dim.height() - 2, Color::foreground);
        cell(0).draw(pi, x + 3, y);
        setPosCache(pi, x, y);
 }
        cell(0).draw(pi, x + 3, y);
        setPosCache(pi, x, y);
 }
index 1a3a2a1fa415b524973de404ab5c7d6df1513c7b..fc5058972330b93573284a8c6dca34d0f83573d6 100644 (file)
@@ -49,7 +49,8 @@ void InsetMathBrace::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.des = std::max(cell(0).descent(), t.des);
        dim.wid = cell(0).width() + 2 * t.wid;
        metricsMarkers(dim);
        dim.des = std::max(cell(0).descent(), t.des);
        dim.wid = cell(0).width() + 2 * t.wid;
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
index bcedc88b764acffe3c839a5b1ad8fb8a125afeeb..46d2602ab7dfa521113cea3e0b2862f6f62e3988 100644 (file)
@@ -45,15 +45,23 @@ Inset * InsetMathCases::clone() const
 
 void InsetMathCases::metrics(MetricsInfo & mi, Dimension & dim) const
 {
 
 void InsetMathCases::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       InsetMathGrid::metrics(mi);
-       dim_.wid += 8;
-       dim = dim_;
+       InsetMathGrid::metrics(mi, dim);
+       dim.wid += 8;
+}
+
+
+Dimension const InsetMathCases::dimension(BufferView const & bv) const
+{
+       Dimension dim = InsetMathGrid::dimension(bv);
+       dim.wid += 8;
+       return dim;
 }
 
 
 void InsetMathCases::draw(PainterInfo & pi, int x, int y) const
 {
 }
 
 
 void InsetMathCases::draw(PainterInfo & pi, int x, int y) const
 {
-       mathed_draw_deco(pi, x + 1, y - dim_.ascent(), 6, dim_.height(), from_ascii("{"));
+       Dimension const dim = dimension(*pi.base.bv);
+       mathed_draw_deco(pi, x + 1, y - dim.ascent(), 6, dim.height(), from_ascii("{"));
        InsetMathGrid::drawWithMargin(pi, x, y, 8, 0);
        setPosCache(pi, x, y);
 }
        InsetMathGrid::drawWithMargin(pi, x, y, 8, 0);
        setPosCache(pi, x, y);
 }
index 312b38b03195fc703bb16e46921d90d5ce03458c..a2a39fc6e62414cd09eefaea50d5ebe4f885e26b 100644 (file)
@@ -27,6 +27,8 @@ public:
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
+       Dimension const dimension(BufferView const &) const;
+       ///
        void draw(PainterInfo & pi, int x, int y) const;
        ///
        virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
        void draw(PainterInfo & pi, int x, int y) const;
        ///
        virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
index 9349663200618671fa836a71cbf64b69eac8d9fc..e669e9d96da40c4dfe5c8d3bcbdccb2605143468 100644 (file)
@@ -86,8 +86,7 @@ void InsetMathChar::metrics(MetricsInfo & mi, Dimension & dim) const
        lyxerr << "InsetMathChar::metrics: " << dim << endl;
 #endif
        // Cache the inset dimension. 
        lyxerr << "InsetMathChar::metrics: " << dim << endl;
 #endif
        // Cache the inset dimension. 
-       // FIXME: put the resulting dim in BufferView.
-       dim_ = dim;
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
index c1d5b1974a1608927410608c1795d1e0cb847bc7..0b57bbe76a05b190e89bc0efb9a40034957995b2 100644 (file)
@@ -26,8 +26,6 @@ public:
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
-       Dimension const dimension(BufferView const &) const { return dim_; }
-       ///
        void draw(PainterInfo & pi, int x, int y) const;
        ///
        void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
        void draw(PainterInfo & pi, int x, int y) const;
        ///
        void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
index eb5ed56ca5f81bd1bd05921e168ddbb9e1de6bd3..6f75c5b86a19bc93514172c3982669952be5e952 100644 (file)
@@ -42,7 +42,8 @@ void InsetMathColor::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        cell(0).metrics(mi, dim);
        metricsMarkers(dim);
 {
        cell(0).metrics(mi, dim);
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
index 7ecdc2da2c19ca11d72db1571851f0989917c2c5..4648ba1f17bcf6795ffe71e1600e4dd33e776ac4 100644 (file)
@@ -42,7 +42,8 @@ void InsetMathComment::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        cell(0).metrics(mi, dim);
        metricsMarkers(dim);
 {
        cell(0).metrics(mi, dim);
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
index cff05927dd6fc8caa7861da820f78bce2b2c6e52..6b051ab7d5320c969b92fc55989d868af9448532 100644 (file)
@@ -38,16 +38,18 @@ void InsetMathDFrac::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.wid = std::max(cell(0).width(), cell(1).width()) + 2;
        dim.asc = cell(0).height() + 2 + 5;
        dim.des = cell(1).height() + 2 - 5;
        dim.wid = std::max(cell(0).width(), cell(1).width()) + 2;
        dim.asc = cell(0).height() + 2 + 5;
        dim.des = cell(1).height() + 2 - 5;
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 void InsetMathDFrac::draw(PainterInfo & pi, int x, int y) const
 {
 }
 
 
 void InsetMathDFrac::draw(PainterInfo & pi, int x, int y) const
 {
-       int m = x + dim_.wid / 2;
+       Dimension const dim = dimension(*pi.base.bv);
+       int m = x + dim.wid / 2;
        cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 2 - 5);
        cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent()  + 2 - 5);
        cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 2 - 5);
        cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent()  + 2 - 5);
-       pi.pain.line(x + 1, y - 5, x + dim_.wid - 2, y - 5, Color::math);
+       pi.pain.line(x + 1, y - 5, x + dim.wid - 2, y - 5, Color::math);
        setPosCache(pi, x, y);
 }
 
        setPosCache(pi, x, y);
 }
 
index 6917757557488b32da5a994658e941d4ce53dda5..2ef910d8751f7c132e92284d55f836c440428e74 100644 (file)
@@ -117,7 +117,8 @@ void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
        }
 
        metricsMarkers(dim);
        }
 
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
index 209e13bd7ccfaba94d9cf3431ea28b17d4d31dbe..19bcc6ccd8f254ad12bec287986575e18a5f97c2 100644 (file)
@@ -83,17 +83,19 @@ void InsetMathDelim::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.wid = cell(0).width() + 2 * dw_ + 8;
        dim.asc = max(a0, d0) + h0;
        dim.des = max(a0, d0) - h0;
        dim.wid = cell(0).width() + 2 * dw_ + 8;
        dim.asc = max(a0, d0) + h0;
        dim.des = max(a0, d0) - h0;
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 void InsetMathDelim::draw(PainterInfo & pi, int x, int y) const
 {
 }
 
 
 void InsetMathDelim::draw(PainterInfo & pi, int x, int y) const
 {
-       int const b = y - dim_.asc;
+       Dimension const dim = dimension(*pi.base.bv);
+       int const b = y - dim.asc;
        cell(0).draw(pi, x + dw_ + 4, y);
        cell(0).draw(pi, x + dw_ + 4, y);
-       mathed_draw_deco(pi, x + 4, b, dw_, dim_.height(), left_);
-       mathed_draw_deco(pi, x + dim_.width() - dw_ - 4,
-               b, dw_, dim_.height(), right_);
+       mathed_draw_deco(pi, x + 4, b, dw_, dim.height(), left_);
+       mathed_draw_deco(pi, x + dim.width() - dw_ - 4,
+               b, dw_, dim.height(), right_);
        setPosCache(pi, x, y);
 }
 
        setPosCache(pi, x, y);
 }
 
index d90b0bdbd332fca2a207c07bd808e827355e1f54..fa93e4bb924193d80e18819360d1495f55af1661 100644 (file)
@@ -47,19 +47,21 @@ void InsetMathDots::metrics(MetricsInfo & mi, Dimension & dim) const
        }
        else if (key_->name == "ddots")
                dh_ = dim.asc;
        }
        else if (key_->name == "ddots")
                dh_ = dim.asc;
-       dim = dim_;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 void InsetMathDots::draw(PainterInfo & pain, int x, int y) const
 {
 }
 
 
 void InsetMathDots::draw(PainterInfo & pain, int x, int y) const
 {
-       mathed_draw_deco(pain, x + 2, y - dh_, dim_.width() - 2, dim_.ascent(),
+       Dimension const dim = dimension(*pain.base.bv);
+       mathed_draw_deco(pain, x + 2, y - dh_, dim.width() - 2, dim.ascent(),
                key_->name);
        if (key_->name == "vdots" || key_->name == "ddots")
                ++x;
        if (key_->name != "vdots")
                --y;
                key_->name);
        if (key_->name == "vdots" || key_->name == "ddots")
                ++x;
        if (key_->name != "vdots")
                --y;
-       mathed_draw_deco(pain, x + 2, y - dh_, dim_.width() - 2, dim_.ascent(),
+       mathed_draw_deco(pain, x + 2, y - dh_, dim.width() - 2, dim.ascent(),
                key_->name);
        setPosCache(pain, x, y);
 }
                key_->name);
        setPosCache(pain, x, y);
 }
index d92303b1b233d906daaf56bb8ae17587e8d11dda..3a4358a518e0ced060b1b122a9d25f1da8516fb6 100644 (file)
@@ -27,8 +27,6 @@ public:
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
-       Dimension const dimension(BufferView const &) const { return dim_; };
-       ///
        void draw(PainterInfo & pi, int x, int y) const;
        ///
        docstring name() const;
        void draw(PainterInfo & pi, int x, int y) const;
        ///
        docstring name() const;
@@ -39,8 +37,6 @@ protected:
        latexkeys const * key_;
 private:
        virtual Inset * clone() const;
        latexkeys const * key_;
 private:
        virtual Inset * clone() const;
-       ///
-       mutable Dimension dim_;
 };
 
 } // namespace lyx
 };
 
 } // namespace lyx
index 2b995e5f50a44cf6a787e49a4dad682e0ac4c40a..5965d2969e77e9bdcc78fd505fefd8c146272e2c 100644 (file)
@@ -34,7 +34,8 @@ void InsetMathEnv::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        cell(0).metrics(mi, dim);
        metricsMarkers(dim);
 {
        cell(0).metrics(mi, dim);
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
index ed5c728ef25b89449306f44479c23178cd071e00..f2471173ed98f8541d81aa378b83fced54eee1f5 100644 (file)
@@ -43,7 +43,8 @@ Inset * InsetMathExFunc::clone() const
 void InsetMathExFunc::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        mathed_string_dim(mi.base.font, name_, dim);
 void InsetMathExFunc::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        mathed_string_dim(mi.base.font, name_, dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
index a9ccc3a81a22f949514fe08697eb7ab55f55482f..7533778f953a9f6ee7eb6757af44ec223fb8ac6b 100644 (file)
@@ -43,14 +43,16 @@ void InsetMathFBox::metrics(MetricsInfo & mi, Dimension & dim) const
        FontSetChanger dummy(mi.base, "textnormal");
        cell(0).metrics(mi, dim);
        metricsMarkers(dim, 3); // 1 pixel space, 1 frame, 1 space
        FontSetChanger dummy(mi.base, "textnormal");
        cell(0).metrics(mi, dim);
        metricsMarkers(dim, 3); // 1 pixel space, 1 frame, 1 space
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 void InsetMathFBox::draw(PainterInfo & pi, int x, int y) const
 {
 }
 
 
 void InsetMathFBox::draw(PainterInfo & pi, int x, int y) const
 {
-       pi.pain.rectangle(x + 1, y - dim_.ascent() + 1,
-               dim_.width() - 2, dim_.height() - 2, Color::foreground);
+       Dimension const dim = dimension(*pi.base.bv);
+       pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
+               dim.width() - 2, dim.height() - 2, Color::foreground);
        FontSetChanger dummy(pi.base, "textnormal");
        cell(0).draw(pi, x + 3, y);
        setPosCache(pi, x, y);
        FontSetChanger dummy(pi.base, "textnormal");
        cell(0).draw(pi, x + 3, y);
        setPosCache(pi, x, y);
index b6af0679c7b69622f4195029c1f11d24e842765c..81b54be10b966a893f6676e0a6dfd758e9beed0c 100644 (file)
@@ -46,7 +46,8 @@ void InsetMathFont::metrics(MetricsInfo & mi, Dimension & dim) const
        FontSetChanger dummy(mi.base, key_->name);
        cell(0).metrics(mi, dim);
        metricsMarkers(dim);
        FontSetChanger dummy(mi.base, key_->name);
        cell(0).metrics(mi, dim);
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
@@ -61,7 +62,9 @@ void InsetMathFont::draw(PainterInfo & pi, int x, int y) const
 
 void InsetMathFont::metricsT(TextMetricsInfo const & mi, Dimension &) const
 {
 
 void InsetMathFont::metricsT(TextMetricsInfo const & mi, Dimension &) const
 {
-       cell(0).metricsT(mi, dim_);
+       // FIXME: BROKEN!
+       Dimension dim;
+       cell(0).metricsT(mi, dim);
 }
 
 
 }
 
 
index 8b8cf64ead9042415047b52ec715a84d5af1834d..2df5a1f8d9d1df35419f20ccb6d5f74e7de29c88 100644 (file)
@@ -38,7 +38,8 @@ void InsetMathFontOld::metrics(MetricsInfo & mi, Dimension & dim) const
        FontSetChanger dummy(mi.base, key_->name.c_str());
        cell(0).metrics(mi, dim);
        metricsMarkers(dim);
        FontSetChanger dummy(mi.base, key_->name.c_str());
        cell(0).metrics(mi, dim);
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
index 4f95377d1bee2789e5a80610afed1800c4e8fdc5..c0364829610169f6b12d2a0616c4e397e9f887b6 100644 (file)
@@ -128,14 +128,16 @@ void InsetMathFrac::metrics(MetricsInfo & mi, Dimension & dim) const
                }
        }
        metricsMarkers(dim);
                }
        }
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 void InsetMathFrac::draw(PainterInfo & pi, int x, int y) const
 {
        setPosCache(pi, x, y);
 }
 
 
 void InsetMathFrac::draw(PainterInfo & pi, int x, int y) const
 {
        setPosCache(pi, x, y);
-       int m = x + dim_.wid / 2;
+       Dimension const dim = dimension(*pi.base.bv);
+       int m = x + dim.wid / 2;
        if (kind_ == UNIT || (kind_ == UNITFRAC && nargs() == 3)) {
                if (nargs() == 1) {
                        ShapeChanger dummy2(pi.base.font, Font::UP_SHAPE);
        if (kind_ == UNIT || (kind_ == UNITFRAC && nargs() == 3)) {
                if (nargs() == 1) {
                        ShapeChanger dummy2(pi.base.font, Font::UP_SHAPE);
@@ -181,13 +183,13 @@ void InsetMathFrac::draw(PainterInfo & pi, int x, int y) const
                if (nargs() == 3)
                        xx += cell(2).width() + 5;
                pi.pain.line(xx + cell(0).width(),
                if (nargs() == 3)
                        xx += cell(2).width() + 5;
                pi.pain.line(xx + cell(0).width(),
-                               y + dim_.des - 2,
+                               y + dim.des - 2,
                                xx + cell(0).width() + 5,
                                xx + cell(0).width() + 5,
-                               y - dim_.asc + 2, Color::math);
+                               y - dim.asc + 2, Color::math);
        }
        if (kind_ == FRAC || kind_ == OVER)
                pi.pain.line(x + 1, y - 5,
        }
        if (kind_ == FRAC || kind_ == OVER)
                pi.pain.line(x + 1, y - 5,
-                               x + dim_.wid - 2, y - 5, Color::math);
+                               x + dim.wid - 2, y - 5, Color::math);
        drawMarkers(pi, x, y);
 }
 
        drawMarkers(pi, x, y);
 }
 
@@ -199,18 +201,19 @@ void InsetMathFrac::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
        dim.wid = std::max(cell(0).width(), cell(1).width());
        dim.asc = cell(0).height() + 1;
        dim.des = cell(1).height();
        dim.wid = std::max(cell(0).width(), cell(1).width());
        dim.asc = cell(0).height() + 1;
        dim.des = cell(1).height();
-       //dim = dim_;
 }
 
 
 void InsetMathFrac::drawT(TextPainter & pain, int x, int y) const
 {
 }
 
 
 void InsetMathFrac::drawT(TextPainter & pain, int x, int y) const
 {
-       int m = x + dim_.width() / 2;
+       // FIXME: BROKEN!
+       Dimension dim;
+       int m = x + dim.width() / 2;
        cell(0).drawT(pain, m - cell(0).width() / 2, y - cell(0).descent() - 1);
        cell(1).drawT(pain, m - cell(1).width() / 2, y + cell(1).ascent());
        // ASCII art: ignore niceties
        if (kind_ == FRAC || kind_ == OVER || kind_ == NICEFRAC || kind_ == UNITFRAC)
        cell(0).drawT(pain, m - cell(0).width() / 2, y - cell(0).descent() - 1);
        cell(1).drawT(pain, m - cell(1).width() / 2, y + cell(1).ascent());
        // ASCII art: ignore niceties
        if (kind_ == FRAC || kind_ == OVER || kind_ == NICEFRAC || kind_ == UNITFRAC)
-               pain.horizontalLine(x, y, dim_.width());
+               pain.horizontalLine(x, y, dim.width());
 }
 
 
 }
 
 
index af0f0592621fe4b57981140cf120d02bcd64c440..5123e17646245dba0f18a7646ac9bf3aa9f24680 100644 (file)
@@ -40,15 +40,17 @@ void InsetMathFrameBox::metrics(MetricsInfo & mi, Dimension & dim) const
        dim += cell(1).dim();
        dim += cell(2).dim();
        metricsMarkers(dim);
        dim += cell(1).dim();
        dim += cell(2).dim();
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 void InsetMathFrameBox::draw(PainterInfo & pi, int x, int y) const
 {
        FontSetChanger dummy(pi.base, "textnormal");
 }
 
 
 void InsetMathFrameBox::draw(PainterInfo & pi, int x, int y) const
 {
        FontSetChanger dummy(pi.base, "textnormal");
-       pi.pain.rectangle(x + 1, y - dim_.ascent() + 1,
-               dim_.width() - 2, dim_.height() - 2, Color::foreground);
+       Dimension const dim = dimension(*pi.base.bv);
+       pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
+               dim.width() - 2, dim.height() - 2, Color::foreground);
        x += 5;
 
        drawStrBlack(pi, x, y, from_ascii("["));
        x += 5;
 
        drawStrBlack(pi, x, y, from_ascii("["));
index 098e173d8d2eefe23187a1401a131dc9d93f2e74..99bb9ded1d7c1607c83012a2cc918f914ce457b9 100644 (file)
@@ -365,7 +365,7 @@ Length InsetMathGrid::vcrskip(row_type row) const
 }
 
 
 }
 
 
-void InsetMathGrid::metrics(MetricsInfo & mi) const
+void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        // let the cells adjust themselves
        InsetMathNest::metrics(mi);
 {
        // let the cells adjust themselves
        InsetMathNest::metrics(mi);
@@ -435,17 +435,17 @@ void InsetMathGrid::metrics(MetricsInfo & mi) const
        }
 
 
        }
 
 
-       dim_.wid   =   colinfo_[ncols() - 1].offset_
+       dim.wid   =   colinfo_[ncols() - 1].offset_
                       + colinfo_[ncols() - 1].width_
                 + vlinesep() * colinfo_[ncols()].lines_
                       + border();
 
                       + colinfo_[ncols() - 1].width_
                 + vlinesep() * colinfo_[ncols()].lines_
                       + border();
 
-       dim_.asc  = - rowinfo_[0].offset_
+       dim.asc  = - rowinfo_[0].offset_
                       + rowinfo_[0].ascent_
                 + hlinesep() * rowinfo_[0].lines_
                       + border();
 
                       + rowinfo_[0].ascent_
                 + hlinesep() * rowinfo_[0].lines_
                       + border();
 
-       dim_.des =   rowinfo_[nrows() - 1].offset_
+       dim.des =   rowinfo_[nrows() - 1].offset_
                       + rowinfo_[nrows() - 1].descent_
                 + hlinesep() * rowinfo_[nrows()].lines_
                       + border();
                       + rowinfo_[nrows() - 1].descent_
                 + hlinesep() * rowinfo_[nrows()].lines_
                       + border();
@@ -501,14 +501,9 @@ void InsetMathGrid::metrics(MetricsInfo & mi) const
                cxrow->setBaseline(cxrow->getBaseline() - ascent);
        }
 */
                cxrow->setBaseline(cxrow->getBaseline() - ascent);
        }
 */
-       metricsMarkers2(dim_);
-}
-
-
-void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const
-{
-       metrics(mi);
-       dim = dim_;
+       metricsMarkers2(dim);
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
@@ -517,9 +512,12 @@ void InsetMathGrid::draw(PainterInfo & pi, int x, int y) const
        drawWithMargin(pi, x, y, 0, 0);
 }
 
        drawWithMargin(pi, x, y, 0, 0);
 }
 
+
 void InsetMathGrid::drawWithMargin(PainterInfo & pi, int x, int y,
        int lmargin, int rmargin) const
 {
 void InsetMathGrid::drawWithMargin(PainterInfo & pi, int x, int y,
        int lmargin, int rmargin) const
 {
+       Dimension const dim = dimension(*pi.base.bv);
+
        for (idx_type idx = 0; idx < nargs(); ++idx)
                cell(idx).draw(pi, x + lmargin + cellXOffset(idx),
                        y + cellYOffset(idx));
        for (idx_type idx = 0; idx < nargs(); ++idx)
                cell(idx).draw(pi, x + lmargin + cellXOffset(idx),
                        y + cellYOffset(idx));
@@ -529,7 +527,7 @@ void InsetMathGrid::drawWithMargin(PainterInfo & pi, int x, int y,
                        int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
                                - i * hlinesep() - hlinesep()/2 - rowsep()/2;
                        pi.pain.line(x + lmargin + 1, yy,
                        int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
                                - i * hlinesep() - hlinesep()/2 - rowsep()/2;
                        pi.pain.line(x + lmargin + 1, yy,
-                                    x + dim_.width() - rmargin - 1, yy,
+                                    x + dim.width() - rmargin - 1, yy,
                                     Color::foreground);
                }
 
                                     Color::foreground);
                }
 
@@ -537,8 +535,8 @@ void InsetMathGrid::drawWithMargin(PainterInfo & pi, int x, int y,
                for (unsigned int i = 0; i < colinfo_[col].lines_; ++i) {
                        int xx = x + lmargin + colinfo_[col].offset_
                                - i * vlinesep() - vlinesep()/2 - colsep()/2;
                for (unsigned int i = 0; i < colinfo_[col].lines_; ++i) {
                        int xx = x + lmargin + colinfo_[col].offset_
                                - i * vlinesep() - vlinesep()/2 - colsep()/2;
-                       pi.pain.line(xx, y - dim_.ascent() + 1,
-                                    xx, y + dim_.descent() - 1,
+                       pi.pain.line(xx, y - dim.ascent() + 1,
+                                    xx, y + dim.descent() - 1,
                                     Color::foreground);
                }
        drawMarkers2(pi, x, y);
                                     Color::foreground);
                }
        drawMarkers2(pi, x, y);
index 92d71aab10678979e0774d5c4e752009f089a67f..4bea98172c9f0d295bbd2d81889d03edea94c6b0 100644 (file)
@@ -100,8 +100,6 @@ public:
        ///
        InsetMathGrid(col_type m, row_type n, char valign, docstring const & halign);
        ///
        ///
        InsetMathGrid(col_type m, row_type n, char valign, docstring const & halign);
        ///
-       void metrics(MetricsInfo & mi) const;
-       ///
        void metrics(MetricsInfo & mi, Dimension &) const;
        ///
        void draw(PainterInfo & pi, int x, int y) const;
        void metrics(MetricsInfo & mi, Dimension &) const;
        ///
        void draw(PainterInfo & pi, int x, int y) const;
index 2857d3dcf5b96ed8b25fb513e81f9c5a083e4522..f858281064451b2412901ae8562842ad3fbf226d 100644 (file)
@@ -290,7 +290,8 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
                dim.wid += 1;
                if (display())
                        dim.des += displayMargin();
                dim.wid += 1;
                if (display())
                        dim.des += displayMargin();
-               dim_ = dim;
+               // Cache the inset dimension. 
+               setDimCache(mi, dim);
                return;
        }
 
                return;
        }
 
@@ -321,19 +322,22 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
        math_font_max_dim(mi.base.font, asc, des);
        dim.asc = max(dim.asc, asc);
        dim.des = max(dim.des, des);
        math_font_max_dim(mi.base.font, asc, des);
        dim.asc = max(dim.asc, asc);
        dim.des = max(dim.des, des);
-       dim_ = dim;
+       // Cache the inset dimension.
+       // FIXME: This will overwrite InsetMathGrid dimension, is that OK?
+       setDimCache(mi, dim);
 }
 
 
 void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
 {
        use_preview_ = previewState(pi.base.bv);
 }
 
 
 void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
 {
        use_preview_ = previewState(pi.base.bv);
+       Dimension const dim = dimension(*pi.base.bv);
 
        // background of mathed under focus is not painted because
        // selection at the top level of nested inset is difficult to handle.
        if (!editing(pi.base.bv))
 
        // background of mathed under focus is not painted because
        // selection at the top level of nested inset is difficult to handle.
        if (!editing(pi.base.bv))
-               pi.pain.fillRectangle(x + 1, y - dim_.asc + 1, dim_.wid - 2,
-                               dim_.asc + dim_.des - 1, Color::mathbg);
+               pi.pain.fillRectangle(x + 1, y - dim.asc + 1, dim.wid - 2,
+                               dim.asc + dim.des - 1, Color::mathbg);
 
        if (use_preview_) {
                // one pixel gap in front
 
        if (use_preview_) {
                // one pixel gap in front
index dc64e6f7df86da294933c4a868baa85e3a4432f5..358ecd3f0c2030cb5cafe8321625ea6b443639c9 100644 (file)
@@ -35,7 +35,8 @@ void InsetMathLefteqn::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.des += 2;
        dim.wid = 4;
        metricsMarkers(dim);
        dim.des += 2;
        dim.wid = 4;
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
index 7e7e83baa3cbeaadbc07ecd326909b395fc3b12c..4ab87db31f062677881d9ba2db1f4155a8d5a4ce 100644 (file)
@@ -41,7 +41,8 @@ void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const
        dim  += cell(2).dim();
        dim.wid += 4 * w_ + 4;
        metricsMarkers(dim);
        dim  += cell(2).dim();
        dim.wid += 4 * w_ + 4;
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
index 31f12c21c145ce91b282e23b537c2beaacc312c6..3e8e1a7087904a898e6504930d9fc5dae39eea67 100644 (file)
@@ -33,8 +33,6 @@ public:
        /// the size is usually some sort of convex hull of the cells
        /// hides inset::metrics() intentionally!
        void metrics(MetricsInfo const & mi) const;
        /// the size is usually some sort of convex hull of the cells
        /// hides inset::metrics() intentionally!
        void metrics(MetricsInfo const & mi) const;
-       ///
-       Dimension const dimension(BufferView const &) const { return dim_; };
        /// draw background if locked
        void draw(PainterInfo & pi, int x, int y) const;
        /// draw selection background
        /// draw background if locked
        void draw(PainterInfo & pi, int x, int y) const;
        /// draw selection background
@@ -161,8 +159,6 @@ protected:
        bool lock_;
        ///
        bool mouse_hover_;
        bool lock_;
        ///
        bool mouse_hover_;
-       /// Cached dimensions of the inset.
-       mutable Dimension dim_;
 };
 
 
 };
 
 
index 3cbf7a28c4914cb4d91afb70483993e0711a3827..82b80d7d438234e943b3d5fadbe0c536f420fa46 100644 (file)
@@ -35,13 +35,15 @@ void InsetMathOverset::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.asc = cell(1).ascent() + cell(0).height() + 4;
        dim.des = cell(1).descent();
        metricsMarkers(dim);
        dim.asc = cell(1).ascent() + cell(0).height() + 4;
        dim.des = cell(1).descent();
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 void InsetMathOverset::draw(PainterInfo & pi, int x, int y) const
 {
 }
 
 
 void InsetMathOverset::draw(PainterInfo & pi, int x, int y) const
 {
-       int m  = x + dim_.wid / 2;
+       Dimension const dim = dimension(*pi.base.bv);
+       int m  = x + dim.wid / 2;
        int yo = y - cell(1).ascent() - cell(0).descent() - 1;
        cell(1).draw(pi, m - cell(1).width() / 2, y);
        FracChanger dummy(pi.base);
        int yo = y - cell(1).ascent() - cell(0).descent() - 1;
        cell(1).draw(pi, m - cell(1).width() / 2, y);
        FracChanger dummy(pi.base);
index 4466e13bb6a1ca5bfca65a35a5d718ba165554a1..38fc9bfc43be051cf2cb949a6bfa382dbc85b8f4 100644 (file)
@@ -27,8 +27,7 @@ InsetMathPar::InsetMathPar(MathData const & ar)
 void InsetMathPar::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        FontSetChanger dummy1(mi.base, "textnormal");
 void InsetMathPar::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        FontSetChanger dummy1(mi.base, "textnormal");
-       InsetMathGrid::metrics(mi);
-       dim = dim_;
+       InsetMathGrid::metrics(mi, dim);
 }
 
 
 }
 
 
index b4649bb83c43d31496a259143263baf216739e81..8448ff724663af6e27a396d119c6a87189e515e8 100644 (file)
@@ -39,7 +39,8 @@ void InsetMathPhantom::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        cell(0).metrics(mi, dim);
        metricsMarkers(dim);
 {
        cell(0).metrics(mi, dim);
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
@@ -52,6 +53,7 @@ void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const
        pi.base.font.setColor(Color::special);
        cell(0).draw(pi, x + 1, y);
        pi.base.font.setColor(origcol);
        pi.base.font.setColor(Color::special);
        cell(0).draw(pi, x + 1, y);
        pi.base.font.setColor(origcol);
+       Dimension const dim = dimension(*pi.base.bv);
 
        if (kind_ == phantom || kind_ == vphantom) {
                // y1---------
 
        if (kind_ == phantom || kind_ == vphantom) {
                // y1---------
@@ -66,13 +68,13 @@ void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const
                //         /  |  \.
                //        x1  x2 x3
 
                //         /  |  \.
                //        x1  x2 x3
 
-               int const x2 = x + dim_.wid / 2;
+               int const x2 = x + dim.wid / 2;
                int const x1 = x2 - arrow_size;
                int const x3 = x2 + arrow_size;
 
                int const x1 = x2 - arrow_size;
                int const x3 = x2 + arrow_size;
 
-               int const y1 = y - dim_.asc;
+               int const y1 = y - dim.asc;
                int const y2 = y1 + arrow_size;
                int const y2 = y1 + arrow_size;
-               int const y4 = y + dim_.des;
+               int const y4 = y + dim.des;
                int const y3 = y4 - arrow_size;
 
                // top arrow
                int const y3 = y4 - arrow_size;
 
                // top arrow
@@ -98,10 +100,10 @@ void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const
 
                int const x1 = x;
                int const x2 = x + arrow_size;
 
                int const x1 = x;
                int const x2 = x + arrow_size;
-               int const x4 = x + dim_.wid;
+               int const x4 = x + dim.wid;
                int const x3 = x4 - arrow_size;
 
                int const x3 = x4 - arrow_size;
 
-               int const y2 = y + (dim_.des - dim_.asc) / 2;
+               int const y2 = y + (dim.des - dim.asc) / 2;
                int const y1 = y2 - arrow_size;
                int const y3 = y2 + arrow_size;
 
                int const y1 = y2 - arrow_size;
                int const y3 = y2 + arrow_size;
 
index 90243eeeb11271286e586109e78528e8067a8c67..f1318ab03deb535dde26c2891fe4c1ec3292ba6c 100644 (file)
@@ -42,7 +42,8 @@ void InsetMathRoot::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.des = max(cell(0).descent() - 5, cell(1).descent()) + 2;
        dim.wid = cell(0).width() + cell(1).width() + 10;
        metricsMarkers(dim);
        dim.des = max(cell(0).descent() - 5, cell(1).descent()) + 2;
        dim.wid = cell(0).width() + cell(1).width() + 10;
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
@@ -53,11 +54,12 @@ void InsetMathRoot::draw(PainterInfo & pi, int x, int y) const
        cell(0).draw(pi, x, y - 5 - cell(0).descent());
        // the "base"
        cell(1).draw(pi, x + w + 8, y);
        cell(0).draw(pi, x, y - 5 - cell(0).descent());
        // the "base"
        cell(1).draw(pi, x + w + 8, y);
-       int const a = dim_.ascent();
-       int const d = dim_.descent();
+       Dimension const dim = dimension(*pi.base.bv);
+       int const a = dim.ascent();
+       int const d = dim.descent();
        int xp[4];
        int yp[4];
        int xp[4];
        int yp[4];
-       pi.pain.line(x + dim_.width(), y - a + 1,
+       pi.pain.line(x + dim.width(), y - a + 1,
                                                         x + w + 4, y - a + 1, Color::math);
        xp[0] = x + w + 4;         yp[0] = y - a + 1;
        xp[1] = x + w;             yp[1] = y + d;
                                                         x + w + 4, y - a + 1, Color::math);
        xp[0] = x + w + 4;         yp[0] = y - a + 1;
        xp[1] = x + w;             yp[1] = y + d;
index ad39adfb95a2e8acd5afc894c017bc2cfb716472..6145628247736f23b1b1d0ed5dc40359e7711c47 100644 (file)
@@ -240,23 +240,26 @@ int InsetMathScript::dy1() const
 }
 
 
 }
 
 
-int InsetMathScript::dx0() const
+int InsetMathScript::dx0(BufferView const & bv) const
 {
        BOOST_ASSERT(hasDown());
 {
        BOOST_ASSERT(hasDown());
-       return hasLimits() ? (dim_.wid - down().width()) / 2 : nwid();
+       Dimension const dim = dimension(bv);
+       return hasLimits() ? (dim.wid - down().width()) / 2 : nwid();
 }
 
 
 }
 
 
-int InsetMathScript::dx1() const
+int InsetMathScript::dx1(BufferView const & bv) const
 {
        BOOST_ASSERT(hasUp());
 {
        BOOST_ASSERT(hasUp());
-       return hasLimits() ? (dim_.wid - up().width()) / 2 : nwid() + nker();
+       Dimension const dim = dimension(bv);
+       return hasLimits() ? (dim.wid - up().width()) / 2 : nwid() + nker();
 }
 
 
 }
 
 
-int InsetMathScript::dxx() const
+int InsetMathScript::dxx(BufferView const & bv) const
 {
 {
-       return hasLimits() ? (dim_.wid - nwid()) / 2  :  0;
+       Dimension const dim = dimension(bv);
+       return hasLimits() ? (dim.wid - nwid()) / 2  :  0;
 }
 
 
 }
 
 
@@ -323,24 +326,25 @@ void InsetMathScript::metrics(MetricsInfo & mi, Dimension & dim) const
        } else
                dim.des = nd;
        metricsMarkers(dim);
        } else
                dim.des = nd;
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 void InsetMathScript::draw(PainterInfo & pi, int x, int y) const
 {
        if (nuc().size())
 }
 
 
 void InsetMathScript::draw(PainterInfo & pi, int x, int y) const
 {
        if (nuc().size())
-               nuc().draw(pi, x + dxx(), y);
+               nuc().draw(pi, x + dxx(*pi.base.bv), y);
        else {
        else {
-               nuc().setXY(*pi.base.bv, x + dxx(), y);
+               nuc().setXY(*pi.base.bv, x + dxx(*pi.base.bv), y);
                if (editing(pi.base.bv))
                if (editing(pi.base.bv))
-                       pi.draw(x + dxx(), y, char_type('.'));
+                       pi.draw(x + dxx(*pi.base.bv), y, char_type('.'));
        }
        ScriptChanger dummy(pi.base);
        if (hasUp())
        }
        ScriptChanger dummy(pi.base);
        if (hasUp())
-               up().draw(pi, x + dx1(), y - dy1());
+               up().draw(pi, x + dx1(*pi.base.bv), y - dy1());
        if (hasDown())
        if (hasDown())
-               down().draw(pi, x + dx0(), y + dy0());
+               down().draw(pi, x + dx0(*pi.base.bv), y + dy0());
        drawMarkers(pi, x, y);
 }
 
        drawMarkers(pi, x, y);
 }
 
@@ -358,11 +362,11 @@ void InsetMathScript::metricsT(TextMetricsInfo const & mi, Dimension & dim) cons
 void InsetMathScript::drawT(TextPainter & pain, int x, int y) const
 {
        if (nuc().size())
 void InsetMathScript::drawT(TextPainter & pain, int x, int y) const
 {
        if (nuc().size())
-               nuc().drawT(pain, x + dxx(), y);
+               nuc().drawT(pain, x + 1, y);
        if (hasUp())
        if (hasUp())
-               up().drawT(pain, x + dx1(), y - dy1());
+               up().drawT(pain, x + 1, y - dy1());
        if (hasDown())
        if (hasDown())
-               down().drawT(pain, x + dx0(), y + dy0());
+               down().drawT(pain, x + 1, y + dy0());
 }
 
 
 }
 
 
index 32abf34fa4bfb8a7445ac79c79226c7bbbfee3e1..e705ea6ebfbd5f6a01e689c2d07fc089592246dc 100644 (file)
@@ -107,7 +107,7 @@ protected:
 private:
        virtual Inset * clone() const;
        /// returns x offset for main part
 private:
        virtual Inset * clone() const;
        /// returns x offset for main part
-       int dxx() const;
+       int dxx(BufferView const & bv) const;
        /// returns width of nucleus if any
        int nwid() const;
        /// returns y offset for either superscript or subscript
        /// returns width of nucleus if any
        int nwid() const;
        /// returns y offset for either superscript or subscript
@@ -117,9 +117,9 @@ private:
        /// returns y offset for subscript
        int dy1() const;
        /// returns x offset for superscript
        /// returns y offset for subscript
        int dy1() const;
        /// returns x offset for superscript
-       int dx0() const;
+       int dx0(BufferView const & bv) const;
        /// returns x offset for subscript
        /// returns x offset for subscript
-       int dx1() const;
+       int dx1(BufferView const & bv) const;
        /// returns ascent of nucleus if any
        int nasc() const;
        /// returns descent of nucleus if any
        /// returns ascent of nucleus if any
        int nasc() const;
        /// returns descent of nucleus if any
index 7b591e7eb1e006387bae61d47ae0bfe17b3194d5..e520b4ea6d231383caf4da0732f41ca30f3bcf5d 100644 (file)
@@ -37,7 +37,8 @@ void InsetMathSize::metrics(MetricsInfo & mi, Dimension & dim) const
        StyleChanger dummy(mi.base, style_);
        cell(0).metrics(mi, dim);
        metricsMarkers(dim);
        StyleChanger dummy(mi.base, style_);
        cell(0).metrics(mi, dim);
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
index 1157dd8b6f43e993a682e5cb1a551b0b97f70a99..2528b265322b9a2b25ea9580b75fa736b111b679 100644 (file)
@@ -38,19 +38,21 @@ void InsetMathSqrt::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.des += 2;
        dim.wid += 12;
        metricsMarkers(dim);
        dim.des += 2;
        dim.wid += 12;
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 void InsetMathSqrt::draw(PainterInfo & pi, int x, int y) const
 {
        cell(0).draw(pi, x + 10, y);
 }
 
 
 void InsetMathSqrt::draw(PainterInfo & pi, int x, int y) const
 {
        cell(0).draw(pi, x + 10, y);
-       int const a = dim_.ascent();
-       int const d = dim_.descent();
+       Dimension const dim = dimension(*pi.base.bv);
+       int const a = dim.ascent();
+       int const d = dim.descent();
        int xp[3];
        int yp[3];
        int xp[3];
        int yp[3];
-       pi.pain.line(x + dim_.width(), y - a + 1,
-                                                        x + 8, y - a + 1, Color::math);
+       pi.pain.line(x + dim.width(), y - a + 1,
+               x + 8, y - a + 1, Color::math);
        xp[0] = x + 8;            yp[0] = y - a + 1;
        xp[1] = x + 5;            yp[1] = y + d - 1;
        xp[2] = x;                yp[2] = y + (d - a)/2;
        xp[0] = x + 8;            yp[0] = y - a + 1;
        xp[1] = x + 5;            yp[1] = y + d - 1;
        xp[2] = x;                yp[2] = y + (d - a)/2;
index 7b4fbef5ef80fa6b2a80d21b19df2e1a275ed572..953b62ba41c2b0a016fa1c740d10cb71dc5ad771 100644 (file)
@@ -36,13 +36,15 @@ void InsetMathStackrel::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.asc = cell(1).ascent() + cell(0).height() + 4;
        dim.des = cell(1).descent();
        metricsMarkers(dim);
        dim.asc = cell(1).ascent() + cell(0).height() + 4;
        dim.des = cell(1).descent();
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 void InsetMathStackrel::draw(PainterInfo & pi, int x, int y) const
 {
 }
 
 
 void InsetMathStackrel::draw(PainterInfo & pi, int x, int y) const
 {
-       int m  = x + dim_.width() / 2;
+       Dimension const dim = dimension(*pi.base.bv);
+       int m  = x + dim.width() / 2;
        int yo = y - cell(1).ascent() - cell(0).descent() - 1;
        cell(1).draw(pi, m - cell(1).width() / 2, y);
        FracChanger dummy(pi.base);
        int yo = y - cell(1).ascent() - cell(0).descent() - 1;
        cell(1).draw(pi, m - cell(1).width() / 2, y);
        FracChanger dummy(pi.base);
index 743e509bb350639eb4c4ef94d66b6507cdb2fb7c..bea27a0231ae2e00cbb88bf7546e82b09fe93bb4 100644 (file)
@@ -48,7 +48,6 @@ void InsetMathSubstack::metrics(MetricsInfo & mi, Dimension & dim) const
        } else {
                InsetMathGrid::metrics(mi, dim);
        }
        } else {
                InsetMathGrid::metrics(mi, dim);
        }
-       dim_ = dim;
 }
 
 
 }
 
 
index 670391361659555bd35327570e68f1366a537622..fa7f3a0ca7ee706a1bbc9de3338c82b62c3fc9a1 100644 (file)
@@ -84,8 +84,7 @@ void InsetMathSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
                        scriptable_ = true;
 
        // Cache the inset dimension. 
                        scriptable_ = true;
 
        // Cache the inset dimension. 
-       // FIXME: put the resulting dim in BufferView.
-       dim_ = dim;
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
index 3068d943abd719715c4fb3e54028dff0610ec492..bc33d2481a4963ce148eedbe05128d915a274a97 100644 (file)
@@ -35,8 +35,6 @@ public:
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
-       Dimension const dimension(BufferView const &) const { return dim_; }
-       ///
        void draw(PainterInfo &, int x, int y) const;
        ///
        int kerning() const { return kerning_; }
        void draw(PainterInfo &, int x, int y) const;
        ///
        int kerning() const { return kerning_; }
@@ -83,8 +81,6 @@ private:
        mutable int kerning_;
        ///
        mutable bool scriptable_;
        mutable int kerning_;
        ///
        mutable bool scriptable_;
-       /// FIXME: move this out to BufferView
-       mutable Dimension dim_;
 };
 
 } // namespace lyx
 };
 
 } // namespace lyx
index 29c4d40c896e7bf7cef8644bdeaafe371f9d4b7e..c375e68020506a09b4c882a26454ab988f6448ca 100644 (file)
@@ -42,17 +42,19 @@ void InsetMathTFrac::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.wid = std::max(cell(0).width(), cell(1).width()) + 2;
        dim.asc = cell(0).height() + 2 + 5;
        dim.des = cell(1).height() + 2 - 5;
        dim.wid = std::max(cell(0).width(), cell(1).width()) + 2;
        dim.asc = cell(0).height() + 2 + 5;
        dim.des = cell(1).height() + 2 - 5;
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 void InsetMathTFrac::draw(PainterInfo & pi, int x, int y) const
 {
        StyleChanger dummy(pi.base, LM_ST_SCRIPT);
 }
 
 
 void InsetMathTFrac::draw(PainterInfo & pi, int x, int y) const
 {
        StyleChanger dummy(pi.base, LM_ST_SCRIPT);
-       int m = x + dim_.wid / 2;
+       Dimension const dim = dimension(*pi.base.bv);
+       int m = x + dim.wid / 2;
        cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 2 - 5);
        cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent()  + 2 - 5);
        cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 2 - 5);
        cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent()  + 2 - 5);
-       pi.pain.line(x + 1, y - 5, x + dim_.wid - 2, y - 5, Color::math);
+       pi.pain.line(x + 1, y - 5, x + dim.wid - 2, y - 5, Color::math);
        setPosCache(pi, x, y);
 }
 
        setPosCache(pi, x, y);
 }
 
index 5231e01aff87da18338320b862343ad8c23f731d..e7309fb026d98d373694b0d14baad6f993228fbb 100644 (file)
@@ -51,7 +51,14 @@ void InsetMathTabular::metrics(MetricsInfo & mi, Dimension & dim) const
        FontSetChanger dummy(mi.base, "textnormal");
        InsetMathGrid::metrics(mi, dim);
        dim.wid += 6;
        FontSetChanger dummy(mi.base, "textnormal");
        InsetMathGrid::metrics(mi, dim);
        dim.wid += 6;
-       dim_ = dim;
+}
+
+
+Dimension const InsetMathTabular::dimension(BufferView const & bv) const
+{
+       Dimension dim = InsetMathGrid::dimension(bv);
+       dim.wid += 6;
+       return dim;
 }
 
 
 }
 
 
index 2dfc3f51bb84914b4b895e900a146f9d86e719c1..d6c5bbac159f8b72dc239654de8518f0afb70d41 100644 (file)
@@ -31,6 +31,8 @@ public:
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
+       Dimension const dimension(BufferView const &) const;
+       ///
        void draw(PainterInfo & pi, int x, int y) const;
        ///
        InsetMathTabular * asTabularInset() { return this; }
        void draw(PainterInfo & pi, int x, int y) const;
        ///
        InsetMathTabular * asTabularInset() { return this; }
index 499986a1ffd61ea9b5d0a31b284fc7c3ffc5638f..f213b80cb04f60f2e6af87bac53485505ef70f7f 100644 (file)
@@ -35,13 +35,15 @@ void InsetMathUnderset::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.asc = cell(1).ascent();
        dim.des = cell(1).descent() + cell(0).height() + 4;
        metricsMarkers(dim);
        dim.asc = cell(1).ascent();
        dim.des = cell(1).descent() + cell(0).height() + 4;
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 void InsetMathUnderset::draw(PainterInfo & pi, int x, int y) const
 {
 }
 
 
 void InsetMathUnderset::draw(PainterInfo & pi, int x, int y) const
 {
-       int m  = x + dim_.wid / 2;
+       Dimension const dim = dimension(*pi.base.bv);
+       int m  = x + dim.wid / 2;
        int yo = y + cell(1).descent() + cell(0).ascent() + 1;
        cell(1).draw(pi, m - cell(1).width() / 2, y);
        FracChanger dummy(pi.base);
        int yo = y + cell(1).descent() + cell(0).ascent() + 1;
        cell(1).draw(pi, m - cell(1).width() / 2, y);
        FracChanger dummy(pi.base);
index 55ad252ddb8e7a549b91b3d04b1ea27813ffa772..886c8a6e7fde57ebf991edc7be19767201ab8dc4 100644 (file)
@@ -42,7 +42,8 @@ void InsetMathXArrow::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.asc = cell(0).height() + 10;
        dim.des = cell(1).height();
        metricsMarkers(dim);
        dim.asc = cell(0).height() + 10;
        dim.des = cell(1).height();
        metricsMarkers(dim);
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
@@ -51,7 +52,8 @@ void InsetMathXArrow::draw(PainterInfo & pi, int x, int y) const
        ScriptChanger dummy(pi.base);
        cell(0).draw(pi, x + 5, y - 10);
        cell(1).draw(pi, x + 5, y + cell(1).height());
        ScriptChanger dummy(pi.base);
        cell(0).draw(pi, x + 5, y - 10);
        cell(1).draw(pi, x + 5, y + cell(1).height());
-       mathed_draw_deco(pi, x + 1, y - 7, dim_.wid - 2, 5, name_);
+       Dimension const dim = dimension(*pi.base.bv);
+       mathed_draw_deco(pi, x + 1, y - 7, dim.wid - 2, 5, name_);
        drawMarkers(pi, x, y);
 }
 
        drawMarkers(pi, x, y);
 }
 
index 391e52dddd9e3cb30c327c3151b55eead92f0283..5e1151ce66dedc55b0151965026b65ea683f2bf1 100644 (file)
@@ -48,7 +48,6 @@ void InsetMathXYMatrix::metrics(MetricsInfo & mi, Dimension & dim) const
        if (mi.base.style == LM_ST_DISPLAY)
                mi.base.style = LM_ST_TEXT;
        InsetMathGrid::metrics(mi, dim);
        if (mi.base.style == LM_ST_DISPLAY)
                mi.base.style = LM_ST_TEXT;
        InsetMathGrid::metrics(mi, dim);
-       dim_ = dim;
 }
 
 
 }
 
 
index 616c1bd4e7f5e9e84cfd81115a4fe785e4b93e64..8711cc6999291ab14efea97ec98697438d88e278 100644 (file)
@@ -142,7 +142,8 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
                        editing_ = false;
                }
        }
                        editing_ = false;
                }
        }
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
@@ -164,7 +165,8 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const
                } else if (editing_) {
                        Font font = pi.base.font;
                        augmentFont(font, from_ascii("lyxtex"));
                } else if (editing_) {
                        Font font = pi.base.font;
                        augmentFont(font, from_ascii("lyxtex"));
-                       int h = y - dim_.ascent() + 2 + tmpl_.ascent();
+                       Dimension const dim = dimension(*pi.base.bv);
+                       int h = y - dim.ascent() + 2 + tmpl_.ascent();
                        pi.pain.text(x + 3, h, name(), font);
                        int const w = mathed_string_width(font, name());
                        tmpl_.draw(pi, x + w + 12, h);
                        pi.pain.text(x + 3, h, name(), font);
                        int const w = mathed_string_width(font, name());
                        tmpl_.draw(pi, x + w + 12, h);
index a7e9112a6feb9413ead84e1b3e8266f9ea3ac11d..923276fabc0221b11c8281e66462e292a493a4a1 100644 (file)
@@ -126,7 +126,8 @@ void MathMacroTemplate::metrics(MetricsInfo & mi, Dimension & dim) const
        if (lockMacro)
                MacroTable::globalMacros().get(name_).unlock();
 
        if (lockMacro)
                MacroTable::globalMacros().get(name_).unlock();
 
-       dim_ = dim;
+       // Cache the inset dimension. 
+       setDimCache(mi, dim);
 }
 
 
 }
 
 
@@ -138,6 +139,8 @@ void MathMacroTemplate::draw(PainterInfo & p, int x, int y) const
 
        setPosCache(p, x, y);
 
 
        setPosCache(p, x, y);
 
+       Dimension const dim = dimension(*p.base.bv);
+
        // label
        Font font = p.base.font;
        font.setColor(Color::math);
        // label
        Font font = p.base.font;
        font.setColor(Color::math);
@@ -146,9 +149,9 @@ void MathMacroTemplate::draw(PainterInfo & p, int x, int y) const
        pi.base.style = LM_ST_TEXT;
        pi.base.font  = font;
 
        pi.base.style = LM_ST_TEXT;
        pi.base.font  = font;
 
-       int const a = y - dim_.asc + 1;
-       int const w = dim_.wid - 2;
-       int const h = dim_.height() - 2;
+       int const a = y - dim.asc + 1;
+       int const w = dim.wid - 2;
+       int const h = dim.height() - 2;
 
        // Color::mathbg used to be "AntiqueWhite" but is "linen" now, too
        // the next line would overwrite the selection!
 
        // Color::mathbg used to be "AntiqueWhite" but is "linen" now, too
        // the next line would overwrite the selection!
@@ -169,11 +172,11 @@ void MathMacroTemplate::draw(PainterInfo & p, int x, int y) const
        int const w0 = cell(0).width();
        int const w1 = cell(1).width();
        cell(0).draw(pi, x + 2, y + 1);
        int const w0 = cell(0).width();
        int const w1 = cell(1).width();
        cell(0).draw(pi, x + 2, y + 1);
-       pi.pain.rectangle(x, y - dim_.ascent() + 3,
-               w0 + 4, dim_.height() - 6, Color::mathline);
+       pi.pain.rectangle(x, y - dim.ascent() + 3,
+               w0 + 4, dim.height() - 6, Color::mathline);
        cell(1).draw(pi, x + 8 + w0, y + 1);
        cell(1).draw(pi, x + 8 + w0, y + 1);
-       pi.pain.rectangle(x + w0 + 6, y - dim_.ascent() + 3,
-               w1 + 4, dim_.height() - 6, Color::mathline);
+       pi.pain.rectangle(x + w0 + 6, y - dim.ascent() + 3,
+               w1 + 4, dim.height() - 6, Color::mathline);
 
        if (lockMacro)
                MacroTable::globalMacros().get(name_).unlock();
 
        if (lockMacro)
                MacroTable::globalMacros().get(name_).unlock();