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