]> git.lyx.org Git - lyx.git/blob - src/cursor.h
- Link against qt-mt333.lib which is what the current qt3 cvs produces
[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 class Point;
26 class LyXFont;
27
28 // these should go
29 class MathUnknownInset;
30 class Encoding;
31
32
33 /// The cursor class describes the position of a cursor within a document.
34
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 {
38 public:
39         /// create the cursor of a BufferView
40         explicit LCursor(BufferView & bv);
41
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
51         void pop();
52         /// pop one slice off the cursor stack and go left
53         bool popLeft();
54         /// pop one slice off the cursor stack and go right
55         bool popRight();
56         /// sets cursor part
57         void setCursor(DocIterator const & it);
58
59         //
60         // selection
61         //
62         /// selection active?
63         bool selection() const { return selection_; }
64         /// selection active?
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_; }
70         ///
71         void setSelection();
72         /// set selection at given position
73         void setSelection(DocIterator const & where, size_t n);
74         ///
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;
84         ///
85         void selHandle(bool selecting);
86         //
87         std::string selectionAsString(bool label) const;
88         ///
89         void paste(std::string const & data);
90         ///
91         std::string currentState();
92
93         /// auto-correct mode
94         bool autocorrect() const { return autocorrect_; }
95         /// auto-correct mode
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;
103
104         //
105         // common part
106         //
107         /// move one step to the left
108         bool posLeft();
109         /// move one step to the right
110         bool posRight();
111
112         /// insert an inset
113         void insert(InsetBase *);
114         /// insert a single char
115         void insert(char c);
116         /// insert a string
117         void insert(std::string const & str);
118
119         /// in pixels from left of screen
120         int targetX() const;
121         /// write acess to target x position of cursor
122         int & x_target();
123         /// return target x position of cursor
124         int x_target() const;
125         /// set targetX in current position
126         void setTargetX();
127         /// clear target x position of cursor
128         void clearTargetX();
129
130         /// access to normalized selection anchor
131         CursorSlice anchor() const;
132         /// sets anchor to cursor position
133         void resetAnchor();
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)?
141         int currentMode();
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
148         void undispatched();
149         /// the event was already dispatched
150         void dispatched();
151         /// call update() when done
152         void needsUpdate();
153         /// don't call update() when done
154         void noUpdate();
155
156         /// output
157         friend std::ostream & operator<<(std::ostream & os, LCursor const & cur);
158
159 public:
160         ///
161         BufferView * bv_;
162 //private:
163         /// the anchor position
164         DocIterator anchor_;
165
166         ///
167         DispatchResult disp_;
168
169
170 private:
171         /**
172          * The target x position of the cursor. This is used for when
173          * we have text like :
174          *
175          * blah blah blah blah| blah blah blah
176          * blah blah blah
177          * blah blah blah blah blah blah
178          *
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
181          * shorter than x()
182          */
183         int x_target_;
184         /// do we have a selection?
185         bool selection_;
186         /// are we on the way to get one?
187         bool mark_;
188
189 private:
190
191         //
192         // math specific stuff that could be promoted to "global" later
193         //
194         /// do we allow autocorrection
195         bool autocorrect_;
196         /// are we entering a macro name?
197         bool macromode_;
198
199
200 ///////////////////////////////////////////////////////////////////
201 //
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.
205 //
206 ///////////////////////////////////////////////////////////////////
207
208 public:
209         ///
210         void insert(MathAtom const &);
211         ///
212         void insert(MathArray const &);
213         /// return false for empty math insets
214         bool erase();
215         /// return false for empty math insets
216         bool backspace();
217         /// called for LFUN_UP etc
218         bool up();
219         /// called for LFUN_DOWN etc
220         bool down();
221         ///
222         void plainErase();
223         ///
224         void plainInsert(MathAtom const & at);
225         ///
226         void niceInsert(MathAtom const & at);
227         ///
228         void niceInsert(std::string const & str);
229
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();
239
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);
243         ///
244         bool isInside(InsetBase const *);
245
246         /// make sure cursor position is valid
247         void normalize();
248         /// mark current cursor trace for redraw
249         void touch();
250
251         /// hack for reveal codes
252         void markInsert();
253         void markErase();
254         /// injects content of a cell into parent
255         void pullArg();
256         /// split font inset etc
257         void handleFont(std::string const & font);
258
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;
263         ///
264         std::string getPossibleLabel();
265
266         /// moves position somehow up or down
267         bool goUpDown(bool up);
268
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?
272         int macroNamePos();
273         /// can we enter the inset?
274         bool openable(MathAtom const &) const;
275         ///
276         Encoding const * getEncoding() const;
277         /// font at cursor position
278         LyXFont getFont() const;
279 };
280
281
282 #endif // LYXCURSOR_H