#include "BufferView.h"
#include "ColorSet.h"
#include "CoordCache.h"
+#include "Cursor.h"
+#include "LyXRC.h"
#include "MetricsInfo.h"
#include "mathed/InsetMath.h"
// We go to the end to handle spacing at the end of equation
for (int i = 1 ; i != static_cast<int>(elements_.size()) ; ++i) {
Element & e = elements_[i];
-
Element & bef = elements_[before(i)];
+
if (dospacing && e.mclass != MC_UNKNOWN) {
int spc = class_spacing(bef.mclass, e.mclass, mi.base);
bef.after += spc / 2;
}
// finally reserve space for markers
- bef.after = max(bef.after, markerMargin(bef));
+ /* FIXME : the test below avoids that the spacing grows grows
+ * when a BEGIN/END_SEL element is added (typically start or
+ * end a selection after a fraction). I would think that the
+ * code should just go under the e.mclass != MC_UNKNOWN branch
+ * below, but I am not sure why it has not been done before.
+ * Therefore, until we double check this, be very conservative
+ */
+ if (e.type != BEGIN_SEL && e.type != END_SEL)
+ bef.after = max(bef.after, markerMargin(bef));
if (e.mclass != MC_UNKNOWN)
e.before = max(e.before, markerMargin(e));
// for linearized insets (macros...) too
Dimension d;
switch (e.type) {
case DUMMY:
+ case BEGIN_SEL:
+ case END_SEL:
break;
case INSET:
e.inset->metrics(mi, d);
void MathRow::draw(PainterInfo & pi, int x, int const y) const
{
+ Changer change_color;
CoordCache & coords = pi.base.bv->coordCache();
for (Element const & e : elements_) {
switch (e.type) {
// This is hackish: the math inset does not know that space
// has been added before and after it; we alter its dimension
// while it is drawing, because it relies on this value.
- Dimension const d = coords.insets().dim(e.inset);
- Dimension d2 = d;
- d2.wid -= e.before + e.after;
- coords.insets().add(e.inset, d2);
- if (pi.pain.develMode() && !e.inset->isBufferValid())
- pi.pain.fillRectangle(x + e.before, y - d2.ascent(),
- d2.width(), d2.height(), Color_error);
+ Geometry & g = coords.insets().geometry(e.inset);
+ g.dim.wid -= e.before + e.after;
+ if (pi.pain.develMode() && !e.inset->isBufferValid()) {
+ pi.pain.fillRectangle(x + e.before, y - g.dim.ascent(),
+ g.dim.width(), g.dim.height(), Color_error);
+ LYXERR0("Unset Buffer memeber in " << insetName(e.inset->lyxCode()));
+ }
e.inset->draw(pi, x + e.before, y);
- coords.insets().add(e.inset, x, y);
- coords.insets().add(e.inset, d);
+ g.pos = {x, y};
+ g.dim.wid += e.before + e.after;
drawMarkers(pi, e, x, y);
- x += d.wid;
+ x += g.dim.wid;
break;
}
case BEGIN:
e.inset->afterDraw(pi);
x += e.before + e.after;
break;
+ case BEGIN_SEL:
+ // Change the color if the selection is indeed active
+ // FIXME: it would be better to make sure that metrics are
+ // computed again when selection status changes.
+ if (pi.base.bv->cursor().selection())
+ change_color = pi.base.font.changeColor(Color_selectionmath);
+ break;
+ case END_SEL:
+ change_color = noChange();
+ break;
case BOX: {
if (e.color == Color_none)
break;
if (e.inset)
os << "]";
break;
+ case MathRow::BEGIN_SEL:
+ os << "<sel>";
+ break;
+ case MathRow::END_SEL:
+ os << "</sel>" ;
+ break;
case MathRow::BOX:
os << "<" << e.before << "-[]-" << e.after << ">";
break;