]> git.lyx.org Git - lyx.git/blob - src/mathed/math_inset.h
cosmetics: rename (x)array.[Ch] into math_(x)data.[Ch]
[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 "math_xdata.h"
32 #include "math_defs.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 MathArrayInset;
42 class MathBoxInset;
43 class MathCharInset;
44 class MathGridInset;
45 class MathNestInset;
46 class MathHullInset;
47 class MathScriptInset;
48 class MathSpaceInset;
49 class MathMacroTemplate;
50
51 class LaTeXFeatures;
52 class BufferView;
53 class UpdatableInset;
54
55
56 class MathInset {
57 public: 
58         /// short of anything else reasonable
59         typedef MathArray::size_type     size_type;
60         /// type for cursor positions within a cell
61         typedef MathArray::size_type     pos_type;
62         /// type for cell indices
63         typedef size_type                idx_type;
64         /// type for row numbers
65         typedef size_type                row_type;
66         /// type for column numbers
67         typedef size_type                col_type;
68
69         ///
70         MathInset();
71         /// the virtual base destructor
72         virtual ~MathInset(); 
73
74         /// draw the object
75         virtual void draw(Painter &, int x, int y) const;
76         /// write LaTeX and Lyx code
77         virtual void write(MathWriteInfo & os) const;
78         /// reproduce itself
79         virtual MathInset * clone() const = 0;
80         ///substitutes macro arguments if necessary
81         virtual void substitute(MathMacro const & macro);
82         /// compute the size of the object, sets ascend_, descend_ and width_
83         virtual void metrics(MathMetricsInfo const & st) const;
84         /// 
85         virtual int ascent() const { return 1; }
86         ///
87         virtual int descent() const { return 1; }
88         ///
89         virtual int width() const { return 2; }
90         ///
91         virtual int height() const;
92
93         /// Where should we go when we press the up cursor key?
94         virtual bool idxUp(idx_type & idx, pos_type & pos) const;
95         /// The down key
96         virtual bool idxDown(idx_type & idx, pos_type & pos) const;
97         /// The left key
98         virtual bool idxLeft(idx_type & idx, pos_type & pos) const;
99         /// The right key
100         virtual bool idxRight(idx_type & idx, pos_type & pos) const;
101
102         /// Move one physical cell up
103         virtual bool idxNext(idx_type & idx, pos_type & pos) const;
104         /// Move one physical cell down
105         virtual bool idxPrev(idx_type & idx, pos_type & pos) const;
106
107         /// Target pos when we enter the inset from the left by pressing "Right"
108         virtual bool idxFirst(idx_type & idx, pos_type & pos) const;
109         /// Target pos when we enter the inset from the right by pressing "Left"
110         virtual bool idxLast(idx_type & idx, pos_type & pos) const;
111
112         /// Where should we go if we press home?
113         virtual bool idxHome(idx_type & idx, pos_type & pos) const;
114         /// Where should we go if we press end?
115         virtual bool idxEnd(idx_type & idx, pos_type & pos) const;
116
117         /// Delete a cell and move cursor
118         // the return value indicates whether the cursor should leave the inset
119         // and/or the whole inset should be deleted
120         virtual void idxDelete(idx_type & idx, bool & popit, bool & deleteit);
121         // deletes a cell range and moves the cursor 
122         virtual void idxDeleteRange(idx_type from, idx_type to);
123         // returns list of cell indices that are "between" from and to for
124         // selection purposes
125         virtual std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
126
127         ///
128         virtual idx_type nargs() const;
129
130         ///
131         virtual MathArray & cell(idx_type);
132         ///
133         virtual MathArray const & cell(idx_type) const;
134         ///
135         virtual MathXArray & xcell(idx_type);
136         ///
137         virtual MathXArray const & xcell(idx_type) const;
138                         
139         ///
140         virtual col_type ncols() const { return 1; }
141         ///
142         virtual row_type nrows() const { return 1; }
143         ///
144         virtual col_type col(row_type) const { return 0; }
145         ///
146         virtual row_type row(row_type) const { return 0; }
147         ///
148         virtual int cellXOffset(row_type) const { return 0; }
149         ///
150         virtual int cellYOffset(row_type) const { return 0; }
151         ///
152         virtual void addRow(row_type) {}
153         ///
154         virtual void delRow(row_type) {}
155         ///
156         virtual void addCol(col_type) {}
157         ///
158         virtual void delCol(col_type) {}
159
160         ///
161         virtual bool covers(int x, int y) const;
162
163         /// identifies NestInsets
164         virtual MathNestInset * asNestInset() { return 0; }
165         /// identifies CharInsets
166         virtual MathCharInset const * asCharInset() const { return 0; }
167         /// identifies ScriptInsets
168         virtual MathScriptInset const * asScriptInset() const { return 0; }
169         /// identifies ScriptInsets
170         virtual MathScriptInset * asScriptInset() { return 0; }
171         /// identifies MatrixInsets
172         virtual MathHullInset const * asMatrixInset() const { return 0; }
173         /// identifies MatrixInsets
174         virtual MathHullInset * asMatrixInset() { return 0; }
175         /// identifies SpaceInset
176         virtual MathSpaceInset * asSpaceInset() { return 0; }
177         /// identifies GridInset
178         virtual MathGridInset * asGridInset() { return 0; }
179         /// identifies ArrayInsets
180         virtual MathArrayInset * asArrayInset() { return 0; }
181         /// identifies BoxInsets
182         virtual MathBoxInset * asBoxInset() { return 0; }
183         /// identifies macro templates
184         virtual MathMacroTemplate * asMacroTemplate() { return 0; }
185         /// identifies hyperactive insets
186         virtual UpdatableInset * asHyperActiveInset() const { return 0; }
187
188         /// identifies things that can get scripts
189         virtual bool isScriptable() const { return false; }
190         ///
191         virtual bool isActive() const { return nargs() > 0; }
192         /// identifies insets from the outer world
193         virtual bool isHyperActive() const { return 0; }
194         ///
195         virtual bool isRelOp() const { return false; }
196         ///
197         virtual bool isMacro() const { return false; }
198         /// is this a matrix or matrix expression?
199         virtual bool isMatrix() const { return false; }
200
201         ///
202         virtual char getChar() const { return 0; }
203         ///
204         virtual MathTextCodes code() const { return LM_TC_MIN; }
205         /// identifies things that can get \limits or \nolimits
206         virtual bool takesLimits() const { return false; }
207
208         ///
209         virtual void dump() const;
210         ///
211         virtual void edit(BufferView *, int, int, unsigned int) {}
212
213         ///
214         virtual void validate(LaTeXFeatures & features) const;
215         ///
216         virtual void handleFont(MathTextCodes) {}
217
218         /// write normalized content
219         virtual void writeNormal(NormalStream &) const;
220         ///
221         virtual void maplize(MapleStream &) const;
222         ///
223         virtual void mathmlize(MathMLStream &) const;
224         ///
225         virtual void octavize(OctaveStream &) const;
226 };
227
228 std::ostream & operator<<(std::ostream &, MathInset const &);
229
230 #endif