]> git.lyx.org Git - lyx.git/blob - src/mathed/math_fracinset.C
further code uglification to make Jean-Marc's compiler happy
[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(bool atop)
12         : atop_(atop)
13 {}
14
15
16 MathInset * MathFracInset::clone() const
17 {   
18         return new MathFracInset(*this);
19 }
20
21
22 void MathFracInset::metrics(MathStyles st) const
23 {
24         size_    = smallerStyleFrac(st);
25         xcell(0).metrics(size_);
26         xcell(1).metrics(size_);
27         width_   = std::max(xcell(0).width(), xcell(1).width()) + 4; 
28         ascent_  = xcell(0).height() + 4 + 5;
29         descent_ = xcell(1).height() + 4 - 5; 
30 }
31
32
33 void MathFracInset::draw(Painter & pain, int x, int y) const
34 {
35         xo(x);
36         yo(y);
37         int m = x + width() / 2;
38         xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
39         xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent()  + 3 - 5);
40         if (!atop_)
41                 pain.line(x + 2, y - 5, x + width() - 4, y - 5, LColor::mathline);
42 }
43
44
45 void MathFracInset::write(std::ostream & os, bool fragile) const
46 {
47         if (atop_) {
48                 os << "{";
49                 cell(0).write(os, fragile);
50                 os << "\\atop ";
51                 cell(1).write(os, fragile);
52                 os << '}';
53         } else {
54                 os << "\\frac{";
55                 cell(0).write(os, fragile);
56                 os << "}{";
57                 cell(1).write(os, fragile);
58                 os << '}';
59         }
60 }
61
62
63 void MathFracInset::writeNormal(std::ostream & os) const
64 {
65         if (atop_) 
66                 os << "[atop ";
67         else
68                 os << "[frac ";
69         cell(0).writeNormal(os);
70         os << " ";
71         cell(1).writeNormal(os);
72         os << "] ";
73 }