]> git.lyx.org Git - lyx.git/blob - src/mathed/math_binominset.C
IU of clone() and getLabelList()
[lyx.git] / src / mathed / math_binominset.C
1 #include <config.h>
2
3 #include "math_binominset.h"
4 #include "math_support.h"
5 #include "support/LOstream.h"
6 #include "math_mathmlstream.h"
7
8
9 using std::max;
10
11
12 MathBinomInset::MathBinomInset(bool choose)
13         : choose_(choose)
14 {}
15
16
17 InsetBase * MathBinomInset::clone() const
18 {
19         return new MathBinomInset(*this);
20 }
21
22
23 int MathBinomInset::dw() const
24 {
25         int w = dim_.height() / 5;
26         if (w > 15)
27                 w = 15;
28         if (w < 6)
29                 w = 6;
30         return w;
31 }
32
33
34 void MathBinomInset::metrics(MetricsInfo & mi, Dimension & dim) const
35 {
36         ScriptChanger dummy(mi.base);
37         cell(0).metrics(mi);
38         cell(1).metrics(mi);
39         dim_.asc = cell(0).height() + 4 + 5;
40         dim_.des = cell(1).height() + 4 - 5;
41         dim_.wid = max(cell(0).width(), cell(1).width()) + 2 * dw() + 4;
42         dim = dim_;
43 }
44
45
46 void MathBinomInset::draw(PainterInfo & pi, int x, int y) const
47 {
48         int m = x + dim_.width() / 2;
49         ScriptChanger dummy(pi.base);
50         cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 3 - 5);
51         cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent()  + 3 - 5);
52         mathed_draw_deco(pi, x, y - dim_.ascent(), dw(), dim_.height(), "(");
53         mathed_draw_deco(pi, x + dim_.width() - dw(), y - dim_.ascent(),
54                 dw(), dim_.height(), ")");
55 }
56
57
58 void MathBinomInset::write(WriteStream & os) const
59 {
60         if (choose_)
61                 os << '{' << cell(0) << " \\choose " << cell(1) << '}';
62         else
63                 os << "\\binom{" << cell(0) << "}{" << cell(1) << '}';
64 }
65
66
67 void MathBinomInset::normalize(NormalStream & os) const
68 {
69         os << "[binom " << cell(0) << ' ' << cell(1) << ']';
70 }