]> git.lyx.org Git - lyx.git/blob - src/cursor.h
Change to use preffered calling of Boost.Function
[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         void dispatch(FuncRequest const & cmd);
42         /// get the resut of the last dispatch
43         DispatchResult result() const;
44         /// are we willing to handle this event?
45         bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
46
47         /// add a new cursor slice
48         void push(InsetBase & inset);
49         /// add a new cursor slice, place cursor on left end
50         void pushLeft(InsetBase & inset);
51         /// pop one level off the cursor
52         void pop();
53         /// pop one slice off the cursor stack and go left
54         bool popLeft();
55         /// pop one slice off the cursor stack and go right
56         bool popRight();
57         /// sets cursor part
58         void setCursor(DocIterator const & it);
59
60         //
61         // selection
62         //
63         /// selection active?
64         bool selection() const { return selection_; }
65         /// selection active?
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_; }
71         ///
72         void setSelection();
73         /// set selection at given position
74         void setSelection(DocIterator const & where, size_t n);
75         ///
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;
85         ///
86         void selHandle(bool selecting);
87         //
88         std::string selectionAsString(bool label) const;
89         ///
90         void paste(std::string const & data);
91         ///
92         std::string currentState();
93
94         /// auto-correct mode
95         bool autocorrect() const { return autocorrect_; }
96         /// auto-correct mode
97         bool & autocorrect() { return autocorrect_; }
98         /// are we entering a macro name?
99         bool macromode() const { return macromode_; }
100         /// are we entering a macro name?
101         bool & macromode() { return macromode_; }
102         /// returns x,y position
103         void getPos(int & x, int & y) const;
104         /// returns cursor dimension
105         void getDim(int & asc, int & desc) const;
106
107         //
108         // common part
109         //
110         /// move one step to the left
111         bool posLeft();
112         /// move one step to the right
113         bool posRight();
114
115         /// insert an inset
116         void insert(InsetBase *);
117         /// insert a single char
118         void insert(char c);
119         /// insert a string
120         void insert(std::string const & str);
121
122         /// write acess to target x position of cursor
123         int & x_target();
124         /// return target x position of cursor
125         int x_target() const;
126         /// clear target x position of cursor
127         void clearTargetX();
128
129         /// access to normalized selection anchor
130         CursorSlice anchor() const;
131         /// sets anchor to cursor position
132         void resetAnchor();
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)?
140         int currentMode();
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);
146         /// the event was not (yet) dispatched
147         void undispatched();
148         /// the event was already dispatched
149         void dispatched();
150         /// call update() when done
151         void needsUpdate();
152         /// don't call update() when done
153         void noUpdate();
154
155         /// output
156         friend std::ostream & operator<<(std::ostream & os, LCursor const & cur);
157
158 public:
159         ///
160         BufferView * bv_;
161 //private:
162         /// the anchor position
163         DocIterator anchor_;
164
165         ///
166         DispatchResult disp_;
167
168 private:
169         /**
170          * The target x position of the cursor. This is used for when
171          * we have text like :
172          *
173          * blah blah blah blah| blah blah blah
174          * blah blah blah
175          * blah blah blah blah blah blah
176          *
177          * When we move onto row 3, we would like to be vertically aligned
178          * with where we were in row 1, despite the fact that row 2 is
179          * shorter than x()
180          */
181         int x_target_;
182         /// do we have a selection?
183         bool selection_;
184         /// are we on the way to get one?
185         bool mark_;
186
187 public:
188         /// the actual cursor position
189         int xo_;
190         int yo_;
191
192 private:
193
194         //
195         // math specific stuff that could be promoted to "global" later
196         //
197         /// do we allow autocorrection
198         bool autocorrect_;
199         /// are we entering a macro name?
200         bool macromode_;
201
202
203 ///////////////////////////////////////////////////////////////////
204 //
205 // The part below is the non-integrated rest of the original math
206 // cursor. This should be either generalized for texted or moved
207 // back to the math insets.
208 //
209 ///////////////////////////////////////////////////////////////////
210
211 public:
212         ///
213         void insert(MathAtom const &);
214         ///
215         void insert(MathArray const &);
216         /// return false for empty math insets
217         bool erase();
218         /// return false for empty math insets
219         bool backspace();
220         /// called for LFUN_UP etc
221         bool up();
222         /// called for LFUN_DOWN etc
223         bool down();
224         ///
225         void plainErase();
226         ///
227         void plainInsert(MathAtom const & at);
228         ///
229         void niceInsert(MathAtom const & at);
230         ///
231         void niceInsert(std::string const & str);
232
233         /// in pixels from top of screen
234         void setScreenPos(int x, int y);
235         /// in pixels from left of screen
236         int targetX() const;
237         /// current offset in the top cell
238         /// interpret name a name of a macro
239         void macroModeClose();
240         /// are we currently typing the name of a macro?
241         bool inMacroMode() const;
242         /// get access to the macro we are currently typing
243         MathUnknownInset * activeMacro();
244
245         /// replace selected stuff with at, placing the former
246         // selection in given cell of atom
247         void handleNest(MathAtom const & at, int cell = 0);
248         ///
249         bool isInside(InsetBase const *);
250
251         /// make sure cursor position is valid
252         void normalize();
253         /// mark current cursor trace for redraw
254         void touch();
255
256         /// hack for reveal codes
257         void markInsert();
258         void markErase();
259         /// injects content of a cell into parent
260         void pullArg();
261         /// split font inset etc
262         void handleFont(std::string const & font);
263
264         /// display a message
265         void message(std::string const & msg) const;
266         /// display an error message
267         void errorMessage(std::string const & msg) const;
268         ///
269         std::string getPossibleLabel();
270
271         /// moves position somehow up or down
272         bool goUpDown(bool up);
273
274         /// the name of the macro we are currently inputting
275         std::string macroName();
276         /// where in the curent cell does the macro name start?
277         int macroNamePos();
278         /// can we enter the inset?
279         bool openable(MathAtom const &) const;
280         ///
281         Encoding const * getEncoding() const;
282 };
283
284 #endif // LYXCURSOR_H