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"
29 class MathMatrixInset;
30 class MathScriptInset;
32 class InsetFormulaBase;
38 /// Description of a position
39 struct MathCursorPos {
46 /// returns cell corresponding to this position
47 MathArray & cell() const;
48 /// returns cell corresponding to this position
49 MathArray & cell(int idx) const;
50 /// returns xcell corresponding to this position
51 MathXArray & xcell() const;
52 /// returns xcell corresponding to this position
53 MathXArray & xcell(int idx) const;
57 bool operator==(MathCursorPos const &, MathCursorPos const &);
59 bool operator<(MathCursorPos const &, MathCursorPos const &);
62 /// This is the external interface of Math's subkernel
66 explicit MathCursor(InsetFormulaBase *);
68 void insert(MathInset *);
70 void insert(MathArray const &);
80 bool right(bool sel = false);
82 bool left(bool sel = false);
84 bool up(bool sel = false);
86 bool down(bool sel = false);
87 /// Put the cursor in the first position
89 /// Put the cursor in the last position
91 /// moves cursor position one cell to the left
93 /// moves cursor position one cell to the right
95 /// moves cursor index one cell to the left
97 /// moves cursor index one cell to the right
99 /// moves position somehow up
101 /// moves position somehow down
110 void plainInsert(MathInset * p);
112 void niceInsert(MathInset * p);
115 /// This is in pixels from (maybe?) the top of inset
116 void setPos(int, int);
118 void getPos(int & x, int & y);
120 MathInset * par() const;
121 /// return the next enclosing grid inset and the cursor's index in it
122 MathArrayInset * enclosingArray(int &) const;
124 InsetFormulaBase const * formula();
132 void interpret(string const &);
134 void setSize(MathStyles);
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 drawSelection(Painter & pain) const;
163 void handleFont(MathTextCodes t);
165 void handleDelim(latexkeys const * l, latexkeys const * r);
167 void handleNest(MathInset * p);
168 /// Splits cells and shifts right part to the next cell
170 /// Splits line and insert new row of cell
173 MathTextCodes getLastCode() const;
175 void pullArg(bool goright);
177 bool isInside(MathInset const *) const;
179 MathTextCodes nextCode() const;
190 MathStyles style() const;
191 /// Make sure cursor position is valid
192 void normalize() const;
194 /// enter a MathInset from the front
195 void pushLeft(MathInset * par);
196 /// enter a MathInset from the back
197 void pushRight(MathInset * par);
198 /// leave current MathInset to the left
200 /// leave current MathInset to the left
204 MathArray & array() const;
206 MathXArray & xarray() const;
208 /// returns the selection
209 void getSelection(MathCursorPos &, MathCursorPos &) const;
210 /// returns the normalized anchor of the selection
211 MathCursorPos normalAnchor() const;
212 /// returns the normalized anchor of the selection
213 bool openable(MathInset *, bool selection, bool useupdown) const;
215 /// path of positions the cursor had to go if it were leving each inset
216 std::vector<MathCursorPos> Cursor_;
217 /// path of positions the anchor had to go if it were leving each inset
218 std::vector<MathCursorPos> Anchor_;
220 /// reference to the last item of the path
221 MathCursorPos & cursor();
223 MathCursorPos const & cursor() const;
229 MathInset * parInset(int i) const;
231 MathMatrixInset * outerPar() const;
233 void seldump(char const * str) const;
235 void dump(char const * str) const;
238 void merge(MathArray const & arr);
240 MathInset * nextInset() const;
242 MathInset * prevInset() const;
244 MathScriptInset * prevScriptInset() const;
246 MathSpaceInset * prevSpaceInset() const;
249 string macroName() const;
251 void insert(char, MathTextCodes t = LM_TC_MIN);
256 /// x-offset of current cell relative to par xo
257 int cellXOffset() const;
258 /// y-offset of current cell relative to par yo
259 int cellYOffset() const;
260 /// current x position relative to par xo
262 /// current y position relative to par yo
264 /// adjust position in current cell according to x. idx is not changed.
268 InsetFormulaBase * const formula_;
270 MathTextCodes lastcode_;
272 /// do we currently select
276 extern MathCursor * mathcursor;