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
45 struct MathCursorPos {
46 /// pointer to an inset
48 /// cell index of a position in this inset
49 MathInset::idx_type idx_;
50 /// position in this cell
51 MathInset::pos_type pos_;
53 /// returns cell corresponding to this position
54 MathArray & cell() const;
55 /// returns cell corresponding to this position
56 MathArray & cell(MathInset::idx_type idx) const;
57 /// returns xcell corresponding to this position
58 MathXArray & xcell() const;
59 /// returns xcell corresponding to this position
60 MathXArray & xcell(MathInset::idx_type idx) const;
64 bool operator==(MathCursorPos const &, MathCursorPos const &);
65 /// test for unequality
66 bool operator<(MathCursorPos const &, MathCursorPos const &);
72 /// short of anything else reasonable
73 typedef MathInset::size_type size_type;
74 /// type for cursor positions within a cell
75 typedef MathInset::pos_type pos_type;
76 /// type for cell indices
77 typedef MathInset::idx_type idx_type;
78 /// type for row numbers
79 typedef MathInset::row_type row_type;
80 /// type for column numbers
81 typedef MathInset::col_type col_type;
82 /// how to store a cursor
83 typedef std::vector<MathCursorPos> cursor_type;
86 explicit MathCursor(InsetFormulaBase *, bool left);
88 void insert(MathAtom const &);
90 void insert(MathArray const &);
92 void paste(MathArray const &);
97 /// called for LFUN_HOME etc
98 void home(bool sel = false);
99 /// called for LFUN_END etc
100 void end(bool sel = false);
101 /// called for LFUN_RIGHT and LFUN_RIGHTSEL
102 bool right(bool sel = false);
103 /// called for LFUN_LEFT etc
104 bool left(bool sel = false);
105 /// called for LFUN_UP etc
106 bool up(bool sel = false);
107 /// called for LFUN_DOWN etc
108 bool down(bool sel = false);
109 /// Put the cursor in the first position
111 /// Put the cursor in the last position
113 /// move to next cell in current inset
115 /// move to previous cell in current inset
120 void plainInsert(MathAtom const &);
122 void niceInsert(MathAtom const &);
126 /// in pixels from top of screen
127 void setPos(int x, int y);
128 /// in pixels from top of screen
129 void getPos(int & x, int & y);
131 MathAtom & par() const;
132 /// return the next enclosing grid inset and the cursor's index in it
133 MathGridInset * enclosingGrid(idx_type &) const;
135 InsetFormulaBase const * formula();
136 /// current offset in the current cell
137 pos_type pos() const;
139 idx_type idx() const;
140 /// size of current cell
141 size_type size() const;
143 bool interpret(string const &);
145 bool interpret(char);
148 /// interpret name a name of a macro
149 void macroModeClose();
151 bool inMacroMode() const;
153 // Local selection methods
155 bool selection() const;
165 void selHandle(bool);
171 void selGet(MathArray & ar);
173 void drawSelection(Painter & pain) const;
175 void handleFont(MathTextCodes t);
177 void handleDelim(string const & l, string const & r);
179 void handleNest(MathInset * p);
180 /// splits cells and shifts right part to the next cell
182 /// splits line and insert new row of cell
184 /// read contents of line into an array
185 void readLine(MathArray & ar) const;
187 MathTextCodes getLastCode() const;
189 void pullArg(bool goright);
191 bool isInside(MathInset const *) const;
193 MathTextCodes nextCode() const;
199 col_type ncols() const;
201 col_type col() const;
203 row_type row() const;
205 /// make sure cursor position is valid
206 void normalize() const;
208 UpdatableInset * asHyperActiveInset() const;
210 /// enter a MathInset
211 void push(MathAtom & par);
212 /// enter a MathInset from the front
213 void pushLeft(MathAtom & par);
214 /// enter a MathInset from the back
215 void pushRight(MathAtom & par);
216 /// leave current MathInset to the left
218 /// leave current MathInset to the left
222 MathArray & array() const;
224 MathXArray & xarray() const;
226 bool hasPrevAtom() const;
228 bool hasNextAtom() const;
230 MathAtom const & prevAtom() const;
232 MathAtom & prevAtom();
234 MathAtom const & nextAtom() const;
236 MathAtom & nextAtom();
238 /// returns the selection
239 void getSelection(MathCursorPos &, MathCursorPos &) const;
240 /// returns the normalized anchor of the selection
241 MathCursorPos normalAnchor() const;
243 /// path of positions the cursor had to go if it were leving each inset
245 /// path of positions the anchor had to go if it were leving each inset
248 /// reference to the last item of the path, i.e. "The Cursor"
249 MathCursorPos & cursor();
250 /// reference to the last item of the path, i.e. "The Cursor"
251 MathCursorPos const & cursor() const;
253 /// dump selection information for debugging
254 void seldump(char const * str) const;
255 /// dump selection information for debugging
256 void dump(char const * str) const;
258 void stripFromLastEqualSign();
261 friend class Selection;
264 /// moves cursor position one cell to the left
266 /// moves cursor position one cell to the right
268 /// moves cursor index one cell to the left
270 /// moves cursor index one cell to the right
272 /// moves position somehow up
274 /// moves position somehow down
276 /// moves position somehow down
277 bool bruteUpDown(int ylow, int yhigh);
280 string macroName() const;
282 int macroNamePos() const;
284 void insert(char, MathTextCodes t);
285 /// can we enter the inset?
286 bool openable(MathAtom const &, bool selection) const;
287 /// can the setPos routine enter that inset?
288 bool positionable(MathAtom const &, int x, int y) const;
289 /// write access to cursor cell position
291 /// write access to cursor cell index
295 InsetFormulaBase * const formula_;
297 MathTextCodes lastcode_;
299 /// do we currently select
303 extern MathCursor * mathcursor;