]> git.lyx.org Git - lyx.git/blob - src/mathed/math_arrayinset.C
97240cb67c67c35621c44fd2e926b6f593ae439a
[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 "math_mathmlstream.h"
8 #include "Lsstream.h"
9
10 using std::vector;
11 using std::istringstream;
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::metrics(MathMetricsInfo const & st) const
56 {
57         MathMetricsInfo mi = st;
58         if (mi.style == LM_ST_DISPLAY)
59                 mi.style = LM_ST_TEXT;
60         MathGridInset::metrics(mi);
61 }
62
63
64 void MathArrayInset::write(WriteStream & os) const
65 {
66         if (os.fragile)
67                 os << "\\protect";
68         os << "\\begin{array}";
69
70         if (v_align_ == 't' || v_align_ == 'b') 
71                 os << '[' << char(v_align_) << ']';
72
73         os << '{';
74         for (col_type col = 0; col < ncols(); ++col)
75                 os << colinfo_[col].align_;
76         os << "}\n";
77
78         MathGridInset::write(os);
79
80         if (os.fragile)
81                 os << "\\protect";
82         os << "\\end{array}\n";
83 }
84
85
86 void MathArrayInset::normalize(NormalStream & os) const
87 {
88         os << "[array ";
89         MathGridInset::normalize(os);
90         os << "]";
91 }
92
93
94 void MathArrayInset::maplize(MapleStream & os) const
95 {
96         os << "array(";
97         MathGridInset::maplize(os);
98         os << ")";
99 }