]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_fracinset.C
rename commandtags.h to lfuns.h and renumber/cleanup. Rebuild the tree !
[lyx.git] / src / mathed / math_fracinset.C
index 73be7a8f75d1afc20cc1e2018759b056e73b6d9e..ec0517161dd6e7e58234f469e4d0fb9a645736a9 100644 (file)
-#include <config.h>
 
 #include "math_fracinset.h"
-#include "math_iter.h"
-#include "LColor.h"
-#include "Painter.h"
-#include "mathed/support.h"
+#include "math_support.h"
+#include "frontends/Painter.h"
+#include "math_mathmlstream.h"
+#include "textpainter.h"
 
 
-MathFracInset::MathFracInset(short ot)
-       : MathParInset(LM_ST_TEXT, "frac", ot)
-{
-       
-       den = new MathParInset(LM_ST_TEXT); // this leaks
-       dh = 0;
-       idx = 0;
-       if (objtype == LM_OT_STACKREL) {
-               flag |= LMPF_SCRIPT;
-               SetName("stackrel");
-       }
-}
+using std::max;
+
+
+MathFracInset::MathFracInset(bool atop)
+       : atop_(atop)
+{}
 
 
-MathFracInset::~MathFracInset()
+MathInset * MathFracInset::clone() const
 {
-       delete den;
+       return new MathFracInset(*this);
 }
 
 
-MathedInset * MathFracInset::Clone()
-{   
-       MathFracInset * p = new MathFracInset(GetType());
-       MathedIter itn(array);
-       MathedIter itd(den->GetData());
-       p->SetData(itn.Copy(), itd.Copy());
-       p->idx = idx;
-       p->dh = dh;
-       return p;
+MathFracInset * MathFracInset::asFracInset()
+{
+       return atop_ ? 0 : this;
 }
 
 
-bool MathFracInset::setArgumentIdx(int i)
+MathFracInset const * MathFracInset::asFracInset() const
 {
-       if (i == 0 || i == 1) {
-               idx = i;
-               return true;
-       } else 
-               return false;
+       return atop_ ? 0 : this;
 }
 
 
-void MathFracInset::SetStyle(short st)
+void MathFracInset::metrics(MathMetricsInfo & mi) const
 {
-       MathParInset::SetStyle(st);
-       dh = 0;
-       den->SetStyle((size == LM_ST_DISPLAY) ?
-                     static_cast<short>(LM_ST_TEXT)
-                     : size);
+       MathFracChanger dummy(mi.base);
+       cell(0).metrics(mi);
+       cell(1).metrics(mi);
+       dim_.w = max(cell(0).width(), cell(1).width()) + 2;
+       dim_.a = cell(0).height() + 2 + 5;
+       dim_.d = cell(1).height() + 2 - 5;
 }
 
 
-void MathFracInset::SetData(MathedArray * n, MathedArray * d)
+void MathFracInset::draw(MathPainterInfo & pi, int x, int y) const
 {
-       den->SetData(d);
-       MathParInset::SetData(n);
+       int m = x + width() / 2;
+       MathFracChanger dummy(pi.base);
+       cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 2 - 5);
+       cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent()  + 2 - 5);
+       if (!atop_)
+               pi.pain.line(x + 1, y - 5, x + width() - 2, y - 5, LColor::math);
 }
 
 
-void MathFracInset::SetData(MathedArray * d)
+void MathFracInset::metricsT(TextMetricsInfo const & mi) const
 {
-       if (idx == 0)
-               MathParInset::SetData(d);
-       else {
-               den->SetData(d);
-       }
+       cell(0).metricsT(mi);
+       cell(1).metricsT(mi);
+       dim_.w = max(cell(0).width(), cell(1).width());
+       dim_.a = cell(0).height() + 1;
+       dim_.d = cell(1).height();
 }
 
 
-void MathFracInset::GetXY(int & x, int & y) const
-{  
-       if (idx == 0)
-               MathParInset::GetXY(x, y);
-       else
-               den->GetXY(x, y);
+void MathFracInset::drawT(TextPainter & pain, int x, int y) const
+{
+       int m = x + width() / 2;
+       cell(0).drawT(pain, m - cell(0).width() / 2, y - cell(0).descent() - 1);
+       cell(1).drawT(pain, m - cell(1).width() / 2, y + cell(1).ascent());
+       if (!atop_)
+               pain.horizontalLine(x, y, width());
 }
 
 
-MathedArray * MathFracInset::GetData()
+void MathFracInset::write(WriteStream & os) const
 {
-       if (idx == 0)
-               return array;
-       else
-               return den->GetData();
+       if (atop_)
+               os << '{' << cell(0) << "\\atop " << cell(1) << '}';
+       else // it's \\frac
+               MathNestInset::write(os);
 }
 
 
-bool MathFracInset::Inside(int x, int y) 
+string MathFracInset::name() const
 {
-       int xx = xo - (width - w0) / 2;
-       
-       return x >= xx && x <= xx + width && y <= yo + descent && y >= yo - ascent;
+       return atop_ ? "atop" : "frac";
 }
 
 
-void MathFracInset::SetFocus(int /*x*/, int y)
-{  
-//    lyxerr << "y " << y << " " << yo << " " << den->yo << " ";
-       idx = (y > yo) ? 1: 0;
+void MathFracInset::maple(MapleStream & os) const
+{
+       os << '(' << cell(0) << ")/(" << cell(1) << ')';
 }
 
 
-void
-MathFracInset::draw(Painter & pain, int x, int y)
-{ 
-       short idxp = idx;
-       short sizex = size;
-       
-       idx = 0;
-       if (size == LM_ST_DISPLAY) ++size;
-       MathParInset::draw(pain, x + (width - w0) / 2, y - des0);
-       den->draw(pain, x + (width - w1) / 2, y + den->Ascent() + 2 - dh);
-       size = sizex;
-       if (objtype == LM_OT_FRAC)
-               pain.line(x + 2, y - dh, x + width - 4, y - dh, LColor::mathline);
-       idx = idxp;
+void MathFracInset::mathematica(MathematicaStream & os) const
+{
+       os << '(' << cell(0) << ")/(" << cell(1) << ')';
 }
 
 
-void
-MathFracInset::Metrics()
+void MathFracInset::octave(OctaveStream & os) const
 {
-       if (!dh) {
-               int a, b;
-               dh = mathed_char_height(LM_TC_CONST, size, 'I', a, b)/2;
-       }
-       short idxp = idx;
-       short sizex = size; 
-       idx = 0;
-       if (size == LM_ST_DISPLAY) ++size; 
-       MathParInset::Metrics();
-       size = sizex;
-       w0 = width;
-       int as = Height() + 2 + dh;
-       des0 = Descent() + 2 + dh;
-       den->Metrics();  
-       w1 = den->Width();   
-       width = ((w0 > w1) ? w0: w1) + 12;
-       ascent = as; 
-       descent = den->Height()+ 2 - dh;
-       idx = idxp;
+       os << '(' << cell(0) << ")/(" << cell(1) << ')';
 }
 
 
-void MathFracInset::Write(ostream & os, bool fragile)
+void MathFracInset::mathmlize(MathMLStream & os) const
 {
-       os << '\\' << name << '{';
-       MathParInset::Write(os, fragile);
-       os << "}{";
-       den->Write(os, fragile);
-       os << '}';
+       os << MTag("mfrac") << cell(0) << cell(1) << ETag("mfrac");
 }