]> git.lyx.org Git - lyx.git/blob - src/mathed/math_arrayinset.C
b2a3fbee52b73e5e2f95cc424dc35716fb961c91
[lyx.git] / src / mathed / math_arrayinset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_arrayinset.h"
6 #include "math_parser.h"
7 #include "support/LOstream.h"
8 #include "Lsstream.h"
9
10
11 MathArrayInset::MathArrayInset(int m, int n)
12         : MathGridInset(m, n)
13 {}
14
15
16 MathArrayInset::MathArrayInset(int m, int n, char valign, string const & halign)
17         : MathGridInset(m, n, valign, halign)
18 {}
19
20
21 MathArrayInset::MathArrayInset(string const & str)
22         : MathGridInset(1, 1)
23 {
24         vector< vector<string> > dat;
25         istringstream is(str);
26         while (is) {
27                 string line;
28                 getline(is, line);
29                 istringstream ls(line);
30                 typedef std::istream_iterator<string> iter;
31                 vector<string> v = vector<string>(iter(ls), iter());
32                 if (v.size())
33                         dat.push_back(v);
34         }
35
36         for (row_type row = 1; row < dat.size(); ++row)
37                 addRow(0);
38         for (col_type col = 1; col < dat[0].size(); ++col)
39                 addCol(0);
40         for (row_type row = 0; row < dat.size(); ++row)
41                 for (col_type col = 0; col < dat[row].size(); ++col)
42                         mathed_parse_cell(cell(index(row, col)), dat[row][col]);
43 }
44
45
46 MathInset * MathArrayInset::clone() const
47 {
48         return new MathArrayInset(*this);
49 }
50
51
52 void MathArrayInset::write(MathWriteInfo & os) const
53 {
54         if (os.fragile)
55                 os << "\\protect";
56         os << "\\begin{array}";
57
58         if (v_align_ == 't' || v_align_ == 'b') 
59                 os << '[' << char(v_align_) << ']';
60
61         os << '{';
62         for (col_type col = 0; col < ncols(); ++col)
63                 os << colinfo_[col].align_;
64         os << "}\n";
65
66         MathGridInset::write(os);
67
68         if (os.fragile)
69                 os << "\\protect";
70         os << "\\end{array}\n";
71 }
72
73
74 void MathArrayInset::writeNormal(std::ostream & os) const
75 {
76         os << "[array ";
77         MathGridInset::writeNormal(os);
78         os << "]";
79 }
80
81
82 void MathArrayInset::metrics(MathMetricsInfo const & st) const
83 {
84         MathMetricsInfo mi = st;
85         if (mi.style == LM_ST_DISPLAY)
86                 mi.style = LM_ST_TEXT;
87         MathGridInset::metrics(mi);
88 }