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 interpret(char);
146 void setSize(MathStyles);
150 // Macro mode methods
151 void macroModeClose();
153 bool inMacroMode() const;
155 // Local selection methods
157 bool selection() const;
167 void selHandle(bool);
173 void drawSelection(Painter & pain) const;
175 void handleFont(MathTextCodes t);
177 void handleDelim(string const & l, string const & r);
179 void handleNest(MathInset * p);
180 /// Splits cells and shifts right part to the next cell
182 /// Splits line and insert new row of cell
185 MathTextCodes getLastCode() const;
187 void pullArg(bool goright);
189 bool isInside(MathInset const *) const;
191 MathTextCodes nextCode() const;
197 col_type col() const;
199 row_type row() const;
202 MathStyles style() const;
203 /// Make sure cursor position is valid
204 void normalize() const;
206 /// enter a MathInset from the front
207 void pushLeft(MathInset * par);
208 /// enter a MathInset from the back
209 void pushRight(MathInset * par);
210 /// leave current MathInset to the left
212 /// leave current MathInset to the left
216 MathArray & array() const;
218 MathXArray & xarray() const;
220 MathAtom const * prevAtom() const;
222 MathAtom * prevAtom();
224 MathAtom const * nextAtom() const;
226 MathAtom * nextAtom();
228 /// returns the selection
229 void getSelection(MathCursorPos &, MathCursorPos &) const;
230 /// returns the normalized anchor of the selection
231 MathCursorPos normalAnchor() const;
233 /// path of positions the cursor had to go if it were leving each inset
234 std::vector<MathCursorPos> Cursor_;
235 /// path of positions the anchor had to go if it were leving each inset
236 std::vector<MathCursorPos> Anchor_;
238 /// reference to the last item of the path
239 MathCursorPos & cursor();
241 MathCursorPos const & cursor() const;
245 pos_type last() const;
247 MathMatrixInset * outerPar() const;
249 void seldump(char const * str) const;
251 void dump(char const * str) const;
254 void merge(MathArray const & arr);
256 MathInset * nextInset() const;
258 MathInset * prevInset() const;
260 MathScriptInset * prevScriptInset() const;
262 MathSpaceInset * prevSpaceInset() const;
265 /// moves cursor position one cell to the left
267 /// moves cursor position one cell to the right
269 /// moves cursor index one cell to the left
271 /// moves cursor index one cell to the right
273 /// moves position somehow up
275 /// moves position somehow down
277 /// glue adjacent atoms if possible
278 void glueAdjacentAtoms();
281 string macroName() const;
283 int macroNamePos() const;
285 void insert(char, MathTextCodes t);
286 /// can we enter the inset?
287 bool openable(MathInset *, bool selection) const;
288 /// can the setPos routine enter that inset?
289 MathInset * positionable(MathAtom *, int x, int y) const;
290 /// write access to "inner" flag
292 /// write access to cursor cell position
294 /// write access to cursor cell index
296 /// x-offset of current cell relative to par xo
297 int cellXOffset() const;
298 /// y-offset of current cell relative to par yo
299 int cellYOffset() const;
300 /// current x position relative to par xo
302 /// current y position relative to par yo
304 /// adjust position in current cell according to x. idx is not changed.
308 InsetFormulaBase * const formula_;
310 MathTextCodes lastcode_;
312 /// do we currently select
316 extern MathCursor * mathcursor;