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(MathArray const &);
70 void paste(MathGridInset const & data);
75 /// called for LFUN_HOME etc
76 bool home(bool sel = false);
77 /// called for LFUN_END etc
78 bool end(bool sel = false);
79 /// called for LFUN_RIGHT and LFUN_RIGHTSEL
80 bool right(bool sel = false);
81 /// called for LFUN_LEFT etc
82 bool left(bool sel = false);
83 /// called for LFUN_UP etc
84 bool up(bool sel = false);
85 /// called for LFUN_DOWN etc
86 bool down(bool sel = false);
87 /// Put the cursor in the first position
89 /// Put the cursor in the last position
91 /// move to next cell in current inset
93 /// move to previous cell in current inset
98 void plainInsert(MathAtom const &);
100 void niceInsert(MathAtom const &);
104 /// in pixels from top of screen
105 void setPos(int x, int y);
106 /// in pixels from top of screen
107 void getPos(int & x, int & y);
109 MathInset * par() const;
110 /// return the next enclosing grid inset and the cursor's index in it
111 MathGridInset * enclosingGrid(idx_type & idx) const;
112 /// return the next enclosing hull inset and the cursor's index in it
113 MathHullInset * enclosingHull(idx_type & idx) const;
114 /// go up to enclosing grid
115 void popToEnclosingGrid();
116 /// go up to the hull inset
117 void popToEnclosingHull();
119 InsetFormulaBase * formula() const;
120 /// current offset in the current cell
121 pos_type pos() const;
123 idx_type idx() const;
124 /// size of current cell
125 size_type size() const;
129 bool interpret(string const &);
131 bool interpret(char);
134 /// interpret name a name of a macro
135 void macroModeClose();
136 /// are we currently typing the name of a macro?
137 bool inMacroMode() const;
138 /// get access to the macro we are currently typing
139 MathUnknownInset * activeMacro();
140 /// get access to the macro we are currently typing
141 MathUnknownInset const * activeMacro() const;
142 /// are we currently typing '#1' or '#2' or...?
143 bool inMacroArgMode() const;
144 /// are we in math mode (1), text mode (-1) or unsure?
145 MathInset::mode_type currentMode() const;
147 // Local selection methods
149 bool selection() const;
159 void selHandle(bool);
164 /// clears or deletes selection depending on lyxrc setting
165 void selClearOrDel();
167 void selGet(MathArray & ar);
169 void drawSelection(MathPainterInfo & pain) const;
171 void handleNest(MathAtom const & at);
172 /// splits cells and shifts right part to the next cell
174 /// splits line and insert new row of cell
176 /// read contents of line into an array
177 void readLine(MathArray & ar) const;
178 /// remove this as soon as LyXFunc::getStatus is "localized"
179 string getLastCode() const { return "mathnormal"; }
181 bool isInside(MathInset const *) const;
187 col_type hullCol() const;
189 row_type hullRow() const;
191 col_type gridCol() const;
193 row_type gridRow() const;
195 /// make sure cursor position is valid
197 /// mark current cursor trace for redraw
200 UpdatableInset * asHyperActiveInset() const;
202 /// enter a MathInset
203 void push(MathAtom & par);
204 /// enter a MathInset from the front
205 void pushLeft(MathAtom & par);
206 /// enter a MathInset from the back
207 void pushRight(MathAtom & par);
208 /// leave current MathInset to the left
210 /// leave current MathInset to the left
214 MathArray & array() const;
216 bool hasPrevAtom() const;
218 bool hasNextAtom() const;
220 MathAtom const & prevAtom() const;
222 MathAtom & prevAtom();
224 MathAtom const & nextAtom() const;
226 MathAtom & nextAtom();
228 /// returns the selection
229 void getSelection(MathCursorPos &, MathCursorPos &) const;
230 /// returns the normalized anchor of the selection
231 MathCursorPos normalAnchor() const;
233 /// reference to the last item of the path, i.e. "The Cursor"
234 MathCursorPos & cursor();
235 /// reference to the last item of the path, i.e. "The Cursor"
236 MathCursorPos const & cursor() const;
237 /// how deep are we nested?
238 unsigned depth() const;
241 int dispatch(FuncRequest const & cmd);
242 /// describe the situation
244 /// dump selection information for debugging
245 void seldump(char const * str) const;
246 /// dump selection information for debugging
247 void dump(char const * str) const;
249 void setSelection(MathIterator const & where, size_type n);
253 void insert(string const & str);
254 /// lock/unlock inset
257 /// hack for reveal codes
260 void handleExtern(string const & arg);
263 friend class Selection;
267 /// injects content of a cell into parent
269 /// moves cursor index one cell to the left
271 /// moves cursor index one cell to the right
273 /// moves cursor to beginning first cell of current line
275 /// moves cursor to end of last cell of current line
277 /// moves cursor position one cell to the left
279 /// moves cursor position one cell to the right
281 /// moves position somehow up or down
282 bool goUpDown(bool up);
283 /// moves position into box
284 bool bruteFind(int xo, int yo, int xlow, int xhigh, int ylow, int yhigh);
285 /// are we in a nucleus of a script inset?
286 bool inNucleus() const;
289 /// grab grid marked by anchor and current cursor
290 MathGridInset grabSelection() const;
291 /// erase the selected part and re-sets the cursor
292 void eraseSelection();
294 MathGridInset grabAndEraseSelection();
297 string macroName() const;
299 MathInset::difference_type macroNamePos() const;
300 /// can we enter the inset?
301 bool openable(MathAtom const &, bool selection) const;
302 /// write access to cursor cell position
304 /// write access to cursor cell index
307 /// path of positions the cursor had to go if it were leaving each inset
308 MathIterator Cursor_;
309 /// path of positions the anchor had to go if it were leaving each inset
310 mutable MathIterator Anchor_;
311 /// pointer to enclsing LyX inset
312 InsetFormulaBase * formula_;
314 /// text code of last char entered
315 //MathTextCodes lastcode_;
316 /// do we allow autocorrection
318 /// do we currently select
320 /// are we entering a macro name?
322 /// are we targeting a certain x coordinate, if so, which one?
326 extern MathCursor * mathcursor;
327 void releaseMathCursor(BufferView * bv);