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