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