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