]> git.lyx.org Git - features.git/blob - src/mathed/math_cursor.h
Part of IU.
[features.git] / src / mathed / math_cursor.h
1 // -*- C++ -*-
2 /**
3  * \file math_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 Alejandro Aguilar Sierra
8  * \author André Pönitz
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef MATH_CURSOR
14 #define MATH_CURSOR
15
16 #include "cursor.h"
17 #include "math_inset.h"
18 #include "math_data.h"
19
20 #include <string>
21
22 class InsetFormulaBase;
23 class BufferView;
24 class PainterInfo;
25 class MathUnknownInset;
26
27 /**
28
29 [Have a look at math_inset.h first]
30
31 The MathCursor is different from the kind of cursor used in the Outer
32 World. It contains a stack of CursorSlice, each of which is made
33 up of a inset pointer, an index and a position offset, marking a path from
34 this formula's MathHullInset to the current position.
35
36 */
37
38
39 namespace mathcursor {
40         /// short of anything else reasonable
41         typedef size_t             size_type;
42         /// type for column numbers
43         typedef ptrdiff_t          difference_type;
44         /// type for cursor positions within a cell
45         typedef lyx::pos_type      pos_type;
46         /// type for cell indices
47         typedef size_t             idx_type;
48         /// type for row numbers
49         typedef size_t             row_type;
50         /// type for column numbers
51         typedef size_t             col_type;
52
53         ///
54         void insert(LCursor & cur, MathAtom const &);
55         ///
56         void insert(LCursor & cur, MathArray const &);
57         ///
58         void insert2(LCursor & cur, std::string const &);
59         ///
60         void paste(LCursor & cur, std::string const & data);
61         /// return false for empty math insets
62         bool erase(LCursor & cur);
63         /// return false for empty math insets
64         bool backspace(LCursor & cur);
65         /// called for LFUN_HOME etc
66         bool home(LCursor & cur, bool sel = false);
67         /// called for LFUN_END etc
68         bool end(LCursor & cur, bool sel = false);
69         /// called for LFUN_RIGHT and LFUN_RIGHTSEL
70         bool right(LCursor & cur, bool sel = false);
71         /// called for LFUN_LEFT etc
72         bool left(LCursor & cur, bool sel = false);
73         /// called for LFUN_UP etc
74         bool up(LCursor & cur, bool sel = false);
75         /// called for LFUN_DOWN etc
76         bool down(LCursor & cur, bool sel = false);
77         /// move to next cell in current inset
78         void idxNext(LCursor & bv);
79         /// move to previous cell in current inset
80         void idxPrev(LCursor & bv);
81         ///
82         void plainErase(LCursor & cur);
83         ///
84         void plainInsert(LCursor & cur, MathAtom const & at);
85         ///
86         void niceInsert(LCursor & cur, MathAtom const & at);
87         ///
88         void niceInsert(LCursor & cur, std::string const & str);
89
90         /// in pixels from top of screen
91         void setScreenPos(LCursor & cur, int x, int y);
92         /// in pixels from top of screen
93         void getScreenPos(LCursor & cur, int & x, int & y);
94         /// in pixels from left of screen
95         int targetX(LCursor & cur);
96         /// return the next enclosing grid inset and the cursor's index in it
97         MathGridInset * enclosingGrid(LCursor & cur, idx_type & idx);
98         /// go up to enclosing grid
99         void popToEnclosingGrid(LCursor & cur);
100         /// go up to the hull inset
101         void popToEnclosingHull(LCursor & cur);
102         /// go up to the hull inset
103         void popToHere(LCursor & cur, MathInset const * p);
104         /// adjust anchor position after deletions/insertions
105         void adjust(LCursor & cur, pos_type from, difference_type diff);
106         ///
107         InsetFormulaBase * formula();
108         /// current offset in the current cell
109         ///
110         bool script(LCursor & cur, bool);
111         ///
112         bool interpret(LCursor & cur, char);
113         /// interpret name a name of a macro
114         void macroModeClose(LCursor & cur);
115         /// are we currently typing the name of a macro?
116         bool inMacroMode(LCursor & cur);
117         /// get access to the macro we are currently typing
118         MathUnknownInset * activeMacro(LCursor & cur);
119         /// are we currently typing '#1' or '#2' or...?
120         bool inMacroArgMode(LCursor & cur);
121         /// are we in math mode (1), text mode (-1) or unsure?
122         MathInset::mode_type currentMode(LCursor & cur);
123
124         // Local selection methods
125         ///
126         void selCopy(LCursor & cur);
127         ///
128         void selCut(LCursor & cur);
129         ///
130         void selDel(LCursor & cur);
131         /// pastes n-th element of cut buffer
132         void selPaste(LCursor & cur, size_t n);
133         ///
134         void selHandle(LCursor & cur, bool);
135         ///
136         void selStart(LCursor & cur);
137         ///
138         void selClear(LCursor & cur);
139         /// clears or deletes selection depending on lyxrc setting
140         void selClearOrDel(LCursor & cur);
141         /// draws light-blue selection background
142         void drawSelection(PainterInfo & pi);
143         /// replace selected stuff with at, placing the former
144         // selection in given cell of atom
145         void handleNest(LCursor & cur, MathAtom const & at, int cell = 0);
146         /// remove this as soon as LyXFunc::getStatus is "localized"
147         inline std::string getLastCode() { return "mathnormal"; }
148         ///
149         bool isInside(MathInset const *);
150         ///
151         char valign(LCursor & cur);
152         ///
153         char halign(LCursor & cur);
154
155         /// make sure cursor position is valid
156         void normalize(LCursor & cur);
157         /// mark current cursor trace for redraw
158         void touch();
159
160         /// enter a MathInset
161         void push(LCursor & cur, MathAtom & par);
162         /// enter a MathInset from the front
163         void pushLeft(LCursor & cur, MathAtom & par);
164         /// enter a MathInset from the back
165         void pushRight(LCursor & cur, MathAtom & par);
166         /// leave current MathInset to the left
167         bool popLeft(LCursor & cur);
168         /// leave current MathInset to the left
169         bool popRight(LCursor & cur);
170
171         /// returns the normalized anchor of the selection
172         CursorSlice normalAnchor(LCursor & cur);
173
174         /// dump selection information for debugging
175         void seldump(char const * str);
176         /// dump selection information for debugging
177         void dump(char const * str);
178         /// moves on
179         void setSelection(LCursor & cur, CursorBase const & where, size_type n);
180         /// grab selection marked by anchor and current cursor
181         std::string grabSelection(LCursor & cur);
182         /// guess what
183         std::string grabAndEraseSelection(LCursor & cur);
184         ///
185         void insert(LCursor & cur, char c);
186         ///
187         void insert(LCursor & cur, std::string const & str);
188         /// lock/unlock inset
189         void insetToggle(LCursor & cur);
190
191         /// hack for reveal codes
192         void markInsert(LCursor & cur);
193         void markErase(LCursor & cur);
194         /// injects content of a cell into parent
195         void pullArg(LCursor & cur);
196         /// split font inset etc
197         void handleFont(LCursor & cur, std::string const & font);
198         ///
199         DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd);
200
201         /// pointer to enclsing LyX inset
202         extern InsetFormulaBase * formula_;
203 }
204
205 void releaseMathCursor(LCursor & cur);
206
207 bool inMathed();
208
209 #endif