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;
40 /// Description of a position
41 struct MathCursorPos {
45 MathInset::idx_type idx_;
47 MathInset::pos_type pos_;
48 /// returns cell corresponding to this position
49 MathArray & cell() const;
50 /// returns cell corresponding to this position
51 MathArray & cell(MathInset::idx_type idx) const;
52 /// returns xcell corresponding to this position
53 MathXArray & xcell() const;
54 /// returns xcell corresponding to this position
55 MathXArray & xcell(MathInset::idx_type idx) const;
59 bool operator==(MathCursorPos const &, MathCursorPos const &);
61 bool operator<(MathCursorPos const &, MathCursorPos const &);
64 /// This is the external interface of Math's subkernel
67 /// short of anything else reasonable
68 typedef MathInset::size_type size_type;
69 /// type for cursor positions within a cell
70 typedef MathInset::pos_type pos_type;
71 /// type for cell indices
72 typedef MathInset::idx_type idx_type;
73 /// type for row numbers
74 typedef MathInset::row_type row_type;
75 /// type for column numbers
76 typedef MathInset::col_type col_type;
79 explicit MathCursor(InsetFormulaBase *);
81 void insert(MathInset *);
83 void insert(MathArray const &);
89 void home(bool sel = false);
91 void end(bool sel = false);
93 bool right(bool sel = false);
95 bool left(bool sel = false);
97 bool up(bool sel = false);
99 bool down(bool sel = false);
100 /// Put the cursor in the first position
102 /// Put the cursor in the last position
104 /// moves cursor position one cell to the left
106 /// moves cursor position one cell to the right
108 /// moves cursor index one cell to the left
110 /// moves cursor index one cell to the right
112 /// moves position somehow up
114 /// moves position somehow down
123 void plainInsert(MathInset * p);
125 void niceInsert(MathInset * p);
128 /// This is in pixels from (maybe?) the top of inset
129 void setPos(int, int);
131 void getPos(int & x, int & y);
133 MathInset * par() const;
134 /// return the next enclosing grid inset and the cursor's index in it
135 MathArrayInset * enclosingArray(idx_type &) const;
137 InsetFormulaBase const * formula();
139 pos_type pos() const;
141 idx_type idx() const;
143 size_type size() const;
145 void interpret(string const &);
147 void setSize(MathStyles);
151 // Macro mode methods
152 void macroModeClose();
154 bool inMacroMode() const;
156 // Local selection methods
158 bool selection() const;
168 void selHandle(bool);
174 void drawSelection(Painter & pain) const;
176 void handleFont(MathTextCodes t);
178 void handleDelim(string const & l, string const & r);
180 void handleNest(MathInset * p);
181 /// Splits cells and shifts right part to the next cell
183 /// Splits line and insert new row of cell
186 MathTextCodes getLastCode() const;
188 void pullArg(bool goright);
190 bool isInside(MathInset const *) const;
192 MathTextCodes nextCode() const;
198 col_type col() const;
200 row_type row() const;
203 MathStyles style() const;
204 /// Make sure cursor position is valid
205 void normalize() const;
207 /// enter a MathInset from the front
208 void pushLeft(MathInset * par);
209 /// enter a MathInset from the back
210 void pushRight(MathInset * par);
211 /// leave current MathInset to the left
213 /// leave current MathInset to the left
217 MathArray & array() const;
219 MathXArray & xarray() const;
221 MathAtom const * prevAtom() const;
223 MathAtom * prevAtom();
225 MathAtom const * nextAtom() const;
227 MathAtom * nextAtom();
229 /// returns the selection
230 void getSelection(MathCursorPos &, MathCursorPos &) const;
231 /// returns the normalized anchor of the selection
232 MathCursorPos normalAnchor() const;
234 /// path of positions the cursor had to go if it were leving each inset
235 std::vector<MathCursorPos> Cursor_;
236 /// path of positions the anchor had to go if it were leving each inset
237 std::vector<MathCursorPos> Anchor_;
239 /// reference to the last item of the path
240 MathCursorPos & cursor();
242 MathCursorPos const & cursor() const;
246 pos_type last() const;
248 MathInset * parInset(int i) const;
250 MathMatrixInset * outerPar() const;
252 void seldump(char const * str) const;
254 void dump(char const * str) const;
257 void merge(MathArray const & arr);
259 MathInset * nextInset() const;
261 MathInset * prevInset() const;
263 MathScriptInset * prevScriptInset() const;
265 MathSpaceInset * prevSpaceInset() const;
268 string macroName() const;
270 void insert(char, MathTextCodes t = LM_TC_MIN);
271 /// can we enter the inset?
272 bool openable(MathInset *, bool selection) const;
273 /// can the setPos routine enter that inset?
274 MathInset * positionable(MathAtom *, int x, int y) const;
275 /// write access to cursor cell position
277 /// write access to cursor cell index
279 /// x-offset of current cell relative to par xo
280 int cellXOffset() const;
281 /// y-offset of current cell relative to par yo
282 int cellYOffset() const;
283 /// current x position relative to par xo
285 /// current y position relative to par yo
287 /// adjust position in current cell according to x. idx is not changed.
291 InsetFormulaBase * const formula_;
293 MathTextCodes lastcode_;
295 /// do we currently select
299 extern MathCursor * mathcursor;