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