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 MathScriptInset;
46 class MathMatrixInset;
48 class MathMacroTemplate;
52 /// short of anything else reasonable
53 typedef MathArray::size_type size_type;
54 /// type for cursor positions within a cell
55 typedef MathArray::size_type pos_type;
56 /// type for cell indices
57 typedef size_type idx_type;
58 /// type for row numbers
59 typedef size_type row_type;
60 /// type for column numbers
61 typedef size_type col_type;
65 /// the virtual base destructor
68 /// draw the object, sets xo_ and yo_ cached values
69 virtual void draw(Painter &, int x, int y) const;
70 /// write LaTeX and Lyx code
71 virtual void write(std::ostream &, bool fragile) const;
72 /// write normalized content
73 virtual void writeNormal(std::ostream &) const;
75 virtual MathInset * clone() const = 0;
76 ///substitutes macro arguments if necessary
77 virtual void substitute(MathMacro const & macro);
78 /// compute the size of the object, sets ascend_, descend_ and width_
79 virtual void metrics(MathStyles st) const;
81 virtual int ascent() const { return 1; }
83 virtual int descent() const { return 1; }
85 virtual int width() const { return 2; }
87 virtual int height() const;
89 virtual MathStyles size() const;
91 /// Where should we go when we press the up cursor key?
92 virtual bool idxUp(idx_type & idx, pos_type & pos) const;
94 virtual bool idxDown(idx_type & idx, pos_type & pos) const;
96 virtual bool idxLeft(idx_type & idx, pos_type & pos) const;
98 virtual bool idxRight(idx_type & idx, pos_type & pos) const;
100 /// Move one physical cell up
101 virtual bool idxNext(idx_type & idx, pos_type & pos) const;
102 /// Move one physical cell down
103 virtual bool idxPrev(idx_type & idx, pos_type & pos) const;
105 /// Target pos when we enter the inset from the left by pressing "Right"
106 virtual bool idxFirst(idx_type & idx, pos_type & pos) const;
107 /// Target pos when we enter the inset from the right by pressing "Left"
108 virtual bool idxLast(idx_type & idx, pos_type & pos) const;
110 /// Where should we go if we press home?
111 virtual bool idxHome(idx_type & idx, pos_type & pos) const;
112 /// Where should we go if we press end?
113 virtual bool idxEnd(idx_type & idx, pos_type & pos) const;
115 /// Delete a cell and move cursor
116 // the return value indicates whether the cursor should leave the inset
117 // and/or the whole inset should be deleted
118 virtual void idxDelete(idx_type & idx, bool & popit, bool & deleteit);
119 // deletes a cell range and moves the cursor
120 virtual void idxDeleteRange(idx_type from, idx_type to);
121 // returns list of cell indices that are "between" from and to for
122 // selection purposes
123 virtual std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
126 virtual idx_type nargs() const;
129 virtual MathArray & cell(idx_type);
131 virtual MathArray const & cell(idx_type) const;
133 virtual MathXArray & xcell(idx_type);
135 virtual MathXArray const & xcell(idx_type) const;
138 virtual int xo() const;
140 virtual int yo() const;
142 virtual void xo(int tx) const;
144 virtual void yo(int ty) const;
148 virtual col_type ncols() const { return 1; }
150 virtual row_type nrows() const { return 1; }
152 virtual col_type col(row_type) const { return 0; }
154 virtual row_type row(row_type) const { return 0; }
156 virtual int cellXOffset(row_type) const { return 0; }
158 virtual int cellYOffset(row_type) const { return 0; }
160 virtual void addRow(row_type) {}
162 virtual void delRow(row_type) {}
164 virtual void addCol(col_type) {}
166 virtual void delCol(col_type) {}
169 virtual void userSetSize(MathStyles &) {}
172 virtual void getXY(int & x, int & y) const;
174 virtual bool covers(int x, int y) const;
176 /// identifies NestInsets
177 virtual MathNestInset * asNestInset() { return 0; }
178 /// identifies CharInsets
179 virtual MathCharInset const * asCharInset() const { return 0; }
180 /// identifies ScriptInsets
181 virtual MathScriptInset const * asScriptInset() const { return 0; }
182 /// identifies ScriptInsets
183 virtual MathScriptInset * asScriptInset() { return 0; }
184 /// identifies MatrixInsets
185 virtual MathMatrixInset const * asMatrixInset() const { return 0; }
186 /// identifies MatrixInsets
187 virtual MathMatrixInset * asMatrixInset() { return 0; }
188 /// identifies SpaceInset
189 virtual MathSpaceInset * asSpaceInset() { return 0; }
190 /// identifies GridInset
191 virtual MathGridInset * asGridInset() { return 0; }
192 /// identifies ArrayInsets
193 virtual MathArrayInset * asArrayInset() { return 0; }
194 /// identifies macro templates
195 virtual MathMacroTemplate * asMacroTemplate() { return 0; }
197 /// identifies things that can get scripts
198 virtual bool isScriptable() const { return false; }
200 virtual bool isActive() const { return nargs() > 0; }
202 virtual bool isRelOp() const { return false; }
204 virtual bool isMacro() const { return false; }
207 virtual char getChar() const { return 0; }
209 virtual MathTextCodes code() const { return LM_TC_MIN; }
210 /// identifies things that can get \limits or \nolimits
211 virtual bool takesLimits() const { return false; }
214 virtual void push_back(MathInset *);
216 virtual void push_back(unsigned char c, MathTextCodes code);
218 virtual void dump() const;
221 virtual void validate(LaTeXFeatures & features) const;
223 virtual void handleFont(MathTextCodes) {}
226 static int workwidth;
230 void size(MathStyles s) const;
231 /// the used font size
232 mutable MathStyles size_;
235 /// the following are used for positioning the cursor with the mouse
236 /// cached cursor start position in pixels from the document left
238 /// cached cursor start position in pixels from the document top
242 std::ostream & operator<<(std::ostream &, MathInset const &);