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 "math_defs.h"
35 /** Abstract base class for all math objects.
36 A math insets is for use of the math editor only, it isn't a
37 general LyX inset. It's used to represent all the math objects.
38 The formulaInset (a LyX inset) encapsulates a math inset.
47 class MathMatrixInset;
48 class MathScriptInset;
50 class MathMacroTemplate;
59 struct MathWriteInfo {
61 MathWriteInfo(Buffer const * buffer_, std::ostream & os_, bool fragile_)
62 : buffer(buffer_), os(os_), fragile(fragile_)
65 explicit MathWriteInfo(std::ostream & os_)
66 : buffer(0), os(os_), fragile(false)
71 MathWriteInfo & operator<<(T const & t)
77 MathWriteInfo & operator<<(MathArray const & ar)
85 Buffer const * buffer;
95 /// short of anything else reasonable
96 typedef MathArray::size_type size_type;
97 /// type for cursor positions within a cell
98 typedef MathArray::size_type pos_type;
99 /// type for cell indices
100 typedef size_type idx_type;
101 /// type for row numbers
102 typedef size_type row_type;
103 /// type for column numbers
104 typedef size_type col_type;
108 /// the virtual base destructor
109 virtual ~MathInset();
112 virtual void draw(Painter &, int x, int y) const;
113 /// write LaTeX and Lyx code
114 virtual void write(MathWriteInfo & os) const;
115 /// write normalized content
116 virtual void writeNormal(std::ostream &) const;
118 virtual MathInset * clone() const = 0;
119 ///substitutes macro arguments if necessary
120 virtual void substitute(MathMacro const & macro);
121 /// compute the size of the object, sets ascend_, descend_ and width_
122 virtual void metrics(MathMetricsInfo const & st) const;
124 virtual int ascent() const { return 1; }
126 virtual int descent() const { return 1; }
128 virtual int width() const { return 2; }
130 virtual int height() const;
132 /// Where should we go when we press the up cursor key?
133 virtual bool idxUp(idx_type & idx, pos_type & pos) const;
135 virtual bool idxDown(idx_type & idx, pos_type & pos) const;
137 virtual bool idxLeft(idx_type & idx, pos_type & pos) const;
139 virtual bool idxRight(idx_type & idx, pos_type & pos) const;
141 /// Move one physical cell up
142 virtual bool idxNext(idx_type & idx, pos_type & pos) const;
143 /// Move one physical cell down
144 virtual bool idxPrev(idx_type & idx, pos_type & pos) const;
146 /// Target pos when we enter the inset from the left by pressing "Right"
147 virtual bool idxFirst(idx_type & idx, pos_type & pos) const;
148 /// Target pos when we enter the inset from the right by pressing "Left"
149 virtual bool idxLast(idx_type & idx, pos_type & pos) const;
151 /// Where should we go if we press home?
152 virtual bool idxHome(idx_type & idx, pos_type & pos) const;
153 /// Where should we go if we press end?
154 virtual bool idxEnd(idx_type & idx, pos_type & pos) const;
156 /// Delete a cell and move cursor
157 // the return value indicates whether the cursor should leave the inset
158 // and/or the whole inset should be deleted
159 virtual void idxDelete(idx_type & idx, bool & popit, bool & deleteit);
160 // deletes a cell range and moves the cursor
161 virtual void idxDeleteRange(idx_type from, idx_type to);
162 // returns list of cell indices that are "between" from and to for
163 // selection purposes
164 virtual std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
167 virtual idx_type nargs() const;
170 virtual MathArray & cell(idx_type);
172 virtual MathArray const & cell(idx_type) const;
174 virtual MathXArray & xcell(idx_type);
176 virtual MathXArray const & xcell(idx_type) const;
179 virtual col_type ncols() const { return 1; }
181 virtual row_type nrows() const { return 1; }
183 virtual col_type col(row_type) const { return 0; }
185 virtual row_type row(row_type) const { return 0; }
187 virtual int cellXOffset(row_type) const { return 0; }
189 virtual int cellYOffset(row_type) const { return 0; }
191 virtual void addRow(row_type) {}
193 virtual void delRow(row_type) {}
195 virtual void addCol(col_type) {}
197 virtual void delCol(col_type) {}
200 virtual bool covers(int x, int y) const;
202 /// identifies NestInsets
203 virtual MathNestInset * asNestInset() { return 0; }
204 /// identifies CharInsets
205 virtual MathCharInset const * asCharInset() const { return 0; }
206 /// identifies ScriptInsets
207 virtual MathScriptInset const * asScriptInset() const { return 0; }
208 /// identifies ScriptInsets
209 virtual MathScriptInset * asScriptInset() { return 0; }
210 /// identifies MatrixInsets
211 virtual MathMatrixInset const * asMatrixInset() const { return 0; }
212 /// identifies MatrixInsets
213 virtual MathMatrixInset * asMatrixInset() { return 0; }
214 /// identifies SpaceInset
215 virtual MathSpaceInset * asSpaceInset() { return 0; }
216 /// identifies GridInset
217 virtual MathGridInset * asGridInset() { return 0; }
218 /// identifies ArrayInsets
219 virtual MathArrayInset * asArrayInset() { return 0; }
220 /// identifies BoxInsets
221 virtual MathBoxInset * asBoxInset() { return 0; }
222 /// identifies macro templates
223 virtual MathMacroTemplate * asMacroTemplate() { return 0; }
224 /// identifies hyperactive insets
225 virtual UpdatableInset * asHyperActiveInset() const { return 0; }
227 /// identifies things that can get scripts
228 virtual bool isScriptable() const { return false; }
230 virtual bool isActive() const { return nargs() > 0; }
231 /// identifies insets from the outer world
232 virtual bool isHyperActive() const { return 0; }
234 virtual bool isRelOp() const { return false; }
236 virtual bool isMacro() const { return false; }
239 virtual char getChar() const { return 0; }
241 virtual MathTextCodes code() const { return LM_TC_MIN; }
242 /// identifies things that can get \limits or \nolimits
243 virtual bool takesLimits() const { return false; }
246 virtual void dump() const;
248 virtual void edit(BufferView *, int, int, unsigned int) {}
251 virtual void validate(LaTeXFeatures & features) const;
253 virtual void handleFont(MathTextCodes) {}
256 virtual string octavize() const;
258 virtual string maplize() const;
260 virtual string mathmlize() const;
263 std::ostream & operator<<(std::ostream &, MathInset const &);