]> git.lyx.org Git - lyx.git/blob - src/mathed/math_fracinset.C
new hierarchy for frac-like things
[lyx.git] / src / mathed / math_fracinset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_fracinset.h"
6 #include "mathed/support.h"
7 #include "Painter.h"
8 #include "support/LOstream.h"
9
10
11 MathFracInset::MathFracInset()
12 {}
13
14
15 MathInset * MathFracInset::clone() const
16 {   
17         return new MathFracInset(*this);
18 }
19
20
21 void MathFracInset::metrics(MathStyles st) const
22 {
23         size_    = smallerStyleFrac(st);
24         xcell(0).metrics(size_);
25         xcell(1).metrics(size_);
26         width_   = std::max(xcell(0).width(), xcell(1).width()) + 4; 
27         ascent_  = xcell(0).height() + 4 + 5;
28         descent_ = xcell(1).height() + 4 - 5; 
29 }
30
31
32 void MathFracInset::draw(Painter & pain, int x, int y) const
33 {
34         xo(x);
35         yo(y);
36         int m = x + width() / 2;
37         xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
38         xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent()  + 3 - 5);
39         pain.line(x + 2, y - 5, x + width() - 4, y - 5, LColor::mathline);
40 }
41
42
43 void MathFracInset::write(std::ostream & os, bool fragile) const
44 {
45         os << "\\frac{";
46         cell(0).write(os, fragile);
47         os << "}{";
48         cell(1).write(os, fragile);
49         os << '}';
50 }
51
52
53 void MathFracInset::writeNormal(std::ostream & os) const
54 {
55         os << "[frac ";
56         cell(0).writeNormal(os);
57         os << " ";
58         cell(1).writeNormal(os);
59         os << "] ";
60 }