]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSqrt.cpp
* src/frontends/controllers/Dialog.{cpp,h}:
[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<Inset> InsetMathSqrt::doClone() const
32 {
33         return auto_ptr<Inset>(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[3];
57         int yp[3];
58         pi.pain.line(x + dim_.width(), y - a + 1,
59                                                          x + 8, y - a + 1, Color::math);
60         xp[0] = x + 8;            yp[0] = y - a + 1;
61         xp[1] = x + 5;            yp[1] = y + d - 1;
62         xp[2] = x;                yp[2] = y + (d - a)/2;
63         pi.pain.lines(xp, yp, 3, Color::math);
64         drawMarkers(pi, x, y);
65 }
66
67
68 void InsetMathSqrt::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
69 {
70         cell(0).metricsT(mi, dim);
71         dim.asc += 1;
72         dim.wid += 2;
73 }
74
75
76 void InsetMathSqrt::drawT(TextPainter & pain, int x, int y) const
77 {
78         cell(0).drawT(pain, x + 2, y);
79         pain.horizontalLine(x + 2, y - cell(0).ascent(), cell(0).width(), '_');
80         pain.verticalLine  (x + 1, y - cell(0).ascent() + 1, cell(0).height());
81         pain.draw(x, y + cell(0).descent(), '\\');
82 }
83
84
85 void InsetMathSqrt::write(WriteStream & os) const
86 {
87         os << "\\sqrt{" << cell(0) << '}';
88 }
89
90
91 void InsetMathSqrt::normalize(NormalStream & os) const
92 {
93         os << "[sqrt " << cell(0) << ']';
94 }
95
96 void InsetMathSqrt::maple(MapleStream & os) const
97 {
98         os << "sqrt(" << cell(0) << ')';
99 }
100
101 void InsetMathSqrt::mathematica(MathematicaStream & os) const
102 {
103         os << "Sqrt[" << cell(0) << ']';
104 }
105
106
107 void InsetMathSqrt::octave(OctaveStream & os) const
108 {
109         os << "sqrt(" << cell(0) << ')';
110 }
111
112
113 void InsetMathSqrt::mathmlize(MathStream & os) const
114 {
115         os << MTag("msqrt") << cell(0) << ETag("msqrt");
116 }
117
118
119 } // namespace lyx