]> git.lyx.org Git - lyx.git/blob - src/mathed/math_inset.C
use a single function dimension() instead of three.
[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 #ifdef __GNUG__
19 #pragma implementation
20 #endif
21
22 #include <config.h>
23
24 #include "Lsstream.h"
25 #include "math_inset.h"
26 #include "math_scriptinset.h"
27 #include "math_charinset.h"
28 #include "math_mathmlstream.h"
29 #include "math_cursor.h"
30 #include "debug.h"
31
32 #include "frontends/LyXView.h"
33 #include "frontends/Dialogs.h"
34 #include "BufferView.h"
35 #include "formulabase.h"
36
37
38 using std::ostream;
39 using std::vector;
40
41
42 int MathInset::height() const
43 {
44         return ascent() + descent();
45 }
46
47
48 ostream & operator<<(ostream & os, MathAtom const & at)
49 {
50         if (at.nucleus())
51                 os << *(at.nucleus());
52         else
53                 os << "(nil)";
54         return os;
55 }
56
57
58 ostream & operator<<(ostream & os, MathInset const & inset)
59 {
60         WriteStream wi(os, false, false);
61         inset.write(wi);
62         return os;
63 }
64
65 MathInset::size_type MathInset::nargs() const
66 {
67         return 0;
68 }
69
70
71 void MathInset::dimensions(int & w, int & a, int & d) const
72 {
73         w = width();
74         a = ascent();
75         d = descent();
76 }
77
78
79 MathXArray dummyCell;
80
81 MathXArray & MathInset::xcell(idx_type)
82 {
83         lyxerr << "I don't have a cell 1\n";
84         return dummyCell;
85 }
86
87
88 MathXArray const & MathInset::xcell(idx_type) const
89 {
90         lyxerr << "I don't have a cell 2\n";
91         return dummyCell;
92 }
93
94
95 MathArray & MathInset::cell(idx_type)
96 {
97         lyxerr << "I don't have a cell 3\n";
98         return dummyCell.data();
99 }
100
101
102 MathArray const & MathInset::cell(idx_type) const
103 {
104         lyxerr << "I don't have a cell 4\n";
105         return dummyCell.data();
106 }
107
108
109 MathInset::idx_type MathInset::index(row_type row, col_type col) const
110 {
111         if (row != 0)
112                 lyxerr << "illegal row: " << row << "\n";
113         if (col != 0)
114                 lyxerr << "illegal col: " << col << "\n";
115         return 0;
116 }
117
118 void MathInset::substitute(MathMacro const &)
119 {}
120
121
122 bool MathInset::idxNext(idx_type &, pos_type &) const
123 {
124         return false;
125 }
126
127
128 bool MathInset::idxRight(idx_type &, pos_type &) const
129 {
130         return false;
131 }
132
133
134 bool MathInset::idxPrev(idx_type &, pos_type &) const
135 {
136         return false;
137 }
138
139
140 bool MathInset::idxLeft(idx_type &, pos_type &) const
141 {
142         return false;
143 }
144
145
146 bool MathInset::idxUpDown(idx_type &, bool) const
147 {
148         return false;
149 }
150
151
152 bool MathInset::idxFirst(idx_type &, pos_type &) const
153 {
154         return false;
155 }
156
157
158 bool MathInset::idxLast(idx_type &, pos_type &) const
159 {
160         return false;
161 }
162
163
164 bool MathInset::idxHome(idx_type &, pos_type &) const
165 {
166         return false;
167 }
168
169
170 bool MathInset::idxEnd(idx_type &, pos_type &) const
171 {
172         return false;
173 }
174
175
176 void MathInset::normalize(NormalStream & os) const
177 {
178         os << "[unknown ";
179         WriteStream wi(os.os(), false, true);
180         write(wi);
181         os << "] ";
182 }
183
184
185 void MathInset::dump() const
186 {
187         lyxerr << "---------------------------------------------\n";
188         WriteStream wi(lyxerr, false, true);
189         write(wi);
190         lyxerr << "\n---------------------------------------------\n";
191 }
192
193
194 void MathInset::validate(LaTeXFeatures &) const
195 {}
196
197
198 vector<MathInset::idx_type>
199         MathInset::idxBetween(idx_type from, idx_type to) const
200 {
201         vector<idx_type> res;
202         for (idx_type i = from; i <= to; ++i)
203                 res.push_back(i);
204         return res;
205 }
206
207
208 void MathInset::metrics(MathMetricsInfo &) const
209 {
210         lyxerr << "MathInset::metrics() called directly!\n";
211 }
212
213
214 void MathInset::draw(MathPainterInfo &, int, int) const
215 {
216         lyxerr << "MathInset::draw() called directly!\n";
217 }
218
219
220 void MathInset::metricsT(TextMetricsInfo const &) const
221 {
222 #ifdef WITH_WARNINGS
223         lyxerr << "MathInset::metricsT(Text) called directly!\n";
224 #endif
225 }
226
227
228 void MathInset::drawT(TextPainter &, int, int) const
229 {
230 #ifdef WITH_WARNINGS
231         lyxerr << "MathInset::drawT(Text) called directly!\n";
232 #endif
233 }
234
235
236
237 void MathInset::write(WriteStream &) const
238 {
239         lyxerr << "MathInset::write() called directly!\n";
240 }
241
242
243 void MathInset::octavize(OctaveStream & os) const
244 {
245         NormalStream ns(os.os());
246         normalize(ns);
247 }
248
249
250 void MathInset::maplize(MapleStream & os) const
251 {
252         NormalStream ns(os.os());
253         normalize(ns);
254 }
255
256
257 void MathInset::mathematicize(MathematicaStream & os) const
258 {
259         NormalStream ns(os.os());
260         normalize(ns);
261 }
262
263
264 void MathInset::mathmlize(MathMLStream & os) const
265 {
266         NormalStream ns(os.os());
267         normalize(ns);
268 }
269
270
271 int MathInset::ascii(std::ostream &, int) const
272 {
273         return 0;
274 }
275
276
277 int MathInset::linuxdoc(std::ostream &) const
278 {
279         return 0;
280 }
281
282
283 int MathInset::docbook(std::ostream &, bool) const
284 {
285         return 0;
286 }
287
288
289 int MathInset::dispatch(string const &, idx_type, pos_type) 
290 {
291         return 0; // undispatched
292 }
293
294
295 std::vector<string> MathInset::getLabelList() const
296 {
297         return std::vector<string>();
298 }
299
300
301 string const & MathInset::getType() const
302 {
303         static string t("none");
304         return t;
305 }
306
307
308 string asString(MathArray const & ar)
309 {
310         string res;
311         for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
312                 if ((*it)->getChar())
313                         res += (*it)->getChar();
314         return res;
315 }
316
317
318 MathArray asArray(string const & str)
319 {
320         MathArray ar;
321         for (string::const_iterator it = str.begin(); it != str.end(); ++it)
322                 ar.push_back(MathAtom(new MathCharInset(*it)));
323         return ar;
324 }
325
326
327 Dialogs * getDialogs()
328 {
329         return mathcursor->formula()->view()->owner()->getDialogs();
330 }
331
332
333 LyXFunc * getLyXFunc()
334 {
335         return mathcursor->formula()->view()->owner()->getLyXFunc();
336 }