]> git.lyx.org Git - lyx.git/blob - src/mathed/math_cursor.h
65d83ba2f2b29a2a5946d9ffac355ede102f5a24
[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         void insert(MathInset *);
69         ///
70         void insert(MathArray const &);
71         ///
72         void erase();
73         ///
74         void backspace();
75         ///
76         void home(bool sel = false);
77         ///
78         void end(bool sel = false);
79         ///
80         bool right(bool sel = false);
81         ///
82         bool left(bool sel = false);
83         ///
84         bool up(bool sel = false);
85         ///
86         bool down(bool sel = false);
87         /// Put the cursor in the first position
88         void first();
89         /// Put the cursor in the last position
90         void last();
91         /// moves cursor position one cell to the left
92         bool posLeft();
93         /// moves cursor position one cell to the right
94         bool posRight();
95         /// moves cursor index one cell to the left
96         bool idxLeft();
97         /// moves cursor index one cell to the right
98         bool idxRight();
99         /// moves position somehow up
100         bool goUp();
101         /// moves position somehow down
102         bool goDown();
103         ///
104         void idxNext();
105         ///
106         void idxPrev();
107         ///
108         void plainErase();
109         ///
110         void plainInsert(MathInset * p);
111         ///
112         void niceInsert(MathInset * p);
113         ///
114         void delLine();
115         /// This is in pixels from (maybe?) the top of inset
116         void setPos(int, int);
117         ///
118         void getPos(int & x, int & y);
119         ///
120         MathInset * par() const;
121         /// return the next enclosing grid inset and the cursor's index in it
122         MathArrayInset * enclosingArray(int &) const;
123         ///
124         InsetFormulaBase const * formula();
125         ///
126         int pos() const;
127         ///
128         int idx() const;
129         ///
130         int size() const;
131         ///
132         void interpret(string const &);
133         ///
134         void setSize(MathStyles);
135         ///
136         bool toggleLimits();
137         ///
138         // Macro mode methods
139         void macroModeClose();
140         ///
141         bool inMacroMode() 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         ///
161         void drawSelection(Painter & pain) const;
162         ///
163         void handleFont(MathTextCodes t);
164         ///
165         void handleDelim(latexkeys const * l, latexkeys const * r);
166         ///
167         void handleNest(MathInset * p);
168         /// Splits cells and shifts right part to the next cell
169         void splitCell();
170         /// Splits line and insert new row of cell 
171         void breakLine();
172         ///
173         MathTextCodes getLastCode() const;
174         ///
175         void pullArg(bool goright);
176         ///
177         bool isInside(MathInset const *) const;
178         ///
179         MathTextCodes nextCode() const;
180         ///
181         char valign() const;
182         ///
183         char halign() const;
184         ///
185         int col() const;
186         ///
187         int row() const;
188
189         ///
190         MathStyles style() const;
191         /// Make sure cursor position is valid
192         void normalize() const;
193         
194         /// enter a MathInset from the front
195         void pushLeft(MathInset * par);
196         /// enter a MathInset from the back
197         void pushRight(MathInset * par);
198         /// leave current MathInset to the left
199         bool popLeft();
200         /// leave current MathInset to the left
201         bool popRight();
202
203         ///
204         MathArray & array() const;
205         ///
206         MathXArray & xarray() const;
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         /// path of positions the cursor had to go if it were leving each inset
214         std::vector<MathCursorPos> Cursor_;
215         /// path of positions the anchor had to go if it were leving each inset
216         std::vector<MathCursorPos> Anchor_;
217
218         /// reference to the last item of the path
219         MathCursorPos & cursor();
220         ///
221         MathCursorPos const & cursor() const;
222
223
224         ///  
225         int last() const;
226         ///
227         MathInset * parInset(int i) const;
228         ///
229         MathMatrixInset * outerPar() const;
230         ///
231         void seldump(char const * str) const;
232         ///
233         void dump(char const * str) const;
234
235         ///
236         void merge(MathArray const & arr);
237         ///
238         MathInset * nextInset() const;
239         ///
240         MathInset * prevInset() const;
241         ///
242         MathScriptInset * prevScriptInset() const;
243         ///
244         MathSpaceInset * prevSpaceInset() const;
245 private:
246         ///
247         string macroName() const;
248         ///
249         void insert(char, MathTextCodes t = LM_TC_MIN);
250         /// can we enter the inset? 
251         bool openable(MathInset *, bool selection) const;
252         /// can the setPos routine enter that inset?
253         bool positionable(MathInset *, bool selection) const;
254         /// write access to cursor cell position
255         int & pos();
256         /// write access to cursor cell index
257         int & idx();
258         /// x-offset of current cell relative to par xo
259         int cellXOffset() const;
260         /// y-offset of current cell relative to par yo
261         int cellYOffset() const;
262         /// current x position relative to par xo
263         int xpos() const;
264         /// current y position relative to par yo
265         int ypos() const;
266         /// adjust position in current cell according to x. idx is not changed.
267         void gotoX(int x);
268
269         ///
270         InsetFormulaBase * const formula_;
271         ///
272         MathTextCodes lastcode_;
273         // Selection stuff
274         /// do we currently select
275         bool selection_;
276 };
277
278 extern MathCursor * mathcursor;
279
280 #endif