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
31 #include "math_xdata.h"
32 #include "math_defs.h"
36 Abstract base class for all math objects. A math insets is for use of the
37 math editor only, it isn't a general LyX inset. It's used to represent all
40 Math insets do not know there parents, a cursor position or things
41 like that. The are dumb object that are contained in other math insets
42 (mathNestInsets, in fact) thus forming a tree. The root of this tree is
43 always a mathHullInset, which provides an interface to the Outer World by
44 inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
57 class MathMatrixInset;
59 class MathScriptInset;
60 class MathStringInset;
62 class MathSymbolInset;
75 class MathMacroTemplate;
81 /// short of anything else reasonable
82 typedef MathArray::size_type size_type;
83 /// type for cursor positions differences within a cell
84 typedef MathArray::difference_type difference_type;
85 /// type for cursor positions within a cell
86 typedef MathArray::size_type pos_type;
87 /// type for cell indices
88 typedef size_type idx_type;
89 /// type for row numbers
90 typedef size_type row_type;
91 /// type for column numbers
92 typedef size_type col_type;
94 /// our members behave nicely...
96 /// the virtual base destructor
97 virtual ~MathInset() {}
100 virtual void draw(Painter &, int x, int y) const;
102 virtual MathInset * clone() const = 0;
103 /// substitutes macro arguments if necessary
104 virtual void substitute(MathMacro const & macro);
105 /// compute the size of the object, sets ascend_, descend_ and width_
106 // updates the (xo,yo)-caches of all contained cells
107 virtual void metrics(MathMetricsInfo const & st) const;
108 /// the ascent of the inset above the baseline
109 virtual int ascent() const { return 1; }
110 /// the descent of the inset below the baseline
111 virtual int descent() const { return 1; }
113 virtual int width() const { return 2; }
114 /// total height (== ascent + descent)
115 virtual int height() const;
117 /// Where should we go when we press the up cursor key?
118 virtual bool idxUp(idx_type & idx) const;
120 virtual bool idxDown(idx_type & idx) const;
122 virtual bool idxLeft(idx_type & idx, pos_type & pos) const;
124 virtual bool idxRight(idx_type & idx, pos_type & pos) const;
126 /// Move one physical cell up
127 virtual bool idxNext(idx_type & idx, pos_type & pos) const;
128 /// Move one physical cell down
129 virtual bool idxPrev(idx_type & idx, pos_type & pos) const;
131 /// Target pos when we enter the inset from the left by pressing "Right"
132 virtual bool idxFirst(idx_type & idx, pos_type & pos) const;
133 /// Target pos when we enter the inset from the right by pressing "Left"
134 virtual bool idxLast(idx_type & idx, pos_type & pos) const;
136 /// Where should we go if we press home?
137 virtual bool idxHome(idx_type & idx, pos_type & pos) const;
138 /// Where should we go if we press end?
139 virtual bool idxEnd(idx_type & idx, pos_type & pos) const;
141 /// Delete a cell and move cursor
142 // the return value indicates whether the cursor should leave the inset
143 // and/or the whole inset should be deleted
144 virtual void idxDelete(idx_type & idx, bool & popit, bool & deleteit);
145 // deletes a cell range and moves the cursor
146 virtual void idxDeleteRange(idx_type from, idx_type to);
147 // returns list of cell indices that are "between" from and to for
148 // selection purposes
149 virtual std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
151 /// the number of nested cells this inset owns
152 virtual idx_type nargs() const;
154 /// return cell given its number
155 virtual MathArray & cell(idx_type);
156 /// return cell given its number
157 virtual MathArray const & cell(idx_type) const;
158 /// return cell plus drawing cache given its number
159 virtual MathXArray & xcell(idx_type);
160 /// return cell plus drawing cache given its number
161 virtual MathXArray const & xcell(idx_type) const;
163 /// the number of columns of this inset if it is grid-like
164 virtual col_type ncols() const { return 1; }
165 /// the number of rows of this inset if it is grid-like
166 virtual row_type nrows() const { return 1; }
167 /// to which column belongs a cell with a given index?
168 virtual col_type col(idx_type) const { return 0; }
169 /// to which row belongs a cell with a given index?
170 virtual row_type row(idx_type) const { return 0; }
171 /// cell idex corresponding to row and column;
172 virtual idx_type index(row_type row, col_type col) const;
173 /// any additional x-offset when drawing a cell?
174 virtual int cellXOffset(idx_type) const { return 0; }
175 /// any additional y-offset when drawing a cell?
176 virtual int cellYOffset(idx_type) const { return 0; }
178 /// identifies certain types of insets
179 virtual MathArrayInset * asArrayInset() { return 0; }
180 virtual MathBoxInset * asBoxInset() { return 0; }
181 virtual MathBoxInset const * asBoxInset() const { return 0; }
182 virtual MathCharInset const * asCharInset() const { return 0; }
183 virtual MathDelimInset * asDelimInset() { return 0; }
184 virtual MathDelimInset const * asDelimInset() const { return 0; }
185 virtual MathFuncInset * asFuncInset() { return 0; }
186 virtual MathFracInset * asFracInset() { return 0; }
187 virtual MathGridInset * asGridInset() { return 0; }
188 virtual MathHullInset * asHullInset() { return 0; }
189 virtual MathHullInset const * asHullInset() const { return 0; }
190 virtual MathMacroTemplate * asMacroTemplate() { return 0; }
191 virtual MathMatrixInset const * asMatrixInset() const { return 0; }
192 virtual MathNestInset * asNestInset() { return 0; }
193 virtual MathScriptInset * asScriptInset() { return 0; }
194 virtual MathScriptInset const * asScriptInset() const { return 0; }
195 virtual MathSpaceInset * asSpaceInset() { return 0; }
196 virtual MathStringInset * asStringInset() { return 0; }
197 virtual MathSymbolInset const * asSymbolInset() const { return 0; }
198 virtual UpdatableInset * asHyperActiveInset() const { return 0; }
200 /// identifies things that can get scripts
201 virtual bool isScriptable() const { return false; }
202 /// thing that can be moved into
203 virtual bool isActive() const { return nargs() > 0; }
204 /// identifies insets from the outer world
205 virtual bool isHyperActive() const { return 0; }
206 /// is the a relational operator (used for splitting equations)
207 virtual bool isRelOp() const { return false; }
209 /// return the content as char if the inset is able to do so
210 virtual char getChar() const { return 0; }
211 /// return the content's char code if it has one
212 virtual MathTextCodes code() const { return LM_TC_MIN; }
213 /// identifies things that can get \limits or \nolimits
214 virtual bool takesLimits() const { return false; }
217 virtual void edit(BufferView *, int, int, unsigned int) {}
219 /// request "external features"
220 virtual void validate(LaTeXFeatures & features) const;
221 /// char char code if possible
222 virtual void handleFont(MathTextCodes) {}
223 /// is this inset equal to a given other inset?
224 virtual bool match(MathInset *) const { return false; }
225 /// replace things by other things
226 virtual void replace(ReplaceData &) {}
228 /// write LaTeX and Lyx code
229 virtual void write(WriteStream & os) const;
230 /// write normalized content
231 virtual void normalize(NormalStream &) const;
232 /// write content as something readable by Maple
233 virtual void maplize(MapleStream &) const;
234 /// write content as something resembling MathML
235 virtual void mathmlize(MathMLStream &) const;
236 /// write content as something readable by Octave
237 virtual void octavize(OctaveStream &) const;
239 virtual void infoize(std::ostream &) const {}
241 /// dump content to stderr for debugging
242 virtual void dump() const;
245 std::ostream & operator<<(std::ostream &, MathInset const &);