]> git.lyx.org Git - lyx.git/blob - src/mathed/math_amsarrayinset.C
the clone auto_ptr patch
[lyx.git] / src / mathed / math_amsarrayinset.C
1 #include <config.h>
2
3 #include "math_amsarrayinset.h"
4 #include "math_mathmlstream.h"
5 #include "metricsinfo.h"
6 #include "math_streamstr.h"
7 #include "math_support.h"
8 #include "Lsstream.h"
9
10 using std::auto_ptr;
11
12
13 MathAMSArrayInset::MathAMSArrayInset(string const & name, int m, int n)
14         : MathGridInset(m, n), name_(name)
15 {}
16
17
18 MathAMSArrayInset::MathAMSArrayInset(string const & name)
19         : MathGridInset(1, 1), name_(name)
20 {}
21
22
23 auto_ptr<InsetBase> MathAMSArrayInset::clone() const
24 {
25         return auto_ptr<InsetBase>(new MathAMSArrayInset(*this));
26 }
27
28
29 char const * MathAMSArrayInset::name_left() const
30 {
31         if (name_ == "bmatrix")
32                 return "[";
33         if (name_ == "Bmatrix")
34                 return "{";
35         if (name_ == "vmatrix")
36                 return "|";
37         if (name_ == "Vmatrix")
38                 return "Vert";
39         if (name_ == "pmatrix")
40                 return "(";
41         return ".";
42 }
43
44
45 char const * MathAMSArrayInset::name_right() const
46 {
47         if (name_ == "bmatrix")
48                 return "]";
49         if (name_ == "Bmatrix")
50                 return "}";
51         if (name_ == "vmatrix")
52                 return "|";
53         if (name_ == "Vmatrix")
54                 return "Vert";
55         if (name_ == "pmatrix")
56                 return ")";
57         return ".";
58 }
59
60
61 void MathAMSArrayInset::metrics(MetricsInfo & mi, Dimension & dim) const
62 {
63         MetricsInfo m = mi;
64         if (m.base.style == LM_ST_DISPLAY)
65                 m.base.style = LM_ST_TEXT;
66         MathGridInset::metrics(m);
67         dim_.wid += 12;
68         dim = dim_;
69 }
70
71
72 void MathAMSArrayInset::draw(PainterInfo & pi, int x, int y) const
73 {
74         MathGridInset::draw(pi, x + 6, y);
75         int const yy = y - dim_.ascent();
76         mathed_draw_deco(pi, x + 1, yy, 5, dim_.height(), name_left());
77         mathed_draw_deco(pi, x + dim_.width() - 6, yy, 5, dim_.height(), name_right());
78 }
79
80
81 void MathAMSArrayInset::write(WriteStream & os) const
82 {
83         os << "\\begin{" << name_ << '}';
84         MathGridInset::write(os);
85         os << "\\end{" << name_ << '}';
86 }
87
88
89 void MathAMSArrayInset::normalize(NormalStream & os) const
90 {
91         os << '[' << name_ << ' ';
92         MathGridInset::normalize(os);
93         os << ']';
94 }