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"
28 class InsetMathUnknown;
32 /// The cursor class describes the position of a cursor within a document.
34 // The public inheritance should go in favour of a suitable data member
35 // (or maybe private inheritance) at some point of time.
36 class LCursor : public DocIterator {
38 /// create the cursor of a BufferView
39 explicit LCursor(BufferView & bv);
41 /// dispatch from innermost inset upwards
42 void dispatch(FuncRequest const & cmd);
43 /// get the resut of the last dispatch
44 DispatchResult result() const;
45 /// add a new cursor slice
46 void push(InsetBase & inset);
47 /// add a new cursor slice, place cursor on left end
48 void pushLeft(InsetBase & inset);
49 /// pop one level off the cursor
51 /// pop one slice off the cursor stack and go left
53 /// pop one slice off the cursor stack and go right
55 /// make sure we are outside of given inset
56 void leaveInset(InsetBase const & inset);
58 void setCursor(DocIterator const & it);
64 bool selection() const { return selection_; }
66 bool & selection() { return selection_; }
67 /// did we place the anchor?
68 bool mark() const { return mark_; }
69 /// did we place the anchor?
70 bool & mark() { return mark_; }
73 /// set selection at given position
74 void setSelection(DocIterator const & where, size_t n);
76 void clearSelection();
77 /// access start of selection
78 CursorSlice selBegin() const;
79 /// access end of selection
80 CursorSlice selEnd() const;
81 /// access start of selection
82 DocIterator selectionBegin() const;
83 /// access start of selection
84 DocIterator selectionEnd() const;
86 void selHandle(bool selecting);
88 lyx::docstring selectionAsString(bool label) const;
90 std::string currentState();
93 bool autocorrect() const { return autocorrect_; }
95 bool & autocorrect() { return autocorrect_; }
96 /// are we entering a macro name?
97 bool macromode() const { return macromode_; }
98 /// are we entering a macro name?
99 bool & macromode() { return macromode_; }
100 /// returns x,y position
101 void getPos(int & x, int & y) const;
106 /// move one step to the left
108 /// move one step to the right
112 void insert(InsetBase *);
113 /// insert a single char
114 void insert(lyx::char_type c);
116 void insert(std::string const & str);
118 /// in pixels from left of screen
120 /// write acess to target x position of cursor
122 /// return target x position of cursor
123 int x_target() const;
124 /// set targetX in current position
126 /// clear target x position of cursor
129 /// access to normalized selection anchor
130 CursorSlice anchor() const;
131 /// sets anchor to cursor position
133 /// access to owning BufferView
134 BufferView & bv() const;
135 /// access to owning Buffer
136 Buffer & buffer() const;
137 /// get some interesting description of top position
138 void info(std::ostream & os) const;
139 /// are we in math mode (2), text mode (1) or unsure (0)?
141 /// reset cursor bottom to the beginning of the given inset
142 // (sort of 'chroot' environment...)
143 void reset(InsetBase &);
144 /// for spellchecking
145 void replaceWord(std::string const & replacestring);
147 * the event was not (yet) dispatched.
149 * Should only be called by an inset's doDispatch() method. It means:
150 * I, the doDispatch() method of InsetFoo, hereby declare that I am
151 * not able to handle that request and trust my parent will do the
152 * Right Thing (even if my getStatus partner said that I can do it).
153 * It is sort of a kludge that should be used only rarely...
156 /// the event was already dispatched
158 /// call update() when done
161 * don't call update() when done
163 * Should only be called by an inset's doDispatch() method. It means:
164 * I handled that request and I can reassure you that the screen does
165 * not need to be re-drawn and all entries in the coord cache stay
166 * valid (and there are no other things to put in the coord cache).
167 * This is a fairly rare event as well and only some optimization.
168 * Not using noUpdate() should never be wrong.
171 /// fix cursor in circumstances that should never happen
175 friend std::ostream & operator<<(std::ostream & os, LCursor const & cur);
181 /// the anchor position
185 DispatchResult disp_;
190 * The target x position of the cursor. This is used for when
191 * we have text like :
193 * blah blah blah blah| blah blah blah
195 * blah blah blah blah blah blah
197 * When we move onto row 3, we would like to be vertically aligned
198 * with where we were in row 1, despite the fact that row 2 is
202 /// do we have a selection?
204 /// are we on the way to get one?
206 /// If true, we are behind the previous char, otherwise we are in front
207 // of the next char. This only make a difference when we are in front
208 // of a big inset spanning a whole row and computing coordinates for
209 // displaying the cursor.
215 // math specific stuff that could be promoted to "global" later
217 /// do we allow autocorrection
219 /// are we entering a macro name?
223 ///////////////////////////////////////////////////////////////////
225 // The part below is the non-integrated rest of the original math
226 // cursor. This should be either generalized for texted or moved
227 // back to the math insets.
229 ///////////////////////////////////////////////////////////////////
233 void insert(MathAtom const &);
235 void insert(MathArray const &);
236 /// return false for empty math insets
238 /// return false for empty math insets
240 /// called for LFUN_UP etc
242 /// called for LFUN_DOWN etc
247 void plainInsert(MathAtom const & at);
249 void niceInsert(MathAtom const & at);
251 void niceInsert(std::string const & str);
253 /// in pixels from top of screen
254 void setScreenPos(int x, int y);
255 /// current offset in the top cell
257 /// interpret name a name of a macro. Returns true if
258 /// something got inserted.
259 bool macroModeClose();
260 /// are we currently typing the name of a macro?
261 bool inMacroMode() const;
262 /// get access to the macro we are currently typing
263 InsetMathUnknown * activeMacro();
265 /// replace selected stuff with at, placing the former
266 // selection in given cell of atom
267 void handleNest(MathAtom const & at, int cell = 0);
269 bool isInside(InsetBase const *);
271 /// make sure cursor position is valid
273 /// mark current cursor trace for redraw
276 /// hack for reveal codes
279 /// injects content of a cell into parent
281 /// split font inset etc
282 void handleFont(std::string const & font);
284 /// display a message
285 void message(lyx::docstring const & msg) const;
286 /// display an error message
287 void errorMessage(lyx::docstring const & msg) const;
289 std::string getPossibleLabel();
291 /// moves position somehow up or down
292 bool goUpDown(bool up);
294 /// the name of the macro we are currently inputting
295 std::string macroName();
296 /// where in the curent cell does the macro name start?
298 /// can we enter the inset?
299 bool openable(MathAtom const &) const;
301 Encoding const * getEncoding() const;
302 /// font at cursor position
303 LyXFont getFont() const;
307 #endif // LYXCURSOR_H