]> git.lyx.org Git - lyx.git/blob - src/mathed/math_inset.h
Even more ugly changes and a new file dependency to shut up Jean-Marc's
[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 "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 LaTeXFeatures;
41 class MathCharInset;
42 class MathScriptInset;
43
44 class MathInset {
45 public: 
46         /// short of anything else reasonable
47         typedef MathArray::size_type     size_type;
48         /// type for cursor positions within a cell
49         typedef MathArray::size_type     pos_type;
50         /// type for cell indices
51         typedef size_type                idx_type;
52         /// type for row numbers
53         typedef size_type                row_type;
54         /// type for column numbers
55         typedef size_type                col_type;
56
57         ///
58         MathInset();
59         /// the virtual base destructor
60         virtual ~MathInset(); 
61
62         /// draw the object, sets xo_ and yo_ cached values 
63         virtual void draw(Painter &, int x, int y) const;
64         /// write LaTeX and Lyx code
65         virtual void write(std::ostream &, bool fragile) const;
66         /// write normalized content
67         virtual void writeNormal(std::ostream &) const;
68         /// reproduce itself
69         virtual MathInset * clone() const = 0;
70         ///substitutes macro arguments if necessary
71         virtual void substitute(MathMacro const & macro);
72         /// compute the size of the object, sets ascend_, descend_ and width_
73         virtual void metrics(MathStyles st) const;
74         /// 
75         virtual int ascent() const { return 1; }
76         ///
77         virtual int descent() const { return 1; }
78         ///
79         virtual int width() const { return 2; }
80         ///
81         virtual int height() const;
82         ///
83         virtual MathStyles size() const;
84
85         /// Where should we go when we press the up cursor key?
86         virtual bool idxUp(idx_type & idx, pos_type & pos) const;
87         /// The down key
88         virtual bool idxDown(idx_type & idx, pos_type & pos) const;
89         /// The left key
90         virtual bool idxLeft(idx_type & idx, pos_type & pos) const;
91         /// The right key
92         virtual bool idxRight(idx_type & idx, pos_type & pos) const;
93
94         /// Move one physical cell up
95         virtual bool idxNext(idx_type & idx, pos_type & pos) const;
96         /// Move one physical cell down
97         virtual bool idxPrev(idx_type & idx, pos_type & pos) const;
98
99         /// Target pos when we enter the inset from the left by pressing "Right"
100         virtual bool idxFirst(idx_type & idx, pos_type & pos) const;
101         /// Target pos when we enter the inset from the right by pressing "Left"
102         virtual bool idxLast(idx_type & idx, pos_type & pos) const;
103
104         /// Where should we go if we press home?
105         virtual bool idxHome(idx_type & idx, pos_type & pos) const;
106         /// Where should we go if we press end?
107         virtual bool idxEnd(idx_type & idx, pos_type & pos) const;
108
109         /// Delete a cell and move cursor
110         // the return value indicates whether the cursor should leave the inset
111         // and/or the whole inset should be deleted
112         virtual void idxDelete(idx_type & idx, bool & popit, bool & deleteit);
113         // deletes a cell range and moves the cursor 
114         virtual void idxDeleteRange(idx_type from, idx_type to);
115         // returns list of cell indices that are "between" from and to for
116         // selection purposes
117         virtual std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
118
119         ///
120         virtual idx_type nargs() const;
121
122         ///
123         virtual MathArray & cell(idx_type);
124         ///
125         virtual MathArray const & cell(idx_type) const;
126         ///
127         virtual MathXArray & xcell(idx_type);
128         ///
129         virtual MathXArray const & xcell(idx_type) const;
130                         
131         ///
132         virtual int xo() const;
133         ///
134         virtual int yo() const;
135         ///
136         virtual void xo(int tx) const;
137         ///
138         virtual void yo(int ty) const;
139         ///
140
141         ///
142         virtual col_type ncols() const { return 1; }
143         ///
144         virtual row_type nrows() const { return 1; }
145         ///
146         virtual col_type col(row_type) const { return 0; }
147         ///
148         virtual row_type row(row_type) const { return 0; }
149         ///
150         virtual int cellXOffset(row_type) const { return 0; }
151         ///
152         virtual int cellYOffset(row_type) const { return 0; }
153         ///
154         virtual void addRow(row_type) {}
155         ///
156         virtual void delRow(row_type) {}
157         ///
158         virtual void addCol(col_type) {}
159         ///
160         virtual void delCol(col_type) {}
161
162         ///
163         virtual void userSetSize(MathStyles &) {}
164
165         ///
166         virtual void getXY(int & x, int & y) const;
167         ///
168         virtual bool covers(int x, int y) const;
169         /// identifies things that can get scripts
170         virtual bool isScriptable() const { return false; }
171         /// identifies ScriptInsets
172         virtual bool isScriptInset() const { return false; }
173         /// identifies SpaceInsets
174         virtual bool isSpaceInset() const { return false; }
175         /// identifies GridInsets
176         virtual bool isGrid() const { return false; }
177         /// identifies ArrayInsets
178         virtual bool isArray() const { return false; }
179         /// identifies CharInsets
180         virtual MathCharInset const * asCharInset() const { return 0; }
181         /// identifies ScriptInsets
182         virtual MathScriptInset const * asScriptInset() const { return 0; }
183         ///
184         virtual bool isActive() const { return nargs() > 0; }
185         ///
186         virtual bool isRelOp() const { return false; }
187         ///
188         virtual bool isMacro() const { return false; }
189         ///
190         virtual char getChar() const { return 0; }
191         ///
192         virtual MathTextCodes code() const { return LM_TC_MIN; }
193         /// identifies things that can get \limits or \nolimits
194         virtual bool takesLimits() const { return false; }
195
196         ///
197         virtual void push_back(MathInset *);
198         ///
199         virtual void push_back(unsigned char c, MathTextCodes code);
200         ///
201         virtual void dump() const;
202
203         ///
204         virtual void validate(LaTeXFeatures & features) const;
205         ///
206         virtual void handleFont(MathTextCodes) {}
207
208         ///
209         static int workwidth;
210
211 protected:
212         /// _sets_ style
213         void size(MathStyles s) const;
214         /// the used font size
215         mutable MathStyles size_;
216
217 private:
218         /// the following are used for positioning the cursor with the mouse
219         /// cached cursor start position in pixels from the document left
220         mutable int xo_;
221         /// cached cursor start position in pixels from the document top
222         mutable int yo_;
223 };
224
225 std::ostream & operator<<(std::ostream &, MathInset const &);
226
227 #endif