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_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.
39 namespace mathcursor {
40 /// short of anything else reasonable
41 typedef size_t size_type;
42 /// type for column numbers
43 typedef ptrdiff_t difference_type;
44 /// type for cursor positions within a cell
45 typedef lyx::pos_type pos_type;
46 /// type for cell indices
47 typedef size_t idx_type;
48 /// type for row numbers
49 typedef size_t row_type;
50 /// type for column numbers
51 typedef size_t col_type;
54 void insert(LCursor & cur, MathAtom const &);
56 void insert(LCursor & cur, MathArray const &);
58 void insert2(LCursor & cur, std::string const &);
60 void paste(LCursor & cur, std::string const & data);
61 /// return false for empty math insets
62 bool erase(LCursor & cur);
63 /// return false for empty math insets
64 bool backspace(LCursor & cur);
65 /// called for LFUN_HOME etc
66 bool home(LCursor & cur, bool sel = false);
67 /// called for LFUN_END etc
68 bool end(LCursor & cur, bool sel = false);
69 /// called for LFUN_RIGHT and LFUN_RIGHTSEL
70 bool right(LCursor & cur, bool sel = false);
71 /// called for LFUN_LEFT etc
72 bool left(LCursor & cur, bool sel = false);
73 /// called for LFUN_UP etc
74 bool up(LCursor & cur, bool sel = false);
75 /// called for LFUN_DOWN etc
76 bool down(LCursor & cur, bool sel = false);
77 /// move to next cell in current inset
78 void idxNext(LCursor & bv);
79 /// move to previous cell in current inset
80 void idxPrev(LCursor & bv);
82 void plainErase(LCursor & cur);
84 void plainInsert(LCursor & cur, MathAtom const & at);
86 void niceInsert(LCursor & cur, MathAtom const & at);
88 void niceInsert(LCursor & cur, std::string const & str);
90 /// in pixels from top of screen
91 void setScreenPos(LCursor & cur, int x, int y);
92 /// in pixels from top of screen
93 void getScreenPos(LCursor & cur, int & x, int & y);
94 /// in pixels from left of screen
95 int targetX(LCursor & cur);
96 /// return the next enclosing grid inset and the cursor's index in it
97 MathGridInset * enclosingGrid(LCursor & cur, idx_type & idx);
98 /// go up to enclosing grid
99 void popToEnclosingGrid(LCursor & cur);
100 /// go up to the hull inset
101 void popToEnclosingHull(LCursor & cur);
102 /// go up to the hull inset
103 void popToHere(LCursor & cur, MathInset const * p);
104 /// adjust anchor position after deletions/insertions
105 void adjust(LCursor & cur, pos_type from, difference_type diff);
107 InsetFormulaBase * formula();
108 /// current offset in the current cell
110 bool script(LCursor & cur, bool);
112 bool interpret(LCursor & cur, char);
113 /// interpret name a name of a macro
114 void macroModeClose(LCursor & cur);
115 /// are we currently typing the name of a macro?
116 bool inMacroMode(LCursor & cur);
117 /// get access to the macro we are currently typing
118 MathUnknownInset * activeMacro(LCursor & cur);
119 /// are we currently typing '#1' or '#2' or...?
120 bool inMacroArgMode(LCursor & cur);
121 /// are we in math mode (1), text mode (-1) or unsure?
122 MathInset::mode_type currentMode(LCursor & cur);
124 // Local selection methods
126 void selCopy(LCursor & cur);
128 void selCut(LCursor & cur);
130 void selDel(LCursor & cur);
131 /// pastes n-th element of cut buffer
132 void selPaste(LCursor & cur, size_t n);
134 void selHandle(LCursor & cur, bool);
136 void selStart(LCursor & cur);
138 void selClear(LCursor & cur);
139 /// clears or deletes selection depending on lyxrc setting
140 void selClearOrDel(LCursor & cur);
141 /// draws light-blue selection background
142 void drawSelection(PainterInfo & pi);
143 /// replace selected stuff with at, placing the former
144 // selection in given cell of atom
145 void handleNest(LCursor & cur, MathAtom const & at, int cell = 0);
146 /// remove this as soon as LyXFunc::getStatus is "localized"
147 inline std::string getLastCode() { return "mathnormal"; }
149 bool isInside(MathInset const *);
151 char valign(LCursor & cur);
153 char halign(LCursor & cur);
155 /// make sure cursor position is valid
156 void normalize(LCursor & cur);
157 /// mark current cursor trace for redraw
160 /// enter a MathInset
161 void push(LCursor & cur, MathAtom & par);
162 /// enter a MathInset from the front
163 void pushLeft(LCursor & cur, MathAtom & par);
164 /// enter a MathInset from the back
165 void pushRight(LCursor & cur, MathAtom & par);
166 /// leave current MathInset to the left
167 bool popLeft(LCursor & cur);
168 /// leave current MathInset to the left
169 bool popRight(LCursor & cur);
171 /// returns the normalized anchor of the selection
172 CursorSlice normalAnchor(LCursor & cur);
174 /// dump selection information for debugging
175 void seldump(char const * str);
176 /// dump selection information for debugging
177 void dump(char const * str);
179 void setSelection(LCursor & cur, CursorBase const & where, size_type n);
180 /// grab selection marked by anchor and current cursor
181 std::string grabSelection(LCursor & cur);
183 std::string grabAndEraseSelection(LCursor & cur);
185 void insert(LCursor & cur, char c);
187 void insert(LCursor & cur, std::string const & str);
188 /// lock/unlock inset
189 void insetToggle(LCursor & cur);
191 /// hack for reveal codes
192 void markInsert(LCursor & cur);
193 void markErase(LCursor & cur);
194 /// injects content of a cell into parent
195 void pullArg(LCursor & cur);
196 /// split font inset etc
197 void handleFont(LCursor & cur, std::string const & font);
199 DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd);
201 /// pointer to enclsing LyX inset
202 extern InsetFormulaBase * formula_;
205 void releaseMathCursor(LCursor & cur);