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);
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 macroModeOpen();
143 void macroModeClose();
145 bool inMacroMode() const;
147 // Local selection methods
149 bool selection() const;
159 void selHandle(bool);
165 void drawSelection(Painter & pain) const;
167 void clearLastCode();
169 void setLastCode(MathTextCodes t);
171 void handleFont(MathTextCodes t);
173 void handleAccent(string const & name);
175 void handleDelim(latexkeys const * l, latexkeys const * r);
177 void handleNest(MathInset * p);
178 /// Splits cells and shifts right part to the next cell
180 /// Splits line and insert new row of cell
183 MathTextCodes getLastCode() const;
185 void pullArg(bool goright);
187 bool isInside(MathInset const *) const;
189 MathTextCodes nextCode() const;
200 MathStyles style() const;
201 /// Make sure cursor position is valid
202 void normalize() const;
204 /// enter a MathInset from the front
205 void pushLeft(MathInset * par);
206 /// enter a MathInset from the back
207 void pushRight(MathInset * par);
208 /// leave current MathInset to the left
210 /// leave current MathInset to the left
214 MathArray & array() const;
216 MathXArray & xarray() const;
218 /// returns the selection
219 void getSelection(MathCursorPos &, MathCursorPos &) const;
220 /// returns the normalized anchor of the selection
221 MathCursorPos normalAnchor() const;
222 /// returns the normalized anchor of the selection
223 bool openable(MathInset *, bool selection, bool useupdown) const;
225 /// path of positions the cursor had to go if it were leving each inset
226 std::vector<MathCursorPos> Cursor_;
227 /// path of positions the anchor had to go if it were leving each inset
228 std::vector<MathCursorPos> Anchor_;
230 /// reference to the last item of the path
231 MathCursorPos & cursor();
233 MathCursorPos const & cursor() const;
239 MathInset * parInset(int i) const;
241 MathMatrixInset * outerPar() const;
243 void seldump(char const * str) const;
245 void dump(char const * str) const;
248 void merge(MathArray const & arr);
250 MathInset * nextInset() const;
252 MathInset * prevInset() const;
254 MathScriptInset * prevScriptInset() const;
256 MathSpaceInset * prevSpaceInset() const;
262 /// x-offset of current cell relative to par xo
263 int cellXOffset() const;
264 /// y-offset of current cell relative to par yo
265 int cellYOffset() const;
266 /// current x position relative to par xo
268 /// current y position relative to par yo
270 /// adjust position in current cell according to x. idx is not changed.
274 InsetFormulaBase * const formula_;
276 MathTextCodes lastcode_;
278 MathFuncInset * imacro_;
280 /// do we currently select
284 extern MathCursor * mathcursor;