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.
21 #include "math_inset.h"
22 #include "math_iterator.h"
25 class InsetFormulaBase;
28 class MathUnknownInset;
32 [Have a look at math_inset.h first]
34 The MathCursor is different from the kind of cursor used in the Outer
35 World. It contains a stack of CursorPos, each of which is made
36 up of a inset pointer, an index and a position offset, marking a path from
37 this formula's MathHullInset to the current position.
44 /// short of anything else reasonable
45 typedef MathInset::size_type size_type;
46 /// type for column numbers
47 typedef MathArray::difference_type difference_type;
48 /// type for cursor positions within a cell
49 typedef MathInset::pos_type pos_type;
50 /// type for cell indices
51 typedef MathInset::idx_type idx_type;
52 /// type for row numbers
53 typedef MathInset::row_type row_type;
54 /// type for column numbers
55 typedef MathInset::col_type col_type;
58 explicit MathCursor(InsetFormulaBase *, bool left);
62 void insert(MathAtom const &);
64 void insert(MathArray const &);
66 void insert2(string const &);
68 void paste(string const & data);
69 /// return false for empty math insets
71 /// return false for empty math insets
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 void niceInsert(string const &);
102 /// in pixels from top of screen
103 void setPos(int x, int y);
104 /// in pixels from top of screen
105 void getPos(int & x, int & y) const;
106 /// in pixels from left of screen
109 MathInset * inset() const;
110 /// return the next enclosing grid inset and the cursor's index in it
111 MathGridInset * enclosingGrid(idx_type & idx) const;
112 /// go up to enclosing grid
113 void popToEnclosingGrid();
114 /// go up to the hull inset
115 void popToEnclosingHull();
116 /// go up to the hull inset
117 void popToHere(MathInset const * p);
118 /// adjust anchor position after deletions/insertions
119 void adjust(pos_type from, difference_type diff);
121 InsetFormulaBase * formula() const;
122 /// current offset in the current cell
123 pos_type pos() const;
125 idx_type idx() const;
126 /// size of current cell
127 size_type size() const;
131 bool interpret(char);
132 /// interpret name a name of a macro
133 void macroModeClose();
134 /// are we currently typing the name of a macro?
135 bool inMacroMode() const;
136 /// get access to the macro we are currently typing
137 MathUnknownInset * activeMacro();
138 /// get access to the macro we are currently typing
139 MathUnknownInset const * activeMacro() const;
140 /// are we currently typing '#1' or '#2' or...?
141 bool inMacroArgMode() const;
142 /// are we in math mode (1), text mode (-1) or unsure?
143 MathInset::mode_type currentMode() const;
145 // Local selection methods
147 bool selection() const;
154 /// pastes n-th element of cut buffer
155 void selPaste(size_t n);
157 void selHandle(bool);
162 /// clears or deletes selection depending on lyxrc setting
163 void selClearOrDel();
164 /// draws light-blue selection background
165 void drawSelection(PainterInfo & pi) const;
167 void handleNest(MathAtom const & at);
168 /// remove this as soon as LyXFunc::getStatus is "localized"
169 string getLastCode() const { return "mathnormal"; }
171 bool isInside(MathInset const *) const;
177 /// make sure cursor position is valid
179 /// mark current cursor trace for redraw
182 UpdatableInset * asHyperActiveInset() const;
184 /// enter a MathInset
185 void push(MathAtom & par);
186 /// enter a MathInset from the front
187 void pushLeft(MathAtom & par);
188 /// enter a MathInset from the back
189 void pushRight(MathAtom & par);
190 /// leave current MathInset to the left
192 /// leave current MathInset to the left
196 MathArray & array() const;
198 bool hasPrevAtom() const;
200 bool hasNextAtom() const;
202 MathAtom const & prevAtom() const;
204 MathAtom & prevAtom();
206 MathAtom const & nextAtom() const;
208 MathAtom & nextAtom();
210 /// returns the selection
211 void getSelection(CursorPos &, CursorPos &) const;
212 /// returns the normalized anchor of the selection
213 CursorPos normalAnchor() const;
215 /// reference to the last item of the path, i.e. "The Cursor"
216 CursorPos & cursor();
217 /// reference to the last item of the path, i.e. "The Cursor"
218 CursorPos const & cursor() const;
219 /// how deep are we nested?
220 unsigned depth() const;
223 dispatch_result dispatch(FuncRequest const & cmd);
224 /// describe the situation
226 /// dump selection information for debugging
227 void seldump(char const * str) const;
228 /// dump selection information for debugging
229 void dump(char const * str) const;
231 void setSelection(MathIterator const & where, size_type n);
232 /// grab selection marked by anchor and current cursor
233 string grabSelection() const;
235 string grabAndEraseSelection();
239 void insert(string const & str);
240 /// lock/unlock inset
243 /// hack for reveal codes
246 /// injects content of a cell into parent
248 /// split font inset etc
249 void handleFont(string const & font);
252 /// moves cursor index one cell to the left
254 /// moves cursor index one cell to the right
256 /// moves cursor to end of last cell of current line
258 /// moves cursor position one cell to the left
260 /// moves cursor position one cell to the right
262 /// moves position somehow up or down
263 bool goUpDown(bool up);
264 /// moves position closest to (x, y) in given box
265 bool bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh);
266 /// moves position closest to (x, y) in current cell
267 void bruteFind2(int x, int y);
268 /// are we in a nucleus of a script inset?
269 bool inNucleus() const;
271 /// erase the selected part and re-sets the cursor
272 void eraseSelection();
274 /// the name of the macro we are currently inputting
275 string macroName() const;
276 /// where in the curent cell does the macro name start?
277 difference_type macroNamePos() const;
278 /// can we enter the inset?
279 bool openable(MathAtom const &, bool selection) const;
280 /// write access to cursor cell position
282 /// write access to cursor cell index
285 /// path of positions the cursor had to go if it were leaving each inset
286 MathIterator Cursor_;
287 /// path of positions the anchor had to go if it were leaving each inset
288 mutable MathIterator Anchor_;
289 /// pointer to enclsing LyX inset
290 InsetFormulaBase * formula_;
292 /// text code of last char entered
293 //MathTextCodes lastcode_;
294 /// do we allow autocorrection
296 /// do we currently select
298 /// are we entering a macro name?
300 /// are we targeting a certain x coordinate, if so, which one?
304 extern MathCursor * mathcursor;
305 void releaseMathCursor(BufferView * bv);