]> git.lyx.org Git - lyx.git/blob - src/mathed/math_binominset.C
rename commandtags.h to lfuns.h and renumber/cleanup. Rebuild the tree !
[lyx.git] / src / mathed / math_binominset.C
1 #include <config.h>
2
3
4 #include "math_binominset.h"
5 #include "math_support.h"
6 #include "support/LOstream.h"
7 #include "math_mathmlstream.h"
8
9
10 using std::max;
11
12
13 MathBinomInset::MathBinomInset(bool choose)
14         : choose_(choose)
15 {}
16
17
18 MathInset * MathBinomInset::clone() const
19 {
20         return new MathBinomInset(*this);
21 }
22
23
24 int MathBinomInset::dw() const
25 {
26         int w = height()/5;
27         if (w > 15)
28                 w = 15;
29         if (w < 6)
30                 w = 6;
31         return w;
32 }
33
34
35 void MathBinomInset::metrics(MathMetricsInfo & mi) const
36 {
37         MathScriptChanger dummy(mi.base);
38         cell(0).metrics(mi);
39         cell(1).metrics(mi);
40         dim_.a = cell(0).height() + 4 + 5;
41         dim_.d = cell(1).height() + 4 - 5;
42         dim_.w = max(cell(0).width(), cell(1).width()) + 2 * dw() + 4;
43 }
44
45
46 void MathBinomInset::draw(MathPainterInfo & pi, int x, int y) const
47 {
48         int m = x + width() / 2;
49         MathScriptChanger 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 - ascent(), dw(), height(), "(");
53         mathed_draw_deco(pi, x + width() - dw(), y - ascent(),  dw(), height(), ")");
54 }
55
56
57 void MathBinomInset::write(WriteStream & os) const
58 {
59         if (choose_)
60                 os << '{' << cell(0) << " \\choose " << cell(1) << '}';
61         else
62                 os << "\\binom{" << cell(0) << "}{" << cell(1) << '}';
63 }
64
65
66 void MathBinomInset::normalize(NormalStream & os) const
67 {
68         os << "[binom " << cell(0) << ' ' << cell(1) << ']';
69 }