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