virtual MathClass mathClass() const;
/// Add this inset to a math row. Return true if contents got added
virtual bool addToMathRow(MathRow &, MetricsInfo & mi) const;
+ /// Hook that is run before metrics computation starts
+ virtual void beforeMetrics() const {}
+ /// Hook that is run after metrics computation
+ virtual void afterMetrics() const {}
+ /// Hook that is run before actual drawing
+ virtual void beforeDraw(PainterInfo const &) const {}
+ /// Hook that is run after drawing
+ virtual void afterDraw(PainterInfo const &) const {}
/// identifies things that can get scripts
virtual bool isScriptable() const { return false; }
mathMacro_->nesting() == 1 ? 0 : mathMacro_->nesting());
MathRow::Element e_beg(mi, MathRow::BEG_ARG);
- e_beg.macro = mathMacro_;
+ e_beg.inset = this;
e_beg.ar = &mathMacro_->cell(idx_);
mrow.push_back(e_beg);
}
MathRow::Element e_end(mi, MathRow::END_ARG);
- e_end.macro = mathMacro_;
+ e_end.inset = this;
e_end.ar = &mathMacro_->cell(idx_);
mrow.push_back(e_end);
return has_contents;
}
///
- void metrics(MetricsInfo &, Dimension &) const {
- // This should never be invoked, since ArgumentProxy insets are linearized
- LATTEST(false);
+ void beforeMetrics() const
+ {
+ mathMacro_->macro()->unlock();
}
///
- int kerning(BufferView const * bv) const
+ void afterMetrics() const
{
- return displayCell(bv).kerning(bv);
+ mathMacro_->macro()->lock();
+ }
+ ///
+ void beforeDraw(PainterInfo const & pi) const
+ {
+ // if the macro is being edited, then the painter is in
+ // monochrome mode.
+ if (mathMacro_->editMetrics(pi.base.bv))
+ pi.pain.leaveMonochromeMode();
+ }
+ ///
+ void afterDraw(PainterInfo const & pi) const
+ {
+ if (mathMacro_->editMetrics(pi.base.bv))
+ pi.pain.enterMonochromeMode(Color_mathbg, Color_mathmacroblend);
+ }
+ ///
+ void metrics(MetricsInfo &, Dimension &) const {
+ // This should never be invoked, since ArgumentProxy insets are linearized
+ LATTEST(false);
}
///
void draw(PainterInfo &, int, int) const {
// This should never be invoked, since ArgumentProxy insets are linearized
LATTEST(false);
}
+ ///
+ int kerning(BufferView const * bv) const
+ {
+ return displayCell(bv).kerning(bv);
+ }
// write(), normalize(), infoize() and infoize2() are not needed since
// MathMacro uses the definition and not the expanded cells.
///
MathRow::Element e_beg(mi, MathRow::BEG_MACRO);
e_beg.inset = this;
- e_beg.macro = this;
e_beg.marker = (d->nesting_ == 1 && nargs()) ? marker() : NO_MARKER;
mrow.push_back(e_beg);
}
MathRow::Element e_end(mi, MathRow::END_MACRO);
- e_end.macro = this;
+ e_end.inset = this;
mrow.push_back(e_end);
return has_contents;
}
+void MathMacro::beforeMetrics() const
+{
+ d->macro_->lock();
+}
+
+
+void MathMacro::afterMetrics() const
+{
+ d->macro_->unlock();
+}
+
+
+void MathMacro::beforeDraw(PainterInfo const & pi) const
+{
+ if (d->editing_[pi.base.bv])
+ pi.pain.enterMonochromeMode(Color_mathbg, Color_mathmacroblend);
+}
+
+
+void MathMacro::afterDraw(PainterInfo const & pi) const
+{
+ if (d->editing_[pi.base.bv])
+ pi.pain.leaveMonochromeMode();
+}
+
Inset * MathMacro::clone() const
{
pi.pain.rectangle(expx, expy - dim.asc + 1, dim.wid - 3,
dim.height() - 2, Color_mathmacroframe);
} else {
- bool drawBox = lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_INLINE_BOX;
+ bool drawBox = lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_INLINE_BOX
+ && d->editing_[pi.base.bv];
// warm up cells
for (size_t i = 0; i < nargs(); ++i)
cell(i).setXY(*pi.base.bv, x, y);
- if (drawBox && d->editing_[pi.base.bv]) {
+ if (drawBox) {
// draw header and rectangle around
FontInfo font = pi.base.font;
augmentFont(font, "lyxtex");
expx += (dim.wid - d->expanded_.dimension(*pi.base.bv).width()) / 2;
}
- if (d->editing_[pi.base.bv]) {
- pi.pain.enterMonochromeMode(Color_mathbg, Color_mathmacroblend);
- d->expanded_.draw(pi, expx, expy);
- pi.pain.leaveMonochromeMode();
+ beforeDraw(pi);
+ d->expanded_.draw(pi, expx, expy);
+ afterDraw(pi);
- if (drawBox)
- pi.pain.rectangle(x, y - dim.asc, dim.wid,
- dim.height(), Color_mathmacroframe);
- } else
- d->expanded_.draw(pi, expx, expy);
+ if (drawBox)
+ pi.pain.rectangle(x, y - dim.asc, dim.wid,
+ dim.height(), Color_mathmacroframe);
}
// edit mode changed?
/// the row. Otherwise, just insert the inset.
bool addToMathRow(MathRow &, MetricsInfo & mi) const;
///
- void draw(PainterInfo & pi, int x, int y) const;
- /// draw selection background
- void drawSelection(PainterInfo & pi, int x, int y) const;
+ void beforeMetrics() const;
+ ///
+ void afterMetrics() const;
+ ///
+ void beforeDraw(PainterInfo const &) const;
+ ///
+ void afterDraw(PainterInfo const &) const;
+
///
void metrics(MetricsInfo & mi, Dimension & dim) const;
/// was the macro in edit mode when computing metrics?
bool editMetrics(BufferView const * bv) const;
///
+ void draw(PainterInfo & pi, int x, int y) const;
+ /// draw selection background
+ void drawSelection(PainterInfo & pi, int x, int y) const;
+ ///
int kerning(BufferView const * bv) const;
/// get cursor position
void cursorPos(BufferView const & bv, CursorSlice const & sl,
#include "InsetMath.h"
#include "MathClass.h"
#include "MathData.h"
-#include "MathMacro.h"
#include "MathSupport.h"
#include "BufferView.h"
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)
+ color(Color_red)
{}
dim.wid = 0;
// In order to compute the dimension of macros and their
// arguments, it is necessary to keep track of them.
- map<MathMacro const *, Dimension> dim_macros;
+ map<InsetMath const *, Dimension> dim_insets;
map<MathData const *, Dimension> dim_arrays;
CoordCache & coords = mi.base.bv->coordCache();
for (Element const & e : elements_) {
coords.insets().add(e.inset, d);
break;
case BEG_MACRO:
- e.macro->macro()->lock();
+ e.inset->beforeMetrics();
// Add a macro to current list
- dim_macros[e.macro] = Dimension();
+ dim_insets[e.inset] = Dimension();
break;
case END_MACRO:
- LATTEST(dim_macros.find(e.macro) != dim_macros.end());
- e.macro->macro()->unlock();
+ LATTEST(dim_insets.find(e.inset) != dim_insets.end());
+ e.inset->afterMetrics();
// 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);
+ coords.insets().add(e.inset, dim_insets[e.inset]);
+ dim_insets.erase(e.inset);
break;
// This is basically like macros
case BEG_ARG:
- if (e.macro)
- e.macro->macro()->unlock();
+ e.inset->beforeMetrics();
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();
+ e.inset->afterMetrics();
coords.arrays().add(e.ar, dim_arrays[e.ar]);
dim_arrays.erase(e.ar);
break;
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;
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());
}
break;
}
case BEG_MACRO:
- coords.insets().add(e.macro, x, y);
+ coords.insets().add(e.inset, x, y);
drawMarkers(pi, e, x, y);
- if (e.macro->editMetrics(pi.base.bv))
- pi.pain.enterMonochromeMode(Color_mathbg, Color_mathmacroblend);
+ e.inset->beforeDraw(pi);
break;
case END_MACRO:
- if (e.macro->editMetrics(pi.base.bv))
- pi.pain.leaveMonochromeMode();
+ e.inset->afterDraw(pi);
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();
+ e.inset->beforeDraw(pi);
break;
case END_ARG:
- if (e.macro->editMetrics(pi.base.bv))
- pi.pain.enterMonochromeMode(Color_mathbg, Color_mathmacroblend);
+ e.inset->afterDraw(pi);
break;
case BOX: {
if (e.color == Color_none)
<< "-" << e.after << ">";
break;
case MathRow::BEG_MACRO:
- os << "\\" << to_utf8(e.macro->name())
- << "^" << e.macro->nesting() << "[";
+ os << "\\" << to_utf8(e.inset->name())
+ << "^" << e.macro_nesting << "[";
break;
case MathRow::END_MACRO:
os << "]";
class InsetMath;
class MathData;
-class MathMacro;
/*
* While for editing purpose it is important that macros are counted
// the number of characters forming the unique part.
size_t compl_unique_to;
- /// When type is BEG_MACRO, END_MACRO, BEG_ARG, END_ARG
- /// the math macro
- MathMacro const * macro;
-
// type is BEG_ARG, END_ARG
MathData const * ar;