]> git.lyx.org Git - lyx.git/blob - src/mathed/math_decorationinset.C
move around stuff, remove unneeded declarations etc
[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
21 #include "debug.h"
22
23 #include "support/std_ostream.h"
24
25 using std::auto_ptr;
26
27
28 MathDecorationInset::MathDecorationInset(latexkeys const * key)
29         : MathNestInset(1), key_(key)
30 {
31 //      lyxerr << " creating deco " << key->name << std::endl;
32 }
33
34
35 auto_ptr<InsetBase> MathDecorationInset::clone() const
36 {
37         return auto_ptr<InsetBase>(new MathDecorationInset(*this));
38 }
39
40
41 bool MathDecorationInset::upper() const
42 {
43         return key_->name.substr(0, 5) != "under";
44 }
45
46
47 bool MathDecorationInset::isScriptable() const
48 {
49         return
50                         key_->name == "overbrace" ||
51                         key_->name == "underbrace" ||
52                         key_->name == "overleftarrow" ||
53                         key_->name == "overrightarrow" ||
54                         key_->name == "overleftrightarrow" ||
55                         key_->name == "underleftarrow" ||
56                         key_->name == "underrightarrow" ||
57                         key_->name == "underleftrightarrow";
58 }
59
60
61 bool MathDecorationInset::protect() const
62 {
63         return
64                         key_->name == "overbrace" ||
65                         key_->name == "underbrace" ||
66                         key_->name == "overleftarrow" ||
67                         key_->name == "overrightarrow" ||
68                         key_->name == "overleftrightarrow" ||
69                         key_->name == "underleftarrow" ||
70                         key_->name == "underrightarrow" ||
71                         key_->name == "underleftrightarrow";
72 }
73
74
75 bool MathDecorationInset::wide() const
76 {
77         return
78                         key_->name == "overline" ||
79                         key_->name == "underline" ||
80                         key_->name == "overbrace" ||
81                         key_->name == "underbrace" ||
82                         key_->name == "overleftarrow" ||
83                         key_->name == "overrightarrow" ||
84                         key_->name == "overleftrightarrow" ||
85                         key_->name == "widehat" ||
86                         key_->name == "widetilde" ||
87                         key_->name == "underleftarrow" ||
88                         key_->name == "underrightarrow" ||
89                         key_->name == "underleftrightarrow";
90 }
91
92
93 void MathDecorationInset::metrics(MetricsInfo & mi, Dimension & dim) const
94 {
95         cell(0).metrics(mi, dim);
96
97         dh_  = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
98         dw_  = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
99
100         if (upper()) {
101                 dy_ = -dim.asc - dh_;
102                 dim.asc += dh_ + 1;
103         } else {
104                 dy_ = dim.des + 1;
105                 dim.des += dh_ + 2;
106         }
107
108         metricsMarkers(dim);
109         dim_ = dim;
110 }
111
112
113 void MathDecorationInset::draw(PainterInfo & pi, int x, int y) const
114 {
115         cell(0).draw(pi, x + 1, y);
116         if (wide())
117                 mathed_draw_deco(pi, x + 1, y + dy_, cell(0).width(), dh_, key_->name);
118         else
119                 mathed_draw_deco(pi, x + 1 + (cell(0).width() - dw_) / 2,
120                         y + dy_, dw_, dh_, key_->name);
121         drawMarkers(pi, x, y);
122 }
123
124
125 void MathDecorationInset::write(WriteStream & os) const
126 {
127         if (os.fragile() && protect())
128                 os << "\\protect";
129         os << '\\' << key_->name << '{' << cell(0) << '}';
130 }
131
132
133 void MathDecorationInset::normalize(NormalStream & os) const
134 {
135         os << "[deco " << key_->name << ' ' <<  cell(0) << ']';
136 }
137
138
139 void MathDecorationInset::infoize(std::ostream & os) const
140 {
141         os << "Deco: " << key_->name;
142 }