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 MathUpDownInset;
29 class InsetFormulaBase;
34 /// Description of a position
35 struct MathCursorPos {
42 /// returns cell corresponding to this position
43 MathArray & cell() const;
44 /// returns cell corresponding to this position
45 MathArray & cell(int idx) const;
46 /// returns xcell corresponding to this position
47 MathXArray & xcell() const;
48 /// returns xcell corresponding to this position
49 MathXArray & xcell(int idx) const;
50 /// moves position on cell to the left
52 /// moves position on cell to the right
54 /// moves position on cell up
56 /// moves position on cell up
61 bool operator==(MathCursorPos const &, MathCursorPos const &);
63 bool operator<(MathCursorPos const &, MathCursorPos const &);
66 /// This is the external interface of Math's subkernel
70 explicit MathCursor(InsetFormulaBase *);
72 void insert(char, MathTextCodes t = LM_TC_MIN);
74 void insert(MathInset *);
76 void insert(MathArray const &);
82 bool Right(bool sel = false);
84 bool Left(bool sel = false);
86 bool Up(bool sel = false);
88 bool Down(bool sel = false);
89 /// Put the cursor in the first position
91 /// Put the cursor in the last position
101 /// This is in pixels from (maybe?) the top of inset
102 void SetPos(int, int);
104 void GetPos(int & x, int & y);
106 MathInset * par() const;
107 /// return the next enclosing par of the given type and the cursor's
109 MathInset * enclosing(MathInsetTypes, int &) const;
111 InsetFormulaBase const * formula();
115 void Interpret(string const &);
117 void SetSize(MathStyles);
121 // Macro mode methods
122 void MacroModeOpen();
124 void MacroModeClose();
126 bool InMacroMode() const;
128 // Local selection methods
130 bool Selection() const;
140 void SelHandle(bool);
146 void drawSelection(Painter & pain) const;
148 void clearLastCode();
150 void setLastCode(MathTextCodes t);
152 void handleFont(MathTextCodes t);
154 void handleAccent(string const & name, int code);
156 void handleDelim(int l, int r);
157 /// Splits cells and shifts right part to the next cell
159 /// Splits line and insert new row of cell
162 MathTextCodes getLastCode() const;
164 int idx() const { return cursor().idx_; }
170 void pullArg(bool goright);
172 bool isInside(MathInset *) const;
174 MathTextCodes nextCode() const;
176 MathTextCodes prevCode() const;
187 MathStyles style() const;
188 /// Make sure cursor position is valid
189 void normalize() const;
191 /// Enter a new MathInset from the front or the back
192 void push(MathInset * par, bool first);
193 /// Leave current MathInset
201 /// do we currently select
205 InsetFormulaBase * const formula_;
207 MathTextCodes lastcode;
210 MathArray & array() const;
212 MathXArray & xarray() const;
214 /// returns the first position of the (normalized) selection
215 MathCursorPos firstSelectionPos() const;
216 /// returns the last position of the (normalized) selection
217 MathCursorPos lastSelectionPos() const;
218 /// returns the selection
219 void getSelection(MathCursorPos &, MathCursorPos &) const;
220 /// returns the normalized anchor of the selection
221 MathCursorPos normalAnchor() const;
222 /// returns the normalized anchor of the selection
223 bool openable(MathInset *, bool selection, bool useupdown) const;
225 /// path of positions the cursor had to go if it were leving each inset
226 std::vector<MathCursorPos> Cursor_;
227 /// path of positions the anchor had to go if it were leving each inset
228 std::vector<MathCursorPos> Anchor_;
230 /// reference to the last item of the path
231 MathCursorPos & cursor();
233 MathCursorPos const & cursor() const;
239 MathInset * parInset(int i) const;
241 void seldump(char const * str) const;
243 void dump(char const * str) const;
251 bool nextIsInset() const;
253 bool prevIsInset() const;
255 void merge(MathArray const & arr);
257 MathInset * nextInset() const;
259 MathInset * prevInset() const;
261 MathUpDownInset * nearbyUpDownInset() const;
264 MathFuncInset * imacro;
267 extern MathCursor * mathcursor;