]> git.lyx.org Git - lyx.git/blob - src/mathed/math_binominset.C
make \newcommand{\bb}[1]{\mathbf{#1}} work for read/write/display.
[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 MathBinomInset::MathBinomInset()
14 {}
15
16
17 MathInset * MathBinomInset::clone() const
18 {   
19         return new MathBinomInset(*this);
20 }
21
22
23 int MathBinomInset::dw() const
24 {
25         int w = 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(MathMetricsInfo const & st) const
35 {
36         MathMetricsInfo mi = st;
37         smallerStyleFrac(mi);
38         xcell(0).metrics(mi);
39         xcell(1).metrics(mi);
40         ascent_  = xcell(0).height() + 4 + 5;
41         descent_ = xcell(1).height() + 4 - 5; 
42         width_   = std::max(xcell(0).width(), xcell(1).width()) + 2 * dw() + 4; 
43 }
44
45
46 void MathBinomInset::draw(Painter & pain, int x, int y) const
47 {
48         int m = x + width() / 2;
49         xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
50         xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent()  + 3 - 5);
51         mathed_draw_deco(pain, x, y - ascent_, dw(), height(), "(");
52         mathed_draw_deco(pain, x + width() - dw(), y - ascent_, dw(), height(), ")");
53 }
54
55
56 void MathBinomInset::write(WriteStream & os) const
57 {
58         os << '{' << cell(0) << " \\choose " << cell(1) << '}';
59 }
60
61
62 void MathBinomInset::normalize(NormalStream & os) const
63 {
64         os << "[binom " << cell(0) << ' ' << cell(1) << ']';
65 }