]> git.lyx.org Git - features.git/blob - src/mathed/InsetMath.h
Better fix for #6049 and similar cases with other math insets.
[features.git] / src / mathed / InsetMath.h
1 // -*- C++ -*-
2 /**
3  * \file InsetMath.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Alejandro Aguilar Sierra
8  * \author André Pönitz
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef MATH_INSET_H
14 #define MATH_INSET_H
15
16 #include "MathData.h"
17
18 #include "insets/Inset.h"
19
20
21 namespace lyx {
22
23 enum HullType {
24         hullNone,
25         hullSimple,
26         hullEquation,
27         hullEqnArray,
28         hullAlign,
29         hullAlignAt,
30         hullXAlignAt,
31         hullXXAlignAt,
32         hullFlAlign,
33         hullMultline,
34         hullGather,
35         hullRegexp
36 };
37
38 HullType hullType(docstring const & name);
39 docstring hullName(HullType type);
40
41 /**
42
43 Abstract base class for all math objects.  A math insets is for use of the
44 math editor only, it isn't a general LyX inset. It's used to represent all
45 the math objects.
46
47 Math insets do not know there parents, a cursor position or things
48 like that. The are dumb object that are contained in other math insets
49 (InsetMathNests, in fact) thus forming a tree. The root of this tree is
50 always a InsetMathHull, which provides an interface to the Outer World by
51 inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
52
53 */
54
55 class OutputParams;
56 class InsetMathArray;
57 class InsetMathAMSArray;
58 class InsetMathBrace;
59 class InsetMathChar;
60 class InsetMathDelim;
61 class InsetMathFrac;
62 class InsetMathFont;
63 class InsetMathGrid;
64 class InsetMathHull;
65 class InsetMathMatrix;
66 class InsetMathNest;
67 class InsetMathScript;
68 class InsetMathString;
69 class InsetMathSpace;
70 class InsetMathSpecialChar;
71 class InsetMathSymbol;
72 class InsetMathUnknown;
73
74 class InsetMathRef;
75
76 class NormalStream;
77 class OctaveStream;
78 class MapleStream;
79 class MaximaStream;
80 class MathematicaStream;
81 class MathStream;
82 class WriteStream;
83 class InfoStream;
84
85 class MathMacroTemplate;
86 class MathMacro;
87 class MathPosFinder;
88 class Cursor;
89 class TextPainter;
90 class TextMetricsInfo;
91 class ReplaceData;
92
93
94 class InsetMath : public Inset {
95 public:
96         /// identification as math inset
97         InsetMath * asInsetMath() { return this; }
98         /// this is overridden in math text insets (i.e. mbox)
99         bool inMathed() const { return true; }
100
101         /// this is overridden by specific insets
102         virtual mode_type currentMode() const { return MATH_MODE; }
103
104         /// the ascent of the inset above the baseline
105         /// compute the size of the object for text based drawing
106         virtual void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
107         /// draw the object as text
108         virtual void drawT(TextPainter &, int x, int y) const;
109
110         /// return cell given its number
111         virtual MathData & cell(idx_type);
112         /// return cell given its number
113         virtual MathData const & cell(idx_type) const;
114
115         /// identifies certain types of insets
116         virtual InsetMathAMSArray       * asAMSArrayInset()       { return 0; }
117         virtual InsetMathAMSArray const * asAMSArrayInset() const { return 0; }
118         virtual InsetMathArray          * asArrayInset()          { return 0; }
119         virtual InsetMathArray const    * asArrayInset() const    { return 0; }
120         virtual InsetMathBrace          * asBraceInset()          { return 0; }
121         virtual InsetMathBrace const    * asBraceInset() const    { return 0; }
122         virtual InsetMathChar const     * asCharInset() const     { return 0; }
123         virtual InsetMathDelim          * asDelimInset()          { return 0; }
124         virtual InsetMathDelim const    * asDelimInset() const    { return 0; }
125         virtual InsetMathFrac           * asFracInset()           { return 0; }
126         virtual InsetMathFrac const     * asFracInset() const     { return 0; }
127         virtual InsetMathFont           * asFontInset()           { return 0; }
128         virtual InsetMathFont const     * asFontInset() const     { return 0; }
129         virtual InsetMathGrid           * asGridInset()           { return 0; }
130         virtual InsetMathGrid const     * asGridInset() const     { return 0; }
131         virtual InsetMathHull           * asHullInset()           { return 0; }
132         virtual InsetMathHull const     * asHullInset() const     { return 0; }
133         virtual MathMacro               * asMacro()               { return 0; }
134         virtual MathMacro const         * asMacro() const         { return 0; }
135         virtual MathMacroTemplate       * asMacroTemplate()       { return 0; }
136         virtual MathMacroTemplate const * asMacroTemplate() const { return 0; }
137         virtual InsetMathMatrix const   * asMatrixInset() const   { return 0; }
138         virtual InsetMathNest           * asNestInset()           { return 0; }
139         virtual InsetMathNest const     * asNestInset() const     { return 0; }
140         virtual InsetMathScript         * asScriptInset()         { return 0; }
141         virtual InsetMathScript const   * asScriptInset() const   { return 0; }
142         virtual InsetMathSpace          * asSpaceInset()          { return 0; }
143         virtual InsetMathSpace const    * asSpaceInset() const    { return 0; }
144         virtual InsetMathString         * asStringInset()         { return 0; }
145         virtual InsetMathString const   * asStringInset() const   { return 0; }
146         virtual InsetMathSymbol const   * asSymbolInset() const   { return 0; }
147         virtual InsetMathUnknown        * asUnknownInset()        { return 0; }
148         virtual InsetMathUnknown const  * asUnknownInset() const  { return 0; }
149         virtual InsetMathRef            * asRefInset()            { return 0; }
150         virtual InsetMathSpecialChar const * asSpecialCharInset() const { return 0; }
151
152         /// identifies things that can get scripts
153         virtual bool isScriptable() const { return false; }
154         /// is the a relational operator (used for splitting equations)
155         virtual bool isRelOp() const { return false; }
156         /// will this get written as a single block in {..}
157         virtual bool extraBraces() const { return false; }
158
159         /// return the content as char if the inset is able to do so
160         virtual char_type getChar() const { return 0; }
161         /// identifies things that can get \limits or \nolimits
162         virtual bool takesLimits() const { return false; }
163
164         /// char char code if possible
165         virtual void handleFont(docstring const &) {}
166         /// replace things by other things
167         virtual void replace(ReplaceData &) {}
168         /// do we contain a given subsequence?
169         virtual bool contains(MathData const &) const { return false; }
170         /// access to the lock (only nest array have one)
171         virtual bool lock() const { return false; }
172         /// access to the lock (only nest array have one)
173         virtual void lock(bool) {}
174
175         /// write LaTeX and Lyx code
176         virtual void write(WriteStream & os) const;
177         /// write normalized content
178         virtual void normalize(NormalStream &) const;
179         /// write content as something readable by Maple
180         virtual void maple(MapleStream &) const;
181         /// write content as something readable by Maxima
182         virtual void maxima(MaximaStream &) const;
183         /// write content as something readable by Mathematica
184         virtual void mathematica(MathematicaStream &) const;
185         /// write content as something resembling MathML
186         virtual void mathmlize(MathStream &) const;
187         /// write content as something readable by Octave
188         virtual void octave(OctaveStream &) const;
189
190         /// plain text output in ucs4 encoding
191         int plaintext(odocstream &, OutputParams const &) const;
192
193         /// dump content to stderr for debugging
194         virtual void dump() const;
195
196         /// LyXInset stuff
197         virtual bool numberedType() const { return false; }
198         /// hull type
199         virtual HullType getType() const;
200         /// change type
201         virtual void mutate(HullType /*newtype*/) {}
202
203         /// math stuff usually isn't allowed in text mode
204         virtual bool allowedIn(mode_type mode) const { return mode == MATH_MODE; }
205
206         /// superscript kerning
207         virtual int kerning(BufferView const *) const { return 0; }
208 };
209
210 ///
211 std::ostream & operator<<(std::ostream &, MathAtom const &);
212 ///
213 odocstream & operator<<(odocstream &, MathAtom const &);
214
215 // initialize math
216 void initMath();
217
218
219 } // namespace lyx
220
221 #endif