X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_root.C;h=e440b798afb4f2060ee6d2f858601523f4ee8374;hb=099779019f066ad014e2dd63ad1b9ec3b180f8de;hp=402ba027bcd279322044a2d48e435531ec2aead1;hpb=31b56dac8042735f75229ad480b3e98531c181ff;p=lyx.git diff --git a/src/mathed/math_root.C b/src/mathed/math_root.C index 402ba027bc..e440b798af 100644 --- a/src/mathed/math_root.C +++ b/src/mathed/math_root.C @@ -11,154 +11,88 @@ * the GNU General Public Licence version 2 or later. */ -#include -#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_(LM_ST_TEXT) +MathRootInset::MathRootInset() + : MathInset(2) {} -MathedInset * MathRootInset::Clone() -{ - MathRootInset * p = new MathRootInset(*this); - p->setArgumentIdx(0); - return p; -} - - -void MathRootInset::setData(MathedArray const & 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; -} - - -int MathRootInset::getArgumentIdx() const -{ - return idx_; -} - - -int MathRootInset::getMaxArgumentIdx() const -{ - return 1; -} - - -void MathRootInset::GetXY(int & x, int & y) const -{ - if (idx_ == 1) - MathParInset::GetXY(x, y); - else - uroot_.GetXY(x, y); -} - - -MathedArray & MathRootInset::GetData() +MathInset * MathRootInset::clone() const { - if (idx_ == 1) - return array; - else - return uroot_.GetData(); + return new MathRootInset(*this); } -MathedArray const & MathRootInset::GetData() const +void MathRootInset::Metrics(MathStyles st, int, int) { - if (idx_ == 1) - return array; - else - return uroot_.GetData(); -} - - -bool MathRootInset::Inside(int x, int y) -{ - return (uroot_.Inside(x, y) || MathSqrtInset::Inside(x, y)); -} - - -void MathRootInset::Metrics() -{ - int const 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; + 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::draw(Painter & pain, int x, int y) { - int const idxp = idx_; - - idx_ = 1; - uroot_.draw(pain, x, y - dh_); - MathSqrtInset::draw(pain, x + wroot_, y); - idx_ = idxp; + 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::SetStyle(short st) +void MathRootInset::Write(std::ostream & os, bool fragile) 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; -} - - -void MathRootInset::Write(ostream & os, bool fragile) -{ - os << '\\' << name << '['; - uroot_.Write(os, fragile); + os << "\\sqrt["; + cell(0).Write(os, fragile); os << "]{"; - MathParInset::Write(os, fragile); + cell(1).Write(os, fragile); os << '}'; } -void MathRootInset::WriteNormal(ostream & os) +void MathRootInset::WriteNormal(std::ostream & os) const { os << "[root "; - uroot_.WriteNormal(os); + cell(1).WriteNormal(os); os << " "; - MathParInset::WriteNormal(os); + cell(0).WriteNormal(os); os << "] "; } + +bool MathRootInset::idxUp(int & idx, int & pos) const +{ + if (idx == 0) + return false; + idx = 0; + pos = 0; + return true; +} + +bool MathRootInset::idxDown(int & idx, int & pos) const +{ + if (idx == 1) + return false; + idx = 1; + pos = 0; + return true; +}