]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathBinom.cpp
adjust
[lyx.git] / src / mathed / InsetMathBinom.cpp
1 /**
2  * \file InsetMathBinom.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 "InsetMathBinom.h"
14 #include "MathData.h"
15 #include "MathSupport.h"
16 #include "MathStream.h"
17
18
19 namespace lyx {
20
21 InsetMathBinom::InsetMathBinom(bool choose)
22         : choose_(choose)
23 {}
24
25
26 Inset * InsetMathBinom::clone() const
27 {
28         return new InsetMathBinom(*this);
29 }
30
31
32 int InsetMathBinom::dw(int height) const
33 {
34         int w = height / 5;
35         if (w > 15)
36                 w = 15;
37         if (w < 6)
38                 w = 6;
39         return w;
40 }
41
42
43 void InsetMathBinom::metrics(MetricsInfo & mi, Dimension & dim) const
44 {
45         ScriptChanger dummy(mi.base);
46         Dimension dim0, dim1;
47         cell(0).metrics(mi, dim0);
48         cell(1).metrics(mi, dim1);
49         dim.asc = dim0.height() + 4 + 5;
50         dim.des = dim1.height() + 4 - 5;
51         dim.wid = std::max(dim0.width(), dim1.wid) + 2 * dw(dim.height()) + 4;
52         metricsMarkers2(dim);
53         // Cache the inset dimension. 
54         setDimCache(mi, dim);
55 }
56
57
58 void InsetMathBinom::draw(PainterInfo & pi, int x, int y) const
59 {
60         Dimension const dim = dimension(*pi.base.bv);
61         Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
62         Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
63         int m = x + dim.width() / 2;
64         ScriptChanger dummy(pi.base);
65         cell(0).draw(pi, m - dim0.width() / 2, y - dim0.des - 3 - 5);
66         cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc  + 3 - 5);
67         mathed_draw_deco(pi, x, y - dim.ascent(), dw(dim.height()), dim.height(), from_ascii("("));
68         mathed_draw_deco(pi, x + dim.width() - dw(dim.height()), y - dim.ascent(),
69                 dw(dim.height()), dim.height(), from_ascii(")"));
70         drawMarkers2(pi, x, y);
71 }
72
73
74 bool InsetMathBinom::extraBraces() const
75 {
76         return choose_;
77 }
78
79
80 void InsetMathBinom::write(WriteStream & os) const
81 {
82         if (choose_)
83                 os << '{' << cell(0) << " \\choose " << cell(1) << '}';
84         else
85                 os << "\\binom{" << cell(0) << "}{" << cell(1) << '}';
86 }
87
88
89 void InsetMathBinom::normalize(NormalStream & os) const
90 {
91         os << "[binom " << cell(0) << ' ' << cell(1) << ']';
92 }
93
94
95 } // namespace lyx