]> git.lyx.org Git - lyx.git/blob - src/mathed/math_cursor.h
prepare infrastructure for multicell selection
[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 InsetFormulaBase;
30 class MathArray;
31 class MathXArray;
32
33 /// This is the external interface of Math's subkernel
34 class MathCursor {
35 public:
36         ///
37         explicit MathCursor(InsetFormulaBase *);
38         ///
39         void insert(char, MathTextCodes t = LM_TC_MIN);
40         ///
41         void insert(MathInset *);
42         ///
43         void Home();
44         ///
45         void End();
46         ///
47         bool Right(bool sel = false);
48         ///
49         bool Left(bool sel = false);
50         ///
51         bool Up(bool sel = false);
52         ///
53         bool Down(bool sel = false);
54         /// Put the cursor in the first position
55         void first();
56         /// Put the cursor in the last position
57         void last();
58         ///
59         bool plainLeft();
60         ///
61         bool plainRight();
62         ///
63         void Delete();
64         ///
65         void DelLine();
66         /// This is in pixels from (maybe?) the top of inset
67         void SetPos(int, int);
68         ///
69         void GetPos(int & x, int & y);
70         ///
71         MathInset * par() const;
72         /// return the next enclosing par of the given type and the cursor's
73         //index in it
74         MathInset * enclosing(MathInsetTypes, int &) const;
75         ///
76         InsetFormulaBase const * formula();
77         ///
78         int pos() const;
79         ///
80         void Interpret(string const &);
81         ///
82         void SetSize(MathStyles);
83         ///
84         bool toggleLimits();
85         ///
86         // Macro mode methods
87         void MacroModeOpen();
88         ///
89         void MacroModeClose();
90         ///
91         bool InMacroMode() const;
92         
93         // Local selection methods
94         ///
95         bool Selection() const;
96         ///
97         void SelCopy();
98         ///
99         void SelCut();
100         ///
101         void SelDel();
102         ///
103         void SelPaste();
104         ///
105         void SelHandle(bool);
106         ///
107         void SelStart();
108         ///
109         void SelClear();
110         ///
111         void SelGetArea(int * xp, int * yp, int & n);
112         ///
113         void clearLastCode();
114         ///
115         void setLastCode(MathTextCodes t);
116         ///
117         void handleFont(MathTextCodes t);
118         ///
119         void handleAccent(string const & name, int code);
120         ///
121         void handleDelim(int l, int r);
122         /// Splits cells and shifts right part to the next cell
123         void splitCell();
124         /// Splits line and insert new row of cell 
125         void breakLine();
126         ///
127         MathTextCodes getLastCode() const;
128         ///
129         int idx() const { return cursor_.idx_; }
130         ///
131         void idxNext();
132         ///
133         void idxPrev();
134         ///
135         void pullArg();
136         ///
137         bool isInside(MathInset *) const;
138         ///
139         MathTextCodes nextCode() const;
140         ///
141         MathTextCodes prevCode() const;
142         ///
143         char valign() const;
144         ///
145         char halign() const;
146         ///
147         int col() const;
148         ///
149         int row() const;
150
151 //protected:
152         ///
153         bool macro_mode;
154         
155         // Selection stuff
156         /// do we currently select
157         bool selection;
158
159         ///
160         InsetFormulaBase * const formula_;
161         ///
162         MathTextCodes lastcode;
163
164         ///
165         MathArray & array() const;
166         ///
167         MathXArray & xarray() const;
168
169         ///
170         MathStyles style() const;
171         /// Make sure cursor position is valid
172         void normalize() const;
173         
174         /// Enter a new MathInset from the front or the back
175         void push(MathInset * par, bool first);
176         /// Leave current MathInset
177         bool pop();
178
179 private:
180         /// Description of a position 
181         struct MathIter {
182                 /// inset
183                 MathInset * par_;
184                 /// cell inset
185                 int idx_;
186                 ///
187                 int pos_;
188         };
189
190         /// path of positions the cursor had to go if it were leving each inset
191         std::vector<MathIter> path_;
192
193         /// reference to the last item of the path
194         MathIter anchor_;
195         ///
196         MathIter cursor_;
197         ///
198         int path_idx_;
199
200
201         ///  
202         int last() const;
203         ///
204         MathInset * parInset(int i) const;
205         ///
206         void seldump(char const * str) const;
207         ///
208         void dump(char const * str) const;
209
210         ///
211         int xpos() const;
212         ///
213         void gotoX(int x);
214
215         ///
216         bool nextIsInset() const;
217         ///
218         bool prevIsInset() const;
219         ///
220         void merge(MathArray const & arr);
221         ///
222         MathInset * nextInset() const;
223         ///
224         MathInset * prevInset() const;
225         ///
226         MathUpDownInset * nearbyUpDownInset() const;
227
228         ///
229         MathFuncInset * imacro;
230 };
231
232 extern MathCursor * mathcursor;
233
234 #endif