]> git.lyx.org Git - lyx.git/blob - src/mathed/math_inset.h
new parser
[lyx.git] / src / mathed / math_inset.h
1 // -*- C++ -*-
2 /*
3  *  File:        math_inset.h
4  *  Purpose:     Declaration of insets for mathed 
5  *  Author:      Alejandro Aguilar Sierra <asierra@servidor.unam.mx> 
6  *  Created:     January 1996
7  *  Description: Math paragraph and objects for a WYSIWYG math editor.
8  *
9  *  Dependencies: Xlib, XForms
10  *
11  *  Copyright: 1996, 1997 Alejandro Aguilar Sierra
12  *
13  *   Version: 0.8beta, Math & Lyx project.
14  *
15  *   You are free to use and modify this code under the terms of
16  *   the GNU General Public Licence version 2 or later.
17  */
18
19 //  Note: These math insets are internal to Math and are not derived
20 //        from lyx inset.
21
22 #ifndef MATH_INSET_H
23 #define MATH_INSET_H
24
25 #include <config.h>
26
27 #ifdef __GNUG__
28 #pragma interface
29 #endif
30
31 #include "symbol_def.h"
32 #include "xarray.h"
33
34 /** Abstract base class for all math objects.
35     A math insets is for use of the math editor only, it isn't a
36     general LyX inset. It's used to represent all the math objects.
37     The formulaInset (a LyX inset) encapsulates a math inset.
38 */
39
40
41 class LaTeXFeatures;
42
43 class MathInset {
44 public: 
45         ///
46         MathInset();
47
48         /// the virtual base destructor
49         virtual ~MathInset() {}
50
51         /// draw the object, sets xo_ and yo_ cached values 
52         virtual void draw(Painter &, int x, int y) const;
53         /// write LaTeX and Lyx code
54         virtual void write(std::ostream &, bool fragile) const;
55         /// write normalized content
56         virtual void writeNormal(std::ostream &) const;
57         /// reproduce itself
58         virtual MathInset * clone() const = 0;
59         /// appends itself with macro arguments substituted
60         virtual void substitute(MathArray & array, MathMacro const & macro) const;
61         /// compute the size of the object, sets ascend_, descend_ and width_
62         virtual void metrics(MathStyles st) const;
63         /// 
64         virtual int ascent() const { return 1; }
65         ///
66         virtual int descent() const { return 1; }
67         ///
68         virtual int width() const { return 2; }
69         ///
70         virtual int height() const;
71         ///
72         virtual MathStyles size() const;
73
74         /// Where should we go when we press the up cursor key?
75         virtual bool idxUp(int & idx, int & pos) const;
76         /// The down key
77         virtual bool idxDown(int & idx, int & pos) const;
78         /// The left key
79         virtual bool idxLeft(int & idx, int & pos) const;
80         /// The right key
81         virtual bool idxRight(int & idx, int & pos) const;
82
83         /// Move one physical cell up
84         virtual bool idxNext(int & idx, int & pos) const;
85         /// Move one physical cell down
86         virtual bool idxPrev(int & idx, int & pos) const;
87
88         /// Target pos when we enter the inset from the left by pressing "Right"
89         virtual bool idxFirst(int & idx, int & pos) const;
90         /// Target pos when we enter the inset from the left by pressing "Up"
91         virtual bool idxFirstUp(int & idx, int & pos) const;
92         /// Target pos when we enter the inset from the left by pressing "Down"
93         virtual bool idxFirstDown(int & idx, int & pos) const;
94
95         /// Target pos when we enter the inset from the right by pressing "Left"
96         virtual bool idxLast(int & idx, int & pos) const;
97         /// Target pos when we enter the inset from the right by pressing "Up"
98         virtual bool idxLastUp(int & idx, int & pos) const;
99         /// Target pos when we enter the inset from the right by pressing "Down"
100         virtual bool idxLastDown(int & idx, int & pos) const;
101
102         /// Where should we go if we press home?
103         virtual bool idxHome(int & idx, int & pos) const;
104         /// Where should we go if we press end?
105         virtual bool idxEnd(int & idx, int & pos) const;
106
107         /// Delete a cell and move cursor
108         // the return value indicates whether the cursor should leave the inset
109         // and/or the whole inset should be deleted
110         virtual void idxDelete(int & idx, bool & popit, bool & deleteit);
111         // deletes a cell range and moves the cursor 
112         virtual void idxDeleteRange(int from, int to);
113         // returns list of cell indices that are "between" from and to for
114         // selection purposes
115         virtual std::vector<int> idxBetween(int from, int to) const;
116
117         ///
118         virtual int nargs() const;
119
120         ///
121         virtual MathArray & cell(int);
122         ///
123         virtual MathArray const & cell(int) const;
124         ///
125         virtual MathXArray & xcell(int);
126         ///
127         virtual MathXArray const & xcell(int) const;
128                         
129         ///
130         virtual int xo() const;
131         ///
132         virtual int yo() const;
133         ///
134         virtual void xo(int tx) const;
135         ///
136         virtual void yo(int ty) const;
137         ///
138
139         ///
140         virtual int ncols() const { return 1; }
141         ///
142         virtual int nrows() const { return 1; }
143         ///
144         virtual int col(int) const { return 0; }
145         ///
146         virtual int row(int) const { return 0; }
147         ///
148         virtual int cellXOffset(int) const { return 0; }
149         ///
150         virtual int cellYOffset(int) const { return 0; }
151         ///
152         virtual void addRow(int) {}
153         ///
154         virtual void delRow(int) {}
155         ///
156         virtual void addCol(int) {}
157         ///
158         virtual void delCol(int) {}
159
160         ///
161         virtual void userSetSize(MathStyles &) {}
162
163         ///
164         virtual void getXY(int & x, int & y) const;
165         ///
166         virtual bool covers(int x, int y) const;
167         /// identifies things that can get scripts
168         virtual bool isScriptable() const { return false; }
169         /// identifies ScriptInsets
170         virtual bool isScriptInset() const { return false; }
171         /// identifies SpaceInsets
172         virtual bool isSpaceInset() const { return false; }
173         /// identifies GridInsets
174         virtual bool isGrid() const { return false; }
175         /// identifies ArrayInsets
176         virtual bool isArray() const { return false; }
177         /// identifies Charinsets
178         virtual bool isCharInset() const { return false; }
179         ///
180         virtual bool isActive() const { return nargs() > 0; }
181         ///
182         virtual bool isRelOp() const { return false; }
183         ///
184         virtual bool isMacro() const { return false; }
185         ///
186         virtual char getChar() const { return 0; }
187         ///
188         virtual MathTextCodes code() const { return LM_TC_MIN; }
189
190         ///
191         virtual void push_back(MathInset *);
192         ///
193         virtual void push_back(unsigned char c, MathTextCodes code);
194         ///
195         virtual void dump() const;
196
197         ///
198         virtual void validate(LaTeXFeatures & features) const;
199         ///
200         virtual void handleFont(MathTextCodes) {}
201
202         ///
203         static int workwidth;
204
205 protected:
206         /// _sets_ style
207         void size(MathStyles s) const;
208         /// the used font size
209         mutable MathStyles size_;
210
211 private:
212         /// the following are used for positioning the cursor with the mouse
213         /// cached cursor start position in pixels from the document left
214         mutable int xo_;
215         /// cached cursor start position in pixels from the document top
216         mutable int yo_;
217 };
218
219 std::ostream & operator<<(std::ostream &, MathInset const &);
220
221 #endif