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 "symbol_def.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.
48 (int na = 0, string const & nm = string(), MathInsetTypes ot = LM_OT_SIMPLE);
50 /// the virtual base destructor
51 virtual ~MathInset() {}
53 /// draw the object, sets xo_ and yo_ cached values
54 virtual void draw(Painter &, int x, int baseline) = 0;
55 /// write LaTeX and Lyx code
56 virtual void write(std::ostream &, bool fragile) const = 0;
57 /// write normalized content
58 virtual void writeNormal(std::ostream &) const;
60 virtual MathInset * clone() const = 0;
61 /// appends itself with macro arguments substituted
62 virtual void substitute(MathArray & array, MathMacro const & macro) const;
63 /// compute the size of the object, sets ascend_, descend_ and width_
64 virtual void metrics(MathStyles st) = 0;
66 virtual int ascent() const;
68 virtual int descent() const;
70 virtual int width() const;
72 virtual int height() const;
74 virtual int limits() const;
76 virtual void limits(int);
78 string const & name() const;
80 MathInsetTypes getType() const;
82 MathInsetTypes GetType() const { return getType(); }
83 //Man: Avoid to use these functions if it's not strictly necessary
85 virtual void setType(MathInsetTypes t);
87 virtual void setName(string const & n);
89 MathStyles size() const;
91 /// Where should we go when we press the up cursor key?
92 virtual bool idxUp(int & idx, int & pos) const;
94 virtual bool idxDown(int & idx, int & pos) const;
96 virtual bool idxLeft(int & idx, int & pos) const;
98 virtual bool idxRight(int & idx, int & pos) const;
100 /// Move one physical cell up
101 virtual bool idxNext(int & idx, int & pos) const;
102 /// Move one physical cell down
103 virtual bool idxPrev(int & idx, int & pos) const;
105 /// Target pos when we enter the inset from the left by pressing "Right"
106 virtual bool idxFirst(int & idx, int & pos) const;
107 /// Target pos when we enter the inset from the left by pressing "Up"
108 virtual bool idxFirstUp(int & idx, int & pos) const;
109 /// Target pos when we enter the inset from the left by pressing "Down"
110 virtual bool idxFirstDown(int & idx, int & pos) const;
112 /// Target pos when we enter the inset from the right by pressing "Left"
113 virtual bool idxLast(int & idx, int & pos) const;
114 /// Target pos when we enter the inset from the right by pressing "Up"
115 virtual bool idxLastUp(int & idx, int & pos) const;
116 /// Target pos when we enter the inset from the right by pressing "Down"
117 virtual bool idxLastDown(int & idx, int & pos) const;
119 /// Where should we go if we press home?
120 virtual bool idxHome(int & idx, int & pos) const;
121 /// Where should we go if we press end?
122 virtual bool idxEnd(int & idx, int & pos) const;
124 /// Delete a cell and move cursor
125 // the return value indicates whether the cursor should leave the inset
126 // and/or the whole inset should be deleted
127 virtual void idxDelete(int & idx, bool & popit, bool & deleteit);
128 // deletes a cell range and moves the cursor
129 virtual void idxDeleteRange(int from, int to);
130 // returns list of cell indices that are "between" from and to for
132 virtual std::vector<int> idxBetween(int from, int to) const;
138 MathArray & cell(int);
140 MathArray const & cell(int) const;
142 MathXArray & xcell(int);
144 MathXArray const & xcell(int) const;
157 virtual int ncols() const { return 1; }
159 virtual int nrows() const { return 1; }
161 virtual int col(int) const { return 0; }
163 virtual int row(int) const { return 0; }
165 virtual void addRow(int) {}
167 virtual void delRow(int) {}
169 virtual void addCol(int) {}
171 virtual void delCol(int) {}
174 virtual void userSetSize(MathStyles &) {}
177 void getXY(int & x, int & y) const;
179 bool covers(int x, int y) const;
180 /// Identifies things that can get scripts
181 virtual bool isScriptable() const { return false; }
182 /// Identifies ScriptInsets
183 virtual bool isScriptInset() const { return false; }
184 /// Identifies SpaceInsets
185 virtual bool isSpaceInset() const { return false; }
187 virtual bool isActive() const { return nargs() > 0; }
191 void push_back(MathInset *);
193 void push_back(unsigned char ch, MathTextCodes fcode);
198 void validate(LaTeXFeatures & features) const;
201 static int workwidth;
203 /// usually the LaTeX name of the thingy
206 MathInsetTypes objtype;
207 /// the width of this inset as computed by metrics()
214 void size(MathStyles s);
215 /// the used font size
220 typedef std::vector<MathXArray> cells_type;
222 * The contents of the inset are contained here.
223 * Each inset is build from a number of insets.
228 /// the following are used for positioning the cursor with the mouse
229 /// cached cursor start position in pixels from the document left
231 /// cached cursor start position in pixels from the document top
235 std::ostream & operator<<(std::ostream &, MathInset const &);