]> git.lyx.org Git - lyx.git/blob - src/mathed/math_cursor.h
Andre's mathinset shrink patch ; default .lyx extension when loading files
[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 MathArrayInset;
31 class InsetFormulaBase;
32 class MathArray;
33 class MathXArray;
34 class Painter;
35
36 /// Description of a position 
37 struct MathCursorPos {
38         /// inset
39         MathInset * par_;
40         /// cell index
41         int idx_;
42         /// cell position
43         int pos_;
44         /// returns cell corresponding to this position
45         MathArray & cell() const;
46         /// returns cell corresponding to this position
47         MathArray & cell(int idx) const;
48         /// returns xcell corresponding to this position
49         MathXArray & xcell() const;
50         /// returns xcell corresponding to this position
51         MathXArray & xcell(int idx) const;
52         /// moves position on cell to the left
53         bool idxLeft();
54         /// moves position on cell to the right
55         bool idxRight();
56         /// moves position on cell up
57         bool idxUp();
58         /// moves position on cell up
59         bool idxDown();
60 };
61
62 /// 
63 bool operator==(MathCursorPos const &, MathCursorPos const &);
64 /// 
65 bool operator<(MathCursorPos const &, MathCursorPos const &);
66
67
68 /// This is the external interface of Math's subkernel
69 class MathCursor {
70 public:
71         ///
72         explicit MathCursor(InsetFormulaBase *);
73         ///
74         void insert(char, MathTextCodes t = LM_TC_MIN);
75         ///
76         void insert(MathInset *);
77         ///
78         void insert(MathArray const &);
79         ///
80         void erase();
81         ///
82         void home();
83         ///
84         void end();
85         ///
86         bool right(bool sel = false);
87         ///
88         bool left(bool sel = false);
89         ///
90         bool up(bool sel = false);
91         ///
92         bool down(bool sel = false);
93         /// Put the cursor in the first position
94         void first();
95         /// Put the cursor in the last position
96         void last();
97         ///
98         bool plainLeft();
99         ///
100         bool plainRight();
101         ///
102         void plainErase();
103         ///
104         void plainInsert(MathInset * p);
105         ///
106         void delLine();
107         /// This is in pixels from (maybe?) the top of inset
108         void setPos(int, int);
109         ///
110         void getPos(int & x, int & y);
111         ///
112         MathInset * par() const;
113         /// return the next enclosing grid inset and the cursor's index in it
114         MathArrayInset * enclosingArray(int &) const;
115         ///
116         InsetFormulaBase const * formula();
117         ///
118         int pos() const;
119         ///
120         void interpret(string const &);
121         ///
122         void setSize(MathStyles);
123         ///
124         bool toggleLimits();
125         ///
126         // Macro mode methods
127         void macroModeOpen();
128         ///
129         void macroModeClose();
130         ///
131         bool inMacroMode() const;
132         
133         // Local selection methods
134         ///
135         bool selection() const;
136         ///
137         void selCopy();
138         ///
139         void selCut();
140         ///
141         void selDel();
142         ///
143         void selPaste();
144         ///
145         void selHandle(bool);
146         ///
147         void selStart();
148         ///
149         void selClear();
150         ///
151         void drawSelection(Painter & pain) const;
152         ///
153         void clearLastCode();
154         ///
155         void setLastCode(MathTextCodes t);
156         ///
157         void handleFont(MathTextCodes t);
158         ///
159         void handleAccent(string const & name);
160         ///
161         void handleDelim(int l, int r);
162         /// Splits cells and shifts right part to the next cell
163         void splitCell();
164         /// Splits line and insert new row of cell 
165         void breakLine();
166         ///
167         MathTextCodes getLastCode() const;
168         ///
169         int idx() const { return cursor().idx_; }
170         ///
171         void idxNext();
172         ///
173         void idxPrev();
174         ///
175         void pullArg(bool goright);
176         ///
177         bool isInside(MathInset *) const;
178         ///
179         MathTextCodes nextCode() const;
180         ///
181         MathTextCodes prevCode() const;
182         ///
183         char valign() const;
184         ///
185         char halign() const;
186         ///
187         int col() const;
188         ///
189         int row() const;
190
191         ///
192         MathStyles style() const;
193         /// Make sure cursor position is valid
194         void normalize() const;
195         
196         /// Enter a new MathInset from the front or the back
197         void push(MathInset * par, bool first);
198         /// Leave current MathInset
199         bool pop();
200
201 //private:
202         ///
203         InsetFormulaBase * const formula_;
204         ///
205         MathTextCodes lastcode_;
206         ///
207         MathFuncInset * imacro_;
208         // Selection stuff
209         /// do we currently select
210         bool selection_;
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 extern MathCursor * mathcursor;
270
271 #endif