]> git.lyx.org Git - lyx.git/blob - src/mathed/math_updowninset.C
fix pullArg when pressing <Delete> at the end of an cell
[lyx.git] / src / mathed / math_updowninset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_updowninset.h"
6 #include "support/LOstream.h"
7
8
9 MathUpDownInset::MathUpDownInset()
10         : MathInset(2), up_(false), down_(false)
11 {}
12
13 MathUpDownInset::MathUpDownInset(bool up, bool down)
14         : MathInset(2), up_(up), down_(down)
15 {}
16
17
18 MathInset * MathUpDownInset::clone() const
19 {   
20         return new MathUpDownInset(*this);
21 }
22
23
24 bool MathUpDownInset::up() const
25 {
26         return up_;
27 }
28
29 bool MathUpDownInset::down() const
30 {
31         return down_;
32 }
33
34 void MathUpDownInset::up(bool b)
35 {
36         up_ = b;
37 }
38
39 void MathUpDownInset::down(bool b)
40 {
41         down_ = b;
42 }
43
44
45 bool MathUpDownInset::idxRight(int &, int &) const
46 {
47         return false;
48 }
49
50 bool MathUpDownInset::idxLeft(int &, int &) const
51 {
52         return false;
53 }
54
55
56 bool MathUpDownInset::idxUp(int & idx, int & pos) const
57 {
58         if (idx == 0 || !up()) 
59                 return false;
60         idx = 0;
61         pos = 0;
62         return true;
63 }
64
65 bool MathUpDownInset::idxDown(int & idx, int & pos) const
66 {
67         if (idx == 1 || !down()) 
68                 return false;
69         idx = 1;
70         pos = 0;
71         return true;
72 }
73
74 bool MathUpDownInset::idxFirst(int & idx, int & pos) const
75 {
76         idx = up() ? 0 : 1;
77         pos = 0;
78         return true;
79 }
80
81 bool MathUpDownInset::idxLast(int & idx, int & pos) const
82 {
83         idx = down() ? 1 : 0;
84         pos = cell(idx).size();
85         return true;
86 }
87
88
89 bool MathUpDownInset::idxFirstUp(int & idx, int & pos) const
90 {
91         if (!up()) 
92                 return false;
93         idx = 0;
94         pos = 0;
95         return true;
96 }
97
98 bool MathUpDownInset::idxFirstDown(int & idx, int & pos) const
99 {
100         if (!down()) 
101                 return false;
102         idx = 1;
103         pos = 0;
104         return true;
105 }
106
107 bool MathUpDownInset::idxLastUp(int & idx, int & pos) const
108 {
109         if (!up()) 
110                 return false;
111         idx = 0;
112         pos = cell(idx).size();
113         return true;
114 }
115
116 bool MathUpDownInset::idxLastDown(int & idx, int & pos) const
117 {
118         if (!down()) 
119                 return false;
120         idx = 1;
121         pos = cell(idx).size();
122         return true;
123 }
124
125
126 void MathUpDownInset::idxDelete(int & idx, bool & popit, bool & deleteit)
127 {
128         if (idx == 0) 
129                 up(false);
130         else
131                 down(false);
132         popit = true;
133         deleteit = !(up() || down());
134 }
135
136 void MathUpDownInset::Write(std::ostream & os, bool fragile) const
137 {
138         if (up()) {
139                 os << "^{";
140                 cell(0).Write(os, fragile);
141                 os << "}";
142         }
143         if (down()) {
144                 os << "_{";
145                 cell(1).Write(os, fragile);
146                 os << "}";
147         }
148 }
149
150 void MathUpDownInset::Metrics(MathStyles st, int asc, int des)
151 {
152         if (up())
153                 xcell(0).Metrics(st);
154         if (down())
155                 xcell(1).Metrics(st);
156
157         // we assume that asc, des, wid are the metrics of the item in front
158         // of this MathScriptInset
159         width_   = std::max(xcell(0).width(), xcell(1).width());
160         ascent_  = up()   ? xcell(0).height() + asc : 0;
161         descent_ = down() ? xcell(1).height() : 0;
162         dy0_     = - asc  - xcell(0).descent();
163         dy1_     =   des + xcell(1).ascent();
164 }
165
166
167 void MathUpDownInset::draw(Painter & pain, int x, int y)
168
169         xo(x);
170         yo(y);
171         if (up())
172                 xcell(0).draw(pain, x, y + dy0_);
173         if (down())
174                 xcell(1).draw(pain, x, y + dy1_);
175 }
176