]> git.lyx.org Git - lyx.git/blob - src/mathed/math_decorationinset.C
6e38a1cca17645e697fa4d9d5e7a9b989629cb75
[lyx.git] / src / mathed / math_decorationinset.C
1 #include <config.h>
2
3 #include "math_decorationinset.h"
4 #include "math_iter.h"
5 #include "mathed/support.h"
6 #include "math_parser.h"
7
8
9 bool MathDecorationInset::GetLimits() const
10
11         return deco == LM_underbrace || deco == LM_overbrace;
12 }    
13
14
15 MathDecorationInset::MathDecorationInset(int d, short st)
16         : MathParInset(st, "", LM_OT_DECO), deco(d)
17 {
18    upper = (deco!= LM_underline && deco!= LM_underbrace);
19 }
20
21
22 MathedInset * MathDecorationInset::Clone()
23 {   
24    MathDecorationInset * p = new MathDecorationInset(deco, GetStyle());
25    MathedIter it(array);
26    p->SetData(it.Copy());
27    return p;
28 }
29
30
31 void
32 MathDecorationInset::draw(Painter & pain, int x, int y)
33
34         MathParInset::draw(pain, x + (width - dw) / 2, y);
35         mathed_draw_deco(pain, x, y + dy, width, dh, deco);
36 }
37
38
39 void
40 MathDecorationInset::Metrics()
41 {
42         int h = 2*mathed_char_height(LM_TC_VAR, size, 'I', ascent, descent);  
43         MathParInset::Metrics();
44         int w = Width()+4;
45         if (w<16) w = 16;
46         dh = w/5;
47         if (dh>h) dh = h;
48         
49         if (upper) {
50                 ascent += dh+2;
51                 dy = -ascent;
52         } else {
53                 dy = descent+2;
54                 descent += dh+4;
55         }
56         dw = width;
57         width = w;
58 }
59
60
61 void MathDecorationInset::Write(ostream & os, bool fragile)
62 {
63         latexkeys * l = lm_get_key_by_id(deco, LM_TK_WIDE);
64         if (fragile &&
65             (strcmp(l->name, "overbrace") == 0 ||
66              strcmp(l->name, "underbrace") == 0 ||
67              strcmp(l->name, "overleftarrow") == 0 ||
68              strcmp(l->name, "overrightarrow") == 0))
69                 os << "\\protect";
70         os << '\\' << l->name << '{';
71         MathParInset::Write(os, fragile);  
72         os << '}';
73 }