]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_colorinset.C
Ensure all #warning statements are wrapped by #ifdef WITH_WARNINGS.
[lyx.git] / src / mathed / math_colorinset.C
index ec3edee0da6265026a01673a36d6e20f7773bfa7..5a87a63f8501f03ca1abb569607505252c49957c 100644 (file)
 #include "math_support.h"
 
 #include "LaTeXFeatures.h"
+#include "LColor.h"
 
 #include "support/std_ostream.h"
 
 using std::auto_ptr;
 
 
-MathColorInset::MathColorInset()
-       : MathNestInset(2)
+MathColorInset::MathColorInset(bool oldstyle)
+       : MathNestInset(2), oldstyle_(oldstyle)
 {}
 
 
@@ -36,7 +37,7 @@ auto_ptr<InsetBase> MathColorInset::clone() const
 void MathColorInset::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        cell(1).metrics(mi, dim);
-       if (editing()) {
+       if (editing(mi.base.bv)) {
                FontSetChanger dummy(mi.base, "textnormal");
                cell(0).metrics(mi);
                dim  += cell(0).dim();
@@ -44,7 +45,7 @@ void MathColorInset::metrics(MetricsInfo & mi, Dimension & dim) const
                dim.asc += 4;
                dim.des += 4;
                dim.wid += 2 * w_ + 4;
-               metricsMarkers();
+               metricsMarkers(dim);
        }
        dim_ = dim;
 }
@@ -52,7 +53,7 @@ void MathColorInset::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void MathColorInset::draw(PainterInfo & pi, int x, int y) const
 {
-       if (editing()) {
+       if (editing(pi.base.bv)) {
                FontSetChanger dummy(pi.base, "textnormal");
                drawMarkers(pi, x, y);
                drawStrBlack(pi, x, y, "[");
@@ -63,8 +64,11 @@ void MathColorInset::draw(PainterInfo & pi, int x, int y) const
                x += w_ + 2;
        }
 
-       ColorChanger dummy1(pi.base.font, asString(cell(0)));
+       LColor_color origcol = pi.base.font.color();
+       pi.base.font.setColor(lcolor.getFromGUIName(asString(cell(0))));
        cell(1).draw(pi, x, y);
+       pi.base.font.setColor(origcol);
+       setPosCache(pi, x, y);
 }
 
 
@@ -77,7 +81,10 @@ void MathColorInset::validate(LaTeXFeatures & features) const
 
 void MathColorInset::write(WriteStream & os) const
 {
-       os << "\\color" << '{' << cell(0) << '}' << '{' << cell(1) << '}';
+       if (oldstyle_)
+               os << "{\\color" << '{' << cell(0) << '}' << cell(1) << '}';
+       else
+               os << "\\textcolor" << '{' << cell(0) << "}{" << cell(1) << '}';
 }