]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMath.h
Merge remote-tracking branch 'features/properpaint' into 2.3.2-staging
[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 InsetMathMacroTemplate;
91 class InsetMathMacro;
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 possible marker types for math insets
118         enum marker_type { NO_MARKER, MARKER2, MARKER, BOX_MARKER };
119         /// this is overridden by insets with specific edit marker type
120         virtual marker_type marker(BufferView const *) const;
121
122         /// the ascent of the inset above the baseline
123         /// compute the size of the object for text based drawing
124         virtual void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
125         /// draw the object as text
126         virtual void drawT(TextPainter &, int x, int y) const;
127
128         /// return cell given its number
129         virtual MathData & cell(idx_type);
130         /// return cell given its number
131         virtual MathData const & cell(idx_type) const;
132
133         /// identifies certain types of insets
134         virtual InsetMathAMSArray       * asAMSArrayInset()       { return 0; }
135         virtual InsetMathAMSArray const * asAMSArrayInset() const { return 0; }
136         virtual InsetMathArray          * asArrayInset()          { return 0; }
137         virtual InsetMathArray const    * asArrayInset() const    { return 0; }
138         virtual InsetMathBrace          * asBraceInset()          { return 0; }
139         virtual InsetMathBrace const    * asBraceInset() const    { return 0; }
140         virtual InsetMathChar const     * asCharInset() const     { return 0; }
141         virtual InsetMathDelim          * asDelimInset()          { return 0; }
142         virtual InsetMathDelim const    * asDelimInset() const    { return 0; }
143         virtual InsetMathFracBase       * asFracBaseInset()       { return 0; }
144         virtual InsetMathFracBase const * asFracBaseInset() const { return 0; }
145         virtual InsetMathFrac           * asFracInset()           { return 0; }
146         virtual InsetMathFrac const     * asFracInset() const     { return 0; }
147         virtual InsetMathFont           * asFontInset()           { return 0; }
148         virtual InsetMathFont const     * asFontInset() const     { return 0; }
149         virtual InsetMathGrid           * asGridInset()           { return 0; }
150         virtual InsetMathGrid const     * asGridInset() const     { return 0; }
151         virtual InsetMathHull           * asHullInset()           { return 0; }
152         virtual InsetMathHull const     * asHullInset() const     { return 0; }
153         virtual InsetMathMacro               * asMacro()               { return 0; }
154         virtual InsetMathMacro const         * asMacro() const         { return 0; }
155         virtual InsetMathMacroTemplate       * asMacroTemplate()       { return 0; }
156         virtual InsetMathMacroTemplate const * asMacroTemplate() const { return 0; }
157         virtual InsetMathMatrix const   * asMatrixInset() const   { return 0; }
158         virtual InsetMathNest           * asNestInset()           { return 0; }
159         virtual InsetMathNest const     * asNestInset() const     { return 0; }
160         virtual InsetMathScript         * asScriptInset()         { return 0; }
161         virtual InsetMathScript const   * asScriptInset() const   { return 0; }
162         virtual InsetMathSpace          * asSpaceInset()          { return 0; }
163         virtual InsetMathSpace const    * asSpaceInset() const    { return 0; }
164         virtual InsetMathString         * asStringInset()         { return 0; }
165         virtual InsetMathString const   * asStringInset() const   { return 0; }
166         virtual InsetMathSymbol const   * asSymbolInset() const   { return 0; }
167         virtual InsetMathUnknown        * asUnknownInset()        { return 0; }
168         virtual InsetMathUnknown const  * asUnknownInset() const  { return 0; }
169         virtual InsetMathRef            * asRefInset()            { return 0; }
170         virtual InsetMathSpecialChar const * asSpecialCharInset() const { return 0; }
171
172         /// The class of the math object (used primarily for spacing)
173         virtual MathClass mathClass() const;
174         /// Add this inset to a math row. Return true if contents got added
175         virtual bool addToMathRow(MathRow &, MetricsInfo & mi) const;
176         /// Hook that is run before metrics computation starts
177         virtual void beforeMetrics() const {}
178         /// Hook that is run after metrics computation
179         virtual void afterMetrics() const {}
180         /// Hook that is run before actual drawing
181         virtual void beforeDraw(PainterInfo const &) const {}
182         /// Hook that is run after drawing
183         virtual void afterDraw(PainterInfo const &) const {}
184
185         /// identifies things that can get scripts
186         virtual bool isScriptable() const { return false; }
187         /// will this get written as a single block in {..}
188         virtual bool extraBraces() const { return false; }
189
190         /// return the content as char if the inset is able to do so
191         virtual char_type getChar() const { return 0; }
192         /// identifies things that can get \limits or \nolimits
193         virtual bool takesLimits() const { return false; }
194
195         /// replace things by other things
196         virtual void replace(ReplaceData &) {}
197         /// do we contain a given subsequence?
198         virtual bool contains(MathData const &) const { return false; }
199         /// access to the lock (only nest array have one)
200         virtual bool lock() const { return false; }
201         /// access to the lock (only nest array have one)
202         virtual void lock(bool) {}
203
204         // Indicate that we do not want to hide the normal version of
205         // write(). This is to shut off a clang warning.
206         using Inset::write;
207         /// write LaTeX and LyX code
208         virtual void write(WriteStream & os) const;
209         /// write normalized content
210         virtual void normalize(NormalStream &) const;
211         /// write content as something readable by Maple
212         virtual void maple(MapleStream &) const;
213         /// write content as something readable by Maxima
214         virtual void maxima(MaximaStream &) const;
215         /// write content as something readable by Mathematica
216         virtual void mathematica(MathematicaStream &) const;
217         /// write content as MathML
218         virtual void mathmlize(MathStream &) const;
219         /// write content as HTML, best we can.
220         /// the idea for this, and some of the details, come from
221         /// eLyXer, written by Alex Fernandez. no code is borrowed. rather,
222         /// we try to mimic how eLyXer outputs some math.
223         virtual void htmlize(HtmlStream &) const;
224         /// write content as something readable by Octave
225         virtual void octave(OctaveStream &) const;
226
227         /// plain text output in ucs4 encoding
228         int plaintext(odocstringstream &, OutputParams const &, size_t) const;
229
230         /// dump content to stderr for debugging
231         virtual void dump() const;
232
233         /// LyXInset stuff
234         virtual bool numberedType() const { return false; }
235         /// hull type
236         virtual HullType getType() const;
237         /// change type
238         virtual void mutate(HullType /*newtype*/) {}
239
240         /// math stuff usually isn't allowed in text mode
241         virtual bool allowedIn(mode_type mode) const { return mode == MATH_MODE; }
242
243         /// Italic correction as described in InsetMathScript.h
244         virtual int kerning(BufferView const *) const { return 0; }
245         ///
246         bool isInToc() const { return true; }
247         ///
248         InsetCode lyxCode() const { return MATH_CODE; }
249         ///
250         uid_type id() const { return this; }
251 };
252
253 ///
254 std::ostream & operator<<(std::ostream &, MathAtom const &);
255 ///
256 odocstream & operator<<(odocstream &, MathAtom const &);
257
258 // initialize math
259 void initMath();
260
261
262 } // namespace lyx
263
264 #endif