]> git.lyx.org Git - lyx.git/blob - src/mathed/math_inset.h
some support for det and abs for math-extern
[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 "xarray.h"
32 #include "math_defs.h"
33 #include "LString.h"
34
35 /** Abstract base class for all math objects.
36     A math insets is for use of the math editor only, it isn't a
37     general LyX inset. It's used to represent all the math objects.
38     The formulaInset (a LyX inset) encapsulates a math inset.
39 */
40
41
42 class MathArrayInset;
43 class MathBoxInset;
44 class MathCharInset;
45 class MathGridInset;
46 class MathNestInset;
47 class MathMatrixInset;
48 class MathScriptInset;
49 class MathSpaceInset;
50 class MathMacroTemplate;
51
52 class LaTeXFeatures;
53 class Buffer;
54 class BufferView;
55 class UpdatableInset;
56 class MathOctaveInfo;
57
58
59 struct MathWriteInfo {
60         ///
61         MathWriteInfo(Buffer const * buffer_, std::ostream & os_, bool fragile_)
62                 : buffer(buffer_), os(os_), fragile(fragile_)
63         {}
64         ///
65         explicit MathWriteInfo(std::ostream & os_)
66                 : buffer(0), os(os_), fragile(false)
67         {}
68
69         ///
70         template <class T>
71         MathWriteInfo & operator<<(T const & t)
72         {
73                 os << t;
74                 return *this;
75         }
76         ///
77         MathWriteInfo & operator<<(MathArray const & ar)
78         {
79                 ar.write(*this);
80                 return *this;
81         }
82
83
84         ///
85         Buffer const * buffer;
86         ///
87         std::ostream & os;
88         ///
89         bool fragile;
90 };
91
92
93 class MathInset {
94 public: 
95         /// short of anything else reasonable
96         typedef MathArray::size_type     size_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         ///
107         MathInset();
108         /// the virtual base destructor
109         virtual ~MathInset(); 
110
111         /// draw the object
112         virtual void draw(Painter &, int x, int y) const;
113         /// write LaTeX and Lyx code
114         virtual void write(MathWriteInfo & os) const;
115         /// write normalized content
116         virtual void writeNormal(std::ostream &) const;
117         /// reproduce itself
118         virtual MathInset * clone() const = 0;
119         ///substitutes macro arguments if necessary
120         virtual void substitute(MathMacro const & macro);
121         /// compute the size of the object, sets ascend_, descend_ and width_
122         virtual void metrics(MathMetricsInfo const & st) const;
123         /// 
124         virtual int ascent() const { return 1; }
125         ///
126         virtual int descent() const { return 1; }
127         ///
128         virtual int width() const { return 2; }
129         ///
130         virtual int height() const;
131
132         /// Where should we go when we press the up cursor key?
133         virtual bool idxUp(idx_type & idx, pos_type & pos) const;
134         /// The down key
135         virtual bool idxDown(idx_type & idx, pos_type & pos) const;
136         /// The left key
137         virtual bool idxLeft(idx_type & idx, pos_type & pos) const;
138         /// The right key
139         virtual bool idxRight(idx_type & idx, pos_type & pos) const;
140
141         /// Move one physical cell up
142         virtual bool idxNext(idx_type & idx, pos_type & pos) const;
143         /// Move one physical cell down
144         virtual bool idxPrev(idx_type & idx, pos_type & pos) const;
145
146         /// Target pos when we enter the inset from the left by pressing "Right"
147         virtual bool idxFirst(idx_type & idx, pos_type & pos) const;
148         /// Target pos when we enter the inset from the right by pressing "Left"
149         virtual bool idxLast(idx_type & idx, pos_type & pos) const;
150
151         /// Where should we go if we press home?
152         virtual bool idxHome(idx_type & idx, pos_type & pos) const;
153         /// Where should we go if we press end?
154         virtual bool idxEnd(idx_type & idx, pos_type & pos) const;
155
156         /// Delete a cell and move cursor
157         // the return value indicates whether the cursor should leave the inset
158         // and/or the whole inset should be deleted
159         virtual void idxDelete(idx_type & idx, bool & popit, bool & deleteit);
160         // deletes a cell range and moves the cursor 
161         virtual void idxDeleteRange(idx_type from, idx_type to);
162         // returns list of cell indices that are "between" from and to for
163         // selection purposes
164         virtual std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
165
166         ///
167         virtual idx_type nargs() const;
168
169         ///
170         virtual MathArray & cell(idx_type);
171         ///
172         virtual MathArray const & cell(idx_type) const;
173         ///
174         virtual MathXArray & xcell(idx_type);
175         ///
176         virtual MathXArray const & xcell(idx_type) const;
177                         
178         ///
179         virtual col_type ncols() const { return 1; }
180         ///
181         virtual row_type nrows() const { return 1; }
182         ///
183         virtual col_type col(row_type) const { return 0; }
184         ///
185         virtual row_type row(row_type) const { return 0; }
186         ///
187         virtual int cellXOffset(row_type) const { return 0; }
188         ///
189         virtual int cellYOffset(row_type) const { return 0; }
190         ///
191         virtual void addRow(row_type) {}
192         ///
193         virtual void delRow(row_type) {}
194         ///
195         virtual void addCol(col_type) {}
196         ///
197         virtual void delCol(col_type) {}
198
199         ///
200         virtual bool covers(int x, int y) const;
201
202         /// identifies NestInsets
203         virtual MathNestInset * asNestInset() { return 0; }
204         /// identifies CharInsets
205         virtual MathCharInset const * asCharInset() const { return 0; }
206         /// identifies ScriptInsets
207         virtual MathScriptInset const * asScriptInset() const { return 0; }
208         /// identifies ScriptInsets
209         virtual MathScriptInset * asScriptInset() { return 0; }
210         /// identifies MatrixInsets
211         virtual MathMatrixInset const * asMatrixInset() const { return 0; }
212         /// identifies MatrixInsets
213         virtual MathMatrixInset * asMatrixInset() { return 0; }
214         /// identifies SpaceInset
215         virtual MathSpaceInset * asSpaceInset() { return 0; }
216         /// identifies GridInset
217         virtual MathGridInset * asGridInset() { return 0; }
218         /// identifies ArrayInsets
219         virtual MathArrayInset * asArrayInset() { return 0; }
220         /// identifies BoxInsets
221         virtual MathBoxInset * asBoxInset() { return 0; }
222         /// identifies macro templates
223         virtual MathMacroTemplate * asMacroTemplate() { return 0; }
224         /// identifies hyperactive insets
225         virtual UpdatableInset * asHyperActiveInset() const { return 0; }
226
227         /// identifies things that can get scripts
228         virtual bool isScriptable() const { return false; }
229         ///
230         virtual bool isActive() const { return nargs() > 0; }
231         /// identifies insets from the outer world
232         virtual bool isHyperActive() const { return 0; }
233         ///
234         virtual bool isRelOp() const { return false; }
235         ///
236         virtual bool isMacro() const { return false; }
237         /// is this a matrix or matrix expression?
238         virtual bool isMatrix() const { return false; }
239
240         ///
241         virtual char getChar() const { return 0; }
242         ///
243         virtual MathTextCodes code() const { return LM_TC_MIN; }
244         /// identifies things that can get \limits or \nolimits
245         virtual bool takesLimits() const { return false; }
246
247         ///
248         virtual void dump() const;
249         ///
250         virtual void edit(BufferView *, int, int, unsigned int) {}
251
252         ///
253         virtual void validate(LaTeXFeatures & features) const;
254         ///
255         virtual void handleFont(MathTextCodes) {}
256
257         ///
258         virtual string octavize() const;
259         ///
260         virtual string maplize() const;
261         ///
262         virtual string mathmlize() const;
263 };
264
265 std::ostream & operator<<(std::ostream &, MathInset const &);
266
267 #endif