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