]> git.lyx.org Git - lyx.git/blob - src/mathed/math_decorationinset.C
\hat & subscript
[lyx.git] / src / mathed / math_decorationinset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_decorationinset.h"
6 #include "mathed/support.h"
7 #include "math_parser.h"
8 #include "support/LOstream.h"
9
10
11 using std::ostream;
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_ != "underline" && name_ != "underbrace";
28 }
29
30
31 bool MathDecorationInset::isScriptable() const
32 {
33         return
34                         name_ == "overbrace" ||
35                         name_ == "underbrace" ||
36                         name_ == "overleftarrow" ||
37                         name_ == "overrightarrow";
38 }
39
40
41 bool MathDecorationInset::protect() const
42 {
43         return
44                         name_ == "overbrace" ||
45                         name_ == "underbrace" ||
46                         name_ == "overleftarrow" ||
47                         name_ == "overrightarrow";
48 }
49
50
51 void MathDecorationInset::metrics(MathStyles st) const
52 {
53         xcell(0).metrics(st);
54         size_    = st;
55         width_   = xcell(0).width();
56         ascent_  = xcell(0).ascent();
57         descent_ = xcell(0).descent();
58
59         dh_ = 5; //mathed_char_height(LM_TC_VAR, size(), 'I', ascent_, descent_);  
60
61         if (upper()) {
62                 dy_ = -ascent_ - dh_;
63                 ascent_ += dh_ + 1;
64         } else {
65                 dy_ = descent_ + 1;
66                 descent_ += dh_ + 2;
67         }
68 }
69
70
71 void MathDecorationInset::draw(Painter & pain, int x, int y) const
72
73         xo(x);
74         yo(x);
75         xcell(0).draw(pain, x, y);
76         mathed_draw_deco(pain, x, y + dy_, width_, dh_, name_);
77 }
78
79
80 void MathDecorationInset::write(ostream & os, bool fragile) const
81 {
82         if (fragile && protect())
83                 os << "\\protect";
84         os << '\\' << name_ << '{';
85         cell(0).write(os, fragile);  
86         os << '}';
87 }
88
89
90 void MathDecorationInset::writeNormal(ostream & os) const
91 {
92         os << "[" << name_ << " ";
93         cell(0).writeNormal(os);
94         os << "] ";
95 }