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;
47 typedef MathArray::size_type size_type;
51 /// the virtual base destructor
54 /// draw the object, sets xo_ and yo_ cached values
55 virtual void draw(Painter &, int x, int y) const;
56 /// write LaTeX and Lyx code
57 virtual void write(std::ostream &, bool fragile) const;
58 /// write normalized content
59 virtual void writeNormal(std::ostream &) const;
61 virtual MathInset * clone() const = 0;
62 ///substitutes macro arguments if necessary
63 virtual void substitute(MathMacro const & macro);
64 /// compute the size of the object, sets ascend_, descend_ and width_
65 virtual void metrics(MathStyles st) const;
67 virtual int ascent() const { return 1; }
69 virtual int descent() const { return 1; }
71 virtual int width() const { return 2; }
73 virtual int height() const;
75 virtual MathStyles size() const;
77 /// Where should we go when we press the up cursor key?
78 virtual bool idxUp(unsigned int & idx, unsigned int & pos) const;
80 virtual bool idxDown(unsigned int & idx, unsigned int & pos) const;
82 virtual bool idxLeft(unsigned int & idx, unsigned int & pos) const;
84 virtual bool idxRight(unsigned int & idx, unsigned int & pos) const;
86 /// Move one physical cell up
87 virtual bool idxNext(unsigned int & idx, unsigned int & pos) const;
88 /// Move one physical cell down
89 virtual bool idxPrev(unsigned int & idx, unsigned int & pos) const;
91 /// Target pos when we enter the inset from the left by pressing "Right"
92 virtual bool idxFirst(unsigned int & idx, unsigned int & pos) const;
93 /// Target pos when we enter the inset from the right by pressing "Left"
94 virtual bool idxLast(unsigned int & idx, unsigned int & pos) const;
96 /// Where should we go if we press home?
97 virtual bool idxHome(unsigned int & idx, unsigned int & pos) const;
98 /// Where should we go if we press end?
99 virtual bool idxEnd(unsigned int & idx, unsigned int & pos) const;
101 /// Delete a cell and move cursor
102 // the return value indicates whether the cursor should leave the inset
103 // and/or the whole inset should be deleted
104 virtual void idxDelete(unsigned int & idx, bool & popit, bool & deleteit);
105 // deletes a cell range and moves the cursor
106 virtual void idxDeleteRange(unsigned int from, unsigned int to);
107 // returns list of cell indices that are "between" from and to for
108 // selection purposes
109 virtual std::vector<unsigned int>
110 idxBetween(unsigned int from, unsigned int to) const;
113 virtual unsigned int nargs() const;
116 virtual MathArray & cell(unsigned int);
118 virtual MathArray const & cell(unsigned int) const;
120 virtual MathXArray & xcell(unsigned int);
122 virtual MathXArray const & xcell(unsigned int) const;
125 virtual int xo() const;
127 virtual int yo() const;
129 virtual void xo(int tx) const;
131 virtual void yo(int ty) const;
135 virtual unsigned int ncols() const { return 1; }
137 virtual unsigned int nrows() const { return 1; }
139 virtual unsigned int col(unsigned int) const { return 0; }
141 virtual unsigned int row(unsigned int) const { return 0; }
143 virtual int cellXOffset(unsigned int) const { return 0; }
145 virtual int cellYOffset(unsigned int) const { return 0; }
147 virtual void addRow(unsigned int) {}
149 virtual void delRow(unsigned int) {}
151 virtual void addCol(unsigned int) {}
153 virtual void delCol(unsigned int) {}
156 virtual void userSetSize(MathStyles &) {}
159 virtual void getXY(int & x, int & y) const;
161 virtual bool covers(int x, int y) const;
162 /// identifies things that can get scripts
163 virtual bool isScriptable() const { return false; }
164 /// identifies ScriptInsets
165 virtual bool isScriptInset() const { return false; }
166 /// identifies SpaceInsets
167 virtual bool isSpaceInset() const { return false; }
168 /// identifies GridInsets
169 virtual bool isGrid() const { return false; }
170 /// identifies ArrayInsets
171 virtual bool isArray() const { return false; }
172 /// identifies CharInsets
173 virtual MathCharInset const * asCharInset() const { return 0; }
174 /// identifies ScriptInsets
175 virtual MathScriptInset const * asScriptInset() const { return 0; }
177 virtual bool isActive() const { return nargs() > 0; }
179 virtual bool isRelOp() const { return false; }
181 virtual bool isMacro() const { return false; }
183 virtual char getChar() const { return 0; }
185 virtual MathTextCodes code() const { return LM_TC_MIN; }
186 /// identifies things that can get \limits or \nolimits
187 virtual bool takesLimits() const { return false; }
190 virtual void push_back(MathInset *);
192 virtual void push_back(unsigned char c, MathTextCodes code);
194 virtual void dump() const;
197 virtual void validate(LaTeXFeatures & features) const;
199 virtual void handleFont(MathTextCodes) {}
202 static int workwidth;
206 void size(MathStyles s) const;
207 /// the used font size
208 mutable MathStyles size_;
211 /// the following are used for positioning the cursor with the mouse
212 /// cached cursor start position in pixels from the document left
214 /// cached cursor start position in pixels from the document top
218 std::ostream & operator<<(std::ostream &, MathInset const &);