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