]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathFrac.cpp
Fix bug 5802 (http://bugzilla.lyx.org/show_bug.cgi?id=5802)
[lyx.git] / src / mathed / InsetMathFrac.cpp
index 915169becc67602f4d03084a090983a8e60bf98b..558bbcddf6304e5416598edba9ed7bb3b6aca65a 100644 (file)
@@ -4,7 +4,8 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Alejandro Aguilar Sierra
- * \author André Pönitz
+ * \author André Pönitz
+ * \author Uwe Stöhr
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -248,7 +249,7 @@ void InsetMathFrac::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
 }
 
 
-void InsetMathFrac::drawT(TextPainter & pain, int x, int y) const
+void InsetMathFrac::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
 {
        // FIXME: BROKEN!
        /*
@@ -265,6 +266,7 @@ void InsetMathFrac::drawT(TextPainter & pain, int x, int y) const
 
 void InsetMathFrac::write(WriteStream & os) const
 {
+       MathEnsurer ensurer(os);
        switch (kind_) {
        case ATOP:
                os << '{' << cell(0) << "\\atop " << cell(1) << '}';
@@ -465,6 +467,62 @@ void InsetMathTFrac::validate(LaTeXFeatures & features) const
 }
 
 
+/////////////////////////////////////////////////////////////////////
+//
+// InsetMathCFrac
+//
+/////////////////////////////////////////////////////////////////////
+
+
+Inset * InsetMathCFrac::clone() const
+{
+       return new InsetMathCFrac(*this);
+}
+
+
+void InsetMathCFrac::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+       Dimension dim0, dim1;
+       cell(0).metrics(mi, dim0);
+       cell(1).metrics(mi, dim1);
+       dim.wid = max(dim0.wid, dim1.wid) + 2;
+       dim.asc = dim0.height() + 2 + 5;
+       dim.des = dim1.height() + 2 - 5;
+}
+
+
+void InsetMathCFrac::draw(PainterInfo & pi, int x, int y) const
+{
+       Dimension const dim = dimension(*pi.base.bv);
+       Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
+       Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
+       int m = x + dim.wid / 2;
+       cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 2 - 5);
+       cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc  + 2 - 5);
+       pi.pain.line(x + 1, y - 5, x + dim.wid - 2, y - 5, Color_math);
+       setPosCache(pi, x, y);
+}
+
+
+docstring InsetMathCFrac::name() const
+{
+       return from_ascii("cfrac");
+}
+
+
+void InsetMathCFrac::mathmlize(MathStream & os) const
+{
+       os << MTag("mcfrac") << cell(0) << cell(1) << ETag("mcfrac");
+}
+
+
+void InsetMathCFrac::validate(LaTeXFeatures & features) const
+{
+       features.require("amsmath");
+       InsetMathNest::validate(features);
+}
+
+
 /////////////////////////////////////////////////////////////////////
 //
 // InsetMathBinom
@@ -472,8 +530,8 @@ void InsetMathTFrac::validate(LaTeXFeatures & features) const
 /////////////////////////////////////////////////////////////////////
 
 
-InsetMathBinom::InsetMathBinom(bool choose)
-       : choose_(choose)
+InsetMathBinom::InsetMathBinom(Kind kind)
+       : kind_(kind)
 {}
 
 
@@ -512,29 +570,44 @@ void InsetMathBinom::draw(PainterInfo & pi, int x, int y) const
        Dimension const dim = dimension(*pi.base.bv);
        Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
        Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
+       docstring const bra = kind_ == BRACE ? from_ascii("{") :
+                             kind_ == BRACK ? from_ascii("[") : from_ascii("(");
+       docstring const ket = kind_ == BRACE ? from_ascii("}") :
+                             kind_ == BRACK ? from_ascii("]") : from_ascii(")");
        int m = x + dim.width() / 2;
        FracChanger dummy(pi.base);
        cell(0).draw(pi, m - dim0.width() / 2, y - dim0.des - 3 - 5);
        cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc  + 3 - 5);
-       mathed_draw_deco(pi, x, y - dim.ascent(), dw(dim.height()), dim.height(), from_ascii("("));
+       mathed_draw_deco(pi, x, y - dim.ascent(), dw(dim.height()), dim.height(), bra);
        mathed_draw_deco(pi, x + dim.width() - dw(dim.height()), y - dim.ascent(),
-               dw(dim.height()), dim.height(), from_ascii(")"));
+               dw(dim.height()), dim.height(), ket);
        drawMarkers2(pi, x, y);
 }
 
 
 bool InsetMathBinom::extraBraces() const
 {
-       return choose_;
+       return kind_ == CHOOSE || kind_ == BRACE || kind_ == BRACK;
 }
 
 
 void InsetMathBinom::write(WriteStream & os) const
 {
-       if (choose_)
-               os << '{' << cell(0) << " \\choose " << cell(1) << '}';
-       else
+       MathEnsurer ensurer(os);
+       switch (kind_) {
+       case BINOM:
                os << "\\binom{" << cell(0) << "}{" << cell(1) << '}';
+               break;
+       case CHOOSE:
+               os << '{' << cell(0) << " \\choose " << cell(1) << '}';
+               break;
+       case BRACE:
+               os << '{' << cell(0) << " \\brace " << cell(1) << '}';
+               break;
+       case BRACK:
+               os << '{' << cell(0) << " \\brack " << cell(1) << '}';
+               break;
+       }
 }
 
 
@@ -544,6 +617,14 @@ void InsetMathBinom::normalize(NormalStream & os) const
 }
 
 
+void InsetMathBinom::validate(LaTeXFeatures & features) const
+{
+       if (kind_ == BINOM)
+               features.require("binom");
+       InsetMathNest::validate(features);
+}
+
+
 /////////////////////////////////////////////////////////////////////
 //
 // InsetMathDBinom