]> git.lyx.org Git - features.git/blob - src/mathed/math_inset.C
LyX Drinkers United: patch 2
[features.git] / src / mathed / math_inset.C
1 /*
2  *  File:        math_inset.C
3  *  Purpose:     Implementation of insets for mathed
4  *  Author:      Alejandro Aguilar Sierra <asierra@servidor.unam.mx> 
5  *  Created:     January 1996
6  *  Description: 
7  *
8  *  Dependencies: Xlib, XForms
9  *
10  *  Copyright: 1996, 1997 Alejandro Aguilar Sierra
11  *
12  *   Version: 0.8beta.
13  *
14  *   You are free to use and modify this code under the terms of
15  *   the GNU General Public Licence version 2 or later.
16  */
17
18 #include <config.h>
19
20 #ifdef __GNUG__
21 #pragma implementation
22 #endif
23
24 #include "math_inset.h"
25 #include "mathed/support.h"
26 #include "Painter.h"
27 #include "debug.h"
28
29
30 int MathInset::workwidth;
31
32
33 MathInset::MathInset(string const & name, MathInsetTypes ot, int nargs)
34         : name_(name), objtype(ot), width_(0), ascent_(0), descent_(0),
35                 size_(LM_ST_TEXT), cells_(nargs), xo_(0), yo_(0)
36 {}
37
38
39 int MathInset::ascent() const
40 {
41         return ascent_;
42 }
43
44
45 int MathInset::descent() const
46 {
47         return descent_;
48 }
49
50
51 int MathInset::width() const
52 {
53         return width_;
54 }
55
56
57 int MathInset::height() const
58 {
59         return ascent_ + descent_;
60 }
61
62
63 int MathInset::limits() const
64 {
65         return false;
66 }
67
68
69 void MathInset::limits(int)
70 {
71 }
72
73 bool MathInset::hasLimits() const
74 {
75         return false;
76 }
77
78
79 string const & MathInset::name() const
80 {
81         return name_;
82 }
83
84
85 MathInsetTypes MathInset::GetType() const
86 {
87         return objtype;
88 }
89
90
91 void MathInset::SetType(MathInsetTypes t)
92 {
93         objtype = t;
94 }
95
96
97 void MathInset::SetName(string const & n)
98 {
99         name_ = n;
100 }
101
102
103 MathStyles MathInset::size() const
104 {
105         return size_;
106 }
107
108
109 void MathInset::size(MathStyles s)
110 {
111         size_ = s;
112 }
113
114 std::ostream & operator<<(std::ostream & os, MathInset const & inset)
115 {
116         inset.Write(os, false);
117         return os;
118 }
119
120
121 int MathInset::xo() const
122 {
123         return xo_;
124 }
125
126
127 int MathInset::yo() const
128 {
129         return yo_;
130 }
131
132
133 void MathInset::xo(int x)
134 {
135         xo_ = x;
136 }
137
138
139 void MathInset::yo(int y)
140 {
141         yo_ = y;
142 }
143
144
145 int MathInset::nargs() const
146 {
147         return cells_.size();
148 }
149
150
151
152 MathXArray & MathInset::xcell(int i)
153 {
154         return cells_[i];
155 }
156
157 MathXArray const & MathInset::xcell(int i) const
158 {
159         return cells_[i];
160 }
161
162
163
164 MathArray & MathInset::cell(int i)
165 {
166         return cells_[i].data_;
167 }
168
169 MathArray const & MathInset::cell(int i) const
170 {
171         return cells_[i].data_;
172 }
173
174
175 void MathInset::setData(MathArray const & a, int idx)
176 {
177         cells_[idx].data_ = a;
178 }
179
180
181 void MathInset::substitute(MathArray & array, MathMacro const & m) const
182 {
183         MathInset * p = Clone();
184         for (int i = 0; i < nargs(); ++i)
185                 p->cell(i).substitute(m);
186         array.push_back(p);
187 }
188
189 void MathInset::Metrics(MathStyles st)
190 {
191         size_ = st;
192         for (int i = 0; i < nargs(); ++i)
193                 xcell(i).Metrics(st);
194 }
195
196 void MathInset::draw(Painter & pain, int x, int y)
197 {
198         xo_ = x;
199         yo_ = y;
200         for (int i = 0; i < nargs(); ++i)
201                 xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
202 }
203
204
205 bool MathInset::idxRight(int & idx, int & pos) const
206 {
207         if (idx + 1 >= nargs())
208                 return false;
209         ++idx;
210         pos = 0;
211         return true;
212 }
213
214
215 bool MathInset::idxLeft(int & idx, int & pos) const
216 {
217         if (idx == 0)
218                 return false;
219         --idx;
220         pos = cell(idx).size();
221         return true;
222 }
223
224
225 bool MathInset::idxUp(int &, int &) const
226 {
227         return false;
228 }
229
230
231 bool MathInset::idxDown(int &, int &) const
232 {
233         return false;
234 }
235
236
237 bool MathInset::idxFirst(int & i, int & pos) const
238 {
239         if (nargs() == 0)
240                 return false;
241         i = 0;
242         pos = 0;
243         return true;
244 }
245
246 bool MathInset::idxLast(int & i, int & pos) const
247 {
248         if (nargs() == 0)
249                 return false;
250         i = nargs() - 1;
251         pos = cell(i).size();
252         return true;
253 }
254
255
256 bool MathInset::idxHome(int & /* idx */, int & pos) const
257 {
258         if (pos == 0)
259                 return false;
260         pos = 0;
261         return true;
262 }
263
264
265 bool MathInset::idxEnd(int & idx, int & pos) const
266 {
267         if (pos == cell(idx).size())
268                 return false;
269
270         pos = cell(idx).size();
271         return true;
272 }
273
274
275 bool MathInset::idxFirstUp(int &, int &) const
276 {
277         return false;
278 }
279
280
281 bool MathInset::idxFirstDown(int &, int &) const
282 {
283         return false;
284 }
285
286 bool MathInset::idxDelete(int)
287 {
288         return false;
289 }
290
291
292 bool MathInset::idxLastUp(int &, int &) const
293 {
294         return false;
295 }
296
297
298 bool MathInset::idxLastDown(int &, int &) const
299 {
300         return false;
301 }
302
303
304 void MathInset::GetXY(int & x, int & y) const
305 {
306    x = xo();
307    y = yo();
308 }
309
310
311 /*
312 void MathInset::UserSetSize(MathStyles sz)
313 {
314         if (sz >= 0) {
315                 size_ = sz;      
316                 flag = flag & ~LMPF_FIXED_SIZE;
317         }
318 }
319 */
320
321 void MathInset::WriteNormal(std::ostream & os) const
322 {
323         os << "[" << name_ << "] ";
324 }
325
326
327 void MathInset::dump() const
328 {
329         lyxerr << "---------------------------------------------\n";
330         Write(lyxerr, false);
331         lyxerr << "\n";
332         for (int i = 0; i < nargs(); ++i)
333                 lyxerr << cell(i) << "\n";
334         lyxerr << "---------------------------------------------\n";
335 }
336
337
338 void MathInset::push_back(byte ch, MathTextCodes fcode)
339 {
340         if (nargs())
341                 cells_.back().data_.push_back(ch, fcode);
342         else
343                 lyxerr << "can't push without a cell\n";
344 }
345
346
347 void MathInset::push_back(MathInset * p)
348 {
349         if (nargs())
350                 cells_.back().data_.push_back(p);
351         else
352                 lyxerr << "can't push without a cell\n";
353 }
354
355
356 bool MathInset::covers(int x, int y) const
357 {
358         return
359                 x >= xo_ &&
360                 x <= xo_ + width_ &&
361                 y >= yo_ - ascent_ &&
362                 y <= yo_ + descent_;
363 }
364