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