]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMath.h
Merge branch 'master' of git.lyx.org:lyx
[lyx.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 #include "TexRow.h"
21
22
23 namespace lyx {
24
25 enum HullType {
26         hullNone,
27         hullSimple,
28         hullEquation,
29         hullEqnArray,
30         hullAlign,
31         hullAlignAt,
32         hullXAlignAt,
33         hullXXAlignAt,
34         hullFlAlign,
35         hullMultline,
36         hullGather,
37         hullRegexp,
38         hullUnknown
39 };
40
41 HullType hullType(docstring const & name);
42 docstring hullName(HullType type);
43
44 /**
45
46 Abstract base class for all math objects.  A math insets is for use of the
47 math editor only, it isn't a general LyX inset. It's used to represent all
48 the math objects.
49
50 Math insets do not know their parents, a cursor position or things
51 like that. They are dumb objects that are contained in other math insets
52 (InsetMathNests, in fact) thus forming a tree. The root of this tree is
53 always a InsetMathHull, which provides an interface to the Outer World by
54 inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
55
56 */
57
58 class OutputParams;
59 class InsetMathArray;
60 class InsetMathAMSArray;
61 class InsetMathBrace;
62 class InsetMathChar;
63 class InsetMathDelim;
64 class InsetMathFracBase;
65 class InsetMathFrac;
66 class InsetMathFont;
67 class InsetMathGrid;
68 class InsetMathHull;
69 class InsetMathMatrix;
70 class InsetMathNest;
71 class InsetMathScript;
72 class InsetMathString;
73 class InsetMathSpace;
74 class InsetMathSpecialChar;
75 class InsetMathSymbol;
76 class InsetMathUnknown;
77
78 class InsetMathRef;
79
80 class HtmlStream;
81 class NormalStream;
82 class OctaveStream;
83 class MapleStream;
84 class MaximaStream;
85 class MathematicaStream;
86 class MathStream;
87 class WriteStream;
88
89 class MathMacroTemplate;
90 class MathMacro;
91 class Cursor;
92 class TextPainter;
93 class TextMetricsInfo;
94 class ReplaceData;
95
96
97 class InsetMath : public Inset {
98 public:
99         ///
100         InsetMath(Buffer * buf = 0) : Inset(buf) {}
101         /// identification as math inset
102         InsetMath * asInsetMath() { return this; }
103         /// identification as math inset
104         InsetMath const * asInsetMath() const { return this; }
105         /// this is overridden in math text insets (i.e. mbox)
106         bool inMathed() const { return true; }
107         ///
108         virtual docstring name() const;
109
110         /// this is overridden by specific insets
111         virtual mode_type currentMode() const { return MATH_MODE; }
112
113         /// the ascent of the inset above the baseline
114         /// compute the size of the object for text based drawing
115         virtual void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
116         /// draw the object as text
117         virtual void drawT(TextPainter &, int x, int y) const;
118
119         /// return cell given its number
120         virtual MathData & cell(idx_type);
121         /// return cell given its number
122         virtual MathData const & cell(idx_type) const;
123
124         /// identifies certain types of insets
125         virtual InsetMathAMSArray       * asAMSArrayInset()       { return 0; }
126         virtual InsetMathAMSArray const * asAMSArrayInset() const { return 0; }
127         virtual InsetMathArray          * asArrayInset()          { return 0; }
128         virtual InsetMathArray const    * asArrayInset() const    { return 0; }
129         virtual InsetMathBrace          * asBraceInset()          { return 0; }
130         virtual InsetMathBrace const    * asBraceInset() const    { return 0; }
131         virtual InsetMathChar const     * asCharInset() const     { return 0; }
132         virtual InsetMathDelim          * asDelimInset()          { return 0; }
133         virtual InsetMathDelim const    * asDelimInset() const    { return 0; }
134         virtual InsetMathFracBase       * asFracBaseInset()       { return 0; }
135         virtual InsetMathFracBase const * asFracBaseInset() const { return 0; }
136         virtual InsetMathFrac           * asFracInset()           { return 0; }
137         virtual InsetMathFrac const     * asFracInset() const     { return 0; }
138         virtual InsetMathFont           * asFontInset()           { return 0; }
139         virtual InsetMathFont const     * asFontInset() const     { return 0; }
140         virtual InsetMathGrid           * asGridInset()           { return 0; }
141         virtual InsetMathGrid const     * asGridInset() const     { return 0; }
142         virtual InsetMathHull           * asHullInset()           { return 0; }
143         virtual InsetMathHull const     * asHullInset() const     { return 0; }
144         virtual MathMacro               * asMacro()               { return 0; }
145         virtual MathMacro const         * asMacro() const         { return 0; }
146         virtual MathMacroTemplate       * asMacroTemplate()       { return 0; }
147         virtual MathMacroTemplate const * asMacroTemplate() const { return 0; }
148         virtual InsetMathMatrix const   * asMatrixInset() const   { return 0; }
149         virtual InsetMathNest           * asNestInset()           { return 0; }
150         virtual InsetMathNest const     * asNestInset() const     { return 0; }
151         virtual InsetMathScript         * asScriptInset()         { return 0; }
152         virtual InsetMathScript const   * asScriptInset() const   { return 0; }
153         virtual InsetMathSpace          * asSpaceInset()          { return 0; }
154         virtual InsetMathSpace const    * asSpaceInset() const    { return 0; }
155         virtual InsetMathString         * asStringInset()         { return 0; }
156         virtual InsetMathString const   * asStringInset() const   { return 0; }
157         virtual InsetMathSymbol const   * asSymbolInset() const   { return 0; }
158         virtual InsetMathUnknown        * asUnknownInset()        { return 0; }
159         virtual InsetMathUnknown const  * asUnknownInset() const  { return 0; }
160         virtual InsetMathRef            * asRefInset()            { return 0; }
161         virtual InsetMathSpecialChar const * asSpecialCharInset() const { return 0; }
162
163         /// identifies things that can get scripts
164         virtual bool isScriptable() const { return false; }
165         /// identifies a binary operators (used for spacing)
166         virtual bool isMathBin() const { return false; }
167         /// identifies relational operators (used for spacing and splitting equations)
168         virtual bool isMathRel() const { return false; }
169         /// identifies punctuation (used for spacing)
170         virtual bool isMathPunct() const { return false; }
171         /// will this get written as a single block in {..}
172         virtual bool extraBraces() const { return false; }
173
174         /// return the content as char if the inset is able to do so
175         virtual char_type getChar() const { return 0; }
176         /// identifies things that can get \limits or \nolimits
177         virtual bool takesLimits() const { return false; }
178
179         /// replace things by other things
180         virtual void replace(ReplaceData &) {}
181         /// do we contain a given subsequence?
182         virtual bool contains(MathData const &) const { return false; }
183         /// access to the lock (only nest array have one)
184         virtual bool lock() const { return false; }
185         /// access to the lock (only nest array have one)
186         virtual void lock(bool) {}
187
188         // Indicate that we do not want to hide the normal version of
189         // write(). This is to shut off a clang warning.
190         using Inset::write;
191         /// write LaTeX and LyX code
192         virtual void write(WriteStream & os) const;
193         /// write normalized content
194         virtual void normalize(NormalStream &) const;
195         /// write content as something readable by Maple
196         virtual void maple(MapleStream &) const;
197         /// write content as something readable by Maxima
198         virtual void maxima(MaximaStream &) const;
199         /// write content as something readable by Mathematica
200         virtual void mathematica(MathematicaStream &) const;
201         /// write content as MathML
202         virtual void mathmlize(MathStream &) const;
203         /// write content as HTML, best we can.
204         /// the idea for this, and some of the details, come from
205         /// eLyXer, written by Alex Fernandez. no code is borrowed. rather,
206         /// we try to mimic how eLyXer outputs some math.
207         virtual void htmlize(HtmlStream &) const;
208         /// write content as something readable by Octave
209         virtual void octave(OctaveStream &) const;
210
211         /// plain text output in ucs4 encoding
212         int plaintext(odocstringstream &, OutputParams const &, size_t) const;
213
214         /// dump content to stderr for debugging
215         virtual void dump() const;
216
217         /// LyXInset stuff
218         virtual bool numberedType() const { return false; }
219         /// hull type
220         virtual HullType getType() const;
221         /// change type
222         virtual void mutate(HullType /*newtype*/) {}
223
224         /// math stuff usually isn't allowed in text mode
225         virtual bool allowedIn(mode_type mode) const { return mode == MATH_MODE; }
226
227         /// superscript kerning
228         virtual int kerning(BufferView const *) const { return 0; }
229         ///
230         bool isInToc() const { return true; }
231         ///
232         InsetCode lyxCode() const { return MATH_CODE; }
233         ///
234         uid_type id() const { return this; }
235 };
236
237 ///
238 std::ostream & operator<<(std::ostream &, MathAtom const &);
239 ///
240 odocstream & operator<<(odocstream &, MathAtom const &);
241
242 // initialize math
243 void initMath();
244
245
246 } // namespace lyx
247
248 #endif