]> git.lyx.org Git - lyx.git/blob - src/mathed/math_fracinset.C
merge MathArray and MathXArray classes.
[lyx.git] / src / mathed / math_fracinset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_fracinset.h"
6 #include "math_support.h"
7 #include "frontends/Painter.h"
8 #include "math_mathmlstream.h"
9 #include "textpainter.h"
10
11
12 using std::max;
13
14
15 MathFracInset::MathFracInset(bool atop)
16         : atop_(atop)
17 {}
18
19
20 MathInset * MathFracInset::clone() const
21 {
22         return new MathFracInset(*this);
23 }
24
25
26 MathFracInset * MathFracInset::asFracInset()
27 {
28         return atop_ ? 0 : this;
29 }
30
31
32 void MathFracInset::metrics(MathMetricsInfo & mi) const
33 {
34         MathFracChanger dummy(mi.base);
35         cell(0).metrics(mi);
36         cell(1).metrics(mi);
37         dim_.w = max(cell(0).width(), cell(1).width()) + 2;
38         dim_.a = cell(0).height() + 2 + 5;
39         dim_.d = cell(1).height() + 2 - 5;
40 }
41
42
43 void MathFracInset::draw(MathPainterInfo & pi, int x, int y) const
44 {
45         int m = x + width() / 2;
46         MathFracChanger dummy(pi.base);
47         cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 2 - 5);
48         cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent()  + 2 - 5);
49         if (!atop_)
50                 pi.pain.line(x + 1, y - 5, x + width() - 2, y - 5, LColor::math);
51 }
52
53
54 void MathFracInset::metricsT(TextMetricsInfo const & mi) const
55 {
56         cell(0).metricsT(mi);
57         cell(1).metricsT(mi);
58         dim_.w = max(cell(0).width(), cell(1).width());
59         dim_.a = cell(0).height() + 1;
60         dim_.d = cell(1).height();
61 }
62
63
64 void MathFracInset::drawT(TextPainter & pain, int x, int y) const
65 {
66         int m = x + width() / 2;
67         cell(0).drawT(pain, m - cell(0).width() / 2, y - cell(0).descent() - 1);
68         cell(1).drawT(pain, m - cell(1).width() / 2, y + cell(1).ascent());
69         if (!atop_)
70                 pain.horizontalLine(x, y, width());
71 }
72
73
74 void MathFracInset::write(WriteStream & os) const
75 {
76         if (atop_)
77                 os << '{' << cell(0) << "\\atop " << cell(1) << '}';
78         else // it's \\frac
79                 MathNestInset::write(os);
80 }
81
82
83 string MathFracInset::name() const
84 {
85         return atop_ ? "atop" : "frac";
86 }
87
88
89 void MathFracInset::maplize(MapleStream & os) const
90 {
91         os << '(' << cell(0) << ")/(" << cell(1) << ')';
92 }
93
94
95 void MathFracInset::mathematicize(MathematicaStream & os) const
96 {
97         os << '(' << cell(0) << ")/(" << cell(1) << ')';
98 }
99
100
101 void MathFracInset::octavize(OctaveStream & os) const
102 {
103         os << '(' << cell(0) << ")/(" << cell(1) << ')';
104 }
105
106
107 void MathFracInset::mathmlize(MathMLStream & os) const
108 {
109         os << MTag("mfrac") << cell(0) << cell(1) << ETag("mfrac");
110 }