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;
37 /// Description of a position
38 struct MathCursorPos {
45 /// returns cell corresponding to this position
46 MathArray & cell() const;
47 /// returns cell corresponding to this position
48 MathArray & cell(int idx) const;
49 /// returns xcell corresponding to this position
50 MathXArray & xcell() const;
51 /// returns xcell corresponding to this position
52 MathXArray & xcell(int idx) const;
53 /// moves position on cell to the left
55 /// moves position on cell to the right
57 /// moves position on cell up
59 /// moves position on cell up
64 bool operator==(MathCursorPos const &, MathCursorPos const &);
66 bool operator<(MathCursorPos const &, MathCursorPos const &);
69 /// This is the external interface of Math's subkernel
73 explicit MathCursor(InsetFormulaBase *);
77 void insert(char, MathTextCodes t = LM_TC_MIN);
79 void insert(MathInset *);
81 void insert(MathArray const &);
89 bool right(bool sel = false);
91 bool left(bool sel = false);
93 bool up(bool sel = false);
95 bool down(bool sel = false);
96 /// Put the cursor in the first position
98 /// Put the cursor in the last position
107 void plainInsert(MathInset * p);
110 /// This is in pixels from (maybe?) the top of inset
111 void setPos(int, int);
113 void getPos(int & x, int & y);
115 MathInset * par() const;
116 /// return the next enclosing grid inset and the cursor's index in it
117 MathArrayInset * enclosingArray(int &) const;
119 InsetFormulaBase const * formula();
123 void interpret(string const &);
125 void setSize(MathStyles);
129 // Macro mode methods
130 void macroModeOpen();
132 void macroModeClose();
134 bool inMacroMode() const;
136 // Local selection methods
138 bool selection() const;
148 void selHandle(bool);
154 void drawSelection(Painter & pain) const;
156 void clearLastCode();
158 void setLastCode(MathTextCodes t);
160 void handleFont(MathTextCodes t);
162 void handleAccent(string const & name);
164 void handleDelim(int l, int r);
165 /// Splits cells and shifts right part to the next cell
167 /// Splits line and insert new row of cell
170 MathTextCodes getLastCode() const;
172 int idx() const { return cursor().idx_; }
178 void pullArg(bool goright);
180 bool isInside(MathInset const *) const;
182 MathTextCodes nextCode() const;
184 MathTextCodes prevCode() const;
195 MathStyles style() const;
196 /// Make sure cursor position is valid
197 void normalize() const;
199 /// Enter a new MathInset from the front or the back
200 void push(MathInset * par, bool first);
201 /// Leave current MathInset
206 InsetFormulaBase * const formula_;
208 MathTextCodes lastcode_;
210 MathFuncInset * imacro_;
212 /// do we currently select
216 MathArray & array() const;
218 MathXArray & xarray() const;
220 /// returns the first position of the (normalized) selection
221 MathCursorPos firstSelectionPos() const;
222 /// returns the last position of the (normalized) selection
223 MathCursorPos lastSelectionPos() const;
224 /// returns the selection
225 void getSelection(MathCursorPos &, MathCursorPos &) const;
226 /// returns the normalized anchor of the selection
227 MathCursorPos normalAnchor() const;
228 /// returns the normalized anchor of the selection
229 bool openable(MathInset *, bool selection, bool useupdown) const;
231 /// path of positions the cursor had to go if it were leving each inset
232 std::vector<MathCursorPos> Cursor_;
233 /// path of positions the anchor had to go if it were leving each inset
234 std::vector<MathCursorPos> Anchor_;
236 /// reference to the last item of the path
237 MathCursorPos & cursor();
239 MathCursorPos const & cursor() const;
245 MathInset * parInset(int i) const;
247 MathMatrixInset * outerPar() const;
249 void seldump(char const * str) const;
251 void dump(char const * str) const;
259 void merge(MathArray const & arr);
261 MathInset * nextInset() const;
263 MathInset * prevInset() const;
265 MathScriptInset * prevScriptInset() const;
267 MathSpaceInset * prevSpaceInset() const;
270 extern MathCursor * mathcursor;