]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_root.C
Minor code shuffle.
[lyx.git] / src / mathed / math_root.C
index c817dc07cac19890d471fceef8fe091d05e76e0e..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_iter.h"
 #include "math_root.h"
+#include "support/LOstream.h"
+#include "Painter.h"
 
-MathRootInset::MathRootInset(short st): MathSqrtInset(st)
-{
-    idx = 1;
-    uroot = new MathParInset(LM_ST_TEXT); 
-}
+MathRootInset::MathRootInset()
+       : MathInset(2)
+{}
 
 
-MathRootInset::~MathRootInset() 
+MathInset * MathRootInset::clone() const
 {
-    delete uroot;
+       return new MathRootInset(*this);
 }
 
 
-MathedInset * MathRootInset::Clone()
+void MathRootInset::Metrics(MathStyles st, int, int)
 {
-   MathRootInset * p = new MathRootInset(GetStyle());
-   MathedIter it(array), itr(uroot->GetData());
-   p->SetData(it.Copy());
-   p->setArgumentIdx(0);
-   p->SetData(itr.Copy());
-
-   return p;
+       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;
 }
 
 
-void MathRootInset::SetData(LyxArrayBase * d)
-{
-   if (idx == 1)
-     MathParInset::SetData(d);
-   else {
-      uroot->SetData(d);
-   }
-}
-
-
-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
-{
-   if (idx == 1)
-     MathParInset::GetXY(x, y);
-   else
-     uroot->GetXY(x, y);
-}
-
-
-LyxArrayBase * MathRootInset::GetData()
-{
-   if (idx == 1)
-     return array;
-   else
-     return uroot->GetData();
-}
-
-
-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 MathRootInset::idxDown(int & idx, int & pos) const
 {
-       os << '\\' << name << '[';
-       uroot->Write(os);  
-       os << "]{";
-       MathParInset::Write(os);
-       os << '}';
+       if (idx == 1)
+               return false;
+       idx = 1;
+       pos = 0;
+       return true;
 }