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