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