]> git.lyx.org Git - lyx.git/blob - src/mathed/math_rootinset.C
98c214552afb28f0f0bf2305552b75ce6b1cc01c
[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 "LColor.h"
18 #include "frontends/Painter.h"
19
20
21 using std::max;
22 using std::auto_ptr;
23
24
25 MathRootInset::MathRootInset()
26         : MathNestInset(2)
27 {}
28
29
30 auto_ptr<InsetBase> MathRootInset::clone() const
31 {
32         return auto_ptr<InsetBase>(new MathRootInset(*this));
33 }
34
35
36 void MathRootInset::metrics(MetricsInfo & mi, Dimension & dim) const
37 {
38         MathNestInset::metrics(mi);
39         dim_.asc = max(cell(0).ascent()  + 5, cell(1).ascent())  + 2;
40         dim_.des = max(cell(1).descent() + 5, cell(0).descent()) + 2;
41         dim_.wid = cell(0).width() + cell(1).width() + 10;
42         metricsMarkers(1);
43         dim = dim_;
44 }
45
46
47 void MathRootInset::draw(PainterInfo & pi, int x, int y) const
48 {
49         int const w = cell(0).width();
50         // the "exponent"
51         cell(0).draw(pi, x, y - 5 - cell(0).descent());
52         // the "base"
53         cell(1).draw(pi, x + w + 8, y);
54         int const a = dim_.ascent();
55         int const d = dim_.descent();
56         int xp[5];
57         int yp[5];
58         xp[0] = x + dim_.width();  yp[0] = y - a + 1;
59         xp[1] = x + w + 4;         yp[1] = y - a + 1;
60         xp[2] = x + w;             yp[2] = y + d;
61         xp[3] = x + w - 2;         yp[3] = y + (d - a)/2 + 2;
62         //xp[4] = x;                 yp[4] = y + (d - a)/2 + 2;
63         xp[4] = x + w - 5;         yp[4] = y + (d - a)/2 + 4;
64         pi.pain.lines(xp, yp, 5, LColor::math);
65         drawMarkers(pi, x, y);
66 }
67
68
69 void MathRootInset::write(WriteStream & os) const
70 {
71         os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}';
72 }
73
74
75 void MathRootInset::normalize(NormalStream & os) const
76 {
77         os << "[root " << cell(0) << ' ' << cell(1) << ']';
78 }
79
80
81 bool MathRootInset::idxUpDown(idx_type & idx, pos_type & pos, bool up, int) const
82 {
83         bool target = !up; // up ? 0 : 1;
84         if (idx == target)
85                 return false;
86         idx = target;
87         pos = target ? 0 : cell(0).size();
88         return true;
89 }
90
91
92 void MathRootInset::maple(MapleStream & os) const
93 {
94         os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
95 }
96
97
98 void MathRootInset::octave(OctaveStream & os) const
99 {
100         os << "root(" << cell(1) << ',' << cell(0) << ')';
101 }
102
103
104 void MathRootInset::mathmlize(MathMLStream & os) const
105 {
106         os << MTag("mroot") << cell(1) << cell(0) << ETag("mroot");
107 }