]> git.lyx.org Git - lyx.git/blob - src/mathed/math_inset.h
some using changes small changes in lyxfont and some other things, read the Changelog
[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, Mathed & 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 Mathed and are not derived
20 //        from lyx inset.
21
22 #ifndef MATH_INSET
23 #define MATH_INSET
24
25 #ifdef __GNUG__
26 #pragma interface
27 #endif
28
29 #include "math_defs.h"
30 #include "symbol_def.h"
31 #include "LString.h"
32
33 using std::ostream;
34
35 /**
36  Functions or LaTeX names for objects that I don't know how to draw.
37  */
38 class MathFuncInset: public MathedInset  {
39 public:
40         ///
41         MathFuncInset(char const * nm,
42                       short ot = LM_OT_FUNC, short st = LM_ST_TEXT);
43         ///
44         ~MathFuncInset();
45         ///
46         MathedInset * Clone();
47         ///
48         void draw(Painter &, int, int);
49         ///
50         void Write(ostream &);
51         ///
52         void Metrics();
53         ///
54         inline bool GetLimits() const;
55 protected:
56         ///
57         int ln;
58         ///
59         bool lims;
60         ///
61         char * fname;
62 };
63
64
65 /// Accents
66 class MathAccentInset: public MathedInset {
67 public:
68         ///
69         MathAccentInset(byte, MathedTextCodes, int, short st = LM_ST_TEXT);
70         ///
71         MathAccentInset(MathedInset *, int, short st = LM_ST_TEXT);
72         ///
73         ~MathAccentInset();
74         ///
75         MathedInset * Clone();
76         ///
77         void draw(Painter &, int, int);
78         ///
79         void Write(ostream &);
80         ///
81         void Metrics();
82         ///
83         int getAccentCode() const { return code; }
84         
85 protected:
86         ///
87         byte c;
88         ///
89         MathedTextCodes fn;
90         ///
91         int code;
92         ///
93         MathedInset * inset;
94         ///
95         int dh, dy;
96 };
97
98
99 ///
100 class MathDotsInset: public MathedInset {
101 public:
102         ///
103         MathDotsInset(char const *, int, short st = LM_ST_TEXT);
104         ///
105         MathedInset * Clone();
106         ///
107         void draw(Painter &, int, int);
108         ///
109         void Write(ostream &);
110         ///
111         void Metrics();
112 protected:
113         ///
114         int dh, code;
115 };   
116
117
118 /// Smart spaces
119 class MathSpaceInset: public MathedInset  {
120 public:
121         ///
122         MathSpaceInset(int sp, short ot = LM_OT_SPACE, short st = LM_ST_TEXT);
123         ///
124         MathedInset * Clone();
125         ///
126         void draw(Painter &, int, int);
127         ///
128         void Write(ostream &);
129         ///
130         inline void Metrics();
131         ///
132         inline void SetSpace(int sp);
133         ///
134         int GetSpace() { return space; }
135 protected:
136         ///
137         int space;
138 };
139
140
141 /// big operators
142 class MathBigopInset: public MathedInset {
143 public:
144         ///
145         MathBigopInset(char const *, int, short st = LM_ST_TEXT);
146         ///
147         MathedInset * Clone();
148         ///
149         void draw(Painter &, int, int);
150         ///
151         void Write(ostream &);
152         ///
153         void Metrics();
154         ///
155         inline bool GetLimits() const;
156         ///
157         inline void SetLimits(bool);
158 protected:
159         ///
160         int lims;
161         ///
162         int sym;   
163 };
164
165  
166 //------- All editable insets must be derived from MathParInset.
167
168 ///
169 class MathSqrtInset: public MathParInset {
170 public:
171         ///
172         MathSqrtInset(short st = LM_ST_TEXT);
173         ///
174         MathedInset * Clone();
175         ///
176         void draw(Painter &, int x, int baseline);
177         ///
178         void Write(ostream &);
179         ///
180         void Metrics();
181         ///
182         bool Inside(int, int);
183 private:
184         ///
185         int hmax, wbody;
186 };
187
188
189 /// Fraction like objects (frac, stackrel, binom) 
190 class MathFracInset: public MathParInset {
191 public:
192         ///
193         MathFracInset(short ot = LM_OT_FRAC);
194         ///
195         ~MathFracInset();
196         ///
197         MathedInset * Clone();
198         ///
199         void draw(Painter &, int x, int baseline);
200         ///
201         void Write(ostream &);
202         ///
203         void Metrics();
204         
205         /** This does the same that SetData(LyxArrayBase*) but for both
206             numerator and denominator at once.
207         */
208         void SetData(LyxArrayBase *, LyxArrayBase *);
209         ///
210         void SetData(LyxArrayBase *);
211         ///
212         void GetXY(int & x, int & y) const;
213         ///
214         void SetFocus(int, int);
215         ///
216         bool Inside(int, int);
217         ///
218         LyxArrayBase * GetData();
219         ///
220         bool setArgumentIdx(int i); // was bool Up/down(void);
221         ///
222         int  getArgumentIdx() { return int(idx); }
223         ///
224         int  getMaxArgumentIdx() { return 1; }
225         ///
226         void  SetStyle(short);
227 protected:
228         ///
229         short idx;
230         ///
231         MathParInset * den;
232         ///
233         int w0, w1, des0, dh;
234 };
235
236
237 /// A delimiter
238 class MathDelimInset: public MathParInset {
239 public:
240         ///
241         MathDelimInset(int, int, short st = LM_ST_TEXT);
242         ///
243         MathedInset * Clone();
244         ///
245         void draw(Painter &, int, int);
246         ///
247         void Write(ostream &);
248         ///
249         void Metrics();
250 protected:
251         ///
252         int left, right;
253         ///
254         int dw, dh;
255 };
256
257
258 /// Decorations over (below) a math object
259 class MathDecorationInset: public MathParInset {
260 public:
261         ///
262         MathDecorationInset(int, short st = LM_ST_TEXT);
263         ///
264         MathedInset * Clone();
265         ///
266         void draw(Painter &, int, int);
267         ///
268         void Write(ostream &);
269         ///
270         void Metrics();
271         ///
272         inline bool GetLimits() const;
273 protected:
274         ///
275         int deco;
276         ///
277         bool upper;
278         ///
279         int dw, dh, dy;
280 };
281
282
283 // --------------------  Inline functions ---------------------
284
285  
286 inline
287 MathFuncInset::~MathFuncInset()
288 {
289     if (fname && GetType() == LM_OT_UNDEF) delete[] fname;
290 }
291
292
293 inline
294 bool MathFuncInset::GetLimits() const 
295 {  
296    return bool(lims && (GetStyle() == LM_ST_DISPLAY)); 
297
298
299
300 inline
301 void MathFuncInset::Write(ostream & os)
302 {
303         os << "\\" << name << ' ';
304 }
305
306
307 inline
308 void MathSpaceInset::Metrics()
309 {
310    width = space ? space * 2 : 2;
311    if (space > 3) width *= 2;
312    if (space == 5) width *= 2;
313    width += 4;
314    ascent = 4; descent = 0;
315 }
316
317
318 inline
319 void MathSpaceInset::SetSpace(int sp)
320
321    space = sp;
322    Metrics();
323 }    
324
325
326 inline
327 bool MathBigopInset::GetLimits() const 
328 {  
329     // Default case
330     if (lims < 0) {
331         return sym != LM_int && sym != LM_oint && GetStyle() == LM_ST_DISPLAY;
332     } 
333     
334     // Custom 
335     return lims > 0;
336
337
338
339 inline
340 void MathBigopInset::SetLimits(bool ls) 
341 {  
342     lims = ls ? 1 : 0; 
343
344
345
346 inline
347 bool MathDecorationInset::GetLimits() const
348
349    return deco == LM_underbrace || deco == LM_overbrace;
350 }    
351
352 #endif