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"
28 class InsetFormulaBase;
32 /// Description of a position
33 struct MathCursorPos {
37 MathInset::idx_type idx_;
39 MathInset::pos_type pos_;
41 /// returns cell corresponding to this position
42 MathArray & cell() const;
43 /// returns cell corresponding to this position
44 MathArray & cell(MathInset::idx_type idx) const;
45 /// returns xcell corresponding to this position
46 MathXArray & xcell() const;
47 /// returns xcell corresponding to this position
48 MathXArray & xcell(MathInset::idx_type idx) const;
52 bool operator==(MathCursorPos const &, MathCursorPos const &);
54 bool operator<(MathCursorPos const &, MathCursorPos const &);
57 /// This is the external interface of Math's subkernel
60 /// short of anything else reasonable
61 typedef MathInset::size_type size_type;
62 /// type for cursor positions within a cell
63 typedef MathInset::pos_type pos_type;
64 /// type for cell indices
65 typedef MathInset::idx_type idx_type;
66 /// type for row numbers
67 typedef MathInset::row_type row_type;
68 /// type for column numbers
69 typedef MathInset::col_type col_type;
72 explicit MathCursor(InsetFormulaBase *, bool left);
74 void insert(MathAtom const &);
76 void insert(MathArray const &);
78 void paste(MathArray const &);
84 void home(bool sel = false);
86 void end(bool sel = false);
88 bool right(bool sel = false);
90 bool left(bool sel = false);
92 bool up(bool sel = false);
94 bool down(bool sel = false);
95 /// Put the cursor in the first position
97 /// Put the cursor in the last position
106 void plainInsert(MathAtom const &);
108 void niceInsert(MathAtom const &);
112 /// This is in pixels from (maybe?) the top of inset
113 void setPos(int x, int y);
114 /// This is in pixels from (maybe?) the top of inset, don't move further
116 void getPos(int & x, int & y);
118 MathAtom & par() const;
119 /// return the next enclosing grid inset and the cursor's index in it
120 MathGridInset * enclosingGrid(idx_type &) const;
122 InsetFormulaBase const * formula();
124 pos_type pos() const;
126 idx_type idx() const;
128 size_type size() const;
130 bool interpret(string const &);
132 bool interpret(char);
136 // Macro mode methods
137 void macroModeClose();
139 bool inMacroMode() const;
141 // Local selection methods
143 bool selection() const;
153 void selHandle(bool);
159 void selGet(MathArray & ar);
161 void drawSelection(Painter & pain) const;
163 void handleFont(MathTextCodes t);
165 void handleDelim(string const & l, string const & r);
167 void handleNest(MathInset * p);
168 /// Splits cells and shifts right part to the next cell
170 /// Splits line and insert new row of cell
172 /// read contents of line into an array
173 void readLine(MathArray & ar) const;
175 MathTextCodes getLastCode() const;
177 void pullArg(bool goright);
179 bool isInside(MathInset const *) const;
181 MathTextCodes nextCode() const;
187 col_type ncols() const;
189 col_type col() const;
191 row_type row() const;
193 /// Make sure cursor position is valid
194 void normalize() const;
196 UpdatableInset * asHyperActiveInset() const;
198 /// enter a MathInset
199 void push(MathAtom & par);
200 /// enter a MathInset from the front
201 void pushLeft(MathAtom & par);
202 /// enter a MathInset from the back
203 void pushRight(MathAtom & par);
204 /// leave current MathInset to the left
206 /// leave current MathInset to the left
210 MathArray & array() const;
212 MathXArray & xarray() const;
214 bool hasPrevAtom() const;
216 bool hasNextAtom() 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;
242 void seldump(char const * str) const;
244 void dump(char const * str) const;
246 void stripFromLastEqualSign();
249 friend class Selection;
252 /// moves cursor position one cell to the left
254 /// moves cursor position one cell to the right
256 /// moves cursor index one cell to the left
258 /// moves cursor index one cell to the right
260 /// moves position somehow up
262 /// moves position somehow down
266 string macroName() const;
268 int macroNamePos() const;
270 void insert(char, MathTextCodes t);
271 /// can we enter the inset?
272 bool openable(MathAtom const &, bool selection) const;
273 /// can the setPos routine enter that inset?
274 bool positionable(MathAtom const &, int x, int y) const;
275 /// write access to cursor cell position
277 /// write access to cursor cell index
281 InsetFormulaBase * const formula_;
283 MathTextCodes lastcode_;
285 /// do we currently select
289 extern MathCursor * mathcursor;