+bool MathMacro::addToMathRow(MathRow & mrow, MetricsInfo & mi) const
+{
+ // set edit mode for which we will have calculated row.
+ // This is the same as what is done in metrics().
+ d->editing_[mi.base.bv] = editMode(mi.base.bv);
+
+ // For now we do not linearize in the following cases (can be improved)
+ // - display mode different from normal
+ // - editing with parameter list
+ // - editing with box around macro
+ if (displayMode() != MathMacro::DISPLAY_NORMAL
+ || (d->editing_[mi.base.bv] && lyxrc.macro_edit_style != LyXRC::MACRO_EDIT_INLINE))
+ return InsetMath::addToMathRow(mrow, mi);
+
+ /// The macro nesting can change display of insets. Change it locally.
+ Changer chg = make_change(mi.base.macro_nesting, d->nesting_);
+
+ MathRow::Element e_beg(mi, MathRow::BEGIN);
+ e_beg.inset = this;
+ e_beg.marker = (d->nesting_ == 1 && nargs()) ? marker() : NO_MARKER;
+ mrow.push_back(e_beg);
+
+ d->macro_->lock();
+ bool has_contents = d->expanded_.addToMathRow(mrow, mi);
+ d->macro_->unlock();
+
+ // if there was no contents and the array is editable, then we
+ // insert a grey box instead.
+ if (!has_contents && mi.base.macro_nesting == 1) {
+ // mathclass is unknown because it is irrelevant for spacing
+ MathRow::Element e(mi, MathRow::BOX);
+ e.color = Color_mathmacroblend;
+ mrow.push_back(e);
+ has_contents = true;
+ }
+
+ MathRow::Element e_end(mi, MathRow::END);
+ 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();
+}
+
+