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, int);
115 void getPos(int & x, int & y);
117 MathAtom & par() const;
118 /// return the next enclosing grid inset and the cursor's index in it
119 MathGridInset * enclosingGrid(idx_type &) const;
121 InsetFormulaBase const * formula();
123 pos_type pos() const;
125 idx_type idx() const;
127 size_type size() const;
129 bool interpret(string const &);
131 bool interpret(char);
135 // Macro mode methods
136 void macroModeClose();
138 bool inMacroMode() const;
140 // Local selection methods
142 bool selection() const;
152 void selHandle(bool);
158 void selGet(MathArray & ar);
160 void drawSelection(Painter & pain) const;
162 void handleFont(MathTextCodes t);
164 void handleDelim(string const & l, string const & r);
166 void handleNest(MathInset * p);
167 /// Splits cells and shifts right part to the next cell
169 /// Splits line and insert new row of cell
171 /// read contents of line into an array
172 void readLine(MathArray & ar) const;
174 MathTextCodes getLastCode() const;
176 void pullArg(bool goright);
178 bool isInside(MathInset const *) const;
180 MathTextCodes nextCode() const;
186 col_type ncols() const;
188 col_type col() const;
190 row_type row() const;
192 /// Make sure cursor position is valid
193 void normalize() const;
195 UpdatableInset * asHyperActiveInset() const;
197 /// enter a MathInset
198 void push(MathAtom & par);
199 /// enter a MathInset from the front
200 void pushLeft(MathAtom & par);
201 /// enter a MathInset from the back
202 void pushRight(MathAtom & par);
203 /// leave current MathInset to the left
205 /// leave current MathInset to the left
209 MathArray & array() const;
211 MathXArray & xarray() const;
213 bool hasPrevAtom() const;
215 bool hasNextAtom() const;
217 MathAtom const & prevAtom() const;
219 MathAtom & prevAtom();
221 MathAtom const & nextAtom() const;
223 MathAtom & nextAtom();
225 /// returns the selection
226 void getSelection(MathCursorPos &, MathCursorPos &) const;
227 /// returns the normalized anchor of the selection
228 MathCursorPos normalAnchor() const;
230 /// path of positions the cursor had to go if it were leving each inset
231 std::vector<MathCursorPos> Cursor_;
232 /// path of positions the anchor had to go if it were leving each inset
233 std::vector<MathCursorPos> Anchor_;
235 /// reference to the last item of the path
236 MathCursorPos & cursor();
238 MathCursorPos const & cursor() const;
241 void seldump(char const * str) const;
243 void dump(char const * str) const;
245 void stripFromLastEqualSign();
248 friend class Selection;
251 /// moves cursor position one cell to the left
253 /// moves cursor position one cell to the right
255 /// moves cursor index one cell to the left
257 /// moves cursor index one cell to the right
259 /// moves position somehow up
261 /// moves position somehow down
265 string macroName() const;
267 int macroNamePos() const;
269 void insert(char, MathTextCodes t);
270 /// can we enter the inset?
271 bool openable(MathAtom const &, bool selection) const;
272 /// can the setPos routine enter that inset?
273 bool positionable(MathAtom const &, int x, int y) const;
274 /// write access to cursor cell position
276 /// write access to cursor cell index
280 InsetFormulaBase * const formula_;
282 MathTextCodes lastcode_;
284 /// do we currently select
288 extern MathCursor * mathcursor;