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"
25 #include "math_inset.h"
28 class InsetFormulaBase;
32 /// Description of a position
33 struct MathCursorPos {
37 MathInset::idx_type idx_;
39 MathInset::pos_type pos_;
41 /// returns cell corresponding to this position
42 MathArray & cell() const;
43 /// returns cell corresponding to this position
44 MathArray & cell(MathInset::idx_type idx) const;
45 /// returns xcell corresponding to this position
46 MathXArray & xcell() const;
47 /// returns xcell corresponding to this position
48 MathXArray & xcell(MathInset::idx_type idx) const;
52 bool operator==(MathCursorPos const &, MathCursorPos const &);
54 bool operator<(MathCursorPos const &, MathCursorPos const &);
57 /// This is the external interface of Math's subkernel
60 /// short of anything else reasonable
61 typedef MathInset::size_type size_type;
62 /// type for cursor positions within a cell
63 typedef MathInset::pos_type pos_type;
64 /// type for cell indices
65 typedef MathInset::idx_type idx_type;
66 /// type for row numbers
67 typedef MathInset::row_type row_type;
68 /// type for column numbers
69 typedef MathInset::col_type col_type;
72 explicit MathCursor(InsetFormulaBase *, bool left);
74 void insert(MathAtom const &);
76 void insert(MathArray const &);
78 void paste(MathArray const &);
84 void home(bool sel = false);
86 void end(bool sel = false);
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(MathAtom const &);
108 void niceInsert(MathAtom const &);
112 /// This is in pixels from (maybe?) the top of inset
113 // don't move further in than the Anchor's inset if respect_anchor == true
114 void setPos(int x, int y, bool respect_anchor = false);
115 /// This is in pixels from (maybe?) the top of inset, don't move further
117 void getPos(int & x, int & y);
119 MathAtom & par() const;
120 /// return the next enclosing grid inset and the cursor's index in it
121 MathGridInset * enclosingGrid(idx_type &) const;
123 InsetFormulaBase const * formula();
125 pos_type pos() const;
127 idx_type idx() const;
129 size_type size() const;
131 bool interpret(string const &);
133 bool interpret(char);
137 // Macro mode methods
138 void macroModeClose();
140 bool inMacroMode() const;
142 // Local selection methods
144 bool selection() const;
154 void selHandle(bool);
160 void selGet(MathArray & ar);
162 void drawSelection(Painter & pain) const;
164 void handleFont(MathTextCodes t);
166 void handleDelim(string const & l, string const & r);
168 void handleNest(MathInset * p);
169 /// Splits cells and shifts right part to the next cell
171 /// Splits line and insert new row of cell
173 /// read contents of line into an array
174 void readLine(MathArray & ar) const;
176 MathTextCodes getLastCode() const;
178 void pullArg(bool goright);
180 bool isInside(MathInset const *) const;
182 MathTextCodes nextCode() const;
188 col_type ncols() const;
190 col_type col() const;
192 row_type row() const;
194 /// Make sure cursor position is valid
195 void normalize() const;
197 UpdatableInset * asHyperActiveInset() const;
199 /// enter a MathInset
200 void push(MathAtom & par);
201 /// enter a MathInset from the front
202 void pushLeft(MathAtom & par);
203 /// enter a MathInset from the back
204 void pushRight(MathAtom & par);
205 /// leave current MathInset to the left
207 /// leave current MathInset to the left
211 MathArray & array() const;
213 MathXArray & xarray() const;
215 bool hasPrevAtom() const;
217 bool hasNextAtom() const;
219 MathAtom const & prevAtom() const;
221 MathAtom & prevAtom();
223 MathAtom const & nextAtom() const;
225 MathAtom & nextAtom();
227 /// returns the selection
228 void getSelection(MathCursorPos &, MathCursorPos &) const;
229 /// returns the normalized anchor of the selection
230 MathCursorPos normalAnchor() const;
232 /// path of positions the cursor had to go if it were leving each inset
233 std::vector<MathCursorPos> Cursor_;
234 /// path of positions the anchor had to go if it were leving each inset
235 std::vector<MathCursorPos> Anchor_;
237 /// reference to the last item of the path
238 MathCursorPos & cursor();
240 MathCursorPos const & cursor() const;
243 void seldump(char const * str) const;
245 void dump(char const * str) const;
247 void stripFromLastEqualSign();
250 friend class Selection;
253 /// moves cursor position one cell to the left
255 /// moves cursor position one cell to the right
257 /// moves cursor index one cell to the left
259 /// moves cursor index one cell to the right
261 /// moves position somehow up
263 /// moves position somehow down
267 string macroName() const;
269 int macroNamePos() const;
271 void insert(char, MathTextCodes t);
272 /// can we enter the inset?
273 bool openable(MathAtom const &, bool selection) const;
274 /// can the setPos routine enter that inset?
275 bool positionable(MathAtom const &, int x, int y) const;
276 /// write access to cursor cell position
278 /// write access to cursor cell index
282 InsetFormulaBase * const formula_;
284 MathTextCodes lastcode_;
286 /// do we currently select
290 extern MathCursor * mathcursor;