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