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"
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 MathGridInset * enclosingGrid(idx_type &) const;
131 InsetFormulaBase const * formula();
133 pos_type pos() const;
135 idx_type idx() const;
137 size_type size() const;
139 bool interpret(string const &);
141 bool 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 selGet(MathArray & ar);
170 void drawSelection(Painter & pain) const;
172 void handleFont(MathTextCodes t);
174 void handleDelim(string const & l, string const & 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
181 /// read contents of line into an array
182 void readLine(MathArray & ar) const;
184 MathTextCodes getLastCode() const;
186 void pullArg(bool goright);
188 bool isInside(MathInset const *) const;
190 MathTextCodes nextCode() const;
196 col_type ncols() const;
198 col_type col() const;
200 row_type row() const;
202 /// Make sure cursor position is valid
203 void normalize() const;
205 UpdatableInset * asHyperActiveInset() const;
207 /// enter a MathInset
208 void push(MathAtom & par);
209 /// enter a MathInset from the front
210 void pushLeft(MathAtom & par);
211 /// enter a MathInset from the back
212 void pushRight(MathAtom & par);
213 /// leave current MathInset to the left
215 /// leave current MathInset to the left
219 MathArray & array() const;
221 MathXArray & xarray() const;
223 bool hasPrevAtom() const;
225 bool hasNextAtom() const;
227 MathAtom const & prevAtom() const;
229 MathAtom & prevAtom();
231 MathAtom const & nextAtom() const;
233 MathAtom & nextAtom();
235 /// returns the selection
236 void getSelection(MathCursorPos &, MathCursorPos &) const;
237 /// returns the normalized anchor of the selection
238 MathCursorPos normalAnchor() const;
240 /// path of positions the cursor had to go if it were leving each inset
241 std::vector<MathCursorPos> Cursor_;
242 /// path of positions the anchor had to go if it were leving each inset
243 std::vector<MathCursorPos> Anchor_;
245 /// reference to the last item of the path
246 MathCursorPos & cursor();
248 MathCursorPos const & cursor() const;
251 void seldump(char const * str) const;
253 void dump(char const * str) const;
255 void stripFromLastEqualSign();
258 friend class Selection;
261 /// moves cursor position one cell to the left
263 /// moves cursor position one cell to the right
265 /// moves cursor index one cell to the left
267 /// moves cursor index one cell to the right
269 /// moves position somehow up
271 /// moves position somehow down
275 string macroName() const;
277 int macroNamePos() const;
279 void insert(char, MathTextCodes t);
280 /// can we enter the inset?
281 bool openable(MathAtom const &, bool selection) const;
282 /// can the setPos routine enter that inset?
283 bool positionable(MathAtom const &, int x, int y) const;
284 /// write access to cursor cell position
286 /// write access to cursor cell index
288 /// x-offset of current cell relative to par xo
289 int cellXOffset() const;
290 /// y-offset of current cell relative to par yo
291 int cellYOffset() const;
292 /// current x position relative to par xo
294 /// current y position relative to par yo
296 /// adjust position in current cell according to x. idx is not changed.
300 InsetFormulaBase * const formula_;
302 MathTextCodes lastcode_;
304 /// do we currently select
308 extern MathCursor * mathcursor;