2 * \file math_arrayinset.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "math_arrayinset.h"
14 #include "math_data.h"
15 #include "math_parser.h"
16 #include "math_mathmlstream.h"
17 #include "math_streamstr.h"
26 using std::istringstream;
27 using std::istream_iterator;
31 MathArrayInset::MathArrayInset(string const & name, int m, int n)
32 : MathGridInset(m, n), name_(name)
36 MathArrayInset::MathArrayInset(string const & name, int m, int n,
37 char valign, string const & halign)
38 : MathGridInset(m, n, valign, halign), name_(name)
42 MathArrayInset::MathArrayInset(string const & name, char valign,
43 string const & halign)
44 : MathGridInset(valign, halign), name_(name)
48 MathArrayInset::MathArrayInset(string const & name, string const & str)
49 : MathGridInset(1, 1), name_(name)
51 vector< vector<string> > dat;
52 istringstream is(str);
54 while (getline(is, line)) {
55 istringstream ls(line);
56 typedef istream_iterator<string> iter;
57 vector<string> v = vector<string>(iter(ls), iter());
62 for (row_type row = 1; row < dat.size(); ++row)
64 for (col_type col = 1; col < dat[0].size(); ++col)
66 for (row_type row = 0; row < dat.size(); ++row)
67 for (col_type col = 0; col < dat[0].size(); ++col)
68 mathed_parse_cell(cell(index(row, col)), dat[row][col]);
72 auto_ptr<InsetBase> MathArrayInset::doClone() const
74 return auto_ptr<InsetBase>(new MathArrayInset(*this));
78 void MathArrayInset::metrics(MetricsInfo & mi, Dimension & dim) const
80 ArrayChanger dummy(mi.base);
81 MathGridInset::metrics(mi, dim);
85 void MathArrayInset::draw(PainterInfo & pi, int x, int y) const
87 setPosCache(pi, x, y);
88 ArrayChanger dummy(pi.base);
89 MathGridInset::draw(pi, x + 1, y);
93 void MathArrayInset::write(WriteStream & os) const
97 os << "\\begin{" << name_ << '}';
99 if (v_align_ == 't' || v_align_ == 'b')
100 os << '[' << char(v_align_) << ']';
101 os << '{' << halign() << "}\n";
103 MathGridInset::write(os);
107 os << "\\end{" << name_ << '}';
108 // adding a \n here is bad if the array is the last item
109 // in an \eqnarray...
113 void MathArrayInset::infoize(std::ostream & os) const
119 void MathArrayInset::normalize(NormalStream & os) const
121 os << '[' << name_ << ' ';
122 MathGridInset::normalize(os);
127 void MathArrayInset::maple(MapleStream & os) const
130 MathGridInset::maple(os);