]> git.lyx.org Git - lyx.git/blob - src/mathed/math_oversetinset.C
Andreas' patch to prevent crash on click on previewd inset
[lyx.git] / src / mathed / math_oversetinset.C
1 /**
2  * \file math_oversetinset.C
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 "math_oversetinset.h"
14 #include "math_data.h"
15 #include "math_mathmlstream.h"
16
17 #include "cursor.h"
18 #include "LaTeXFeatures.h"
19
20 using std::max;
21 using std::auto_ptr;
22
23
24 auto_ptr<InsetBase> MathOversetInset::doClone() const
25 {
26         return auto_ptr<InsetBase>(new MathOversetInset(*this));
27 }
28
29
30 void MathOversetInset::metrics(MetricsInfo & mi, Dimension & dim) const
31 {
32         cell(1).metrics(mi);
33         FracChanger dummy(mi.base);
34         cell(0).metrics(mi);
35         dim.wid = max(cell(0).width(), cell(1).width()) + 4;
36         dim.asc = cell(1).ascent() + cell(0).height() + 4;
37         dim.des = cell(1).descent();
38         metricsMarkers(dim);
39         dim_ = dim;
40 }
41
42
43 void MathOversetInset::draw(PainterInfo & pi, int x, int y) const
44 {
45         int m  = x + width() / 2;
46         int yo = y - cell(1).ascent() + cell(0).descent() - 1;
47         cell(1).draw(pi, m - cell(1).width() / 2, y);
48         FracChanger dummy(pi.base);
49         cell(0).draw(pi, m - cell(0).width() / 2, yo);
50         drawMarkers(pi, x, y);
51 }
52
53
54 bool MathOversetInset::idxFirst(LCursor & cur) const
55 {
56         cur.idx() = 1;
57         cur.pos() = 0;
58         return true;
59 }
60
61
62 bool MathOversetInset::idxLast(LCursor & cur) const
63 {
64         cur.idx() = 1;
65         cur.pos() = cur.lastpos();
66         return true;
67 }
68
69
70 void MathOversetInset::write(WriteStream & os) const
71 {
72         os << "\\overset{" << cell(0) << "}{" << cell(1) << '}';
73 }
74
75
76 void MathOversetInset::normalize(NormalStream & os) const
77 {
78         os << "[overset " << cell(0) << ' ' << cell(1) << ']';
79 }
80
81
82 void MathOversetInset::validate(LaTeXFeatures & features) const
83 {
84         features.require("amsmath");
85         MathNestInset::validate(features);
86 }