]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_root.C
Minor code shuffle.
[lyx.git] / src / mathed / math_root.C
index 96583fd590ce93cd037636eaf1714f773fa4f5da..e440b798afb4f2060ee6d2f858601523f4ee8374 100644 (file)
@@ -1,4 +1,3 @@
-// -*- C++ -*-
 /*
  *  File:        math_root.C
  *  Purpose:     Implementation of the root object 
  *   the GNU General Public Licence version 2 or later.
  */
 
-#include <config.h>
-#include FORMS_H_LOCATION
-
 #ifdef __GNUG__
 #pragma implementation
 #endif
 
 #include "math_root.h"
-#include "math_iter.h"
 #include "support/LOstream.h"
+#include "Painter.h"
 
-using std::ostream;
-
-MathRootInset::MathRootInset(short st)
-       : MathSqrtInset(st)
-{
-       idx_ = 1;
-       uroot_ = new MathParInset(LM_ST_TEXT); 
-}
-
-
-MathRootInset::~MathRootInset() 
-{
-       delete uroot_;
-}
-
-
-MathedInset * MathRootInset::Clone()
-{
-       MathRootInset * p = new MathRootInset(*this);
-       p->uroot_ = static_cast<MathParInset *>(p->uroot_->Clone());
-       p->setArgumentIdx(0);
-       return p;
-}
-
-
-void MathRootInset::setData(MathedArray const & d)
-{
-       if (idx_ == 1)
-               MathParInset::setData(d);
-       else {
-               uroot_->setData(d);
-       }
-}
-
+MathRootInset::MathRootInset()
+       : MathInset(2)
+{}
 
-bool MathRootInset::setArgumentIdx(int i)
-{
-       if (i == 0 || i == 1) {
-               idx_ = i;
-               return true;
-       } else
-               return false;
-}
 
-
-void MathRootInset::GetXY(int & x, int & y) const
+MathInset * MathRootInset::clone() const
 {
-       if (idx_ == 1)
-               MathParInset::GetXY(x, y);
-       else
-               uroot_->GetXY(x, y);
+       return new MathRootInset(*this);
 }
 
 
-MathedArray & MathRootInset::GetData()
+void MathRootInset::Metrics(MathStyles st, int, int)
 {
-       if (idx_ == 1)
-               return array;
-       else
-               return uroot_->GetData();
+       MathInset::Metrics(st);
+       size_    = st;
+       ascent_  = std::max(xcell(0).ascent()  + 5, xcell(1).ascent())  + 2;
+       descent_ = std::max(xcell(1).descent() + 5, xcell(0).descent()) + 2;
+       width_   = xcell(0).width() + xcell(1).width() + 10;
 }
 
 
-bool MathRootInset::Inside(int x, int y)
+void MathRootInset::draw(Painter & pain, int x, int y)
 {
-       return (uroot_->Inside(x, y) || MathSqrtInset::Inside(x, y));
+       xo(x);
+       yo(y);
+       int const w = xcell(0).width();
+       xcell(0).draw(pain, x, y - 5 - xcell(0).descent());       // the "exponent"
+       xcell(1).draw(pain, x + w + 8, y);   // the "base"
+       int const a = ascent();
+       int const d = descent();
+       int xp[5];
+       int yp[5];
+       xp[0] = x + width_;   yp[0] = y - a + 1;
+       xp[1] = x + w + 4;    yp[1] = y - a + 1;
+       xp[2] = x + w;        yp[2] = y + d;
+       xp[3] = x + w - 2;    yp[3] = y + (d - a)/2 + 2;
+       xp[4] = x;            yp[4] = y + (d - a)/2 + 2;
+       pain.lines(xp, yp, 5, LColor::mathline);
 }
 
 
-void MathRootInset::Metrics()
+void MathRootInset::Write(std::ostream & os, bool fragile) const
 {
-       int idxp = idx_;
-       
-       idx_ = 1;
-       MathSqrtInset::Metrics();
-       uroot_->Metrics();
-       wroot_ = uroot_->Width();
-       dh_ = Height()/2;
-       width += wroot_;
-       //    if (uroot->Ascent() > dh) 
-       if (uroot_->Height() > dh_) 
-               ascent += uroot_->Height() - dh_;
-       dh_ -= descent - uroot_->Descent();
-       idx_ = idxp;
+       os << "\\sqrt[";
+       cell(0).Write(os, fragile);  
+       os << "]{";
+       cell(1).Write(os, fragile);
+       os << '}';
 }
 
 
-void MathRootInset::draw(Painter & pain, int x, int y)
+void MathRootInset::WriteNormal(std::ostream & os) const
 {
-       int idxp = idx_;
-       
-       idx_ = 1;
-       uroot_->draw(pain, x, y - dh_);
-       MathSqrtInset::draw(pain, x + wroot_, y);
-       idx_ = idxp;
+       os << "[root ";
+       cell(1).WriteNormal(os);  
+       os << " ";
+       cell(0).WriteNormal(os);
+       os << "] ";
 }
 
-
-void MathRootInset::SetStyle(short st)
+bool MathRootInset::idxUp(int & idx, int & pos) const
 {
-       MathSqrtInset::SetStyle(st);
-       
-       uroot_->SetStyle((size() < LM_ST_SCRIPTSCRIPT) ? size() + 1 : size());
-}
-
-
-void MathRootInset::SetFocus(int x, int)
-{  
-       idx_ = (x > xo() + wroot_) ? 1: 0;
+       if (idx == 0)
+               return false;
+       idx = 0;
+       pos = 0;
+       return true;
 }
 
-
-void MathRootInset::Write(ostream & os, bool fragile)
+bool MathRootInset::idxDown(int & idx, int & pos) const
 {
-       os << '\\' << name << '[';
-       uroot_->Write(os, fragile);  
-       os << "]{";
-       MathParInset::Write(os, fragile);
-       os << '}';
+       if (idx == 1)
+               return false;
+       idx = 1;
+       pos = 0;
+       return true;
 }