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 {
43 bool operator==(const MathCursorPos &) const;
45 bool operator<(const MathCursorPos &) const;
46 /// returns cell corresponding to this position
47 MathArray & cell() const;
48 /// returns cell corresponding to this position
49 MathArray & cell(int idx) const;
50 /// returns xcell corresponding to this position
51 MathXArray & xcell() const;
52 /// returns xcell corresponding to this position
53 MathXArray & xcell(int idx) const;
54 /// moves position on cell to the left
56 /// moves position on cell to the right
58 /// moves position on cell up
60 /// moves position on cell up
65 /// This is the external interface of Math's subkernel
69 explicit MathCursor(InsetFormulaBase *);
71 void insert(char, MathTextCodes t = LM_TC_MIN);
73 void insert(MathInset *);
75 void insert(MathArray const &);
81 bool Right(bool sel = false);
83 bool Left(bool sel = false);
85 bool Up(bool sel = false);
87 bool Down(bool sel = false);
88 /// Put the cursor in the first position
90 /// Put the cursor in the last position
100 /// This is in pixels from (maybe?) the top of inset
101 void SetPos(int, int);
103 void GetPos(int & x, int & y);
105 MathInset * par() const;
106 /// return the next enclosing par of the given type and the cursor's
108 MathInset * enclosing(MathInsetTypes, int &) const;
110 InsetFormulaBase const * formula();
114 void Interpret(string const &);
116 void SetSize(MathStyles);
120 // Macro mode methods
121 void MacroModeOpen();
123 void MacroModeClose();
125 bool InMacroMode() const;
127 // Local selection methods
129 bool Selection() const;
139 void SelHandle(bool);
145 void drawSelection(Painter & pain) const;
147 void clearLastCode();
149 void setLastCode(MathTextCodes t);
151 void handleFont(MathTextCodes t);
153 void handleAccent(string const & name, int code);
155 void handleDelim(int l, int r);
156 /// Splits cells and shifts right part to the next cell
158 /// Splits line and insert new row of cell
161 MathTextCodes getLastCode() const;
163 int idx() const { return cursor().idx_; }
171 bool isInside(MathInset *) const;
173 MathTextCodes nextCode() const;
175 MathTextCodes prevCode() const;
186 MathStyles style() const;
187 /// Make sure cursor position is valid
188 void normalize() const;
190 /// Enter a new MathInset from the front or the back
191 void push(MathInset * par, bool first);
192 /// Leave current MathInset
200 /// do we currently select
204 InsetFormulaBase * const formula_;
206 MathTextCodes lastcode;
209 MathArray & array() const;
211 MathXArray & xarray() const;
213 /// returns the first position of the (normalized) selection
214 MathCursorPos firstSelectionPos() const;
215 /// returns the last position of the (normalized) selection
216 MathCursorPos lastSelectionPos() const;
217 /// returns the selection
218 void getSelection(MathCursorPos &, MathCursorPos &) const;
219 /// returns the normalized anchor of the selection
220 MathCursorPos normalAnchor() const;
221 /// returns the normalized anchor of the selection
222 bool openable(MathInset *, bool selection, bool useupdown) const;
224 /// path of positions the cursor had to go if it were leving each inset
225 std::vector<MathCursorPos> Cursor_;
226 /// path of positions the anchor had to go if it were leving each inset
227 std::vector<MathCursorPos> Anchor_;
229 /// reference to the last item of the path
230 MathCursorPos & cursor();
232 MathCursorPos const & cursor() const;
238 MathInset * parInset(int i) const;
240 void seldump(char const * str) const;
242 void dump(char const * str) const;
250 bool nextIsInset() const;
252 bool prevIsInset() const;
254 void merge(MathArray const & arr);
256 MathInset * nextInset() const;
258 MathInset * prevInset() const;
260 MathUpDownInset * nearbyUpDownInset() const;
263 MathFuncInset * imacro;
266 extern MathCursor * mathcursor;