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