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