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