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