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"
28 class InsetFormulaBase;
29 class MathPainterInfo;
30 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 MathCursorPositions, 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;
57 /// how to store a cursor
58 typedef std::vector<MathCursorPos> cursor_type;
61 explicit MathCursor(InsetFormulaBase *, bool left);
65 void insert(MathAtom const &);
67 void insert(MathArray const &);
69 void paste(MathArray const &);
71 void paste(MathGridInset const & data);
76 /// called for LFUN_HOME etc
77 void home(bool sel = false);
78 /// called for LFUN_END etc
79 void end(bool sel = false);
80 /// called for LFUN_RIGHT and LFUN_RIGHTSEL
81 bool right(bool sel = false);
82 /// called for LFUN_LEFT etc
83 bool left(bool sel = false);
84 /// called for LFUN_UP etc
85 bool up(bool sel = false);
86 /// called for LFUN_DOWN etc
87 bool down(bool sel = false);
88 /// Put the cursor in the first position
90 /// Put the cursor in the last position
92 /// move to next cell in current inset
94 /// move to previous cell in current inset
99 void plainInsert(MathAtom const &);
101 void niceInsert(MathAtom const &);
105 /// in pixels from top of screen
106 void setPos(int x, int y);
107 /// in pixels from top of screen
108 void getPos(int & x, int & y);
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 /// return the next enclosing hull inset and the cursor's index in it
114 MathHullInset * enclosingHull(idx_type & idx) const;
115 /// go up to enclosing grid
116 void popToEnclosingGrid();
117 /// go up to the hull inset
118 void popToEnclosingHull();
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(string const &);
132 bool interpret(char);
135 /// interpret name a name of a macro
136 void macroModeClose();
137 /// are we currently typing the name of a macro?
138 MathUnknownInset * inMacroMode() const;
139 /// are we currently typing '#1' or '#2' or...?
140 bool inMacroArgMode() const;
141 /// are we in an mbox?
142 bool inMathMode() 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();
164 void selGet(MathArray & ar);
166 void drawSelection(MathPainterInfo & pain) const;
168 void handleNest(MathAtom const & at);
169 /// splits cells and shifts right part to the next cell
171 /// splits line and insert new row of cell
173 /// read contents of line into an array
174 void readLine(MathArray & ar) const;
175 /// remove this as soon as LyXFunc::getStatus is "localized"
176 string getLastCode() const { return "mathnormal"; }
178 void pullArg(bool goright);
180 bool isInside(MathInset const *) const;
186 col_type hullCol() const;
188 row_type hullRow() const;
190 col_type gridCol() const;
192 row_type gridRow() const;
194 /// make sure cursor position is valid
196 /// mark current cursor trace for redraw
199 UpdatableInset * asHyperActiveInset() const;
201 /// enter a MathInset
202 void push(MathAtom & par);
203 /// enter a MathInset from the front
204 void pushLeft(MathAtom & par);
205 /// enter a MathInset from the back
206 void pushRight(MathAtom & par);
207 /// leave current MathInset to the left
209 /// leave current MathInset to the left
213 MathArray & array() const;
215 MathXArray & xarray() const;
217 bool hasPrevAtom() const;
219 bool hasNextAtom() const;
221 MathAtom const & prevAtom() const;
223 MathAtom & prevAtom();
225 MathAtom const & nextAtom() const;
227 MathAtom & nextAtom();
229 /// returns the selection
230 void getSelection(MathCursorPos &, MathCursorPos &) const;
231 /// returns the normalized anchor of the selection
232 MathCursorPos normalAnchor() const;
234 /// reference to the last item of the path, i.e. "The Cursor"
235 MathCursorPos & cursor();
236 /// reference to the last item of the path, i.e. "The Cursor"
237 MathCursorPos const & cursor() const;
238 /// how deep are we nested?
239 unsigned depth() const;
242 int dispatch(string const & cmd);
243 /// describe the situation
245 /// dump selection information for debugging
246 void seldump(char const * str) const;
247 /// dump selection information for debugging
248 void dump(char const * str) const;
250 void setSelection(cursor_type const & where, size_type n);
254 void insert(string const & str);
255 /// lock/unlock inset
258 /// hack for reveal codes
261 void handleExtern(string const & arg);
264 friend class Selection;
268 /// moves cursor index one cell to the left
270 /// moves cursor index one cell to the right
272 /// moves cursor to beginning first cell of current line
274 /// moves cursor to end of last cell of current line
276 /// moves cursor position one cell to the left
278 /// moves cursor position one cell to the right
280 /// moves position somehow up or down
281 bool goUpDown(bool up);
282 /// moves position into box
283 bool bruteFind(int xo, int yo, int xlow, int xhigh, int ylow, int yhigh);
286 /// grab grid marked by anchor and current cursor
287 MathGridInset grabSelection() const;
288 /// erase the selected part and re-sets the cursor
289 void eraseSelection();
291 MathGridInset grabAndEraseSelection();
294 string macroName() const;
296 MathInset::difference_type macroNamePos() const;
297 /// can we enter the inset?
298 bool openable(MathAtom const &, bool selection) const;
299 /// write access to cursor cell position
301 /// write access to cursor cell index
304 /// path of positions the cursor had to go if it were leaving each inset
306 /// path of positions the anchor had to go if it were leaving each inset
307 mutable cursor_type Anchor_;
308 /// pointer to enclsing LyX inset
309 InsetFormulaBase * formula_;
311 /// text code of last char entered
312 //MathTextCodes lastcode_;
313 /// do we allow autocorrection
315 /// do we currently select
317 /// are we entering a macro name?
319 /// are we targeting a certain x coordinate, if so, which one?
323 extern MathCursor * mathcursor;