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