]> git.lyx.org Git - lyx.git/blob - src/mathed/math_inset.C
bc635a3a7b00917d3943e60c12dedaf916d87e4f
[lyx.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(int nargs, string const & name, MathInsetTypes ot)
34         : name_(name), objtype(ot), width_(0), ascent_(0), descent_(0),
35                 size_(LM_ST_DISPLAY), 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 string const & MathInset::name() const
74 {
75         return name_;
76 }
77
78
79 MathInsetTypes MathInset::GetType() const
80 {
81         return objtype;
82 }
83
84
85 void MathInset::SetType(MathInsetTypes t)
86 {
87         objtype = t;
88 }
89
90
91 void MathInset::SetName(string const & n)
92 {
93         name_ = n;
94 }
95
96
97 MathStyles MathInset::size() const
98 {
99         return size_;
100 }
101
102
103 void MathInset::size(MathStyles s)
104 {
105         size_ = s;
106 }
107
108 std::ostream & operator<<(std::ostream & os, MathInset const & inset)
109 {
110         inset.Write(os, false);
111         return os;
112 }
113
114
115 int MathInset::xo() const
116 {
117         return xo_;
118 }
119
120
121 int MathInset::yo() const
122 {
123         return yo_;
124 }
125
126
127 void MathInset::xo(int x)
128 {
129         xo_ = x;
130 }
131
132
133 void MathInset::yo(int y)
134 {
135         yo_ = y;
136 }
137
138
139 int MathInset::nargs() const
140 {
141         return cells_.size();
142 }
143
144
145
146 MathXArray & MathInset::xcell(int i)
147 {
148         return cells_[i];
149 }
150
151 MathXArray const & MathInset::xcell(int i) const
152 {
153         return cells_[i];
154 }
155
156
157
158 MathArray & MathInset::cell(int i)
159 {
160         return cells_[i].data_;
161 }
162
163 MathArray const & MathInset::cell(int i) const
164 {
165         return cells_[i].data_;
166 }
167
168
169 void MathInset::substitute(MathArray & array, MathMacro const & m) const
170 {
171         MathInset * p = clone();
172         for (int i = 0; i < nargs(); ++i)
173                 p->cell(i).substitute(m);
174         array.push_back(p);
175 }
176
177 void MathInset::Metrics(MathStyles st, int, int)
178 {
179         size_ = st;
180         for (int i = 0; i < nargs(); ++i)
181                 xcell(i).Metrics(st);
182 }
183
184 void MathInset::draw(Painter & pain, int x, int y)
185 {
186         xo_ = x;
187         yo_ = y;
188         for (int i = 0; i < nargs(); ++i)
189                 xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
190 }
191
192
193 bool MathInset::idxNext(int & idx, int & pos) const
194 {
195         if (idx + 1 >= nargs())
196                 return false;
197         ++idx;
198         pos = 0;
199         return true;
200 }
201
202
203 bool MathInset::idxRight(int & idx, int & pos) const
204 {
205         return idxNext(idx, pos);
206 }
207
208
209 bool MathInset::idxPrev(int & idx, int & pos) const
210 {
211         if (idx == 0)
212                 return false;
213         --idx;
214         pos = cell(idx).size();
215         return true;
216 }
217
218
219 bool MathInset::idxLeft(int & idx, int & pos) const
220 {
221         return idxPrev(idx, pos);
222 }
223
224 bool MathInset::idxUp(int &, int &) const
225 {
226         return false;
227 }
228
229
230 bool MathInset::idxDown(int &, int &) const
231 {
232         return false;
233 }
234
235
236 bool MathInset::idxFirst(int & i, int & pos) const
237 {
238         if (nargs() == 0)
239                 return false;
240         i = 0;
241         pos = 0;
242         return true;
243 }
244
245 bool MathInset::idxLast(int & i, int & pos) const
246 {
247         if (nargs() == 0)
248                 return false;
249         i = nargs() - 1;
250         pos = cell(i).size();
251         return true;
252 }
253
254
255 bool MathInset::idxHome(int & /* idx */, int & pos) const
256 {
257         if (pos == 0)
258                 return false;
259         pos = 0;
260         return true;
261 }
262
263
264 bool MathInset::idxEnd(int & idx, int & pos) const
265 {
266         if (pos == cell(idx).size())
267                 return false;
268
269         pos = cell(idx).size();
270         return true;
271 }
272
273
274 bool MathInset::idxFirstUp(int &, int &) const
275 {
276         return false;
277 }
278
279
280 bool MathInset::idxFirstDown(int &, int &) const
281 {
282         return false;
283 }
284
285 void MathInset::idxDelete(int &, bool & popit, bool & deleteit)
286 {
287         popit    = false;
288         deleteit = 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 }