]> git.lyx.org Git - lyx.git/blob - src/mathed/math_binominset.C
split LyXText::rowlist_ into individual Paragraph::rows_ chunks
[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 using std::auto_ptr;
11
12
13 MathBinomInset::MathBinomInset(bool choose)
14         : choose_(choose)
15 {}
16
17
18 auto_ptr<InsetBase> MathBinomInset::clone() const
19 {
20         return auto_ptr<InsetBase>(new MathBinomInset(*this));
21 }
22
23
24 int MathBinomInset::dw() const
25 {
26         int w = dim_.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(MetricsInfo & mi, Dimension & dim) const
36 {
37         ScriptChanger dummy(mi.base);
38         cell(0).metrics(mi);
39         cell(1).metrics(mi);
40         dim_.asc = cell(0).height() + 4 + 5;
41         dim_.des = cell(1).height() + 4 - 5;
42         dim_.wid = max(cell(0).width(), cell(1).width()) + 2 * dw() + 4;
43         dim = dim_;
44 }
45
46
47 void MathBinomInset::draw(PainterInfo & pi, int x, int y) const
48 {
49         int m = x + dim_.width() / 2;
50         ScriptChanger dummy(pi.base);
51         cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 3 - 5);
52         cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent()  + 3 - 5);
53         mathed_draw_deco(pi, x, y - dim_.ascent(), dw(), dim_.height(), "(");
54         mathed_draw_deco(pi, x + dim_.width() - dw(), y - dim_.ascent(),
55                 dw(), dim_.height(), ")");
56 }
57
58
59 void MathBinomInset::write(WriteStream & os) const
60 {
61         if (choose_)
62                 os << '{' << cell(0) << " \\choose " << cell(1) << '}';
63         else
64                 os << "\\binom{" << cell(0) << "}{" << cell(1) << '}';
65 }
66
67
68 void MathBinomInset::normalize(NormalStream & os) const
69 {
70         os << "[binom " << cell(0) << ' ' << cell(1) << ']';
71 }