]> git.lyx.org Git - lyx.git/blob - src/mathed/math_sqrtinset.C
Make Helge happy: no more crash on arrow up/down in math macro
[lyx.git] / src / mathed / math_sqrtinset.C
1 /**
2  * \file math_sqrtinset.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "math_sqrtinset.h"
14 #include "math_data.h"
15 #include "math_mathmlstream.h"
16 #include "textpainter.h"
17 #include "LColor.h"
18 #include "frontends/Painter.h"
19
20 using std::auto_ptr;
21
22
23 MathSqrtInset::MathSqrtInset()
24         : MathNestInset(1)
25 {}
26
27
28 auto_ptr<InsetBase> MathSqrtInset::doClone() const
29 {
30         return auto_ptr<InsetBase>(new MathSqrtInset(*this));
31 }
32
33
34 void MathSqrtInset::metrics(MetricsInfo & mi, Dimension & dim) const
35 {
36         cell(0).metrics(mi, dim);
37         dim.asc += 4;
38         dim.des += 2;
39         dim.wid += 12;
40         metricsMarkers(dim);
41         dim_ = dim;
42 }
43
44
45 void MathSqrtInset::draw(PainterInfo & pi, int x, int y) const
46 {
47         cell(0).draw(pi, x + 10, y);
48         int const a = dim_.ascent();
49         int const d = dim_.descent();
50         int xp[4];
51         int yp[4];
52         xp[0] = x + dim_.width(); yp[0] = y - a + 1;
53         xp[1] = x + 8;            yp[1] = y - a + 1;
54         xp[2] = x + 5;            yp[2] = y + d - 1;
55         xp[3] = x;                yp[3] = y + (d - a)/2;
56         pi.pain.lines(xp, yp, 4, LColor::math);
57         drawMarkers(pi, x, y);
58 }
59
60
61 void MathSqrtInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
62 {
63         cell(0).metricsT(mi, dim);
64         dim.asc += 1;
65         dim.wid += 2;
66 }
67
68
69 void MathSqrtInset::drawT(TextPainter & pain, int x, int y) const
70 {
71         cell(0).drawT(pain, x + 2, y);
72         pain.horizontalLine(x + 2, y - cell(0).ascent(), cell(0).width(), '_');
73         pain.verticalLine  (x + 1, y - cell(0).ascent() + 1, cell(0).height());
74         pain.draw(x, y + cell(0).descent(), '\\');
75 }
76
77
78 void MathSqrtInset::write(WriteStream & os) const
79 {
80         os << "\\sqrt{" << cell(0) << '}';
81 }
82
83
84 void MathSqrtInset::normalize(NormalStream & os) const
85 {
86         os << "[sqrt " << cell(0) << ']';
87 }
88
89 void MathSqrtInset::maple(MapleStream & os) const
90 {
91         os << "sqrt(" << cell(0) << ')';
92 }
93
94 void MathSqrtInset::mathematica(MathematicaStream & os) const
95 {
96         os << "Sqrt[" << cell(0) << ']';
97 }
98
99
100 void MathSqrtInset::octave(OctaveStream & os) const
101 {
102         os << "sqrt(" << cell(0) << ')';
103 }
104
105
106 void MathSqrtInset::mathmlize(MathMLStream & os) const
107 {
108         os << MTag("msqrt") << cell(0) << ETag("msqrt");
109 }