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