]> git.lyx.org Git - lyx.git/blob - src/mathed/math_fracinset.C
fix pullArg when pressing <Delete> at the end of an cell
[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(string const & name)
12         : MathInset(2, name)
13 {}
14
15
16 MathInset * MathFracInset::clone() const
17 {   
18         return new MathFracInset(*this);
19 }
20
21
22 void MathFracInset::Metrics(MathStyles st, int, int)
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)
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         
41         if (name() == "frac")
42                 pain.line(x + 2, y - 5, x + width() - 4, y - 5, LColor::mathline);
43 }
44
45
46 void MathFracInset::Write(std::ostream & os, bool fragile) const
47 {
48         os << '\\' << name() << '{';
49         cell(0).Write(os, fragile);
50         os << "}{";
51         cell(1).Write(os, fragile);
52         os << '}';
53 }
54
55
56 void MathFracInset::WriteNormal(std::ostream & os) const
57 {
58         os << '[' << name() << ' ';
59         cell(0).WriteNormal(os);
60         os << " ";
61         cell(1).WriteNormal(os);
62         os << "] ";
63 }
64
65
66 bool MathFracInset::idxRight(int &, int &) const
67 {
68         return false;
69 }
70
71 bool MathFracInset::idxLeft(int &, int &) const
72 {
73         return false;
74 }
75
76
77 bool MathFracInset::idxUp(int & idx, int &) const
78 {
79         if (idx == 0)
80                 return false;
81         idx = 0;
82         return true;
83 }
84
85 bool MathFracInset::idxDown(int & idx, int &) const
86 {
87         if (idx == 1)
88                 return false;
89         idx = 1;
90         return true;
91 }
92
93 bool MathFracInset::idxFirstUp(int & idx, int & pos) const
94 {
95         idx = 0;
96         pos = 0;
97         return true;
98 }
99
100 bool MathFracInset::idxFirstDown(int & idx, int & pos) const
101 {
102         idx = 1;
103         pos = 0;
104         return true;
105 }
106
107 bool MathFracInset::idxLastUp(int & idx, int & pos) const
108 {
109         idx = 0;
110         pos = cell(idx).size();
111         return true;
112 }
113
114 bool MathFracInset::idxLastDown(int & idx, int & pos) const
115 {
116         idx = 1;
117         pos = cell(idx).size();
118         return true;
119 }
120