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_inset.h"
28 class InsetFormulaBase;
29 class MathPainterInfo;
30 class MathUnknownInset;
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 &);
69 void paste(MathGridInset const & data);
74 /// called for LFUN_HOME etc
75 void home(bool sel = false);
76 /// called for LFUN_END etc
77 void end(bool sel = false);
78 /// called for LFUN_RIGHT and LFUN_RIGHTSEL
79 bool right(bool sel = false);
80 /// called for LFUN_LEFT etc
81 bool left(bool sel = false);
82 /// called for LFUN_UP etc
83 bool up(bool sel = false);
84 /// called for LFUN_DOWN etc
85 bool down(bool sel = false);
86 /// Put the cursor in the first position
88 /// Put the cursor in the last position
90 /// move to next cell in current inset
92 /// move to previous cell in current inset
97 void plainInsert(MathAtom const &);
99 void niceInsert(MathAtom const &);
103 /// in pixels from top of screen
104 void setPos(int x, int y);
105 /// in pixels from top of screen
106 void getPos(int & x, int & y);
108 MathInset * par() const;
109 /// return the next enclosing grid inset and the cursor's index in it
110 MathGridInset * enclosingGrid(idx_type & idx) const;
111 /// return the next enclosing hull inset and the cursor's index in it
112 MathHullInset * enclosingHull(idx_type & idx) const;
113 /// go up to enclosing grid
114 void popToEnclosingGrid();
115 /// go up to the hull inset
116 void popToEnclosingHull();
118 InsetFormulaBase * formula();
119 /// current offset in the current cell
120 pos_type pos() const;
122 idx_type idx() const;
123 /// size of current cell
124 size_type size() const;
128 bool interpret(string const &);
130 bool interpret(char);
133 /// interpret name a name of a macro
134 void macroModeClose();
135 /// are we currently typing the name of a macro?
136 MathUnknownInset * inMacroMode() const;
137 /// are we currently typing '#1' or '#2' or...?
138 bool inMacroArgMode() const;
139 /// are we in an mbox?
140 bool inMathMode() const;
142 // Local selection methods
144 bool selection() const;
154 void selHandle(bool);
159 /// clears or deletes selection depending on lyxrc setting
160 void selClearOrDel();
162 void selGet(MathArray & ar);
164 void drawSelection(MathPainterInfo & pain) const;
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;
175 /// remove this as soon as LyXFunc::getStatus is "localized"
176 string getLastCode() const { return "mathnormal"; }
178 void pullArg(bool goright);
180 bool isInside(MathInset const *) const;
186 col_type hullCol() const;
188 row_type hullRow() const;
190 col_type gridCol() const;
192 row_type gridRow() const;
194 /// make sure cursor position is valid
196 /// mark current cursor trace for redraw
199 UpdatableInset * asHyperActiveInset() const;
201 /// enter a MathInset
202 void push(MathAtom & par);
203 /// enter a MathInset from the front
204 void pushLeft(MathAtom & par);
205 /// enter a MathInset from the back
206 void pushRight(MathAtom & par);
207 /// leave current MathInset to the left
209 /// leave current MathInset to the left
213 MathArray & array() const;
215 MathXArray & xarray() const;
217 bool hasPrevAtom() const;
219 bool hasNextAtom() const;
221 MathAtom const & prevAtom() const;
223 MathAtom & prevAtom();
225 MathAtom const & nextAtom() const;
227 MathAtom & nextAtom();
229 /// returns the selection
230 void getSelection(MathCursorPos &, MathCursorPos &) const;
231 /// returns the normalized anchor of the selection
232 MathCursorPos normalAnchor() const;
234 /// reference to the last item of the path, i.e. "The Cursor"
235 MathCursorPos & cursor();
236 /// reference to the last item of the path, i.e. "The Cursor"
237 MathCursorPos const & cursor() const;
238 /// how deep are we nested?
239 unsigned depth() const;
241 /// describe the situation
243 /// dump selection information for debugging
244 void seldump(char const * str) const;
245 /// dump selection information for debugging
246 void dump(char const * str) const;
248 void setSelection(cursor_type const & where, size_type n);
251 /// lock/unlock inset
254 /// hack for reveal codes
257 void handleExtern(string const & arg);
260 friend class Selection;
264 /// moves cursor index one cell to the left
266 /// moves cursor index one cell to the right
268 /// moves cursor to beginning first cell of current line
270 /// moves cursor to end of last cell of current line
272 /// moves cursor position one cell to the left
274 /// moves cursor position one cell to the right
276 /// moves position somehow up or down
277 bool goUpDown(bool up);
278 /// moves position into box
279 bool bruteFind(int xo, int yo, int xlow, int xhigh, int ylow, int yhigh);
282 /// grab grid marked by anchor and current cursor
283 MathGridInset grabSelection() const;
284 /// erase the selected part and re-sets the cursor
285 void eraseSelection();
287 MathGridInset grabAndEraseSelection();
290 string macroName() const;
292 MathInset::difference_type macroNamePos() const;
293 /// can we enter the inset?
294 bool openable(MathAtom const &, bool selection) const;
295 /// write access to cursor cell position
297 /// write access to cursor cell index
300 /// path of positions the cursor had to go if it were leaving each inset
302 /// path of positions the anchor had to go if it were leaving each inset
303 mutable cursor_type Anchor_;
304 /// pointer to enclsing LyX inset
305 InsetFormulaBase * formula_;
307 /// text code of last char entered
308 //MathTextCodes lastcode_;
309 /// do we allow autocorrection
311 /// do we currently select
313 /// are we entering a macro name?
315 /// are we targeting a certain x coordinate, if so, which one?
319 extern MathCursor * mathcursor;