]> git.lyx.org Git - lyx.git/blob - src/mathed/math_undersetinset.C
Fix math cursor positioning bug
[lyx.git] / src / mathed / math_undersetinset.C
1 /**
2  * \file math_undersetinset.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_undersetinset.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
25 auto_ptr<InsetBase> MathUndersetInset::doClone() const
26 {
27         return auto_ptr<InsetBase>(new MathUndersetInset(*this));
28 }
29
30
31 void MathUndersetInset::metrics(MetricsInfo & mi, Dimension & dim) const
32 {
33         cell(1).metrics(mi);
34         FracChanger dummy(mi.base);
35         cell(0).metrics(mi);
36         dim.wid = max(cell(0).width(), cell(1).width()) + 4;
37         dim.asc = cell(1).ascent();
38         dim.des = cell(1).descent() + cell(0).height() + 4;
39         metricsMarkers(dim);
40         dim_ = dim;
41 }
42
43
44 void MathUndersetInset::draw(PainterInfo & pi, int x, int y) const
45 {
46         int m  = x + width() / 2;
47         int yo = y + cell(1).descent() + cell(0).ascent() + 1;
48         cell(1).draw(pi, m - cell(1).width() / 2, y);
49         FracChanger dummy(pi.base);
50         cell(0).draw(pi, m - cell(0).width() / 2, yo);
51         drawMarkers(pi, x, y);
52 }
53
54
55 bool MathUndersetInset::idxFirst(LCursor & cur) const
56 {
57         cur.idx() = 1;
58         cur.pos() = 0;
59         return true;
60 }
61
62
63 bool MathUndersetInset::idxLast(LCursor & cur) const
64 {
65         cur.idx() = 1;
66         cur.pos() = cur.lastpos();
67         return true;
68 }
69
70
71 bool MathUndersetInset::idxUpDown(LCursor & cur, bool up) const
72 {
73         idx_type target = up; // up ? 1 : 0, since upper cell has idx 1
74         if (cur.idx() == target)
75                 return false;
76         cur.idx() = target;
77         cur.pos() = cur.cell().x2pos(cur.x_target());
78         return true;
79 }
80
81
82 void MathUndersetInset::write(WriteStream & os) const
83 {
84         os << "\\underset{" << cell(0) << "}{" << cell(1) << '}';
85 }
86
87
88 void MathUndersetInset::normalize(NormalStream & os) const
89 {
90         os << "[underset " << cell(0) << ' ' << cell(1) << ']';
91 }
92
93
94 void MathUndersetInset::validate(LaTeXFeatures & features) const
95 {
96         features.require("amsmath");
97         MathNestInset::validate(features);
98 }