]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathDecoration.C
Fix comment according to Enricos explanation
[lyx.git] / src / mathed / InsetMathDecoration.C
1 /**
2  * \file InsetMathDecoration.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 "InsetMathDecoration.h"
15 #include "MathData.h"
16 #include "MathSupport.h"
17 #include "MathParser.h"
18 #include "MathStream.h"
19 #include "MathStream.h"
20
21 #include "LaTeXFeatures.h"
22 #include "debug.h"
23
24 #include "support/std_ostream.h"
25
26
27 namespace lyx {
28
29
30 InsetMathDecoration::InsetMathDecoration(latexkeys const * key)
31         : InsetMathNest(1), key_(key)
32 {
33 //      lyxerr << " creating deco " << key->name << std::endl;
34 }
35
36
37 std::auto_ptr<InsetBase> InsetMathDecoration::doClone() const
38 {
39         return std::auto_ptr<InsetBase>(new InsetMathDecoration(*this));
40 }
41
42
43 bool InsetMathDecoration::upper() const
44 {
45         return key_->name.substr(0, 5) != "under";
46 }
47
48
49 bool InsetMathDecoration::isScriptable() const
50 {
51         return
52                         key_->name == "overbrace" ||
53                         key_->name == "underbrace" ||
54                         key_->name == "overleftarrow" ||
55                         key_->name == "overrightarrow" ||
56                         key_->name == "overleftrightarrow" ||
57                         key_->name == "underleftarrow" ||
58                         key_->name == "underrightarrow" ||
59                         key_->name == "underleftrightarrow";
60 }
61
62
63 bool InsetMathDecoration::protect() const
64 {
65         return
66                         key_->name == "overbrace" ||
67                         key_->name == "underbrace" ||
68                         key_->name == "overleftarrow" ||
69                         key_->name == "overrightarrow" ||
70                         key_->name == "overleftrightarrow" ||
71                         key_->name == "underleftarrow" ||
72                         key_->name == "underrightarrow" ||
73                         key_->name == "underleftrightarrow";
74 }
75
76
77 bool InsetMathDecoration::wide() const
78 {
79         return
80                         key_->name == "overline" ||
81                         key_->name == "underline" ||
82                         key_->name == "overbrace" ||
83                         key_->name == "underbrace" ||
84                         key_->name == "overleftarrow" ||
85                         key_->name == "overrightarrow" ||
86                         key_->name == "overleftrightarrow" ||
87                         key_->name == "widehat" ||
88                         key_->name == "widetilde" ||
89                         key_->name == "underleftarrow" ||
90                         key_->name == "underrightarrow" ||
91                         key_->name == "underleftrightarrow";
92 }
93
94
95 bool InsetMathDecoration::ams() const
96 {
97         return
98                         key_->name == "overleftrightarrow" ||
99                         key_->name == "underleftarrow" ||
100                         key_->name == "underrightarrow" ||
101                         key_->name == "underleftrightarrow";
102 }
103
104
105 void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
106 {
107         cell(0).metrics(mi, dim);
108
109         dh_  = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
110         dw_  = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
111
112         if (upper()) {
113                 dy_ = -dim.asc - dh_;
114                 dim.asc += dh_ + 1;
115         } else {
116                 dy_ = dim.des + 1;
117                 dim.des += dh_ + 2;
118         }
119
120         metricsMarkers(dim);
121         dim_ = dim;
122 }
123
124
125 void InsetMathDecoration::draw(PainterInfo & pi, int x, int y) const
126 {
127         cell(0).draw(pi, x + 1, y);
128         if (wide())
129                 mathed_draw_deco(pi, x + 1, y + dy_, cell(0).width(), dh_, key_->name);
130         else
131                 mathed_draw_deco(pi, x + 1 + (cell(0).width() - dw_) / 2,
132                         y + dy_, dw_, dh_, key_->name);
133         drawMarkers(pi, x, y);
134         setPosCache(pi, x, y);
135 }
136
137
138 void InsetMathDecoration::write(WriteStream & os) const
139 {
140         if (os.fragile() && protect())
141                 os << "\\protect";
142         os << '\\' << key_->name << '{' << cell(0) << '}';
143 }
144
145
146 void InsetMathDecoration::normalize(NormalStream & os) const
147 {
148         os << "[deco " << key_->name << ' ' <<  cell(0) << ']';
149 }
150
151
152 void InsetMathDecoration::infoize(odocstream & os) const
153 {
154         os << "Deco: " << key_->name;
155 }
156
157
158 void InsetMathDecoration::validate(LaTeXFeatures & features) const
159 {
160         if (ams())
161                 features.require("amsmath");
162         InsetMathNest::validate(features);
163 }
164
165
166 } // namespace lyx