]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_fracinset.C
further code uglification to make Jean-Marc's compiler happy
[lyx.git] / src / mathed / math_fracinset.C
index 73be7a8f75d1afc20cc1e2018759b056e73b6d9e..e4e08935ed0e250fa757ad7c20b6a1ebdb307717 100644 (file)
-#include <config.h>
+#ifdef __GNUG__
+#pragma implementation
+#endif
 
 #include "math_fracinset.h"
-#include "math_iter.h"
-#include "LColor.h"
-#include "Painter.h"
 #include "mathed/support.h"
+#include "Painter.h"
+#include "support/LOstream.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");
-       }
-}
-
-
-MathFracInset::~MathFracInset()
-{
-       delete den;
-}
+MathFracInset::MathFracInset(bool atop)
+       : atop_(atop)
+{}
 
 
-MathedInset * MathFracInset::Clone()
+MathInset * MathFracInset::clone() const
 {   
-       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;
+       return new MathFracInset(*this);
 }
 
 
-bool MathFracInset::setArgumentIdx(int i)
+void MathFracInset::metrics(MathStyles st) const
 {
-       if (i == 0 || i == 1) {
-               idx = i;
-               return true;
-       } else 
-               return false;
+       size_    = smallerStyleFrac(st);
+       xcell(0).metrics(size_);
+       xcell(1).metrics(size_);
+       width_   = std::max(xcell(0).width(), xcell(1).width()) + 4; 
+       ascent_  = xcell(0).height() + 4 + 5;
+       descent_ = xcell(1).height() + 4 - 5; 
 }
 
 
-void MathFracInset::SetStyle(short st)
+void MathFracInset::draw(Painter & pain, int x, int y) const
 {
-       MathParInset::SetStyle(st);
-       dh = 0;
-       den->SetStyle((size == LM_ST_DISPLAY) ?
-                     static_cast<short>(LM_ST_TEXT)
-                     : size);
+       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 (!atop_)
+               pain.line(x + 2, y - 5, x + width() - 4, y - 5, LColor::mathline);
 }
 
 
-void MathFracInset::SetData(MathedArray * n, MathedArray * d)
+void MathFracInset::write(std::ostream & os, bool fragile) const
 {
-       den->SetData(d);
-       MathParInset::SetData(n);
-}
-
-
-void MathFracInset::SetData(MathedArray * d)
-{
-       if (idx == 0)
-               MathParInset::SetData(d);
-       else {
-               den->SetData(d);
+       if (atop_) {
+               os << "{";
+               cell(0).write(os, fragile);
+               os << "\\atop ";
+               cell(1).write(os, fragile);
+               os << '}';
+       } else {
+               os << "\\frac{";
+               cell(0).write(os, fragile);
+               os << "}{";
+               cell(1).write(os, fragile);
+               os << '}';
        }
 }
 
 
-void MathFracInset::GetXY(int & x, int & y) const
-{  
-       if (idx == 0)
-               MathParInset::GetXY(x, y);
-       else
-               den->GetXY(x, y);
-}
-
-
-MathedArray * MathFracInset::GetData()
+void MathFracInset::writeNormal(std::ostream & os) const
 {
-       if (idx == 0)
-               return array;
+       if (atop_) 
+               os << "[atop ";
        else
-               return den->GetData();
-}
-
-
-bool MathFracInset::Inside(int x, int y) 
-{
-       int xx = xo - (width - w0) / 2;
-       
-       return x >= xx && x <= xx + width && y <= yo + descent && y >= yo - ascent;
-}
-
-
-void MathFracInset::SetFocus(int /*x*/, int y)
-{  
-//    lyxerr << "y " << y << " " << yo << " " << den->yo << " ";
-       idx = (y > yo) ? 1: 0;
-}
-
-
-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::Metrics()
-{
-       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;
-}
-
-
-void MathFracInset::Write(ostream & os, bool fragile)
-{
-       os << '\\' << name << '{';
-       MathParInset::Write(os, fragile);
-       os << "}{";
-       den->Write(os, fragile);
-       os << '}';
+               os << "[frac ";
+       cell(0).writeNormal(os);
+       os << " ";
+       cell(1).writeNormal(os);
+       os << "] ";
 }