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