]> git.lyx.org Git - lyx.git/blob - src/cursor.h
convert author names and status messages to docstring
[lyx.git] / src / cursor.h
1 // -*- C++ -*-
2 /**
3  * \file cursor.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef CURSOR_H
13 #define CURSOR_H
14
15 #include "dispatchresult.h"
16 #include "dociterator.h"
17
18 #include <iosfwd>
19 #include <vector>
20
21
22 namespace lyx {
23
24 class Buffer;
25 class BufferView;
26 class FuncStatus;
27 class FuncRequest;
28 class LyXFont;
29 class Row;
30
31 // these should go
32 class InsetMathUnknown;
33 class Encoding;
34
35
36 /// The cursor class describes the position of a cursor within a document.
37
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 LCursor : public DocIterator {
41 public:
42         /// create the cursor of a BufferView
43         explicit LCursor(BufferView & bv);
44
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(InsetBase & inset);
51         /// add a new cursor slice, place cursor on left end
52         void pushLeft(InsetBase & inset);
53         /// pop one level off the cursor
54         void pop();
55         /// pop one slice off the cursor stack and go left
56         bool popLeft();
57         /// pop one slice off the cursor stack and go right
58         bool popRight();
59         /// make sure we are outside of given inset
60         void leaveInset(InsetBase const & inset);
61         /// sets cursor part
62         void setCursor(DocIterator const & it);
63
64         //
65         // selection
66         //
67         /// selection active?
68         bool selection() const { return selection_; }
69         /// selection active?
70         bool & selection() { return selection_; }
71         /// did we place the anchor?
72         bool mark() const { return mark_; }
73         /// did we place the anchor?
74         bool & mark() { return mark_; }
75         ///
76         void setSelection();
77         /// set selection at given position
78         void setSelection(DocIterator const & where, int n);
79         ///
80         void clearSelection();
81         /// access start of selection
82         CursorSlice selBegin() const;
83         /// access end of selection
84         CursorSlice selEnd() const;
85         /// access start of selection
86         DocIterator selectionBegin() const;
87         /// access start of selection
88         DocIterator selectionEnd() const;
89         ///
90         bool selHandle(bool selecting);
91         //
92         docstring selectionAsString(bool label) const;
93         ///
94         docstring currentState();
95
96         /// auto-correct mode
97         bool autocorrect() const { return autocorrect_; }
98         /// auto-correct mode
99         bool & autocorrect() { return autocorrect_; }
100         /// are we entering a macro name?
101         bool macromode() const { return macromode_; }
102         /// are we entering a macro name?
103         bool & macromode() { return macromode_; }
104         /// returns x,y position
105         void getPos(int & x, int & y) const;
106         /// the row in the paragraph we're in
107         Row & textRow();
108         /// the row in the paragraph we're in
109         Row const & textRow() const;
110
111         //
112         // common part
113         //
114         /// move one step to the left
115         bool posLeft();
116         /// move one step to the right
117         bool posRight();
118
119         /// insert an inset
120         void insert(InsetBase *);
121         /// insert a single char
122         void insert(char_type c);
123         /// insert a string
124         void insert(docstring const & str);
125
126         /// in pixels from left of screen
127         int targetX() const;
128         /// write acess to target x position of cursor
129         int & x_target();
130         /// return target x position of cursor
131         int x_target() const;
132         /// set targetX in current position
133         void setTargetX();
134         /// clear target x position of cursor
135         void clearTargetX();
136
137         /// access to normalized selection anchor
138         CursorSlice anchor() const;
139         /// sets anchor to cursor position
140         void resetAnchor();
141         /// access to owning BufferView
142         BufferView & bv() const;
143         /// access to owning Buffer
144         Buffer & buffer() const;
145         /// get some interesting description of top position
146         void info(odocstream & os) const;
147         /// are we in math mode (2), text mode (1) or unsure (0)?
148         int currentMode();
149         /// reset cursor bottom to the beginning of the given inset
150         // (sort of 'chroot' environment...)
151         void reset(InsetBase &);
152         /// for spellchecking
153         void replaceWord(std::string const & replacestring);
154         /**
155          * the event was not (yet) dispatched.
156          *
157          * Should only be called by an inset's doDispatch() method. It means:
158          * I, the doDispatch() method of InsetFoo, hereby declare that I am
159          * not able to handle that request and trust my parent will do the
160          * Right Thing (even if my getStatus partner said that I can do it).
161          * It is sort of a kludge that should be used only rarely...
162          */
163         void undispatched();
164         /// the event was already dispatched
165         void dispatched();
166         /// Set which update should be done
167         void updateFlags(Update::flags f);
168         /**
169          * don't call update() when done
170          *
171          * Should only be called by an inset's doDispatch() method. It means:
172          * I handled that request and I can reassure you that the screen does
173          * not need to be re-drawn and all entries in the coord cache stay
174          * valid (and there are no other things to put in the coord cache).
175          * This is a fairly rare event as well and only some optimization.
176          * Not using noUpdate() should never be wrong.
177          */
178         void noUpdate();
179         /// fix cursor in circumstances that should never happen
180         void fixIfBroken();
181
182         /// output
183         friend std::ostream & operator<<(std::ostream & os, LCursor const & cur);
184
185 public:
186         ///
187         BufferView * bv_;
188 //private:
189         /// the anchor position
190         DocIterator anchor_;
191
192         ///
193         DispatchResult disp_;
194
195
196 private:
197         /**
198          * The target x position of the cursor. This is used for when
199          * we have text like :
200          *
201          * blah blah blah blah| blah blah blah
202          * blah blah blah
203          * blah blah blah blah blah blah
204          *
205          * When we move onto row 3, we would like to be vertically aligned
206          * with where we were in row 1, despite the fact that row 2 is
207          * shorter than x()
208          */
209         int x_target_;
210         /// do we have a selection?
211         bool selection_;
212         /// are we on the way to get one?
213         bool mark_;
214         /// If true, we are behind the previous char, otherwise we are in front
215         // of the next char. This only make a difference when we are in front
216         // of a big inset spanning a whole row and computing coordinates for
217         // displaying the cursor.
218         bool logicalpos_;
219
220 private:
221
222         //
223         // math specific stuff that could be promoted to "global" later
224         //
225         /// do we allow autocorrection
226         bool autocorrect_;
227         /// are we entering a macro name?
228         bool macromode_;
229
230
231 ///////////////////////////////////////////////////////////////////
232 //
233 // The part below is the non-integrated rest of the original math
234 // cursor. This should be either generalized for texted or moved
235 // back to the math insets.
236 //
237 ///////////////////////////////////////////////////////////////////
238
239 public:
240         ///
241         void insert(MathAtom const &);
242         ///
243         void insert(MathArray const &);
244         /// return false for empty math insets
245         bool erase();
246         /// return false for empty math insets
247         bool backspace();
248         /// called for LFUN_UP etc
249         bool up();
250         /// called for LFUN_DOWN etc
251         bool down();
252         ///
253         void plainErase();
254         ///
255         void plainInsert(MathAtom const & at);
256         ///
257         void niceInsert(MathAtom const & at);
258         ///
259         void niceInsert(docstring const & str);
260
261         /// in pixels from top of screen
262         void setScreenPos(int x, int y);
263         /// current offset in the top cell
264
265         /// interpret name a name of a macro. Returns true if
266         /// something got inserted.
267         bool macroModeClose();
268         /// are we currently typing the name of a macro?
269         bool inMacroMode() const;
270         /// get access to the macro we are currently typing
271         InsetMathUnknown * activeMacro();
272
273         /// replace selected stuff with at, placing the former
274         // selection in given cell of atom
275         void handleNest(MathAtom const & at, int cell = 0);
276         ///
277         bool isInside(InsetBase const *);
278
279         /// make sure cursor position is valid
280         void normalize();
281         /// mark current cursor trace for redraw
282         void touch();
283
284         /// hack for reveal codes
285         void markInsert();
286         void markErase();
287         /// injects content of a cell into parent
288         void pullArg();
289         /// split font inset etc
290         void handleFont(std::string const & font);
291
292         /// display a message
293         void message(docstring const & msg) const;
294         /// display an error message
295         void errorMessage(docstring const & msg) const;
296         ///
297         docstring getPossibleLabel();
298
299         /// moves position somehow up or down
300         bool goUpDown(bool up);
301
302         /// the name of the macro we are currently inputting
303         docstring macroName();
304         /// where in the curent cell does the macro name start?
305         int macroNamePos();
306         /// can we enter the inset?
307         bool openable(MathAtom const &) const;
308         ///
309         Encoding const * getEncoding() const;
310         /// font at cursor position
311         LyXFont getFont() const;
312 };
313
314
315
316 } // namespace lyx
317
318 #endif // LYXCURSOR_H