]> git.lyx.org Git - lyx.git/blob - src/mathed/math_arrayinset.C
Ensure all #warning statements are wrapped by #ifdef WITH_WARNINGS.
[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, dim);
82 }
83
84
85 void MathArrayInset::draw(PainterInfo & pi, int x, int y) const
86 {
87         setPosCache(pi, x, y);
88         ArrayChanger dummy(pi.base);
89         MathGridInset::draw(pi, x + 1, 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 }