4 * Purpose: Declaration of insets for mathed
5 * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
6 * Created: January 1996
7 * Description: Math paragraph and objects for a WYSIWYG math editor.
9 * Dependencies: Xlib, XForms
11 * Copyright: 1996, 1997 Alejandro Aguilar Sierra
13 * Version: 0.8beta, Math & Lyx project.
15 * You are free to use and modify this code under the terms of
16 * the GNU General Public Licence version 2 or later.
19 // Note: These math insets are internal to Math and are not derived
32 #include "frontends/mouse_state.h"
33 #include "math_xdata.h"
37 Abstract base class for all math objects. A math insets is for use of the
38 math editor only, it isn't a general LyX inset. It's used to represent all
41 Math insets do not know there parents, a cursor position or things
42 like that. The are dumb object that are contained in other math insets
43 (mathNestInsets, in fact) thus forming a tree. The root of this tree is
44 always a mathHullInset, which provides an interface to the Outer World by
45 inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
51 class MathAMSArrayInset;
61 class MathMatrixInset;
64 class MathParboxInset;
65 class MathScriptInset;
66 class MathStringInset;
68 class MathSymbolInset;
69 class MathUnknownInset;
70 class MathXYMatrixInset;
71 class MathXYMatrixInset;
78 class MathematicaStream;
87 class MathMacroTemplate;
93 /// short of anything else reasonable
94 typedef MathArray::size_type size_type;
95 /// type for cursor positions differences within a cell
96 typedef MathArray::difference_type difference_type;
97 /// type for cursor positions within a cell
98 typedef MathArray::size_type pos_type;
99 /// type for cell indices
100 typedef size_type idx_type;
101 /// type for row numbers
102 typedef size_type row_type;
103 /// type for column numbers
104 typedef size_type col_type;
106 /// our members behave nicely...
108 /// the virtual base destructor
109 virtual ~MathInset() {}
112 virtual MathInset * clone() const = 0;
113 /// substitutes macro arguments if necessary
114 virtual void substitute(MathMacro const & macro);
115 /// compute the size of the object, sets ascend_, descend_ and width_
116 // updates the (xo,yo)-caches of all contained cells
117 virtual void metrics(MathMetricsInfo & st) const;
119 virtual void draw(MathPainterInfo &, int x, int y) const;
120 /// the ascent of the inset above the baseline
121 /// compute the size of the object for text based drawing
122 virtual void metricsT(TextMetricsInfo const & st) const;
123 /// draw the object as text
124 virtual void drawT(TextPainter &, int x, int y) const;
125 /// the ascent of the inset above the baseline
126 virtual int ascent() const { return 1; }
127 /// the descent of the inset below the baseline
128 virtual int descent() const { return 1; }
130 virtual int width() const { return 2; }
131 /// total height (== ascent + descent)
132 virtual int height() const;
134 /// Where should we go when we press the up or down cursor key?
135 virtual bool idxUpDown(idx_type & idx, bool up) const;
137 virtual bool idxLeft(idx_type & idx, pos_type & pos) const;
139 virtual bool idxRight(idx_type & idx, pos_type & pos) const;
141 /// Move one physical cell up
142 virtual bool idxNext(idx_type & idx, pos_type & pos) const;
143 /// Move one physical cell down
144 virtual bool idxPrev(idx_type & idx, pos_type & pos) const;
146 /// Target pos when we enter the inset from the left by pressing "Right"
147 virtual bool idxFirst(idx_type & idx, pos_type & pos) const;
148 /// Target pos when we enter the inset from the right by pressing "Left"
149 virtual bool idxLast(idx_type & idx, pos_type & pos) const;
151 /// Where should we go if we press home?
152 virtual bool idxHome(idx_type & idx, pos_type & pos) const;
153 /// Where should we go if we press end?
154 virtual bool idxEnd(idx_type & idx, pos_type & pos) const;
156 /// Delete a cell and move cursor
157 virtual bool idxDelete(idx_type &) { return false; }
158 /// pulls cell after pressing erase
159 virtual void idxGlue(idx_type) {}
160 // returns list of cell indices that are "between" from and to for
161 // selection purposes
162 virtual std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
164 /// the number of nested cells this inset owns
165 virtual idx_type nargs() const;
167 /// return cell given its number
168 virtual MathArray & cell(idx_type);
169 /// return cell given its number
170 virtual MathArray const & cell(idx_type) const;
171 /// return cell plus drawing cache given its number
172 virtual MathXArray & xcell(idx_type);
173 /// return cell plus drawing cache given its number
174 virtual MathXArray const & xcell(idx_type) const;
176 /// the number of columns of this inset if it is grid-like
177 virtual col_type ncols() const { return 1; }
178 /// the number of rows of this inset if it is grid-like
179 virtual row_type nrows() const { return 1; }
180 /// to which column belongs a cell with a given index?
181 virtual col_type col(idx_type) const { return 0; }
182 /// to which row belongs a cell with a given index?
183 virtual row_type row(idx_type) const { return 0; }
184 /// cell idex corresponding to row and column;
185 virtual idx_type index(row_type row, col_type col) const;
186 /// any additional x-offset when drawing a cell?
187 virtual int cellXOffset(idx_type) const { return 0; }
188 /// any additional y-offset when drawing a cell?
189 virtual int cellYOffset(idx_type) const { return 0; }
190 /// can we enter this cell?
191 virtual bool validCell(idx_type) const { return true; }
193 /// identifies certain types of insets
194 virtual MathAMSArrayInset * asAMSArrayInset() { return 0; }
195 virtual MathArrayInset * asArrayInset() { return 0; }
196 virtual MathBraceInset * asBraceInset() { return 0; }
197 virtual MathBoxInset * asBoxInset() { return 0; }
198 virtual MathBoxInset const * asBoxInset() const { return 0; }
199 virtual MathCharInset const * asCharInset() const { return 0; }
200 virtual MathDelimInset * asDelimInset() { return 0; }
201 virtual MathDelimInset const * asDelimInset() const { return 0; }
202 virtual MathFboxInset * asFboxInset() { return 0; }
203 virtual MathFontInset const * asFontInset() const { return 0; }
204 virtual MathFracInset * asFracInset() { return 0; }
205 virtual MathGridInset * asGridInset() { return 0; }
206 virtual MathHullInset * asHullInset() { return 0; }
207 virtual MathHullInset const * asHullInset() const { return 0; }
208 virtual MathMacroTemplate * asMacroTemplate() { return 0; }
209 virtual MathMatrixInset const * asMatrixInset() const { return 0; }
210 virtual MathNestInset * asNestInset() { return 0; }
211 virtual MathParInset * asParInset() { return 0; }
212 virtual MathParboxInset * asParboxInset() { return 0; }
213 virtual MathScriptInset * asScriptInset() { return 0; }
214 virtual MathScriptInset const * asScriptInset() const { return 0; }
215 virtual MathSpaceInset * asSpaceInset() { return 0; }
216 virtual MathStringInset * asStringInset() { return 0; }
217 virtual MathSymbolInset const * asSymbolInset() const { return 0; }
218 virtual MathUnknownInset * asUnknownInset() { return 0; }
219 virtual MathUnknownInset const * asUnknownInset() const { return 0; }
220 virtual MathXYMatrixInset const* asXYMatrixInset() const{ return 0; }
221 virtual InsetRef * asInsetRef() { return 0; }
223 /// identifies things that can get scripts
224 virtual bool isScriptable() const { return false; }
225 /// thing that can be moved into
226 virtual bool isActive() const { return nargs() > 0; }
227 /// is the a relational operator (used for splitting equations)
228 virtual bool isRelOp() const { return false; }
230 /// return the content as char if the inset is able to do so
231 virtual char getChar() const { return 0; }
232 /// identifies things that can get \limits or \nolimits
233 virtual bool takesLimits() const { return false; }
236 virtual void edit(BufferView *, int, int, mouse_button::state) {}
238 /// request "external features"
239 virtual void validate(LaTeXFeatures & features) const;
240 /// char char code if possible
241 virtual void handleFont(string const &) {}
242 /// is this inset equal to a given other inset?
243 virtual bool match(MathInset *) const { return false; }
244 /// replace things by other things
245 virtual void replace(ReplaceData &) {}
246 /// do we contain a given subsequence?
247 virtual bool contains(MathArray const &) { return false; }
248 /// access to the lock (only nest array have one)
249 virtual bool lock() const { return false; }
250 /// access to the lock (only nest array have one)
251 virtual void lock(bool) {}
252 /// get notification when the cursor leaves this inset
253 virtual void notifyCursorLeaves() {}
255 /// write LaTeX and Lyx code
256 virtual void write(WriteStream & os) const;
257 /// write normalized content
258 virtual void normalize(NormalStream &) const;
259 /// write content as something readable by Maple
260 virtual void maplize(MapleStream &) const;
261 /// write content as something readable by Mathematica
262 virtual void mathematicize(MathematicaStream &) const;
263 /// write content as something resembling MathML
264 virtual void mathmlize(MathMLStream &) const;
265 /// write content as something readable by Octave
266 virtual void octavize(OctaveStream &) const;
268 virtual void infoize(std::ostream &) const {}
269 /// plain ascii output
270 virtual int ascii(std::ostream & os, int) const;
272 virtual int linuxdoc(std::ostream & os) const;
274 virtual int docbook(std::ostream & os, bool) const;
276 /// dump content to stderr for debugging
277 virtual void dump() const;
279 virtual int dispatch(string const & cmd, idx_type idx, pos_type pos);
282 virtual std::vector<string> getLabelList() const;
284 virtual bool numberedType() const { return false; }
286 virtual string const & getType() const;
288 virtual void mutate(string const &) {}
289 /// how is the inset called in the .lyx file?
290 virtual string fileInsetLabel() const { return "Formula"; }
293 std::ostream & operator<<(std::ostream &, MathInset const &);
294 std::ostream & operator<<(std::ostream &, MathAtom const &);
296 string asString(MathArray const & ar);
297 MathArray asArray(string const & str);
299 /// here to ssave a few includes in the insets
303 Dialogs * getDialogs();
304 LyXFunc * getLyXFunc();