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