]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathDFrac.cpp
small simplification
[lyx.git] / src / mathed / InsetMathDFrac.cpp
1 /**
2  * \file InsetMathDFrac.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 "InsetMathDFrac.h"
14 #include "MathData.h"
15 #include "MathStream.h"
16 #include "LaTeXFeatures.h"
17 #include "Color.h"
18 #include "frontends/Painter.h"
19
20
21 namespace lyx {
22
23 InsetMathDFrac::InsetMathDFrac()
24         : InsetMathFrac()
25 {}
26
27
28 Inset * InsetMathDFrac::clone() const
29 {
30         return new InsetMathDFrac(*this);
31 }
32
33
34 void InsetMathDFrac::metrics(MetricsInfo & mi, Dimension & dim) const
35 {
36         Dimension dim0, dim1;
37         cell(0).metrics(mi, dim0);
38         cell(1).metrics(mi, dim1);
39         dim.wid = std::max(dim0.wid, dim1.wid) + 2;
40         dim.asc = dim0.height() + 2 + 5;
41         dim.des = dim1.height() + 2 - 5;
42         // Cache the inset dimension. 
43         setDimCache(mi, dim);
44 }
45
46
47 void InsetMathDFrac::draw(PainterInfo & pi, int x, int y) const
48 {
49         Dimension const dim = dimension(*pi.base.bv);
50         Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
51         Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
52         int m = x + dim.wid / 2;
53         cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 2 - 5);
54         cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc  + 2 - 5);
55         pi.pain.line(x + 1, y - 5, x + dim.wid - 2, y - 5, Color::math);
56         setPosCache(pi, x, y);
57 }
58
59
60 docstring InsetMathDFrac::name() const
61 {
62         return from_ascii("dfrac");
63 }
64
65
66 void InsetMathDFrac::mathmlize(MathStream & os) const
67 {
68         os << MTag("mdfrac") << cell(0) << cell(1) << ETag("mdfrac");
69 }
70
71
72 void InsetMathDFrac::validate(LaTeXFeatures & features) const
73 {
74         features.require("amsmath");
75         InsetMathNest::validate(features);
76 }
77
78
79 } // namespace lyx