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