]> git.lyx.org Git - lyx.git/blob - src/cursor.h
Fix the missing "Figure #:" label from the caption of a figure float.
[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 class Buffer;
22 class BufferView;
23 class FuncStatus;
24 class FuncRequest;
25
26 // these should go
27 class MathUnknownInset;
28 class Encoding;
29
30
31 /// The cursor class describes the position of a cursor within a document.
32
33 // The public inheritance should go in favour of a suitable data member
34 // (or maybe private inheritance) at some point of time.
35 class LCursor : public DocIterator {
36 public:
37         /// create the cursor of a BufferView
38         explicit LCursor(BufferView & bv);
39
40         /// dispatch from innermost inset upwards
41         DispatchResult dispatch(FuncRequest const & cmd);
42         /// are we willing to handle this event?
43         bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
44
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
50         void pop();
51         /// pop one slice off the cursor stack and go left
52         bool popLeft();
53         /// pop one slice off the cursor stack and go right
54         bool popRight();
55         /// sets cursor part
56         void setCursor(DocIterator const & it, bool sel);
57
58         //
59         // selection
60         //
61         /// selection active?
62         bool selection() const { return selection_; }
63         /// selection active?
64         bool & selection() { return selection_; }
65         /// did we place the anchor?
66         bool mark() const { return mark_; }
67         /// did we place the anchor?
68         bool & mark() { return mark_; }
69         ///
70         void setSelection();
71         /// set selection at given position
72         void setSelection(DocIterator const & where, size_t n);
73         ///
74         void clearSelection();
75         /// access start of selection
76         CursorSlice selBegin() const;
77         /// access end of selection
78         CursorSlice selEnd() const;
79         /// access start of selection
80         DocIterator selectionBegin() const;
81         /// access start of selection
82         DocIterator selectionEnd() const;
83         ///
84         std::string grabSelection();
85         ///
86         void eraseSelection();
87         ///
88         std::string grabAndEraseSelection();
89         // other selection methods
90         ///
91         void selCopy();
92         ///
93         void selCut();
94         ///
95         void selDel();
96         /// pastes n-th element of cut buffer
97         void selPaste(size_t n);
98         ///
99         void selHandle(bool selecting);
100         /// clears or deletes selection depending on lyxrc setting
101         void selClearOrDel();
102         //
103         std::string selectionAsString(bool label) const;
104         ///
105         void paste(std::string const & data);
106         ///
107         std::string currentState();
108
109         /// auto-correct mode
110         bool autocorrect() const { return autocorrect_; }
111         /// auto-correct mode
112         bool & autocorrect() { return autocorrect_; }
113         /// are we entering a macro name?
114         bool macromode() const { return macromode_; }
115         /// are we entering a macro name?
116         bool & macromode() { return macromode_; }
117         /// returns x,y position
118         void getPos(int & x, int & y) const;
119         /// returns cursor dimension
120         void getDim(int & asc, int & desc) const;
121
122         //
123         // common part
124         //
125         /// move one step to the left
126         bool posLeft();
127         /// move one step to the right
128         bool posRight();
129
130         /// insert an inset
131         void insert(InsetBase *);
132         /// insert a single char
133         void insert(char c);
134         /// insert a string
135         void insert(std::string const & str);
136
137         /// write acess to target x position of cursor
138         int & x_target();
139         /// return target x position of cursor
140         int x_target() const;
141         /// clear target x position of cursor
142         void clearTargetX();
143
144         /// access to normalized selection anchor
145         CursorSlice anchor() const;
146         /// sets anchor to cursor position
147         void resetAnchor();
148         /// access to owning BufferView
149         BufferView & bv() const;
150         /// access to owning Buffer
151         Buffer & buffer() const;
152         /// get some interesting description of top position
153         void info(std::ostream & os) const;
154         /// are we in math mode (2), text mode (1) or unsure (0)?
155         int currentMode();
156         /// reset cursor bottom to the beginning of the given inset
157         // (sort of 'chroot' environment...)
158         void reset(InsetBase &);
159         /// for spellchecking
160         void replaceWord(std::string const & replacestring);
161         /// the event was not (yet) dispatched
162         void undispatched();
163         /// the event was already dispatched
164         void dispatched();
165         /// don't call update() when done
166         void noUpdate();
167
168         /// output
169         friend std::ostream & operator<<(std::ostream & os, LCursor const & cur);
170
171 public:
172         ///
173         BufferView * bv_;
174 //private:
175         /// the anchor position
176         DocIterator anchor_;
177
178         ///
179         DispatchResult disp_;
180
181 private:
182         /**
183          * The target x position of the cursor. This is used for when
184          * we have text like :
185          *
186          * blah blah blah blah| blah blah blah
187          * blah blah blah
188          * blah blah blah blah blah blah
189          *
190          * When we move onto row 3, we would like to be vertically aligned
191          * with where we were in row 1, despite the fact that row 2 is
192          * shorter than x()
193          */
194         int x_target_;
195         /// do we have a selection?
196         bool selection_;
197         /// are we on the way to get one?
198         bool mark_;
199
200         //
201         // math specific stuff that could be promoted to "global" later
202         //
203         /// do we allow autocorrection
204         bool autocorrect_;
205         /// are we entering a macro name?
206         bool macromode_;
207
208
209 ///////////////////////////////////////////////////////////////////
210 //
211 // The part below is the non-integrated rest of the original math
212 // cursor. This should be either generalized for texted or moved
213 // back to the math insets.
214 //
215 ///////////////////////////////////////////////////////////////////
216
217 public:
218         ///
219         void insert(MathAtom const &);
220         ///
221         void insert(MathArray const &);
222         /// return false for empty math insets
223         bool erase();
224         /// return false for empty math insets
225         bool backspace();
226         /// called for LFUN_UP etc
227         bool up();
228         /// called for LFUN_DOWN etc
229         bool down();
230         ///
231         void plainErase();
232         ///
233         void plainInsert(MathAtom const & at);
234         ///
235         void niceInsert(MathAtom const & at);
236         ///
237         void niceInsert(std::string const & str);
238
239         /// in pixels from top of screen
240         void setScreenPos(int x, int y);
241         /// in pixels from left of screen
242         int targetX() const;
243         /// current offset in the top cell
244         /// interpret name a name of a macro
245         void macroModeClose();
246         /// are we currently typing the name of a macro?
247         bool inMacroMode() const;
248         /// get access to the macro we are currently typing
249         MathUnknownInset * activeMacro();
250
251         /// replace selected stuff with at, placing the former
252         // selection in given cell of atom
253         void handleNest(MathAtom const & at, int cell = 0);
254         ///
255         bool isInside(InsetBase const *);
256
257         /// make sure cursor position is valid
258         void normalize();
259         /// mark current cursor trace for redraw
260         void touch();
261
262         /// hack for reveal codes
263         void markInsert();
264         void markErase();
265         /// injects content of a cell into parent
266         void pullArg();
267         /// split font inset etc
268         void handleFont(std::string const & font);
269
270         /// display a message
271         void message(std::string const & msg) const;
272         /// display an error message
273         void errorMessage(std::string const & msg) const;
274         ///
275         std::string getPossibleLabel();
276
277         /// moves position somehow up or down
278         bool goUpDown(bool up);
279
280         /// the name of the macro we are currently inputting
281         std::string macroName();
282         /// where in the curent cell does the macro name start?
283         int macroNamePos();
284         /// can we enter the inset?
285         bool openable(MathAtom const &) const;
286         ///
287         Encoding const * getEncoding() const;
288
289 private:
290         /// moves position closest to (x, y) in current cell
291         void bruteFind2(int x, int y);
292         /// moves position closest to (x, y) in given box
293         bool bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh);
294 };
295
296 #endif // LYXCURSOR_H