]> git.lyx.org Git - lyx.git/blob - src/mathed/math_fracinset.C
split super/subscript handling in new base class MathUpDownInset and
[lyx.git] / src / mathed / math_fracinset.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include <functional>
8
9 #include "math_fracinset.h"
10 #include "LColor.h"
11 #include "Painter.h"
12 #include "mathed/support.h"
13 #include "support/LOstream.h"
14
15
16 MathFracInset::MathFracInset(string const & name)
17         : MathInset(2, name)
18 {}
19
20
21 MathInset * MathFracInset::clone() const
22 {   
23         return new MathFracInset(*this);
24 }
25
26
27 void MathFracInset::Metrics(MathStyles st, int, int)
28 {
29         size_    = smallerStyleFrac(st);
30         xcell(0).Metrics(size_);
31         xcell(1).Metrics(size_);
32         width_   = std::max(xcell(0).width(), xcell(1).width()) + 4; 
33         ascent_  = xcell(0).height() + 4 + 5;
34         descent_ = xcell(1).height() + 4 - 5; 
35 }
36
37
38 void MathFracInset::draw(Painter & pain, int x, int y)
39 {
40         xo(x);
41         yo(y);
42         int m = x + width() / 2;
43         xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
44         xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent()  + 3 - 5);
45         
46         if (name() == "frac")
47                 pain.line(x + 2, y - 5, x + width() - 4, y - 5, LColor::mathline);
48 }
49
50
51 void MathFracInset::Write(std::ostream & os, bool fragile) const
52 {
53         os << '\\' << name() << '{';
54         cell(0).Write(os, fragile);
55         os << "}{";
56         cell(1).Write(os, fragile);
57         os << '}';
58 }
59
60
61 void MathFracInset::WriteNormal(std::ostream & os) const
62 {
63         os << '[' << name() << ' ';
64         cell(0).WriteNormal(os);
65         os << " ";
66         cell(1).WriteNormal(os);
67         os << "] ";
68 }
69
70
71 bool MathFracInset::idxRight(int &, int &) const
72 {
73         return false;
74 }
75
76 bool MathFracInset::idxLeft(int &, int &) const
77 {
78         return false;
79 }
80
81
82 bool MathFracInset::idxUp(int & idx, int &) const
83 {
84         if (idx == 0)
85                 return false;
86         idx = 0;
87         return true;
88 }
89
90 bool MathFracInset::idxDown(int & idx, int &) const
91 {
92         if (idx == 1)
93                 return false;
94         idx = 1;
95         return true;
96 }
97
98 bool MathFracInset::idxFirstUp(int & idx, int & pos) const
99 {
100         idx = 0;
101         pos = 0;
102         return true;
103 }
104
105 bool MathFracInset::idxFirstDown(int & idx, int & pos) const
106 {
107         idx = 1;
108         pos = 0;
109         return true;
110 }
111
112 bool MathFracInset::idxLastUp(int & idx, int & pos) const
113 {
114         idx = 0;
115         pos = cell(idx).size();
116         return true;
117 }
118
119 bool MathFracInset::idxLastDown(int & idx, int & pos) const
120 {
121         idx = 1;
122         pos = cell(idx).size();
123         return true;
124 }
125