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