]> git.lyx.org Git - lyx.git/blob - src/mathed/math_decorationinset.C
adjust to be able to complile with gcc 3.0, put selection vars into own struct, remov...
[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 #include "support/lstrings.h"
13
14
15 using std::ostream;
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 bool MathDecorationInset::GetLimits() const
26
27         return deco_ == LM_underbrace || deco_ == LM_overbrace;
28 }    
29
30
31 MathedInset * MathDecorationInset::Clone()
32 {   
33         return new MathDecorationInset(*this);
34 }
35
36
37 void
38 MathDecorationInset::draw(Painter & pain, int x, int y)
39
40         MathParInset::draw(pain, x + (width - dw_) / 2, y);
41         mathed_draw_deco(pain, x, y + dy_, width, dh_, deco_);
42 }
43
44
45 void
46 MathDecorationInset::Metrics()
47 {
48         int const h = 2 * mathed_char_height(LM_TC_VAR, size(), 'I',
49                                              ascent, descent);  
50         MathParInset::Metrics();
51         int w = Width() + 4;
52         if (w < 16) w = 16;
53         dh_ = w / 5;
54         if (dh_ > h) dh_ = h;
55         
56         if (upper_) {
57                 ascent += dh_ + 2;
58                 dy_ = -ascent;
59         } else {
60                 dy_ = descent + 2;
61                 descent += dh_ + 4;
62         }
63         dw_ = width;
64         width = w;
65 }
66
67
68 void MathDecorationInset::Write(ostream & os, bool fragile)
69 {
70         latexkeys const * l = lm_get_key_by_id(deco_, LM_TK_WIDE);
71         if (fragile &&
72             (compare(l->name, "overbrace") == 0 ||
73              compare(l->name, "underbrace") == 0 ||
74              compare(l->name, "overleftarrow") == 0 ||
75              compare(l->name, "overrightarrow") == 0))
76                 os << "\\protect";
77         os << '\\' << l->name << '{';
78         MathParInset::Write(os, fragile);  
79         os << '}';
80 }