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