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