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