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