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.
47 explicit MathInset(string const & nm = string());
49 /// the virtual base destructor
50 virtual ~MathInset() {}
52 /// draw the object, sets xo_ and yo_ cached values
53 virtual void draw(Painter &, int x, int y) const;
54 /// write LaTeX and Lyx code
55 virtual void write(std::ostream &, bool fragile) const;
56 /// write normalized content
57 virtual void writeNormal(std::ostream &) const;
59 virtual MathInset * clone() const = 0;
60 /// appends itself with macro arguments substituted
61 virtual void substitute(MathArray & array, MathMacro const & macro) const;
62 /// compute the size of the object, sets ascend_, descend_ and width_
63 virtual void metrics(MathStyles st) const;
65 virtual int ascent() const { return 1; }
67 virtual int descent() const { return 1; }
69 virtual int width() const { return 2; }
71 virtual int height() const;
73 virtual string const & name() const;
75 virtual void setName(string const & n);
77 virtual MathStyles size() const;
79 /// Where should we go when we press the up cursor key?
80 virtual bool idxUp(int & idx, int & pos) const;
82 virtual bool idxDown(int & idx, int & pos) const;
84 virtual bool idxLeft(int & idx, int & pos) const;
86 virtual bool idxRight(int & idx, int & pos) const;
88 /// Move one physical cell up
89 virtual bool idxNext(int & idx, int & pos) const;
90 /// Move one physical cell down
91 virtual bool idxPrev(int & idx, int & pos) const;
93 /// Target pos when we enter the inset from the left by pressing "Right"
94 virtual bool idxFirst(int & idx, int & pos) const;
95 /// Target pos when we enter the inset from the left by pressing "Up"
96 virtual bool idxFirstUp(int & idx, int & pos) const;
97 /// Target pos when we enter the inset from the left by pressing "Down"
98 virtual bool idxFirstDown(int & idx, int & pos) const;
100 /// Target pos when we enter the inset from the right by pressing "Left"
101 virtual bool idxLast(int & idx, int & pos) const;
102 /// Target pos when we enter the inset from the right by pressing "Up"
103 virtual bool idxLastUp(int & idx, int & pos) const;
104 /// Target pos when we enter the inset from the right by pressing "Down"
105 virtual bool idxLastDown(int & idx, int & pos) const;
107 /// Where should we go if we press home?
108 virtual bool idxHome(int & idx, int & pos) const;
109 /// Where should we go if we press end?
110 virtual bool idxEnd(int & idx, int & pos) const;
112 /// Delete a cell and move cursor
113 // the return value indicates whether the cursor should leave the inset
114 // and/or the whole inset should be deleted
115 virtual void idxDelete(int & idx, bool & popit, bool & deleteit);
116 // deletes a cell range and moves the cursor
117 virtual void idxDeleteRange(int from, int to);
118 // returns list of cell indices that are "between" from and to for
119 // selection purposes
120 virtual std::vector<int> idxBetween(int from, int to) const;
123 virtual int nargs() const;
126 virtual MathArray & cell(int);
128 virtual MathArray const & cell(int) const;
130 virtual MathXArray & xcell(int);
132 virtual MathXArray const & xcell(int) const;
135 virtual int xo() const;
137 virtual int yo() const;
139 virtual void xo(int tx) const;
141 virtual void yo(int ty) const;
145 virtual int ncols() const { return 1; }
147 virtual int nrows() const { return 1; }
149 virtual int col(int) const { return 0; }
151 virtual int row(int) const { return 0; }
153 virtual void addRow(int) {}
155 virtual void delRow(int) {}
157 virtual void addCol(int) {}
159 virtual void delCol(int) {}
162 virtual void userSetSize(MathStyles &) {}
165 virtual void getXY(int & x, int & y) const;
167 virtual bool covers(int x, int y) const;
168 /// identifies things that can get scripts
169 virtual bool isScriptable() const { return false; }
170 /// identifies ScriptInsets
171 virtual bool isScriptInset() const { return false; }
172 /// identifies SpaceInsets
173 virtual bool isSpaceInset() const { return false; }
174 /// identifies GridInsets
175 virtual bool isGrid() const { return false; }
176 /// identifies ArrayInsets
177 virtual bool isArray() const { return false; }
178 /// identifies Charinsets
179 virtual bool isCharInset() const { return false; }
181 virtual bool isActive() const { return nargs() > 0; }
183 virtual char getChar() const { return 0; }
186 virtual void push_back(MathInset *);
188 virtual void push_back(unsigned char ch, MathTextCodes fcode);
190 virtual void dump() const;
193 virtual void validate(LaTeXFeatures & features) const;
196 static int workwidth;
198 /// the inherited text style
199 virtual MathTextCodes code() const;
201 virtual void code(MathTextCodes t);
204 /// usually the LaTeX name of the thingy
207 void size(MathStyles s) const;
208 /// the used font size
209 mutable MathStyles size_;
210 /// the inherited text style
211 mutable MathTextCodes code_;
214 /// the following are used for positioning the cursor with the mouse
215 /// cached cursor start position in pixels from the document left
217 /// cached cursor start position in pixels from the document top
221 std::ostream & operator<<(std::ostream &, MathInset const &);