A bit more re-organization.
[lyx.git] / src / mathed / InsetMathRoot.cpp
blob38c09469c90473840745c441e2b1fe307c47ce6c
1 /**
2 * \file InsetMathRoot.cpp
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
7 * \author André Pönitz
9 * Full author contact details are available in file CREDITS.
12 #include <config.h>
14 #include "InsetMathRoot.h"
15 #include "MathData.h"
16 #include "MathStream.h"
17 #include "Cursor.h"
19 #include "frontends/Painter.h"
21 using namespace std;
23 namespace lyx {
26 InsetMathRoot::InsetMathRoot(Buffer * buf)
27 : InsetMathNest(buf, 2)
31 Inset * InsetMathRoot::clone() const
33 return new InsetMathRoot(*this);
37 void InsetMathRoot::metrics(MetricsInfo & mi, Dimension & dim) const
39 InsetMathNest::metrics(mi);
40 Dimension const & dim0 = cell(0).dimension(*mi.base.bv);
41 Dimension const & dim1 = cell(1).dimension(*mi.base.bv);
42 dim.asc = max(dim0.ascent() + 5, dim1.ascent()) + 2;
43 dim.des = max(dim0.descent() - 5, dim1.descent()) + 2;
44 dim.wid = dim0.width() + dim1.width() + 10;
45 metricsMarkers(dim);
49 void InsetMathRoot::draw(PainterInfo & pi, int x, int y) const
51 Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
52 int const w = dim0.width();
53 // the "exponent"
54 cell(0).draw(pi, x, y - 5 - dim0.descent());
55 // the "base"
56 cell(1).draw(pi, x + w + 8, y);
57 Dimension const dim = dimension(*pi.base.bv);
58 int const a = dim.ascent();
59 int const d = dim.descent();
60 int xp[4];
61 int yp[4];
62 pi.pain.line(x + dim.width(), y - a + 1,
63 x + w + 4, y - a + 1, Color_math);
64 xp[0] = x + w + 4; yp[0] = y - a + 1;
65 xp[1] = x + w; yp[1] = y + d;
66 xp[2] = x + w - 2; yp[2] = y + (d - a)/2 + 2;
67 xp[3] = x + w - 5; yp[3] = y + (d - a)/2 + 4;
68 pi.pain.lines(xp, yp, 4, Color_math);
69 drawMarkers(pi, x, y);
73 void InsetMathRoot::write(WriteStream & os) const
75 MathEnsurer ensurer(os);
76 os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}';
80 void InsetMathRoot::normalize(NormalStream & os) const
82 os << "[root " << cell(0) << ' ' << cell(1) << ']';
86 bool InsetMathRoot::idxUpDown(Cursor & cur, bool up) const
88 Cursor::idx_type const target = up ? 0 : 1;
89 if (cur.idx() == target)
90 return false;
91 cur.idx() = target;
92 cur.pos() = up ? cur.lastpos() : 0;
93 return true;
97 void InsetMathRoot::maple(MapleStream & os) const
99 os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
103 void InsetMathRoot::mathematica(MathematicaStream & os) const
105 os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
109 void InsetMathRoot::octave(OctaveStream & os) const
111 os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
115 void InsetMathRoot::mathmlize(MathStream & os) const
117 os << MTag("mroot") << cell(1) << cell(0) << ETag("mroot");
121 } // namespace lyx