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;
70 /// how to store a cursor
71 typedef std::vector<MathCursorPos> cursor_type;
74 explicit MathCursor(InsetFormulaBase *, bool left);
76 void insert(MathAtom const &);
78 void insert(MathArray const &);
80 void paste(MathArray const &);
86 void home(bool sel = false);
88 void end(bool sel = false);
90 bool right(bool sel = false);
92 bool left(bool sel = false);
94 bool up(bool sel = false);
96 bool down(bool sel = false);
97 /// Put the cursor in the first position
99 /// Put the cursor in the last position
108 void plainInsert(MathAtom const &);
110 void niceInsert(MathAtom const &);
114 /// This is in pixels from (maybe?) the top of inset
115 void setPos(int x, int y);
116 /// This is in pixels from (maybe?) the top of inset, don't move further
118 void getPos(int & x, int & y);
120 MathAtom & par() const;
121 /// return the next enclosing grid inset and the cursor's index in it
122 MathGridInset * enclosingGrid(idx_type &) const;
124 InsetFormulaBase const * formula();
126 pos_type pos() const;
128 idx_type idx() const;
130 size_type size() const;
132 bool interpret(string const &);
134 bool interpret(char);
138 // Macro mode methods
139 void macroModeClose();
141 bool inMacroMode() const;
143 // Local selection methods
145 bool selection() const;
155 void selHandle(bool);
161 void selGet(MathArray & ar);
163 void drawSelection(Painter & pain) const;
165 void handleFont(MathTextCodes t);
167 void handleDelim(string const & l, string const & r);
169 void handleNest(MathInset * p);
170 /// Splits cells and shifts right part to the next cell
172 /// Splits line and insert new row of cell
174 /// read contents of line into an array
175 void readLine(MathArray & ar) const;
177 MathTextCodes getLastCode() const;
179 void pullArg(bool goright);
181 bool isInside(MathInset const *) const;
183 MathTextCodes nextCode() const;
189 col_type ncols() const;
191 col_type col() const;
193 row_type row() const;
195 /// Make sure cursor position is valid
196 void normalize() const;
198 UpdatableInset * asHyperActiveInset() const;
200 /// enter a MathInset
201 void push(MathAtom & par);
202 /// enter a MathInset from the front
203 void pushLeft(MathAtom & par);
204 /// enter a MathInset from the back
205 void pushRight(MathAtom & par);
206 /// leave current MathInset to the left
208 /// leave current MathInset to the left
212 MathArray & array() const;
214 MathXArray & xarray() const;
216 bool hasPrevAtom() const;
218 bool hasNextAtom() 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
235 /// path of positions the anchor had to go if it were leving each inset
238 /// reference to the last item of the path
239 MathCursorPos & cursor();
241 MathCursorPos const & cursor() const;
244 void seldump(char const * str) const;
246 void dump(char const * str) const;
248 void stripFromLastEqualSign();
251 friend class Selection;
254 /// moves cursor position one cell to the left
256 /// moves cursor position one cell to the right
258 /// moves cursor index one cell to the left
260 /// moves cursor index one cell to the right
262 /// moves position somehow up
264 /// moves position somehow down
266 /// moves position somehow down
267 bool bruteUpDown(int ylow, int yhigh);
270 string macroName() const;
272 int macroNamePos() const;
274 void insert(char, MathTextCodes t);
275 /// can we enter the inset?
276 bool openable(MathAtom const &, bool selection) const;
277 /// can the setPos routine enter that inset?
278 bool positionable(MathAtom const &, int x, int y) const;
279 /// write access to cursor cell position
281 /// write access to cursor cell index
285 InsetFormulaBase * const formula_;
287 MathTextCodes lastcode_;
289 /// do we currently select
293 extern MathCursor * mathcursor;