]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathBinom.cpp
make index label translatable
[lyx.git] / src / mathed / InsetMathBinom.cpp
1 /**
2  * \file InsetMathBinom.cpp
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 "InsetMathBinom.h"
14 #include "MathData.h"
15 #include "MathSupport.h"
16 #include "MathStream.h"
17
18
19 namespace lyx {
20
21 InsetMathBinom::InsetMathBinom(bool choose)
22         : choose_(choose)
23 {}
24
25
26 Inset * InsetMathBinom::clone() const
27 {
28         return new InsetMathBinom(*this);
29 }
30
31
32 int InsetMathBinom::dw() const
33 {
34         int w = dim_.height() / 5;
35         if (w > 15)
36                 w = 15;
37         if (w < 6)
38                 w = 6;
39         return w;
40 }
41
42
43 bool InsetMathBinom::metrics(MetricsInfo & mi, Dimension & dim) const
44 {
45         ScriptChanger dummy(mi.base);
46         cell(0).metrics(mi);
47         cell(1).metrics(mi);
48         dim.asc = cell(0).height() + 4 + 5;
49         dim.des = cell(1).height() + 4 - 5;
50         dim.wid = std::max(cell(0).width(), cell(1).width()) + 2 * dw() + 4;
51         metricsMarkers2(dim);
52         bool const changed = dim_ != dim;
53         dim_ = dim;
54         return changed;
55 }
56
57
58 void InsetMathBinom::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(), from_ascii("("));
65         mathed_draw_deco(pi, x + dim_.width() - dw(), y - dim_.ascent(),
66                 dw(), dim_.height(), from_ascii(")"));
67         drawMarkers2(pi, x, y);
68 }
69
70
71 bool InsetMathBinom::extraBraces() const
72 {
73         return choose_;
74 }
75
76
77 void InsetMathBinom::write(WriteStream & os) const
78 {
79         if (choose_)
80                 os << '{' << cell(0) << " \\choose " << cell(1) << '}';
81         else
82                 os << "\\binom{" << cell(0) << "}{" << cell(1) << '}';
83 }
84
85
86 void InsetMathBinom::normalize(NormalStream & os) const
87 {
88         os << "[binom " << cell(0) << ' ' << cell(1) << ']';
89 }
90
91
92 } // namespace lyx