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