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"
25 #include "math_inset.h"
32 class MathMatrixInset;
33 class MathScriptInset;
35 class InsetFormulaBase;
42 /// Description of a position
43 struct MathCursorPos {
47 MathInset::idx_type idx_;
49 MathInset::pos_type pos_;
51 /// returns cell corresponding to this position
52 MathArray & cell() const;
53 /// returns cell corresponding to this position
54 MathArray & cell(MathInset::idx_type idx) const;
55 /// returns xcell corresponding to this position
56 MathXArray & xcell() const;
57 /// returns xcell corresponding to this position
58 MathXArray & xcell(MathInset::idx_type idx) const;
62 bool operator==(MathCursorPos const &, MathCursorPos const &);
64 bool operator<(MathCursorPos const &, MathCursorPos const &);
67 /// This is the external interface of Math's subkernel
70 /// short of anything else reasonable
71 typedef MathInset::size_type size_type;
72 /// type for cursor positions within a cell
73 typedef MathInset::pos_type pos_type;
74 /// type for cell indices
75 typedef MathInset::idx_type idx_type;
76 /// type for row numbers
77 typedef MathInset::row_type row_type;
78 /// type for column numbers
79 typedef MathInset::col_type col_type;
82 explicit MathCursor(InsetFormulaBase *, bool left);
84 void insert(MathAtom const &);
86 void insert(MathArray const &);
88 void paste(MathArray const &);
94 void home(bool sel = false);
96 void end(bool sel = false);
98 bool right(bool sel = false);
100 bool left(bool sel = false);
102 bool up(bool sel = false);
104 bool down(bool sel = false);
105 /// Put the cursor in the first position
107 /// Put the cursor in the last position
116 void plainInsert(MathAtom const &);
118 void niceInsert(MathAtom const &);
122 /// This is in pixels from (maybe?) the top of inset
123 void setPos(int, int);
125 void getPos(int & x, int & y);
127 MathAtom & par() const;
128 /// return the next enclosing grid inset and the cursor's index in it
129 MathArrayInset * enclosingArray(idx_type &) const;
131 InsetFormulaBase const * formula();
133 pos_type pos() const;
135 idx_type idx() const;
137 size_type size() const;
139 void interpret(string const &);
141 void interpret(char);
145 // Macro mode methods
146 void macroModeClose();
148 bool inMacroMode() const;
150 // Local selection methods
152 bool selection() const;
162 void selHandle(bool);
168 void drawSelection(Painter & pain) const;
170 void handleFont(MathTextCodes t);
172 void handleDelim(string const & l, string const & r);
174 void handleNest(MathInset * p);
175 /// Splits cells and shifts right part to the next cell
177 /// Splits line and insert new row of cell
180 MathTextCodes getLastCode() const;
182 void pullArg(bool goright);
184 bool isInside(MathInset const *) const;
186 MathTextCodes nextCode() const;
192 col_type col() const;
194 row_type row() const;
196 /// Make sure cursor position is valid
197 void normalize() const;
199 /// enter a MathInset
200 void push(MathAtom & par);
201 /// enter a MathInset from the front
202 void pushLeft(MathAtom & par);
203 /// enter a MathInset from the back
204 void pushRight(MathAtom & par);
205 /// leave current MathInset to the left
207 /// leave current MathInset to the left
211 MathArray & array() const;
213 MathXArray & xarray() const;
215 bool hasPrevAtom() const;
217 bool hasNextAtom() const;
219 MathAtom const & prevAtom() const;
221 MathAtom & prevAtom();
223 MathAtom const & nextAtom() const;
225 MathAtom & nextAtom();
227 /// returns the selection
228 void getSelection(MathCursorPos &, MathCursorPos &) const;
229 /// returns the normalized anchor of the selection
230 MathCursorPos normalAnchor() const;
232 /// path of positions the cursor had to go if it were leving each inset
233 std::vector<MathCursorPos> Cursor_;
234 /// path of positions the anchor had to go if it were leving each inset
235 std::vector<MathCursorPos> Anchor_;
237 /// reference to the last item of the path
238 MathCursorPos & cursor();
240 MathCursorPos const & cursor() const;
243 void seldump(char const * str) const;
245 void dump(char const * str) const;
248 friend class Selection;
251 /// moves cursor position one cell to the left
253 /// moves cursor position one cell to the right
255 /// moves cursor index one cell to the left
257 /// moves cursor index one cell to the right
259 /// moves position somehow up
261 /// moves position somehow down
265 string macroName() const;
267 int macroNamePos() const;
269 void insert(char, MathTextCodes t);
270 /// can we enter the inset?
271 bool openable(MathAtom const &, bool selection) const;
272 /// can the setPos routine enter that inset?
273 bool positionable(MathAtom const &, int x, int y) const;
274 /// write access to cursor cell position
276 /// write access to cursor cell index
278 /// x-offset of current cell relative to par xo
279 int cellXOffset() const;
280 /// y-offset of current cell relative to par yo
281 int cellYOffset() const;
282 /// current x position relative to par xo
284 /// current y position relative to par yo
286 /// adjust position in current cell according to x. idx is not changed.
290 InsetFormulaBase * const formula_;
292 MathTextCodes lastcode_;
294 /// do we currently select
298 extern MathCursor * mathcursor;