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