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