]> git.lyx.org Git - lyx.git/blob - src/mathed/math_cursor.h
8e700b943ac916a23e4a3b05add50349f6e40852
[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 };
54
55 /// 
56 bool operator==(MathCursorPos const &, MathCursorPos const &);
57 /// 
58 bool operator<(MathCursorPos const &, MathCursorPos const &);
59
60
61 /// This is the external interface of Math's subkernel
62 class MathCursor {
63 public:
64         ///
65         explicit MathCursor(InsetFormulaBase *);
66         ///
67         ~MathCursor();
68         ///
69         void insert(char, MathTextCodes t = LM_TC_MIN);
70         ///
71         void insert(MathInset *);
72         ///
73         void insert(MathArray const &);
74         ///
75         void erase();
76         ///
77         void backspace();
78         ///
79         void home();
80         ///
81         void end();
82         ///
83         bool right(bool sel = false);
84         ///
85         bool left(bool sel = false);
86         ///
87         bool up(bool sel = false);
88         ///
89         bool down(bool sel = false);
90         /// Put the cursor in the first position
91         void first();
92         /// Put the cursor in the last position
93         void last();
94         ///
95         bool posLeft();
96         ///
97         bool posRight();
98         /// moves position one cell to the left
99         bool idxLeft();
100         /// moves position one cell to the right
101         bool idxRight();
102         /// moves position one cell up
103         bool idxUp();
104         /// moves position one cell down
105         bool idxDown();
106         ///
107         void idxNext();
108         ///
109         void idxPrev();
110         ///
111         void plainErase();
112         ///
113         void plainInsert(MathInset * p);
114         ///
115         void delLine();
116         /// This is in pixels from (maybe?) the top of inset
117         void setPos(int, int);
118         ///
119         void getPos(int & x, int & y);
120         ///
121         MathInset * par() const;
122         /// return the next enclosing grid inset and the cursor's index in it
123         MathArrayInset * enclosingArray(int &) const;
124         ///
125         InsetFormulaBase const * formula();
126         ///
127         int pos() const;
128         ///
129         int idx() const;
130         ///
131         int size() const;
132         ///
133         void interpret(string const &);
134         ///
135         void setSize(MathStyles);
136         ///
137         bool toggleLimits();
138         ///
139         // Macro mode methods
140         void macroModeOpen();
141         ///
142         void macroModeClose();
143         ///
144         bool inMacroMode() const;
145         
146         // Local selection methods
147         ///
148         bool selection() const;
149         ///
150         void selCopy();
151         ///
152         void selCut();
153         ///
154         void selDel();
155         ///
156         void selPaste();
157         ///
158         void selHandle(bool);
159         ///
160         void selStart();
161         ///
162         void selClear();
163         ///
164         void drawSelection(Painter & pain) const;
165         ///
166         void clearLastCode();
167         ///
168         void setLastCode(MathTextCodes t);
169         ///
170         void handleFont(MathTextCodes t);
171         ///
172         void handleAccent(string const & name);
173         ///
174         void handleDelim(int l, int r);
175         ///
176         void handleNest(MathInset * p);
177         /// Splits cells and shifts right part to the next cell
178         void splitCell();
179         /// Splits line and insert new row of cell 
180         void breakLine();
181         ///
182         MathTextCodes getLastCode() const;
183         ///
184         void pullArg(bool goright);
185         ///
186         bool isInside(MathInset const *) const;
187         ///
188         MathTextCodes nextCode() const;
189         ///
190         MathTextCodes prevCode() const;
191         ///
192         char valign() const;
193         ///
194         char halign() const;
195         ///
196         int col() const;
197         ///
198         int row() const;
199
200         ///
201         MathStyles style() const;
202         /// Make sure cursor position is valid
203         void normalize() const;
204         
205         /// enter a MathInset from the front
206         void pushLeft(MathInset * par);
207         /// enter a MathInset from the back
208         void pushRight(MathInset * par);
209         /// leave current MathInset to the left
210         bool popLeft();
211         /// leave current MathInset to the left
212         bool popRight();
213
214         ///
215         MathArray & array() const;
216         ///
217         MathXArray & xarray() const;
218
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         void merge(MathArray const & arr);
250         ///
251         MathInset * nextInset() const;
252         ///
253         MathInset * prevInset() const;
254         ///
255         MathScriptInset * prevScriptInset() const;
256         ///
257         MathSpaceInset * prevSpaceInset() const;
258 private:
259         ///
260         int & pos();
261         ///
262         int & idx();
263         /// x-offset of current cell relative to par xo
264         int cellXOffset() const;
265         /// y-offset of current cell relative to par yo
266         int cellYOffset() const;
267         /// current x position relative to par xo
268         int xpos() const;
269         /// current y position relative to par yo
270         int ypos() const;
271         /// adjust position in current cell according to x. idx is not changed.
272         void gotoX(int x);
273
274         ///
275         InsetFormulaBase * const formula_;
276         ///
277         MathTextCodes lastcode_;
278         ///
279         MathFuncInset * imacro_;
280         // Selection stuff
281         /// do we currently select
282         bool selection_;
283 };
284
285 extern MathCursor * mathcursor;
286
287 #endif