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"
29 class MathUnknownInset;
33 /// The cursor class describes the position of a cursor within a document.
35 // The public inheritance should go in favour of a suitable data member
36 // (or maybe private inheritance) at some point of time.
37 class LCursor : public DocIterator {
39 /// create the cursor of a BufferView
40 explicit LCursor(BufferView & bv);
42 /// dispatch from innermost inset upwards
43 void dispatch(FuncRequest const & cmd);
44 /// get the resut of the last dispatch
45 DispatchResult result() const;
46 /// add a new cursor slice
47 void push(InsetBase & inset);
48 /// add a new cursor slice, place cursor on left end
49 void pushLeft(InsetBase & inset);
50 /// pop one level off the cursor
52 /// pop one slice off the cursor stack and go left
54 /// pop one slice off the cursor stack and go right
57 void setCursor(DocIterator const & it);
63 bool selection() const { return selection_; }
65 bool & selection() { return selection_; }
66 /// did we place the anchor?
67 bool mark() const { return mark_; }
68 /// did we place the anchor?
69 bool & mark() { return mark_; }
72 /// set selection at given position
73 void setSelection(DocIterator const & where, size_t n);
75 void clearSelection();
76 /// access start of selection
77 CursorSlice selBegin() const;
78 /// access end of selection
79 CursorSlice selEnd() const;
80 /// access start of selection
81 DocIterator selectionBegin() const;
82 /// access start of selection
83 DocIterator selectionEnd() const;
85 void selHandle(bool selecting);
87 std::string selectionAsString(bool label) const;
89 void paste(std::string const & data);
91 std::string currentState();
94 bool autocorrect() const { return autocorrect_; }
96 bool & autocorrect() { return autocorrect_; }
97 /// are we entering a macro name?
98 bool macromode() const { return macromode_; }
99 /// are we entering a macro name?
100 bool & macromode() { return macromode_; }
101 /// returns x,y position
102 void getPos(int & x, int & y) const;
107 /// move one step to the left
109 /// move one step to the right
113 void insert(InsetBase *);
114 /// insert a single char
117 void insert(std::string const & str);
119 /// in pixels from left of screen
121 /// write acess to target x position of cursor
123 /// return target x position of cursor
124 int x_target() const;
125 /// set targetX in current position
127 /// clear target x position of cursor
130 /// access to normalized selection anchor
131 CursorSlice anchor() const;
132 /// sets anchor to cursor position
134 /// access to owning BufferView
135 BufferView & bv() const;
136 /// access to owning Buffer
137 Buffer & buffer() const;
138 /// get some interesting description of top position
139 void info(std::ostream & os) const;
140 /// are we in math mode (2), text mode (1) or unsure (0)?
142 /// reset cursor bottom to the beginning of the given inset
143 // (sort of 'chroot' environment...)
144 void reset(InsetBase &);
145 /// for spellchecking
146 void replaceWord(std::string const & replacestring);
147 /// the event was not (yet) dispatched
149 /// the event was already dispatched
151 /// call update() when done
153 /// don't call update() when done
157 friend std::ostream & operator<<(std::ostream & os, LCursor const & cur);
163 /// the anchor position
167 DispatchResult disp_;
172 * The target x position of the cursor. This is used for when
173 * we have text like :
175 * blah blah blah blah| blah blah blah
177 * blah blah blah blah blah blah
179 * When we move onto row 3, we would like to be vertically aligned
180 * with where we were in row 1, despite the fact that row 2 is
184 /// do we have a selection?
186 /// are we on the way to get one?
192 // math specific stuff that could be promoted to "global" later
194 /// do we allow autocorrection
196 /// are we entering a macro name?
200 ///////////////////////////////////////////////////////////////////
202 // The part below is the non-integrated rest of the original math
203 // cursor. This should be either generalized for texted or moved
204 // back to the math insets.
206 ///////////////////////////////////////////////////////////////////
210 void insert(MathAtom const &);
212 void insert(MathArray const &);
213 /// return false for empty math insets
215 /// return false for empty math insets
217 /// called for LFUN_UP etc
219 /// called for LFUN_DOWN etc
224 void plainInsert(MathAtom const & at);
226 void niceInsert(MathAtom const & at);
228 void niceInsert(std::string const & str);
230 /// in pixels from top of screen
231 void setScreenPos(int x, int y);
232 /// current offset in the top cell
233 /// interpret name a name of a macro
234 void macroModeClose();
235 /// are we currently typing the name of a macro?
236 bool inMacroMode() const;
237 /// get access to the macro we are currently typing
238 MathUnknownInset * activeMacro();
240 /// replace selected stuff with at, placing the former
241 // selection in given cell of atom
242 void handleNest(MathAtom const & at, int cell = 0);
244 bool isInside(InsetBase const *);
246 /// make sure cursor position is valid
248 /// mark current cursor trace for redraw
251 /// hack for reveal codes
254 /// injects content of a cell into parent
256 /// split font inset etc
257 void handleFont(std::string const & font);
259 /// display a message
260 void message(std::string const & msg) const;
261 /// display an error message
262 void errorMessage(std::string const & msg) const;
264 std::string getPossibleLabel();
266 /// moves position somehow up or down
267 bool goUpDown(bool up);
269 /// the name of the macro we are currently inputting
270 std::string macroName();
271 /// where in the curent cell does the macro name start?
273 /// can we enter the inset?
274 bool openable(MathAtom const &) const;
276 Encoding const * getEncoding() const;
277 /// font at cursor position
278 LyXFont getFont() const;
282 #endif // LYXCURSOR_H