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 handleDelim(string const & l, string const & r);
170 void handleNest(MathInset * p);
171 /// splits cells and shifts right part to the next cell
173 /// splits line and insert new row of cell
175 /// read contents of line into an array
176 void readLine(MathArray & ar) const;
177 /// remove this as soon as LyXFunc::getStatus is "localized"
178 string getLastCode() const { return "mathnormal"; }
180 void pullArg(bool goright);
182 bool isInside(MathInset const *) const;
188 col_type hullCol() const;
190 row_type hullRow() const;
192 col_type gridCol() const;
194 row_type gridRow() const;
196 /// make sure cursor position is valid
198 /// mark current cursor trace for redraw
201 UpdatableInset * asHyperActiveInset() const;
203 /// enter a MathInset
204 void push(MathAtom & par);
205 /// enter a MathInset from the front
206 void pushLeft(MathAtom & par);
207 /// enter a MathInset from the back
208 void pushRight(MathAtom & par);
209 /// leave current MathInset to the left
211 /// leave current MathInset to the left
215 MathArray & array() const;
217 MathXArray & xarray() const;
219 bool hasPrevAtom() const;
221 bool hasNextAtom() const;
223 MathAtom const & prevAtom() const;
225 MathAtom & prevAtom();
227 MathAtom const & nextAtom() const;
229 MathAtom & nextAtom();
231 /// returns the selection
232 void getSelection(MathCursorPos &, MathCursorPos &) const;
233 /// returns the normalized anchor of the selection
234 MathCursorPos normalAnchor() const;
236 /// reference to the last item of the path, i.e. "The Cursor"
237 MathCursorPos & cursor();
238 /// reference to the last item of the path, i.e. "The Cursor"
239 MathCursorPos const & cursor() const;
240 /// how deep are we nested?
241 unsigned depth() const;
244 int dispatch(string const & cmd);
245 /// describe the situation
247 /// dump selection information for debugging
248 void seldump(char const * str) const;
249 /// dump selection information for debugging
250 void dump(char const * str) const;
252 void setSelection(cursor_type const & where, size_type n);
256 void insert(string const & str);
257 /// lock/unlock inset
260 /// hack for reveal codes
263 void handleExtern(string const & arg);
266 friend class Selection;
270 /// moves cursor index one cell to the left
272 /// moves cursor index one cell to the right
274 /// moves cursor to beginning first cell of current line
276 /// moves cursor to end of last cell of current line
278 /// moves cursor position one cell to the left
280 /// moves cursor position one cell to the right
282 /// moves position somehow up or down
283 bool goUpDown(bool up);
284 /// moves position into box
285 bool bruteFind(int xo, int yo, int xlow, int xhigh, int ylow, int yhigh);
288 /// grab grid marked by anchor and current cursor
289 MathGridInset grabSelection() const;
290 /// erase the selected part and re-sets the cursor
291 void eraseSelection();
293 MathGridInset grabAndEraseSelection();
296 string macroName() const;
298 MathInset::difference_type macroNamePos() const;
299 /// can we enter the inset?
300 bool openable(MathAtom const &, bool selection) const;
301 /// write access to cursor cell position
303 /// write access to cursor cell index
306 /// path of positions the cursor had to go if it were leaving each inset
308 /// path of positions the anchor had to go if it were leaving each inset
309 mutable cursor_type Anchor_;
310 /// pointer to enclsing LyX inset
311 InsetFormulaBase * formula_;
313 /// text code of last char entered
314 //MathTextCodes lastcode_;
315 /// do we allow autocorrection
317 /// do we currently select
319 /// are we entering a macro name?
321 /// are we targeting a certain x coordinate, if so, which one?
325 extern MathCursor * mathcursor;