]> git.lyx.org Git - lyx.git/blob - src/mathed/math_decorationinset.C
get rid of several friends small cleanup
[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',
46                                        ascent, descent);  
47         MathParInset::Metrics();
48         int w = Width() + 4;
49         if (w < 16) w = 16;
50         dh = w / 5;
51         if (dh > h) dh = h;
52         
53         if (upper) {
54                 ascent += dh + 2;
55                 dy = -ascent;
56         } else {
57                 dy = descent + 2;
58                 descent += dh + 4;
59         }
60         dw = width;
61         width = w;
62 }
63
64
65 void MathDecorationInset::Write(ostream & os, bool fragile)
66 {
67         latexkeys * l = lm_get_key_by_id(deco, LM_TK_WIDE);
68         if (fragile &&
69             (strcmp(l->name, "overbrace") == 0 ||
70              strcmp(l->name, "underbrace") == 0 ||
71              strcmp(l->name, "overleftarrow") == 0 ||
72              strcmp(l->name, "overrightarrow") == 0))
73                 os << "\\protect";
74         os << '\\' << l->name << '{';
75         MathParInset::Write(os, fragile);  
76         os << '}';
77 }