]> git.lyx.org Git - lyx.git/blob - src/mathed/math_inset.C
fix 'vanishing \sin' bug
[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_mathmlstream.h"
28 #include "math_cursor.h"
29 #include "math_parser.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
66 MathInset::size_type MathInset::nargs() const
67 {
68         return 0;
69 }
70
71
72 Dimension MathInset::dimensions() const
73 {
74         lyxerr << "call MathInset::dimensions()\n";
75         return Dimension(width(), ascent(), descent());
76 }
77
78
79 MathArray dummyCell;
80
81 MathArray & MathInset::cell(idx_type)
82 {
83         lyxerr << "I don't have a cell 1\n";
84         return dummyCell;
85 }
86
87
88 MathArray const & MathInset::cell(idx_type) const
89 {
90         lyxerr << "I don't have a cell 2\n";
91         return dummyCell;
92 }
93
94
95 MathInset::idx_type MathInset::index(row_type row, col_type col) const
96 {
97         if (row != 0)
98                 lyxerr << "illegal row: " << row << "\n";
99         if (col != 0)
100                 lyxerr << "illegal col: " << col << "\n";
101         return 0;
102 }
103
104 void MathInset::substitute(MathMacro const &)
105 {}
106
107
108 bool MathInset::idxNext(idx_type &, pos_type &) const
109 {
110         return false;
111 }
112
113
114 bool MathInset::idxRight(idx_type &, pos_type &) const
115 {
116         return false;
117 }
118
119
120 bool MathInset::idxPrev(idx_type &, pos_type &) const
121 {
122         return false;
123 }
124
125
126 bool MathInset::idxLeft(idx_type &, pos_type &) const
127 {
128         return false;
129 }
130
131
132 bool MathInset::idxUpDown(idx_type &, pos_type &, bool, int) const
133 {
134         return false;
135 }
136
137
138 bool MathInset::idxFirst(idx_type &, pos_type &) const
139 {
140         return false;
141 }
142
143
144 bool MathInset::idxLast(idx_type &, pos_type &) const
145 {
146         return false;
147 }
148
149
150 bool MathInset::idxHome(idx_type &, pos_type &) const
151 {
152         return false;
153 }
154
155
156 bool MathInset::idxEnd(idx_type &, pos_type &) const
157 {
158         return false;
159 }
160
161
162 void MathInset::getPos(idx_type, pos_type, int & x, int & y) const
163 {
164         lyxerr << "MathInset::getPos() called directly!\n";
165         x = y = 0;
166 }
167
168
169 void MathInset::dump() const
170 {
171         lyxerr << "---------------------------------------------\n";
172         WriteStream wi(lyxerr, false, true);
173         write(wi);
174         lyxerr << "\n---------------------------------------------\n";
175 }
176
177
178 bool MathInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
179 {
180         return from <= idx && idx <= to;
181 }
182
183
184 void MathInset::metrics(MathMetricsInfo &) const
185 {
186         lyxerr << "MathInset::metrics() called directly!\n";
187 }
188
189
190 void MathInset::draw(MathPainterInfo &, int, int) const
191 {
192         lyxerr << "MathInset::draw() called directly!\n";
193 }
194
195
196 void MathInset::drawSelection(MathPainterInfo &,
197         idx_type, pos_type, idx_type, pos_type) const
198 {
199         lyxerr << "MathInset::drawSelection() called directly!\n";
200 }
201
202
203 void MathInset::metricsT(TextMetricsInfo const &) const
204 {
205 #ifdef WITH_WARNINGS
206         lyxerr << "MathInset::metricsT(Text) called directly!\n";
207 #endif
208 }
209
210
211 void MathInset::drawT(TextPainter &, int, int) const
212 {
213 #ifdef WITH_WARNINGS
214         lyxerr << "MathInset::drawT(Text) called directly!\n";
215 #endif
216 }
217
218
219
220 void MathInset::write(WriteStream & os) const
221 {
222         os << '\\' << name().c_str() << ' ';
223 }
224
225
226 void MathInset::normalize(NormalStream & os) const
227 {
228         os << '[' << name().c_str() << "] ";
229 }
230
231
232 void MathInset::octavize(OctaveStream & os) const
233 {
234         NormalStream ns(os.os());
235         normalize(ns);
236 }
237
238
239 void MathInset::maplize(MapleStream & os) const
240 {
241         NormalStream ns(os.os());
242         normalize(ns);
243 }
244
245
246 void MathInset::mathematicize(MathematicaStream & os) const
247 {
248         NormalStream ns(os.os());
249         normalize(ns);
250 }
251
252
253 void MathInset::mathmlize(MathMLStream & os) const
254 {
255         NormalStream ns(os.os());
256         normalize(ns);
257 }
258
259
260 int MathInset::ascii(std::ostream &, int) const
261 {
262         return 0;
263 }
264
265
266 int MathInset::linuxdoc(std::ostream &) const
267 {
268         return 0;
269 }
270
271
272 int MathInset::docbook(std::ostream &, bool) const
273 {
274         return 0;
275 }
276
277
278 int MathInset::dispatch(string const &, idx_type, pos_type) 
279 {
280         return 0; // undispatched
281 }
282
283
284 string const & MathInset::getType() const
285 {
286         static string t("none");
287         return t;
288 }
289
290
291 string MathInset::name() const
292 {
293         return "unknown";
294 }
295
296
297 string asString(MathArray const & ar)
298 {
299         std::ostringstream os;
300         WriteStream ws(os);
301         ws << ar;
302         return os.str();
303 }
304
305
306 MathArray asArray(string const & str)
307 {
308         MathArray ar;
309         mathed_parse_cell(ar, str);
310         return ar;
311 }
312
313
314 Dialogs * getDialogs()
315 {
316         return mathcursor->formula()->view()->owner()->getDialogs();
317 }
318
319
320 LyXFunc * getLyXFunc()
321 {
322         return mathcursor->formula()->view()->owner()->getLyXFunc();
323 }