]> git.lyx.org Git - lyx.git/blob - src/mathed/math_cursor.h
769143eb0561d4d601f7b3267b8a2cfaa1402d8a
[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 MathFuncInset;
28 class MathUpDownInset;
29 class MathSpaceInset;
30 class InsetFormulaBase;
31 class MathArray;
32 class MathXArray;
33 class Painter;
34
35 /// Description of a position 
36 struct MathCursorPos {
37         /// inset
38         MathInset * par_;
39         /// cell index
40         int idx_;
41         /// cell position
42         int pos_;
43         /// returns cell corresponding to this position
44         MathArray & cell() const;
45         /// returns cell corresponding to this position
46         MathArray & cell(int idx) const;
47         /// returns xcell corresponding to this position
48         MathXArray & xcell() const;
49         /// returns xcell corresponding to this position
50         MathXArray & xcell(int idx) const;
51         /// moves position on cell to the left
52         bool idxLeft();
53         /// moves position on cell to the right
54         bool idxRight();
55         /// moves position on cell up
56         bool idxUp();
57         /// moves position on cell up
58         bool idxDown();
59 };
60
61 /// 
62 bool operator==(MathCursorPos const &, MathCursorPos const &);
63 /// 
64 bool operator<(MathCursorPos const &, MathCursorPos const &);
65
66
67 /// This is the external interface of Math's subkernel
68 class MathCursor {
69 public:
70         ///
71         explicit MathCursor(InsetFormulaBase *);
72         ///
73         void insert(char, MathTextCodes t = LM_TC_MIN);
74         ///
75         void insert(MathInset *);
76         ///
77         void insert(MathArray const &);
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 plainLeft();
96         ///
97         bool plainRight();
98         ///
99         void Delete();
100         ///
101         void DelLine();
102         /// This is in pixels from (maybe?) the top of inset
103         void SetPos(int, int);
104         ///
105         void GetPos(int & x, int & y);
106         ///
107         MathInset * par() const;
108         /// return the next enclosing par of the given type and the cursor's
109         //index in it
110         MathInset * enclosing(MathInsetTypes, int &) const;
111         ///
112         InsetFormulaBase const * formula();
113         ///
114         int pos() const;
115         ///
116         void Interpret(string const &);
117         ///
118         void SetSize(MathStyles);
119         ///
120         bool toggleLimits();
121         ///
122         // Macro mode methods
123         void MacroModeOpen();
124         ///
125         void MacroModeClose();
126         ///
127         bool InMacroMode() const;
128         
129         // Local selection methods
130         ///
131         bool Selection() const;
132         ///
133         void SelCopy();
134         ///
135         void SelCut();
136         ///
137         void SelDel();
138         ///
139         void SelPaste();
140         ///
141         void SelHandle(bool);
142         ///
143         void SelStart();
144         ///
145         void SelClear();
146         ///
147         void drawSelection(Painter & pain) const;
148         ///
149         void clearLastCode();
150         ///
151         void setLastCode(MathTextCodes t);
152         ///
153         void handleFont(MathTextCodes t);
154         ///
155         void handleAccent(string const & name, int code);
156         ///
157         void handleDelim(int l, int r);
158         /// Splits cells and shifts right part to the next cell
159         void splitCell();
160         /// Splits line and insert new row of cell 
161         void breakLine();
162         ///
163         MathTextCodes getLastCode() const;
164         ///
165         int idx() const { return cursor().idx_; }
166         ///
167         void idxNext();
168         ///
169         void idxPrev();
170         ///
171         void pullArg(bool goright);
172         ///
173         bool isInside(MathInset *) const;
174         ///
175         MathTextCodes nextCode() const;
176         ///
177         MathTextCodes prevCode() const;
178         ///
179         char valign() const;
180         ///
181         char halign() const;
182         ///
183         int col() const;
184         ///
185         int row() const;
186
187         ///
188         MathStyles style() const;
189         /// Make sure cursor position is valid
190         void normalize() const;
191         
192         /// Enter a new MathInset from the front or the back
193         void push(MathInset * par, bool first);
194         /// Leave current MathInset
195         bool pop();
196
197 //private:
198         ///
199         bool macro_mode;
200         
201         // Selection stuff
202         /// do we currently select
203         bool selection;
204
205         ///
206         InsetFormulaBase * const formula_;
207         ///
208         MathTextCodes lastcode;
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         void seldump(char const * str) const;
243         ///
244         void dump(char const * str) const;
245
246         ///
247         int xpos() const;
248         ///
249         void gotoX(int x);
250
251         ///
252         bool nextIsInset() const;
253         ///
254         bool prevIsInset() const;
255         ///
256         void merge(MathArray const & arr);
257         ///
258         MathInset * nextInset() const;
259         ///
260         MathInset * prevInset() const;
261         ///
262         MathUpDownInset * prevUpDownInset() const;
263         ///
264         MathSpaceInset * prevSpaceInset() const;
265
266         ///
267         MathFuncInset * imacro;
268 };
269
270 extern MathCursor * mathcursor;
271
272 #endif