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