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