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