]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathRow.cpp
Force a Buffer * argument to math insets constructor
[lyx.git] / src / mathed / MathRow.cpp
index b8a9a9518b5ba404d93bc7b38f7ab02542ccd6fa..b8d8f63d8ec915805078ab2805840fc805d7c3ba 100644 (file)
@@ -18,6 +18,8 @@
 #include "BufferView.h"
 #include "ColorSet.h"
 #include "CoordCache.h"
+#include "Cursor.h"
+#include "LyXRC.h"
 #include "MetricsInfo.h"
 
 #include "mathed/InsetMath.h"
@@ -184,8 +186,8 @@ MathRow::MathRow(MetricsInfo & mi, MathData const * ar)
        // 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;
@@ -194,7 +196,15 @@ MathRow::MathRow(MetricsInfo & mi, MathData const * ar)
                }
 
                // 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
@@ -247,6 +257,8 @@ void MathRow::metrics(MetricsInfo & mi, Dimension & dim)
                Dimension d;
                switch (e.type) {
                case DUMMY:
+               case BEGIN_SEL:
+               case END_SEL:
                        break;
                case INSET:
                        e.inset->metrics(mi, d);
@@ -315,6 +327,7 @@ void MathRow::metrics(MetricsInfo & mi, Dimension & dim)
 
 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) {
@@ -322,18 +335,18 @@ void MathRow::draw(PainterInfo & pi, int x, int const y) const
                        // 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:
@@ -353,6 +366,16 @@ void MathRow::draw(PainterInfo & pi, int x, int const y) const
                                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;
@@ -426,6 +449,12 @@ ostream & operator<<(ostream & os, MathRow::Element const & e)
                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;