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