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