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