]> git.lyx.org Git - lyx.git/blob - src/mathed/math_cursor.h
LyX Drinkers United: patch 2
[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 toggleLastCode(MathTextCodes t);
120         ///
121         MathTextCodes getLastCode() const;
122         ///
123         int idx() const { return idx_; }
124         ///
125         void idxRight();
126         ///
127         void pullArg();
128         ///
129         bool isInside(MathInset *) const;
130         ///
131         MathTextCodes nextCode() const;
132         ///
133         MathTextCodes prevCode() const;
134         ///
135         void selArray(MathArray &) const;
136         ///
137         char valign() const;
138         ///
139         char halign() const;
140         ///
141         int col() const;
142         ///
143         int row() const;
144
145 //protected:
146         ///
147         bool macro_mode;
148         
149         // Selection stuff
150         ///
151         bool selection;
152         ///
153         int anchor_;
154         ///
155         int cursor_;
156         ///
157         int idx_;
158         ///
159         MathInset       * par_;
160         ///
161         InsetFormulaBase * const formula_;
162         ///
163         void doAccent(char c, MathTextCodes t);
164         ///
165         void doAccent(MathInset * p);
166         ///
167         int accent;
168         ///
169         int nestaccent[8];
170         ///
171         MathTextCodes lastcode;
172
173         ///
174         MathArray & array() const;
175         ///
176         MathXArray & xarray() const;
177
178         ///
179         MathStyles style() const;
180         /// Make sure cursor position is valid
181         void normalize() const;
182         
183         /// Enter a new MathInset from the front or the back
184         void push(MathInset * par, bool first);
185         /// Leave current MathInset
186         bool pop();
187
188 private:
189         /// Description of a position 
190         struct MathIter {
191                 MathInset * par_;
192                 int idx_;
193                 int cursor_;
194         };
195
196         /// MathPath
197         std::vector<MathIter> path_;
198
199         ///  
200         int last() const;
201         ///
202         MathInset * parInset(int i) const;
203         ///
204         void seldump(char const * str) const;
205         ///
206         void dump(char const * str) const;
207
208         ///
209         int xpos() const;
210         ///
211         void gotoX(int x);
212
213         ///
214         bool nextIsInset() const;
215         ///
216         bool nextIsActive() const;
217         ///
218         bool prevIsInset() const;
219         ///
220         bool prevIsActive() const;
221         ///
222         bool IsFont() const;
223         ///
224         bool IsScript() const;
225         ///
226         void merge(MathArray const & arr);
227         ///
228         MathInset * nextInset() const;
229         ///
230         MathInset * nextActiveInset() const;
231         ///
232         MathInset * prevInset() const;
233         ///
234         MathInset * prevActiveInset() const;
235         ///
236         MathScriptInset * nearbyScriptInset() const;
237
238         ///
239         MathFuncInset * imacro;
240 };
241
242 extern MathCursor * mathcursor;
243
244 #endif