]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathBinom.cpp
* Inset and derivatives: insetName() -> name()
[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
22 using std::max;
23 using std::auto_ptr;
24
25
26 InsetMathBinom::InsetMathBinom(bool choose)
27         : choose_(choose)
28 {}
29
30
31 auto_ptr<Inset> InsetMathBinom::doClone() const
32 {
33         return auto_ptr<Inset>(new InsetMathBinom(*this));
34 }
35
36
37 int InsetMathBinom::dw() const
38 {
39         int w = dim_.height() / 5;
40         if (w > 15)
41                 w = 15;
42         if (w < 6)
43                 w = 6;
44         return w;
45 }
46
47
48 bool InsetMathBinom::metrics(MetricsInfo & mi, Dimension & dim) const
49 {
50         ScriptChanger dummy(mi.base);
51         cell(0).metrics(mi);
52         cell(1).metrics(mi);
53         dim.asc = cell(0).height() + 4 + 5;
54         dim.des = cell(1).height() + 4 - 5;
55         dim.wid = max(cell(0).width(), cell(1).width()) + 2 * dw() + 4;
56         metricsMarkers2(dim);
57         bool const changed = dim_ != dim;
58         dim_ = dim;
59         return changed;
60 }
61
62
63 void InsetMathBinom::draw(PainterInfo & pi, int x, int y) const
64 {
65         int m = x + dim_.width() / 2;
66         ScriptChanger dummy(pi.base);
67         cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 3 - 5);
68         cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent()  + 3 - 5);
69         mathed_draw_deco(pi, x, y - dim_.ascent(), dw(), dim_.height(), from_ascii("("));
70         mathed_draw_deco(pi, x + dim_.width() - dw(), y - dim_.ascent(),
71                 dw(), dim_.height(), from_ascii(")"));
72         drawMarkers2(pi, x, y);
73 }
74
75
76 bool InsetMathBinom::extraBraces() const
77 {
78         return choose_;
79 }
80
81
82 void InsetMathBinom::write(WriteStream & os) const
83 {
84         if (choose_)
85                 os << '{' << cell(0) << " \\choose " << cell(1) << '}';
86         else
87                 os << "\\binom{" << cell(0) << "}{" << cell(1) << '}';
88 }
89
90
91 void InsetMathBinom::normalize(NormalStream & os) const
92 {
93         os << "[binom " << cell(0) << ' ' << cell(1) << ']';
94 }
95
96
97 } // namespace lyx