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