]> git.lyx.org Git - lyx.git/blob - src/mathed/math_arrayinset.C
don't draw spaces...
[lyx.git] / src / mathed / math_arrayinset.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "math_arrayinset.h"
8 #include "math_parser.h"
9 #include "math_mathmlstream.h"
10 #include "math_streamstr.h"
11 #include "Lsstream.h"
12
13 #include <iterator>
14
15 using std::vector;
16 using std::istringstream;
17 using std::getline;
18 using std::istream_iterator;
19
20
21 MathArrayInset::MathArrayInset(string const & name, int m, int n)
22         : MathGridInset(m, n), name_(name)
23 {}
24
25
26 MathArrayInset::MathArrayInset(string const & name, int m, int n,
27                 char valign, string const & halign)
28         : MathGridInset(m, n, valign, halign), name_(name)
29 {}
30
31
32 MathArrayInset::MathArrayInset(string const & name, char valign,
33                 string const & halign)
34         : MathGridInset(valign, halign), name_(name)
35 {}
36
37
38 MathArrayInset::MathArrayInset(string const & name, string const & str)
39         : MathGridInset(1, 1), name_(name)
40 {
41         vector< vector<string> > dat;
42         istringstream is(str.c_str());
43         while (is) {
44                 string line;
45                 getline(is, line);
46                 istringstream ls(line.c_str());
47                 typedef istream_iterator<string> iter;
48                 vector<string> v = vector<string>(iter(ls), iter());
49                 if (v.size())
50                         dat.push_back(v);
51         }
52
53         for (row_type row = 1; row < dat.size(); ++row)
54                 addRow(0);
55         for (col_type col = 1; col < dat[0].size(); ++col)
56                 addCol(0);
57         for (row_type row = 0; row < dat.size(); ++row)
58                 for (col_type col = 0; col < dat[row].size(); ++col)
59                         mathed_parse_cell(cell(index(row, col)), dat[row][col]);
60 }
61
62
63 MathInset * MathArrayInset::clone() const
64 {
65         return new MathArrayInset(*this);
66 }
67
68
69 void MathArrayInset::metrics(MathMetricsInfo const & st) const
70 {
71         MathMetricsInfo mi = st;
72         if (mi.style == LM_ST_DISPLAY)
73                 mi.style = LM_ST_TEXT;
74         MathGridInset::metrics(mi);
75 }
76
77
78 void MathArrayInset::write(WriteStream & os) const
79 {
80         if (os.fragile())
81                 os << "\\protect";
82         os << "\\begin{" << name_ << "}";
83
84         if (v_align_ == 't' || v_align_ == 'b') 
85                 os << '[' << char(v_align_) << ']';
86         os << '{' << halign() << "}\n";
87
88         MathGridInset::write(os);
89
90         if (os.fragile())
91                 os << "\\protect";
92         os << "\\end{" << name_ << "}\n";
93 }
94
95
96 void MathArrayInset::normalize(NormalStream & os) const
97 {
98         os << "[" << name_ << " ";
99         MathGridInset::normalize(os);
100         os << "]";
101 }
102
103
104 void MathArrayInset::maplize(MapleStream & os) const
105 {
106         os << "array(";
107         MathGridInset::maplize(os);
108         os << ")";
109 }