]> git.lyx.org Git - lyx.git/blob - src/mathed/math_inset.h
Use references instead of pointers where possible
[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 "xarray.h"
32
33 /** Abstract base class for all math objects.
34     A math insets is for use of the math editor only, it isn't a
35     general LyX inset. It's used to represent all the math objects.
36     The formulaInset (a LyX inset) encapsulates a math inset.
37 */
38
39
40 class LaTeXFeatures;
41 class MathArrayInset;
42 class MathCharInset;
43 class MathGridInset;
44 class MathNestInset;
45 class MathScriptInset;
46 class MathMatrixInset;
47 class MathSpaceInset;
48 class MathMacroTemplate;
49
50 class MathInset {
51 public: 
52         /// short of anything else reasonable
53         typedef MathArray::size_type     size_type;
54         /// type for cursor positions within a cell
55         typedef MathArray::size_type     pos_type;
56         /// type for cell indices
57         typedef size_type                idx_type;
58         /// type for row numbers
59         typedef size_type                row_type;
60         /// type for column numbers
61         typedef size_type                col_type;
62
63         ///
64         MathInset();
65         /// the virtual base destructor
66         virtual ~MathInset(); 
67
68         /// draw the object, sets xo_ and yo_ cached values 
69         virtual void draw(Painter &, int x, int y) const;
70         /// write LaTeX and Lyx code
71         virtual void write(std::ostream &, bool fragile) const;
72         /// write normalized content
73         virtual void writeNormal(std::ostream &) const;
74         /// reproduce itself
75         virtual MathInset * clone() const = 0;
76         ///substitutes macro arguments if necessary
77         virtual void substitute(MathMacro const & macro);
78         /// compute the size of the object, sets ascend_, descend_ and width_
79         virtual void metrics(MathStyles st) const;
80         /// 
81         virtual int ascent() const { return 1; }
82         ///
83         virtual int descent() const { return 1; }
84         ///
85         virtual int width() const { return 2; }
86         ///
87         virtual int height() const;
88         ///
89         virtual MathStyles size() const;
90
91         /// Where should we go when we press the up cursor key?
92         virtual bool idxUp(idx_type & idx, pos_type & pos) const;
93         /// The down key
94         virtual bool idxDown(idx_type & idx, pos_type & pos) const;
95         /// The left key
96         virtual bool idxLeft(idx_type & idx, pos_type & pos) const;
97         /// The right key
98         virtual bool idxRight(idx_type & idx, pos_type & pos) const;
99
100         /// Move one physical cell up
101         virtual bool idxNext(idx_type & idx, pos_type & pos) const;
102         /// Move one physical cell down
103         virtual bool idxPrev(idx_type & idx, pos_type & pos) const;
104
105         /// Target pos when we enter the inset from the left by pressing "Right"
106         virtual bool idxFirst(idx_type & idx, pos_type & pos) const;
107         /// Target pos when we enter the inset from the right by pressing "Left"
108         virtual bool idxLast(idx_type & idx, pos_type & pos) const;
109
110         /// Where should we go if we press home?
111         virtual bool idxHome(idx_type & idx, pos_type & pos) const;
112         /// Where should we go if we press end?
113         virtual bool idxEnd(idx_type & idx, pos_type & pos) const;
114
115         /// Delete a cell and move cursor
116         // the return value indicates whether the cursor should leave the inset
117         // and/or the whole inset should be deleted
118         virtual void idxDelete(idx_type & idx, bool & popit, bool & deleteit);
119         // deletes a cell range and moves the cursor 
120         virtual void idxDeleteRange(idx_type from, idx_type to);
121         // returns list of cell indices that are "between" from and to for
122         // selection purposes
123         virtual std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
124
125         ///
126         virtual idx_type nargs() const;
127
128         ///
129         virtual MathArray & cell(idx_type);
130         ///
131         virtual MathArray const & cell(idx_type) const;
132         ///
133         virtual MathXArray & xcell(idx_type);
134         ///
135         virtual MathXArray const & xcell(idx_type) const;
136                         
137         ///
138         virtual int xo() const;
139         ///
140         virtual int yo() const;
141         ///
142         virtual void xo(int tx) const;
143         ///
144         virtual void yo(int ty) const;
145         ///
146
147         ///
148         virtual col_type ncols() const { return 1; }
149         ///
150         virtual row_type nrows() const { return 1; }
151         ///
152         virtual col_type col(row_type) const { return 0; }
153         ///
154         virtual row_type row(row_type) const { return 0; }
155         ///
156         virtual int cellXOffset(row_type) const { return 0; }
157         ///
158         virtual int cellYOffset(row_type) const { return 0; }
159         ///
160         virtual void addRow(row_type) {}
161         ///
162         virtual void delRow(row_type) {}
163         ///
164         virtual void addCol(col_type) {}
165         ///
166         virtual void delCol(col_type) {}
167
168         ///
169         virtual void userSetSize(MathStyles &) {}
170
171         ///
172         virtual void getXY(int & x, int & y) const;
173         ///
174         virtual bool covers(int x, int y) const;
175
176         /// identifies NestInsets
177         virtual MathNestInset * asNestInset() { return 0; }
178         /// identifies CharInsets
179         virtual MathCharInset const * asCharInset() const { return 0; }
180         /// identifies ScriptInsets
181         virtual MathScriptInset const * asScriptInset() const { return 0; }
182         /// identifies ScriptInsets
183         virtual MathScriptInset * asScriptInset() { return 0; }
184         /// identifies MatrixInsets
185         virtual MathMatrixInset const * asMatrixInset() const { return 0; }
186         /// identifies MatrixInsets
187         virtual MathMatrixInset * asMatrixInset() { return 0; }
188         /// identifies SpaceInset
189         virtual MathSpaceInset * asSpaceInset() { return 0; }
190         /// identifies GridInset
191         virtual MathGridInset * asGridInset() { return 0; }
192         /// identifies ArrayInsets
193         virtual MathArrayInset * asArrayInset() { return 0; }
194         /// identifies macro templates
195         virtual MathMacroTemplate * asMacroTemplate() { return 0; }
196
197         /// identifies things that can get scripts
198         virtual bool isScriptable() const { return false; }
199         ///
200         virtual bool isActive() const { return nargs() > 0; }
201         ///
202         virtual bool isRelOp() const { return false; }
203         ///
204         virtual bool isMacro() const { return false; }
205
206         ///
207         virtual char getChar() const { return 0; }
208         ///
209         virtual MathTextCodes code() const { return LM_TC_MIN; }
210         /// identifies things that can get \limits or \nolimits
211         virtual bool takesLimits() const { return false; }
212
213         ///
214         virtual void push_back(MathInset *);
215         ///
216         virtual void push_back(unsigned char c, MathTextCodes code);
217         ///
218         virtual void dump() const;
219
220         ///
221         virtual void validate(LaTeXFeatures & features) const;
222         ///
223         virtual void handleFont(MathTextCodes) {}
224
225         ///
226         static int workwidth;
227
228 protected:
229         /// _sets_ style
230         void size(MathStyles s) const;
231         /// the used font size
232         mutable MathStyles size_;
233
234 private:
235         /// the following are used for positioning the cursor with the mouse
236         /// cached cursor start position in pixels from the document left
237         mutable int xo_;
238         /// cached cursor start position in pixels from the document top
239         mutable int yo_;
240 };
241
242 std::ostream & operator<<(std::ostream &, MathInset const &);
243
244 #endif