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