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