From 137158532b1ac0cde1557226ee486b3fda39b545 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sun, 23 Sep 2007 22:39:49 +0000 Subject: [PATCH] Put mathed on a diet: transfer dimension cache from inset to BufferView. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20457 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/CoordCache.cpp | 4 +-- src/CoordCache.h | 48 ++++++++++++++++-------------- src/Cursor.cpp | 6 ++-- src/insets/Inset.cpp | 14 +++++---- src/insets/Inset.h | 2 ++ src/insets/InsetSpecialChar.cpp | 2 ++ src/mathed/CommandInset.cpp | 3 +- src/mathed/InsetMathAMSArray.cpp | 16 +++++++--- src/mathed/InsetMathAMSArray.h | 2 ++ src/mathed/InsetMathArray.cpp | 9 +++++- src/mathed/InsetMathArray.h | 2 ++ src/mathed/InsetMathBig.h | 2 -- src/mathed/InsetMathBinom.cpp | 18 ++++++----- src/mathed/InsetMathBinom.h | 2 +- src/mathed/InsetMathBoldSymbol.cpp | 7 +++-- src/mathed/InsetMathBox.cpp | 3 +- src/mathed/InsetMathBoxed.cpp | 8 +++-- src/mathed/InsetMathBrace.cpp | 3 +- src/mathed/InsetMathCases.cpp | 16 +++++++--- src/mathed/InsetMathCases.h | 2 ++ src/mathed/InsetMathChar.cpp | 3 +- src/mathed/InsetMathChar.h | 2 -- src/mathed/InsetMathColor.cpp | 3 +- src/mathed/InsetMathComment.cpp | 3 +- src/mathed/InsetMathDFrac.cpp | 8 +++-- src/mathed/InsetMathDecoration.cpp | 3 +- src/mathed/InsetMathDelim.cpp | 12 ++++---- src/mathed/InsetMathDots.cpp | 8 +++-- src/mathed/InsetMathDots.h | 4 --- src/mathed/InsetMathEnv.cpp | 3 +- src/mathed/InsetMathExFunc.cpp | 3 +- src/mathed/InsetMathFBox.cpp | 8 +++-- src/mathed/InsetMathFont.cpp | 7 +++-- src/mathed/InsetMathFontOld.cpp | 3 +- src/mathed/InsetMathFrac.cpp | 19 +++++++----- src/mathed/InsetMathFrameBox.cpp | 8 +++-- src/mathed/InsetMathGrid.cpp | 28 ++++++++--------- src/mathed/InsetMathGrid.h | 2 -- src/mathed/InsetMathHull.cpp | 12 +++++--- src/mathed/InsetMathLefteqn.cpp | 3 +- src/mathed/InsetMathMakebox.cpp | 3 +- src/mathed/InsetMathNest.h | 4 --- src/mathed/InsetMathOverset.cpp | 6 ++-- src/mathed/InsetMathPar.cpp | 3 +- src/mathed/InsetMathPhantom.cpp | 14 +++++---- src/mathed/InsetMathRoot.cpp | 10 ++++--- src/mathed/InsetMathScript.cpp | 34 +++++++++++---------- src/mathed/InsetMathScript.h | 6 ++-- src/mathed/InsetMathSize.cpp | 3 +- src/mathed/InsetMathSqrt.cpp | 12 ++++---- src/mathed/InsetMathStackrel.cpp | 6 ++-- src/mathed/InsetMathSubstack.cpp | 1 - src/mathed/InsetMathSymbol.cpp | 3 +- src/mathed/InsetMathSymbol.h | 4 --- src/mathed/InsetMathTFrac.cpp | 8 +++-- src/mathed/InsetMathTabular.cpp | 9 +++++- src/mathed/InsetMathTabular.h | 2 ++ src/mathed/InsetMathUnderset.cpp | 6 ++-- src/mathed/InsetMathXArrow.cpp | 6 ++-- src/mathed/InsetMathXYMatrix.cpp | 1 - src/mathed/MathMacro.cpp | 6 ++-- src/mathed/MathMacroTemplate.cpp | 19 +++++++----- 62 files changed, 281 insertions(+), 196 deletions(-) diff --git a/src/CoordCache.cpp b/src/CoordCache.cpp index 38baabf805..5be3a50f06 100644 --- a/src/CoordCache.cpp +++ b/src/CoordCache.cpp @@ -43,8 +43,6 @@ void CoordCache::clear() { arrays_.clear(); insets_.clear(); - slices0_.clear(); - slices1_.clear(); } @@ -53,7 +51,7 @@ void CoordCache::dump() const lyxerr << "InsetCache contains:" << std::endl; for (CoordCacheBase::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; } diff --git a/src/CoordCache.h b/src/CoordCache.h index 296de324e9..a93696df1e 100644 --- a/src/CoordCache.h +++ b/src/CoordCache.h @@ -14,6 +14,8 @@ // It seems that MacOSX define the check macro. #undef check +#include "Dimension.h" + #include "support/types.h" #include @@ -38,6 +40,13 @@ public: int x_, y_; }; + +struct Geometry { + Point pos; + Dimension dim; +}; + + template class CoordCacheBase { public: void clear() @@ -52,25 +61,36 @@ public: 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"); - return data_.find(thing)->second.x_; + return data_.find(thing)->second.pos.x_; } 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"); - return data_.find(thing)->second; + return data_.find(thing)->second.pos; } bool has(T const * thing) const @@ -93,7 +113,7 @@ private: lyxbreaker(thing, hint, data_.size()); } - typedef std::map cache_type; + typedef std::map cache_type; cache_type data_; public: @@ -114,26 +134,12 @@ class CoordCache { public: void clear(); - /// A map from paragraph index number to screen point - typedef std::map InnerParPosCache; - /// A map from a CursorSlice to screen points - typedef std::map SliceCache; - /// A map from MathData to position on the screen CoordCacheBase & arrays() { return arrays_; } CoordCacheBase const & getArrays() const { return arrays_; } /// A map from insets to positions on the screen CoordCacheBase & insets() { return insets_; } CoordCacheBase 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; @@ -142,10 +148,6 @@ private: CoordCacheBase arrays_; // All insets CoordCacheBase insets_; - /// Used with boundary == 0 - SliceCache slices0_; - /// Used with boundary == 1 - SliceCache slices1_; }; } // namespace lyx diff --git a/src/Cursor.cpp b/src/Cursor.cpp index 60598573d6..285a370b0e 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -97,9 +97,9 @@ namespace { int xo; int yo; Inset const * inset = &it.inset(); - std::map const & data = + std::map const & data = c.bv().coordCache().getInsets().getData(); - std::map::const_iterator I = data.find(inset); + std::map::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 @@ -110,7 +110,7 @@ namespace { 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_; diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp index 40c3c52bd3..252e399e82 100644 --- a/src/insets/Inset.cpp +++ b/src/insets/Inset.cpp @@ -36,7 +36,6 @@ #include "frontends/Painter.h" #include "support/convert.h" -#include "support/ExceptionMessage.h" #include @@ -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(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) diff --git a/src/insets/Inset.h b/src/insets/Inset.h index b8b068acfa..2090a7e369 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -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; + /// + 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) diff --git a/src/insets/InsetSpecialChar.cpp b/src/insets/InsetSpecialChar.cpp index 6ced90c05d..e1d176638f 100644 --- a/src/insets/InsetSpecialChar.cpp +++ b/src/insets/InsetSpecialChar.cpp @@ -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 + + setDimCache(mi, dim); } diff --git a/src/mathed/CommandInset.cpp b/src/mathed/CommandInset.cpp index a7d90fb0c2..01337c595f 100644 --- a/src/mathed/CommandInset.cpp +++ b/src/mathed/CommandInset.cpp @@ -43,7 +43,8 @@ void CommandInset::metrics(MetricsInfo & mi, Dimension & dim) const button_.update(screenLabel(), true); } button_.metrics(mi, dim); - dim_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); } diff --git a/src/mathed/InsetMathAMSArray.cpp b/src/mathed/InsetMathAMSArray.cpp index b3894e9322..4ec493f03f 100644 --- a/src/mathed/InsetMathAMSArray.cpp +++ b/src/mathed/InsetMathAMSArray.cpp @@ -83,16 +83,24 @@ void InsetMathAMSArray::metrics(MetricsInfo & mi, Dimension & dim) const 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 { - 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 - 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); } diff --git a/src/mathed/InsetMathAMSArray.h b/src/mathed/InsetMathAMSArray.h index 6555c5914b..2b5491fe37 100644 --- a/src/mathed/InsetMathAMSArray.h +++ b/src/mathed/InsetMathAMSArray.h @@ -27,6 +27,8 @@ public: /// 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; } diff --git a/src/mathed/InsetMathArray.cpp b/src/mathed/InsetMathArray.cpp index cee277b738..8ce2b8f676 100644 --- a/src/mathed/InsetMathArray.cpp +++ b/src/mathed/InsetMathArray.cpp @@ -83,7 +83,14 @@ void InsetMathArray::metrics(MetricsInfo & mi, Dimension & dim) const 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; } diff --git a/src/mathed/InsetMathArray.h b/src/mathed/InsetMathArray.h index 94ea543436..f59d9e7304 100644 --- a/src/mathed/InsetMathArray.h +++ b/src/mathed/InsetMathArray.h @@ -33,6 +33,8 @@ public: /// 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; } diff --git a/src/mathed/InsetMathBig.h b/src/mathed/InsetMathBig.h index 1c2ca3f739..ec590a094d 100644 --- a/src/mathed/InsetMathBig.h +++ b/src/mathed/InsetMathBig.h @@ -29,8 +29,6 @@ public: /// 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; diff --git a/src/mathed/InsetMathBinom.cpp b/src/mathed/InsetMathBinom.cpp index fe948c14b2..325dfdd509 100644 --- a/src/mathed/InsetMathBinom.cpp +++ b/src/mathed/InsetMathBinom.cpp @@ -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) @@ -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; - 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); - dim_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); } 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); - 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); } diff --git a/src/mathed/InsetMathBinom.h b/src/mathed/InsetMathBinom.h index de29985d4b..0f89a0706f 100644 --- a/src/mathed/InsetMathBinom.h +++ b/src/mathed/InsetMathBinom.h @@ -39,7 +39,7 @@ public: private: virtual Inset * clone() const; /// - int dw() const; + int dw(int height) const; /// bool choose_; }; diff --git a/src/mathed/InsetMathBoldSymbol.cpp b/src/mathed/InsetMathBoldSymbol.cpp index 0b0e9afc44..27ee877c28 100644 --- a/src/mathed/InsetMathBoldSymbol.cpp +++ b/src/mathed/InsetMathBoldSymbol.cpp @@ -36,7 +36,8 @@ void InsetMathBoldSymbol::metrics(MetricsInfo & mi, Dimension & dim) const 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 { - cell(0).metricsT(mi, dim_); + // FIXME: BROKEN! + Dimension dim; + cell(0).metricsT(mi, dim); } diff --git a/src/mathed/InsetMathBox.cpp b/src/mathed/InsetMathBox.cpp index efbfd4a433..36c1c16350 100644 --- a/src/mathed/InsetMathBox.cpp +++ b/src/mathed/InsetMathBox.cpp @@ -49,7 +49,8 @@ void InsetMathBox::metrics(MetricsInfo & mi, Dimension & dim) const FontSetChanger dummy(mi.base, "textnormal"); cell(0).metrics(mi, dim); metricsMarkers(dim); - dim_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); } diff --git a/src/mathed/InsetMathBoxed.cpp b/src/mathed/InsetMathBoxed.cpp index 9f2a7ed591..d9e52c3e1f 100644 --- a/src/mathed/InsetMathBoxed.cpp +++ b/src/mathed/InsetMathBoxed.cpp @@ -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 - dim_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); } 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); } diff --git a/src/mathed/InsetMathBrace.cpp b/src/mathed/InsetMathBrace.cpp index 1a3a2a1fa4..fc50589723 100644 --- a/src/mathed/InsetMathBrace.cpp +++ b/src/mathed/InsetMathBrace.cpp @@ -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_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); } diff --git a/src/mathed/InsetMathCases.cpp b/src/mathed/InsetMathCases.cpp index bcedc88b76..46d2602ab7 100644 --- a/src/mathed/InsetMathCases.cpp +++ b/src/mathed/InsetMathCases.cpp @@ -45,15 +45,23 @@ Inset * InsetMathCases::clone() 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 { - 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); } diff --git a/src/mathed/InsetMathCases.h b/src/mathed/InsetMathCases.h index 312b38b031..a2a39fc6e6 100644 --- a/src/mathed/InsetMathCases.h +++ b/src/mathed/InsetMathCases.h @@ -27,6 +27,8 @@ public: /// 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); diff --git a/src/mathed/InsetMathChar.cpp b/src/mathed/InsetMathChar.cpp index 9349663200..e669e9d96d 100644 --- a/src/mathed/InsetMathChar.cpp +++ b/src/mathed/InsetMathChar.cpp @@ -86,8 +86,7 @@ void InsetMathChar::metrics(MetricsInfo & mi, Dimension & dim) const lyxerr << "InsetMathChar::metrics: " << dim << endl; #endif // Cache the inset dimension. - // FIXME: put the resulting dim in BufferView. - dim_ = dim; + setDimCache(mi, dim); } diff --git a/src/mathed/InsetMathChar.h b/src/mathed/InsetMathChar.h index c1d5b1974a..0b57bbe76a 100644 --- a/src/mathed/InsetMathChar.h +++ b/src/mathed/InsetMathChar.h @@ -26,8 +26,6 @@ public: /// 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; diff --git a/src/mathed/InsetMathColor.cpp b/src/mathed/InsetMathColor.cpp index eb5ed56ca5..6f75c5b86a 100644 --- a/src/mathed/InsetMathColor.cpp +++ b/src/mathed/InsetMathColor.cpp @@ -42,7 +42,8 @@ void InsetMathColor::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi, dim); metricsMarkers(dim); - dim_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); } diff --git a/src/mathed/InsetMathComment.cpp b/src/mathed/InsetMathComment.cpp index 7ecdc2da2c..4648ba1f17 100644 --- a/src/mathed/InsetMathComment.cpp +++ b/src/mathed/InsetMathComment.cpp @@ -42,7 +42,8 @@ void InsetMathComment::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi, dim); metricsMarkers(dim); - dim_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); } diff --git a/src/mathed/InsetMathDFrac.cpp b/src/mathed/InsetMathDFrac.cpp index cff05927dd..6b051ab7d5 100644 --- a/src/mathed/InsetMathDFrac.cpp +++ b/src/mathed/InsetMathDFrac.cpp @@ -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_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); } 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); - 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); } diff --git a/src/mathed/InsetMathDecoration.cpp b/src/mathed/InsetMathDecoration.cpp index 6917757557..2ef910d875 100644 --- a/src/mathed/InsetMathDecoration.cpp +++ b/src/mathed/InsetMathDecoration.cpp @@ -117,7 +117,8 @@ void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const } metricsMarkers(dim); - dim_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); } diff --git a/src/mathed/InsetMathDelim.cpp b/src/mathed/InsetMathDelim.cpp index 209e13bd7c..19bcc6ccd8 100644 --- a/src/mathed/InsetMathDelim.cpp +++ b/src/mathed/InsetMathDelim.cpp @@ -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_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); } 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); - 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); } diff --git a/src/mathed/InsetMathDots.cpp b/src/mathed/InsetMathDots.cpp index d90b0bdbd3..fa93e4bb92 100644 --- a/src/mathed/InsetMathDots.cpp +++ b/src/mathed/InsetMathDots.cpp @@ -47,19 +47,21 @@ void InsetMathDots::metrics(MetricsInfo & mi, Dimension & dim) const } 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 { - 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; - 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); } diff --git a/src/mathed/InsetMathDots.h b/src/mathed/InsetMathDots.h index d92303b1b2..3a4358a518 100644 --- a/src/mathed/InsetMathDots.h +++ b/src/mathed/InsetMathDots.h @@ -27,8 +27,6 @@ public: /// 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; @@ -39,8 +37,6 @@ protected: latexkeys const * key_; private: virtual Inset * clone() const; - /// - mutable Dimension dim_; }; } // namespace lyx diff --git a/src/mathed/InsetMathEnv.cpp b/src/mathed/InsetMathEnv.cpp index 2b995e5f50..5965d2969e 100644 --- a/src/mathed/InsetMathEnv.cpp +++ b/src/mathed/InsetMathEnv.cpp @@ -34,7 +34,8 @@ void InsetMathEnv::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi, dim); metricsMarkers(dim); - dim_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); } diff --git a/src/mathed/InsetMathExFunc.cpp b/src/mathed/InsetMathExFunc.cpp index ed5c728ef2..f2471173ed 100644 --- a/src/mathed/InsetMathExFunc.cpp +++ b/src/mathed/InsetMathExFunc.cpp @@ -43,7 +43,8 @@ Inset * InsetMathExFunc::clone() const 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); } diff --git a/src/mathed/InsetMathFBox.cpp b/src/mathed/InsetMathFBox.cpp index a9ccc3a81a..7533778f95 100644 --- a/src/mathed/InsetMathFBox.cpp +++ b/src/mathed/InsetMathFBox.cpp @@ -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 - dim_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); } 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); diff --git a/src/mathed/InsetMathFont.cpp b/src/mathed/InsetMathFont.cpp index b6af0679c7..81b54be10b 100644 --- a/src/mathed/InsetMathFont.cpp +++ b/src/mathed/InsetMathFont.cpp @@ -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); - 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 { - cell(0).metricsT(mi, dim_); + // FIXME: BROKEN! + Dimension dim; + cell(0).metricsT(mi, dim); } diff --git a/src/mathed/InsetMathFontOld.cpp b/src/mathed/InsetMathFontOld.cpp index 8b8cf64ead..2df5a1f8d9 100644 --- a/src/mathed/InsetMathFontOld.cpp +++ b/src/mathed/InsetMathFontOld.cpp @@ -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); - dim_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); } diff --git a/src/mathed/InsetMathFrac.cpp b/src/mathed/InsetMathFrac.cpp index 4f95377d1b..c036482961 100644 --- a/src/mathed/InsetMathFrac.cpp +++ b/src/mathed/InsetMathFrac.cpp @@ -128,14 +128,16 @@ void InsetMathFrac::metrics(MetricsInfo & mi, Dimension & dim) const } } 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); - 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); @@ -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(), - y + dim_.des - 2, + y + dim.des - 2, 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, - x + dim_.wid - 2, y - 5, Color::math); + x + dim.wid - 2, y - 5, Color::math); 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 = dim_; } 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) - pain.horizontalLine(x, y, dim_.width()); + pain.horizontalLine(x, y, dim.width()); } diff --git a/src/mathed/InsetMathFrameBox.cpp b/src/mathed/InsetMathFrameBox.cpp index af0f059262..5123e17646 100644 --- a/src/mathed/InsetMathFrameBox.cpp +++ b/src/mathed/InsetMathFrameBox.cpp @@ -40,15 +40,17 @@ void InsetMathFrameBox::metrics(MetricsInfo & mi, Dimension & dim) const 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"); - 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("[")); diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index 098e173d8d..99bb9ded1d 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -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); @@ -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(); - dim_.asc = - rowinfo_[0].offset_ + dim.asc = - rowinfo_[0].offset_ + 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(); @@ -501,14 +501,9 @@ void InsetMathGrid::metrics(MetricsInfo & mi) const 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); } + 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)); @@ -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, - x + dim_.width() - rmargin - 1, yy, + x + dim.width() - rmargin - 1, yy, 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; - 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); diff --git a/src/mathed/InsetMathGrid.h b/src/mathed/InsetMathGrid.h index 92d71aab10..4bea98172c 100644 --- a/src/mathed/InsetMathGrid.h +++ b/src/mathed/InsetMathGrid.h @@ -100,8 +100,6 @@ public: /// 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; diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index 2857d3dcf5..f858281064 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -290,7 +290,8 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const dim.wid += 1; if (display()) dim.des += displayMargin(); - dim_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); 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); - 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); + 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)) - 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 diff --git a/src/mathed/InsetMathLefteqn.cpp b/src/mathed/InsetMathLefteqn.cpp index dc64e6f7df..358ecd3f0c 100644 --- a/src/mathed/InsetMathLefteqn.cpp +++ b/src/mathed/InsetMathLefteqn.cpp @@ -35,7 +35,8 @@ void InsetMathLefteqn::metrics(MetricsInfo & mi, Dimension & dim) const dim.des += 2; dim.wid = 4; metricsMarkers(dim); - dim_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); } diff --git a/src/mathed/InsetMathMakebox.cpp b/src/mathed/InsetMathMakebox.cpp index 7e7e83baa3..4ab87db31f 100644 --- a/src/mathed/InsetMathMakebox.cpp +++ b/src/mathed/InsetMathMakebox.cpp @@ -41,7 +41,8 @@ void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const dim += cell(2).dim(); dim.wid += 4 * w_ + 4; metricsMarkers(dim); - dim_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); } diff --git a/src/mathed/InsetMathNest.h b/src/mathed/InsetMathNest.h index 31f12c21c1..3e8e1a7087 100644 --- a/src/mathed/InsetMathNest.h +++ b/src/mathed/InsetMathNest.h @@ -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; - /// - Dimension const dimension(BufferView const &) const { return dim_; }; /// 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_; - /// Cached dimensions of the inset. - mutable Dimension dim_; }; diff --git a/src/mathed/InsetMathOverset.cpp b/src/mathed/InsetMathOverset.cpp index 3cbf7a28c4..82b80d7d43 100644 --- a/src/mathed/InsetMathOverset.cpp +++ b/src/mathed/InsetMathOverset.cpp @@ -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_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); } 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); diff --git a/src/mathed/InsetMathPar.cpp b/src/mathed/InsetMathPar.cpp index 4466e13bb6..38fc9bfc43 100644 --- a/src/mathed/InsetMathPar.cpp +++ b/src/mathed/InsetMathPar.cpp @@ -27,8 +27,7 @@ InsetMathPar::InsetMathPar(MathData const & ar) void InsetMathPar::metrics(MetricsInfo & mi, Dimension & dim) const { FontSetChanger dummy1(mi.base, "textnormal"); - InsetMathGrid::metrics(mi); - dim = dim_; + InsetMathGrid::metrics(mi, dim); } diff --git a/src/mathed/InsetMathPhantom.cpp b/src/mathed/InsetMathPhantom.cpp index b4649bb83c..8448ff7246 100644 --- a/src/mathed/InsetMathPhantom.cpp +++ b/src/mathed/InsetMathPhantom.cpp @@ -39,7 +39,8 @@ void InsetMathPhantom::metrics(MetricsInfo & mi, Dimension & dim) const { 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); + Dimension const dim = dimension(*pi.base.bv); if (kind_ == phantom || kind_ == vphantom) { // y1--------- @@ -66,13 +68,13 @@ void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const // / | \. // 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 y1 = y - dim_.asc; + int const y1 = y - dim.asc; 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 @@ -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 x4 = x + dim_.wid; + int const x4 = x + dim.wid; 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; diff --git a/src/mathed/InsetMathRoot.cpp b/src/mathed/InsetMathRoot.cpp index 90243eeeb1..f1318ab03d 100644 --- a/src/mathed/InsetMathRoot.cpp +++ b/src/mathed/InsetMathRoot.cpp @@ -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_ = 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); - 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]; - 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; diff --git a/src/mathed/InsetMathScript.cpp b/src/mathed/InsetMathScript.cpp index ad39adfb95..6145628247 100644 --- a/src/mathed/InsetMathScript.cpp +++ b/src/mathed/InsetMathScript.cpp @@ -240,23 +240,26 @@ int InsetMathScript::dy1() const } -int InsetMathScript::dx0() const +int InsetMathScript::dx0(BufferView const & bv) const { 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()); - 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); - dim_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); } 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 { - nuc().setXY(*pi.base.bv, x + dxx(), y); + nuc().setXY(*pi.base.bv, x + dxx(*pi.base.bv), y); 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()) - up().draw(pi, x + dx1(), y - dy1()); + up().draw(pi, x + dx1(*pi.base.bv), y - dy1()); if (hasDown()) - down().draw(pi, x + dx0(), y + dy0()); + down().draw(pi, x + dx0(*pi.base.bv), y + dy0()); 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()) - nuc().drawT(pain, x + dxx(), y); + nuc().drawT(pain, x + 1, y); if (hasUp()) - up().drawT(pain, x + dx1(), y - dy1()); + up().drawT(pain, x + 1, y - dy1()); if (hasDown()) - down().drawT(pain, x + dx0(), y + dy0()); + down().drawT(pain, x + 1, y + dy0()); } diff --git a/src/mathed/InsetMathScript.h b/src/mathed/InsetMathScript.h index 32abf34fa4..e705ea6ebf 100644 --- a/src/mathed/InsetMathScript.h +++ b/src/mathed/InsetMathScript.h @@ -107,7 +107,7 @@ protected: 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 @@ -117,9 +117,9 @@ private: /// 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 - int dx1() const; + int dx1(BufferView const & bv) const; /// returns ascent of nucleus if any int nasc() const; /// returns descent of nucleus if any diff --git a/src/mathed/InsetMathSize.cpp b/src/mathed/InsetMathSize.cpp index 7b591e7eb1..e520b4ea6d 100644 --- a/src/mathed/InsetMathSize.cpp +++ b/src/mathed/InsetMathSize.cpp @@ -37,7 +37,8 @@ void InsetMathSize::metrics(MetricsInfo & mi, Dimension & dim) const StyleChanger dummy(mi.base, style_); cell(0).metrics(mi, dim); metricsMarkers(dim); - dim_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); } diff --git a/src/mathed/InsetMathSqrt.cpp b/src/mathed/InsetMathSqrt.cpp index 1157dd8b6f..2528b26532 100644 --- a/src/mathed/InsetMathSqrt.cpp +++ b/src/mathed/InsetMathSqrt.cpp @@ -38,19 +38,21 @@ void InsetMathSqrt::metrics(MetricsInfo & mi, Dimension & dim) const 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); - 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]; - 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; diff --git a/src/mathed/InsetMathStackrel.cpp b/src/mathed/InsetMathStackrel.cpp index 7b4fbef5ef..953b62ba41 100644 --- a/src/mathed/InsetMathStackrel.cpp +++ b/src/mathed/InsetMathStackrel.cpp @@ -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_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); } 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); diff --git a/src/mathed/InsetMathSubstack.cpp b/src/mathed/InsetMathSubstack.cpp index 743e509bb3..bea27a0231 100644 --- a/src/mathed/InsetMathSubstack.cpp +++ b/src/mathed/InsetMathSubstack.cpp @@ -48,7 +48,6 @@ void InsetMathSubstack::metrics(MetricsInfo & mi, Dimension & dim) const } else { InsetMathGrid::metrics(mi, dim); } - dim_ = dim; } diff --git a/src/mathed/InsetMathSymbol.cpp b/src/mathed/InsetMathSymbol.cpp index 6703913616..fa7f3a0ca7 100644 --- a/src/mathed/InsetMathSymbol.cpp +++ b/src/mathed/InsetMathSymbol.cpp @@ -84,8 +84,7 @@ void InsetMathSymbol::metrics(MetricsInfo & mi, Dimension & dim) const scriptable_ = true; // Cache the inset dimension. - // FIXME: put the resulting dim in BufferView. - dim_ = dim; + setDimCache(mi, dim); } diff --git a/src/mathed/InsetMathSymbol.h b/src/mathed/InsetMathSymbol.h index 3068d943ab..bc33d2481a 100644 --- a/src/mathed/InsetMathSymbol.h +++ b/src/mathed/InsetMathSymbol.h @@ -35,8 +35,6 @@ public: /// 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_; } @@ -83,8 +81,6 @@ private: mutable int kerning_; /// mutable bool scriptable_; - /// FIXME: move this out to BufferView - mutable Dimension dim_; }; } // namespace lyx diff --git a/src/mathed/InsetMathTFrac.cpp b/src/mathed/InsetMathTFrac.cpp index 29c4d40c89..c375e68020 100644 --- a/src/mathed/InsetMathTFrac.cpp +++ b/src/mathed/InsetMathTFrac.cpp @@ -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_ = 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); - 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); - 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); } diff --git a/src/mathed/InsetMathTabular.cpp b/src/mathed/InsetMathTabular.cpp index 5231e01aff..e7309fb026 100644 --- a/src/mathed/InsetMathTabular.cpp +++ b/src/mathed/InsetMathTabular.cpp @@ -51,7 +51,14 @@ void InsetMathTabular::metrics(MetricsInfo & mi, Dimension & dim) const 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; } diff --git a/src/mathed/InsetMathTabular.h b/src/mathed/InsetMathTabular.h index 2dfc3f51bb..d6c5bbac15 100644 --- a/src/mathed/InsetMathTabular.h +++ b/src/mathed/InsetMathTabular.h @@ -31,6 +31,8 @@ public: /// 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; } diff --git a/src/mathed/InsetMathUnderset.cpp b/src/mathed/InsetMathUnderset.cpp index 499986a1ff..f213b80cb0 100644 --- a/src/mathed/InsetMathUnderset.cpp +++ b/src/mathed/InsetMathUnderset.cpp @@ -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_ = dim; + // Cache the inset dimension. + setDimCache(mi, dim); } 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); diff --git a/src/mathed/InsetMathXArrow.cpp b/src/mathed/InsetMathXArrow.cpp index 55ad252ddb..886c8a6e7f 100644 --- a/src/mathed/InsetMathXArrow.cpp +++ b/src/mathed/InsetMathXArrow.cpp @@ -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_ = 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()); - 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); } diff --git a/src/mathed/InsetMathXYMatrix.cpp b/src/mathed/InsetMathXYMatrix.cpp index 391e52dddd..5e1151ce66 100644 --- a/src/mathed/InsetMathXYMatrix.cpp +++ b/src/mathed/InsetMathXYMatrix.cpp @@ -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); - dim_ = dim; } diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp index 616c1bd4e7..8711cc6999 100644 --- a/src/mathed/MathMacro.cpp +++ b/src/mathed/MathMacro.cpp @@ -142,7 +142,8 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const 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")); - 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); diff --git a/src/mathed/MathMacroTemplate.cpp b/src/mathed/MathMacroTemplate.cpp index a7e9112a6f..923276fabc 100644 --- a/src/mathed/MathMacroTemplate.cpp +++ b/src/mathed/MathMacroTemplate.cpp @@ -126,7 +126,8 @@ void MathMacroTemplate::metrics(MetricsInfo & mi, Dimension & dim) const 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); + Dimension const dim = dimension(*p.base.bv); + // 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; - 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! @@ -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); - 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); - 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(); -- 2.39.5