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