]> git.lyx.org Git - features.git/blob - src/mathed/math_inset.h
bb56cdb4b8d21612a10c78141a8fc6e61d7e3b0b
[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         /// Target pos when we enter the inset from the left by pressing "Right"
99         virtual bool idxFirst(int & idx, int & pos) const;
100         /// Target pos when we enter the inset from the left by pressing "Up"
101         virtual bool idxFirstUp(int & idx, int & pos) const;
102         /// Target pos when we enter the inset from the left by pressing "Down"
103         virtual bool idxFirstDown(int & idx, int & pos) const;
104
105         /// Target pos when we enter the inset from the right by pressing "Left"
106         virtual bool idxLast(int & idx, int & pos) const;
107         /// Target pos when we enter the inset from the right by pressing "Up"
108         virtual bool idxLastUp(int & idx, int & pos) const;
109         /// Target pos when we enter the inset from the right by pressing "Down"
110         virtual bool idxLastDown(int & idx, int & pos) const;
111
112         /// Where should we go if we press home?
113         virtual bool idxHome(int & idx, int & pos) const;
114         /// Where should we go if we press end?
115         virtual bool idxEnd(int & idx, int & pos) const;
116
117         /// Delete a cell and move cursor
118         // a return value true indicates that the whole inset should be deleted
119         virtual bool idxDelete(int idx);
120
121         ///
122         int nargs() const;
123
124         ///
125         MathArray & cell(int);
126         ///
127         MathArray const & cell(int) const;
128         ///
129         MathXArray & xcell(int);
130         ///
131         MathXArray const & xcell(int) const;
132         ///
133         void setData(MathArray const &, int);
134                         
135         ///
136         int xo() const;
137         ///
138         int yo() const;
139         ///
140         void xo(int tx);
141         ///
142         void yo(int ty);
143         ///
144
145         ///
146         virtual int ncols() const { return 1; }
147         ///
148         virtual int nrows() const { return 1; }
149         ///
150         virtual int col(int) const { return 0; }
151         ///
152         virtual int row(int) const { return 0; }
153         ///
154         virtual void addRow(int) {}
155         ///
156         virtual void delRow(int) {}
157         ///
158         virtual void addCol(int) {}
159         ///
160         virtual void delCol(int) {}
161
162         ///
163         virtual void UserSetSize(MathStyles &) {}
164
165         ///
166         void GetXY(int & x, int & y) const;
167         ///
168         bool covers(int x, int y) const;
169         /// Identifies ScriptInsets
170         virtual bool isScriptInset() const { return false; }
171         ///
172         virtual bool isActive() const { return nargs() > 0; }
173
174
175         ///
176         void push_back(MathInset *);
177         ///
178         void push_back(byte ch, MathTextCodes fcode);
179         ///
180         void dump() const;
181
182         ///
183         ///
184         static int workwidth;
185 protected:
186         ///
187         string name_;
188         ///
189         MathInsetTypes objtype;
190         ///
191         int width_;
192         ///
193         int ascent_;
194         ///
195         int descent_;
196         ///
197         void size(MathStyles s);
198         ///
199         MathStyles size_;
200
201 protected:
202         ///
203         typedef std::vector<MathXArray> cells_type;
204         /**
205          * The contents of the inset are contained here.
206          * Each inset is build from a number of insets.
207          * For instance, a
208          */
209         cells_type cells_;
210
211 private:
212         /// Cursor start position in pixels from the document top
213         int xo_;
214         ///
215         int yo_;
216 };
217
218 std::ostream & operator<<(std::ostream &, MathInset const &);
219
220 #endif