]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSqrt.cpp
23ded20156eb97e9c6d9dea34901d8e8f860a21c
[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 "MathStream.h"
16 #include "TextPainter.h"
17 #include "frontends/Painter.h"
18
19
20 namespace lyx {
21
22 InsetMathSqrt::InsetMathSqrt()
23         : InsetMathNest(1)
24 {}
25
26
27 Inset * InsetMathSqrt::clone() const
28 {
29         return new InsetMathSqrt(*this);
30 }
31
32
33 void InsetMathSqrt::metrics(MetricsInfo & mi, Dimension & dim) const
34 {
35         cell(0).metrics(mi, dim);
36         dim.asc += 4;
37         dim.des += 2;
38         dim.wid += 12;
39         metricsMarkers(dim);
40         // Cache the inset dimension. 
41         setDimCache(mi, dim);
42 }
43
44
45 void InsetMathSqrt::draw(PainterInfo & pi, int x, int y) const
46 {
47         cell(0).draw(pi, x + 10, y);
48         Dimension const dim = dimension(*pi.base.bv);
49         int const a = dim.ascent();
50         int const d = dim.descent();
51         int xp[3];
52         int yp[3];
53         pi.pain.line(x + dim.width(), y - a + 1,
54                 x + 8, y - a + 1, Color_math);
55         xp[0] = x + 8;            yp[0] = y - a + 1;
56         xp[1] = x + 5;            yp[1] = y + d - 1;
57         xp[2] = x;                yp[2] = y + (d - a)/2;
58         pi.pain.lines(xp, yp, 3, Color_math);
59         drawMarkers(pi, x, y);
60 }
61
62
63 void InsetMathSqrt::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
64 {
65         cell(0).metricsT(mi, dim);
66         dim.asc += 1;
67         dim.wid += 2;
68 }
69
70
71 void InsetMathSqrt::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
72 {
73         /*
74         cell(0).drawT(pain, x + 2, y);
75         Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
76         pain.horizontalLine(x + 2, y - dim0.ascent(), dim0.width(), '_');
77         pain.verticalLine  (x + 1, y - dim0.ascent() + 1, dim0.height());
78         pain.draw(x, y + dim0.descent(), '\\');
79         */
80 }
81
82
83 void InsetMathSqrt::write(WriteStream & os) const
84 {
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 void InsetMathSqrt::mathmlize(MathStream & os) const
112 {
113         os << MTag("msqrt") << cell(0) << ETag("msqrt");
114 }
115
116
117 } // namespace lyx