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
33 /** Abstract base class for all math objects.
34 A math insets is for use of the math editor only, it isn't a
35 general LyX inset. It's used to represent all the math objects.
36 The formulaInset (a LyX inset) encapsulates a math inset.
45 class MathMatrixInset;
46 class MathScriptInset;
48 class MathMacroTemplate;
56 struct MathMetricsInfo {
59 : view(0), font(0), size(LM_ST_TEXT)
62 MathMetricsInfo(BufferView * v, LyXFont const * f, MathStyles s)
63 : view(v), font(f), size(s)
75 struct MathWriteInfo {
77 MathWriteInfo(Buffer const * buffer_, std::ostream & os_, bool fragile_)
78 : buffer(buffer_), os(os_), fragile(fragile_)
81 explicit MathWriteInfo(std::ostream & os_)
82 : buffer(0), os(os_), fragile(false)
87 MathWriteInfo & operator<<(T const & t)
93 MathWriteInfo & operator<<(MathArray const & ar)
101 Buffer const * buffer;
111 /// short of anything else reasonable
112 typedef MathArray::size_type size_type;
113 /// type for cursor positions within a cell
114 typedef MathArray::size_type pos_type;
115 /// type for cell indices
116 typedef size_type idx_type;
117 /// type for row numbers
118 typedef size_type row_type;
119 /// type for column numbers
120 typedef size_type col_type;
124 /// the virtual base destructor
125 virtual ~MathInset();
127 /// draw the object, sets xo_ and yo_ cached values
128 virtual void draw(Painter &, int x, int y) const;
129 /// write LaTeX and Lyx code
130 virtual void write(MathWriteInfo & os) const;
131 /// write normalized content
132 virtual void writeNormal(std::ostream &) const;
134 virtual MathInset * clone() const = 0;
135 ///substitutes macro arguments if necessary
136 virtual void substitute(MathMacro const & macro);
137 /// compute the size of the object, sets ascend_, descend_ and width_
138 virtual void metrics(MathMetricsInfo const & st) const;
140 virtual int ascent() const { return 1; }
142 virtual int descent() const { return 1; }
144 virtual int width() const { return 2; }
146 virtual int height() const;
148 virtual MathStyles size() const;
150 /// Where should we go when we press the up cursor key?
151 virtual bool idxUp(idx_type & idx, pos_type & pos) const;
153 virtual bool idxDown(idx_type & idx, pos_type & pos) const;
155 virtual bool idxLeft(idx_type & idx, pos_type & pos) const;
157 virtual bool idxRight(idx_type & idx, pos_type & pos) const;
159 /// Move one physical cell up
160 virtual bool idxNext(idx_type & idx, pos_type & pos) const;
161 /// Move one physical cell down
162 virtual bool idxPrev(idx_type & idx, pos_type & pos) const;
164 /// Target pos when we enter the inset from the left by pressing "Right"
165 virtual bool idxFirst(idx_type & idx, pos_type & pos) const;
166 /// Target pos when we enter the inset from the right by pressing "Left"
167 virtual bool idxLast(idx_type & idx, pos_type & pos) const;
169 /// Where should we go if we press home?
170 virtual bool idxHome(idx_type & idx, pos_type & pos) const;
171 /// Where should we go if we press end?
172 virtual bool idxEnd(idx_type & idx, pos_type & pos) const;
174 /// Delete a cell and move cursor
175 // the return value indicates whether the cursor should leave the inset
176 // and/or the whole inset should be deleted
177 virtual void idxDelete(idx_type & idx, bool & popit, bool & deleteit);
178 // deletes a cell range and moves the cursor
179 virtual void idxDeleteRange(idx_type from, idx_type to);
180 // returns list of cell indices that are "between" from and to for
181 // selection purposes
182 virtual std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
185 virtual idx_type nargs() const;
188 virtual MathArray & cell(idx_type);
190 virtual MathArray const & cell(idx_type) const;
192 virtual MathXArray & xcell(idx_type);
194 virtual MathXArray const & xcell(idx_type) const;
197 virtual int xo() const;
199 virtual int yo() const;
201 virtual void xo(int tx) const;
203 virtual void yo(int ty) const;
207 virtual col_type ncols() const { return 1; }
209 virtual row_type nrows() const { return 1; }
211 virtual col_type col(row_type) const { return 0; }
213 virtual row_type row(row_type) const { return 0; }
215 virtual int cellXOffset(row_type) const { return 0; }
217 virtual int cellYOffset(row_type) const { return 0; }
219 virtual void addRow(row_type) {}
221 virtual void delRow(row_type) {}
223 virtual void addCol(col_type) {}
225 virtual void delCol(col_type) {}
228 virtual void userSetSize(MathStyles &) {}
231 virtual void getXY(int & x, int & y) const;
233 virtual bool covers(int x, int y) const;
235 /// identifies NestInsets
236 virtual MathNestInset * asNestInset() { return 0; }
237 /// identifies CharInsets
238 virtual MathCharInset const * asCharInset() const { return 0; }
239 /// identifies ScriptInsets
240 virtual MathScriptInset const * asScriptInset() const { return 0; }
241 /// identifies ScriptInsets
242 virtual MathScriptInset * asScriptInset() { return 0; }
243 /// identifies MatrixInsets
244 virtual MathMatrixInset const * asMatrixInset() const { return 0; }
245 /// identifies MatrixInsets
246 virtual MathMatrixInset * asMatrixInset() { return 0; }
247 /// identifies SpaceInset
248 virtual MathSpaceInset * asSpaceInset() { return 0; }
249 /// identifies GridInset
250 virtual MathGridInset * asGridInset() { return 0; }
251 /// identifies ArrayInsets
252 virtual MathArrayInset * asArrayInset() { return 0; }
253 /// identifies BoxInsets
254 virtual MathBoxInset * asBoxInset() { return 0; }
255 /// identifies macro templates
256 virtual MathMacroTemplate * asMacroTemplate() { return 0; }
258 /// identifies things that can get scripts
259 virtual bool isScriptable() const { return false; }
261 virtual bool isActive() const { return nargs() > 0; }
263 virtual bool isRelOp() const { return false; }
265 virtual bool isMacro() const { return false; }
268 virtual char getChar() const { return 0; }
270 virtual MathTextCodes code() const { return LM_TC_MIN; }
271 /// identifies things that can get \limits or \nolimits
272 virtual bool takesLimits() const { return false; }
275 virtual void push_back(MathInset *);
277 virtual void push_back(unsigned char c, MathTextCodes code);
279 virtual void dump() const;
282 virtual void validate(LaTeXFeatures & features) const;
284 virtual void handleFont(MathTextCodes) {}
287 static int workwidth;
290 /// the used font size
291 mutable MathMetricsInfo size_;
294 /// the following are used for positioning the cursor with the mouse
295 /// cached cursor start position in pixels from the document left
297 /// cached cursor start position in pixels from the document top
301 std::ostream & operator<<(std::ostream &, MathInset const &);