]> git.lyx.org Git - lyx.git/blob - src/mathed/math_arrayinset.C
The "I want this in now" patch.
[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 "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(MetricsInfo & mi) const
67 {
68         ArrayChanger dummy(mi.base);
69         MathGridInset::metrics(mi);
70         metricsMarkers2();
71 }
72
73
74 void MathArrayInset::draw(PainterInfo & pi, int x, int y) const
75 {
76         ArrayChanger dummy(pi.base);
77         MathGridInset::draw(pi, x, y);
78         drawMarkers2(pi, x, y);
79 }
80
81
82 void MathArrayInset::write(WriteStream & os) const
83 {
84         if (os.fragile())
85                 os << "\\protect";
86         os << "\\begin{" << name_ << '}';
87
88         if (v_align_ == 't' || v_align_ == 'b')
89                 os << '[' << char(v_align_) << ']';
90         os << '{' << halign() << "}\n";
91
92         MathGridInset::write(os);
93
94         if (os.fragile())
95                 os << "\\protect";
96         os << "\\end{" << name_ << '}';
97         // adding a \n here is bad if the array is the last item
98         // in an \eqnarray...
99 }
100
101
102 void MathArrayInset::infoize(std::ostream & os) const
103 {
104         os << "Array";
105 }
106
107
108 void MathArrayInset::normalize(NormalStream & os) const
109 {
110         os << '[' << name_ << ' ';
111         MathGridInset::normalize(os);
112         os << ']';
113 }
114
115
116 void MathArrayInset::maple(MapleStream & os) const
117 {
118         os << "array(";
119         MathGridInset::maple(os);
120         os << ')';
121 }