]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_fracinset.C
oh well
[lyx.git] / src / mathed / math_fracinset.C
index 09429072fb4444984d1a7bc19081353ee57b3118..69f935689e62322fe7a992e045e7d08a1ead0bb1 100644 (file)
-#include <config.h>
-
 #ifdef __GNUG__
 #pragma implementation
 #endif
 
 #include "math_fracinset.h"
-#include "LColor.h"
+#include "math_support.h"
 #include "Painter.h"
-#include "mathed/support.h"
-#include "support/LOstream.h"
+#include "math_mathmlstream.h"
+#include "textpainter.h"
 
 
-MathFracInset::MathFracInset(MathInsetTypes ot)
-       : MathInset("frac", ot, 2)
-{
-       if (objtype == LM_OT_STACKREL) 
-               SetName("stackrel");
-}
+using std::max;
 
 
-MathInset * MathFracInset::Clone() const
-{   
-       return new MathFracInset(*this);
-}
+MathFracInset::MathFracInset(bool atop)
+       : atop_(atop)
+{}
 
 
-void MathFracInset::Metrics(MathStyles st)
+MathInset * MathFracInset::clone() const
 {
-       xcell(0).Metrics(st);
-       xcell(1).Metrics(st);
-       size_    = st;
-       width_   = max(xcell(0).width(), xcell(1).width()) + 4; 
-       ascent_  = xcell(0).height() + 4 + 5;
-       descent_ = xcell(1).height() + 4 - 5; 
+       return new MathFracInset(*this);
 }
 
 
-void MathFracInset::draw(Painter & pain, int x, int y)
+MathFracInset * MathFracInset::asFracInset()
 {
-       xo(x);
-       yo(y);
-       int m = x + width() / 2;
-       xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
-       xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent()  + 3 - 5);
-       
-       if (objtype == LM_OT_FRAC)
-               pain.line(x + 2, y - 5, x + width() - 4, y - 5, LColor::mathline);
+       return atop_ ? 0 : this;
 }
 
 
-void MathFracInset::Write(std::ostream & os, bool fragile) const
+void MathFracInset::metrics(MathMetricsInfo const & mi) const
 {
-       os << '\\' << name() << '{';
-       cell(0).Write(os, fragile);
-       os << "}{";
-       cell(1).Write(os, fragile);
-       os << '}';
+       MathMetricsInfo m = mi;
+       smallerStyleFrac(m);
+       xcell(0).metrics(m);
+       xcell(1).metrics(m);
+       width_   = max(xcell(0).width(), xcell(1).width()) + 2;
+       ascent_  = xcell(0).height() + 2 + 5;
+       descent_ = xcell(1).height() + 2 - 5;
 }
 
 
-void MathFracInset::WriteNormal(std::ostream & os) const
+void MathFracInset::draw(Painter & pain, int x, int y) const
 {
-       os << '[' << name() << ' ';
-       cell(0).WriteNormal(os);
-       os << " ";
-       cell(1).WriteNormal(os);
-       os << "] ";
+       int m = x + width() / 2;
+       xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 2 - 5);
+       xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent()  + 2 - 5);
+       if (!atop_)
+               pain.line(x, y - 5, x + width(), y - 5, LColor::math);
 }
 
 
-bool MathFracInset::idxRight(int &, int &) const
+void MathFracInset::metricsT(TextMetricsInfo const & mi) const
 {
-       return false;
+       xcell(0).metricsT(mi);
+       xcell(1).metricsT(mi);
+       width_   = max(xcell(0).width(), xcell(1).width());
+       ascent_  = xcell(0).height() + 1;
+       descent_ = xcell(1).height();
 }
 
-bool MathFracInset::idxLeft(int &, int &) const
+
+void MathFracInset::drawT(TextPainter & pain, int x, int y) const
 {
-       return false;
+       int m = x + width() / 2;
+       xcell(0).drawT(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 1);
+       xcell(1).drawT(pain, m - xcell(1).width() / 2, y + xcell(1).ascent());
+       if (!atop_)
+               pain.horizontalLine(x, y, width());
 }
 
 
-bool MathFracInset::idxUp(int & idx, int &) const
+void MathFracInset::write(WriteStream & os) const
 {
-       if (idx == 0)
-               return false;
-       idx = 0;
-       return true;
+       if (atop_)
+               os << '{' << cell(0) << "\\atop " << cell(1) << '}';
+       else
+               os << "\\frac{" << cell(0) << "}{" << cell(1) << '}';
 }
 
-bool MathFracInset::idxDown(int & idx, int &) const
-{
-       if (idx == 1)
-               return false;
-       idx = 1;
-       return true;
-}
 
-bool MathFracInset::idxFirstUp(int & idx, int & pos) const
+void MathFracInset::normalize(NormalStream & os) const
 {
-       idx = 0;
-       pos = 0;
-       return true;
+       if (atop_)
+               os << "[atop ";
+       else
+               os << "[frac ";
+       os << cell(0) << ' ' << cell(1) << ']';
 }
 
-bool MathFracInset::idxFirstDown(int & idx, int & pos) const
+
+void MathFracInset::maplize(MapleStream & os) const
 {
-       idx = 1;
-       pos = 0;
-       return true;
+       os << '(' << cell(0) << ")/(" << cell(1) << ')';
 }
 
-bool MathFracInset::idxLastUp(int & idx, int & pos) const
+
+void MathFracInset::octavize(OctaveStream & os) const
 {
-       idx = 0;
-       pos = cell(idx).size();
-       return true;
+       os << '(' << cell(0) << ")/(" << cell(1) << ')';
 }
 
-bool MathFracInset::idxLastDown(int & idx, int & pos) const
+
+void MathFracInset::mathmlize(MathMLStream & os) const
 {
-       idx = 1;
-       pos = cell(idx).size();
-       return true;
+       os << MTag("mfrac") << cell(0) << cell(1) << ETag("mfrac");
 }
-