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 "math_inset.h"
17 #include "math_data.h"
18 #include "math_iterator.h"
23 class InsetFormulaBase;
26 class MathUnknownInset;
30 [Have a look at math_inset.h first]
32 The MathCursor is different from the kind of cursor used in the Outer
33 World. It contains a stack of CursorSlice, each of which is made
34 up of a inset pointer, an index and a position offset, marking a path from
35 this formula's MathHullInset to the current position.
42 /// short of anything else reasonable
43 typedef MathInset::size_type size_type;
44 /// type for column numbers
45 typedef MathArray::difference_type difference_type;
46 /// type for cursor positions within a cell
47 typedef MathInset::pos_type pos_type;
48 /// type for cell indices
49 typedef MathInset::idx_type idx_type;
50 /// type for row numbers
51 typedef MathInset::row_type row_type;
52 /// type for column numbers
53 typedef MathInset::col_type col_type;
56 explicit MathCursor(InsetFormulaBase *, bool left);
60 void insert(MathAtom const &);
62 void insert(MathArray const &);
64 void insert2(std::string const &);
66 void paste(std::string const & data);
67 /// return false for empty math insets
69 /// return false for empty math insets
71 /// called for LFUN_HOME etc
72 bool home(bool sel = false);
73 /// called for LFUN_END etc
74 bool end(bool sel = false);
75 /// called for LFUN_RIGHT and LFUN_RIGHTSEL
76 bool right(bool sel = false);
77 /// called for LFUN_LEFT etc
78 bool left(bool sel = false);
79 /// called for LFUN_UP etc
80 bool up(bool sel = false);
81 /// called for LFUN_DOWN etc
82 bool down(bool sel = false);
83 /// Put the cursor in the first position
85 /// Put the cursor in the last position
87 /// move to next cell in current inset
89 /// move to previous cell in current inset
94 void plainInsert(MathAtom const &);
96 void niceInsert(MathAtom const &);
98 void niceInsert(std::string const &);
100 /// in pixels from top of screen
101 void setPos(int x, int y);
102 /// in pixels from top of screen
103 void getPos(int & x, int & y) const;
104 /// in pixels from left of screen
107 MathInset * inset() const;
108 /// return the next enclosing grid inset and the cursor's index in it
109 MathGridInset * enclosingGrid(idx_type & idx) const;
110 /// go up to enclosing grid
111 void popToEnclosingGrid();
112 /// go up to the hull inset
113 void popToEnclosingHull();
114 /// go up to the hull inset
115 void popToHere(MathInset const * p);
116 /// adjust anchor position after deletions/insertions
117 void adjust(pos_type from, difference_type diff);
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(char);
130 /// interpret name a name of a macro
131 void macroModeClose();
132 /// are we currently typing the name of a macro?
133 bool inMacroMode() const;
134 /// get access to the macro we are currently typing
135 MathUnknownInset * activeMacro();
136 /// get access to the macro we are currently typing
137 MathUnknownInset const * activeMacro() const;
138 /// are we currently typing '#1' or '#2' or...?
139 bool inMacroArgMode() const;
140 /// are we in math mode (1), text mode (-1) or unsure?
141 MathInset::mode_type currentMode() const;
143 // Local selection methods
145 bool selection() const;
152 /// pastes n-th element of cut buffer
153 void selPaste(size_t n);
155 void selHandle(bool);
160 /// clears or deletes selection depending on lyxrc setting
161 void selClearOrDel();
162 /// draws light-blue selection background
163 void drawSelection(PainterInfo & pi) const;
164 /// replace selected stuff with at, placing the former
165 // selection in given cell of atom
166 void handleNest(MathAtom const & at, int cell = 0);
167 /// remove this as soon as LyXFunc::getStatus is "localized"
168 std::string getLastCode() const { return "mathnormal"; }
170 bool isInside(MathInset const *) const;
176 /// make sure cursor position is valid
178 /// mark current cursor trace for redraw
181 UpdatableInset * asHyperActiveInset() const;
183 /// enter a MathInset
184 void push(MathAtom & par);
185 /// enter a MathInset from the front
186 void pushLeft(MathAtom & par);
187 /// enter a MathInset from the back
188 void pushRight(MathAtom & par);
189 /// leave current MathInset to the left
191 /// leave current MathInset to the left
195 MathArray & array() const;
197 bool hasPrevAtom() const;
199 bool hasNextAtom() const;
201 MathAtom const & prevAtom() const;
203 MathAtom & prevAtom();
205 MathAtom const & nextAtom() const;
207 MathAtom & nextAtom();
209 /// returns the selection
210 void getSelection(CursorSlice &, CursorSlice &) const;
211 /// returns the normalized anchor of the selection
212 CursorSlice normalAnchor() const;
214 /// reference to the last item of the path, i.e. "The Cursor"
215 CursorSlice & cursor();
216 /// reference to the last item of the path, i.e. "The Cursor"
217 CursorSlice const & cursor() const;
218 /// how deep are we nested?
219 unsigned depth() const;
220 /// describe the situation
221 std::string info() const;
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 std::string grabSelection() const;
231 std::string grabAndEraseSelection();
235 void insert(std::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(std::string const & font);
248 dispatch(FuncRequest const & cmd);
250 /// moves cursor index one cell to the left
252 /// moves cursor index one cell to the right
254 /// moves cursor to end of last cell of current line
256 /// moves cursor position one cell to the left
258 /// moves cursor position one cell to the right
260 /// moves position somehow up or down
261 bool goUpDown(bool up);
262 /// moves position closest to (x, y) in given box
263 bool bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh);
264 /// moves position closest to (x, y) in current cell
265 void bruteFind2(int x, int y);
266 /// are we in a nucleus of a script inset?
267 bool inNucleus() const;
269 /// erase the selected part and re-sets the cursor
270 void eraseSelection();
272 /// the name of the macro we are currently inputting
273 std::string macroName() const;
274 /// where in the curent cell does the macro name start?
275 difference_type macroNamePos() const;
276 /// can we enter the inset?
277 bool openable(MathAtom const &, bool selection) const;
278 /// write access to cursor cell position
280 /// write access to cursor cell index
283 /// path of positions the cursor had to go if it were leaving each inset
284 MathIterator Cursor_;
285 /// path of positions the anchor had to go if it were leaving each inset
286 mutable MathIterator Anchor_;
287 /// pointer to enclsing LyX inset
288 InsetFormulaBase * formula_;
290 /// text code of last char entered
291 //MathTextCodes lastcode_;
292 /// do we allow autocorrection
294 /// do we currently select
296 /// are we entering a macro name?
298 /// are we targeting a certain x coordinate, if so, which one?
302 extern MathCursor * mathcursor;
303 void releaseMathCursor(BufferView * bv);