]> git.lyx.org Git - lyx.git/blob - src/mathed/math_decorationinset.C
nest step...
[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(latexkeys const * key)
15         : MathInset(1), key_(key)
16 {
17         upper_ = key_->id != LM_underline && key_->id != LM_underbrace;
18 }
19
20
21 MathInset * MathDecorationInset::clone() const
22 {   
23         return new MathDecorationInset(*this);
24 }
25
26
27
28 void MathDecorationInset::metrics(MathStyles st)
29 {
30         xcell(0).metrics(st);
31         size_    = st;
32         width_   = xcell(0).width();
33         ascent_  = xcell(0).ascent();
34         descent_ = xcell(0).descent();
35
36         dh_ = 5; //mathed_char_height(LM_TC_VAR, size(), 'I', ascent_, descent_);  
37
38         if (upper_) {
39                 dy_ = -ascent_ - dh_;
40                 ascent_ += dh_ + 1;
41         } else {
42                 dy_ = descent_ + 1;
43                 descent_ += dh_ + 2;
44         }
45
46         if (key_->id == LM_not) {
47                 ascent_  += dh_;
48                 descent_ += dh_;
49                 dh_ = height();
50                 dy_ = - ascent_;
51         }
52 }
53
54 void MathDecorationInset::draw(Painter & pain, int x, int y)
55
56         xo(x);
57         yo(x);
58         xcell(0).draw(pain, x, y);
59         mathed_draw_deco(pain, x, y + dy_, width_, dh_, key_->id);
60 }
61
62
63 void MathDecorationInset::write(ostream & os, bool fragile) const
64 {
65         string name = key_->name;
66         if (fragile &&
67                         (name == "overbrace" ||
68                          name == "underbrace" ||
69                          name == "overleftarrow" ||
70                          name == "overrightarrow"))
71                 os << "\\protect";
72         os << '\\' << name;
73
74         if (key_->id == LM_not)
75                 os << ' ';
76         else
77                 os << '{';
78
79         cell(0).write(os, fragile);  
80
81         if (key_->id != LM_not)
82                 os << '}';
83 }
84
85 void MathDecorationInset::writeNormal(ostream & os) const
86 {
87         os << "[" << key_->name << " ";
88         cell(0).writeNormal(os);
89         os << "] ";
90 }