]> git.lyx.org Git - lyx.git/blob - src/mathed/math_inset.h
and some mathed de-uglyfication
[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 "cursor.h"
17 #include "insets/insetbase.h"
18
19 #include <string>
20
21 /**
22
23 Abstract base class for all math objects.  A math insets is for use of the
24 math editor only, it isn't a general LyX inset. It's used to represent all
25 the math objects.
26
27 Math insets do not know there parents, a cursor position or things
28 like that. The are dumb object that are contained in other math insets
29 (MathNestInsets, in fact) thus forming a tree. The root of this tree is
30 always a MathHullInset, which provides an interface to the Outer World by
31 inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
32
33 */
34
35 class OutputParams;
36 class MathArrayInset;
37 class MathAMSArrayInset;
38 class MathCharInset;
39 class MathDelimInset;
40 class MathFracInset;
41 class MathFontInset;
42 class MathGridInset;
43 class MathHullInset;
44 class MathMatrixInset;
45 class MathNestInset;
46 class MathParboxInset;
47 class MathScriptInset;
48 class MathStringInset;
49 class MathSpaceInset;
50 class MathSymbolInset;
51 class MathUnknownInset;
52
53 class RefInset;
54
55 class MathArray;
56 class MathAtom;
57
58 class NormalStream;
59 class OctaveStream;
60 class MapleStream;
61 class MaximaStream;
62 class MathematicaStream;
63 class MathMLStream;
64 class WriteStream;
65 class InfoStream;
66
67 class MathMacroTemplate;
68 class MathMacro;
69 class MathPosFinder;
70 class Dimension;
71 class TextPainter;
72 class TextMetricsInfo;
73 class ReplaceData;
74
75
76 class MathInset : public InsetBase {
77 public:
78         /// our members behave nicely...
79         MathInset() {}
80         /// identification as math inset
81         MathInset * asMathInset() { return this; }
82
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;
93
94         /// Where should we go when we press the up or down cursor key?
95         virtual bool idxUpDown(LCursor & cur, bool up, int targetx) const;
96         /// Where should we go when we press the up or down cursor key?
97         virtual bool idxUpDown2(LCursor & cur, bool up, int targetx) const;
98         /// The left key
99         virtual bool idxLeft(LCursor & cur) const;
100         /// The right key
101         virtual bool idxRight(LCursor & cur) const;
102
103         /// Move one physical cell up
104         virtual bool idxNext(LCursor & cur) const;
105         /// Move one physical cell down
106         virtual bool idxPrev(LCursor & cur) const;
107
108         /// Target pos when we enter the inset from the left by pressing "Right"
109         virtual bool idxFirst(LCursor & cur) const;
110         /// Target pos when we enter the inset from the right by pressing "Left"
111         virtual bool idxLast(LCursor & cur) const;
112
113         /// Where should we go if we press home?
114         virtual bool idxHome(LCursor & cur) const;
115         /// Where should we go if we press end?
116         virtual bool idxEnd(LCursor & cur) const;
117
118         /// Delete a cell and move cursor
119         virtual bool idxDelete(idx_type &) { return false; }
120         /// pulls cell after pressing erase
121         virtual void idxGlue(idx_type) {}
122         // returns list of cell indices that are "between" from and to for
123         // selection purposes
124         virtual bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
125
126         /// the number of nested cells this inset owns
127         virtual idx_type nargs() const;
128
129         /// return cell given its number
130         virtual MathArray & cell(idx_type);
131         /// return cell given its number
132         virtual MathArray const & cell(idx_type) const;
133
134         /// the number of columns of this inset if it is grid-like
135         virtual col_type ncols() const { return 1; }
136         /// the number of rows of this inset if it is grid-like
137         virtual row_type nrows() const { return 1; }
138         /// to which column belongs a cell with a given index?
139         virtual col_type col(idx_type) const { return 0; }
140         /// to which row belongs a cell with a given index?
141         virtual row_type row(idx_type) const { return 0; }
142         /// cell idex corresponding to row and column;
143         virtual idx_type index(row_type row, col_type col) const;
144         /// any additional x-offset when drawing a cell?
145         virtual int cellXOffset(idx_type) const { return 0; }
146         /// any additional y-offset when drawing a cell?
147         virtual int cellYOffset(idx_type) const { return 0; }
148         /// can we enter this cell?
149         virtual bool validCell(idx_type) const { return true; }
150         /// get coordinates
151         virtual void getScreenPos(idx_type idx, pos_type pos, int & x, int & y) const;
152
153         /// identifies certain types of insets
154         virtual MathAMSArrayInset       * asAMSArrayInset()       { return 0; }
155         virtual MathAMSArrayInset const * asAMSArrayInset() const { return 0; }
156         virtual MathArrayInset          * asArrayInset()          { return 0; }
157         virtual MathArrayInset const    * asArrayInset() const    { return 0; }
158         virtual MathCharInset const     * asCharInset() const     { return 0; }
159         virtual MathDelimInset          * asDelimInset()          { return 0; }
160         virtual MathDelimInset const    * asDelimInset() const    { return 0; }
161         virtual MathFracInset           * asFracInset()           { return 0; }
162         virtual MathFracInset const     * asFracInset() const     { return 0; }
163         virtual MathFontInset           * asFontInset()           { return 0; }
164         virtual MathFontInset const     * asFontInset() const     { return 0; }
165         virtual MathGridInset           * asGridInset()           { return 0; }
166         virtual MathGridInset const     * asGridInset() const     { return 0; }
167         virtual MathHullInset           * asHullInset()           { return 0; }
168         virtual MathHullInset const     * asHullInset() const     { return 0; }
169         virtual MathMacroTemplate       * asMacroTemplate()       { return 0; }
170         virtual MathMacroTemplate const * asMacroTemplate() const { return 0; }
171         virtual MathMatrixInset const   * asMatrixInset() const   { return 0; }
172         virtual MathNestInset           * asNestInset()           { return 0; }
173         virtual MathNestInset const     * asNestInset() const     { return 0; }
174         virtual MathParboxInset         * asParboxInset()         { return 0; }
175         virtual MathScriptInset         * asScriptInset()         { return 0; }
176         virtual MathScriptInset const   * asScriptInset() const   { return 0; }
177         virtual MathSpaceInset          * asSpaceInset()          { return 0; }
178         virtual MathSpaceInset const    * asSpaceInset() const    { return 0; }
179         virtual MathStringInset         * asStringInset()         { return 0; }
180         virtual MathStringInset const   * asStringInset() const   { return 0; }
181         virtual MathSymbolInset const   * asSymbolInset() const   { return 0; }
182         virtual MathUnknownInset        * asUnknownInset()        { return 0; }
183         virtual MathUnknownInset const  * asUnknownInset() const  { return 0; }
184         virtual RefInset                * asRefInset()            { return 0; }
185
186         /// identifies things that can get scripts
187         virtual bool isScriptable() const { return false; }
188         /// thing that can be moved into
189         virtual bool isActive() const { return nargs() > 0; }
190         /// is the a relational operator (used for splitting equations)
191         virtual bool isRelOp() const { return false; }
192         /// -1: text mode, 1: math mode, 0 undecided
193         enum mode_type {UNDECIDED_MODE, TEXT_MODE, MATH_MODE};
194
195         virtual mode_type currentMode() const { return UNDECIDED_MODE; }
196         /// will this get written as a single block in {..}
197         virtual bool extraBraces() const { return false; }
198
199         /// return the content as char if the inset is able to do so
200         virtual char getChar() const { return 0; }
201         /// identifies things that can get \limits or \nolimits
202         virtual bool takesLimits() const { return false; }
203
204         /// char char code if possible
205         virtual void handleFont(std::string const &) {}
206         /// replace things by other things
207         virtual void replace(ReplaceData &) {}
208         /// do we contain a given subsequence?
209         virtual bool contains(MathArray const &) const { return false; }
210         /// access to the lock (only nest array have one)
211         virtual bool lock() const { return false; }
212         /// access to the lock (only nest array have one)
213         virtual void lock(bool) {}
214         /// get notification when the cursor leaves this inset
215         virtual void notifyCursorLeaves(idx_type) {}
216
217         /// write LaTeX and Lyx code
218         virtual void write(WriteStream & os) const;
219         /// write normalized content
220         virtual void normalize(NormalStream &) const;
221         /// write content as something readable by Maple
222         virtual void maple(MapleStream &) const;
223         /// write content as something readable by Maxima
224         virtual void maxima(MaximaStream &) const;
225         /// write content as something readable by Mathematica
226         virtual void mathematica(MathematicaStream &) const;
227         /// write content as something resembling MathML
228         virtual void mathmlize(MathMLStream &) const;
229         /// write content as something readable by Octave
230         virtual void octave(OctaveStream &) const;
231         /// describe content if cursor inside
232         virtual void infoize(std::ostream &) const {}
233         /// describe content if cursor behind
234         virtual void infoize2(std::ostream &) const {}
235         /// plain ascii output
236         virtual int plaintext(std::ostream & os, OutputParams const &) const;
237         /// linuxdoc output
238         virtual int linuxdoc(std::ostream & os, OutputParams const &) const;
239         /// docbook output
240         virtual int docbook(std::ostream & os, OutputParams const &) const;
241
242         /// dump content to stderr for debugging
243         virtual void dump() const;
244
245         /// LyXInset stuff
246         virtual bool numberedType() const { return false; }
247         /// hull type
248         virtual std::string const & getType() const;
249         /// change type
250         virtual void mutate(std::string const &) {}
251         /// how is the inset called in the .lyx file?
252         virtual std::string fileInsetLabel() const;
253         /// usually the latex name
254         virtual std::string name() const;
255 };
256
257 std::ostream & operator<<(std::ostream &, MathAtom const &);
258
259 // initialize math
260 void initMath();
261
262 #endif