]> git.lyx.org Git - lyx.git/blob - src/mathed/math_cursor.h
8fa6d16fd4e43234e10a70fa331cdbc85228af0f
[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 #ifdef __GNUG__
21 #pragma interface
22 #endif
23
24 #include "math_defs.h"
25
26 class MathInset;
27 class MathArrayInset;
28 class MathFuncInset;
29 class MathMatrixInset;
30 class MathScriptInset;
31 class MathSpaceInset;
32 class InsetFormulaBase;
33 class MathArray;
34 class MathXArray;
35 class Painter;
36 class latexkeys;
37
38 /// Description of a position 
39 struct MathCursorPos {
40         /// inset
41         MathInset * par_;
42         /// cell index
43         int idx_;
44         /// cell position
45         int pos_;
46         /// returns cell corresponding to this position
47         MathArray & cell() const;
48         /// returns cell corresponding to this position
49         MathArray & cell(int idx) const;
50         /// returns xcell corresponding to this position
51         MathXArray & xcell() const;
52         /// returns xcell corresponding to this position
53         MathXArray & xcell(int idx) const;
54 };
55
56 /// 
57 bool operator==(MathCursorPos const &, MathCursorPos const &);
58 /// 
59 bool operator<(MathCursorPos const &, MathCursorPos const &);
60
61
62 /// This is the external interface of Math's subkernel
63 class MathCursor {
64 public:
65         ///
66         explicit MathCursor(InsetFormulaBase *);
67         ///
68         ~MathCursor();
69         ///
70         void insert(MathInset *);
71         ///
72         void insert(MathArray const &);
73         ///
74         void erase();
75         ///
76         void backspace();
77         ///
78         void home();
79         ///
80         void end();
81         ///
82         bool right(bool sel = false);
83         ///
84         bool left(bool sel = false);
85         ///
86         bool up(bool sel = false);
87         ///
88         bool down(bool sel = false);
89         /// Put the cursor in the first position
90         void first();
91         /// Put the cursor in the last position
92         void last();
93         /// moves cursor position one cell to the left
94         bool posLeft();
95         /// moves cursor position one cell to the right
96         bool posRight();
97         /// moves cursor index one cell to the left
98         bool idxLeft();
99         /// moves cursor index one cell to the right
100         bool idxRight();
101         /// moves position somehow up
102         bool goUp();
103         /// moves position somehow down
104         bool goDown();
105         ///
106         void idxNext();
107         ///
108         void idxPrev();
109         ///
110         void plainErase();
111         ///
112         void plainInsert(MathInset * p);
113         ///
114         void niceInsert(MathInset * p);
115         ///
116         void delLine();
117         /// This is in pixels from (maybe?) the top of inset
118         void setPos(int, int);
119         ///
120         void getPos(int & x, int & y);
121         ///
122         MathInset * par() const;
123         /// return the next enclosing grid inset and the cursor's index in it
124         MathArrayInset * enclosingArray(int &) const;
125         ///
126         InsetFormulaBase const * formula();
127         ///
128         int pos() const;
129         ///
130         int idx() const;
131         ///
132         int size() const;
133         ///
134         void interpret(string const &);
135         ///
136         void setSize(MathStyles);
137         ///
138         bool toggleLimits();
139         ///
140         // Macro mode methods
141         void macroModeClose();
142         ///
143         bool inMacroMode() const;
144         
145         // Local selection methods
146         ///
147         bool selection() const;
148         ///
149         void selCopy();
150         ///
151         void selCut();
152         ///
153         void selDel();
154         ///
155         void selPaste();
156         ///
157         void selHandle(bool);
158         ///
159         void selStart();
160         ///
161         void selClear();
162         ///
163         void drawSelection(Painter & pain) const;
164         ///
165         void handleFont(MathTextCodes t);
166         ///
167         void handleAccent(string const & name);
168         ///
169         void handleDelim(latexkeys const * l, latexkeys const * r);
170         ///
171         void handleNest(MathInset * p);
172         /// Splits cells and shifts right part to the next cell
173         void splitCell();
174         /// Splits line and insert new row of cell 
175         void breakLine();
176         ///
177         MathTextCodes getLastCode() const;
178         ///
179         void pullArg(bool goright);
180         ///
181         bool isInside(MathInset const *) const;
182         ///
183         MathTextCodes nextCode() const;
184         ///
185         char valign() const;
186         ///
187         char halign() const;
188         ///
189         int col() const;
190         ///
191         int row() const;
192
193         ///
194         MathStyles style() const;
195         /// Make sure cursor position is valid
196         void normalize() const;
197         
198         /// enter a MathInset from the front
199         void pushLeft(MathInset * par);
200         /// enter a MathInset from the back
201         void pushRight(MathInset * par);
202         /// leave current MathInset to the left
203         bool popLeft();
204         /// leave current MathInset to the left
205         bool popRight();
206
207         ///
208         MathArray & array() const;
209         ///
210         MathXArray & xarray() const;
211
212         /// returns the selection
213         void getSelection(MathCursorPos &, MathCursorPos &) const;
214         /// returns the normalized anchor of the selection
215         MathCursorPos normalAnchor() const;
216         /// returns the normalized anchor of the selection
217         bool openable(MathInset *, bool selection, bool useupdown) const;
218
219         /// path of positions the cursor had to go if it were leving each inset
220         std::vector<MathCursorPos> Cursor_;
221         /// path of positions the anchor had to go if it were leving each inset
222         std::vector<MathCursorPos> Anchor_;
223
224         /// reference to the last item of the path
225         MathCursorPos & cursor();
226         ///
227         MathCursorPos const & cursor() const;
228
229
230         ///  
231         int last() const;
232         ///
233         MathInset * parInset(int i) const;
234         ///
235         MathMatrixInset * outerPar() const;
236         ///
237         void seldump(char const * str) const;
238         ///
239         void dump(char const * str) const;
240
241         ///
242         void merge(MathArray const & arr);
243         ///
244         MathInset * nextInset() const;
245         ///
246         MathInset * prevInset() const;
247         ///
248         MathScriptInset * prevScriptInset() const;
249         ///
250         MathSpaceInset * prevSpaceInset() const;
251 private:
252         ///
253         string macroName() const;
254         ///
255         void insert(char, MathTextCodes t = LM_TC_MIN);
256         ///
257         int & pos();
258         ///
259         int & idx();
260         /// x-offset of current cell relative to par xo
261         int cellXOffset() const;
262         /// y-offset of current cell relative to par yo
263         int cellYOffset() const;
264         /// current x position relative to par xo
265         int xpos() const;
266         /// current y position relative to par yo
267         int ypos() const;
268         /// adjust position in current cell according to x. idx is not changed.
269         void gotoX(int x);
270
271         ///
272         InsetFormulaBase * const formula_;
273         ///
274         MathTextCodes lastcode_;
275         // Selection stuff
276         /// do we currently select
277         bool selection_;
278 };
279
280 extern MathCursor * mathcursor;
281
282 #endif