]> git.lyx.org Git - lyx.git/blob - src/mathed/math_decorationinset.C
cosmetics: rename support.[Ch] into math_support.[Ch]
[lyx.git] / src / mathed / math_decorationinset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_decorationinset.h"
6 #include "math_support.h"
7 #include "math_parser.h"
8 #include "math_mathmlstream.h"
9
10
11 MathDecorationInset::MathDecorationInset(string const & name)
12         : MathNestInset(1), name_(name)
13 {}
14
15
16 MathInset * MathDecorationInset::clone() const
17 {   
18         return new MathDecorationInset(*this);
19 }
20
21
22 bool MathDecorationInset::upper() const
23 {
24         return name_ != "underline" && name_ != "underbrace";
25 }
26
27
28 bool MathDecorationInset::isScriptable() const
29 {
30         return
31                         name_ == "overbrace" ||
32                         name_ == "underbrace" ||
33                         name_ == "overleftarrow" ||
34                         name_ == "overrightarrow";
35 }
36
37
38 bool MathDecorationInset::protect() const
39 {
40         return
41                         name_ == "overbrace" ||
42                         name_ == "underbrace" ||
43                         name_ == "overleftarrow" ||
44                         name_ == "overrightarrow";
45 }
46
47
48 bool MathDecorationInset::wide() const
49 {
50         return
51                         name_ == "overline" ||
52                         name_ == "underline" ||
53                         name_ == "overbrace" ||
54                         name_ == "underbrace" ||
55                         name_ == "overleftarrow" ||
56                         name_ == "overrightarrow" ||
57                         name_ == "widehat" ||
58                         name_ == "widetilde";
59 }
60
61
62 void MathDecorationInset::metrics(MathMetricsInfo const & st) const
63 {
64         xcell(0).metrics(st);
65         size_    = st;
66         width_   = xcell(0).width();
67         ascent_  = xcell(0).ascent();
68         descent_ = xcell(0).descent();
69
70         dh_ = 5; //mathed_char_height(LM_TC_VAR, size(), 'I', ascent_, descent_);  
71
72         if (upper()) {
73                 dy_ = -ascent_ - dh_;
74                 ascent_ += dh_ + 1;
75         } else {
76                 dy_ = descent_ + 1;
77                 descent_ += dh_ + 2;
78         }
79 }
80
81
82 void MathDecorationInset::draw(Painter & pain, int x, int y) const
83
84         xcell(0).draw(pain, x, y);
85         if (wide()) 
86                 mathed_draw_deco(pain, x, y + dy_, width_, dh_, name_);
87         else {
88                 int w = 2 + mathed_char_width(LM_TC_VAR, size_, 'x'); 
89                 mathed_draw_deco(pain, x + (width_ - w) / 2, y + dy_, w, dh_, name_);
90         }
91 }
92
93
94 void MathDecorationInset::write(MathWriteInfo & os) const
95 {
96         if (os.fragile && protect())
97                 os << "\\protect";
98         os << '\\' << name_.c_str() << '{' << cell(0) << '}';
99 }
100
101
102 void MathDecorationInset::writeNormal(NormalStream & os) const
103 {
104         os << "[deco " << name_.c_str() << ' ' <<  cell(0) << ']';
105 }