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"
30 class MathMatrixInset;
31 class MathScriptInset;
33 class InsetFormulaBase;
39 /// Description of a position
40 struct MathCursorPos {
47 /// returns cell corresponding to this position
48 MathArray & cell() const;
49 /// returns cell corresponding to this position
50 MathArray & cell(int idx) const;
51 /// returns xcell corresponding to this position
52 MathXArray & xcell() const;
53 /// returns xcell corresponding to this position
54 MathXArray & xcell(int idx) const;
58 bool operator==(MathCursorPos const &, MathCursorPos const &);
60 bool operator<(MathCursorPos const &, MathCursorPos const &);
63 /// This is the external interface of Math's subkernel
67 explicit MathCursor(InsetFormulaBase *);
69 void insert(MathInset *);
71 void insert(MathArray const &);
77 void home(bool sel = false);
79 void end(bool sel = false);
81 bool right(bool sel = false);
83 bool left(bool sel = false);
85 bool up(bool sel = false);
87 bool down(bool sel = false);
88 /// Put the cursor in the first position
90 /// Put the cursor in the last position
92 /// moves cursor position one cell to the left
94 /// moves cursor position one cell to the right
96 /// moves cursor index one cell to the left
98 /// moves cursor index one cell to the right
100 /// moves position somehow up
102 /// moves position somehow down
111 void plainInsert(MathInset * p);
113 void niceInsert(MathInset * p);
116 /// This is in pixels from (maybe?) the top of inset
117 void setPos(int, int);
119 void getPos(int & x, int & y);
121 MathInset * par() const;
122 /// return the next enclosing grid inset and the cursor's index in it
123 MathArrayInset * enclosingArray(int &) const;
125 InsetFormulaBase const * formula();
133 void interpret(string const &);
135 void setSize(MathStyles);
139 // Macro mode methods
140 void macroModeClose();
142 bool inMacroMode() const;
144 // Local selection methods
146 bool selection() const;
156 void selHandle(bool);
162 void drawSelection(Painter & pain) const;
164 void handleFont(MathTextCodes t);
166 void handleDelim(string const & l, string const & r);
168 void handleNest(MathInset * p);
169 /// Splits cells and shifts right part to the next cell
171 /// Splits line and insert new row of cell
174 MathTextCodes getLastCode() const;
176 void pullArg(bool goright);
178 bool isInside(MathInset const *) const;
180 MathTextCodes nextCode() const;
191 MathStyles style() const;
192 /// Make sure cursor position is valid
193 void normalize() const;
195 /// enter a MathInset from the front
196 void pushLeft(MathInset * par);
197 /// enter a MathInset from the back
198 void pushRight(MathInset * par);
199 /// leave current MathInset to the left
201 /// leave current MathInset to the left
205 MathArray & array() const;
207 MathXArray & xarray() const;
209 MathAtom const * prevAtom() const;
211 MathAtom * prevAtom();
213 MathAtom const * nextAtom() const;
215 MathAtom * nextAtom();
217 /// returns the selection
218 void getSelection(MathCursorPos &, MathCursorPos &) const;
219 /// returns the normalized anchor of the selection
220 MathCursorPos normalAnchor() const;
222 /// path of positions the cursor had to go if it were leving each inset
223 std::vector<MathCursorPos> Cursor_;
224 /// path of positions the anchor had to go if it were leving each inset
225 std::vector<MathCursorPos> Anchor_;
227 /// reference to the last item of the path
228 MathCursorPos & cursor();
230 MathCursorPos const & cursor() const;
236 MathInset * parInset(int i) const;
238 MathMatrixInset * outerPar() const;
240 void seldump(char const * str) const;
242 void dump(char const * str) const;
245 void merge(MathArray const & arr);
247 MathInset * nextInset() const;
249 MathInset * prevInset() const;
251 MathScriptInset * prevScriptInset() const;
253 MathSpaceInset * prevSpaceInset() const;
256 string macroName() const;
258 void insert(char, MathTextCodes t = LM_TC_MIN);
259 /// can we enter the inset?
260 bool openable(MathInset *, bool selection) const;
261 /// can the setPos routine enter that inset?
262 MathInset * positionable(MathAtom *, int x, int y) const;
263 /// write access to cursor cell position
265 /// write access to cursor cell index
267 /// x-offset of current cell relative to par xo
268 int cellXOffset() const;
269 /// y-offset of current cell relative to par yo
270 int cellYOffset() const;
271 /// current x position relative to par xo
273 /// current y position relative to par yo
275 /// adjust position in current cell according to x. idx is not changed.
279 InsetFormulaBase * const formula_;
281 MathTextCodes lastcode_;
283 /// do we currently select
287 extern MathCursor * mathcursor;