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;
34 [Have a look at math_inset.h first]
36 The MathCursor is different from the kind of cursor used in the Outer
37 World. It contains a stack of MathCursorPositions, each of which is made
38 up of a inset pointer, an index and a position offset, marking a path from
39 this formula's mathHullInset to the current position.
44 /// Description of a position
50 explicit MathCursorPos(MathInset * p);
52 /// returns cell corresponding to this position
53 MathArray & cell() const;
54 /// returns cell corresponding to this position
55 MathArray & cell(MathInset::idx_type idx) const;
56 /// returns xcell corresponding to this position
57 MathXArray & xcell() const;
58 /// returns xcell corresponding to this position
59 MathXArray & xcell(MathInset::idx_type idx) const;
66 /// pointer to an inset
68 /// cell index of a position in this inset
69 MathInset::idx_type idx_;
70 /// position in this cell
71 MathInset::pos_type pos_;
75 bool operator==(MathCursorPos const &, MathCursorPos const &);
76 /// test for inequality
77 bool operator!=(MathCursorPos const &, MathCursorPos const &);
79 bool operator<(MathCursorPos const &, MathCursorPos const &);
81 std::ostream & operator<<(std::ostream &, MathCursorPos const &);
87 /// short of anything else reasonable
88 typedef MathInset::size_type size_type;
89 /// type for cursor positions within a cell
90 typedef MathInset::pos_type pos_type;
91 /// type for cell indices
92 typedef MathInset::idx_type idx_type;
93 /// type for row numbers
94 typedef MathInset::row_type row_type;
95 /// type for column numbers
96 typedef MathInset::col_type col_type;
97 /// how to store a cursor
98 typedef std::vector<MathCursorPos> cursor_type;
101 explicit MathCursor(InsetFormulaBase *, bool left);
103 void insert(MathAtom const &);
105 void insert(MathArray const &);
107 void paste(MathArray const &);
112 /// called for LFUN_HOME etc
113 void home(bool sel = false);
114 /// called for LFUN_END etc
115 void end(bool sel = false);
116 /// called for LFUN_RIGHT and LFUN_RIGHTSEL
117 bool right(bool sel = false);
118 /// called for LFUN_LEFT etc
119 bool left(bool sel = false);
120 /// called for LFUN_UP etc
121 bool up(bool sel = false);
122 /// called for LFUN_DOWN etc
123 bool down(bool sel = false);
124 /// Put the cursor in the first position
126 /// Put the cursor in the last position
128 /// move to next cell in current inset
130 /// move to previous cell in current inset
135 void plainInsert(MathAtom const &);
137 void niceInsert(MathAtom const &);
141 /// in pixels from top of screen
142 void setPos(int x, int y);
143 /// in pixels from top of screen
144 void getPos(int & x, int & y);
146 MathInset * par() const;
147 /// return the next enclosing grid inset and the cursor's index in it
148 MathGridInset * enclosingGrid(idx_type &) const;
150 InsetFormulaBase const * formula();
151 /// current offset in the current cell
152 pos_type pos() const;
154 idx_type idx() const;
155 /// size of current cell
156 size_type size() const;
158 bool interpret(string const &);
160 bool interpret(char);
163 /// interpret name a name of a macro
164 void macroModeClose();
166 bool inMacroMode() const;
168 // Local selection methods
170 bool selection() const;
180 void selHandle(bool);
186 void selGet(MathArray & ar);
188 void drawSelection(Painter & pain) const;
190 void handleFont(MathTextCodes t);
192 void handleDelim(string const & l, string const & r);
194 void handleNest(MathInset * p);
195 /// splits cells and shifts right part to the next cell
197 /// splits line and insert new row of cell
199 /// read contents of line into an array
200 void readLine(MathArray & ar) const;
202 MathTextCodes getLastCode() const;
204 void pullArg(bool goright);
206 bool isInside(MathInset const *) const;
208 MathTextCodes nextCode() const;
214 col_type ncols() const;
216 col_type col() const;
218 row_type row() const;
220 /// make sure cursor position is valid
221 void normalize() const;
223 UpdatableInset * asHyperActiveInset() const;
225 /// enter a MathInset
226 void push(MathAtom & par);
227 /// enter a MathInset from the front
228 void pushLeft(MathAtom & par);
229 /// enter a MathInset from the back
230 void pushRight(MathAtom & par);
231 /// leave current MathInset to the left
233 /// leave current MathInset to the left
237 MathArray & array() const;
239 MathXArray & xarray() const;
241 bool hasPrevAtom() const;
243 bool hasNextAtom() const;
245 MathAtom const & prevAtom() const;
247 MathAtom & prevAtom();
249 MathAtom const & nextAtom() const;
251 MathAtom & nextAtom();
253 /// returns the selection
254 void getSelection(MathCursorPos &, MathCursorPos &) const;
255 /// returns the normalized anchor of the selection
256 MathCursorPos normalAnchor() const;
258 /// path of positions the cursor had to go if it were leving each inset
260 /// path of positions the anchor had to go if it were leving each inset
263 /// reference to the last item of the path, i.e. "The Cursor"
264 MathCursorPos & cursor();
265 /// reference to the last item of the path, i.e. "The Cursor"
266 MathCursorPos const & cursor() const;
268 /// dump selection information for debugging
269 void seldump(char const * str) const;
270 /// dump selection information for debugging
271 void dump(char const * str) const;
273 void stripFromLastEqualSign();
276 friend class Selection;
279 /// moves cursor position one cell to the left
281 /// moves cursor position one cell to the right
283 /// moves cursor index one cell to the left
285 /// moves cursor index one cell to the right
287 /// moves position somehow up
289 /// moves position somehow down
291 /// moves position into box
292 bool bruteFind(int xlow, int xhigh, int ylow, int yhigh);
295 string macroName() const;
297 int macroNamePos() const;
299 void insert(char, MathTextCodes t);
300 /// can we enter the inset?
301 bool openable(MathAtom const &, bool selection) const;
302 /// write access to cursor cell position
304 /// write access to cursor cell index
308 InsetFormulaBase * const formula_;
310 MathTextCodes lastcode_;
312 /// do we currently select
316 extern MathCursor * mathcursor;