]> git.lyx.org Git - lyx.git/blob - src/mathed/math_decorationinset.C
db3c44bc1931783d67afc86568424637418ca941
[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 MathDecorationInset::MathDecorationInset(int d, short st)
13         : MathParInset(st, "", LM_OT_DECO), deco_(d)
14 {
15         upper_ = (deco_ != LM_underline && deco_ != LM_underbrace);
16 }
17
18
19 bool MathDecorationInset::GetLimits() const
20
21         return deco_ == LM_underbrace || deco_ == LM_overbrace;
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 const * 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 }