]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathOverset.cpp
Fix -Winconsistent-missing-override
[lyx.git] / src / mathed / InsetMathOverset.cpp
1 /**
2  * \file InsetMathOverset.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathOverset.h"
14
15 #include "MathData.h"
16 #include "MathStream.h"
17
18 #include "Cursor.h"
19 #include "LaTeXFeatures.h"
20 #include "MetricsInfo.h"
21
22 #include "support/lassert.h"
23
24 using namespace std;
25
26 namespace lyx {
27
28 Inset * InsetMathOverset::clone() const
29 {
30         return new InsetMathOverset(*this);
31 }
32
33
34 void InsetMathOverset::metrics(MetricsInfo & mi, Dimension & dim) const
35 {
36         Changer dummy2 = mi.base.changeEnsureMath();
37         Dimension dim0;
38         cell(0).metrics(mi, dim0);
39         Changer dummy = mi.base.changeScript();
40         Dimension dim1;
41         cell(1).metrics(mi, dim1);
42         dim.wid = max(dim1.width(), dim0.wid) + 4;
43         dim.asc = dim0.asc + dim1.height() + 4;
44         dim.des = dim0.des;
45 }
46
47
48 void InsetMathOverset::draw(PainterInfo & pi, int x, int y) const
49 {
50         Changer dummy2 = pi.base.changeEnsureMath();
51         Dimension const dim = dimension(*pi.base.bv);
52         Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
53         Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
54         int m  = x + dim.wid / 2;
55         int yo = y - dim0.asc - dim1.des - 1;
56         cell(0).draw(pi, m - dim0.wid / 2, y);
57         Changer dummy = pi.base.changeScript();
58         cell(1).draw(pi, m - dim1.width() / 2, yo);
59 }
60
61
62 bool InsetMathOverset::idxUpDown(Cursor & cur, bool up) const
63 {
64         idx_type target = up; // up ? 1 : 0, since upper cell has idx 1
65         if (cur.idx() == target)
66                 return false;
67         cur.idx() = target;
68         cur.pos() = cur.cell().x2pos(&cur.bv(), cur.x_target());
69         return true;
70 }
71
72
73 bool InsetMathOverset::idxFirst(Cursor & cur) const
74 {
75         LASSERT(&cur.inset() == this, return false);
76         cur.idx() = 0;
77         cur.pos() = 0;
78         return true;
79 }
80
81
82 bool InsetMathOverset::idxLast(Cursor & cur) const
83 {
84         LASSERT(&cur.inset() == this, return false);
85         cur.idx() = 0;
86         cur.pos() = cur.lastpos();
87         return true;
88 }
89
90
91 void InsetMathOverset::write(TeXMathStream & os) const
92 {
93         MathEnsurer ensurer(os);
94         if (os.fragile())
95                 os << "\\protect";
96         os << "\\overset{" << cell(1) << "}{" << cell(0) << '}';
97 }
98
99
100 void InsetMathOverset::normalize(NormalStream & os) const
101 {
102         os << "[overset " << cell(1) << ' ' << cell(0) << ']';
103 }
104
105
106 void InsetMathOverset::mathmlize(MathMLStream & ms) const
107 {
108         ms << MTag("mover", "accent='false'")
109            << cell(0) << cell(1)
110            << ETag("mover");
111 }
112
113
114 void InsetMathOverset::htmlize(HtmlStream & os) const
115 {
116         os << MTag("span", "class='overset'")
117            << MTag("span", "class='top'") << cell(1) << ETag("span")
118            << MTag("span") << cell(0) << ETag("span")
119            << ETag("span");
120 }
121
122
123 void InsetMathOverset::validate(LaTeXFeatures & features) const
124 {
125         if (features.runparams().isLaTeX())
126                 features.require("amsmath");
127         else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
128                 features.addCSSSnippet(
129                         "span.overset{display: inline-block; vertical-align: bottom; text-align:center;}\n"
130                         "span.overset span {display: block;}\n"
131                         "span.top{font-size: 66%;}");
132
133         InsetMathNest::validate(features);
134 }
135
136
137 } // namespace lyx