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;
41 /// Description of a position
42 struct MathCursorPos {
46 MathInset::idx_type idx_;
48 MathInset::pos_type pos_;
50 /// returns cell corresponding to this position
51 MathArray & cell() const;
52 /// returns cell corresponding to this position
53 MathArray & cell(MathInset::idx_type idx) const;
54 /// returns xcell corresponding to this position
55 MathXArray & xcell() const;
56 /// returns xcell corresponding to this position
57 MathXArray & xcell(MathInset::idx_type idx) const;
61 bool operator==(MathCursorPos const &, MathCursorPos const &);
63 bool operator<(MathCursorPos const &, MathCursorPos const &);
66 /// This is the external interface of Math's subkernel
69 /// short of anything else reasonable
70 typedef MathInset::size_type size_type;
71 /// type for cursor positions within a cell
72 typedef MathInset::pos_type pos_type;
73 /// type for cell indices
74 typedef MathInset::idx_type idx_type;
75 /// type for row numbers
76 typedef MathInset::row_type row_type;
77 /// type for column numbers
78 typedef MathInset::col_type col_type;
81 explicit MathCursor(InsetFormulaBase *, bool left);
83 void insert(MathAtom const &);
85 void insert(MathArray const &);
87 void paste(MathArray const &);
93 void home(bool sel = false);
95 void end(bool sel = false);
97 bool right(bool sel = false);
99 bool left(bool sel = false);
101 bool up(bool sel = false);
103 bool down(bool sel = false);
104 /// Put the cursor in the first position
106 /// Put the cursor in the last position
115 void plainInsert(MathAtom const &);
117 void niceInsert(MathAtom const &);
121 /// This is in pixels from (maybe?) the top of inset
122 void setPos(int, int);
124 void getPos(int & x, int & y);
126 MathAtom & par() const;
127 /// return the next enclosing grid inset and the cursor's index in it
128 MathArrayInset * enclosingArray(idx_type &) const;
130 InsetFormulaBase const * formula();
132 pos_type pos() const;
134 idx_type idx() const;
136 size_type size() const;
138 void interpret(string const &);
140 void interpret(char);
142 void setSize(MathStyles);
146 // Macro mode methods
147 void macroModeClose();
149 bool inMacroMode() const;
151 // Local selection methods
153 bool selection() const;
163 void selHandle(bool);
169 void drawSelection(Painter & pain) const;
171 void handleFont(MathTextCodes t);
173 void handleDelim(string const & l, string const & r);
175 void handleNest(MathInset * p);
176 /// Splits cells and shifts right part to the next cell
178 /// Splits line and insert new row of cell
181 MathTextCodes getLastCode() const;
183 void pullArg(bool goright);
185 bool isInside(MathInset const *) const;
187 MathTextCodes nextCode() const;
193 col_type col() const;
195 row_type row() const;
198 MathStyles style() const;
199 /// Make sure cursor position is valid
200 void normalize() const;
202 /// enter a MathInset
203 void push(MathAtom & par);
204 /// enter a MathInset from the front
205 void pushLeft(MathAtom & par);
206 /// enter a MathInset from the back
207 void pushRight(MathAtom & par);
208 /// leave current MathInset to the left
210 /// leave current MathInset to the left
214 MathArray & array() const;
216 MathXArray & xarray() const;
218 bool hasPrevAtom() const;
220 bool hasNextAtom() const;
222 MathAtom const & prevAtom() const;
224 MathAtom & prevAtom();
226 MathAtom const & nextAtom() const;
228 MathAtom & nextAtom();
230 /// returns the selection
231 void getSelection(MathCursorPos &, MathCursorPos &) const;
232 /// returns the normalized anchor of the selection
233 MathCursorPos normalAnchor() const;
235 /// path of positions the cursor had to go if it were leving each inset
236 std::vector<MathCursorPos> Cursor_;
237 /// path of positions the anchor had to go if it were leving each inset
238 std::vector<MathCursorPos> Anchor_;
240 /// reference to the last item of the path
241 MathCursorPos & cursor();
243 MathCursorPos const & cursor() const;
246 void seldump(char const * str) const;
248 void dump(char const * str) const;
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
268 string macroName() const;
270 int macroNamePos() const;
272 void insert(char, MathTextCodes t);
273 /// can we enter the inset?
274 bool openable(MathAtom const &, bool selection) const;
275 /// can the setPos routine enter that inset?
276 bool positionable(MathAtom const &, int x, int y) const;
277 /// write access to cursor cell position
279 /// write access to cursor cell index
281 /// x-offset of current cell relative to par xo
282 int cellXOffset() const;
283 /// y-offset of current cell relative to par yo
284 int cellYOffset() const;
285 /// current x position relative to par xo
287 /// current y position relative to par yo
289 /// adjust position in current cell according to x. idx is not changed.
293 InsetFormulaBase * const formula_;
295 MathTextCodes lastcode_;
297 /// do we currently select
301 extern MathCursor * mathcursor;