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"
28 class MathScriptInset;
31 class InsetFormulaBase;
36 /// Description of a position
37 struct MathCursorPos {
44 /// returns cell corresponding to this position
45 MathArray & cell() const;
46 /// returns cell corresponding to this position
47 MathArray & cell(int idx) const;
48 /// returns xcell corresponding to this position
49 MathXArray & xcell() const;
50 /// returns xcell corresponding to this position
51 MathXArray & xcell(int idx) const;
52 /// moves position on cell to the left
54 /// moves position on cell to the right
56 /// moves position on cell up
58 /// moves position on cell up
63 bool operator==(MathCursorPos const &, MathCursorPos const &);
65 bool operator<(MathCursorPos const &, MathCursorPos const &);
68 /// This is the external interface of Math's subkernel
72 explicit MathCursor(InsetFormulaBase *);
76 void insert(char, MathTextCodes t = LM_TC_MIN);
78 void insert(MathInset *);
80 void insert(MathArray const &);
88 bool right(bool sel = false);
90 bool left(bool sel = false);
92 bool up(bool sel = false);
94 bool down(bool sel = false);
95 /// Put the cursor in the first position
97 /// Put the cursor in the last position
106 void plainInsert(MathInset * p);
109 /// This is in pixels from (maybe?) the top of inset
110 void setPos(int, int);
112 void getPos(int & x, int & y);
114 MathInset * par() const;
115 /// return the next enclosing grid inset and the cursor's index in it
116 MathArrayInset * enclosingArray(int &) const;
118 InsetFormulaBase const * formula();
122 void interpret(string const &);
124 void setSize(MathStyles);
128 // Macro mode methods
129 void macroModeOpen();
131 void macroModeClose();
133 bool inMacroMode() const;
135 // Local selection methods
137 bool selection() const;
147 void selHandle(bool);
153 void drawSelection(Painter & pain) const;
155 void clearLastCode();
157 void setLastCode(MathTextCodes t);
159 void handleFont(MathTextCodes t);
161 void handleAccent(string const & name);
163 void handleDelim(int l, int r);
164 /// Splits cells and shifts right part to the next cell
166 /// Splits line and insert new row of cell
169 MathTextCodes getLastCode() const;
171 int idx() const { return cursor().idx_; }
177 void pullArg(bool goright);
179 bool isInside(MathInset *) const;
181 MathTextCodes nextCode() const;
183 MathTextCodes prevCode() const;
194 MathStyles style() const;
195 /// Make sure cursor position is valid
196 void normalize() const;
198 /// Enter a new MathInset from the front or the back
199 void push(MathInset * par, bool first);
200 /// Leave current MathInset
205 InsetFormulaBase * const formula_;
207 MathTextCodes lastcode_;
209 MathFuncInset * imacro_;
211 /// do we currently select
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 void seldump(char const * str) const;
248 void dump(char const * str) const;
256 bool nextIsInset() const;
258 bool prevIsInset() const;
260 void merge(MathArray const & arr);
262 MathInset * nextInset() const;
264 MathInset * prevInset() const;
266 MathScriptInset * prevScriptInset() const;
268 MathSpaceInset * prevSpaceInset() const;
271 extern MathCursor * mathcursor;