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
155 /// fix cursor in circumstances that should never happen
159 friend std::ostream & operator<<(std::ostream & os, LCursor const & cur);
165 /// the anchor position
169 DispatchResult disp_;
174 * The target x position of the cursor. This is used for when
175 * we have text like :
177 * blah blah blah blah| blah blah blah
179 * blah blah blah blah blah blah
181 * When we move onto row 3, we would like to be vertically aligned
182 * with where we were in row 1, despite the fact that row 2 is
186 /// do we have a selection?
188 /// are we on the way to get one?
194 // math specific stuff that could be promoted to "global" later
196 /// do we allow autocorrection
198 /// are we entering a macro name?
202 ///////////////////////////////////////////////////////////////////
204 // The part below is the non-integrated rest of the original math
205 // cursor. This should be either generalized for texted or moved
206 // back to the math insets.
208 ///////////////////////////////////////////////////////////////////
212 void insert(MathAtom const &);
214 void insert(MathArray const &);
215 /// return false for empty math insets
217 /// return false for empty math insets
219 /// called for LFUN_UP etc
221 /// called for LFUN_DOWN etc
226 void plainInsert(MathAtom const & at);
228 void niceInsert(MathAtom const & at);
230 void niceInsert(std::string const & str);
232 /// in pixels from top of screen
233 void setScreenPos(int x, int y);
234 /// current offset in the top cell
235 /// interpret name a name of a macro
236 void macroModeClose();
237 /// are we currently typing the name of a macro?
238 bool inMacroMode() const;
239 /// get access to the macro we are currently typing
240 MathUnknownInset * activeMacro();
242 /// replace selected stuff with at, placing the former
243 // selection in given cell of atom
244 void handleNest(MathAtom const & at, int cell = 0);
246 bool isInside(InsetBase const *);
248 /// make sure cursor position is valid
250 /// mark current cursor trace for redraw
253 /// hack for reveal codes
256 /// injects content of a cell into parent
258 /// split font inset etc
259 void handleFont(std::string const & font);
261 /// display a message
262 void message(std::string const & msg) const;
263 /// display an error message
264 void errorMessage(std::string const & msg) const;
266 std::string getPossibleLabel();
268 /// moves position somehow up or down
269 bool goUpDown(bool up);
271 /// the name of the macro we are currently inputting
272 std::string macroName();
273 /// where in the curent cell does the macro name start?
275 /// can we enter the inset?
276 bool openable(MathAtom const &) const;
278 Encoding const * getEncoding() const;
279 /// font at cursor position
280 LyXFont getFont() const;
284 #endif // LYXCURSOR_H