]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathRoot.cpp
* Inset:
[lyx.git] / src / mathed / InsetMathRoot.cpp
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.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "InsetMathRoot.h"
15 #include "MathData.h"
16 #include "MathStream.h"
17 #include "Cursor.h"
18 #include "Color.h"
19
20 #include "frontends/Painter.h"
21
22
23 namespace lyx {
24
25
26 InsetMathRoot::InsetMathRoot()
27         : InsetMathNest(2)
28 {}
29
30
31 Inset * InsetMathRoot::clone() const
32 {
33         return new InsetMathRoot(*this);
34 }
35
36
37 void InsetMathRoot::metrics(MetricsInfo & mi, Dimension & dim) const
38 {
39         using std::max;
40         InsetMathNest::metrics(mi);
41         dim.asc = max(cell(0).ascent()  + 5, cell(1).ascent())  + 2;
42         dim.des = max(cell(0).descent() - 5, cell(1).descent()) + 2;
43         dim.wid = cell(0).width() + cell(1).width() + 10;
44         metricsMarkers(dim);
45         dim_ = dim;
46 }
47
48
49 void InsetMathRoot::draw(PainterInfo & pi, int x, int y) const
50 {
51         int const w = cell(0).width();
52         // the "exponent"
53         cell(0).draw(pi, x, y - 5 - cell(0).descent());
54         // the "base"
55         cell(1).draw(pi, x + w + 8, y);
56         int const a = dim_.ascent();
57         int const d = dim_.descent();
58         int xp[4];
59         int yp[4];
60         pi.pain.line(x + dim_.width(), y - a + 1,
61                                                          x + w + 4, y - a + 1, Color::math);
62         xp[0] = x + w + 4;         yp[0] = y - a + 1;
63         xp[1] = x + w;             yp[1] = y + d;
64         xp[2] = x + w - 2;         yp[2] = y + (d - a)/2 + 2;
65         xp[3] = x + w - 5;         yp[3] = y + (d - a)/2 + 4;
66         pi.pain.lines(xp, yp, 4, Color::math);
67         drawMarkers(pi, x, y);
68 }
69
70
71 void InsetMathRoot::write(WriteStream & os) const
72 {
73         os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}';
74 }
75
76
77 void InsetMathRoot::normalize(NormalStream & os) const
78 {
79         os << "[root " << cell(0) << ' ' << cell(1) << ']';
80 }
81
82
83 bool InsetMathRoot::idxUpDown(Cursor & cur, bool up) const
84 {
85         Cursor::idx_type const target = up ? 0 : 1;
86         if (cur.idx() == target)
87                 return false;
88         cur.idx() = target;
89         cur.pos() = up ? cur.lastpos() : 0;
90         return true;
91 }
92
93
94 void InsetMathRoot::maple(MapleStream & os) const
95 {
96         os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
97 }
98
99
100 void InsetMathRoot::mathematica(MathematicaStream & os) const
101 {
102         os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
103 }
104
105
106 void InsetMathRoot::octave(OctaveStream & os) const
107 {
108         os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
109 }
110
111
112 void InsetMathRoot::mathmlize(MathStream & os) const
113 {
114         os << MTag("mroot") << cell(1) << cell(0) << ETag("mroot");
115 }
116
117
118 } // namespace lyx