]> git.lyx.org Git - lyx.git/blob - src/mathed/math_inset.h
Andre's mathinset shrink patch ; default .lyx extension when loading files
[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 "LString.h"
32 #include "symbol_def.h"
33 #include "xarray.h"
34
35 /** Abstract base class for all math objects.
36     A math insets is for use of the math editor only, it isn't a
37     general LyX inset. It's used to represent all the math objects.
38     The formulaInset (a LyX inset) encapsulates a math inset.
39 */
40
41
42 class LaTeXFeatures;
43
44 class MathInset {
45 public: 
46         ///
47         explicit MathInset(int na = 0, string const & nm = string());
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 baseline) = 0;  
54         /// write LaTeX and Lyx code
55         virtual void write(std::ostream &, bool fragile) const = 0;
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) = 0;
64         /// 
65         virtual int ascent() const;
66         ///
67         virtual int descent() const;
68         ///
69         virtual int width() const;
70         ///
71         virtual int height() const;
72         ///
73         virtual int limits() const;
74         ///
75         virtual void limits(int);
76         ///
77         string const & name() const;
78         ///
79         virtual void setName(string const & n);
80         ///
81         MathStyles size() const;
82
83         /// Where should we go when we press the up cursor key?
84         virtual bool idxUp(int & idx, int & pos) const;
85         /// The down key
86         virtual bool idxDown(int & idx, int & pos) const;
87         /// The left key
88         virtual bool idxLeft(int & idx, int & pos) const;
89         /// The right key
90         virtual bool idxRight(int & idx, int & pos) const;
91
92         /// Move one physical cell up
93         virtual bool idxNext(int & idx, int & pos) const;
94         /// Move one physical cell down
95         virtual bool idxPrev(int & idx, int & pos) const;
96
97         /// Target pos when we enter the inset from the left by pressing "Right"
98         virtual bool idxFirst(int & idx, int & pos) const;
99         /// Target pos when we enter the inset from the left by pressing "Up"
100         virtual bool idxFirstUp(int & idx, int & pos) const;
101         /// Target pos when we enter the inset from the left by pressing "Down"
102         virtual bool idxFirstDown(int & idx, int & pos) const;
103
104         /// Target pos when we enter the inset from the right by pressing "Left"
105         virtual bool idxLast(int & idx, int & pos) const;
106         /// Target pos when we enter the inset from the right by pressing "Up"
107         virtual bool idxLastUp(int & idx, int & pos) const;
108         /// Target pos when we enter the inset from the right by pressing "Down"
109         virtual bool idxLastDown(int & idx, int & pos) const;
110
111         /// Where should we go if we press home?
112         virtual bool idxHome(int & idx, int & pos) const;
113         /// Where should we go if we press end?
114         virtual bool idxEnd(int & idx, int & pos) const;
115
116         /// Delete a cell and move cursor
117         // the return value indicates whether the cursor should leave the inset
118         // and/or the whole inset should be deleted
119         virtual void idxDelete(int & idx, bool & popit, bool & deleteit);
120         // deletes a cell range and moves the cursor 
121         virtual void idxDeleteRange(int from, int to);
122         // returns list of cell indices that are "between" from and to for
123         // selction purposes
124         virtual std::vector<int> idxBetween(int from, int to) const;
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         ///
139         int xo() const;
140         ///
141         int yo() const;
142         ///
143         void xo(int tx);
144         ///
145         void yo(int ty);
146         ///
147
148         ///
149         virtual int ncols() const { return 1; }
150         ///
151         virtual int nrows() const { return 1; }
152         ///
153         virtual int col(int) const { return 0; }
154         ///
155         virtual int row(int) const { return 0; }
156         ///
157         virtual void addRow(int) {}
158         ///
159         virtual void delRow(int) {}
160         ///
161         virtual void addCol(int) {}
162         ///
163         virtual void delCol(int) {}
164
165         ///
166         virtual void userSetSize(MathStyles &) {}
167
168         ///
169         void getXY(int & x, int & y) const;
170         ///
171         bool covers(int x, int y) const;
172         /// identifies things that can get scripts
173         virtual bool isScriptable() const { return false; }
174         /// identifies ScriptInsets
175         virtual bool isScriptInset() const { return false; }
176         /// identifies SpaceInsets
177         virtual bool isSpaceInset() const { return false; }
178         /// identifies GridInsets
179         virtual bool isGrid() const { return false; }
180         /// identifies ArrayInsets
181         virtual bool isArray() const { return false; }
182         ///
183         virtual bool isActive() const { return nargs() > 0; }
184
185
186         ///
187         void push_back(MathInset *);
188         ///
189         void push_back(unsigned char ch, MathTextCodes fcode);
190         ///
191         void dump() const;
192
193         ///
194         void validate(LaTeXFeatures & features) const;
195
196         ///
197         static int workwidth;
198 protected:
199         /// usually the LaTeX name of the thingy
200         string name_;
201         /// the width of this inset as computed by metrics()
202         int width_;
203         /// 
204         int ascent_;
205         ///
206         int descent_;
207         /// 
208         void size(MathStyles s);
209         /// the used font size
210         MathStyles size_;
211
212 protected:
213         ///
214         typedef std::vector<MathXArray> cells_type;
215         /**
216          * The contents of the inset are contained here.
217          * Each inset is build from a number of insets.
218          */
219         cells_type cells_;
220
221 private:
222         /// the following are used for positioning the cursor with the mouse
223         /// cached cursor start position in pixels from the document left
224         int xo_;
225         /// cached cursor start position in pixels from the document top
226         int yo_;
227 };
228
229 std::ostream & operator<<(std::ostream &, MathInset const &);
230
231 #endif