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);
117 /// adjust position after deletion/insertion
118 void adjust(pos_type from, size_type size);
120 InsetFormulaBase * formula() const;
121 /// current offset in the current cell
122 pos_type pos() const;
124 idx_type idx() const;
125 /// size of current cell
126 size_type size() const;
130 bool interpret(char);
131 /// interpret name a name of a macro
132 void macroModeClose();
133 /// are we currently typing the name of a macro?
134 bool inMacroMode() const;
135 /// get access to the macro we are currently typing
136 MathUnknownInset * activeMacro();
137 /// get access to the macro we are currently typing
138 MathUnknownInset const * activeMacro() const;
139 /// are we currently typing '#1' or '#2' or...?
140 bool inMacroArgMode() const;
141 /// are we in math mode (1), text mode (-1) or unsure?
142 MathInset::mode_type currentMode() const;
144 // Local selection methods
146 bool selection() const;
156 void selHandle(bool);
161 /// clears or deletes selection depending on lyxrc setting
162 void selClearOrDel();
163 /// draws light-blue selection background
164 void drawSelection(MathPainterInfo & pi) const;
166 void handleNest(MathAtom const & at);
167 /// remove this as soon as LyXFunc::getStatus is "localized"
168 string getLastCode() const { return "mathnormal"; }
170 bool isInside(MathInset const *) const;
176 /// make sure cursor position is valid
178 /// mark current cursor trace for redraw
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 bool hasPrevAtom() const;
199 bool hasNextAtom() const;
201 MathAtom const & prevAtom() const;
203 MathAtom & prevAtom();
205 MathAtom const & nextAtom() const;
207 MathAtom & nextAtom();
209 /// returns the selection
210 void getSelection(MathCursorPos &, MathCursorPos &) const;
211 /// returns the normalized anchor of the selection
212 MathCursorPos normalAnchor() const;
214 /// reference to the last item of the path, i.e. "The Cursor"
215 MathCursorPos & cursor();
216 /// reference to the last item of the path, i.e. "The Cursor"
217 MathCursorPos const & cursor() const;
218 /// how deep are we nested?
219 unsigned depth() const;
222 MathInset::result_type dispatch(FuncRequest const & cmd);
223 /// describe the situation
225 /// dump selection information for debugging
226 void seldump(char const * str) const;
227 /// dump selection information for debugging
228 void dump(char const * str) const;
230 void setSelection(MathIterator const & where, size_type n);
231 /// grab selection marked by anchor and current cursor
232 string grabSelection() const;
236 void insert(string const & str);
237 /// lock/unlock inset
240 /// hack for reveal codes
243 /// injects content of a cell into parent
245 /// split font inset etc
246 void handleFont(string const & font);
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 /// erase the selected part and re-sets the cursor
269 void eraseSelection();
271 string grabAndEraseSelection();
273 /// the name of the macro we are currently inputting
274 string macroName() const;
275 /// where in the curent cell does the macro name start?
276 MathInset::difference_type macroNamePos() const;
277 /// can we enter the inset?
278 bool openable(MathAtom const &, bool selection) const;
279 /// write access to cursor cell position
281 /// write access to cursor cell index
284 /// path of positions the cursor had to go if it were leaving each inset
285 MathIterator Cursor_;
286 /// path of positions the anchor had to go if it were leaving each inset
287 mutable MathIterator Anchor_;
288 /// pointer to enclsing LyX inset
289 InsetFormulaBase * formula_;
291 /// text code of last char entered
292 //MathTextCodes lastcode_;
293 /// do we allow autocorrection
295 /// do we currently select
297 /// are we entering a macro name?
299 /// are we targeting a certain x coordinate, if so, which one?
303 extern MathCursor * mathcursor;
304 void releaseMathCursor(BufferView * bv);