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