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