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;
63 class MathScriptInset;
64 class MathStringInset;
66 class MathSymbolInset;
67 class MathUnknownInset;
68 class MathXYMatrixInset;
81 class MathMacroTemplate;
87 /// short of anything else reasonable
88 typedef MathArray::size_type size_type;
89 /// type for cursor positions differences within a cell
90 typedef MathArray::difference_type difference_type;
91 /// type for cursor positions within a cell
92 typedef MathArray::size_type pos_type;
93 /// type for cell indices
94 typedef size_type idx_type;
95 /// type for row numbers
96 typedef size_type row_type;
97 /// type for column numbers
98 typedef size_type col_type;
100 /// our members behave nicely...
102 /// the virtual base destructor
103 virtual ~MathInset() {}
106 virtual MathInset * clone() const = 0;
107 /// substitutes macro arguments if necessary
108 virtual void substitute(MathMacro const & macro);
109 /// compute the size of the object, sets ascend_, descend_ and width_
110 // updates the (xo,yo)-caches of all contained cells
111 virtual void metrics(MathMetricsInfo & st) const;
113 virtual void draw(MathPainterInfo &, int x, int y) const;
114 /// the ascent of the inset above the baseline
115 /// compute the size of the object for text based drawing
116 virtual void metricsT(TextMetricsInfo const & st) const;
117 /// draw the object as text
118 virtual void drawT(TextPainter &, int x, int y) const;
119 /// the ascent of the inset above the baseline
120 virtual int ascent() const { return 1; }
121 /// the descent of the inset below the baseline
122 virtual int descent() const { return 1; }
124 virtual int width() const { return 2; }
125 /// total height (== ascent + descent)
126 virtual int height() const;
128 /// Where should we go when we press the up or down cursor key?
129 virtual bool idxUpDown(idx_type & idx, bool up) const;
131 virtual bool idxLeft(idx_type & idx, pos_type & pos) const;
133 virtual bool idxRight(idx_type & idx, pos_type & pos) const;
135 /// Move one physical cell up
136 virtual bool idxNext(idx_type & idx, pos_type & pos) const;
137 /// Move one physical cell down
138 virtual bool idxPrev(idx_type & idx, pos_type & pos) const;
140 /// Target pos when we enter the inset from the left by pressing "Right"
141 virtual bool idxFirst(idx_type & idx, pos_type & pos) const;
142 /// Target pos when we enter the inset from the right by pressing "Left"
143 virtual bool idxLast(idx_type & idx, pos_type & pos) const;
145 /// Where should we go if we press home?
146 virtual bool idxHome(idx_type & idx, pos_type & pos) const;
147 /// Where should we go if we press end?
148 virtual bool idxEnd(idx_type & idx, pos_type & pos) const;
150 /// Delete a cell and move cursor
151 virtual bool idxDelete(idx_type &) { return false; }
152 /// pulls cell after pressing erase
153 virtual void idxGlue(idx_type) {}
154 // returns list of cell indices that are "between" from and to for
155 // selection purposes
156 virtual std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
158 /// the number of nested cells this inset owns
159 virtual idx_type nargs() const;
161 /// return cell given its number
162 virtual MathArray & cell(idx_type);
163 /// return cell given its number
164 virtual MathArray const & cell(idx_type) const;
165 /// return cell plus drawing cache given its number
166 virtual MathXArray & xcell(idx_type);
167 /// return cell plus drawing cache given its number
168 virtual MathXArray const & xcell(idx_type) const;
170 /// the number of columns of this inset if it is grid-like
171 virtual col_type ncols() const { return 1; }
172 /// the number of rows of this inset if it is grid-like
173 virtual row_type nrows() const { return 1; }
174 /// to which column belongs a cell with a given index?
175 virtual col_type col(idx_type) const { return 0; }
176 /// to which row belongs a cell with a given index?
177 virtual row_type row(idx_type) const { return 0; }
178 /// cell idex corresponding to row and column;
179 virtual idx_type index(row_type row, col_type col) const;
180 /// any additional x-offset when drawing a cell?
181 virtual int cellXOffset(idx_type) const { return 0; }
182 /// any additional y-offset when drawing a cell?
183 virtual int cellYOffset(idx_type) const { return 0; }
184 /// can we enter this cell?
185 virtual bool validCell(idx_type) const { return true; }
187 /// identifies certain types of insets
188 virtual MathAMSArrayInset * asAMSArrayInset() { return 0; }
189 virtual MathArrayInset * asArrayInset() { return 0; }
190 virtual MathBraceInset * asBraceInset() { return 0; }
191 virtual MathBoxInset * asBoxInset() { return 0; }
192 virtual MathBoxInset const * asBoxInset() const { return 0; }
193 virtual MathCharInset const * asCharInset() const { return 0; }
194 virtual MathDelimInset * asDelimInset() { return 0; }
195 virtual MathDelimInset const * asDelimInset() const { return 0; }
196 virtual MathFontInset const * asFontInset() const { return 0; }
197 virtual MathFuncInset * asFuncInset() { return 0; }
198 virtual MathFracInset * asFracInset() { return 0; }
199 virtual MathGridInset * asGridInset() { return 0; }
200 virtual MathHullInset * asHullInset() { return 0; }
201 virtual MathHullInset const * asHullInset() const { return 0; }
202 virtual MathMacroTemplate * asMacroTemplate() { return 0; }
203 virtual MathMatrixInset const * asMatrixInset() const { return 0; }
204 virtual MathNestInset * asNestInset() { return 0; }
205 virtual MathScriptInset * asScriptInset() { return 0; }
206 virtual MathScriptInset const * asScriptInset() const { return 0; }
207 virtual MathSpaceInset * asSpaceInset() { return 0; }
208 virtual MathStringInset * asStringInset() { return 0; }
209 virtual MathSymbolInset const * asSymbolInset() const { return 0; }
210 virtual MathUnknownInset * asUnknownInset() { return 0; }
211 virtual MathUnknownInset const * asUnknownInset() const { return 0; }
212 virtual MathXYMatrixInset const* asXYMatrixInset() const{ return 0; }
214 /// identifies things that can get scripts
215 virtual bool isScriptable() const { return false; }
216 /// thing that can be moved into
217 virtual bool isActive() const { return nargs() > 0; }
218 /// is the a relational operator (used for splitting equations)
219 virtual bool isRelOp() const { return false; }
221 /// return the content as char if the inset is able to do so
222 virtual char getChar() const { return 0; }
223 /// identifies things that can get \limits or \nolimits
224 virtual bool takesLimits() const { return false; }
225 /// identifies complicated things that need braces if used as arg
226 virtual bool needsBraces() const { return true; }
229 virtual void edit(BufferView *, int, int, mouse_button::state) {}
231 /// request "external features"
232 virtual void validate(LaTeXFeatures & features) const;
233 /// char char code if possible
234 virtual void handleFont(string const &) {}
235 /// is this inset equal to a given other inset?
236 virtual bool match(MathInset *) const { return false; }
237 /// replace things by other things
238 virtual void replace(ReplaceData &) {}
239 /// do we contain a given subsequence?
240 virtual bool contains(MathArray const &) { return false; }
241 /// access to the lock (only nest array have one)
242 virtual bool lock() const { return false; }
243 /// access to the lock (only nest array have one)
244 virtual void lock(bool) {}
246 /// write LaTeX and Lyx code
247 virtual void write(WriteStream & os) const;
248 /// write normalized content
249 virtual void normalize(NormalStream &) const;
250 /// write content as something readable by Maple
251 virtual void maplize(MapleStream &) const;
252 /// write content as something resembling MathML
253 virtual void mathmlize(MathMLStream &) const;
254 /// write content as something readable by Octave
255 virtual void octavize(OctaveStream &) const;
257 virtual void infoize(std::ostream &) const {}
259 /// dump content to stderr for debugging
260 virtual void dump() const;
263 std::ostream & operator<<(std::ostream &, MathInset const &);
264 std::ostream & operator<<(std::ostream &, MathAtom const &);