]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_colorinset.C
Make Helge happy: no more crash on arrow up/down in math macro
[lyx.git] / src / mathed / math_colorinset.C
index 3d5a68b398fbe52372e583055c46e59ca2dfe26e..10271c589fd1c0b10261b5a079fa4e0835b6f21e 100644 (file)
 using std::auto_ptr;
 
 
+namespace {
+
+// color "none" (reset to default) needs special treatment
+bool normalcolor(MathArray const & ar)
+{
+       return (asString(ar) == "none");
+}
+
+} // namespace anon
+
+
 MathColorInset::MathColorInset(bool oldstyle)
        : MathNestInset(2), oldstyle_(oldstyle)
 {}
 
 
-auto_ptr<InsetBase> MathColorInset::clone() const
+auto_ptr<InsetBase> MathColorInset::doClone() const
 {
        return auto_ptr<InsetBase>(new MathColorInset(*this));
 }
@@ -37,7 +48,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();
@@ -45,7 +56,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;
 }
@@ -53,7 +64,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, "[");
@@ -68,21 +79,25 @@ void MathColorInset::draw(PainterInfo & pi, int x, int y) const
        pi.base.font.setColor(lcolor.getFromGUIName(asString(cell(0))));
        cell(1).draw(pi, x, y);
        pi.base.font.setColor(origcol);
+       setPosCache(pi, x, y);
 }
 
 
 void MathColorInset::validate(LaTeXFeatures & features) const
 {
        MathNestInset::validate(features);
-       features.require("color");
+       if (!normalcolor(cell(0)))
+               features.require("color");
 }
 
 
 void MathColorInset::write(WriteStream & os) const
 {
-       if (oldstyle_)
+       if (normalcolor(cell(0)))
+               os << "{\\normalcolor " << cell(1) << '}';
+       else if (oldstyle_)
                os << "{\\color" << '{' << cell(0) << '}' << cell(1) << '}';
-       else 
+       else
                os << "\\textcolor" << '{' << cell(0) << "}{" << cell(1) << '}';
 }