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