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 *);
74 void insert(char, MathTextCodes t = LM_TC_MIN);
76 void insert(MathInset *);
78 void insert(MathArray const &);
86 bool right(bool sel = false);
88 bool left(bool sel = false);
90 bool up(bool sel = false);
92 bool down(bool sel = false);
93 /// Put the cursor in the first position
95 /// Put the cursor in the last position
104 void plainInsert(MathInset * p);
107 /// This is in pixels from (maybe?) the top of inset
108 void setPos(int, int);
110 void getPos(int & x, int & y);
112 MathInset * par() const;
113 /// return the next enclosing grid inset and the cursor's index in it
114 MathArrayInset * enclosingArray(int &) const;
116 InsetFormulaBase const * formula();
120 void interpret(string const &);
122 void setSize(MathStyles);
126 // Macro mode methods
127 void macroModeOpen();
129 void macroModeClose();
131 bool inMacroMode() const;
133 // Local selection methods
135 bool selection() const;
145 void selHandle(bool);
151 void drawSelection(Painter & pain) const;
153 void clearLastCode();
155 void setLastCode(MathTextCodes t);
157 void handleFont(MathTextCodes t);
159 void handleAccent(string const & name);
161 void handleDelim(int l, int r);
162 /// Splits cells and shifts right part to the next cell
164 /// Splits line and insert new row of cell
167 MathTextCodes getLastCode() const;
169 int idx() const { return cursor().idx_; }
175 void pullArg(bool goright);
177 bool isInside(MathInset *) const;
179 MathTextCodes nextCode() const;
181 MathTextCodes prevCode() const;
192 MathStyles style() const;
193 /// Make sure cursor position is valid
194 void normalize() const;
196 /// Enter a new MathInset from the front or the back
197 void push(MathInset * par, bool first);
198 /// Leave current MathInset
203 InsetFormulaBase * const formula_;
205 MathTextCodes lastcode_;
207 MathFuncInset * imacro_;
209 /// do we currently select
213 MathArray & array() const;
215 MathXArray & xarray() const;
217 /// returns the first position of the (normalized) selection
218 MathCursorPos firstSelectionPos() const;
219 /// returns the last position of the (normalized) selection
220 MathCursorPos lastSelectionPos() const;
221 /// returns the selection
222 void getSelection(MathCursorPos &, MathCursorPos &) const;
223 /// returns the normalized anchor of the selection
224 MathCursorPos normalAnchor() const;
225 /// returns the normalized anchor of the selection
226 bool openable(MathInset *, bool selection, bool useupdown) const;
228 /// path of positions the cursor had to go if it were leving each inset
229 std::vector<MathCursorPos> Cursor_;
230 /// path of positions the anchor had to go if it were leving each inset
231 std::vector<MathCursorPos> Anchor_;
233 /// reference to the last item of the path
234 MathCursorPos & cursor();
236 MathCursorPos const & cursor() const;
242 MathInset * parInset(int i) const;
244 void seldump(char const * str) const;
246 void dump(char const * str) const;
254 bool nextIsInset() const;
256 bool prevIsInset() const;
258 void merge(MathArray const & arr);
260 MathInset * nextInset() const;
262 MathInset * prevInset() const;
264 MathScriptInset * prevScriptInset() const;
266 MathSpaceInset * prevSpaceInset() const;
269 extern MathCursor * mathcursor;