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;
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 MathCursorPos, 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;
59 explicit MathCursor(InsetFormulaBase *, bool left);
63 void insert(MathAtom const &);
65 void insert(MathArray const &);
67 void paste(string const & data);
72 /// called for LFUN_HOME etc
73 bool home(bool sel = false);
74 /// called for LFUN_END etc
75 bool 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 &);
99 void niceInsert(string 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) const;
105 /// in pixels from left of screen
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 /// go up to enclosing grid
112 void popToEnclosingGrid();
113 /// go up to the hull inset
114 void popToEnclosingHull();
115 /// go up to the hull inset
116 void popToHere(MathInset const * p);
118 InsetFormulaBase * formula() const;
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(char);
129 /// interpret name a name of a macro
130 void macroModeClose();
131 /// are we currently typing the name of a macro?
132 bool inMacroMode() const;
133 /// get access to the macro we are currently typing
134 MathUnknownInset * activeMacro();
135 /// get access to the macro we are currently typing
136 MathUnknownInset const * activeMacro() const;
137 /// are we currently typing '#1' or '#2' or...?
138 bool inMacroArgMode() const;
139 /// are we in math mode (1), text mode (-1) or unsure?
140 MathInset::mode_type currentMode() 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();
161 /// draws light-blue selection background
162 void drawSelection(MathPainterInfo & pi) const;
164 void handleNest(MathAtom const & at);
165 /// remove this as soon as LyXFunc::getStatus is "localized"
166 string getLastCode() const { return "mathnormal"; }
168 bool isInside(MathInset const *) const;
174 /// make sure cursor position is valid
176 /// mark current cursor trace for redraw
179 UpdatableInset * asHyperActiveInset() const;
181 /// enter a MathInset
182 void push(MathAtom & par);
183 /// enter a MathInset from the front
184 void pushLeft(MathAtom & par);
185 /// enter a MathInset from the back
186 void pushRight(MathAtom & par);
187 /// leave current MathInset to the left
189 /// leave current MathInset to the left
193 MathArray & array() const;
195 bool hasPrevAtom() const;
197 bool hasNextAtom() const;
199 MathAtom const & prevAtom() const;
201 MathAtom & prevAtom();
203 MathAtom const & nextAtom() const;
205 MathAtom & nextAtom();
207 /// returns the selection
208 void getSelection(MathCursorPos &, MathCursorPos &) const;
209 /// returns the normalized anchor of the selection
210 MathCursorPos normalAnchor() const;
212 /// reference to the last item of the path, i.e. "The Cursor"
213 MathCursorPos & cursor();
214 /// reference to the last item of the path, i.e. "The Cursor"
215 MathCursorPos const & cursor() const;
216 /// how deep are we nested?
217 unsigned depth() const;
220 MathInset::result_type dispatch(FuncRequest const & cmd);
221 /// describe the situation
223 /// dump selection information for debugging
224 void seldump(char const * str) const;
225 /// dump selection information for debugging
226 void dump(char const * str) const;
228 void setSelection(MathIterator const & where, size_type n);
229 /// grab selection marked by anchor and current cursor
230 string grabSelection() const;
234 void insert(string const & str);
235 /// lock/unlock inset
238 /// hack for reveal codes
241 //void handleExtern(string const & arg);
244 /// injects content of a cell into parent
246 /// moves cursor index one cell to the left
248 /// moves cursor index one cell to the right
250 /// moves cursor to end of last cell of current line
252 /// moves cursor position one cell to the left
254 /// moves cursor position one cell to the right
256 /// moves position somehow up or down
257 bool goUpDown(bool up);
258 /// moves position closest to (x, y) in given box
259 bool bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh);
260 /// moves position closest to (x, y) in current cell
261 void bruteFind2(int x, int y);
262 /// are we in a nucleus of a script inset?
263 bool inNucleus() const;
265 /// erase the selected part and re-sets the cursor
266 void eraseSelection();
268 string grabAndEraseSelection();
270 /// the name of the macro we are currently inputting
271 string macroName() const;
272 /// where in the curent cell does the macro name start?
273 MathInset::difference_type macroNamePos() const;
274 /// can we enter the inset?
275 bool openable(MathAtom const &, bool selection) const;
276 /// write access to cursor cell position
278 /// write access to cursor cell index
281 /// path of positions the cursor had to go if it were leaving each inset
282 MathIterator Cursor_;
283 /// path of positions the anchor had to go if it were leaving each inset
284 mutable MathIterator Anchor_;
285 /// pointer to enclsing LyX inset
286 InsetFormulaBase * formula_;
288 /// text code of last char entered
289 //MathTextCodes lastcode_;
290 /// do we allow autocorrection
292 /// do we currently select
294 /// are we entering a macro name?
296 /// are we targeting a certain x coordinate, if so, which one?
300 extern MathCursor * mathcursor;
301 void releaseMathCursor(BufferView * bv);