]> git.lyx.org Git - lyx.git/blob - src/mathed/math_decorationinset.C
split LyXText::rowlist_ into individual Paragraph::rows_ chunks
[lyx.git] / src / mathed / math_decorationinset.C
1 #include <config.h>
2
3
4 #include "math_decorationinset.h"
5 #include "math_support.h"
6 #include "math_parser.h"
7 #include "math_mathmlstream.h"
8 #include "math_streamstr.h"
9 #include "support/LOstream.h"
10
11 using std::auto_ptr;
12
13
14 MathDecorationInset::MathDecorationInset(latexkeys const * key)
15         : MathNestInset(1), key_(key)
16 {}
17
18
19 auto_ptr<InsetBase> MathDecorationInset::clone() const
20 {
21         return auto_ptr<InsetBase>(new MathDecorationInset(*this));
22 }
23
24
25 bool MathDecorationInset::upper() const
26 {
27         return key_->name.substr(0, 5) != "under";
28 }
29
30
31 bool MathDecorationInset::isScriptable() const
32 {
33         return
34                         key_->name == "overbrace" ||
35                         key_->name == "underbrace" ||
36                         key_->name == "overleftarrow" ||
37                         key_->name == "overrightarrow" ||
38                         key_->name == "overleftrightarrow" ||
39                         key_->name == "underleftarrow" ||
40                         key_->name == "underrightarrow" ||
41                         key_->name == "underleftrightarrow";
42 }
43
44
45 bool MathDecorationInset::protect() const
46 {
47         return
48                         key_->name == "overbrace" ||
49                         key_->name == "underbrace" ||
50                         key_->name == "overleftarrow" ||
51                         key_->name == "overrightarrow" ||
52                         key_->name == "overleftrightarrow" ||
53                         key_->name == "underleftarrow" ||
54                         key_->name == "underrightarrow" ||
55                         key_->name == "underleftrightarrow";
56 }
57
58
59 bool MathDecorationInset::wide() const
60 {
61         return
62                         key_->name == "overline" ||
63                         key_->name == "underline" ||
64                         key_->name == "overbrace" ||
65                         key_->name == "underbrace" ||
66                         key_->name == "overleftarrow" ||
67                         key_->name == "overrightarrow" ||
68                         key_->name == "overleftrightarrow" ||
69                         key_->name == "widehat" ||
70                         key_->name == "widetilde" ||
71                         key_->name == "underleftarrow" ||
72                         key_->name == "underrightarrow" ||
73                         key_->name == "underleftrightarrow";
74 }
75
76
77 void MathDecorationInset::metrics(MetricsInfo & mi, Dimension & dim) const
78 {
79         cell(0).metrics(mi);
80         dim_ = cell(0).dim();
81
82         dh_  = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
83         dw_  = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
84
85         if (upper()) {
86                 dy_ = -dim_.asc - dh_;
87                 dim_.asc += dh_ + 1;
88         } else {
89                 dy_ = dim_.des + 1;
90                 dim_.des += dh_ + 2;
91         }
92
93         metricsMarkers();
94         dim = dim_;
95 }
96
97
98 void MathDecorationInset::draw(PainterInfo & pi, int x, int y) const
99 {
100         cell(0).draw(pi, x + 1, y);
101         if (wide())
102                 mathed_draw_deco(pi, x + 1, y + dy_, cell(0).width(), dh_, key_->name);
103         else
104                 mathed_draw_deco(pi, x + 1 + (pi.width - dw_) / 2,
105                         y + dy_, dw_, dh_, key_->name);
106         drawMarkers(pi, x, y);
107 }
108
109
110 void MathDecorationInset::write(WriteStream & os) const
111 {
112         if (os.fragile() && protect())
113                 os << "\\protect";
114         os << '\\' << key_->name << '{' << cell(0) << '}';
115 }
116
117
118 void MathDecorationInset::normalize(NormalStream & os) const
119 {
120         os << "[deco " << key_->name << ' ' <<  cell(0) << ']';
121 }
122
123
124 void MathDecorationInset::infoize(std::ostream & os) const
125 {
126         os << "Deco: " << key_->name;
127 }