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