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"
25 #include "math_iterator.h"
28 class InsetFormulaBase;
30 class MathPainterInfo;
31 class MathUnknownInset;
36 [Have a look at math_inset.h first]
38 The MathCursor is different from the kind of cursor used in the Outer
39 World. It contains a stack of MathCursorPos, each of which is made
40 up of a inset pointer, an index and a position offset, marking a path from
41 this formula's MathHullInset to the current position.
48 /// short of anything else reasonable
49 typedef MathInset::size_type size_type;
50 /// type for cursor positions within a cell
51 typedef MathInset::pos_type pos_type;
52 /// type for cell indices
53 typedef MathInset::idx_type idx_type;
54 /// type for row numbers
55 typedef MathInset::row_type row_type;
56 /// type for column numbers
57 typedef MathInset::col_type col_type;
60 explicit MathCursor(InsetFormulaBase *, bool left);
64 void insert(MathAtom const &);
66 void insert(MathArray const &);
68 void paste(MathGridInset const & data);
73 /// called for LFUN_HOME etc
74 bool home(bool sel = false);
75 /// called for LFUN_END etc
76 bool end(bool sel = false);
77 /// called for LFUN_RIGHT and LFUN_RIGHTSEL
78 bool right(bool sel = false);
79 /// called for LFUN_LEFT etc
80 bool left(bool sel = false);
81 /// called for LFUN_UP etc
82 bool up(bool sel = false);
83 /// called for LFUN_DOWN etc
84 bool down(bool sel = false);
85 /// Put the cursor in the first position
87 /// Put the cursor in the last position
89 /// move to next cell in current inset
91 /// move to previous cell in current inset
96 void plainInsert(MathAtom const &);
98 void niceInsert(MathAtom const &);
100 /// in pixels from top of screen
101 void setPos(int x, int y);
102 /// in pixels from top of screen
103 void getPos(int & x, int & y) const;
104 /// in pixels from left of screen
107 MathInset * par() const;
108 /// return the next enclosing grid inset and the cursor's index in it
109 MathGridInset * enclosingGrid(idx_type & idx) const;
110 /// go up to enclosing grid
111 void popToEnclosingGrid();
112 /// go up to the hull inset
113 void popToEnclosingHull();
114 /// go up to the hull inset
115 void popToHere(MathInset const * p);
117 InsetFormulaBase * formula() const;
118 /// current offset in the current cell
119 pos_type pos() const;
121 idx_type idx() const;
122 /// size of current cell
123 size_type size() const;
127 bool interpret(char);
128 /// interpret name a name of a macro
129 void macroModeClose();
130 /// are we currently typing the name of a macro?
131 bool inMacroMode() const;
132 /// get access to the macro we are currently typing
133 MathUnknownInset * activeMacro();
134 /// get access to the macro we are currently typing
135 MathUnknownInset const * activeMacro() const;
136 /// are we currently typing '#1' or '#2' or...?
137 bool inMacroArgMode() const;
138 /// are we in math mode (1), text mode (-1) or unsure?
139 MathInset::mode_type currentMode() const;
141 // Local selection methods
143 bool selection() const;
153 void selHandle(bool);
158 /// clears or deletes selection depending on lyxrc setting
159 void selClearOrDel();
161 void selGet(MathArray & ar);
163 void drawSelection(MathPainterInfo & pain) const;
165 void handleNest(MathAtom const & at);
166 /// remove this as soon as LyXFunc::getStatus is "localized"
167 string getLastCode() const { return "mathnormal"; }
169 bool isInside(MathInset const *) const;
175 /// make sure cursor position is valid
177 /// mark current cursor trace for redraw
180 UpdatableInset * asHyperActiveInset() const;
182 /// enter a MathInset
183 void push(MathAtom & par);
184 /// enter a MathInset from the front
185 void pushLeft(MathAtom & par);
186 /// enter a MathInset from the back
187 void pushRight(MathAtom & par);
188 /// leave current MathInset to the left
190 /// leave current MathInset to the left
194 MathArray & array() const;
196 bool hasPrevAtom() const;
198 bool hasNextAtom() const;
200 MathAtom const & prevAtom() const;
202 MathAtom & prevAtom();
204 MathAtom const & nextAtom() const;
206 MathAtom & nextAtom();
208 /// returns the selection
209 void getSelection(MathCursorPos &, MathCursorPos &) const;
210 /// returns the normalized anchor of the selection
211 MathCursorPos normalAnchor() const;
213 /// reference to the last item of the path, i.e. "The Cursor"
214 MathCursorPos & cursor();
215 /// reference to the last item of the path, i.e. "The Cursor"
216 MathCursorPos const & cursor() const;
217 /// how deep are we nested?
218 unsigned depth() const;
221 MathInset::result_type dispatch(FuncRequest const & cmd);
222 /// describe the situation
224 /// dump selection information for debugging
225 void seldump(char const * str) const;
226 /// dump selection information for debugging
227 void dump(char const * str) const;
229 void setSelection(MathIterator const & where, size_type n);
233 void insert(string const & str);
234 /// lock/unlock inset
237 /// hack for reveal codes
240 //void handleExtern(string const & arg);
243 friend class Selection;
247 /// injects content of a cell into parent
249 /// moves cursor index one cell to the left
251 /// moves cursor index one cell to the right
253 /// moves cursor to end of last cell of current line
255 /// moves cursor position one cell to the left
257 /// moves cursor position one cell to the right
259 /// moves position somehow up or down
260 bool goUpDown(bool up);
261 /// moves position closest to (x, y) in given box
262 bool bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh);
263 /// moves position closest to (x, y) in current cell
264 void bruteFind2(int x, int y);
265 /// are we in a nucleus of a script inset?
266 bool inNucleus() const;
268 /// grab grid marked by anchor and current cursor
269 MathGridInset grabSelection() const;
270 /// erase the selected part and re-sets the cursor
271 void eraseSelection();
273 MathGridInset grabAndEraseSelection();
275 /// the name of the macro we are currently inputting
276 string macroName() const;
277 /// where in the curent cell does the macro name start?
278 MathInset::difference_type macroNamePos() const;
279 /// can we enter the inset?
280 bool openable(MathAtom const &, bool selection) const;
281 /// write access to cursor cell position
283 /// write access to cursor cell index
286 /// path of positions the cursor had to go if it were leaving each inset
287 MathIterator Cursor_;
288 /// path of positions the anchor had to go if it were leaving each inset
289 mutable MathIterator Anchor_;
290 /// pointer to enclsing LyX inset
291 InsetFormulaBase * formula_;
293 /// text code of last char entered
294 //MathTextCodes lastcode_;
295 /// do we allow autocorrection
297 /// do we currently select
299 /// are we entering a macro name?
301 /// are we targeting a certain x coordinate, if so, which one?
305 extern MathCursor * mathcursor;
306 void releaseMathCursor(BufferView * bv);