]> git.lyx.org Git - lyx.git/blob - src/mathed/math_inset.h
some (yet unfinished) up/down work
[lyx.git] / src / mathed / math_inset.h
1 // -*- C++ -*-
2 /**
3  * \file math_inset.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 "math_data.h"
17
18 #include "insets/insetbase.h"
19
20 #include <string>
21
22 /**
23
24 Abstract base class for all math objects.  A math insets is for use of the
25 math editor only, it isn't a general LyX inset. It's used to represent all
26 the math objects.
27
28 Math insets do not know there parents, a cursor position or things
29 like that. The are dumb object that are contained in other math insets
30 (MathNestInsets, in fact) thus forming a tree. The root of this tree is
31 always a MathHullInset, which provides an interface to the Outer World by
32 inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
33
34 */
35
36 class OutputParams;
37 class MathArrayInset;
38 class MathAMSArrayInset;
39 class MathBraceInset;
40 class MathCharInset;
41 class MathDelimInset;
42 class MathFracInset;
43 class MathFontInset;
44 class MathGridInset;
45 class MathHullInset;
46 class MathMatrixInset;
47 class MathNestInset;
48 class MathParboxInset;
49 class MathScriptInset;
50 class MathStringInset;
51 class MathSpaceInset;
52 class MathSymbolInset;
53 class MathUnknownInset;
54
55 class RefInset;
56
57 class NormalStream;
58 class OctaveStream;
59 class MapleStream;
60 class MaximaStream;
61 class MathematicaStream;
62 class MathMLStream;
63 class WriteStream;
64 class InfoStream;
65
66 class MathMacroTemplate;
67 class MathMacro;
68 class MathPosFinder;
69 class Dimension;
70 class LCursor;
71 class TextPainter;
72 class TextMetricsInfo;
73 class ReplaceData;
74
75
76 class MathInset : public InsetBase {
77 public:
78         /// identification as math inset
79         MathInset * asMathInset() { return this; }
80         /// this is overridden in math text insets (i.e. mbox)
81         bool inMathed() const { return true; }
82
83         /// the ascent of the inset above the baseline
84         /// compute the size of the object for text based drawing
85         virtual void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
86         /// draw the object as text
87         virtual void drawT(TextPainter &, int x, int y) const;
88
89         /// return cell given its number
90         virtual MathArray & cell(idx_type);
91         /// return cell given its number
92         virtual MathArray const & cell(idx_type) const;
93
94         /// identifies certain types of insets
95         virtual MathAMSArrayInset       * asAMSArrayInset()       { return 0; }
96         virtual MathAMSArrayInset const * asAMSArrayInset() const { return 0; }
97         virtual MathArrayInset          * asArrayInset()          { return 0; }
98         virtual MathArrayInset const    * asArrayInset() const    { return 0; }
99         virtual MathBraceInset const    * asBraceInset() const    { return 0; }
100         virtual MathCharInset const     * asCharInset() const     { return 0; }
101         virtual MathDelimInset          * asDelimInset()          { return 0; }
102         virtual MathDelimInset const    * asDelimInset() const    { return 0; }
103         virtual MathFracInset           * asFracInset()           { return 0; }
104         virtual MathFracInset const     * asFracInset() const     { return 0; }
105         virtual MathFontInset           * asFontInset()           { return 0; }
106         virtual MathFontInset const     * asFontInset() const     { return 0; }
107         virtual MathGridInset           * asGridInset()           { return 0; }
108         virtual MathGridInset const     * asGridInset() const     { return 0; }
109         virtual MathHullInset           * asHullInset()           { return 0; }
110         virtual MathHullInset const     * asHullInset() const     { return 0; }
111         virtual MathMacro               * asMacro()               { return 0; }
112         virtual MathMacro const         * asMacro() const         { return 0; }
113         virtual MathMacroTemplate       * asMacroTemplate()       { return 0; }
114         virtual MathMacroTemplate const * asMacroTemplate() const { return 0; }
115         virtual MathMatrixInset const   * asMatrixInset() const   { return 0; }
116         virtual MathNestInset           * asNestInset()           { return 0; }
117         virtual MathNestInset const     * asNestInset() const     { return 0; }
118         virtual MathParboxInset         * asParboxInset()         { return 0; }
119         virtual MathScriptInset         * asScriptInset()         { return 0; }
120         virtual MathScriptInset const   * asScriptInset() const   { return 0; }
121         virtual MathSpaceInset          * asSpaceInset()          { return 0; }
122         virtual MathSpaceInset const    * asSpaceInset() const    { return 0; }
123         virtual MathStringInset         * asStringInset()         { return 0; }
124         virtual MathStringInset const   * asStringInset() const   { return 0; }
125         virtual MathSymbolInset const   * asSymbolInset() const   { return 0; }
126         virtual MathUnknownInset        * asUnknownInset()        { return 0; }
127         virtual MathUnknownInset const  * asUnknownInset() const  { return 0; }
128         virtual RefInset                * asRefInset()            { return 0; }
129
130         /// identifies things that can get scripts
131         virtual bool isScriptable() const { return false; }
132         /// is the a relational operator (used for splitting equations)
133         virtual bool isRelOp() const { return false; }
134         /// will this get written as a single block in {..}
135         virtual bool extraBraces() const { return false; }
136
137         /// return the content as char if the inset is able to do so
138         virtual char getChar() const { return 0; }
139         /// identifies things that can get \limits or \nolimits
140         virtual bool takesLimits() const { return false; }
141
142         /// char char code if possible
143         virtual void handleFont(std::string const &) {}
144         /// replace things by other things
145         virtual void replace(ReplaceData &) {}
146         /// do we contain a given subsequence?
147         virtual bool contains(MathArray const &) const { return false; }
148         /// access to the lock (only nest array have one)
149         virtual bool lock() const { return false; }
150         /// access to the lock (only nest array have one)
151         virtual void lock(bool) {}
152
153         /// write LaTeX and Lyx code
154         virtual void write(WriteStream & os) const;
155         /// write normalized content
156         virtual void normalize(NormalStream &) const;
157         /// write content as something readable by Maple
158         virtual void maple(MapleStream &) const;
159         /// write content as something readable by Maxima
160         virtual void maxima(MaximaStream &) const;
161         /// write content as something readable by Mathematica
162         virtual void mathematica(MathematicaStream &) const;
163         /// write content as something resembling MathML
164         virtual void mathmlize(MathMLStream &) const;
165         /// write content as something readable by Octave
166         virtual void octave(OctaveStream &) const;
167
168         /// dump content to stderr for debugging
169         virtual void dump() const;
170
171         /// LyXInset stuff
172         virtual bool numberedType() const { return false; }
173         /// hull type
174         virtual std::string const & getType() const;
175         /// change type
176         virtual void mutate(std::string const &) {}
177         /// usually the latex name
178         virtual std::string name() const;
179
180         /// math stuff usually isn't allowed in text mode
181         virtual bool allowedIn(mode_type mode) const { return mode == MATH_MODE; }
182 };
183
184 std::ostream & operator<<(std::ostream &, MathAtom const &);
185
186 // initialize math
187 void initMath();
188
189 #endif