]> git.lyx.org Git - lyx.git/blob - src/mathed/math_binominset.C
support for TeX's \choose
[lyx.git] / src / mathed / math_binominset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_binominset.h"
6 #include "math_parser.h"
7 #include "support.h"
8 #include "support/LOstream.h"
9
10
11 MathBinomInset::MathBinomInset()
12 {}
13
14
15 MathInset * MathBinomInset::clone() const
16 {   
17         return new MathBinomInset(*this);
18 }
19
20
21 int MathBinomInset::dw() const
22 {
23         int w = height()/5;
24         if (w > 15)
25                 w = 15;
26         if (w < 6)
27                 w = 6;
28         return w;
29 }
30
31
32 void MathBinomInset::metrics(MathStyles st) const
33 {
34         size_    = smallerStyleFrac(st);
35         xcell(0).metrics(size_);
36         xcell(1).metrics(size_);
37         ascent_  = xcell(0).height() + 4 + 5;
38         descent_ = xcell(1).height() + 4 - 5; 
39         width_   = std::max(xcell(0).width(), xcell(1).width()) + 2 * dw() + 4; 
40 }
41
42
43 void MathBinomInset::draw(Painter & pain, int x, int y) const
44 {
45         xo(x);
46         yo(y);
47         int m = x + width() / 2;
48         xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
49         xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent()  + 3 - 5);
50         mathed_draw_deco(pain, x, y - ascent_,
51                 dw(), height(), in_word_set("("));
52         mathed_draw_deco(pain, x + width() - dw(), y - ascent_, 
53                 dw(), height(), in_word_set(")"));
54 }
55
56
57 void MathBinomInset::write(std::ostream & os, bool fragile) const
58 {
59         os << '{';
60         cell(0).write(os, fragile);
61         os << " \\choose ";
62         cell(1).write(os, fragile);
63         os << '}';
64 }
65
66
67 void MathBinomInset::writeNormal(std::ostream & os) const
68 {
69         os << "[binom ";
70         cell(0).writeNormal(os);
71         os << " ";
72         cell(1).writeNormal(os);
73         os << "] ";
74 }