]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSqrt.cpp
dc154f8f6b6573dde96f5477372c267a349da9b7
[lyx.git] / src / mathed / InsetMathSqrt.cpp
1 /**
2  * \file InsetMathSqrt.cpp
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 "InsetMathSqrt.h"
14 #include "MathData.h"
15 #include "MathExtern.h"
16 #include "MathStream.h"
17 #include "TextPainter.h"
18 #include "frontends/Painter.h"
19
20
21 namespace lyx {
22
23 InsetMathSqrt::InsetMathSqrt(Buffer * buf)
24         : InsetMathNest(buf, 1)
25 {}
26
27
28 Inset * InsetMathSqrt::clone() const
29 {
30         return new InsetMathSqrt(*this);
31 }
32
33
34 void InsetMathSqrt::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 }
42
43
44 void InsetMathSqrt::draw(PainterInfo & pi, int x, int y) const
45 {
46         cell(0).draw(pi, x + 10, y);
47         Dimension const dim = dimension(*pi.base.bv);
48         int const a = dim.ascent();
49         int const d = dim.descent();
50         int xp[3];
51         int yp[3];
52         pi.pain.line(x + dim.width(), y - a + 1,
53                 x + 8, y - a + 1, Color_math);
54         xp[0] = x + 8;            yp[0] = y - a + 1;
55         xp[1] = x + 5;            yp[1] = y + d - 1;
56         xp[2] = x;                yp[2] = y + (d - a)/2;
57         pi.pain.lines(xp, yp, 3, Color_math);
58         drawMarkers(pi, x, y);
59 }
60
61
62 void InsetMathSqrt::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
63 {
64         cell(0).metricsT(mi, dim);
65         dim.asc += 1;
66         dim.wid += 2;
67 }
68
69
70 void InsetMathSqrt::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
71 {
72         /*
73         cell(0).drawT(pain, x + 2, y);
74         Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
75         pain.horizontalLine(x + 2, y - dim0.ascent(), dim0.width(), '_');
76         pain.verticalLine  (x + 1, y - dim0.ascent() + 1, dim0.height());
77         pain.draw(x, y + dim0.descent(), '\\');
78         */
79 }
80
81
82 void InsetMathSqrt::write(WriteStream & os) const
83 {
84         MathEnsurer ensurer(os);
85         os << "\\sqrt{" << cell(0) << '}';
86 }
87
88
89 void InsetMathSqrt::normalize(NormalStream & os) const
90 {
91         os << "[sqrt " << cell(0) << ']';
92 }
93
94 void InsetMathSqrt::maple(MapleStream & os) const
95 {
96         os << "sqrt(" << cell(0) << ')';
97 }
98
99 void InsetMathSqrt::mathematica(MathematicaStream & os) const
100 {
101         os << "Sqrt[" << cell(0) << ']';
102 }
103
104
105 void InsetMathSqrt::octave(OctaveStream & os) const
106 {
107         os << "sqrt(" << cell(0) << ')';
108 }
109
110
111 docstring InsetMathSqrt::mathmlize(MathStream & os) const
112 {
113         os << MTag("msqrt");
114         docstring const rv = lyx::mathmlize(cell(0), os);
115         os << ETag("msqrt");
116         return rv;
117 }
118
119
120 } // namespace lyx