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;
56 bool operator==(MathCursorPos const &, MathCursorPos const &);
58 bool operator<(MathCursorPos const &, MathCursorPos const &);
61 /// This is the external interface of Math's subkernel
65 explicit MathCursor(InsetFormulaBase *);
69 void insert(char, MathTextCodes t = LM_TC_MIN);
71 void insert(MathInset *);
73 void insert(MathArray const &);
83 bool right(bool sel = false);
85 bool left(bool sel = false);
87 bool up(bool sel = false);
89 bool down(bool sel = false);
90 /// Put the cursor in the first position
92 /// Put the cursor in the last position
98 /// moves position one cell to the left
100 /// moves position one cell to the right
102 /// moves position one cell up
104 /// moves position one cell down
113 void plainInsert(MathInset * p);
116 /// This is in pixels from (maybe?) the top of inset
117 void setPos(int, int);
119 void getPos(int & x, int & y);
121 MathInset * par() const;
122 /// return the next enclosing grid inset and the cursor's index in it
123 MathArrayInset * enclosingArray(int &) const;
125 InsetFormulaBase const * formula();
133 void interpret(string const &);
135 void setSize(MathStyles);
139 // Macro mode methods
140 void macroModeOpen();
142 void macroModeClose();
144 bool inMacroMode() const;
146 // Local selection methods
148 bool selection() const;
158 void selHandle(bool);
164 void drawSelection(Painter & pain) const;
166 void clearLastCode();
168 void setLastCode(MathTextCodes t);
170 void handleFont(MathTextCodes t);
172 void handleAccent(string const & name);
174 void handleDelim(int l, int r);
176 void handleNest(MathInset * p);
177 /// Splits cells and shifts right part to the next cell
179 /// Splits line and insert new row of cell
182 MathTextCodes getLastCode() const;
184 void pullArg(bool goright);
186 bool isInside(MathInset const *) const;
188 MathTextCodes nextCode() const;
190 MathTextCodes prevCode() const;
201 MathStyles style() const;
202 /// Make sure cursor position is valid
203 void normalize() const;
205 /// enter a MathInset from the front
206 void pushLeft(MathInset * par);
207 /// enter a MathInset from the back
208 void pushRight(MathInset * par);
209 /// leave current MathInset to the left
211 /// leave current MathInset to the left
215 MathArray & array() const;
217 MathXArray & xarray() const;
219 /// returns the first position of the (normalized) selection
220 MathCursorPos firstSelectionPos() const;
221 /// returns the last position of the (normalized) selection
222 MathCursorPos lastSelectionPos() const;
223 /// returns the selection
224 void getSelection(MathCursorPos &, MathCursorPos &) const;
225 /// returns the normalized anchor of the selection
226 MathCursorPos normalAnchor() const;
227 /// returns the normalized anchor of the selection
228 bool openable(MathInset *, bool selection, bool useupdown) const;
230 /// path of positions the cursor had to go if it were leving each inset
231 std::vector<MathCursorPos> Cursor_;
232 /// path of positions the anchor had to go if it were leving each inset
233 std::vector<MathCursorPos> Anchor_;
235 /// reference to the last item of the path
236 MathCursorPos & cursor();
238 MathCursorPos const & cursor() const;
244 MathInset * parInset(int i) const;
246 MathMatrixInset * outerPar() const;
248 void seldump(char const * str) const;
250 void dump(char const * str) const;
258 void merge(MathArray const & arr);
260 MathInset * nextInset() const;
262 MathInset * prevInset() const;
264 MathScriptInset * prevScriptInset() const;
266 MathSpaceInset * prevSpaceInset() const;
274 InsetFormulaBase * const formula_;
276 MathTextCodes lastcode_;
278 MathFuncInset * imacro_;
280 /// do we currently select
284 extern MathCursor * mathcursor;