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;
30 class InsetFormulaBase;
35 /// Description of a position
36 struct MathCursorPos {
43 /// returns cell corresponding to this position
44 MathArray & cell() const;
45 /// returns cell corresponding to this position
46 MathArray & cell(int idx) const;
47 /// returns xcell corresponding to this position
48 MathXArray & xcell() const;
49 /// returns xcell corresponding to this position
50 MathXArray & xcell(int idx) const;
51 /// moves position on cell to the left
53 /// moves position on cell to the right
55 /// moves position on cell up
57 /// moves position on cell up
62 bool operator==(MathCursorPos const &, MathCursorPos const &);
64 bool operator<(MathCursorPos const &, MathCursorPos const &);
67 /// This is the external interface of Math's subkernel
71 explicit MathCursor(InsetFormulaBase *);
73 void insert(char, MathTextCodes t = LM_TC_MIN);
75 void insert(MathInset *);
77 void insert(MathArray const &);
85 bool Right(bool sel = false);
87 bool Left(bool sel = false);
89 bool Up(bool sel = false);
91 bool Down(bool sel = false);
92 /// Put the cursor in the first position
94 /// Put the cursor in the last position
104 /// This is in pixels from (maybe?) the top of inset
105 void SetPos(int, int);
107 void GetPos(int & x, int & y);
109 MathInset * par() const;
110 /// return the next enclosing par of the given type and the cursor's
112 MathInset * enclosing(MathInsetTypes, int &) const;
114 InsetFormulaBase const * formula();
118 void Interpret(string const &);
120 void SetSize(MathStyles);
124 // Macro mode methods
125 void MacroModeOpen();
127 void MacroModeClose();
129 bool InMacroMode() const;
131 // Local selection methods
133 bool Selection() const;
143 void SelHandle(bool);
149 void drawSelection(Painter & pain) const;
151 void clearLastCode();
153 void setLastCode(MathTextCodes t);
155 void handleFont(MathTextCodes t);
157 void handleAccent(string const & name, int code);
159 void handleDelim(int l, int r);
160 /// Splits cells and shifts right part to the next cell
162 /// Splits line and insert new row of cell
165 MathTextCodes getLastCode() const;
167 int idx() const { return cursor().idx_; }
173 void pullArg(bool goright);
175 bool isInside(MathInset *) const;
177 MathTextCodes nextCode() const;
179 MathTextCodes prevCode() const;
190 MathStyles style() const;
191 /// Make sure cursor position is valid
192 void normalize() const;
194 /// Enter a new MathInset from the front or the back
195 void push(MathInset * par, bool first);
196 /// Leave current MathInset
204 /// do we currently select
208 InsetFormulaBase * const formula_;
210 MathTextCodes lastcode;
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 MathFuncInset * imacro;
272 extern MathCursor * mathcursor;