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 *);
70 void insert(char, MathTextCodes t = LM_TC_MIN);
72 void insert(MathInset *);
74 void insert(MathArray const &);
84 bool right(bool sel = false);
86 bool left(bool sel = false);
88 bool up(bool sel = false);
90 bool down(bool sel = false);
91 /// Put the cursor in the first position
93 /// Put the cursor in the last position
95 /// moves cursor position one cell to the left
97 /// moves cursor position one cell to the right
99 /// moves cursor index one cell to the left
101 /// moves cursor index one cell to the right
103 /// moves position somehow up
105 /// moves position somehow down
114 void plainInsert(MathInset * p);
116 void niceInsert(MathInset * p);
119 /// This is in pixels from (maybe?) the top of inset
120 void setPos(int, int);
122 void getPos(int & x, int & y);
124 MathInset * par() const;
125 /// return the next enclosing grid inset and the cursor's index in it
126 MathArrayInset * enclosingArray(int &) const;
128 InsetFormulaBase const * formula();
136 void interpret(string const &);
138 void setSize(MathStyles);
142 // Macro mode methods
143 void macroModeOpen();
145 void macroModeClose();
147 bool inMacroMode() const;
149 // Local selection methods
151 bool selection() const;
161 void selHandle(bool);
167 void drawSelection(Painter & pain) const;
169 void handleFont(MathTextCodes t);
171 void handleAccent(string const & name);
173 void handleDelim(latexkeys const * l, latexkeys 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;
198 MathStyles style() const;
199 /// Make sure cursor position is valid
200 void normalize() const;
202 /// enter a MathInset from the front
203 void pushLeft(MathInset * par);
204 /// enter a MathInset from the back
205 void pushRight(MathInset * par);
206 /// leave current MathInset to the left
208 /// leave current MathInset to the left
212 MathArray & array() const;
214 MathXArray & xarray() const;
216 /// returns the selection
217 void getSelection(MathCursorPos &, MathCursorPos &) const;
218 /// returns the normalized anchor of the selection
219 MathCursorPos normalAnchor() const;
220 /// returns the normalized anchor of the selection
221 bool openable(MathInset *, bool selection, bool useupdown) const;
223 /// path of positions the cursor had to go if it were leving each inset
224 std::vector<MathCursorPos> Cursor_;
225 /// path of positions the anchor had to go if it were leving each inset
226 std::vector<MathCursorPos> Anchor_;
228 /// reference to the last item of the path
229 MathCursorPos & cursor();
231 MathCursorPos const & cursor() const;
237 MathInset * parInset(int i) const;
239 MathMatrixInset * outerPar() const;
241 void seldump(char const * str) const;
243 void dump(char const * str) const;
246 void merge(MathArray const & arr);
248 MathInset * nextInset() const;
250 MathInset * prevInset() const;
252 MathScriptInset * prevScriptInset() const;
254 MathSpaceInset * prevSpaceInset() const;
260 /// x-offset of current cell relative to par xo
261 int cellXOffset() const;
262 /// y-offset of current cell relative to par yo
263 int cellYOffset() const;
264 /// current x position relative to par xo
266 /// current y position relative to par yo
268 /// adjust position in current cell according to x. idx is not changed.
272 InsetFormulaBase * const formula_;
274 MathTextCodes lastcode_;
276 MathFuncInset * imacro_;
278 /// do we currently select
282 extern MathCursor * mathcursor;