X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FMathRow.cpp;h=3263d1c48315f373bd04cd5c642a236839de0e40;hb=ad79ac406f9c8fc85880cfeb5416b0299ee9a617;hp=cfb41642d476d6506cb30f797fa4d7cf6403c8e1;hpb=ce8929e9b237af569934b434154d199634363268;p=lyx.git diff --git a/src/mathed/MathRow.cpp b/src/mathed/MathRow.cpp index cfb41642d4..3263d1c483 100644 --- a/src/mathed/MathRow.cpp +++ b/src/mathed/MathRow.cpp @@ -15,7 +15,6 @@ #include "InsetMath.h" #include "MathClass.h" #include "MathData.h" -#include "MathMacro.h" #include "MathSupport.h" #include "BufferView.h" @@ -38,8 +37,8 @@ namespace lyx { MathRow::Element::Element(MetricsInfo const & mi, Type t, MathClass mc) : type(t), mclass(mc), before(0), after(0), macro_nesting(mi.base.macro_nesting), - marker(InsetMath::NO_MARKER), inset(0), compl_unique_to(0), - macro(0), color(Color_red) + marker(InsetMath::NO_MARKER), inset(0), compl_unique_to(0), ar(0), + color(Color_red) {} @@ -51,10 +50,10 @@ MathRow::MathRow(MetricsInfo & mi, MathData const * ar) // Then insert the MathData argument bool const has_contents = ar->addToMathRow(*this, mi); - // empty arrays are visible when they are editable - // we reserve the necessary space anyway (even if nothing gets drawn) + // A MathRow should not be completely empty if (!has_contents) { Element e(mi, BOX, MC_ORD); + // empty arrays are visible when they are editable e.color = mi.base.macro_nesting == 0 ? Color_mathline : Color_none; push_back(e); } @@ -133,8 +132,8 @@ void MathRow::metrics(MetricsInfo & mi, Dimension & dim) const dim.wid = 0; // In order to compute the dimension of macros and their // arguments, it is necessary to keep track of them. - map dim_macros; - map dim_arrays; + vector> dim_insets; + vector> dim_arrays; CoordCache & coords = mi.base.bv->coordCache(); for (Element const & e : elements_) { mi.base.macro_nesting = e.macro_nesting; @@ -147,35 +146,36 @@ void MathRow::metrics(MetricsInfo & mi, Dimension & dim) const d.wid += e.before + e.after; coords.insets().add(e.inset, d); break; - case BEG_MACRO: - e.macro->macro()->lock(); - // Add a macro to current list - dim_macros[e.macro] = Dimension(); + case BEGIN: + if (e.inset) { + dim_insets.push_back(make_pair(e.inset, Dimension())); + e.inset->beforeMetrics(); + } + if (e.ar) + dim_arrays.push_back(make_pair(e.ar, Dimension())); break; - case END_MACRO: - LATTEST(dim_macros.find(e.macro) != dim_macros.end()); - e.macro->macro()->unlock(); - // Cache the dimension of the macro and remove it from - // tracking map. - coords.insets().add(e.macro, dim_macros[e.macro]); - dim_macros.erase(e.macro); - break; - // This is basically like macros - case BEG_ARG: - if (e.macro) - e.macro->macro()->unlock(); - dim_arrays[e.ar] = Dimension(); - break; - case END_ARG: - LATTEST(dim_arrays.find(e.ar) != dim_arrays.end()); - if (e.macro) - e.macro->macro()->lock(); - coords.arrays().add(e.ar, dim_arrays[e.ar]); - dim_arrays.erase(e.ar); + case END: + if (e.inset) { + e.inset->afterMetrics(); + LATTEST(dim_insets.back().first == e.inset); + coords.insets().add(e.inset, dim_insets.back().second); + dim_insets.pop_back(); + } + if (e.ar) { + LATTEST(dim_arrays.back().first == e.ar); + coords.arrays().add(e.ar, dim_arrays.back().second); + dim_arrays.pop_back(); + } break; case BOX: d = theFontMetrics(mi.base.font).dimension('I'); - d.wid += e.before + e.after; + if (e.color != Color_none) { + // allow for one pixel before/after the box. + d.wid += e.before + e.after + 2; + } else { + // hide the box, but give it some height + d.wid = 0; + } break; } @@ -194,7 +194,7 @@ void MathRow::metrics(MetricsInfo & mi, Dimension & dim) const if (!d.empty()) { dim += d; // Now add the dimension to current macros and arguments. - for (auto & dim_macro : dim_macros) + for (auto & dim_macro : dim_insets) dim_macro.second += d; for (auto & dim_array : dim_arrays) dim_array.second += d; @@ -206,7 +206,7 @@ void MathRow::metrics(MetricsInfo & mi, Dimension & dim) const augmentFont(font, "mathnormal"); dim.wid += mathed_string_width(font, e.compl_text); } - LATTEST(dim_macros.empty() && dim_arrays.empty()); + LATTEST(dim_insets.empty() && dim_arrays.empty()); } @@ -268,33 +268,29 @@ void MathRow::draw(PainterInfo & pi, int x, int const y) const x += d.wid; break; } - case BEG_MACRO: - coords.insets().add(e.macro, x, y); - - drawMarkers(pi, e, x, y); - break; - case BEG_ARG: - coords.arrays().add(e.ar, x, y); - // if the macro is being edited, then the painter is in - // monochrome mode. - if (e.macro->editMetrics(pi.base.bv)) - pi.pain.leaveMonochromeMode(); + case BEGIN: + if (e.inset) { + coords.insets().add(e.inset, x, y); + drawMarkers(pi, e, x, y); + e.inset->beforeDraw(pi); + } + if (e.ar) + coords.arrays().add(e.ar, x, y); break; - case END_ARG: - if (e.macro->editMetrics(pi.base.bv)) - pi.pain.enterMonochromeMode(Color_mathbg, Color_mathmacroblend); + case END: + if (e.inset) + e.inset->afterDraw(pi); break; case BOX: { + if (e.color == Color_none) + break; Dimension const d = theFontMetrics(pi.base.font).dimension('I'); - // the box is not visible in non-editable context (except for grey macro boxes). - if (e.color != Color_none) - pi.pain.rectangle(x + e.before, y - d.ascent(), - d.width(), d.height(), e.color); - x += d.wid + e.before + e.after; + pi.pain.rectangle(x + e.before + 1, y - d.ascent(), + d.width() - 1, d.height() - 1, e.color); + x += d.wid + 2 + e.before + e.after; break; } case DUMMY: - case END_MACRO: break; } @@ -343,18 +339,18 @@ ostream & operator<<(ostream & os, MathRow::Element const & e) << to_utf8(class_to_string(e.mclass)) << "-" << e.after << ">"; break; - case MathRow::BEG_MACRO: - os << "\\" << to_utf8(e.macro->name()) - << "^" << e.macro->nesting() << "["; - break; - case MathRow::END_MACRO: - os << "]"; - break; - case MathRow::BEG_ARG: - os << "#("; + case MathRow::BEGIN: + if (e.inset) + os << "\\" << to_utf8(e.inset->name()) + << "^" << e.macro_nesting << "["; + if (e.ar) + os << "("; break; - case MathRow::END_ARG: - os << ")"; + case MathRow::END: + if (e.ar) + os << ")"; + if (e.inset) + os << "]"; break; case MathRow::BOX: os << "<" << e.before << "-[]-" << e.after << ">";