4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
15 #include "dispatchresult.h"
16 #include "dociterator.h"
26 class MathUnknownInset;
30 /// The cursor class describes the position of a cursor within a document.
32 // The public inheritance should go in favour of a suitable data member
33 // (or maybe private inheritance) at some point of time.
34 class LCursor : public DocIterator {
36 /// create the cursor of a BufferView
37 explicit LCursor(BufferView & bv);
39 /// dispatch from innermost inset upwards
40 DispatchResult dispatch(FuncRequest const & cmd);
41 /// are we willing to handle this event?
42 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
44 /// add a new cursor slice
45 void push(InsetBase & inset);
46 /// add a new cursor slice, place cursor on left end
47 void pushLeft(InsetBase & inset);
48 /// pop one level off the cursor
50 /// pop one slice off the cursor stack and go left
52 /// pop one slice off the cursor stack and go right
55 void setCursor(DocIterator const & it, bool sel);
61 bool selection() const { return selection_; }
63 bool & selection() { return selection_; }
64 /// did we place the anchor?
65 bool mark() const { return mark_; }
66 /// did we place the anchor?
67 bool & mark() { return mark_; }
70 /// set selection at given position
71 void setSelection(DocIterator const & where, size_t n);
73 void clearSelection();
74 /// access start of selection
75 CursorSlice selBegin() const;
76 /// access end of selection
77 CursorSlice selEnd() const;
78 /// access start of selection
79 DocIterator selectionBegin() const;
80 /// access start of selection
81 DocIterator selectionEnd() const;
83 std::string grabSelection();
85 void eraseSelection();
87 std::string grabAndEraseSelection();
88 // other selection methods
95 /// pastes n-th element of cut buffer
96 void selPaste(size_t n);
98 void selHandle(bool selecting);
99 /// clears or deletes selection depending on lyxrc setting
100 void selClearOrDel();
102 std::string selectionAsString(bool label) const;
104 void paste(std::string const & data);
106 std::string currentState();
108 /// auto-correct mode
109 bool autocorrect() const { return autocorrect_; }
110 /// auto-correct mode
111 bool & autocorrect() { return autocorrect_; }
112 /// are we entering a macro name?
113 bool macromode() const { return macromode_; }
114 /// are we entering a macro name?
115 bool & macromode() { return macromode_; }
116 /// returns x,y position
117 void getPos(int & x, int & y) const;
118 /// returns cursor dimension
119 void getDim(int & asc, int & desc) const;
124 /// move one step to the left
126 /// move one step to the right
130 void insert(InsetBase *);
131 /// insert a single char
134 void insert(std::string const & str);
136 /// write acess to target x position of cursor
138 /// return target x position of cursor
139 int x_target() const;
140 /// clear target x position of cursor
143 /// access to normalized selection anchor
144 CursorSlice anchor() const;
145 /// cache the absolute coordinate from the top inset
147 /// sets anchor to cursor position
149 /// access to owning BufferView
150 BufferView & bv() const;
151 /// get some interesting description of top position
152 void info(std::ostream & os) const;
153 /// are we in math mode (2), text mode (1) or unsure (0)?
155 /// reset cursor bottom to the beginning of the given inset
156 // (sort of 'chroot' environment...)
157 void reset(InsetBase &);
158 /// for spellchecking
159 void replaceWord(std::string const & replacestring);
162 /// the event was not (yet) dispatched
164 /// the event was already dispatched
166 /// don't call update() when done
170 friend std::ostream & operator<<(std::ostream & os, LCursor const & cur);
176 /// the anchor position
180 DispatchResult disp_;
186 * The target x position of the cursor. This is used for when
187 * we have text like :
189 * blah blah blah blah| blah blah blah
191 * blah blah blah blah blah blah
193 * When we move onto row 3, we would like to be vertically aligned
194 * with where we were in row 1, despite the fact that row 2 is
198 /// do we have a selection?
200 /// are we on the way to get one?
204 // math specific stuff that could be promoted to "global" later
206 /// do we allow autocorrection
208 /// are we entering a macro name?
212 ///////////////////////////////////////////////////////////////////
214 // The part below is the non-integrated rest of the original math
215 // cursor. This should be either generalized for texted or moved
216 // back to the math insets.
218 ///////////////////////////////////////////////////////////////////
222 void insert(MathAtom const &);
224 void insert(MathArray const &);
225 /// return false for empty math insets
227 /// return false for empty math insets
229 /// called for LFUN_UP etc
231 /// called for LFUN_DOWN etc
236 void plainInsert(MathAtom const & at);
238 void niceInsert(MathAtom const & at);
240 void niceInsert(std::string const & str);
242 /// in pixels from top of screen
243 void setScreenPos(int x, int y);
244 /// in pixels from left of screen
246 /// current offset in the top cell
247 /// interpret name a name of a macro
248 void macroModeClose();
249 /// are we currently typing the name of a macro?
250 bool inMacroMode() const;
251 /// get access to the macro we are currently typing
252 MathUnknownInset * activeMacro();
254 /// replace selected stuff with at, placing the former
255 // selection in given cell of atom
256 void handleNest(MathAtom const & at, int cell = 0);
258 bool isInside(InsetBase const *);
260 /// make sure cursor position is valid
262 /// mark current cursor trace for redraw
265 /// hack for reveal codes
268 /// injects content of a cell into parent
270 /// split font inset etc
271 void handleFont(std::string const & font);
273 /// display a message
274 void message(std::string const & msg) const;
275 /// display an error message
276 void errorMessage(std::string const & msg) const;
278 std::string getPossibleLabel();
280 /// moves position somehow up or down
281 bool goUpDown(bool up);
283 /// the name of the macro we are currently inputting
284 std::string macroName();
285 /// where in the curent cell does the macro name start?
287 /// can we enter the inset?
288 bool openable(MathAtom const &) const;
290 Encoding const * getEncoding() const;
293 /// moves position closest to (x, y) in current cell
294 void bruteFind2(int x, int y);
295 /// moves position closest to (x, y) in given box
296 bool bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh);
299 #endif // LYXCURSOR_H