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