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(MathInset *);
72 void insert(MathArray const &);
82 bool right(bool sel = false);
84 bool left(bool sel = false);
86 bool up(bool sel = false);
88 bool down(bool sel = false);
89 /// Put the cursor in the first position
91 /// Put the cursor in the last position
93 /// moves cursor position one cell to the left
95 /// moves cursor position one cell to the right
97 /// moves cursor index one cell to the left
99 /// moves cursor index one cell to the right
101 /// moves position somehow up
103 /// moves position somehow down
112 void plainInsert(MathInset * p);
114 void niceInsert(MathInset * p);
117 /// This is in pixels from (maybe?) the top of inset
118 void setPos(int, int);
120 void getPos(int & x, int & y);
122 MathInset * par() const;
123 /// return the next enclosing grid inset and the cursor's index in it
124 MathArrayInset * enclosingArray(int &) const;
126 InsetFormulaBase const * formula();
134 void interpret(string const &);
136 void setSize(MathStyles);
140 // Macro mode methods
141 void macroModeClose();
143 bool inMacroMode() const;
145 // Local selection methods
147 bool selection() const;
157 void selHandle(bool);
163 void drawSelection(Painter & pain) const;
165 void handleFont(MathTextCodes t);
167 void handleAccent(string const & name);
169 void handleDelim(latexkeys const * l, latexkeys const * r);
171 void handleNest(MathInset * p);
172 /// Splits cells and shifts right part to the next cell
174 /// Splits line and insert new row of cell
177 MathTextCodes getLastCode() const;
179 void pullArg(bool goright);
181 bool isInside(MathInset const *) const;
183 MathTextCodes nextCode() const;
194 MathStyles style() const;
195 /// Make sure cursor position is valid
196 void normalize() const;
198 /// enter a MathInset from the front
199 void pushLeft(MathInset * par);
200 /// enter a MathInset from the back
201 void pushRight(MathInset * par);
202 /// leave current MathInset to the left
204 /// leave current MathInset to the left
208 MathArray & array() const;
210 MathXArray & xarray() const;
212 /// returns the selection
213 void getSelection(MathCursorPos &, MathCursorPos &) const;
214 /// returns the normalized anchor of the selection
215 MathCursorPos normalAnchor() const;
216 /// returns the normalized anchor of the selection
217 bool openable(MathInset *, bool selection, bool useupdown) const;
219 /// path of positions the cursor had to go if it were leving each inset
220 std::vector<MathCursorPos> Cursor_;
221 /// path of positions the anchor had to go if it were leving each inset
222 std::vector<MathCursorPos> Anchor_;
224 /// reference to the last item of the path
225 MathCursorPos & cursor();
227 MathCursorPos const & cursor() const;
233 MathInset * parInset(int i) const;
235 MathMatrixInset * outerPar() const;
237 void seldump(char const * str) const;
239 void dump(char const * str) const;
242 void merge(MathArray const & arr);
244 MathInset * nextInset() const;
246 MathInset * prevInset() const;
248 MathScriptInset * prevScriptInset() const;
250 MathSpaceInset * prevSpaceInset() const;
253 string macroName() const;
255 void insert(char, MathTextCodes t = LM_TC_MIN);
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 /// do we currently select
280 extern MathCursor * mathcursor;