The branch, betterspacing, has been updated. - Log -----------------------------------------------------------------
commit 26101ac62b9b23e12e1d4944d1cd8285ed5257e9 Author: Jean-Marc Lasgouttes <[email protected]> Date: Mon Nov 14 18:01:56 2016 +0100 Skip drawing of markers in non-editable math data There is no reason to reserve pixel space in macros replacement text, which is not editable. This makes macros more compact and eases the writing of lib/symbols. * introduce new InsetMath::drawMarkers and friends that do nothing when nested inside a macro. This required to move macro_nesting inside MetricsBase, and to pass MetricsInfo & to metricsMarkers. * keep track of nesting when drawing rows or macros. diff --git a/src/MetricsInfo.cpp b/src/MetricsInfo.cpp index 02bbab3..fdde05f 100644 --- a/src/MetricsInfo.cpp +++ b/src/MetricsInfo.cpp @@ -38,8 +38,8 @@ namespace lyx { MetricsBase::MetricsBase(BufferView * b, FontInfo f, int w) : bv(b), font(move(f)), style(LM_ST_TEXT), fontname("mathnormal"), - textwidth(w), solid_line_thickness_(1), solid_line_offset_(1), - dotted_line_thickness_(1) + textwidth(w), macro_nesting(0), + solid_line_thickness_(1), solid_line_offset_(1), dotted_line_thickness_(1) { if (lyxrc.zoom >= 200) { // derive the line thickness from zoom factor @@ -88,7 +88,7 @@ Changer MetricsBase::changeFontSet(string const & name, bool cond) MetricsInfo::MetricsInfo(BufferView * bv, FontInfo font, int textwidth, MacroContext const & mc) - : base(bv, font, textwidth), macro_nesting(0), macrocontext(mc) + : base(bv, font, textwidth), macrocontext(mc) {} diff --git a/src/MetricsInfo.h b/src/MetricsInfo.h index 415fe25..a48b45c 100644 --- a/src/MetricsInfo.h +++ b/src/MetricsInfo.h @@ -65,6 +65,8 @@ public: std::string fontname; /// This is the width available in pixels int textwidth; + /// count wether the current mathdata is nested in macro(s) + int macro_nesting; /// Temporarily change a full font. Changer changeFontSet(std::string const & font, bool cond = true); @@ -101,8 +103,6 @@ public: /// MetricsBase base; - /// count wether the current mathdata is nested in macro(s) - int macro_nesting; /// The context to resolve macros MacroContext const & macrocontext; }; diff --git a/src/mathed/InsetMath.cpp b/src/mathed/InsetMath.cpp index d2182a5..cbf33cd 100644 --- a/src/mathed/InsetMath.cpp +++ b/src/mathed/InsetMath.cpp @@ -16,13 +16,15 @@ #include "MathRow.h" #include "MathStream.h" +#include "MetricsInfo.h" + #include "support/debug.h" #include "support/docstream.h" #include "support/gettext.h" +#include "support/lassert.h" #include "support/lstrings.h" #include "support/textutils.h" -#include "support/lassert.h" using namespace std; @@ -65,6 +67,36 @@ bool InsetMath::addToMathRow(MathRow & mrow, MetricsInfo & mi) const return true; } +void InsetMath::metricsMarkers(MetricsInfo & mi, Dimension & dim, + int framesize) const +{ + if (!mi.base.macro_nesting) + Inset::metricsMarkers(dim, framesize); +} + + +void InsetMath::metricsMarkers2(MetricsInfo & mi, Dimension & dim, + int framesize) const +{ + if (!mi.base.macro_nesting) + Inset::metricsMarkers2(dim, framesize); +} + + +void InsetMath::drawMarkers(PainterInfo & pi, int x, int y) const +{ + if (!pi.base.macro_nesting) + Inset::drawMarkers(pi, x, y); +} + + +void InsetMath::drawMarkers2(PainterInfo & pi, int x, int y) const +{ + if (!pi.base.macro_nesting) + Inset::drawMarkers2(pi, x, y); +} + + void InsetMath::dump() const { diff --git a/src/mathed/InsetMath.h b/src/mathed/InsetMath.h index f9c0735..9d6368a 100644 --- a/src/mathed/InsetMath.h +++ b/src/mathed/InsetMath.h @@ -170,6 +170,15 @@ public: /// Add this inset to a math row. Return true if contents got added virtual bool addToMathRow(MathRow &, MetricsInfo & mi) const; + /// draw four angular markers + void drawMarkers(PainterInfo & pi, int x, int y) const; + /// draw two angular markers + void drawMarkers2(PainterInfo & pi, int x, int y) const; + /// add space for markers + void metricsMarkers(MetricsInfo & mi, Dimension & dim, int framesize = 1) const; + /// add space for markers + void metricsMarkers2(MetricsInfo & mi, Dimension & dim, int framesize = 1) const; + /// identifies things that can get scripts virtual bool isScriptable() const { return false; } /// will this get written as a single block in {..} diff --git a/src/mathed/InsetMathBoldSymbol.cpp b/src/mathed/InsetMathBoldSymbol.cpp index 215bd5f..ade29f7 100644 --- a/src/mathed/InsetMathBoldSymbol.cpp +++ b/src/mathed/InsetMathBoldSymbol.cpp @@ -51,7 +51,7 @@ void InsetMathBoldSymbol::metrics(MetricsInfo & mi, Dimension & dim) const { //Changer dummy = mi.base.changeFontSet("mathbf"); cell(0).metrics(mi, dim); - metricsMarkers(dim); + metricsMarkers(mi, dim); ++dim.wid; // for 'double stroke' } diff --git a/src/mathed/InsetMathBox.cpp b/src/mathed/InsetMathBox.cpp index e9e483c..d0ac82f 100644 --- a/src/mathed/InsetMathBox.cpp +++ b/src/mathed/InsetMathBox.cpp @@ -83,7 +83,7 @@ void InsetMathBox::metrics(MetricsInfo & mi, Dimension & dim) const { Changer dummy = mi.base.changeFontSet("textnormal"); cell(0).metrics(mi, dim); - metricsMarkers(dim); + metricsMarkers(mi, dim); } @@ -135,7 +135,7 @@ void InsetMathFBox::metrics(MetricsInfo & mi, Dimension & dim) const { Changer dummy = mi.base.changeFontSet("textnormal"); cell(0).metrics(mi, dim); - metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space + metricsMarkers2(mi, dim, 3); // 1 pixel space, 1 frame, 1 space } @@ -246,7 +246,7 @@ void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const dim.des += 1; } - metricsMarkers(dim); + metricsMarkers(mi, dim); } @@ -360,7 +360,7 @@ InsetMathBoxed::InsetMathBoxed(Buffer * buf) void InsetMathBoxed::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi, dim); - metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space + metricsMarkers2(mi, dim, 3); // 1 pixel space, 1 frame, 1 space } diff --git a/src/mathed/InsetMathBrace.cpp b/src/mathed/InsetMathBrace.cpp index 52ccc01..6870fa6 100644 --- a/src/mathed/InsetMathBrace.cpp +++ b/src/mathed/InsetMathBrace.cpp @@ -55,7 +55,7 @@ void InsetMathBrace::metrics(MetricsInfo & mi, Dimension & dim) const dim.asc = max(dim0.asc, t.asc); dim.des = max(dim0.des, t.des); dim.wid = dim0.width() + 2 * t.wid; - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathCancel.cpp b/src/mathed/InsetMathCancel.cpp index dcda5b6..0a8aad9 100644 --- a/src/mathed/InsetMathCancel.cpp +++ b/src/mathed/InsetMathCancel.cpp @@ -38,7 +38,7 @@ Inset * InsetMathCancel::clone() const void InsetMathCancel::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi, dim); - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathCancelto.cpp b/src/mathed/InsetMathCancelto.cpp index 6a04cfa..6170cbd 100644 --- a/src/mathed/InsetMathCancelto.cpp +++ b/src/mathed/InsetMathCancelto.cpp @@ -47,7 +47,7 @@ void InsetMathCancelto::metrics(MetricsInfo & mi, Dimension & dim) const dim.asc = max(dim0.ascent() + 2, dim0.ascent() + dim1.ascent()) + 2 + 8; dim.des = max(dim0.descent() - 2, dim1.descent()) + 2; dim.wid = dim0.width() + dim1.width() + 10; - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathClass.cpp b/src/mathed/InsetMathClass.cpp index 10a9600..8d73867 100644 --- a/src/mathed/InsetMathClass.cpp +++ b/src/mathed/InsetMathClass.cpp @@ -31,7 +31,7 @@ Inset * InsetMathClass::clone() const void InsetMathClass::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi, dim); - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathColor.cpp b/src/mathed/InsetMathColor.cpp index 0a6d0aa..966fe5e 100644 --- a/src/mathed/InsetMathColor.cpp +++ b/src/mathed/InsetMathColor.cpp @@ -49,7 +49,7 @@ Inset * InsetMathColor::clone() const void InsetMathColor::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi, dim); - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathComment.cpp b/src/mathed/InsetMathComment.cpp index ff91991..b8c157b 100644 --- a/src/mathed/InsetMathComment.cpp +++ b/src/mathed/InsetMathComment.cpp @@ -50,7 +50,7 @@ Inset * InsetMathComment::clone() const void InsetMathComment::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi, dim); - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathDecoration.cpp b/src/mathed/InsetMathDecoration.cpp index cd34d4d..acc4974 100644 --- a/src/mathed/InsetMathDecoration.cpp +++ b/src/mathed/InsetMathDecoration.cpp @@ -122,7 +122,7 @@ void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const dim.des += dh_ + 2; } - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathEnsureMath.cpp b/src/mathed/InsetMathEnsureMath.cpp index d1e69fb..382c6fe 100644 --- a/src/mathed/InsetMathEnsureMath.cpp +++ b/src/mathed/InsetMathEnsureMath.cpp @@ -41,7 +41,7 @@ void InsetMathEnsureMath::metrics(MetricsInfo & mi, Dimension & dim) const bool really_change_font = isTextFont(mi.base.fontname); Changer dummy = mi.base.changeFontSet("mathnormal", really_change_font); cell(0).metrics(mi, dim); - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathEnv.cpp b/src/mathed/InsetMathEnv.cpp index cc613fd..7582201 100644 --- a/src/mathed/InsetMathEnv.cpp +++ b/src/mathed/InsetMathEnv.cpp @@ -39,7 +39,7 @@ Inset * InsetMathEnv::clone() const void InsetMathEnv::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi, dim); - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathFont.cpp b/src/mathed/InsetMathFont.cpp index 40623f6..825cf33 100644 --- a/src/mathed/InsetMathFont.cpp +++ b/src/mathed/InsetMathFont.cpp @@ -86,7 +86,7 @@ void InsetMathFont::metrics(MetricsInfo & mi, Dimension & dim) const { Changer dummy = mi.base.changeFontSet(font()); cell(0).metrics(mi, dim); - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathFontOld.cpp b/src/mathed/InsetMathFontOld.cpp index 20f3b1d..aa574bd 100644 --- a/src/mathed/InsetMathFontOld.cpp +++ b/src/mathed/InsetMathFontOld.cpp @@ -61,7 +61,7 @@ void InsetMathFontOld::metrics(MetricsInfo & mi, Dimension & dim) const Changer dummy = mi.base.changeFontSet(fontname, really_change_font); cell(0).metrics(mi, dim); - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathFrac.cpp b/src/mathed/InsetMathFrac.cpp index 263587e..6254924 100644 --- a/src/mathed/InsetMathFrac.cpp +++ b/src/mathed/InsetMathFrac.cpp @@ -207,7 +207,7 @@ void InsetMathFrac::metrics(MetricsInfo & mi, Dimension & dim) const dim.des = dim1.height() + 2 - 5; } } - metricsMarkers(dim); + metricsMarkers(mi, dim); } @@ -582,7 +582,7 @@ void InsetMathBinom::metrics(MetricsInfo & mi, Dimension & dim) const dim.asc = dim0.height() + 4 + 5; dim.des = dim1.height() + 4 - 5; dim.wid = max(dim0.wid, dim1.wid) + 2 * dw(dim.height()) + 4; - metricsMarkers2(dim); + metricsMarkers2(mi, dim); } diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index 053958d..fca8f38 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -588,7 +588,7 @@ void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const } */ dim.wid += leftMargin() + rightMargin(); - metricsMarkers2(dim); + metricsMarkers2(mi, dim); // Cache the inset dimension. setDimCache(mi, dim); } diff --git a/src/mathed/InsetMathLefteqn.cpp b/src/mathed/InsetMathLefteqn.cpp index ec4fe7e..176c743 100644 --- a/src/mathed/InsetMathLefteqn.cpp +++ b/src/mathed/InsetMathLefteqn.cpp @@ -34,7 +34,7 @@ void InsetMathLefteqn::metrics(MetricsInfo & mi, Dimension & dim) const dim.asc += 2; dim.des += 2; dim.wid = 4; - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathOverset.cpp b/src/mathed/InsetMathOverset.cpp index f05bbd7..b791c24 100644 --- a/src/mathed/InsetMathOverset.cpp +++ b/src/mathed/InsetMathOverset.cpp @@ -39,7 +39,7 @@ void InsetMathOverset::metrics(MetricsInfo & mi, Dimension & dim) const dim.wid = max(dim0.width(), dim1.wid) + 4; dim.asc = dim1.asc + dim0.height() + 4; dim.des = dim1.des; - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathPhantom.cpp b/src/mathed/InsetMathPhantom.cpp index 4a190ea..6d0b88d 100644 --- a/src/mathed/InsetMathPhantom.cpp +++ b/src/mathed/InsetMathPhantom.cpp @@ -39,7 +39,7 @@ Inset * InsetMathPhantom::clone() const void InsetMathPhantom::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi, dim); - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathRoot.cpp b/src/mathed/InsetMathRoot.cpp index 2b4b668..aa0a81b 100644 --- a/src/mathed/InsetMathRoot.cpp +++ b/src/mathed/InsetMathRoot.cpp @@ -47,7 +47,7 @@ void InsetMathRoot::metrics(MetricsInfo & mi, Dimension & dim) const dim.asc = max(dim0.ascent() + 5, dim1.ascent()) + 2; dim.des = max(dim0.descent() - 5, dim1.descent()) + 2; dim.wid = dim0.width() + dim1.width() + 10; - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathScript.cpp b/src/mathed/InsetMathScript.cpp index 91c4ad4..4ea4aa3 100644 --- a/src/mathed/InsetMathScript.cpp +++ b/src/mathed/InsetMathScript.cpp @@ -333,7 +333,7 @@ void InsetMathScript::metrics(MetricsInfo & mi, Dimension & dim) const dim.des = max(nd, des); } else dim.des = nd; - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathSideset.cpp b/src/mathed/InsetMathSideset.cpp index 37f437d..b04eca7 100644 --- a/src/mathed/InsetMathSideset.cpp +++ b/src/mathed/InsetMathSideset.cpp @@ -221,7 +221,7 @@ void InsetMathSideset::metrics(MetricsInfo & mi, Dimension & dim) const int nd = ndes(bv); int des = dyb(bv) + max(dimbl.descent(), dimbr.descent()); dim.des = max(nd, des); - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathSize.cpp b/src/mathed/InsetMathSize.cpp index 31cdb6a..46ea29b 100644 --- a/src/mathed/InsetMathSize.cpp +++ b/src/mathed/InsetMathSize.cpp @@ -45,7 +45,7 @@ void InsetMathSize::metrics(MetricsInfo & mi, Dimension & dim) const { Changer dummy = mi.base.changeStyle(style_); cell(0).metrics(mi, dim); - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathSqrt.cpp b/src/mathed/InsetMathSqrt.cpp index d04eab3..3e49abc 100644 --- a/src/mathed/InsetMathSqrt.cpp +++ b/src/mathed/InsetMathSqrt.cpp @@ -41,7 +41,7 @@ void InsetMathSqrt::metrics(MetricsInfo & mi, Dimension & dim) const dim.asc += 4; dim.des += 2; dim.wid += 12; - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathStackrel.cpp b/src/mathed/InsetMathStackrel.cpp index 3dda0da..e34448a 100644 --- a/src/mathed/InsetMathStackrel.cpp +++ b/src/mathed/InsetMathStackrel.cpp @@ -77,7 +77,7 @@ void InsetMathStackrel::metrics(MetricsInfo & mi, Dimension & dim) const dim.asc = dim1.ascent() + dim0.height() + 4; dim.des = dim1.descent(); } - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathUnderset.cpp b/src/mathed/InsetMathUnderset.cpp index 46f5277..2027cf2 100644 --- a/src/mathed/InsetMathUnderset.cpp +++ b/src/mathed/InsetMathUnderset.cpp @@ -40,7 +40,7 @@ void InsetMathUnderset::metrics(MetricsInfo & mi, Dimension & dim) const dim.wid = max(dim0.width(), dim1.width()) + 4; dim.asc = dim1.ascent(); dim.des = dim1.descent() + dim0.height() + 4; - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/InsetMathXArrow.cpp b/src/mathed/InsetMathXArrow.cpp index 96fdc83..a4c1c12 100644 --- a/src/mathed/InsetMathXArrow.cpp +++ b/src/mathed/InsetMathXArrow.cpp @@ -51,7 +51,7 @@ void InsetMathXArrow::metrics(MetricsInfo & mi, Dimension & dim) const dim.wid = max(dim0.width(), dim1.width()) + 10; dim.asc = dim0.height() + 10; dim.des = dim1.height(); - metricsMarkers(dim); + metricsMarkers(mi, dim); } diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp index 8415181..708f30a 100644 --- a/src/mathed/MathMacro.cpp +++ b/src/mathed/MathMacro.cpp @@ -71,9 +71,9 @@ public: bool addToMathRow(MathRow & mrow, MetricsInfo & mi) const { // macro arguments are in macros - LATTEST(mi.macro_nesting > 0); - if (mi.macro_nesting == 1) - mi.macro_nesting = 0; + LATTEST(mi.base.macro_nesting > 0); + if (mi.base.macro_nesting == 1) + mi.base.macro_nesting = 0; MathRow::Element e_beg(MathRow::BEG_ARG, mi); e_beg.macro = mathMacro_; @@ -84,12 +84,12 @@ public: bool has_contents = mathMacro_->cell(idx_).addToMathRow(mrow, mi); mathMacro_->macro()->lock(); - if (mi.macro_nesting == 0) - mi.macro_nesting = 1; + if (mi.base.macro_nesting == 0) + mi.base.macro_nesting = 1; // if there was no contents, and the contents is editable, // then we insert a box instead. - if (!has_contents && mi.macro_nesting == 1) { + if (!has_contents && mi.base.macro_nesting == 1) { MathRow::Element e(MathRow::BOX, mi); e.color = Color_mathline; mrow.push_back(e); @@ -107,9 +107,9 @@ public: /// void metrics(MetricsInfo & mi, Dimension & dim) const { // macro arguments are in macros - LATTEST(mi.macro_nesting > 0); - if (mi.macro_nesting == 1) - mi.macro_nesting = 0; + LATTEST(mi.base.macro_nesting > 0); + if (mi.base.macro_nesting == 1) + mi.base.macro_nesting = 0; mathMacro_->macro()->unlock(); mathMacro_->cell(idx_).metrics(mi, dim); @@ -119,8 +119,8 @@ public: def_.metrics(mi, dim); mathMacro_->macro()->lock(); - if (mi.macro_nesting == 0) - mi.macro_nesting = 1; + if (mi.base.macro_nesting == 0) + mi.base.macro_nesting = 1; } // write(), normalize(), infoize() and infoize2() are not needed since // MathMacro uses the definition and not the expanded cells. @@ -138,6 +138,10 @@ public: void octave(OctaveStream & os) const { os << mathMacro_->cell(idx_); } /// void draw(PainterInfo & pi, int x, int y) const { + LATTEST(pi.base.macro_nesting > 0); + if (pi.base.macro_nesting == 1) + pi.base.macro_nesting = 0; + if (mathMacro_->editMetrics(pi.base.bv)) { // The only way a ArgumentProxy can appear is in a cell of the // MathMacro. Moreover the cells are only drawn in the DISPLAY_FOLDED @@ -155,6 +159,9 @@ public: def_.draw(pi, x, y); } else mathMacro_->cell(idx_).draw(pi, x, y); + + if (pi.base.macro_nesting == 0) + pi.base.macro_nesting = 1; } /// size_t idx() const { return idx_; } @@ -324,7 +331,7 @@ bool MathMacro::addToMathRow(MathRow & mrow, MetricsInfo & mi) const e_beg.macro = this; mrow.push_back(e_beg); - ++mi.macro_nesting; + ++mi.base.macro_nesting; d->macro_->lock(); bool has_contents = d->expanded_.addToMathRow(mrow, mi); @@ -332,14 +339,14 @@ bool MathMacro::addToMathRow(MathRow & mrow, MetricsInfo & mi) const // if there was no contents and the array is editable, then we // insert a grey box instead. - if (!has_contents && mi.macro_nesting == 1) { + if (!has_contents && mi.base.macro_nesting == 1) { MathRow::Element e(MathRow::BOX, mi); e.color = Color_mathmacroblend; mrow.push_back(e); has_contents = true; } - --mi.macro_nesting; + --mi.base.macro_nesting; MathRow::Element e_end(MathRow::END_MACRO, mi); e_end.macro = this; @@ -442,7 +449,7 @@ bool MathMacro::editMetrics(BufferView const * bv) const void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const { // the macro contents is not editable (except the arguments) - ++mi.macro_nesting; + ++mi.base.macro_nesting; // set edit mode for which we will have calculated metrics. But only d->editing_[mi.base.bv] = editMode(mi.base.bv); @@ -457,7 +464,7 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const dim.wid += bsdim.width() + 1; dim.asc = max(bsdim.ascent(), dim.ascent()); dim.des = max(bsdim.descent(), dim.descent()); - metricsMarkers(dim); + metricsMarkers(mi, dim); } else if (lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_LIST && d->editing_[mi.base.bv]) { // Macro will be edited in a old-style list mode here: @@ -497,7 +504,7 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const dim.asc += 1; dim.des += 1; dim.wid += 2; - metricsMarkers2(dim); + metricsMarkers2(mi, dim); } else { LBUFERR(d->macro_); @@ -534,7 +541,7 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const } // restore macro nesting - --mi.macro_nesting; + --mi.base.macro_nesting; } @@ -703,6 +710,9 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const dim.height() - 2, Color_mathmacroframe); drawMarkers2(pi, expx, expy); } else { + // the macro contents is not editable (except the arguments) + ++pi.base.macro_nesting; + bool drawBox = lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_INLINE_BOX; bool upshape = currentMode() == TEXT_MODE; Changer dummy = pi.base.font.changeShape(upshape ? UP_SHAPE @@ -737,8 +747,11 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const } else d->expanded_.draw(pi, expx, expy); + --pi.base.macro_nesting; + if (!drawBox) drawMarkers(pi, x, y); + } // edit mode changed? diff --git a/src/mathed/MathMacroTemplate.cpp b/src/mathed/MathMacroTemplate.cpp index cf74272..b4d1c1c 100644 --- a/src/mathed/MathMacroTemplate.cpp +++ b/src/mathed/MathMacroTemplate.cpp @@ -269,7 +269,7 @@ Inset * InsetMathWrapper::clone() const void InsetMathWrapper::metrics(MetricsInfo & mi, Dimension & dim) const { value_->metrics(mi, dim); - //metricsMarkers2(dim); + //metricsMarkers2(mi, dim); } diff --git a/src/mathed/MathRow.cpp b/src/mathed/MathRow.cpp index a5f440e..e3f727c 100644 --- a/src/mathed/MathRow.cpp +++ b/src/mathed/MathRow.cpp @@ -37,7 +37,7 @@ namespace lyx { MathRow::Element::Element(Type t, MetricsInfo &mi) - : type(t), macro_nesting(mi.macro_nesting), + : type(t), macro_nesting(mi.base.macro_nesting), inset(0), mclass(MC_ORD), before(0), after(0), compl_unique_to(0), macro(0), color(Color_red) {} @@ -128,7 +128,7 @@ void MathRow::metrics(MetricsInfo & mi, Dimension & dim) const CoordCache & coords = mi.base.bv->coordCache(); for (Element const & e : elements_) { Dimension d; - mi.macro_nesting = e.macro_nesting; + mi.base.macro_nesting = e.macro_nesting; switch (e.type) { case BEGIN: case END: @@ -193,6 +193,7 @@ void MathRow::draw(PainterInfo & pi, int x, int const y) const { CoordCache & coords = pi.base.bv->coordCache(); for (Element const & e : elements_) { + pi.base.macro_nesting = e.macro_nesting; switch (e.type) { case INSET: { coords.insets().add(e.inset, x, y); ----------------------------------------------------------------------- Summary of changes: src/MetricsInfo.cpp | 6 ++-- src/MetricsInfo.h | 4 +- src/mathed/InsetMath.cpp | 34 ++++++++++++++++++++++++- src/mathed/InsetMath.h | 9 ++++++ src/mathed/InsetMathBoldSymbol.cpp | 2 +- src/mathed/InsetMathBox.cpp | 8 +++--- src/mathed/InsetMathBrace.cpp | 2 +- src/mathed/InsetMathCancel.cpp | 2 +- src/mathed/InsetMathCancelto.cpp | 2 +- src/mathed/InsetMathClass.cpp | 2 +- src/mathed/InsetMathColor.cpp | 2 +- src/mathed/InsetMathComment.cpp | 2 +- src/mathed/InsetMathDecoration.cpp | 2 +- src/mathed/InsetMathEnsureMath.cpp | 2 +- src/mathed/InsetMathEnv.cpp | 2 +- src/mathed/InsetMathFont.cpp | 2 +- src/mathed/InsetMathFontOld.cpp | 2 +- src/mathed/InsetMathFrac.cpp | 4 +- src/mathed/InsetMathGrid.cpp | 2 +- src/mathed/InsetMathLefteqn.cpp | 2 +- src/mathed/InsetMathOverset.cpp | 2 +- src/mathed/InsetMathPhantom.cpp | 2 +- src/mathed/InsetMathRoot.cpp | 2 +- src/mathed/InsetMathScript.cpp | 2 +- src/mathed/InsetMathSideset.cpp | 2 +- src/mathed/InsetMathSize.cpp | 2 +- src/mathed/InsetMathSqrt.cpp | 2 +- src/mathed/InsetMathStackrel.cpp | 2 +- src/mathed/InsetMathUnderset.cpp | 2 +- src/mathed/InsetMathXArrow.cpp | 2 +- src/mathed/MathMacro.cpp | 49 ++++++++++++++++++++++------------- src/mathed/MathMacroTemplate.cpp | 2 +- src/mathed/MathRow.cpp | 5 ++- 33 files changed, 112 insertions(+), 57 deletions(-) hooks/post-receive -- Repository for new features
