]> git.lyx.org Git - lyx.git/blob - src/mathed/math_decorationinset.C
mathed30.diff
[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         return new MathDecorationInset(*this);
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',
43                                        ascent, descent);  
44         MathParInset::Metrics();
45         int w = Width() + 4;
46         if (w < 16) w = 16;
47         dh_ = w / 5;
48         if (dh_ > h) dh_ = h;
49         
50         if (upper_) {
51                 ascent += dh_ + 2;
52                 dy_ = -ascent;
53         } else {
54                 dy_ = descent + 2;
55                 descent += dh_ + 4;
56         }
57         dw_ = width;
58         width = w;
59 }
60
61
62 void MathDecorationInset::Write(ostream & os, bool fragile)
63 {
64         latexkeys const * l = lm_get_key_by_id(deco_, LM_TK_WIDE);
65         if (fragile &&
66             (strcmp(l->name, "overbrace") == 0 ||
67              strcmp(l->name, "underbrace") == 0 ||
68              strcmp(l->name, "overleftarrow") == 0 ||
69              strcmp(l->name, "overrightarrow") == 0))
70                 os << "\\protect";
71         os << '\\' << l->name << '{';
72         MathParInset::Write(os, fragile);  
73         os << '}';
74 }