]> git.lyx.org Git - lyx.git/blob - src/mathed/math_decorationinset.C
fix pullArg when pressing <Delete> at the end of an cell
[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, int d)
15         : MathInset(1, name), deco_(d)
16 {
17         upper_ = deco_ != LM_underline && deco_ != 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, int, int)
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 (deco_ == 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_, deco_);
60 }
61
62
63 void MathDecorationInset::Write(ostream & os, bool fragile) const
64 {
65         if (fragile &&
66                         (name_ == "overbrace" ||
67                          name_ == "underbrace" ||
68                          name_ == "overleftarrow" ||
69                          name_ == "overrightarrow"))
70                 os << "\\protect";
71         os << '\\' << name_;
72
73         if (deco_ == LM_not)
74                 os << ' ';
75         else
76                 os << '{';
77
78         cell(0).Write(os, fragile);  
79
80         if (deco_ != LM_not)
81                 os << '}';
82 }
83
84 void MathDecorationInset::WriteNormal(ostream & os) const
85 {
86         os << "[" << name_ << " ";
87         cell(0).WriteNormal(os);
88         os << "] ";
89 }