X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_root.C;h=e440b798afb4f2060ee6d2f858601523f4ee8374;hb=099779019f066ad014e2dd63ad1b9ec3b180f8de;hp=0d7d1024f9cb3f32f7f180f5ab77e6416fc4b101;hpb=0eccdd1c3613e5170deb77b22174dd0afde833e9;p=lyx.git diff --git a/src/mathed/math_root.C b/src/mathed/math_root.C index 0d7d1024f9..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 @@ -6,149 +5,94 @@ * Created: January 1999 * Description: Root math object * - * Copyright: (c) 1999 Alejandro Aguilar Sierra + * Copyright: 1999 Alejandro Aguilar Sierra * * You are free to use and modify this code under the terms of * 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" -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()); +MathRootInset::MathRootInset() + : MathInset(2) +{} - return p; -} - -void MathRootInset::SetData(LyxArrayBase *d) +MathInset * MathRootInset::clone() const { - if (idx==1) - MathParInset::SetData(d); - else { - uroot->SetData(d); - } + return new MathRootInset(*this); } -bool MathRootInset::setArgumentIdx(int i) +void MathRootInset::Metrics(MathStyles st, int, int) { - if (i==0 || i==1) { - idx = i; - return true; - } else - return false; + 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::GetXY(int& x, int& y) const -{ - if (idx==1) - MathParInset::GetXY(x, y); - else - uroot->GetXY(x, y); -} - -LyxArrayBase *MathRootInset::GetData() +void MathRootInset::draw(Painter & pain, int x, int y) { - if (idx==1) - return array; - else - return uroot->GetData(); + 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); } -bool MathRootInset::Inside(int x, int y) +void MathRootInset::Write(std::ostream & os, bool fragile) const { - return (uroot->Inside(x, y) || MathSqrtInset::Inside(x, y)); + os << "\\sqrt["; + cell(0).Write(os, fragile); + os << "]{"; + cell(1).Write(os, fragile); + os << '}'; } -void MathRootInset::Metrics() +void MathRootInset::WriteNormal(std::ostream & os) 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 << "[root "; + cell(1).WriteNormal(os); + os << " "; + cell(0).WriteNormal(os); + os << "] "; } - -void MathRootInset::Draw(int x, int y) +bool MathRootInset::idxUp(int & idx, int & pos) const { - int idxp = idx; - - idx = 1; - uroot->Draw(x, y - dh); - MathSqrtInset::Draw(x+wroot, y); - XFlush(fl_display); - idx = idxp; + if (idx == 0) + return false; + idx = 0; + pos = 0; + return true; } - -void MathRootInset::SetStyle(short st) +bool MathRootInset::idxDown(int & idx, int & pos) const { - MathSqrtInset::SetStyle(st); - - uroot->SetStyle((size xo + wroot) ? 1: 0; -} - - -void MathRootInset::Write(FILE *outf) -{ - string output; - MathRootInset::Write(output); - fprintf(outf, "%s", output.c_str()); -} - - -void MathRootInset::Write(string &outf) -{ - outf += '\\'; - outf += name; - outf += '['; - uroot->Write(outf); - outf += "]{"; - MathParInset::Write(outf); - outf += '}'; + if (idx == 1) + return false; + idx = 1; + pos = 0; + return true; }