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.
16 #include "cursor_slice.h"
17 #include "math_inset.h"
18 #include "math_data.h"
22 class InsetFormulaBase;
25 class MathUnknownInset;
29 [Have a look at math_inset.h first]
31 The MathCursor is different from the kind of cursor used in the Outer
32 World. It contains a stack of CursorSlice, each of which is made
33 up of a inset pointer, an index and a position offset, marking a path from
34 this formula's MathHullInset to the current position.
41 /// short of anything else reasonable
42 typedef size_t size_type;
43 /// type for column numbers
44 typedef ptrdiff_t difference_type;
45 /// type for cursor positions within a cell
46 typedef lyx::pos_type pos_type;
47 /// type for cell indices
48 typedef size_t idx_type;
49 /// type for row numbers
50 typedef size_t row_type;
51 /// type for column numbers
52 typedef size_t col_type;
55 explicit MathCursor(BufferView *, InsetFormulaBase *, bool left);
59 void insert(MathAtom const &);
61 void insert(MathArray const &);
63 void insert2(std::string const &);
65 void paste(std::string const & data);
66 /// return false for empty math insets
68 /// return false for empty math insets
70 /// called for LFUN_HOME etc
71 bool home(bool sel = false);
72 /// called for LFUN_END etc
73 bool end(bool sel = false);
74 /// called for LFUN_RIGHT and LFUN_RIGHTSEL
75 bool right(bool sel = false);
76 /// called for LFUN_LEFT etc
77 bool left(bool sel = false);
78 /// called for LFUN_UP etc
79 bool up(bool sel = false);
80 /// called for LFUN_DOWN etc
81 bool down(bool sel = false);
82 /// Put the cursor in the first position
84 /// Put the cursor in the last position
86 /// move to next cell in current inset
88 /// move to previous cell in current inset
93 void plainInsert(MathAtom const &);
95 void niceInsert(MathAtom const &);
97 void niceInsert(std::string const &);
99 /// in pixels from top of screen
100 void setScreenPos(int x, int y);
101 /// in pixels from top of screen
102 void getScreenPos(int & x, int & y) const;
103 /// in pixels from left of screen
106 MathInset * inset() const;
107 /// return the next enclosing grid inset and the cursor's index in it
108 MathGridInset * enclosingGrid(idx_type & idx) const;
109 /// go up to enclosing grid
110 void popToEnclosingGrid();
111 /// go up to the hull inset
112 void popToEnclosingHull();
113 /// go up to the hull inset
114 void popToHere(MathInset const * p);
115 /// adjust anchor position after deletions/insertions
116 void adjust(pos_type from, difference_type diff);
118 InsetFormulaBase * formula() const;
119 /// current offset in the current cell
120 pos_type pos() const;
122 idx_type idx() const;
123 /// size of current cell
124 size_type size() const;
128 bool interpret(char);
129 /// interpret name a name of a macro
130 void macroModeClose();
131 /// are we currently typing the name of a macro?
132 bool inMacroMode() const;
133 /// get access to the macro we are currently typing
134 MathUnknownInset * activeMacro();
135 /// get access to the macro we are currently typing
136 MathUnknownInset const * activeMacro() const;
137 /// are we currently typing '#1' or '#2' or...?
138 bool inMacroArgMode() const;
139 /// are we in math mode (1), text mode (-1) or unsure?
140 MathInset::mode_type currentMode() const;
142 // Local selection methods
144 bool selection() const;
151 /// pastes n-th element of cut buffer
152 void selPaste(size_t n);
154 void selHandle(bool);
159 /// clears or deletes selection depending on lyxrc setting
160 void selClearOrDel();
161 /// draws light-blue selection background
162 void drawSelection(PainterInfo & pi) const;
163 /// replace selected stuff with at, placing the former
164 // selection in given cell of atom
165 void handleNest(MathAtom const & at, int cell = 0);
166 /// remove this as soon as LyXFunc::getStatus is "localized"
167 std::string getLastCode() const { return "mathnormal"; }
169 bool isInside(MathInset const *) const;
175 /// make sure cursor position is valid
177 /// mark current cursor trace for redraw
180 UpdatableInset * asHyperActiveInset() const;
182 /// enter a MathInset
183 void push(MathAtom & par);
184 /// enter a MathInset from the front
185 void pushLeft(MathAtom & par);
186 /// enter a MathInset from the back
187 void pushRight(MathAtom & par);
188 /// leave current MathInset to the left
190 /// leave current MathInset to the left
194 MathArray & array() const;
196 bool hasPrevAtom() const;
198 bool hasNextAtom() const;
200 MathAtom const & prevAtom() const;
202 MathAtom & prevAtom();
204 MathAtom const & nextAtom() const;
206 MathAtom & nextAtom();
208 /// returns the selection
209 void getSelection(CursorSlice &, CursorSlice &) const;
210 /// returns the normalized anchor of the selection
211 CursorSlice normalAnchor() const;
213 /// reference to the last item of the path, i.e. "The Cursor"
214 CursorSlice & cursor();
215 /// reference to the last item of the path, i.e. "The Cursor"
216 CursorSlice const & cursor() const;
217 /// how deep are we nested?
218 unsigned depth() const;
219 /// describe the situation
220 std::string info() const;
221 /// dump selection information for debugging
222 void seldump(char const * str) const;
223 /// dump selection information for debugging
224 void dump(char const * str) const;
226 void setSelection(CursorBase const & where, size_type n);
227 /// grab selection marked by anchor and current cursor
228 std::string grabSelection() const;
230 std::string grabAndEraseSelection();
234 void insert(std::string const & str);
235 /// lock/unlock inset
238 /// hack for reveal codes
241 /// injects content of a cell into parent
243 /// split font inset etc
244 void handleFont(std::string const & font);
247 dispatch(FuncRequest const & cmd);
249 /// moves cursor index one cell to the left
251 /// moves cursor index one cell to the right
253 /// moves cursor to end of last cell of current line
255 /// moves cursor position one cell to the left
257 /// moves cursor position one cell to the right
259 /// moves position somehow up or down
260 bool goUpDown(bool up);
261 /// moves position closest to (x, y) in given box
262 bool bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh);
263 /// moves position closest to (x, y) in current cell
264 void bruteFind2(int x, int y);
265 /// are we in a nucleus of a script inset?
266 bool inNucleus() const;
268 /// erase the selected part and re-sets the cursor
269 void eraseSelection();
271 /// the name of the macro we are currently inputting
272 std::string macroName() const;
273 /// where in the curent cell does the macro name start?
274 difference_type macroNamePos() const;
275 /// can we enter the inset?
276 bool openable(MathAtom const &, bool selection) const;
277 /// write access to cursor cell position
279 /// write access to cursor cell index
282 /// pointer to enclsing LyX inset
283 InsetFormulaBase * formula_;
285 /// text code of last char entered
286 //MathTextCodes lastcode_;
287 /// do we allow autocorrection
289 /// do we currently select
291 /// are we entering a macro name?
297 extern MathCursor * mathcursor;
298 void releaseMathCursor(BufferView & bv);