]> git.lyx.org Git - lyx.git/blob - src/mathed/math_inset.h
oh well
[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 /**
35
36 Abstract base class for all math objects.  A math insets is for use of the
37 math editor only, it isn't a general LyX inset. It's used to represent all
38 the math objects.
39
40 Math insets do not know there parents, a cursor position or things
41 like that. The are dumb object that are contained in other math insets
42 (mathNestInsets, in fact) thus forming a tree. The root of this tree is
43 always a mathHullInset, which provides an interface to the Outer World by
44 inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
45
46 */
47
48
49 class MathArrayInset;
50 class MathAMSArrayInset;
51 class MathBraceInset;
52 class MathBoxInset;
53 class MathCharInset;
54 class MathDelimInset;
55 class MathFuncInset;
56 class MathGridInset;
57 class MathFracInset;
58 class MathHullInset;
59 class MathMatrixInset;
60 class MathNestInset;
61 class MathScriptInset;
62 class MathStringInset;
63 class MathSpaceInset;
64 class MathSymbolInset;
65 class MathUnknownInset;
66 class MathXYMatrixInset;
67
68 class NormalStream;
69 class OctaveStream;
70 class MapleStream;
71 class MathMLStream;
72 class WriteStream;
73 class InfoStream;
74 class MathArray;
75
76 class LaTeXFeatures;
77 class BufferView;
78 class UpdatableInset;
79 class MathMacroTemplate;
80 class MathPosFinder;
81
82
83 class MathInset {
84 public:
85         /// short of anything else reasonable
86         typedef MathArray::size_type        size_type;
87         /// type for cursor positions differences within a cell
88         typedef MathArray::difference_type  difference_type;
89         /// type for cursor positions within a cell
90         typedef MathArray::size_type        pos_type;
91         /// type for cell indices
92         typedef size_type                   idx_type;
93         /// type for row numbers
94         typedef size_type                   row_type;
95         /// type for column numbers
96         typedef size_type                   col_type;
97
98         /// our members behave nicely...
99         MathInset() {}
100         /// the virtual base destructor
101         virtual ~MathInset() {}
102
103         /// reproduce itself
104         virtual MathInset * clone() const = 0;
105         /// substitutes macro arguments if necessary
106         virtual void substitute(MathMacro const & macro);
107         /// compute the size of the object, sets ascend_, descend_ and width_
108         // updates the (xo,yo)-caches of all contained cells
109         virtual void metrics(MathMetricsInfo const & st) const;
110         /// draw the object
111         virtual void draw(Painter &, int x, int y) const;
112         /// the ascent of the inset above the baseline
113         /// compute the size of the object for text based drawing
114         virtual void metricsT(TextMetricsInfo const & st) const;
115         /// draw the object as text
116         virtual void drawT(TextPainter &, int x, int y) const;
117         /// the ascent of the inset above the baseline
118         virtual int ascent() const { return 1; }
119         /// the descent of the inset below the baseline
120         virtual int descent() const { return 1; }
121         /// total width
122         virtual int width() const { return 2; }
123         /// total height (== ascent + descent)
124         virtual int height() const;
125
126         /// Where should we go when we press the up or down cursor key?
127         virtual bool idxUpDown(idx_type & idx, bool up) const;
128         /// The left key
129         virtual bool idxLeft(idx_type & idx, pos_type & pos) const;
130         /// The right key
131         virtual bool idxRight(idx_type & idx, pos_type & pos) const;
132
133         /// Move one physical cell up
134         virtual bool idxNext(idx_type & idx, pos_type & pos) const;
135         /// Move one physical cell down
136         virtual bool idxPrev(idx_type & idx, pos_type & pos) const;
137
138         /// Target pos when we enter the inset from the left by pressing "Right"
139         virtual bool idxFirst(idx_type & idx, pos_type & pos) const;
140         /// Target pos when we enter the inset from the right by pressing "Left"
141         virtual bool idxLast(idx_type & idx, pos_type & pos) const;
142
143         /// Where should we go if we press home?
144         virtual bool idxHome(idx_type & idx, pos_type & pos) const;
145         /// Where should we go if we press end?
146         virtual bool idxEnd(idx_type & idx, pos_type & pos) const;
147
148         /// Delete a cell and move cursor
149         virtual bool idxDelete(idx_type &) { return false; }
150         /// pulls cell after pressing erase
151         virtual void idxGlue(idx_type) {}
152         // returns list of cell indices that are "between" from and to for
153         // selection purposes
154         virtual std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
155
156         /// the number of nested cells this inset owns
157         virtual idx_type nargs() const;
158
159         /// return cell given its number
160         virtual MathArray & cell(idx_type);
161         /// return cell given its number
162         virtual MathArray const & cell(idx_type) const;
163         /// return cell plus drawing cache given its number
164         virtual MathXArray & xcell(idx_type);
165         /// return cell plus drawing cache given its number
166         virtual MathXArray const & xcell(idx_type) const;
167
168         /// the number of columns of this inset if it is grid-like
169         virtual col_type ncols() const { return 1; }
170         /// the number of rows of this inset if it is grid-like
171         virtual row_type nrows() const { return 1; }
172         /// to which column belongs a cell with a given index?
173         virtual col_type col(idx_type) const { return 0; }
174         /// to which row belongs a cell with a given index?
175         virtual row_type row(idx_type) const { return 0; }
176         /// cell idex corresponding to row and column;
177         virtual idx_type index(row_type row, col_type col) const;
178         /// any additional x-offset when drawing a cell?
179         virtual int cellXOffset(idx_type) const { return 0; }
180         /// any additional y-offset when drawing a cell?
181         virtual int cellYOffset(idx_type) const { return 0; }
182         /// can we enter this cell?
183         virtual bool validCell(idx_type) const { return true; }
184
185         /// identifies certain types of insets
186         virtual MathAMSArrayInset      * asAMSArrayInset()      { return 0; }
187         virtual MathArrayInset         * asArrayInset()         { return 0; }
188         virtual MathBraceInset         * asBraceInset()         { return 0; }
189         virtual MathBoxInset           * asBoxInset()           { return 0; }
190         virtual MathBoxInset const     * asBoxInset() const     { return 0; }
191         virtual MathCharInset const    * asCharInset() const    { return 0; }
192         virtual MathDelimInset         * asDelimInset()         { return 0; }
193         virtual MathDelimInset const   * asDelimInset() const   { return 0; }
194         virtual MathFuncInset          * asFuncInset()          { return 0; }
195         virtual MathFracInset          * asFracInset()          { return 0; }
196         virtual MathGridInset          * asGridInset()          { return 0; }
197         virtual MathHullInset          * asHullInset()          { return 0; }
198         virtual MathHullInset const    * asHullInset() const    { return 0; }
199         virtual MathMacroTemplate      * asMacroTemplate()      { return 0; }
200         virtual MathMatrixInset const  * asMatrixInset() const  { return 0; }
201         virtual MathNestInset          * asNestInset()          { return 0; }
202         virtual MathScriptInset        * asScriptInset()        { return 0; }
203         virtual MathScriptInset const  * asScriptInset() const  { return 0; }
204         virtual MathSpaceInset         * asSpaceInset()         { return 0; }
205         virtual MathStringInset        * asStringInset()        { return 0; }
206         virtual MathSymbolInset const  * asSymbolInset() const  { return 0; }
207         virtual MathUnknownInset const * asUnknownInset() const { return 0; }
208         virtual MathXYMatrixInset const* asXYMatrixInset() const{ return 0; }
209
210         /// identifies things that can get scripts
211         virtual bool isScriptable() const { return false; }
212         /// thing that can be moved into
213         virtual bool isActive() const { return nargs() > 0; }
214         /// is the a relational operator (used for splitting equations)
215         virtual bool isRelOp() const { return false; }
216
217         /// return the content as char if the inset is able to do so
218         virtual char getChar() const { return 0; }
219         /// return the content's char code if it has one
220         virtual MathTextCodes code() const { return LM_TC_MIN; }
221         /// identifies things that can get \limits or \nolimits
222         virtual bool takesLimits() const { return false; }
223         /// identifies complicated things that need braces if used as arg
224         virtual bool needsBraces() const { return true; }
225
226         ///
227         virtual void edit(BufferView *, int, int, unsigned int) {}
228
229         /// request "external features"
230         virtual void validate(LaTeXFeatures & features) const;
231         /// char char code if possible
232         virtual void handleFont(MathTextCodes) {}
233         /// is this inset equal to a given other inset?
234         virtual bool match(MathInset *) const { return false; }
235         /// replace things by other things
236         virtual void replace(ReplaceData &) {}
237         /// do we contain a given subsequence?
238         virtual bool contains(MathArray const &) { return false; }
239
240         /// write LaTeX and Lyx code
241         virtual void write(WriteStream & os) const;
242         /// write normalized content
243         virtual void normalize(NormalStream &) const;
244         /// write content as something readable by Maple
245         virtual void maplize(MapleStream &) const;
246         /// write content as something resembling MathML
247         virtual void mathmlize(MathMLStream &) const;
248         /// write content as something readable by Octave
249         virtual void octavize(OctaveStream &) const;
250         /// describe content
251         virtual void infoize(std::ostream &) const {}
252
253         /// dump content to stderr for debugging
254         virtual void dump() const;
255 };
256
257 std::ostream & operator<<(std::ostream &, MathInset const &);
258
259 #endif