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.
48 class MathMatrixInset;
50 class MathScriptInset;
52 class MathMacroTemplate;
68 /// short of anything else reasonable
69 typedef MathArray::size_type size_type;
70 /// type for cursor positions within a cell
71 typedef MathArray::size_type pos_type;
72 /// type for cell indices
73 typedef size_type idx_type;
74 /// type for row numbers
75 typedef size_type row_type;
76 /// type for column numbers
77 typedef size_type col_type;
81 /// the virtual base destructor
85 virtual void draw(Painter &, int x, int y) const;
86 /// write LaTeX and Lyx code
87 virtual void write(WriteStream & os) const;
89 virtual MathInset * clone() const = 0;
90 ///substitutes macro arguments if necessary
91 virtual void substitute(MathMacro const & macro);
92 /// compute the size of the object, sets ascend_, descend_ and width_
93 virtual void metrics(MathMetricsInfo const & st) const;
95 virtual int ascent() const { return 1; }
97 virtual int descent() const { return 1; }
99 virtual int width() const { return 2; }
101 virtual int height() const;
103 /// Where should we go when we press the up cursor key?
104 virtual bool idxUp(idx_type & idx, pos_type & pos) const;
106 virtual bool idxDown(idx_type & idx, pos_type & pos) const;
108 virtual bool idxLeft(idx_type & idx, pos_type & pos) const;
110 virtual bool idxRight(idx_type & idx, pos_type & pos) const;
112 /// Move one physical cell up
113 virtual bool idxNext(idx_type & idx, pos_type & pos) const;
114 /// Move one physical cell down
115 virtual bool idxPrev(idx_type & idx, pos_type & pos) const;
117 /// Target pos when we enter the inset from the left by pressing "Right"
118 virtual bool idxFirst(idx_type & idx, pos_type & pos) const;
119 /// Target pos when we enter the inset from the right by pressing "Left"
120 virtual bool idxLast(idx_type & idx, pos_type & pos) const;
122 /// Where should we go if we press home?
123 virtual bool idxHome(idx_type & idx, pos_type & pos) const;
124 /// Where should we go if we press end?
125 virtual bool idxEnd(idx_type & idx, pos_type & pos) const;
127 /// Delete a cell and move cursor
128 // the return value indicates whether the cursor should leave the inset
129 // and/or the whole inset should be deleted
130 virtual void idxDelete(idx_type & idx, bool & popit, bool & deleteit);
131 // deletes a cell range and moves the cursor
132 virtual void idxDeleteRange(idx_type from, idx_type to);
133 // returns list of cell indices that are "between" from and to for
134 // selection purposes
135 virtual std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
138 virtual idx_type nargs() const;
141 virtual MathArray & cell(idx_type);
143 virtual MathArray const & cell(idx_type) const;
145 virtual MathXArray & xcell(idx_type);
147 virtual MathXArray const & xcell(idx_type) const;
150 virtual col_type ncols() const { return 1; }
152 virtual row_type nrows() const { return 1; }
154 virtual col_type col(row_type) const { return 0; }
156 virtual row_type row(row_type) const { return 0; }
158 virtual int cellXOffset(row_type) const { return 0; }
160 virtual int cellYOffset(row_type) const { return 0; }
162 virtual void addRow(row_type) {}
164 virtual void delRow(row_type) {}
166 virtual void addCol(col_type) {}
168 virtual void delCol(col_type) {}
171 virtual bool covers(int x, int y) const;
173 /// identifies NestInsets
174 virtual MathNestInset * asNestInset() { return 0; }
175 /// identifies CharInsets
176 virtual MathCharInset const * asCharInset() const { return 0; }
177 /// identifies ScriptInsets
178 virtual MathScriptInset * asScriptInset() { return 0; }
179 virtual MathScriptInset const * asScriptInset() const { return 0; }
180 /// identifies HullInsets
181 virtual MathHullInset * asHullInset() { return 0; }
182 virtual MathHullInset const * asHullInset() const { return 0; }
183 /// identifies SpaceInset
184 virtual MathSpaceInset * asSpaceInset() { return 0; }
185 /// identifies GridInset
186 virtual MathGridInset * asGridInset() { return 0; }
187 /// identifies ArrayInsets
188 virtual MathArrayInset * asArrayInset() { return 0; }
189 /// identifies MatrixInsets
190 virtual MathMatrixInset const * asMatrixInset() const { return 0; }
191 /// identifies BoxInsets
192 virtual MathBoxInset * asBoxInset() { return 0; }
193 /// identifies DelimInsets
194 virtual MathDelimInset * asDelimInset() { return 0; }
195 virtual MathDelimInset const * asDelimInset() const { return 0; }
196 /// identifies FuncInsets
197 virtual MathFuncInset * asFuncInset() { return 0; }
198 /// identifies macro templates
199 virtual MathMacroTemplate * asMacroTemplate() { return 0; }
200 /// identifies hyperactive insets
201 virtual UpdatableInset * asHyperActiveInset() const { return 0; }
203 /// identifies things that can get scripts
204 virtual bool isScriptable() const { return false; }
205 /// thing that can be moved into
206 virtual bool isActive() const { return nargs() > 0; }
207 /// identifies insets from the outer world
208 virtual bool isHyperActive() const { return 0; }
210 virtual bool isRelOp() const { return false; }
212 virtual bool isMacro() const { return false; }
215 virtual char getChar() const { return 0; }
217 virtual MathTextCodes code() const { return LM_TC_MIN; }
218 /// identifies things that can get \limits or \nolimits
219 virtual bool takesLimits() const { return false; }
222 virtual void dump() const;
224 virtual void edit(BufferView *, int, int, unsigned int) {}
227 virtual void validate(LaTeXFeatures & features) const;
229 virtual void handleFont(MathTextCodes) {}
231 /// write normalized content
232 virtual void normalize(NormalStream &) const;
234 virtual void maplize(MapleStream &) const;
236 virtual void mathmlize(MathMLStream &) const;
238 virtual void octavize(OctaveStream &) const;
241 std::ostream & operator<<(std::ostream &, MathInset const &);