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"
29 class InsetFormulaBase;
35 [Have a look at math_inset.h first]
37 The MathCursor is different from the kind of cursor used in the Outer
38 World. It contains a stack of MathCursorPositions, each of which is made
39 up of a inset pointer, an index and a position offset, marking a path from
40 this formula's mathHullInset to the current position.
47 /// short of anything else reasonable
48 typedef MathInset::size_type size_type;
49 /// type for cursor positions within a cell
50 typedef MathInset::pos_type pos_type;
51 /// type for cell indices
52 typedef MathInset::idx_type idx_type;
53 /// type for row numbers
54 typedef MathInset::row_type row_type;
55 /// type for column numbers
56 typedef MathInset::col_type col_type;
57 /// how to store a cursor
58 typedef std::vector<MathCursorPos> cursor_type;
61 explicit MathCursor(InsetFormulaBase *, bool left);
63 void insert(MathAtom const &);
65 void insert(MathArray const &);
67 void paste(MathArray const &);
72 /// called for LFUN_HOME etc
73 void home(bool sel = false);
74 /// called for LFUN_END etc
75 void end(bool sel = false);
76 /// called for LFUN_RIGHT and LFUN_RIGHTSEL
77 bool right(bool sel = false);
78 /// called for LFUN_LEFT etc
79 bool left(bool sel = false);
80 /// called for LFUN_UP etc
81 bool up(bool sel = false);
82 /// called for LFUN_DOWN etc
83 bool down(bool sel = false);
84 /// Put the cursor in the first position
86 /// Put the cursor in the last position
88 /// move to next cell in current inset
90 /// move to previous cell in current inset
95 void plainInsert(MathAtom const &);
97 void niceInsert(MathAtom const &);
101 /// in pixels from top of screen
102 void setPos(int x, int y);
103 /// in pixels from top of screen
104 void getPos(int & x, int & y);
106 MathInset * par() const;
107 /// return the next enclosing grid inset and the cursor's index in it
108 MathGridInset * enclosingGrid(idx_type &) const;
110 InsetFormulaBase * formula();
111 /// current offset in the current cell
112 pos_type pos() const;
114 idx_type idx() const;
115 /// size of current cell
116 size_type size() const;
118 bool interpret(string const &);
120 bool interpret(char);
123 /// interpret name a name of a macro
124 void macroModeClose();
126 bool inMacroMode() const;
128 // Local selection methods
130 bool selection() const;
140 void selHandle(bool);
146 void selGet(MathArray & ar);
148 void drawSelection(Painter & pain) const;
150 void handleFont(MathTextCodes t);
152 void handleDelim(string const & l, string const & r);
154 void handleNest(MathInset * p);
155 /// splits cells and shifts right part to the next cell
157 /// splits line and insert new row of cell
159 /// read contents of line into an array
160 void readLine(MathArray & ar) const;
162 MathTextCodes getLastCode() const;
164 void pullArg(bool goright);
166 bool isInside(MathInset const *) const;
168 MathTextCodes nextCode() const;
174 col_type hullCol() const;
176 row_type hullRow() const;
178 /// make sure cursor position is valid
179 void normalize() const;
181 UpdatableInset * asHyperActiveInset() const;
183 /// enter a MathInset
184 void push(MathAtom & par);
185 /// enter a MathInset from the front
186 void pushLeft(MathAtom & par);
187 /// enter a MathInset from the back
188 void pushRight(MathAtom & par);
189 /// leave current MathInset to the left
191 /// leave current MathInset to the left
195 MathArray & array() const;
197 MathXArray & xarray() const;
199 bool hasPrevAtom() const;
201 bool hasNextAtom() const;
203 MathAtom const & prevAtom() const;
205 MathAtom & prevAtom();
207 MathAtom const & nextAtom() const;
209 MathAtom & nextAtom();
211 /// returns the selection
212 void getSelection(MathCursorPos &, MathCursorPos &) const;
213 /// returns the normalized anchor of the selection
214 MathCursorPos normalAnchor() const;
216 /// path of positions the cursor had to go if it were leving each inset
218 /// path of positions the anchor had to go if it were leving each inset
221 /// reference to the last item of the path, i.e. "The Cursor"
222 MathCursorPos & cursor();
223 /// reference to the last item of the path, i.e. "The Cursor"
224 MathCursorPos const & cursor() const;
226 /// dump selection information for debugging
227 void seldump(char const * str) const;
228 /// dump selection information for debugging
229 void dump(char const * str) const;
231 void stripFromLastEqualSign();
234 friend class Selection;
237 /// moves cursor position one cell to the left
239 /// moves cursor position one cell to the right
241 /// moves cursor index one cell to the left
243 /// moves cursor index one cell to the right
245 /// moves position somehow up
247 /// moves position somehow down
249 /// moves position into box
250 bool bruteFind(int xlow, int xhigh, int ylow, int yhigh);
253 string macroName() const;
255 int macroNamePos() const;
257 void insert(char, MathTextCodes t);
258 /// can we enter the inset?
259 bool openable(MathAtom const &, bool selection) const;
260 /// write access to cursor cell position
262 /// write access to cursor cell index
266 InsetFormulaBase * formula_;
268 MathTextCodes lastcode_;
270 /// do we currently select
274 extern MathCursor * mathcursor;