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