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