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