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 column numbers
50 typedef MathArray::difference_type difference_type;
51 /// type for cursor positions within a cell
52 typedef MathInset::pos_type pos_type;
53 /// type for cell indices
54 typedef MathInset::idx_type idx_type;
55 /// type for row numbers
56 typedef MathInset::row_type row_type;
57 /// type for column numbers
58 typedef MathInset::col_type col_type;
61 explicit MathCursor(InsetFormulaBase *, bool left);
65 void insert(MathAtom const &);
67 void insert(MathArray const &);
69 void paste(string const & data);
74 /// called for LFUN_HOME etc
75 bool home(bool sel = false);
76 /// called for LFUN_END etc
77 bool 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 &);
101 void niceInsert(string 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) const;
107 /// in pixels from left of screen
110 MathInset * par() const;
111 /// return the next enclosing grid inset and the cursor's index in it
112 MathGridInset * enclosingGrid(idx_type & idx) const;
113 /// go up to enclosing grid
114 void popToEnclosingGrid();
115 /// go up to the hull inset
116 void popToEnclosingHull();
117 /// go up to the hull inset
118 void popToHere(MathInset const * p);
119 /// adjust anchor position after deletions/insertions
120 void adjust(pos_type from, difference_type diff);
122 InsetFormulaBase * formula() const;
123 /// current offset in the current cell
124 pos_type pos() const;
126 idx_type idx() const;
127 /// size of current cell
128 size_type size() const;
132 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 bool inMacroMode() const;
137 /// get access to the macro we are currently typing
138 MathUnknownInset * activeMacro();
139 /// get access to the macro we are currently typing
140 MathUnknownInset const * activeMacro() const;
141 /// are we currently typing '#1' or '#2' or...?
142 bool inMacroArgMode() const;
143 /// are we in math mode (1), text mode (-1) or unsure?
144 MathInset::mode_type currentMode() const;
146 // Local selection methods
148 bool selection() const;
158 void selHandle(bool);
163 /// clears or deletes selection depending on lyxrc setting
164 void selClearOrDel();
165 /// draws light-blue selection background
166 void drawSelection(MathPainterInfo & pi) const;
168 void handleNest(MathAtom const & at);
169 /// remove this as soon as LyXFunc::getStatus is "localized"
170 string getLastCode() const { return "mathnormal"; }
172 bool isInside(MathInset const *) const;
178 /// make sure cursor position is valid
180 /// mark current cursor trace for redraw
183 UpdatableInset * asHyperActiveInset() const;
185 /// enter a MathInset
186 void push(MathAtom & par);
187 /// enter a MathInset from the front
188 void pushLeft(MathAtom & par);
189 /// enter a MathInset from the back
190 void pushRight(MathAtom & par);
191 /// leave current MathInset to the left
193 /// leave current MathInset to the left
197 MathArray & array() 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 /// reference to the last item of the path, i.e. "The Cursor"
217 MathCursorPos & cursor();
218 /// reference to the last item of the path, i.e. "The Cursor"
219 MathCursorPos const & cursor() const;
220 /// how deep are we nested?
221 unsigned depth() const;
224 MathInset::result_type dispatch(FuncRequest const & cmd);
225 /// describe the situation
227 /// dump selection information for debugging
228 void seldump(char const * str) const;
229 /// dump selection information for debugging
230 void dump(char const * str) const;
232 void setSelection(MathIterator const & where, size_type n);
233 /// grab selection marked by anchor and current cursor
234 string grabSelection() const;
236 string grabAndEraseSelection();
240 void insert(string const & str);
241 /// lock/unlock inset
244 /// hack for reveal codes
247 /// injects content of a cell into parent
249 /// split font inset etc
250 void handleFont(string const & font);
253 /// moves cursor index one cell to the left
255 /// moves cursor index one cell to the right
257 /// moves cursor to end of last cell of current line
259 /// moves cursor position one cell to the left
261 /// moves cursor position one cell to the right
263 /// moves position somehow up or down
264 bool goUpDown(bool up);
265 /// moves position closest to (x, y) in given box
266 bool bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh);
267 /// moves position closest to (x, y) in current cell
268 void bruteFind2(int x, int y);
269 /// are we in a nucleus of a script inset?
270 bool inNucleus() const;
272 /// erase the selected part and re-sets the cursor
273 void eraseSelection();
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 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);