]> git.lyx.org Git - lyx.git/blob - src/mathed/math_decorationinset.C
change a lot of methods to begin with small char
[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 "mathed/support.h"
9 #include "math_parser.h"
10 #include "support/LOstream.h"
11 #include "support/lstrings.h"
12
13
14 using std::ostream;
15
16
17 MathDecorationInset::MathDecorationInset(int d)
18         : MathInset("", LM_OT_DECO, 1), deco_(d)
19 {
20         upper_ = deco_ != LM_underline && deco_ != LM_underbrace;
21 }
22
23
24 bool MathDecorationInset::GetLimits() const
25
26         return deco_ == LM_underbrace || deco_ == LM_overbrace;
27 }    
28
29
30 MathInset * MathDecorationInset::clone() const
31 {   
32         return new MathDecorationInset(*this);
33 }
34
35
36 void MathDecorationInset::draw(Painter & pain, int x, int y)
37
38         xcell(0).draw(pain, x, y);
39         mathed_draw_deco(pain, x, y + 10, width_, 10, deco_);
40 }
41
42
43 void MathDecorationInset::Metrics(MathStyles st)
44 {
45         int const h = 2 * mathed_char_height(LM_TC_VAR, size(), 'I',
46                                              ascent_, descent_);  
47         xcell(0).Metrics(st);
48         width_   = xcell(0).width();
49         ascent_  = xcell(0).ascent();
50         descent_ = xcell(0).descent();
51
52         int w = width() + 4;
53         if (w < 16)
54                 w = 16;
55
56         int dh_ = w / 5;
57         if (dh_ > h)
58                 dh_ = h;
59
60         int dy_;        
61         if (upper_) {
62                 ascent_ += dh_ + 2;
63                 dy_ = -ascent_;
64         } else {
65                 dy_ = descent_ + 2;
66                 descent_ += dh_ + 4;
67         }
68         width_ = w;
69 }
70
71
72 void MathDecorationInset::Write(ostream & os, bool fragile) const
73 {
74         latexkeys const * l = lm_get_key_by_id(deco_, LM_TK_WIDE);
75         if (fragile &&
76             (compare(l->name, "overbrace") == 0 ||
77              compare(l->name, "underbrace") == 0 ||
78              compare(l->name, "overleftarrow") == 0 ||
79              compare(l->name, "overrightarrow") == 0))
80                 os << "\\protect";
81         os << '\\' << l->name << '{';
82         cell(0).Write(os, fragile);  
83         os << '}';
84 }