]> git.lyx.org Git - lyx.git/blob - src/mathed/math_decorationinset.C
fix typo that put too many include paths for most people
[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_support.h"
9 #include "math_parser.h"
10 #include "math_mathmlstream.h"
11 #include "math_streamstr.h"
12
13
14 MathDecorationInset::MathDecorationInset(string const & name)
15         : MathNestInset(1), name_(name)
16 {}
17
18
19 MathInset * MathDecorationInset::clone() const
20 {
21         return new MathDecorationInset(*this);
22 }
23
24
25 bool MathDecorationInset::upper() const
26 {
27         return name_.substr(0, 5) != "under";
28 }
29
30
31 bool MathDecorationInset::isScriptable() const
32 {
33         return
34                         name_ == "overbrace" ||
35                         name_ == "underbrace" ||
36                         name_ == "overleftarrow" ||
37                         name_ == "overrightarrow" ||
38                         name_ == "overleftrightarrow" ||
39                         name_ == "underleftarrow" ||
40                         name_ == "underrightarrow" ||
41                         name_ == "underleftrightarrow";
42 }
43
44
45 bool MathDecorationInset::protect() const
46 {
47         return
48                         name_ == "overbrace" ||
49                         name_ == "underbrace" ||
50                         name_ == "overleftarrow" ||
51                         name_ == "overrightarrow" ||
52                         name_ == "overleftrightarrow" ||
53                         name_ == "underleftarrow" ||
54                         name_ == "underrightarrow" ||
55                         name_ == "underleftrightarrow";
56 }
57
58
59 bool MathDecorationInset::wide() const
60 {
61         return
62                         name_ == "overline" ||
63                         name_ == "underline" ||
64                         name_ == "overbrace" ||
65                         name_ == "underbrace" ||
66                         name_ == "overleftarrow" ||
67                         name_ == "overrightarrow" ||
68                         name_ == "overleftrightarrow" ||
69                         name_ == "widehat" ||
70                         name_ == "widetilde" ||
71                         name_ == "underleftarrow" ||
72                         name_ == "underrightarrow" ||
73                         name_ == "underleftrightarrow";
74 }
75
76
77 void MathDecorationInset::metrics(MathMetricsInfo const & mi) const
78 {
79         xcell(0).metrics(mi);
80         width_   = xcell(0).width();
81         ascent_  = xcell(0).ascent();
82         descent_ = xcell(0).descent();
83
84         dh_ = 6; //mathed_char_height(LM_TC_VAR, mi(), 'I', ascent_, descent_);
85         dw_ = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
86
87         if (upper()) {
88                 dy_ = -ascent_ - dh_;
89                 ascent_ += dh_ + 1;
90         } else {
91                 dy_ = descent_ + 1;
92                 descent_ += dh_ + 2;
93         }
94 }
95
96
97 void MathDecorationInset::draw(Painter & pain, int x, int y) const
98 {
99         xcell(0).draw(pain, x, y);
100         if (wide())
101                 mathed_draw_deco(pain, x, y + dy_, width_, dh_, name_);
102         else
103                 mathed_draw_deco(pain, x + (width_ - dw_) / 2, y + dy_, dw_, dh_, name_);
104 }
105
106
107 void MathDecorationInset::write(WriteStream & os) const
108 {
109         if (os.fragile() && protect())
110                 os << "\\protect";
111         os << '\\' << name_ << '{' << cell(0) << '}';
112 }
113
114
115 void MathDecorationInset::normalize(NormalStream & os) const
116 {
117         os << "[deco " << name_ << ' ' <<  cell(0) << ']';
118 }