+namespace {
+
+// Helper functions for markers
+
+int markerMargin(MathRow::Element const & e)
+{
+ return e.marker == InsetMath::MARKER
+ || e.marker == InsetMath::MARKER2;
+}
+
+
+void afterMetricsMarkers(MetricsInfo const & , MathRow::Element & e,
+ Dimension & dim)
+{
+ // handle vertical space for markers
+ switch(e.marker) {
+ case InsetMath::NO_MARKER:
+ break;
+ case InsetMath::MARKER:
+ ++dim.des;
+ break;
+ case InsetMath::MARKER2:
+ ++dim.asc;
+ ++dim.des;
+ break;
+ case InsetMath::BOX_MARKER:
+ FontInfo font;
+ font.setSize(FONT_SIZE_TINY);
+ Dimension namedim;
+ mathed_string_dim(font, e.inset->name(), namedim);
+ int const namewid = 1 + namedim.wid + 1;
+
+ if (namewid > dim.wid)
+ e.after += namewid - dim.wid;
+ dim.des += 3 + namedim.height();
+ }
+}
+
+
+void drawMarkers(PainterInfo const & pi, MathRow::Element const & e,
+ int const x, int const y)
+{
+ if (e.marker == InsetMath::NO_MARKER)
+ return;
+
+ CoordCache const & coords = pi.base.bv->coordCache();
+ Dimension const dim = coords.getInsets().dim(e.inset);
+
+ // the marker is before/after the inset. Necessary space has been reserved already.
+ int const l = x + e.before - markerMargin(e);
+ int const r = x + dim.width() - e.after;
+
+ if (e.marker == InsetMath::BOX_MARKER) {
+ // draw header and rectangle around
+ FontInfo font;
+ font.setSize(FONT_SIZE_TINY);
+ font.setColor(Color_mathmacrolabel);
+ Dimension namedim;
+ mathed_string_dim(font, e.inset->name(), namedim);
+ pi.pain.fillRectangle(l, y + dim.des - namedim.height() - 2,
+ dim.wid, namedim.height() + 2, Color_mathmacrobg);
+ pi.pain.text(l, y + dim.des - namedim.des - 1, e.inset->name(), font);
+ return;
+ }
+
+ // Now markers with corners
+ bool const highlight = e.inset->mouseHovered(pi.base.bv)
+ || e.inset->editing(pi.base.bv);
+ ColorCode const pen_color = highlight ? Color_mathframe : Color_mathcorners;
+
+ int const d = y + dim.descent();
+ pi.pain.line(l, d - 3, l, d, pen_color);
+ pi.pain.line(r, d - 3, r, d, pen_color);
+ pi.pain.line(l, d, l + 3, d, pen_color);
+ pi.pain.line(r - 3, d, r, d, pen_color);
+
+ if (e.marker == InsetMath::MARKER)
+ return;
+
+ int const a = y - dim.ascent();
+ pi.pain.line(l, a + 3, l, a, pen_color);
+ pi.pain.line(r, a + 3, r, a, pen_color);
+ pi.pain.line(l, a, l + 3, a, pen_color);
+ pi.pain.line(r - 3, a, r, a, pen_color);
+}
+
+}
+
+