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 virtual void metrics(MathMetricsInfo const & st) const;
98 virtual int ascent() const { return 1; }
100 virtual int descent() const { return 1; }
102 virtual int width() const { return 2; }
104 virtual int height() const;
106 /// Where should we go when we press the up cursor key?
107 virtual bool idxUp(idx_type & idx, pos_type & pos) const;
109 virtual bool idxDown(idx_type & idx, pos_type & pos) const;
111 virtual bool idxLeft(idx_type & idx, pos_type & pos) const;
113 virtual bool idxRight(idx_type & idx, pos_type & pos) const;
115 /// Move one physical cell up
116 virtual bool idxNext(idx_type & idx, pos_type & pos) const;
117 /// Move one physical cell down
118 virtual bool idxPrev(idx_type & idx, pos_type & pos) const;
120 /// Target pos when we enter the inset from the left by pressing "Right"
121 virtual bool idxFirst(idx_type & idx, pos_type & pos) const;
122 /// Target pos when we enter the inset from the right by pressing "Left"
123 virtual bool idxLast(idx_type & idx, pos_type & pos) const;
125 /// Where should we go if we press home?
126 virtual bool idxHome(idx_type & idx, pos_type & pos) const;
127 /// Where should we go if we press end?
128 virtual bool idxEnd(idx_type & idx, pos_type & pos) const;
130 /// Delete a cell and move cursor
131 // the return value indicates whether the cursor should leave the inset
132 // and/or the whole inset should be deleted
133 virtual void idxDelete(idx_type & idx, bool & popit, bool & deleteit);
134 // deletes a cell range and moves the cursor
135 virtual void idxDeleteRange(idx_type from, idx_type to);
136 // returns list of cell indices that are "between" from and to for
137 // selection purposes
138 virtual std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
141 virtual idx_type nargs() const;
144 virtual MathArray & cell(idx_type);
146 virtual MathArray const & cell(idx_type) const;
148 virtual MathXArray & xcell(idx_type);
150 virtual MathXArray const & xcell(idx_type) const;
153 virtual col_type ncols() const { return 1; }
155 virtual row_type nrows() const { return 1; }
157 virtual col_type col(row_type) const { return 0; }
159 virtual row_type row(row_type) const { return 0; }
161 virtual int cellXOffset(row_type) const { return 0; }
163 virtual int cellYOffset(row_type) const { return 0; }
165 virtual void addRow(row_type) {}
167 virtual void delRow(row_type) {}
169 virtual void addCol(col_type) {}
171 virtual void delCol(col_type) {}
174 virtual bool covers(int x, int y) const;
176 /// identifies certain types of insets
177 virtual MathArrayInset * asArrayInset() { return 0; }
178 virtual MathBoxInset * asBoxInset() { return 0; }
179 virtual MathCharInset const * asCharInset() const { return 0; }
180 virtual MathDelimInset * asDelimInset() { return 0; }
181 virtual MathDelimInset const * asDelimInset() const { return 0; }
182 virtual MathFuncInset * asFuncInset() { return 0; }
183 virtual MathFracInset * asFracInset() { return 0; }
184 virtual MathGridInset * asGridInset() { return 0; }
185 virtual MathHullInset * asHullInset() { return 0; }
186 virtual MathHullInset const * asHullInset() const { return 0; }
187 virtual MathMacroTemplate * asMacroTemplate() { return 0; }
188 virtual MathMatrixInset const * asMatrixInset() const { return 0; }
189 virtual MathNestInset * asNestInset() { return 0; }
190 virtual MathScriptInset * asScriptInset() { return 0; }
191 virtual MathScriptInset const * asScriptInset() const { return 0; }
192 virtual MathSpaceInset * asSpaceInset() { return 0; }
193 virtual MathStringInset * asStringInset() { return 0; }
194 virtual MathSymbolInset * asSymbolInset() { return 0; }
195 virtual UpdatableInset * asHyperActiveInset() const { return 0; }
197 /// identifies things that can get scripts
198 virtual bool isScriptable() const { return false; }
199 /// thing that can be moved into
200 virtual bool isActive() const { return nargs() > 0; }
201 /// identifies insets from the outer world
202 virtual bool isHyperActive() const { return 0; }
204 virtual bool isRelOp() const { return false; }
206 virtual bool isMacro() const { return false; }
209 virtual char getChar() const { return 0; }
211 virtual MathTextCodes code() const { return LM_TC_MIN; }
212 /// identifies things that can get \limits or \nolimits
213 virtual bool takesLimits() const { return false; }
216 virtual void dump() const;
218 virtual void edit(BufferView *, int, int, unsigned int) {}
221 virtual void validate(LaTeXFeatures & features) const;
223 virtual void handleFont(MathTextCodes) {}
225 /// write normalized content
226 virtual void normalize(NormalStream &) const;
228 virtual void maplize(MapleStream &) const;
230 virtual void mathmlize(MathMLStream &) const;
232 virtual void octavize(OctaveStream &) const;
235 std::ostream & operator<<(std::ostream &, MathInset const &);