2 * \file math_rootinset.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
9 * Full author contact details are available in file CREDITS.
14 #include "math_rootinset.h"
15 #include "math_data.h"
16 #include "math_mathmlstream.h"
20 #include "frontends/Painter.h"
27 InsetMathRoot::InsetMathRoot()
32 auto_ptr<InsetBase> InsetMathRoot::doClone() const
34 return auto_ptr<InsetBase>(new InsetMathRoot(*this));
38 void InsetMathRoot::metrics(MetricsInfo & mi, Dimension & dim) const
40 InsetMathNest::metrics(mi);
41 dim.asc = max(cell(0).ascent() + 5, cell(1).ascent()) + 2;
42 dim.des = max(cell(1).descent() + 5, cell(0).descent()) + 2;
43 dim.wid = cell(0).width() + cell(1).width() + 10;
49 void InsetMathRoot::draw(PainterInfo & pi, int x, int y) const
51 int const w = cell(0).width();
53 cell(0).draw(pi, x, y - 5 - cell(0).descent());
55 cell(1).draw(pi, x + w + 8, y);
56 int const a = dim_.ascent();
57 int const d = dim_.descent();
60 xp[0] = x + dim_.width(); yp[0] = y - a + 1;
61 xp[1] = x + w + 4; yp[1] = y - a + 1;
62 xp[2] = x + w; yp[2] = y + d;
63 xp[3] = x + w - 2; yp[3] = y + (d - a)/2 + 2;
64 //xp[4] = x; yp[4] = y + (d - a)/2 + 2;
65 xp[4] = x + w - 5; yp[4] = y + (d - a)/2 + 4;
66 pi.pain.lines(xp, yp, 5, LColor::math);
67 drawMarkers(pi, x, y);
71 void InsetMathRoot::write(WriteStream & os) const
73 os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}';
77 void InsetMathRoot::normalize(NormalStream & os) const
79 os << "[root " << cell(0) << ' ' << cell(1) << ']';
83 bool InsetMathRoot::idxUpDown(LCursor & cur, bool up) const
85 LCursor::idx_type const target = up ? 0 : 1;
86 if (cur.idx() == target)
89 cur.pos() = up ? cur.lastpos() : 0;
94 void InsetMathRoot::maple(MapleStream & os) const
96 os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
100 void InsetMathRoot::octave(OctaveStream & os) const
102 os << "root(" << cell(1) << ',' << cell(0) << ')';
106 void InsetMathRoot::mathmlize(MathMLStream & os) const
108 os << MTag("mroot") << cell(1) << cell(0) << ETag("mroot");