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 "MathClass.h"
18 #include "insets/Inset.h"
39 HullType hullType(docstring const & name);
40 docstring hullName(HullType type);
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
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.
61 class InsetMathAMSArray;
65 class InsetMathFracBase;
70 class InsetMathMatrix;
72 class InsetMathScript;
73 class InsetMathString;
75 class InsetMathSpecialChar;
76 class InsetMathSymbol;
77 class InsetMathUnknown;
85 class MathematicaStream;
90 class MathMacroTemplate;
94 class TextMetricsInfo;
97 /// Type of unique identifiers for math insets (used in TexRow)
98 typedef void const * uid_type;
101 class InsetMath : public Inset {
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; }
112 virtual docstring name() const;
114 /// this is overridden by specific insets
115 virtual mode_type currentMode() const { return MATH_MODE; }
117 /// the ascent of the inset above the baseline
118 /// compute the size of the object for text based drawing
119 virtual void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
120 /// draw the object as text
121 virtual void drawT(TextPainter &, int x, int y) const;
123 /// return cell given its number
124 virtual MathData & cell(idx_type);
125 /// return cell given its number
126 virtual MathData const & cell(idx_type) const;
128 /// identifies certain types of insets
129 virtual InsetMathAMSArray * asAMSArrayInset() { return 0; }
130 virtual InsetMathAMSArray const * asAMSArrayInset() const { return 0; }
131 virtual InsetMathArray * asArrayInset() { return 0; }
132 virtual InsetMathArray const * asArrayInset() const { return 0; }
133 virtual InsetMathBrace * asBraceInset() { return 0; }
134 virtual InsetMathBrace const * asBraceInset() const { return 0; }
135 virtual InsetMathChar const * asCharInset() const { return 0; }
136 virtual InsetMathDelim * asDelimInset() { return 0; }
137 virtual InsetMathDelim const * asDelimInset() const { return 0; }
138 virtual InsetMathFracBase * asFracBaseInset() { return 0; }
139 virtual InsetMathFracBase const * asFracBaseInset() const { return 0; }
140 virtual InsetMathFrac * asFracInset() { return 0; }
141 virtual InsetMathFrac const * asFracInset() const { return 0; }
142 virtual InsetMathFont * asFontInset() { return 0; }
143 virtual InsetMathFont const * asFontInset() const { return 0; }
144 virtual InsetMathGrid * asGridInset() { return 0; }
145 virtual InsetMathGrid const * asGridInset() const { return 0; }
146 virtual InsetMathHull * asHullInset() { return 0; }
147 virtual InsetMathHull const * asHullInset() const { return 0; }
148 virtual MathMacro * asMacro() { return 0; }
149 virtual MathMacro const * asMacro() const { return 0; }
150 virtual MathMacroTemplate * asMacroTemplate() { return 0; }
151 virtual MathMacroTemplate const * asMacroTemplate() const { return 0; }
152 virtual InsetMathMatrix const * asMatrixInset() const { return 0; }
153 virtual InsetMathNest * asNestInset() { return 0; }
154 virtual InsetMathNest const * asNestInset() const { return 0; }
155 virtual InsetMathScript * asScriptInset() { return 0; }
156 virtual InsetMathScript const * asScriptInset() const { return 0; }
157 virtual InsetMathSpace * asSpaceInset() { return 0; }
158 virtual InsetMathSpace const * asSpaceInset() const { return 0; }
159 virtual InsetMathString * asStringInset() { return 0; }
160 virtual InsetMathString const * asStringInset() const { return 0; }
161 virtual InsetMathSymbol const * asSymbolInset() const { return 0; }
162 virtual InsetMathUnknown * asUnknownInset() { return 0; }
163 virtual InsetMathUnknown const * asUnknownInset() const { return 0; }
164 virtual InsetMathRef * asRefInset() { return 0; }
165 virtual InsetMathSpecialChar const * asSpecialCharInset() const { return 0; }
167 /// The class of the math object (used primarily for spacing)
168 virtual MathClass mathClass() const;
169 /// Add this inset to a math row. Return true if contents got added
170 virtual bool addToMathRow(MathRow &, MetricsInfo & mi) const;
172 /// draw four angular markers
173 void drawMarkers(PainterInfo & pi, int x, int y) const;
174 /// draw two angular markers
175 void drawMarkers2(PainterInfo & pi, int x, int y) const;
176 /// add space for markers
177 void metricsMarkers(MetricsInfo & mi, Dimension & dim, int framesize = 1) const;
178 /// add space for markers
179 void metricsMarkers2(MetricsInfo & mi, Dimension & dim, int framesize = 1) const;
181 /// identifies things that can get scripts
182 virtual bool isScriptable() const { return false; }
183 /// will this get written as a single block in {..}
184 virtual bool extraBraces() const { return false; }
186 /// return the content as char if the inset is able to do so
187 virtual char_type getChar() const { return 0; }
188 /// identifies things that can get \limits or \nolimits
189 virtual bool takesLimits() const { return false; }
191 /// replace things by other things
192 virtual void replace(ReplaceData &) {}
193 /// do we contain a given subsequence?
194 virtual bool contains(MathData const &) const { return false; }
195 /// access to the lock (only nest array have one)
196 virtual bool lock() const { return false; }
197 /// access to the lock (only nest array have one)
198 virtual void lock(bool) {}
200 // Indicate that we do not want to hide the normal version of
201 // write(). This is to shut off a clang warning.
203 /// write LaTeX and LyX code
204 virtual void write(WriteStream & os) const;
205 /// write normalized content
206 virtual void normalize(NormalStream &) const;
207 /// write content as something readable by Maple
208 virtual void maple(MapleStream &) const;
209 /// write content as something readable by Maxima
210 virtual void maxima(MaximaStream &) const;
211 /// write content as something readable by Mathematica
212 virtual void mathematica(MathematicaStream &) const;
213 /// write content as MathML
214 virtual void mathmlize(MathStream &) const;
215 /// write content as HTML, best we can.
216 /// the idea for this, and some of the details, come from
217 /// eLyXer, written by Alex Fernandez. no code is borrowed. rather,
218 /// we try to mimic how eLyXer outputs some math.
219 virtual void htmlize(HtmlStream &) const;
220 /// write content as something readable by Octave
221 virtual void octave(OctaveStream &) const;
223 /// plain text output in ucs4 encoding
224 int plaintext(odocstringstream &, OutputParams const &, size_t) const;
226 /// dump content to stderr for debugging
227 virtual void dump() const;
230 virtual bool numberedType() const { return false; }
232 virtual HullType getType() const;
234 virtual void mutate(HullType /*newtype*/) {}
236 /// math stuff usually isn't allowed in text mode
237 virtual bool allowedIn(mode_type mode) const { return mode == MATH_MODE; }
239 /// superscript kerning
240 virtual int kerning(BufferView const *) const { return 0; }
242 bool isInToc() const { return true; }
244 InsetCode lyxCode() const { return MATH_CODE; }
246 uid_type id() const { return this; }
250 std::ostream & operator<<(std::ostream &, MathAtom const &);
252 odocstream & operator<<(odocstream &, MathAtom const &);