4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Alejandro Aguilar Sierra
10 * Full author contact details are available in file CREDITS.
17 #include "math_inset.h"
18 #include "math_iterator.h"
21 class InsetFormulaBase;
24 class MathUnknownInset;
28 [Have a look at math_inset.h first]
30 The MathCursor is different from the kind of cursor used in the Outer
31 World. It contains a stack of CursorPos, each of which is made
32 up of a inset pointer, an index and a position offset, marking a path from
33 this formula's MathHullInset to the current position.
40 /// short of anything else reasonable
41 typedef MathInset::size_type size_type;
42 /// type for column numbers
43 typedef MathArray::difference_type difference_type;
44 /// type for cursor positions within a cell
45 typedef MathInset::pos_type pos_type;
46 /// type for cell indices
47 typedef MathInset::idx_type idx_type;
48 /// type for row numbers
49 typedef MathInset::row_type row_type;
50 /// type for column numbers
51 typedef MathInset::col_type col_type;
54 explicit MathCursor(InsetFormulaBase *, bool left);
58 void insert(MathAtom const &);
60 void insert(MathArray const &);
62 void insert2(string const &);
64 void paste(string const & data);
65 /// return false for empty math insets
67 /// return false for empty math insets
69 /// called for LFUN_HOME etc
70 bool home(bool sel = false);
71 /// called for LFUN_END etc
72 bool end(bool sel = false);
73 /// called for LFUN_RIGHT and LFUN_RIGHTSEL
74 bool right(bool sel = false);
75 /// called for LFUN_LEFT etc
76 bool left(bool sel = false);
77 /// called for LFUN_UP etc
78 bool up(bool sel = false);
79 /// called for LFUN_DOWN etc
80 bool down(bool sel = false);
81 /// Put the cursor in the first position
83 /// Put the cursor in the last position
85 /// move to next cell in current inset
87 /// move to previous cell in current inset
92 void plainInsert(MathAtom const &);
94 void niceInsert(MathAtom const &);
96 void niceInsert(string const &);
98 /// in pixels from top of screen
99 void setPos(int x, int y);
100 /// in pixels from top of screen
101 void getPos(int & x, int & y) const;
102 /// in pixels from left of screen
105 MathInset * inset() const;
106 /// return the next enclosing grid inset and the cursor's index in it
107 MathGridInset * enclosingGrid(idx_type & idx) const;
108 /// go up to enclosing grid
109 void popToEnclosingGrid();
110 /// go up to the hull inset
111 void popToEnclosingHull();
112 /// go up to the hull inset
113 void popToHere(MathInset const * p);
114 /// adjust anchor position after deletions/insertions
115 void adjust(pos_type from, difference_type diff);
117 InsetFormulaBase * formula() const;
118 /// current offset in the current cell
119 pos_type pos() const;
121 idx_type idx() const;
122 /// size of current cell
123 size_type size() const;
127 bool interpret(char);
128 /// interpret name a name of a macro
129 void macroModeClose();
130 /// are we currently typing the name of a macro?
131 bool inMacroMode() const;
132 /// get access to the macro we are currently typing
133 MathUnknownInset * activeMacro();
134 /// get access to the macro we are currently typing
135 MathUnknownInset const * activeMacro() const;
136 /// are we currently typing '#1' or '#2' or...?
137 bool inMacroArgMode() const;
138 /// are we in math mode (1), text mode (-1) or unsure?
139 MathInset::mode_type currentMode() const;
141 // Local selection methods
143 bool selection() const;
150 /// pastes n-th element of cut buffer
151 void selPaste(size_t n);
153 void selHandle(bool);
158 /// clears or deletes selection depending on lyxrc setting
159 void selClearOrDel();
160 /// draws light-blue selection background
161 void drawSelection(PainterInfo & pi) const;
163 void handleNest(MathAtom const & at);
164 /// remove this as soon as LyXFunc::getStatus is "localized"
165 string getLastCode() const { return "mathnormal"; }
167 bool isInside(MathInset const *) const;
173 /// make sure cursor position is valid
175 /// mark current cursor trace for redraw
178 UpdatableInset * asHyperActiveInset() const;
180 /// enter a MathInset
181 void push(MathAtom & par);
182 /// enter a MathInset from the front
183 void pushLeft(MathAtom & par);
184 /// enter a MathInset from the back
185 void pushRight(MathAtom & par);
186 /// leave current MathInset to the left
188 /// leave current MathInset to the left
192 MathArray & array() const;
194 bool hasPrevAtom() const;
196 bool hasNextAtom() const;
198 MathAtom const & prevAtom() const;
200 MathAtom & prevAtom();
202 MathAtom const & nextAtom() const;
204 MathAtom & nextAtom();
206 /// returns the selection
207 void getSelection(CursorPos &, CursorPos &) const;
208 /// returns the normalized anchor of the selection
209 CursorPos normalAnchor() const;
211 /// reference to the last item of the path, i.e. "The Cursor"
212 CursorPos & cursor();
213 /// reference to the last item of the path, i.e. "The Cursor"
214 CursorPos const & cursor() const;
215 /// how deep are we nested?
216 unsigned depth() const;
219 dispatch_result dispatch(FuncRequest const & cmd);
220 /// describe the situation
222 /// dump selection information for debugging
223 void seldump(char const * str) const;
224 /// dump selection information for debugging
225 void dump(char const * str) const;
227 void setSelection(MathIterator const & where, size_type n);
228 /// grab selection marked by anchor and current cursor
229 string grabSelection() const;
231 string grabAndEraseSelection();
235 void insert(string const & str);
236 /// lock/unlock inset
239 /// hack for reveal codes
242 /// injects content of a cell into parent
244 /// split font inset etc
245 void handleFont(string const & font);
248 /// moves cursor index one cell to the left
250 /// moves cursor index one cell to the right
252 /// moves cursor to end of last cell of current line
254 /// moves cursor position one cell to the left
256 /// moves cursor position one cell to the right
258 /// moves position somehow up or down
259 bool goUpDown(bool up);
260 /// moves position closest to (x, y) in given box
261 bool bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh);
262 /// moves position closest to (x, y) in current cell
263 void bruteFind2(int x, int y);
264 /// are we in a nucleus of a script inset?
265 bool inNucleus() const;
267 /// erase the selected part and re-sets the cursor
268 void eraseSelection();
270 /// the name of the macro we are currently inputting
271 string macroName() const;
272 /// where in the curent cell does the macro name start?
273 difference_type macroNamePos() const;
274 /// can we enter the inset?
275 bool openable(MathAtom const &, bool selection) const;
276 /// write access to cursor cell position
278 /// write access to cursor cell index
281 /// path of positions the cursor had to go if it were leaving each inset
282 MathIterator Cursor_;
283 /// path of positions the anchor had to go if it were leaving each inset
284 mutable MathIterator Anchor_;
285 /// pointer to enclsing LyX inset
286 InsetFormulaBase * formula_;
288 /// text code of last char entered
289 //MathTextCodes lastcode_;
290 /// do we allow autocorrection
292 /// do we currently select
294 /// are we entering a macro name?
296 /// are we targeting a certain x coordinate, if so, which one?
300 extern MathCursor * mathcursor;
301 void releaseMathCursor(BufferView * bv);