]> git.lyx.org Git - features.git/blob - src/mathed/math_cursor.h
928431907053bfd1a036115d9eae50822c1ace51
[features.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         void Delete();
60         ///
61         void DelLine();
62         /// This is in pixels from (maybe?) the top of inset
63         void SetPos(int, int);
64         ///
65         void GetPos(int & x, int & y);
66         ///
67         MathInset * par() const;
68         /// return the next enclosing par of the given type and the cursor's
69         //index in it
70         MathInset * enclosing(MathInsetTypes, int &) const;
71         ///
72         InsetFormulaBase const * formula();
73         ///
74         int pos() const;
75         ///
76         void Interpret(string const &);
77         ///
78         void SetSize(MathStyles);
79         ///
80         bool toggleLimits();
81         /// Set accent: if argument = 0 it's considered consumed 
82         void setAccent(int ac = 0);
83         /// Returns last accent
84         int getAccent() const;
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 toggleLastCode(MathTextCodes t);
118         ///
119         MathTextCodes getLastCode() const;
120         ///
121         int idx() const { return idx_; }
122         ///
123         void idxRight();
124         ///
125         void pullArg();
126         ///
127         bool isInside(MathInset *) const;
128         ///
129         MathTextCodes nextCode() const;
130         ///
131         MathTextCodes prevCode() const;
132         ///
133         void selArray(MathArray &) const;
134         
135 //protected:
136         ///
137         bool macro_mode;
138         
139         // Selection stuff
140         ///
141         bool selection;
142         ///
143         int anchor_;
144         ///
145         int cursor_;
146         ///
147         int idx_;
148         ///
149         MathInset       * par_;
150         ///
151         InsetFormulaBase * const formula_;
152         ///
153         void doAccent(char c, MathTextCodes t);
154         ///
155         void doAccent(MathInset * p);
156         ///
157         int accent;
158         ///
159         int nestaccent[8];
160         ///
161         MathTextCodes lastcode;
162
163         ///
164         MathArray & array() const;
165         ///
166         MathXArray & xarray() const;
167
168         ///
169         MathStyles style() const;
170         ///
171         void normalize() const;
172         
173 private:
174         /// Description of a position 
175         struct MathIter {
176                 MathInset * par_;
177                 int idx_;
178                 int cursor_;
179         };
180
181         /// MathPath
182         std::vector<MathIter> path_;
183
184         ///  
185         void push(MathInset * par, bool first);
186         ///
187         void pop();
188         ///  
189         int last() const;
190         ///
191         MathInset * parInset(int i) const;
192         ///
193         void seldump(char const * str) const;
194         ///
195         void dump(char const * str) const;
196
197         ///
198         int xpos() const;
199         ///
200         void gotoX(int x);
201
202         ///
203         bool nextIsInset() const;
204         ///
205         bool nextIsActive() const;
206         ///
207         bool prevIsInset() const;
208         ///
209         bool prevIsActive() const;
210         ///
211         bool IsFont() const;
212         ///
213         bool IsScript() const;
214         ///
215         void merge(MathArray const & arr);
216         ///
217         MathInset * nextInset() const;
218         ///
219         MathInset * nextActiveInset() const;
220         ///
221         MathInset * prevInset() const;
222         ///
223         MathInset * prevActiveInset() const;
224         ///
225         MathScriptInset * prevScriptInset() const;
226         ///
227         int col() const;
228         ///
229         int row() const;
230
231         ///
232         MathFuncInset * imacro;
233 };
234
235 extern MathCursor * mathcursor;
236
237 #endif