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