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