]> git.lyx.org Git - lyx.git/blob - src/mathed/math_inset.h
cosmetics
[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 "symbol_def.h"
33 #include "xarray.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 LaTeXFeatures;
43
44 class MathInset {
45 public: 
46         ///
47         explicit MathInset
48         (int na = 0, string const & nm = string(), MathInsetTypes ot = LM_OT_SIMPLE);
49
50         /// the virtual base destructor
51         virtual ~MathInset() {}
52
53         /// draw the object, sets xo_ and yo_ cached values 
54         virtual void draw(Painter &, int x, int baseline) = 0;  
55         /// write LaTeX and Lyx code
56         virtual void write(std::ostream &, bool fragile) const = 0;
57         /// write normalized content
58         virtual void writeNormal(std::ostream &) const;
59         /// reproduce itself
60         virtual MathInset * clone() const = 0;
61         /// appends itself with macro arguments substituted
62         virtual void substitute(MathArray & array, MathMacro const & macro) const;
63         /// compute the size of the object, sets ascend_, descend_ and width_
64         virtual void metrics(MathStyles st) = 0;
65         /// 
66         virtual int ascent() const;
67         ///
68         virtual int descent() const;
69         ///
70         virtual int width() const;
71         ///
72         virtual int height() const;
73         ///
74         virtual int limits() const;
75         ///
76         virtual void limits(int);
77         ///
78         string const & name() const;
79         ///
80         MathInsetTypes getType() const;
81         ///
82         MathInsetTypes GetType() const { return getType(); }
83         //Man:  Avoid to use these functions if it's not strictly necessary 
84         ///
85         virtual void setType(MathInsetTypes t);
86         ///
87         virtual void setName(string const & n);
88         ///
89         MathStyles size() const;
90
91         /// Where should we go when we press the up cursor key?
92         virtual bool idxUp(int & idx, int & pos) const;
93         /// The down key
94         virtual bool idxDown(int & idx, int & pos) const;
95         /// The left key
96         virtual bool idxLeft(int & idx, int & pos) const;
97         /// The right key
98         virtual bool idxRight(int & idx, int & pos) const;
99
100         /// Move one physical cell up
101         virtual bool idxNext(int & idx, int & pos) const;
102         /// Move one physical cell down
103         virtual bool idxPrev(int & idx, int & pos) const;
104
105         /// Target pos when we enter the inset from the left by pressing "Right"
106         virtual bool idxFirst(int & idx, int & pos) const;
107         /// Target pos when we enter the inset from the left by pressing "Up"
108         virtual bool idxFirstUp(int & idx, int & pos) const;
109         /// Target pos when we enter the inset from the left by pressing "Down"
110         virtual bool idxFirstDown(int & idx, int & pos) const;
111
112         /// Target pos when we enter the inset from the right by pressing "Left"
113         virtual bool idxLast(int & idx, int & pos) const;
114         /// Target pos when we enter the inset from the right by pressing "Up"
115         virtual bool idxLastUp(int & idx, int & pos) const;
116         /// Target pos when we enter the inset from the right by pressing "Down"
117         virtual bool idxLastDown(int & idx, int & pos) const;
118
119         /// Where should we go if we press home?
120         virtual bool idxHome(int & idx, int & pos) const;
121         /// Where should we go if we press end?
122         virtual bool idxEnd(int & idx, int & pos) const;
123
124         /// Delete a cell and move cursor
125         // the return value indicates whether the cursor should leave the inset
126         // and/or the whole inset should be deleted
127         virtual void idxDelete(int & idx, bool & popit, bool & deleteit);
128         // deletes a cell range and moves the cursor 
129         virtual void idxDeleteRange(int from, int to);
130         // returns list of cell indices that are "between" from and to for
131         // selction purposes
132         virtual std::vector<int> idxBetween(int from, int to) const;
133
134         ///
135         int nargs() const;
136
137         ///
138         MathArray & cell(int);
139         ///
140         MathArray const & cell(int) const;
141         ///
142         MathXArray & xcell(int);
143         ///
144         MathXArray const & xcell(int) const;
145                         
146         ///
147         int xo() const;
148         ///
149         int yo() const;
150         ///
151         void xo(int tx);
152         ///
153         void yo(int ty);
154         ///
155
156         ///
157         virtual int ncols() const { return 1; }
158         ///
159         virtual int nrows() const { return 1; }
160         ///
161         virtual int col(int) const { return 0; }
162         ///
163         virtual int row(int) const { return 0; }
164         ///
165         virtual void addRow(int) {}
166         ///
167         virtual void delRow(int) {}
168         ///
169         virtual void addCol(int) {}
170         ///
171         virtual void delCol(int) {}
172
173         ///
174         virtual void userSetSize(MathStyles &) {}
175
176         ///
177         void getXY(int & x, int & y) const;
178         ///
179         bool covers(int x, int y) const;
180         /// Identifies things that can get scripts
181         virtual bool isScriptable() const { return false; }
182         /// Identifies ScriptInsets
183         virtual bool isScriptInset() const { return false; }
184         /// Identifies SpaceInsets
185         virtual bool isSpaceInset() const { return false; }
186         ///
187         virtual bool isActive() const { return nargs() > 0; }
188
189
190         ///
191         void push_back(MathInset *);
192         ///
193         void push_back(unsigned char ch, MathTextCodes fcode);
194         ///
195         void dump() const;
196
197         ///
198         void validate(LaTeXFeatures & features) const;
199
200         ///
201         static int workwidth;
202 protected:
203         /// usually the LaTeX name of the thingy
204         string name_;
205         ///  
206         MathInsetTypes objtype;
207         /// the width of this inset as computed by metrics()
208         int width_;
209         /// 
210         int ascent_;
211         ///
212         int descent_;
213         /// 
214         void size(MathStyles s);
215         /// the used font size
216         MathStyles size_;
217
218 protected:
219         ///
220         typedef std::vector<MathXArray> cells_type;
221         /**
222          * The contents of the inset are contained here.
223          * Each inset is build from a number of insets.
224          */
225         cells_type cells_;
226
227 private:
228         /// the following are used for positioning the cursor with the mouse
229         /// cached cursor start position in pixels from the document left
230         int xo_;
231         /// cached cursor start position in pixels from the document top
232         int yo_;
233 };
234
235 std::ostream & operator<<(std::ostream &, MathInset const &);
236
237 #endif