]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathHull.cpp
Simplify Changers interface
[lyx.git] / src / mathed / InsetMathHull.cpp
index 345ee44af715dd2f86184d7222441475a64d5752..52442b225b84a149a51900c2111ca45153d1b76b 100644 (file)
@@ -15,7 +15,6 @@
 #include "InsetMathChar.h"
 #include "InsetMathColor.h"
 #include "InsetMathFrac.h"
-#include "InsetMathGrid.h"
 #include "InsetMathNest.h"
 #include "InsetMathScript.h"
 #include "MathExtern.h"
@@ -109,7 +108,7 @@ namespace {
        size_t firstRelOp(MathData const & ar)
        {
                for (MathData::const_iterator it = ar.begin(); it != ar.end(); ++it)
-                       if ((*it)->isMathRel())
+                       if ((*it)->mathClass() == MC_REL)
                                return it - ar.begin();
                return ar.size();
        }
@@ -121,6 +120,37 @@ namespace {
        }
 
 
+       // writes a preamble for underlined or struck out math display
+       void writeMathdisplayPreamble(WriteStream & os)
+       {
+               if (os.strikeoutMath()) {
+                       if (os.ulemCmd() == WriteStream::UNDERLINE)
+                               os << "\\raisebox{-\\belowdisplayshortskip}{"
+                                     "\\lyxmathsout{\\parbox[b]{\\columnwidth}{";
+                       else
+                               os << "\\lyxmathsout{\\parbox{\\columnwidth}{";
+               } else if (os.ulemCmd() == WriteStream::UNDERLINE)
+                       os << "\\raisebox{-\\belowdisplayshortskip}{"
+                             "\\parbox[b]{\\columnwidth}{";
+               else if (os.ulemCmd() == WriteStream::STRIKEOUT)
+                       os << "\\parbox{\\columnwidth}{";
+       }
+
+
+       // writes a postamble for underlined or struck out math display
+       void writeMathdisplayPostamble(WriteStream & os)
+       {
+               if (os.strikeoutMath()) {
+                       if (os.ulemCmd() == WriteStream::UNDERLINE)
+                               os << "}";
+                       os << "}}\\\\\n";
+               } else if (os.ulemCmd() == WriteStream::UNDERLINE)
+                       os << "}}\\\\\n";
+               else if (os.ulemCmd() == WriteStream::STRIKEOUT)
+                       os << "}\\\\\n";
+       }
+
+
 } // end anon namespace
 
 
@@ -490,9 +520,9 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
                return;
        }
 
-       // FIXME: Changing the same object repeatedly is inefficient.
        Changer dummy1 = mi.base.changeFontSet(standardFont());
-       Changer dummy2 = mi.base.changeStyle(display() ? LM_ST_DISPLAY : LM_ST_TEXT);
+       Changer dummy2 = mi.base.font.changeStyle(display() ? LM_ST_DISPLAY
+                                                           : LM_ST_TEXT);
 
        // let the cells adjust themselves
        InsetMathGrid::metrics(mi, dim);
@@ -570,7 +600,8 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
        if (previewState(bv)) {
                // Do not draw change tracking cue if taken care of by RowPainter
                // already.
-               Changer dummy = make_change(pi.change_, Change(), !canPaintChange(*bv));
+               Changer dummy = !canPaintChange(*bv) ? make_change(pi.change_, Change())
+                       : Changer();
                if (previewTooSmall(dim)) {
                        // we have an extra frame
                        preview_->draw(pi, x + ERROR_FRAME_WIDTH, y);
@@ -585,9 +616,11 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
        ColorCode color = pi.selected && lyxrc.use_system_colors
                                ? Color_selectiontext : standardColor();
        bool const really_change_color = pi.base.font.color() == Color_none;
-       Changer dummy0 = pi.base.font.changeColor(color, really_change_color);
+       Changer dummy0 = really_change_color ? pi.base.font.changeColor(color)
+               : Changer();
        Changer dummy1 = pi.base.changeFontSet(standardFont());
-       Changer dummy2 = pi.base.changeStyle(display() ? LM_ST_DISPLAY : LM_ST_TEXT);
+       Changer dummy2 = pi.base.font.changeStyle(display() ? LM_ST_DISPLAY
+                                                           : LM_ST_TEXT);
 
        InsetMathGrid::draw(pi, x + 1, y);
 
@@ -1029,14 +1062,7 @@ void InsetMathHull::header_write(WriteStream & os) const
                break;
 
        case hullEquation:
-               if (os.strikeoutMath()) {
-                       if (os.ulemCmd() == WriteStream::UNDERLINE)
-                               os << "\\raisebox{1ex}{";
-                       os << "\\lyxmathsout{\\parbox{\\columnwidth}{";
-               } else if (os.ulemCmd() == WriteStream::UNDERLINE)
-                       os << "\\raisebox{-1ex}{\\parbox[b]{\\columnwidth}{";
-               else if (os.ulemCmd() == WriteStream::STRIKEOUT)
-                       os << "\\parbox{\\columnwidth}{";
+               writeMathdisplayPreamble(os);
                os << "\n";
                os.startOuterRow();
                if (n)
@@ -1050,14 +1076,7 @@ void InsetMathHull::header_write(WriteStream & os) const
        case hullFlAlign:
        case hullGather:
        case hullMultline:
-               if (os.strikeoutMath()) {
-                       if (os.ulemCmd() == WriteStream::UNDERLINE)
-                               os << "\\raisebox{1ex}{";
-                       os << "\\lyxmathsout{\\parbox{\\columnwidth}{";
-               } else if (os.ulemCmd() == WriteStream::UNDERLINE)
-                       os << "\\raisebox{-1ex}{\\parbox[b]{\\columnwidth}{";
-               else if (os.ulemCmd() == WriteStream::STRIKEOUT)
-                       os << "\\parbox{\\columnwidth}{";
+               writeMathdisplayPreamble(os);
                os << "\n";
                os.startOuterRow();
                os << "\\begin{" << hullName(type_) << star(n) << "}\n";
@@ -1113,14 +1132,7 @@ void InsetMathHull::footer_write(WriteStream & os) const
                        os << "\\end{equation" << star(n) << "}\n";
                else
                        os << "\\]\n";
-               if (os.strikeoutMath()) {
-                       if (os.ulemCmd() == WriteStream::UNDERLINE)
-                               os << "}";
-                       os << "}}\\\\\n";
-               } else if (os.ulemCmd() == WriteStream::UNDERLINE)
-                       os << "}}\\\\\n";
-               else if (os.ulemCmd() == WriteStream::STRIKEOUT)
-                       os << "}\\\\\n";
+               writeMathdisplayPostamble(os);
                break;
 
        case hullEqnArray:
@@ -1131,14 +1143,7 @@ void InsetMathHull::footer_write(WriteStream & os) const
                os << "\n";
                os.startOuterRow();
                os << "\\end{" << hullName(type_) << star(n) << "}\n";
-               if (os.strikeoutMath()) {
-                       if (os.ulemCmd() == WriteStream::UNDERLINE)
-                               os << "}";
-                       os << "}}\\\\\n";
-               } else if (os.ulemCmd() == WriteStream::UNDERLINE)
-                       os << "}}\\\\\n";
-               else if (os.ulemCmd() == WriteStream::STRIKEOUT)
-                       os << "}\\\\\n";
+               writeMathdisplayPostamble(os);
                break;
 
        case hullAlignAt: