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