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"
34 /** Abstract base class for all math objects.
35 A math insets is for use of the math editor only, it isn't a
36 general LyX inset. It's used to represent all the math objects.
37 The formulaInset (a LyX inset) encapsulates a math inset.
49 class MathMatrixInset;
51 class MathScriptInset;
52 class MathStringInset;
54 class MathSymbolInset;
66 class MathMacroTemplate;
71 /// short of anything else reasonable
72 typedef MathArray::size_type size_type;
73 /// type for cursor positions within a cell
74 typedef MathArray::size_type pos_type;
75 /// type for cell indices
76 typedef size_type idx_type;
77 /// type for row numbers
78 typedef size_type row_type;
79 /// type for column numbers
80 typedef size_type col_type;
84 /// the virtual base destructor
88 virtual void draw(Painter &, int x, int y) const;
89 /// write LaTeX and Lyx code
90 virtual void write(WriteStream & os) const;
92 virtual MathInset * clone() const = 0;
93 /// substitutes macro arguments if necessary
94 virtual void substitute(MathMacro const & macro);
95 /// compute the size of the object, sets ascend_, descend_ and width_
96 // updates the (xo,yo)-caches of all contained cells
97 virtual void metrics(MathMetricsInfo const & st) const;
98 /// the ascent of the inset above the baseline
99 virtual int ascent() const { return 1; }
100 /// the descent of the inset below the baseline
101 virtual int descent() const { return 1; }
103 virtual int width() const { return 2; }
104 /// total height (== ascent + descent)
105 virtual int height() const;
107 /// Where should we go when we press the up cursor key?
108 virtual bool idxUp(idx_type & idx, pos_type & pos) const;
110 virtual bool idxDown(idx_type & idx, pos_type & pos) const;
112 virtual bool idxLeft(idx_type & idx, pos_type & pos) const;
114 virtual bool idxRight(idx_type & idx, pos_type & pos) const;
116 /// Move one physical cell up
117 virtual bool idxNext(idx_type & idx, pos_type & pos) const;
118 /// Move one physical cell down
119 virtual bool idxPrev(idx_type & idx, pos_type & pos) const;
121 /// Target pos when we enter the inset from the left by pressing "Right"
122 virtual bool idxFirst(idx_type & idx, pos_type & pos) const;
123 /// Target pos when we enter the inset from the left by pressing "Up"
124 virtual bool idxFirstUp(idx_type & idx, pos_type & pos) const;
125 /// Target pos when we enter the inset from the left by pressing "Down"
126 virtual bool idxFirstDown(idx_type & idx, pos_type & pos) const;
127 /// Target pos when we enter the inset from the right by pressing "Left"
128 virtual bool idxLast(idx_type & idx, pos_type & pos) const;
129 /// Target pos when we enter the inset from the right by pressing "Up"
130 virtual bool idxLastUp(idx_type & idx, pos_type & pos) const;
131 /// Target pos when we enter the inset from the right by pressing "Down"
132 virtual bool idxLastDown(idx_type & idx, pos_type & pos) const;
134 /// Where should we go if we press home?
135 virtual bool idxHome(idx_type & idx, pos_type & pos) const;
136 /// Where should we go if we press end?
137 virtual bool idxEnd(idx_type & idx, pos_type & pos) const;
139 /// Delete a cell and move cursor
140 // the return value indicates whether the cursor should leave the inset
141 // and/or the whole inset should be deleted
142 virtual void idxDelete(idx_type & idx, bool & popit, bool & deleteit);
143 // deletes a cell range and moves the cursor
144 virtual void idxDeleteRange(idx_type from, idx_type to);
145 // returns list of cell indices that are "between" from and to for
146 // selection purposes
147 virtual std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
149 /// the number of nested cells this inset owns
150 virtual idx_type nargs() const;
152 /// return cell given its number
153 virtual MathArray & cell(idx_type);
154 /// return cell given its number
155 virtual MathArray const & cell(idx_type) const;
156 /// return cell plus drawing cache given its number
157 virtual MathXArray & xcell(idx_type);
158 /// return cell plus drawing cache given its number
159 virtual MathXArray const & xcell(idx_type) const;
161 /// the number of columns of this inset if it is grid-like
162 virtual col_type ncols() const { return 1; }
163 /// the number of rows of this inset if it is grid-like
164 virtual row_type nrows() const { return 1; }
165 /// to which column belongs a cell with a given index?
166 virtual col_type col(idx_type) const { return 0; }
167 /// to which row belongs a cell with a given index?
168 virtual row_type row(idx_type) const { return 0; }
169 /// any additional x-offset when drawing a cell?
170 virtual int cellXOffset(idx_type) const { return 0; }
171 /// any additional y-offset when drawing a cell?
172 virtual int cellYOffset(idx_type) const { return 0; }
173 /// add a row after a given one
174 virtual void addRow(row_type) {}
175 /// delete a given row
176 virtual void delRow(row_type) {}
177 /// add a column after a given one
178 virtual void addCol(col_type) {}
179 /// delete a given row
180 virtual void delCol(col_type) {}
182 /// does this inset cover the pixel at (x,y)?
183 virtual bool covers(int x, int y) const;
185 /// identifies certain types of insets
186 virtual MathArrayInset * asArrayInset() { return 0; }
187 virtual MathBoxInset * asBoxInset() { return 0; }
188 virtual MathCharInset const * asCharInset() const { return 0; }
189 virtual MathDelimInset * asDelimInset() { return 0; }
190 virtual MathDelimInset const * asDelimInset() const { return 0; }
191 virtual MathFuncInset * asFuncInset() { return 0; }
192 virtual MathFracInset * asFracInset() { return 0; }
193 virtual MathGridInset * asGridInset() { return 0; }
194 virtual MathHullInset * asHullInset() { return 0; }
195 virtual MathHullInset const * asHullInset() const { return 0; }
196 virtual MathMacroTemplate * asMacroTemplate() { return 0; }
197 virtual MathMatrixInset const * asMatrixInset() const { return 0; }
198 virtual MathNestInset * asNestInset() { return 0; }
199 virtual MathScriptInset * asScriptInset() { return 0; }
200 virtual MathScriptInset const * asScriptInset() const { return 0; }
201 virtual MathSpaceInset * asSpaceInset() { return 0; }
202 virtual MathStringInset * asStringInset() { return 0; }
203 virtual MathSymbolInset const * asSymbolInset() const { return 0; }
204 virtual UpdatableInset * asHyperActiveInset() const { return 0; }
206 /// identifies things that can get scripts
207 virtual bool isScriptable() const { return false; }
208 /// thing that can be moved into
209 virtual bool isActive() const { return nargs() > 0; }
210 /// identifies insets from the outer world
211 virtual bool isHyperActive() const { return 0; }
212 /// is the a relational operator (used for splitting equations)
213 virtual bool isRelOp() const { return false; }
215 /// return the content as char if the inset is able to do so
216 virtual char getChar() const { return 0; }
217 /// return the content's char code if it has one
218 virtual MathTextCodes code() const { return LM_TC_MIN; }
219 /// identifies things that can get \limits or \nolimits
220 virtual bool takesLimits() const { return false; }
223 virtual void edit(BufferView *, int, int, unsigned int) {}
225 /// request "external features"
226 virtual void validate(LaTeXFeatures & features) const;
227 /// char char code if possible
228 virtual void handleFont(MathTextCodes) {}
229 /// is this inset equal to a given other inset?
230 virtual bool match(MathInset *) const { return false; }
231 /// replace things by other things
232 virtual void replace(ReplaceData &) {}
234 /// write normalized content
235 virtual void normalize(NormalStream &) const;
236 /// write content as something readable by Maple
237 virtual void maplize(MapleStream &) const;
238 /// write content as something resembling MathML
239 virtual void mathmlize(MathMLStream &) const;
240 /// write content as something readable by Octave
241 virtual void octavize(OctaveStream &) const;
243 /// dump content to stderr for debugging
244 virtual void dump() const;
247 std::ostream & operator<<(std::ostream &, MathInset const &);