]> git.lyx.org Git - lyx.git/blob - src/mathed/math_cursor.h
836c43ee007a1ecfa34ad3037635acf14af7845c
[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(char, MathTextCodes t = LM_TC_MIN);
71         ///
72         void insert(MathInset *);
73         ///
74         void insert(MathArray const &);
75         ///
76         void erase();
77         ///
78         void backspace();
79         ///
80         void home();
81         ///
82         void end();
83         ///
84         bool right(bool sel = false);
85         ///
86         bool left(bool sel = false);
87         ///
88         bool up(bool sel = false);
89         ///
90         bool down(bool sel = false);
91         /// Put the cursor in the first position
92         void first();
93         /// Put the cursor in the last position
94         void last();
95         /// moves cursor position one cell to the left
96         bool posLeft();
97         /// moves cursor position one cell to the right
98         bool posRight();
99         /// moves cursor index one cell to the left
100         bool idxLeft();
101         /// moves cursor index one cell to the right
102         bool idxRight();
103         /// moves position somehow up
104         bool goUp();
105         /// moves position somehow down
106         bool goDown();
107         ///
108         void idxNext();
109         ///
110         void idxPrev();
111         ///
112         void plainErase();
113         ///
114         void plainInsert(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 macroModeOpen();
142         ///
143         void macroModeClose();
144         ///
145         bool inMacroMode() const;
146         
147         // Local selection methods
148         ///
149         bool selection() const;
150         ///
151         void selCopy();
152         ///
153         void selCut();
154         ///
155         void selDel();
156         ///
157         void selPaste();
158         ///
159         void selHandle(bool);
160         ///
161         void selStart();
162         ///
163         void selClear();
164         ///
165         void drawSelection(Painter & pain) const;
166         ///
167         void clearLastCode();
168         ///
169         void setLastCode(MathTextCodes t);
170         ///
171         void handleFont(MathTextCodes t);
172         ///
173         void handleAccent(string const & name);
174         ///
175         void handleDelim(latexkeys const * l, latexkeys const * r);
176         ///
177         void handleNest(MathInset * p);
178         /// Splits cells and shifts right part to the next cell
179         void splitCell();
180         /// Splits line and insert new row of cell 
181         void breakLine();
182         ///
183         MathTextCodes getLastCode() const;
184         ///
185         void pullArg(bool goright);
186         ///
187         bool isInside(MathInset const *) const;
188         ///
189         MathTextCodes nextCode() const;
190         ///
191         char valign() const;
192         ///
193         char halign() const;
194         ///
195         int col() const;
196         ///
197         int row() const;
198
199         ///
200         MathStyles style() const;
201         /// Make sure cursor position is valid
202         void normalize() const;
203         
204         /// enter a MathInset from the front
205         void pushLeft(MathInset * par);
206         /// enter a MathInset from the back
207         void pushRight(MathInset * par);
208         /// leave current MathInset to the left
209         bool popLeft();
210         /// leave current MathInset to the left
211         bool popRight();
212
213         ///
214         MathArray & array() const;
215         ///
216         MathXArray & xarray() const;
217
218         /// returns the selection
219         void getSelection(MathCursorPos &, MathCursorPos &) const;
220         /// returns the normalized anchor of the selection
221         MathCursorPos normalAnchor() const;
222         /// returns the normalized anchor of the selection
223         bool openable(MathInset *, bool selection, bool useupdown) const;
224
225         /// path of positions the cursor had to go if it were leving each inset
226         std::vector<MathCursorPos> Cursor_;
227         /// path of positions the anchor had to go if it were leving each inset
228         std::vector<MathCursorPos> Anchor_;
229
230         /// reference to the last item of the path
231         MathCursorPos & cursor();
232         ///
233         MathCursorPos const & cursor() const;
234
235
236         ///  
237         int last() const;
238         ///
239         MathInset * parInset(int i) const;
240         ///
241         MathMatrixInset * outerPar() const;
242         ///
243         void seldump(char const * str) const;
244         ///
245         void dump(char const * str) const;
246
247         ///
248         void merge(MathArray const & arr);
249         ///
250         MathInset * nextInset() const;
251         ///
252         MathInset * prevInset() const;
253         ///
254         MathScriptInset * prevScriptInset() const;
255         ///
256         MathSpaceInset * prevSpaceInset() const;
257 private:
258         ///
259         int & pos();
260         ///
261         int & idx();
262         /// x-offset of current cell relative to par xo
263         int cellXOffset() const;
264         /// y-offset of current cell relative to par yo
265         int cellYOffset() const;
266         /// current x position relative to par xo
267         int xpos() const;
268         /// current y position relative to par yo
269         int ypos() const;
270         /// adjust position in current cell according to x. idx is not changed.
271         void gotoX(int x);
272
273         ///
274         InsetFormulaBase * const formula_;
275         ///
276         MathTextCodes lastcode_;
277         ///
278         MathFuncInset * imacro_;
279         // Selection stuff
280         /// do we currently select
281         bool selection_;
282 };
283
284 extern MathCursor * mathcursor;
285
286 #endif