X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_root.C;h=e440b798afb4f2060ee6d2f858601523f4ee8374;hb=099779019f066ad014e2dd63ad1b9ec3b180f8de;hp=0a95822fdf9ce8fb06287888e81dcd33fe19d016;hpb=5b55f3baff0812c010b85d4a815e8aacc16bd116;p=lyx.git diff --git a/src/mathed/math_root.C b/src/mathed/math_root.C index 0a95822fdf..e440b798af 100644 --- a/src/mathed/math_root.C +++ b/src/mathed/math_root.C @@ -1,4 +1,3 @@ -// -*- C++ -*- /* * File: math_root.C * Purpose: Implementation of the root object @@ -12,137 +11,88 @@ * the GNU General Public Licence version 2 or later. */ -#include -#include FORMS_H_LOCATION - #ifdef __GNUG__ #pragma implementation #endif -#include "math_iter.h" #include "math_root.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(GetStyle()); - MathedIter it(array), itr(uroot->GetData()); - p->SetData(it.Copy()); - p->setArgumentIdx(0); - p->SetData(itr.Copy()); - - return p; -} - - -void MathRootInset::SetData(MathedArray * 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 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; }