]> git.lyx.org Git - lyx.git/blob - src/mathed/math_inset.h
more work on \parbox support
[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 //  Note: These math insets are internal to Math and are not derived
20 //        from lyx inset.
21
22 #ifndef MATH_INSET_H
23 #define MATH_INSET_H
24
25 #include <config.h>
26
27 #ifdef __GNUG__
28 #pragma interface
29 #endif
30
31 #include "LString.h"
32 #include "frontends/mouse_state.h"
33 #include "math_xdata.h"
34
35 /**
36
37 Abstract base class for all math objects.  A math insets is for use of the
38 math editor only, it isn't a general LyX inset. It's used to represent all
39 the math objects.
40
41 Math insets do not know there parents, a cursor position or things
42 like that. The are dumb object that are contained in other math insets
43 (mathNestInsets, in fact) thus forming a tree. The root of this tree is
44 always a mathHullInset, which provides an interface to the Outer World by
45 inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
46
47 */
48
49
50 class MathArrayInset;
51 class MathAMSArrayInset;
52 class MathBoxInset;
53 class MathCharInset;
54 class MathDelimInset;
55 class MathFboxInset;
56 class MathFontInset;
57 class MathGridInset;
58 class MathFracInset;
59 class MathHullInset;
60 class MathMatrixInset;
61 class MathNestInset;
62 class MathParInset;
63 class MathParboxInset;
64 class MathScriptInset;
65 class MathStringInset;
66 class MathSpaceInset;
67 class MathSymbolInset;
68 class MathUnknownInset;
69 class MathXYMatrixInset;
70 class MathXYMatrixInset;
71
72 class InsetRef;
73
74 class NormalStream;
75 class OctaveStream;
76 class MapleStream;
77 class MathematicaStream;
78 class MathMLStream;
79 class WriteStream;
80 class InfoStream;
81 class MathArray;
82
83 class LaTeXFeatures;
84 class BufferView;
85 class UpdatableInset;
86 class MathMacroTemplate;
87 class MathPosFinder;
88 class Dimension;
89
90
91 class MathInset {
92 public:
93         /// short of anything else reasonable
94         typedef MathArray::size_type        size_type;
95         /// type for cursor positions differences within a cell
96         typedef MathArray::difference_type  difference_type;
97         /// type for cursor positions within a cell
98         typedef MathArray::size_type        pos_type;
99         /// type for cell indices
100         typedef size_type                   idx_type;
101         /// type for row numbers
102         typedef size_type                   row_type;
103         /// type for column numbers
104         typedef size_type                   col_type;
105
106         /// our members behave nicely...
107         MathInset() {}
108         /// the virtual base destructor
109         virtual ~MathInset() {}
110
111         /// reproduce itself
112         virtual MathInset * clone() const = 0;
113         /// substitutes macro arguments if necessary
114         virtual void substitute(MathMacro const & macro);
115         /// compute the size of the object, sets ascend_, descend_ and width_
116         // updates the (xo,yo)-caches of all contained cells
117         virtual void metrics(MathMetricsInfo & st) const;
118         /// draw the object
119         virtual void draw(MathPainterInfo &, int x, int y) const;
120         /// the ascent of the inset above the baseline
121         /// compute the size of the object for text based drawing
122         virtual void metricsT(TextMetricsInfo const & st) const;
123         /// draw the object as text
124         virtual void drawT(TextPainter &, int x, int y) const;
125         /// the ascent of the inset above the baseline
126         virtual int ascent() const { return 1; }
127         /// the descent of the inset below the baseline
128         virtual int descent() const { return 1; }
129         /// total width
130         virtual int width() const { return 2; }
131         /// all in one batch
132         virtual void dimensions(Dimension & dim) const;
133         /// total height (== ascent + descent)
134         virtual int height() const;
135         /// get cursor position
136         virtual void getPos(idx_type idx, pos_type pos, int & x, int & y) const;
137
138         /// Where should we go when we press the up or down cursor key?
139         virtual bool idxUpDown(idx_type & idx, bool up) const;
140         /// The left key
141         virtual bool idxLeft(idx_type & idx, pos_type & pos) const;
142         /// The right key
143         virtual bool idxRight(idx_type & idx, pos_type & pos) const;
144
145         /// Move one physical cell up
146         virtual bool idxNext(idx_type & idx, pos_type & pos) const;
147         /// Move one physical cell down
148         virtual bool idxPrev(idx_type & idx, pos_type & pos) const;
149
150         /// Target pos when we enter the inset from the left by pressing "Right"
151         virtual bool idxFirst(idx_type & idx, pos_type & pos) const;
152         /// Target pos when we enter the inset from the right by pressing "Left"
153         virtual bool idxLast(idx_type & idx, pos_type & pos) const;
154
155         /// Where should we go if we press home?
156         virtual bool idxHome(idx_type & idx, pos_type & pos) const;
157         /// Where should we go if we press end?
158         virtual bool idxEnd(idx_type & idx, pos_type & pos) const;
159
160         /// Delete a cell and move cursor
161         virtual bool idxDelete(idx_type &) { return false; }
162         /// pulls cell after pressing erase
163         virtual void idxGlue(idx_type) {}
164         // returns list of cell indices that are "between" from and to for
165         // selection purposes
166         virtual std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
167
168         /// the number of nested cells this inset owns
169         virtual idx_type nargs() const;
170
171         /// return cell given its number
172         virtual MathArray & cell(idx_type);
173         /// return cell given its number
174         virtual MathArray const & cell(idx_type) const;
175         /// return cell plus drawing cache given its number
176         virtual MathXArray & xcell(idx_type);
177         /// return cell plus drawing cache given its number
178         virtual MathXArray const & xcell(idx_type) const;
179
180         /// the number of columns of this inset if it is grid-like
181         virtual col_type ncols() const { return 1; }
182         /// the number of rows of this inset if it is grid-like
183         virtual row_type nrows() const { return 1; }
184         /// to which column belongs a cell with a given index?
185         virtual col_type col(idx_type) const { return 0; }
186         /// to which row belongs a cell with a given index?
187         virtual row_type row(idx_type) const { return 0; }
188         /// cell idex corresponding to row and column;
189         virtual idx_type index(row_type row, col_type col) const;
190         /// any additional x-offset when drawing a cell?
191         virtual int cellXOffset(idx_type) const { return 0; }
192         /// any additional y-offset when drawing a cell?
193         virtual int cellYOffset(idx_type) const { return 0; }
194         /// can we enter this cell?
195         virtual bool validCell(idx_type) const { return true; }
196
197         /// identifies certain types of insets
198         virtual MathAMSArrayInset      * asAMSArrayInset()      { return 0; }
199         virtual MathArrayInset         * asArrayInset()         { return 0; }
200         virtual MathBoxInset           * asBoxInset()           { return 0; }
201         virtual MathBoxInset const     * asBoxInset() const     { return 0; }
202         virtual MathCharInset const    * asCharInset() const    { return 0; }
203         virtual MathDelimInset         * asDelimInset()         { return 0; }
204         virtual MathDelimInset const   * asDelimInset() const   { return 0; }
205         virtual MathFboxInset          * asFboxInset()          { return 0; }
206         virtual MathFontInset const    * asFontInset() const    { return 0; }
207         virtual MathFracInset          * asFracInset()          { return 0; }
208         virtual MathGridInset          * asGridInset()          { return 0; }
209         virtual MathHullInset          * asHullInset()          { return 0; }
210         virtual MathHullInset const    * asHullInset() const    { return 0; }
211         virtual MathMacroTemplate      * asMacroTemplate()      { return 0; }
212         virtual MathMatrixInset const  * asMatrixInset() const  { return 0; }
213         virtual MathNestInset          * asNestInset()          { return 0; }
214         virtual MathParInset           * asParInset()           { return 0; }
215         virtual MathParboxInset        * asParboxInset()        { return 0; }
216         virtual MathScriptInset        * asScriptInset()        { return 0; }
217         virtual MathScriptInset const  * asScriptInset() const  { return 0; }
218         virtual MathSpaceInset         * asSpaceInset()         { return 0; }
219         virtual MathStringInset        * asStringInset()        { return 0; }
220         virtual MathSymbolInset const  * asSymbolInset() const  { return 0; }
221         virtual MathUnknownInset       * asUnknownInset()       { return 0; }
222         virtual MathUnknownInset const * asUnknownInset() const { return 0; }
223         virtual MathXYMatrixInset const* asXYMatrixInset() const{ return 0; }
224         virtual InsetRef               * asInsetRef()           { return 0; }
225
226         /// identifies things that can get scripts
227         virtual bool isScriptable() const { return false; }
228         /// thing that can be moved into
229         virtual bool isActive() const { return nargs() > 0; }
230         /// is the a relational operator (used for splitting equations)
231         virtual bool isRelOp() const { return false; }
232         /// will this get written as a single block in {..}
233         virtual bool extraBraces() const { return false; }
234
235         /// return the content as char if the inset is able to do so
236         virtual char getChar() const { return 0; }
237         /// identifies things that can get \limits or \nolimits
238         virtual bool takesLimits() const { return false; }
239
240         ///
241         virtual void edit(BufferView *, int, int, mouse_button::state) {}
242
243         /// request "external features"
244         virtual void validate(LaTeXFeatures & features) const;
245         /// char char code if possible
246         virtual void handleFont(string const &) {}
247         /// is this inset equal to a given other inset?
248         virtual bool match(MathInset *) const { return false; }
249         /// replace things by other things
250         virtual void replace(ReplaceData &) {}
251         /// do we contain a given subsequence?
252         virtual bool contains(MathArray const &) { return false; }
253         /// access to the lock (only nest array have one)
254         virtual bool lock() const { return false; }
255         /// access to the lock (only nest array have one)
256         virtual void lock(bool) {}
257         /// get notification when the cursor leaves this inset
258         virtual void notifyCursorLeaves() {}
259
260         /// write LaTeX and Lyx code
261         virtual void write(WriteStream & os) const;
262         /// write normalized content
263         virtual void normalize(NormalStream &) const;
264         /// write content as something readable by Maple
265         virtual void maplize(MapleStream &) const;
266         /// write content as something readable by Mathematica
267         virtual void mathematicize(MathematicaStream &) const;
268         /// write content as something resembling MathML
269         virtual void mathmlize(MathMLStream &) const;
270         /// write content as something readable by Octave
271         virtual void octavize(OctaveStream &) const;
272         /// describe content
273         virtual void infoize(std::ostream &) const {}
274         /// plain ascii output
275         virtual int ascii(std::ostream & os, int) const;
276         /// linuxdoc output
277         virtual int linuxdoc(std::ostream & os) const;
278         /// docbook output
279         virtual int docbook(std::ostream & os, bool) const;
280
281         /// dump content to stderr for debugging
282         virtual void dump() const;
283         /// local dispatcher
284         virtual int dispatch(string const & cmd, idx_type idx, pos_type pos);
285
286         /// LyXInset stuff
287         virtual std::vector<string> getLabelList() const;
288         /// LyXInset stuff
289         virtual bool numberedType() const { return false; }
290         /// hull type
291         virtual string const & getType() const;
292         /// change type
293         virtual void mutate(string const &) {}
294         /// how is the inset called in the .lyx file?
295         virtual string fileInsetLabel() const { return "Formula"; }
296 };
297
298 std::ostream & operator<<(std::ostream &, MathInset const &);
299 std::ostream & operator<<(std::ostream &, MathAtom const &);
300
301 string asString(MathArray const & ar);
302 MathArray asArray(string const & str);
303 void initMath();
304
305 /// here to ssave a few includes in the insets
306 class Dialogs;
307 class LyXFunc;
308
309 Dialogs * getDialogs();
310 LyXFunc * getLyXFunc();
311
312 #endif