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