]> git.lyx.org Git - lyx.git/blob - src/mathed/math_cursor.h
59e76f691808d3c164f4ab1f06ccf3ed1606439c
[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 MathScriptInset;
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         /// Set accent: if argument = 0 it's considered consumed 
84         void setAccent(int ac = 0);
85         /// Returns last accent
86         int getAccent() const;
87         ///
88         // Macro mode methods
89         void MacroModeOpen();
90         ///
91         void MacroModeClose();
92         ///
93         bool InMacroMode() const;
94         
95         // Local selection methods
96         ///
97         bool Selection() const;
98         ///
99         void SelCopy();
100         ///
101         void SelCut();
102         ///
103         void SelDel();
104         ///
105         void SelPaste();
106         ///
107         void SelHandle(bool);
108         ///
109         void SelStart();
110         ///
111         void SelClear();
112         ///
113         void SelGetArea(int * xp, int * yp, int & n);
114         ///
115         void clearLastCode();
116         ///
117         void setLastCode(MathTextCodes t);
118         ///
119         void handleFont(MathTextCodes t);
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         void selArray(MathArray &) 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         ///
157         bool selection;
158         ///
159         int anchor_;
160         ///
161         int cursor_;
162         ///
163         int idx_;
164         ///
165         MathInset       * par_;
166         ///
167         InsetFormulaBase * const formula_;
168         ///
169         void doAccent(char c, MathTextCodes t);
170         ///
171         void doAccent(MathInset * p);
172         ///
173         int accent;
174         ///
175         int nestaccent[8];
176         ///
177         MathTextCodes lastcode;
178
179         ///
180         MathArray & array() const;
181         ///
182         MathXArray & xarray() const;
183
184         ///
185         MathStyles style() const;
186         /// Make sure cursor position is valid
187         void normalize() const;
188         
189         /// Enter a new MathInset from the front or the back
190         void push(MathInset * par, bool first);
191         /// Leave current MathInset
192         bool pop();
193
194 private:
195         /// Description of a position 
196         struct MathIter {
197                 MathInset * par_;
198                 int idx_;
199                 int cursor_;
200         };
201
202         /// MathPath
203         std::vector<MathIter> path_;
204
205         ///  
206         int last() const;
207         ///
208         MathInset * parInset(int i) const;
209         ///
210         void seldump(char const * str) const;
211         ///
212         void dump(char const * str) const;
213
214         ///
215         int xpos() const;
216         ///
217         void gotoX(int x);
218
219         ///
220         bool nextIsInset() const;
221         ///
222         bool prevIsInset() const;
223         ///
224         bool IsFont() const;
225         ///
226         bool IsScript() const;
227         ///
228         void merge(MathArray const & arr);
229         ///
230         MathInset * nextInset() const;
231         ///
232         MathInset * prevInset() const;
233         ///
234         MathScriptInset * nearbyScriptInset() const;
235
236         ///
237         MathFuncInset * imacro;
238 };
239
240 extern MathCursor * mathcursor;
241
242 #endif