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