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"
32 class InsetMathUnknown;
36 /// The cursor class describes the position of a cursor within a document.
38 // The public inheritance should go in favour of a suitable data member
39 // (or maybe private inheritance) at some point of time.
40 class Cursor : public DocIterator {
42 /// create the cursor of a BufferView
43 explicit Cursor(BufferView & bv);
45 /// dispatch from innermost inset upwards
46 void dispatch(FuncRequest const & cmd);
47 /// get the resut of the last dispatch
48 DispatchResult result() const;
49 /// add a new cursor slice
50 void push(Inset & inset);
51 /// add a new cursor slice, place cursor on left end
52 void pushLeft(Inset & inset);
53 /// pop one level off the cursor
55 /// pop one slice off the cursor stack and go left
57 /// pop one slice off the cursor stack and go right
59 /// make sure we are outside of given inset
60 void leaveInset(Inset const & inset);
62 void setCursor(DocIterator const & it);
65 void setCurrentFont();
71 bool selection() const { return selection_; }
73 bool & selection() { return selection_; }
74 /// did we place the anchor?
75 bool mark() const { return mark_; }
76 /// did we place the anchor?
77 bool & mark() { return mark_; }
80 /// set selection at given position
81 void setSelection(DocIterator const & where, int n);
83 void clearSelection();
84 /// access start of selection
85 CursorSlice selBegin() const;
86 /// access end of selection
87 CursorSlice selEnd() const;
88 /// access start of selection
89 DocIterator selectionBegin() const;
90 /// access start of selection
91 DocIterator selectionEnd() const;
92 /// FIXME: document this
93 bool selHandle(bool selecting);
95 docstring selectionAsString(bool label) const;
97 docstring currentState();
100 bool autocorrect() const { return autocorrect_; }
101 /// auto-correct mode
102 bool & autocorrect() { return autocorrect_; }
103 /// are we entering a macro name?
104 bool macromode() const { return macromode_; }
105 /// are we entering a macro name?
106 bool & macromode() { return macromode_; }
107 /// returns x,y position
108 void getPos(int & x, int & y) const;
109 /// the row in the paragraph we're in
110 Row const & textRow() const;
115 /// move one step to the left
117 /// move one step to the right
121 void insert(Inset *);
122 /// insert a single char
123 void insert(char_type c);
125 void insert(docstring const & str);
127 /// FIXME: rename to something sensible showing difference to x_target()
128 /// in pixels from left of screen, set to current position if unset
130 /// set the targetX to x
131 void setTargetX(int x);
132 /// return targetX or -1 if unset
133 int x_target() const;
134 /// set targetX to current position
136 /// clear targetX, i.e. set it to -1
138 /// set offset to actual position - targetX
139 void updateTextTargetOffset();
140 /// distance between actual and targeted position during last up/down in text
141 int textTargetOffset() const;
143 /// access to normalized selection anchor
144 CursorSlice anchor() const;
145 /// sets anchor to cursor position
147 /// access to owning BufferView
148 BufferView & bv() const;
149 /// access to owning Buffer
150 Buffer & buffer() const;
151 /// get some interesting description of top position
152 void info(odocstream & 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...)
158 /// for spellchecking
159 void replaceWord(std::string const & replacestring);
161 * the event was not (yet) dispatched.
163 * Should only be called by an inset's doDispatch() method. It means:
164 * I, the doDispatch() method of InsetFoo, hereby declare that I am
165 * not able to handle that request and trust my parent will do the
166 * Right Thing (even if my getStatus partner said that I can do it).
167 * It is sort of a kludge that should be used only rarely...
170 /// the event was already dispatched
172 /// Set which update should be done
173 void updateFlags(Update::flags f);
175 * don't call update() when done
177 * Should only be called by an inset's doDispatch() method. It means:
178 * I handled that request and I can reassure you that the screen does
179 * not need to be re-drawn and all entries in the coord cache stay
180 * valid (and there are no other things to put in the coord cache).
181 * This is a fairly rare event as well and only some optimization.
182 * Not using noUpdate() should never be wrong.
185 /// fix cursor in circumstances that should never happen.
186 /// \retval true if a fix occured.
190 friend std::ostream & operator<<(std::ostream & os, Cursor const & cur);
196 /// the anchor position
200 DispatchResult disp_;
202 DocIterator const & beforeDispatchCursor() { return beforeDispatchCursor_; }
206 * The target x position of the cursor. This is used for when
207 * we have text like :
209 * blah blah blah blah| blah blah blah
211 * blah blah blah blah blah blah
213 * When we move onto row 3, we would like to be vertically aligned
214 * with where we were in row 1, despite the fact that row 2 is
218 /// if a x_target cannot be hit exactly in a text, put the difference here
219 int textTargetOffset_;
220 /// do we have a selection?
222 /// are we on the way to get one?
224 /// If true, we are behind the previous char, otherwise we are in front
225 // of the next char. This only make a difference when we are in front
226 // of a big inset spanning a whole row and computing coordinates for
227 // displaying the cursor.
229 /// x position before dispatch started
231 /// y position before dispatch started
233 /// position before dispatch started
234 DocIterator beforeDispatchCursor_;
236 // FIXME: make them private.
238 /// the current font settings
241 Font real_current_font;
246 // math specific stuff that could be promoted to "global" later
248 /// do we allow autocorrection
250 /// are we entering a macro name?
254 ///////////////////////////////////////////////////////////////////
256 // The part below is the non-integrated rest of the original math
257 // cursor. This should be either generalized for texted or moved
258 // back to the math insets.
260 ///////////////////////////////////////////////////////////////////
264 void insert(MathAtom const &);
266 void insert(MathData const &);
267 /// return false for empty math insets
269 /// return false for empty math insets
271 /// move the cursor up by sending an internal LFUN_UP
272 /// return true if fullscreen update is needed
274 /// move the cursor up by sending an internal LFUN_DOWN,
275 /// return true if fullscreen update is needed
277 /// move up/down in a text inset, called for LFUN_UP/DOWN,
278 /// return true if successful, updateNeeded set to true if fullscreen
279 /// update is needed, otherwise it's not touched
280 bool upDownInText(bool up, bool & updateNeeded);
281 /// move up/down in math or any non text inset, call for LFUN_UP/DOWN
282 /// return true if successful
283 bool upDownInMath(bool up);
287 void plainInsert(MathAtom const & at);
289 void niceInsert(MathAtom const & at);
291 void niceInsert(docstring const & str);
293 /// in pixels from top of screen
294 void setScreenPos(int x, int y);
295 /// current offset in the top cell
297 /// interpret name a name of a macro. Returns true if
298 /// something got inserted.
299 bool macroModeClose();
300 /// are we currently typing the name of a macro?
301 bool inMacroMode() const;
302 /// get access to the macro we are currently typing
303 InsetMathUnknown * activeMacro();
305 /// replace selected stuff with at, placing the former
306 // selection in given cell of atom
307 void handleNest(MathAtom const & at, int cell = 0);
309 bool isInside(Inset const *);
311 /// make sure cursor position is valid
312 /// FIXME: It does a subset of fixIfBroken. Maybe merge them?
314 /// mark current cursor trace for redraw
317 /// hack for reveal codes
320 /// injects content of a cell into parent
322 /// split font inset etc
323 void handleFont(std::string const & font);
325 /// display a message
326 void message(docstring const & msg) const;
327 /// display an error message
328 void errorMessage(docstring const & msg) const;
330 docstring getPossibleLabel();
332 /// the name of the macro we are currently inputting
333 docstring macroName();
334 /// where in the curent cell does the macro name start?
336 /// can we enter the inset?
337 bool openable(MathAtom const &) const;
339 Encoding const * getEncoding() const;
340 /// font at cursor position
341 Font getFont() const;
346 * Notifies all insets which appear in old, but not in cur. Make
347 * Sure that the cursor old is valid, i.e. als inset pointer
348 * point to valid insets! Use Cursor::fixIfBroken if necessary.
350 bool notifyCursorLeaves(DocIterator const & old, Cursor & cur);
355 #endif // LYXLCURSOR_H