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 &);
91 bool right(bool sel = false);
93 bool left(bool sel = false);
95 bool up(bool sel = false);
97 bool down(bool sel = false);
98 /// Put the cursor in the first position
100 /// Put the cursor in the last position
109 void plainInsert(MathInset * p);
112 /// This is in pixels from (maybe?) the top of inset
113 void setPos(int, int);
115 void getPos(int & x, int & y);
117 MathInset * par() const;
118 /// return the next enclosing grid inset and the cursor's index in it
119 MathArrayInset * enclosingArray(int &) const;
121 InsetFormulaBase const * formula();
127 void interpret(string const &);
129 void setSize(MathStyles);
133 // Macro mode methods
134 void macroModeOpen();
136 void macroModeClose();
138 bool inMacroMode() const;
140 // Local selection methods
142 bool selection() const;
152 void selHandle(bool);
158 void drawSelection(Painter & pain) const;
160 void clearLastCode();
162 void setLastCode(MathTextCodes t);
164 void handleFont(MathTextCodes t);
166 void handleAccent(string const & name);
168 void handleDelim(int l, int r);
169 /// Splits cells and shifts right part to the next cell
171 /// Splits line and insert new row of cell
174 MathTextCodes getLastCode() const;
180 void pullArg(bool goright);
182 bool isInside(MathInset const *) const;
184 MathTextCodes nextCode() const;
186 MathTextCodes prevCode() const;
197 MathStyles style() const;
198 /// Make sure cursor position is valid
199 void normalize() const;
201 /// enter a MathInset from the front
202 void pushLeft(MathInset * par);
203 /// enter a MathInset from the back
204 void pushRight(MathInset * par);
205 /// leave current MathInset to the left
207 /// leave current MathInset to the left
211 MathArray & array() const;
213 MathXArray & xarray() const;
215 /// returns the first position of the (normalized) selection
216 MathCursorPos firstSelectionPos() const;
217 /// returns the last position of the (normalized) selection
218 MathCursorPos lastSelectionPos() const;
219 /// returns the selection
220 void getSelection(MathCursorPos &, MathCursorPos &) const;
221 /// returns the normalized anchor of the selection
222 MathCursorPos normalAnchor() const;
223 /// returns the normalized anchor of the selection
224 bool openable(MathInset *, bool selection, bool useupdown) const;
226 /// path of positions the cursor had to go if it were leving each inset
227 std::vector<MathCursorPos> Cursor_;
228 /// path of positions the anchor had to go if it were leving each inset
229 std::vector<MathCursorPos> Anchor_;
231 /// reference to the last item of the path
232 MathCursorPos & cursor();
234 MathCursorPos const & cursor() const;
240 MathInset * parInset(int i) const;
242 MathMatrixInset * outerPar() const;
244 void seldump(char const * str) const;
246 void dump(char const * str) const;
254 void merge(MathArray const & arr);
256 MathInset * nextInset() const;
258 MathInset * prevInset() const;
260 MathScriptInset * prevScriptInset() const;
262 MathSpaceInset * prevSpaceInset() const;
270 InsetFormulaBase * const formula_;
272 MathTextCodes lastcode_;
274 MathFuncInset * imacro_;
276 /// do we currently select
280 extern MathCursor * mathcursor;