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 new MathInset from the front or the back
202 void push(MathInset * par, bool first);
203 /// Leave current MathInset
208 InsetFormulaBase * const formula_;
210 MathTextCodes lastcode_;
212 MathFuncInset * imacro_;
214 /// do we currently select
218 MathArray & array() const;
220 MathXArray & xarray() const;
222 /// returns the first position of the (normalized) selection
223 MathCursorPos firstSelectionPos() const;
224 /// returns the last position of the (normalized) selection
225 MathCursorPos lastSelectionPos() const;
226 /// returns the selection
227 void getSelection(MathCursorPos &, MathCursorPos &) const;
228 /// returns the normalized anchor of the selection
229 MathCursorPos normalAnchor() const;
230 /// returns the normalized anchor of the selection
231 bool openable(MathInset *, bool selection, bool useupdown) const;
233 /// path of positions the cursor had to go if it were leving each inset
234 std::vector<MathCursorPos> Cursor_;
235 /// path of positions the anchor had to go if it were leving each inset
236 std::vector<MathCursorPos> Anchor_;
238 /// reference to the last item of the path
239 MathCursorPos & cursor();
241 MathCursorPos const & cursor() const;
247 MathInset * parInset(int i) const;
249 MathMatrixInset * outerPar() const;
251 void seldump(char const * str) const;
253 void dump(char const * str) const;
261 void merge(MathArray const & arr);
263 MathInset * nextInset() const;
265 MathInset * prevInset() const;
267 MathScriptInset * prevScriptInset() const;
269 MathSpaceInset * prevSpaceInset() const;
277 extern MathCursor * mathcursor;