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