]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMath.h
Coding style
[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 };
36
37 HullType hullType(docstring const & name);
38 docstring hullName(HullType type);
39
40 /**
41
42 Abstract base class for all math objects.  A math insets is for use of the
43 math editor only, it isn't a general LyX inset. It's used to represent all
44 the math objects.
45
46 Math insets do not know there parents, a cursor position or things
47 like that. The are dumb object that are contained in other math insets
48 (InsetMathNests, in fact) thus forming a tree. The root of this tree is
49 always a InsetMathHull, which provides an interface to the Outer World by
50 inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
51
52 */
53
54 class OutputParams;
55 class InsetMathArray;
56 class InsetMathAMSArray;
57 class InsetMathBrace;
58 class InsetMathChar;
59 class InsetMathDelim;
60 class InsetMathFrac;
61 class InsetMathFont;
62 class InsetMathGrid;
63 class InsetMathHull;
64 class InsetMathMatrix;
65 class InsetMathNest;
66 class InsetMathScript;
67 class InsetMathString;
68 class InsetMathSpace;
69 class InsetMathSymbol;
70 class InsetMathUnknown;
71
72 class InsetMathRef;
73
74 class NormalStream;
75 class OctaveStream;
76 class MapleStream;
77 class MaximaStream;
78 class MathematicaStream;
79 class MathStream;
80 class WriteStream;
81 class InfoStream;
82
83 class MathMacroTemplate;
84 class MathMacro;
85 class MathPosFinder;
86 class Cursor;
87 class TextPainter;
88 class TextMetricsInfo;
89 class ReplaceData;
90
91
92 class InsetMath : public Inset {
93 public:
94         /// identification as math inset
95         InsetMath * asInsetMath() { return this; }
96         /// this is overridden in math text insets (i.e. mbox)
97         bool inMathed() const { return true; }
98
99         /// the ascent of the inset above the baseline
100         /// compute the size of the object for text based drawing
101         virtual void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
102         /// draw the object as text
103         virtual void drawT(TextPainter &, int x, int y) const;
104
105         /// return cell given its number
106         virtual MathData & cell(idx_type);
107         /// return cell given its number
108         virtual MathData const & cell(idx_type) const;
109
110         /// identifies certain types of insets
111         virtual InsetMathAMSArray       * asAMSArrayInset()       { return 0; }
112         virtual InsetMathAMSArray const * asAMSArrayInset() const { return 0; }
113         virtual InsetMathArray          * asArrayInset()          { return 0; }
114         virtual InsetMathArray const    * asArrayInset() const    { return 0; }
115         virtual InsetMathBrace          * asBraceInset()          { return 0; }
116         virtual InsetMathBrace const    * asBraceInset() const    { return 0; }
117         virtual InsetMathChar const     * asCharInset() const     { return 0; }
118         virtual InsetMathDelim          * asDelimInset()          { return 0; }
119         virtual InsetMathDelim const    * asDelimInset() const    { return 0; }
120         virtual InsetMathFrac           * asFracInset()           { return 0; }
121         virtual InsetMathFrac const     * asFracInset() const     { return 0; }
122         virtual InsetMathFont           * asFontInset()           { return 0; }
123         virtual InsetMathFont const     * asFontInset() const     { return 0; }
124         virtual InsetMathGrid           * asGridInset()           { return 0; }
125         virtual InsetMathGrid const     * asGridInset() const     { return 0; }
126         virtual InsetMathHull           * asHullInset()           { return 0; }
127         virtual InsetMathHull const     * asHullInset() const     { return 0; }
128         virtual MathMacro               * asMacro()               { return 0; }
129         virtual MathMacro const         * asMacro() const         { return 0; }
130         virtual MathMacroTemplate       * asMacroTemplate()       { return 0; }
131         virtual MathMacroTemplate const * asMacroTemplate() const { return 0; }
132         virtual InsetMathMatrix const   * asMatrixInset() const   { return 0; }
133         virtual InsetMathNest           * asNestInset()           { return 0; }
134         virtual InsetMathNest const     * asNestInset() const     { return 0; }
135         virtual InsetMathScript         * asScriptInset()         { return 0; }
136         virtual InsetMathScript const   * asScriptInset() const   { return 0; }
137         virtual InsetMathSpace          * asSpaceInset()          { return 0; }
138         virtual InsetMathSpace const    * asSpaceInset() const    { return 0; }
139         virtual InsetMathString         * asStringInset()         { return 0; }
140         virtual InsetMathString const   * asStringInset() const   { return 0; }
141         virtual InsetMathSymbol const   * asSymbolInset() const   { return 0; }
142         virtual InsetMathUnknown        * asUnknownInset()        { return 0; }
143         virtual InsetMathUnknown const  * asUnknownInset() const  { return 0; }
144         virtual InsetMathRef            * asRefInset()            { return 0; }
145
146         /// identifies things that can get scripts
147         virtual bool isScriptable() const { return false; }
148         /// is the a relational operator (used for splitting equations)
149         virtual bool isRelOp() const { return false; }
150         /// will this get written as a single block in {..}
151         virtual bool extraBraces() const { return false; }
152
153         /// return the content as char if the inset is able to do so
154         virtual char_type getChar() const { return 0; }
155         /// identifies things that can get \limits or \nolimits
156         virtual bool takesLimits() const { return false; }
157
158         /// char char code if possible
159         virtual void handleFont(docstring const &) {}
160         /// replace things by other things
161         virtual void replace(ReplaceData &) {}
162         /// do we contain a given subsequence?
163         virtual bool contains(MathData const &) const { return false; }
164         /// access to the lock (only nest array have one)
165         virtual bool lock() const { return false; }
166         /// access to the lock (only nest array have one)
167         virtual void lock(bool) {}
168
169         /// write LaTeX and Lyx code
170         virtual void write(WriteStream & os) const;
171         /// write normalized content
172         virtual void normalize(NormalStream &) const;
173         /// write content as something readable by Maple
174         virtual void maple(MapleStream &) const;
175         /// write content as something readable by Maxima
176         virtual void maxima(MaximaStream &) const;
177         /// write content as something readable by Mathematica
178         virtual void mathematica(MathematicaStream &) const;
179         /// write content as something resembling MathML
180         virtual void mathmlize(MathStream &) const;
181         /// write content as something readable by Octave
182         virtual void octave(OctaveStream &) const;
183
184         /// plain text output in ucs4 encoding
185         int plaintext(odocstream &, OutputParams const &) const;
186
187         /// dump content to stderr for debugging
188         virtual void dump() const;
189
190         /// LyXInset stuff
191         virtual bool numberedType() const { return false; }
192         /// hull type
193         virtual HullType getType() const;
194         /// change type
195         virtual void mutate(HullType /*newtype*/) {}
196
197         /// math stuff usually isn't allowed in text mode
198         virtual bool allowedIn(mode_type mode) const { return mode == MATH_MODE; }
199
200         /// superscript kerning
201         virtual int kerning(BufferView const *) const { return 0; }
202 };
203
204 ///
205 std::ostream & operator<<(std::ostream &, MathAtom const &);
206 ///
207 odocstream & operator<<(odocstream &, MathAtom const &);
208
209 // initialize math
210 void initMath();
211
212
213 } // namespace lyx
214
215 #endif