4 * Purpose: Declaration of interaction classes for mathed
5 * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
6 * Created: January 1996
7 * Description: MathCursor control all user interaction
9 * Dependencies: Xlib, XForms
11 * Copyright: 1996, Alejandro Aguilar Sierra
13 * You are free to use and modify this code under the terms of
14 * the GNU General Public Licence version 2 or later.
24 #include "math_defs.h"
29 class MathMatrixInset;
30 class MathScriptInset;
32 class InsetFormulaBase;
37 /// Description of a position
38 struct MathCursorPos {
45 /// returns cell corresponding to this position
46 MathArray & cell() const;
47 /// returns cell corresponding to this position
48 MathArray & cell(int idx) const;
49 /// returns xcell corresponding to this position
50 MathXArray & xcell() const;
51 /// returns xcell corresponding to this position
52 MathXArray & xcell(int idx) const;
56 bool operator==(MathCursorPos const &, MathCursorPos const &);
58 bool operator<(MathCursorPos const &, MathCursorPos const &);
61 /// This is the external interface of Math's subkernel
65 explicit MathCursor(InsetFormulaBase *);
69 void insert(char, MathTextCodes t = LM_TC_MIN);
71 void insert(MathInset *);
73 void insert(MathArray const &);
83 bool right(bool sel = false);
85 bool left(bool sel = false);
87 bool up(bool sel = false);
89 bool down(bool sel = false);
90 /// Put the cursor in the first position
92 /// Put the cursor in the last position
94 /// moves cursor position one cell to the left
96 /// moves cursor position one cell to the right
98 /// moves cursor index one cell to the left
100 /// moves cursor index one cell to the right
102 /// moves position somehow up
104 /// moves position somehow down
113 void plainInsert(MathInset * p);
116 /// This is in pixels from (maybe?) the top of inset
117 void setPos(int, int);
119 void getPos(int & x, int & y);
121 MathInset * par() const;
122 /// return the next enclosing grid inset and the cursor's index in it
123 MathArrayInset * enclosingArray(int &) const;
125 InsetFormulaBase const * formula();
133 void interpret(string const &);
135 void setSize(MathStyles);
139 // Macro mode methods
140 void macroModeOpen();
142 void macroModeClose();
144 bool inMacroMode() const;
146 // Local selection methods
148 bool selection() const;
158 void selHandle(bool);
164 void drawSelection(Painter & pain) const;
166 void clearLastCode();
168 void setLastCode(MathTextCodes t);
170 void handleFont(MathTextCodes t);
172 void handleAccent(string const & name);
174 void handleDelim(int l, int r);
176 void handleNest(MathInset * p);
177 /// Splits cells and shifts right part to the next cell
179 /// Splits line and insert new row of cell
182 MathTextCodes getLastCode() const;
184 void pullArg(bool goright);
186 bool isInside(MathInset const *) const;
188 MathTextCodes nextCode() const;
190 MathTextCodes prevCode() const;
201 MathStyles style() const;
202 /// Make sure cursor position is valid
203 void normalize() const;
205 /// enter a MathInset from the front
206 void pushLeft(MathInset * par);
207 /// enter a MathInset from the back
208 void pushRight(MathInset * par);
209 /// leave current MathInset to the left
211 /// leave current MathInset to the left
215 MathArray & array() const;
217 MathXArray & xarray() const;
219 /// returns the selection
220 void getSelection(MathCursorPos &, MathCursorPos &) const;
221 /// returns the normalized anchor of the selection
222 MathCursorPos normalAnchor() const;
223 /// returns the normalized anchor of the selection
224 bool openable(MathInset *, bool selection, bool useupdown) const;
226 /// path of positions the cursor had to go if it were leving each inset
227 std::vector<MathCursorPos> Cursor_;
228 /// path of positions the anchor had to go if it were leving each inset
229 std::vector<MathCursorPos> Anchor_;
231 /// reference to the last item of the path
232 MathCursorPos & cursor();
234 MathCursorPos const & cursor() const;
240 MathInset * parInset(int i) const;
242 MathMatrixInset * outerPar() const;
244 void seldump(char const * str) const;
246 void dump(char const * str) const;
249 void merge(MathArray const & arr);
251 MathInset * nextInset() const;
253 MathInset * prevInset() const;
255 MathScriptInset * prevScriptInset() const;
257 MathSpaceInset * prevSpaceInset() const;
263 /// x-offset of current cell relative to par xo
264 int cellXOffset() const;
265 /// y-offset of current cell relative to par yo
266 int cellYOffset() const;
267 /// current x position relative to par xo
269 /// current y position relative to par yo
271 /// adjust position in current cell according to x. idx is not changed.
275 InsetFormulaBase * const formula_;
277 MathTextCodes lastcode_;
279 MathFuncInset * imacro_;
281 /// do we currently select
285 extern MathCursor * mathcursor;