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.
42 class MathScriptInset;
46 /// short of anything else reasonable
47 typedef MathArray::size_type size_type;
48 /// type for cursor positions within a cell
49 typedef MathArray::size_type pos_type;
50 /// type for cell indices
51 typedef size_type idx_type;
52 /// type for row numbers
53 typedef size_type row_type;
54 /// type for column numbers
55 typedef size_type col_type;
59 /// the virtual base destructor
62 /// draw the object, sets xo_ and yo_ cached values
63 virtual void draw(Painter &, int x, int y) const;
64 /// write LaTeX and Lyx code
65 virtual void write(std::ostream &, bool fragile) const;
66 /// write normalized content
67 virtual void writeNormal(std::ostream &) const;
69 virtual MathInset * clone() const = 0;
70 ///substitutes macro arguments if necessary
71 virtual void substitute(MathMacro const & macro);
72 /// compute the size of the object, sets ascend_, descend_ and width_
73 virtual void metrics(MathStyles st) const;
75 virtual int ascent() const { return 1; }
77 virtual int descent() const { return 1; }
79 virtual int width() const { return 2; }
81 virtual int height() const;
83 virtual MathStyles size() const;
85 /// Where should we go when we press the up cursor key?
86 virtual bool idxUp(idx_type & idx, pos_type & pos) const;
88 virtual bool idxDown(idx_type & idx, pos_type & pos) const;
90 virtual bool idxLeft(idx_type & idx, pos_type & pos) const;
92 virtual bool idxRight(idx_type & idx, pos_type & pos) const;
94 /// Move one physical cell up
95 virtual bool idxNext(idx_type & idx, pos_type & pos) const;
96 /// Move one physical cell down
97 virtual bool idxPrev(idx_type & idx, pos_type & pos) const;
99 /// Target pos when we enter the inset from the left by pressing "Right"
100 virtual bool idxFirst(idx_type & idx, pos_type & pos) const;
101 /// Target pos when we enter the inset from the right by pressing "Left"
102 virtual bool idxLast(idx_type & idx, pos_type & pos) const;
104 /// Where should we go if we press home?
105 virtual bool idxHome(idx_type & idx, pos_type & pos) const;
106 /// Where should we go if we press end?
107 virtual bool idxEnd(idx_type & idx, pos_type & pos) const;
109 /// Delete a cell and move cursor
110 // the return value indicates whether the cursor should leave the inset
111 // and/or the whole inset should be deleted
112 virtual void idxDelete(idx_type & idx, bool & popit, bool & deleteit);
113 // deletes a cell range and moves the cursor
114 virtual void idxDeleteRange(idx_type from, idx_type to);
115 // returns list of cell indices that are "between" from and to for
116 // selection purposes
117 virtual std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
120 virtual idx_type nargs() const;
123 virtual MathArray & cell(idx_type);
125 virtual MathArray const & cell(idx_type) const;
127 virtual MathXArray & xcell(idx_type);
129 virtual MathXArray const & xcell(idx_type) const;
132 virtual int xo() const;
134 virtual int yo() const;
136 virtual void xo(int tx) const;
138 virtual void yo(int ty) const;
142 virtual col_type ncols() const { return 1; }
144 virtual row_type nrows() const { return 1; }
146 virtual col_type col(row_type) const { return 0; }
148 virtual row_type row(row_type) const { return 0; }
150 virtual int cellXOffset(row_type) const { return 0; }
152 virtual int cellYOffset(row_type) const { return 0; }
154 virtual void addRow(row_type) {}
156 virtual void delRow(row_type) {}
158 virtual void addCol(col_type) {}
160 virtual void delCol(col_type) {}
163 virtual void userSetSize(MathStyles &) {}
166 virtual void getXY(int & x, int & y) const;
168 virtual bool covers(int x, int y) const;
169 /// identifies things that can get scripts
170 virtual bool isScriptable() const { return false; }
171 /// identifies ScriptInsets
172 virtual bool isScriptInset() const { return false; }
173 /// identifies SpaceInsets
174 virtual bool isSpaceInset() const { return false; }
175 /// identifies GridInsets
176 virtual bool isGrid() const { return false; }
177 /// identifies ArrayInsets
178 virtual bool isArray() const { return false; }
179 /// identifies CharInsets
180 virtual MathCharInset const * asCharInset() const { return 0; }
181 /// identifies ScriptInsets
182 virtual MathScriptInset const * asScriptInset() const { return 0; }
184 virtual bool isActive() const { return nargs() > 0; }
186 virtual bool isRelOp() const { return false; }
188 virtual bool isMacro() const { return false; }
190 virtual char getChar() const { return 0; }
192 virtual MathTextCodes code() const { return LM_TC_MIN; }
193 /// identifies things that can get \limits or \nolimits
194 virtual bool takesLimits() const { return false; }
197 virtual void push_back(MathInset *);
199 virtual void push_back(unsigned char c, MathTextCodes code);
201 virtual void dump() const;
204 virtual void validate(LaTeXFeatures & features) const;
206 virtual void handleFont(MathTextCodes) {}
209 static int workwidth;
213 void size(MathStyles s) const;
214 /// the used font size
215 mutable MathStyles size_;
218 /// the following are used for positioning the cursor with the mouse
219 /// cached cursor start position in pixels from the document left
221 /// cached cursor start position in pixels from the document top
225 std::ostream & operator<<(std::ostream &, MathInset const &);