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