]> git.lyx.org Git - lyx.git/blob - src/mathed/math_arrayinset.C
Make lyx2lyx output the new external inset format.
[lyx.git] / src / mathed / math_arrayinset.C
1 #include <config.h>
2
3
4 #include "math_arrayinset.h"
5 #include "math_parser.h"
6 #include "math_mathmlstream.h"
7 #include "metricsinfo.h"
8 #include "math_streamstr.h"
9 #include "Lsstream.h"
10
11 #include <iterator>
12
13 using std::vector;
14 using std::istringstream;
15 using std::getline;
16 using std::istream_iterator;
17
18
19 MathArrayInset::MathArrayInset(string const & name, int m, int n)
20         : MathGridInset(m, n), name_(name)
21 {}
22
23
24 MathArrayInset::MathArrayInset(string const & name, int m, int n,
25                 char valign, string const & halign)
26         : MathGridInset(m, n, valign, halign), name_(name)
27 {}
28
29
30 MathArrayInset::MathArrayInset(string const & name, char valign,
31                 string const & halign)
32         : MathGridInset(valign, halign), name_(name)
33 {}
34
35
36 MathArrayInset::MathArrayInset(string const & name, string const & str)
37         : MathGridInset(1, 1), name_(name)
38 {
39         vector< vector<string> > dat;
40         istringstream is(STRCONV(str));
41         string line;
42         while (getline(is, line)) {
43                 istringstream ls(STRCONV(line));
44                 typedef istream_iterator<string> iter;
45                 vector<string> v = vector<string>(iter(ls), iter());
46                 if (v.size())
47                         dat.push_back(v);
48         }
49
50         for (row_type row = 1; row < dat.size(); ++row)
51                 addRow(0);
52         for (col_type col = 1; col < dat[0].size(); ++col)
53                 addCol(0);
54         for (row_type row = 0; row < dat.size(); ++row)
55                 for (col_type col = 0; col < dat[0].size(); ++col)
56                         mathed_parse_cell(cell(index(row, col)), dat[row][col]);
57 }
58
59
60 MathInset * MathArrayInset::clone() const
61 {
62         return new MathArrayInset(*this);
63 }
64
65
66 void MathArrayInset::metrics(MetricsInfo & mi, Dimension & dim) const
67 {
68         ArrayChanger dummy(mi.base);
69         MathGridInset::metrics(mi);
70         metricsMarkers2();
71         dim = dim_;
72 }
73
74
75 void MathArrayInset::draw(PainterInfo & pi, int x, int y) const
76 {
77         ArrayChanger dummy(pi.base);
78         MathGridInset::draw(pi, x + 1, y);
79         drawMarkers2(pi, x, y);
80 }
81
82
83 void MathArrayInset::write(WriteStream & os) const
84 {
85         if (os.fragile())
86                 os << "\\protect";
87         os << "\\begin{" << name_ << '}';
88
89         if (v_align_ == 't' || v_align_ == 'b')
90                 os << '[' << char(v_align_) << ']';
91         os << '{' << halign() << "}\n";
92
93         MathGridInset::write(os);
94
95         if (os.fragile())
96                 os << "\\protect";
97         os << "\\end{" << name_ << '}';
98         // adding a \n here is bad if the array is the last item
99         // in an \eqnarray...
100 }
101
102
103 void MathArrayInset::infoize(std::ostream & os) const
104 {
105         os << "Array";
106 }
107
108
109 void MathArrayInset::normalize(NormalStream & os) const
110 {
111         os << '[' << name_ << ' ';
112         MathGridInset::normalize(os);
113         os << ']';
114 }
115
116
117 void MathArrayInset::maple(MapleStream & os) const
118 {
119         os << "array(";
120         MathGridInset::maple(os);
121         os << ')';
122 }