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