]> git.lyx.org Git - lyx.git/blob - src/mathed/math_cursor.h
dont use pragma impementation and interface anymore
[lyx.git] / src / mathed / math_cursor.h
1 // -*- C++ -*-
2 /**
3  *  File:        math_cursor.h
4  *  Purpose:     Declaration of interaction classes for mathed
5  *  Author:      Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
6  *  Created:     January 1996
7  *  Description: MathCursor control all user interaction
8  *
9  *  Dependencies: Xlib, XForms
10  *
11  *  Copyright: 1996, Alejandro Aguilar Sierra
12  *
13  *   You are free to use and modify this code under the terms of
14  *   the GNU General Public Licence version 2 or later.
15  */
16
17 #ifndef MATH_CURSOR
18 #define MATH_CURSOR
19
20
21 #include "math_inset.h"
22 #include "math_iterator.h"
23 #include "LString.h"
24
25 class InsetFormulaBase;
26 class BufferView;
27 class MathPainterInfo;
28 class MathUnknownInset;
29
30 /**
31
32 [Have a look at math_inset.h first]
33
34 The MathCursor is different from the kind of cursor used in the Outer
35 World. It contains a stack of MathCursorPos, each of which is made
36 up of a inset pointer, an index and a position offset, marking a path from
37 this formula's MathHullInset to the current position.
38
39 */
40
41
42 class MathCursor {
43 public:
44         /// short of anything else reasonable
45         typedef MathInset::size_type       size_type;
46         /// type for column numbers
47         typedef MathArray::difference_type difference_type;
48         /// type for cursor positions within a cell
49         typedef MathInset::pos_type        pos_type;
50         /// type for cell indices
51         typedef MathInset::idx_type        idx_type;
52         /// type for row numbers
53         typedef MathInset::row_type        row_type;
54         /// type for column numbers
55         typedef MathInset::col_type        col_type;
56
57         ///
58         explicit MathCursor(InsetFormulaBase *, bool left);
59         ///
60         ~MathCursor();
61         ///
62         void insert(MathAtom const &);
63         ///
64         void insert(MathArray const &);
65         ///
66         void paste(string const & data);
67         ///
68         void erase();
69         ///
70         void backspace();
71         /// called for LFUN_HOME etc
72         bool home(bool sel = false);
73         /// called for LFUN_END etc
74         bool end(bool sel = false);
75         /// called for LFUN_RIGHT and LFUN_RIGHTSEL
76         bool right(bool sel = false);
77         /// called for LFUN_LEFT etc
78         bool left(bool sel = false);
79         /// called for LFUN_UP etc
80         bool up(bool sel = false);
81         /// called for LFUN_DOWN etc
82         bool down(bool sel = false);
83         /// Put the cursor in the first position
84         void first();
85         /// Put the cursor in the last position
86         void last();
87         /// move to next cell in current inset
88         void idxNext();
89         /// move to previous cell in current inset
90         void idxPrev();
91         ///
92         void plainErase();
93         ///
94         void plainInsert(MathAtom const &);
95         ///
96         void niceInsert(MathAtom const &);
97         ///
98         void niceInsert(string const &);
99
100         /// in pixels from top of screen
101         void setPos(int x, int y);
102         /// in pixels from top of screen
103         void getPos(int & x, int & y) const;
104         /// in pixels from left of screen
105         int targetX() const;
106         /// current inset
107         MathInset * par() const;
108         /// return the next enclosing grid inset and the cursor's index in it
109         MathGridInset * enclosingGrid(idx_type & idx) const;
110         /// go up to enclosing grid
111         void popToEnclosingGrid();
112         /// go up to the hull inset
113         void popToEnclosingHull();
114         /// go up to the hull inset
115         void popToHere(MathInset const * p);
116         /// adjust anchor position after deletions/insertions
117         void adjust(pos_type from, difference_type diff);
118         ///
119         InsetFormulaBase * formula() const;
120         /// current offset in the current cell
121         pos_type pos() const;
122         /// current cell
123         idx_type idx() const;
124         /// size of current cell
125         size_type size() const;
126         ///
127         bool script(bool);
128         ///
129         bool interpret(char);
130         /// interpret name a name of a macro
131         void macroModeClose();
132         /// are we currently typing the name of a macro?
133         bool inMacroMode() const;
134         /// get access to the macro we are currently typing
135         MathUnknownInset * activeMacro();
136         /// get access to the macro we are currently typing
137         MathUnknownInset const * activeMacro() const;
138         /// are we currently typing '#1' or '#2' or...?
139         bool inMacroArgMode() const;
140         /// are we in math mode (1), text mode (-1) or unsure?
141         MathInset::mode_type currentMode() const;
142
143         // Local selection methods
144         ///
145         bool selection() const;
146         ///
147         void selCopy();
148         ///
149         void selCut();
150         ///
151         void selDel();
152         ///
153         void selPaste();
154         ///
155         void selHandle(bool);
156         ///
157         void selStart();
158         ///
159         void selClear();
160         /// clears or deletes selection depending on lyxrc setting
161         void selClearOrDel();
162         /// draws light-blue selection background
163         void drawSelection(MathPainterInfo & pi) const;
164         ///
165         void handleNest(MathAtom const & at);
166         /// remove this as soon as LyXFunc::getStatus is "localized"
167         string getLastCode() const { return "mathnormal"; }
168         ///
169         bool isInside(MathInset const *) const;
170         ///
171         char valign() const;
172         ///
173         char halign() const;
174
175         /// make sure cursor position is valid
176         void normalize();
177         /// mark current cursor trace for redraw
178         void touch();
179         ///
180         UpdatableInset * asHyperActiveInset() const;
181
182         /// enter a MathInset
183         void push(MathAtom & par);
184         /// enter a MathInset from the front
185         void pushLeft(MathAtom & par);
186         /// enter a MathInset from the back
187         void pushRight(MathAtom & par);
188         /// leave current MathInset to the left
189         bool popLeft();
190         /// leave current MathInset to the left
191         bool popRight();
192
193         ///
194         MathArray & array() const;
195         ///
196         bool hasPrevAtom() const;
197         ///
198         bool hasNextAtom() const;
199         ///
200         MathAtom const & prevAtom() const;
201         ///
202         MathAtom & prevAtom();
203         ///
204         MathAtom const & nextAtom() const;
205         ///
206         MathAtom & nextAtom();
207
208         /// returns the selection
209         void getSelection(MathCursorPos &, MathCursorPos &) const;
210         /// returns the normalized anchor of the selection
211         MathCursorPos normalAnchor() const;
212
213         /// reference to the last item of the path, i.e. "The Cursor"
214         MathCursorPos & cursor();
215         /// reference to the last item of the path, i.e. "The Cursor"
216         MathCursorPos const & cursor() const;
217         /// how deep are we nested?
218         unsigned depth() const;
219
220         /// local dispatcher
221         MathInset::result_type dispatch(FuncRequest const & cmd);
222         /// describe the situation
223         string info() const;
224         /// dump selection information for debugging
225         void seldump(char const * str) const;
226         /// dump selection information for debugging
227         void dump(char const * str) const;
228         /// moves on
229         void setSelection(MathIterator const & where, size_type n);
230         /// grab selection marked by anchor and current cursor
231         string grabSelection() const;
232         /// guess what
233         string grabAndEraseSelection();
234         ///
235         void insert(char c);
236         ///
237         void insert(string const & str);
238         /// lock/unlock inset
239         void insetToggle();
240
241         /// hack for reveal codes
242         void markInsert();
243         void markErase();
244         /// injects content of a cell into parent
245         void pullArg();
246         /// split font inset etc
247         void handleFont(string const & font);
248
249 private:
250         /// moves cursor index one cell to the left
251         bool idxLeft();
252         /// moves cursor index one cell to the right
253         bool idxRight();
254         /// moves cursor to end of last cell of current line
255         bool idxLineLast();
256         /// moves cursor position one cell to the left
257         bool posLeft();
258         /// moves cursor position one cell to the right
259         bool posRight();
260         /// moves position somehow up or down
261         bool goUpDown(bool up);
262         /// moves position closest to (x, y) in given box
263         bool bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh);
264         /// moves position closest to (x, y) in current cell
265         void bruteFind2(int x, int y);
266         /// are we in a nucleus of a script inset?
267         bool inNucleus() const;
268
269         /// erase the selected part and re-sets the cursor
270         void eraseSelection();
271
272         /// the name of the macro we are currently inputting
273         string macroName() const;
274         /// where in the curent cell does the macro name start?
275         difference_type macroNamePos() const;
276         /// can we enter the inset?
277         bool openable(MathAtom const &, bool selection) const;
278         /// write access to cursor cell position
279         pos_type & pos();
280         /// write access to cursor cell index
281         idx_type & idx();
282
283         /// path of positions the cursor had to go if it were leaving each inset
284         MathIterator Cursor_;
285         /// path of positions the anchor had to go if it were leaving each inset
286         mutable MathIterator Anchor_;
287         /// pointer to enclsing LyX inset
288         InsetFormulaBase * formula_;
289         // Selection stuff
290         /// text code of last char entered
291         //MathTextCodes lastcode_;
292         /// do we allow autocorrection
293         bool autocorrect_;
294         /// do we currently select
295         bool selection_;
296         /// are we entering a macro name?
297         bool macromode_;
298         /// are we targeting a certain x coordinate, if so, which one?
299         int targetx_;
300 };
301
302 extern MathCursor * mathcursor;
303 void releaseMathCursor(BufferView * bv);
304
305 #endif