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