]> git.lyx.org Git - lyx.git/blob - src/mathed/math_rootinset.C
some (yet unfinished) up/down work
[lyx.git] / src / mathed / math_rootinset.C
1 /**
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.
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 "math_rootinset.h"
15 #include "math_data.h"
16 #include "math_mathmlstream.h"
17 #include "cursor.h"
18 #include "LColor.h"
19
20 #include "frontends/Painter.h"
21
22 using std::max;
23 using std::auto_ptr;
24
25
26
27 MathRootInset::MathRootInset()
28         : MathNestInset(2)
29 {}
30
31
32 auto_ptr<InsetBase> MathRootInset::doClone() const
33 {
34         return auto_ptr<InsetBase>(new MathRootInset(*this));
35 }
36
37
38 void MathRootInset::metrics(MetricsInfo & mi, Dimension & dim) const
39 {
40         MathNestInset::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;
44         metricsMarkers(dim);
45         dim_ = dim;
46 }
47
48
49 void MathRootInset::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[5];
59         int yp[5];
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);
68 }
69
70
71 void MathRootInset::write(WriteStream & os) const
72 {
73         os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}';
74 }
75
76
77 void MathRootInset::normalize(NormalStream & os) const
78 {
79         os << "[root " << cell(0) << ' ' << cell(1) << ']';
80 }
81
82
83 bool MathRootInset::idxUpDown(LCursor & cur, bool up) const
84 {
85         LCursor::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 MathRootInset::maple(MapleStream & os) const
95 {
96         os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
97 }
98
99
100 void MathRootInset::octave(OctaveStream & os) const
101 {
102         os << "root(" << cell(1) << ',' << cell(0) << ')';
103 }
104
105
106 void MathRootInset::mathmlize(MathMLStream & os) const
107 {
108         os << MTag("mroot") << cell(1) << cell(0) << ETag("mroot");
109 }