4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Alejandro Aguilar Sierra
10 * Full author contact details are available in file CREDITS.
16 #include "insets/insetbase.h"
22 Abstract base class for all math objects. A math insets is for use of the
23 math editor only, it isn't a general LyX inset. It's used to represent all
26 Math insets do not know there parents, a cursor position or things
27 like that. The are dumb object that are contained in other math insets
28 (MathNestInsets, in fact) thus forming a tree. The root of this tree is
29 always a MathHullInset, which provides an interface to the Outer World by
30 inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
36 class MathAMSArrayInset;
43 class MathMatrixInset;
45 class MathParboxInset;
46 class MathScriptInset;
47 class MathStringInset;
49 class MathSymbolInset;
50 class MathUnknownInset;
61 class MathematicaStream;
66 class MathMacroTemplate;
72 class TextMetricsInfo;
76 class MathInset : public InsetBase {
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; }
83 /// substitutes macro arguments if necessary
84 virtual void substitute(MathMacro const & macro);
85 /// draw selection between two positions
86 virtual void drawSelection(PainterInfo & pi,
87 idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const;
88 /// the ascent of the inset above the baseline
89 /// compute the size of the object for text based drawing
90 virtual void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
91 /// draw the object as text
92 virtual void drawT(TextPainter &, int x, int y) const;
94 /// return cell given its number
95 virtual MathArray & cell(idx_type);
96 /// return cell given its number
97 virtual MathArray const & cell(idx_type) const;
99 /// identifies certain types of insets
100 virtual MathAMSArrayInset * asAMSArrayInset() { return 0; }
101 virtual MathAMSArrayInset const * asAMSArrayInset() const { return 0; }
102 virtual MathArrayInset * asArrayInset() { return 0; }
103 virtual MathArrayInset const * asArrayInset() const { return 0; }
104 virtual MathCharInset const * asCharInset() const { return 0; }
105 virtual MathDelimInset * asDelimInset() { return 0; }
106 virtual MathDelimInset const * asDelimInset() const { return 0; }
107 virtual MathFracInset * asFracInset() { return 0; }
108 virtual MathFracInset const * asFracInset() const { return 0; }
109 virtual MathFontInset * asFontInset() { return 0; }
110 virtual MathFontInset const * asFontInset() const { return 0; }
111 virtual MathGridInset * asGridInset() { return 0; }
112 virtual MathGridInset const * asGridInset() const { return 0; }
113 virtual MathHullInset * asHullInset() { return 0; }
114 virtual MathHullInset const * asHullInset() const { return 0; }
115 virtual MathMacroTemplate * asMacroTemplate() { return 0; }
116 virtual MathMacroTemplate const * asMacroTemplate() const { return 0; }
117 virtual MathMatrixInset const * asMatrixInset() const { return 0; }
118 virtual MathNestInset * asNestInset() { return 0; }
119 virtual MathNestInset const * asNestInset() const { return 0; }
120 virtual MathParboxInset * asParboxInset() { return 0; }
121 virtual MathScriptInset * asScriptInset() { return 0; }
122 virtual MathScriptInset const * asScriptInset() const { return 0; }
123 virtual MathSpaceInset * asSpaceInset() { return 0; }
124 virtual MathSpaceInset const * asSpaceInset() const { return 0; }
125 virtual MathStringInset * asStringInset() { return 0; }
126 virtual MathStringInset const * asStringInset() const { return 0; }
127 virtual MathSymbolInset const * asSymbolInset() const { return 0; }
128 virtual MathUnknownInset * asUnknownInset() { return 0; }
129 virtual MathUnknownInset const * asUnknownInset() const { return 0; }
130 virtual RefInset * asRefInset() { return 0; }
132 /// identifies things that can get scripts
133 virtual bool isScriptable() const { return false; }
134 /// is the a relational operator (used for splitting equations)
135 virtual bool isRelOp() const { return false; }
136 /// will this get written as a single block in {..}
137 virtual bool extraBraces() const { return false; }
139 /// return the content as char if the inset is able to do so
140 virtual char getChar() const { return 0; }
141 /// identifies things that can get \limits or \nolimits
142 virtual bool takesLimits() const { return false; }
144 /// char char code if possible
145 virtual void handleFont(std::string const &) {}
146 /// replace things by other things
147 virtual void replace(ReplaceData &) {}
148 /// do we contain a given subsequence?
149 virtual bool contains(MathArray const &) const { return false; }
150 /// access to the lock (only nest array have one)
151 virtual bool lock() const { return false; }
152 /// access to the lock (only nest array have one)
153 virtual void lock(bool) {}
155 /// write LaTeX and Lyx code
156 virtual void write(WriteStream & os) const;
157 /// write normalized content
158 virtual void normalize(NormalStream &) const;
159 /// write content as something readable by Maple
160 virtual void maple(MapleStream &) const;
161 /// write content as something readable by Maxima
162 virtual void maxima(MaximaStream &) const;
163 /// write content as something readable by Mathematica
164 virtual void mathematica(MathematicaStream &) const;
165 /// write content as something resembling MathML
166 virtual void mathmlize(MathMLStream &) const;
167 /// write content as something readable by Octave
168 virtual void octave(OctaveStream &) const;
170 /// dump content to stderr for debugging
171 virtual void dump() const;
174 virtual bool numberedType() const { return false; }
176 virtual std::string const & getType() const;
178 virtual void mutate(std::string const &) {}
179 /// how is the inset called in the .lyx file?
180 virtual std::string fileInsetLabel() const;
181 /// usually the latex name
182 virtual std::string name() const;
185 std::ostream & operator<<(std::ostream &, MathAtom const &);