]> git.lyx.org Git - lyx.git/blob - src/mathed/math_binominset.C
Make Helge happy: no more crash on arrow up/down in math macro
[lyx.git] / src / mathed / math_binominset.C
1 /**
2  * \file math_binominset.C
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 "math_binominset.h"
14 #include "math_data.h"
15 #include "math_support.h"
16 #include "math_mathmlstream.h"
17
18
19 using std::max;
20 using std::auto_ptr;
21
22
23 MathBinomInset::MathBinomInset(bool choose)
24         : choose_(choose)
25 {}
26
27
28 auto_ptr<InsetBase> MathBinomInset::doClone() const
29 {
30         return auto_ptr<InsetBase>(new MathBinomInset(*this));
31 }
32
33
34 int MathBinomInset::dw() const
35 {
36         int w = dim_.height() / 5;
37         if (w > 15)
38                 w = 15;
39         if (w < 6)
40                 w = 6;
41         return w;
42 }
43
44
45 void MathBinomInset::metrics(MetricsInfo & mi, Dimension & dim) const
46 {
47         ScriptChanger dummy(mi.base);
48         cell(0).metrics(mi);
49         cell(1).metrics(mi);
50         dim.asc = cell(0).height() + 4 + 5;
51         dim.des = cell(1).height() + 4 - 5;
52         dim.wid = max(cell(0).width(), cell(1).width()) + 2 * dw() + 4;
53         metricsMarkers2(dim);
54         dim_ = dim;
55 }
56
57
58 void MathBinomInset::draw(PainterInfo & pi, int x, int y) const
59 {
60         int m = x + dim_.width() / 2;
61         ScriptChanger dummy(pi.base);
62         cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 3 - 5);
63         cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent()  + 3 - 5);
64         mathed_draw_deco(pi, x, y - dim_.ascent(), dw(), dim_.height(), "(");
65         mathed_draw_deco(pi, x + dim_.width() - dw(), y - dim_.ascent(),
66                 dw(), dim_.height(), ")");
67         drawMarkers2(pi, x, y);
68 }
69
70
71 void MathBinomInset::write(WriteStream & os) const
72 {
73         if (choose_)
74                 os << '{' << cell(0) << " \\choose " << cell(1) << '}';
75         else
76                 os << "\\binom{" << cell(0) << "}{" << cell(1) << '}';
77 }
78
79
80 void MathBinomInset::normalize(NormalStream & os) const
81 {
82         os << "[binom " << cell(0) << ' ' << cell(1) << ']';
83 }