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