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"
31 class MathMatrixInset;
32 class MathScriptInset;
34 class InsetFormulaBase;
40 /// Description of a position
41 struct MathCursorPos {
45 MathInset::idx_type idx_;
47 MathInset::pos_type pos_;
48 /// faked position "inside an atom"
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;
60 /// returns atom corresponding to this position
61 MathAtom * at() const;
65 bool operator==(MathCursorPos const &, MathCursorPos const &);
67 bool operator<(MathCursorPos const &, MathCursorPos const &);
70 /// This is the external interface of Math's subkernel
73 /// short of anything else reasonable
74 typedef MathInset::size_type size_type;
75 /// type for cursor positions within a cell
76 typedef MathInset::pos_type pos_type;
77 /// type for cell indices
78 typedef MathInset::idx_type idx_type;
79 /// type for row numbers
80 typedef MathInset::row_type row_type;
81 /// type for column numbers
82 typedef MathInset::col_type col_type;
85 explicit MathCursor(InsetFormulaBase *);
87 void insert(MathInset *);
89 void insert(MathArray const &);
95 void home(bool sel = false);
97 void end(bool sel = false);
99 bool right(bool sel = false);
101 bool left(bool sel = false);
103 bool up(bool sel = false);
105 bool down(bool sel = false);
106 /// Put the cursor in the first position
108 /// Put the cursor in the last position
117 void plainInsert(MathInset * p);
119 void niceInsert(MathInset * p);
123 /// This is in pixels from (maybe?) the top of inset
124 void setPos(int, int);
126 void getPos(int & x, int & y);
128 MathInset * par() const;
129 /// return the next enclosing grid inset and the cursor's index in it
130 MathArrayInset * enclosingArray(idx_type &) const;
132 InsetFormulaBase const * formula();
136 pos_type pos() const;
138 idx_type idx() const;
140 size_type size() const;
142 void interpret(string const &);
144 void setSize(MathStyles);
148 // Macro mode methods
149 void macroModeClose();
151 bool inMacroMode() const;
153 // Local selection methods
155 bool selection() const;
165 void selHandle(bool);
171 void drawSelection(Painter & pain) const;
173 void handleFont(MathTextCodes t);
175 void handleDelim(string const & l, string const & r);
177 void handleNest(MathInset * p);
178 /// Splits cells and shifts right part to the next cell
180 /// Splits line and insert new row of cell
183 MathTextCodes getLastCode() const;
185 void pullArg(bool goright);
187 bool isInside(MathInset const *) const;
189 MathTextCodes nextCode() const;
195 col_type col() const;
197 row_type row() const;
200 MathStyles style() const;
201 /// Make sure cursor position is valid
202 void normalize() const;
204 /// enter a MathInset from the front
205 void pushLeft(MathInset * par);
206 /// enter a MathInset from the back
207 void pushRight(MathInset * par);
208 /// leave current MathInset to the left
210 /// leave current MathInset to the left
214 MathArray & array() const;
216 MathXArray & xarray() const;
218 MathAtom const * prevAtom() const;
220 MathAtom * prevAtom();
222 MathAtom const * nextAtom() const;
224 MathAtom * nextAtom();
226 /// returns the selection
227 void getSelection(MathCursorPos &, MathCursorPos &) const;
228 /// returns the normalized anchor of the selection
229 MathCursorPos normalAnchor() const;
231 /// path of positions the cursor had to go if it were leving each inset
232 std::vector<MathCursorPos> Cursor_;
233 /// path of positions the anchor had to go if it were leving each inset
234 std::vector<MathCursorPos> Anchor_;
236 /// reference to the last item of the path
237 MathCursorPos & cursor();
239 MathCursorPos const & cursor() const;
243 pos_type last() const;
245 MathMatrixInset * outerPar() const;
247 void seldump(char const * str) const;
249 void dump(char const * str) const;
252 void merge(MathArray const & arr);
254 MathInset * nextInset() const;
256 MathInset * prevInset() const;
258 MathScriptInset * prevScriptInset() const;
260 MathSpaceInset * prevSpaceInset() const;
263 /// moves cursor position one cell to the left
265 /// moves cursor position one cell to the right
267 /// moves cursor index one cell to the left
269 /// moves cursor index one cell to the right
271 /// moves position somehow up
273 /// moves position somehow down
275 /// glue adjacent atoms if possible
276 void glueAdjacentAtoms();
279 string macroName() const;
281 void insert(char, MathTextCodes t);
282 /// can we enter the inset?
283 bool openable(MathInset *, bool selection) const;
284 /// can the setPos routine enter that inset?
285 MathInset * positionable(MathAtom *, int x, int y) const;
286 /// write access to "inner" flag
288 /// write access to cursor cell position
290 /// write access to cursor cell index
292 /// x-offset of current cell relative to par xo
293 int cellXOffset() const;
294 /// y-offset of current cell relative to par yo
295 int cellYOffset() const;
296 /// current x position relative to par xo
298 /// current y position relative to par yo
300 /// adjust position in current cell according to x. idx is not changed.
304 InsetFormulaBase * const formula_;
306 MathTextCodes lastcode_;
308 /// do we currently select
312 extern MathCursor * mathcursor;