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