]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathArray.C
cursor is no more damaging the background. L-shaped cursor is broken right now....
[lyx.git] / src / mathed / InsetMathArray.C
1 /**
2  * \file InsetMathArray.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 "LaTeXFeatures.h"
14 #include "InsetMathArray.h"
15 #include "MathData.h"
16 #include "MathParser.h"
17 #include "MathStream.h"
18 #include "MathStream.h"
19
20 #include "support/lstrings.h"
21
22 #include <iterator>
23 #include <sstream>
24
25
26 namespace lyx {
27
28 using std::getline;
29 using std::auto_ptr;
30 using std::istringstream;
31 using std::istream_iterator;
32 using std::vector;
33 using std::string;
34
35
36 InsetMathArray::InsetMathArray(docstring const & name, int m, int n)
37         : InsetMathGrid(m, n), name_(name)
38 {}
39
40
41 InsetMathArray::InsetMathArray(docstring const & name, int m, int n,
42                 char valign, docstring const & halign)
43         : InsetMathGrid(m, n, valign, halign), name_(name)
44 {}
45
46
47 InsetMathArray::InsetMathArray(docstring const & name, char valign,
48                 docstring const & halign)
49         : InsetMathGrid(valign, halign), name_(name)
50 {}
51
52
53 InsetMathArray::InsetMathArray(docstring const & name, docstring const & str)
54         : InsetMathGrid(1, 1), name_(name)
55 {
56         vector< vector<string> > dat;
57         istringstream is(to_utf8(str));
58         string line;
59         while (getline(is, line)) {
60                 istringstream ls(line);
61                 typedef istream_iterator<string> iter;
62                 vector<string> v = vector<string>(iter(ls), iter());
63                 if (v.size())
64                         dat.push_back(v);
65         }
66
67         for (row_type row = 1; row < dat.size(); ++row)
68                 addRow(0);
69         for (col_type col = 1; col < dat[0].size(); ++col)
70                 addCol(0);
71         for (row_type row = 0; row < dat.size(); ++row)
72                 for (col_type col = 0; col < dat[0].size(); ++col)
73                         mathed_parse_cell(cell(index(row, col)), from_utf8(dat[row][col]));
74 }
75
76
77 auto_ptr<InsetBase> InsetMathArray::doClone() const
78 {
79         return auto_ptr<InsetBase>(new InsetMathArray(*this));
80 }
81
82
83 void InsetMathArray::metrics(MetricsInfo & mi, Dimension & dim) const
84 {
85         ArrayChanger dummy(mi.base);
86         InsetMathGrid::metrics(mi, dim);
87         dim.wid += 6;
88         dim_ = dim;
89 }
90
91
92 void InsetMathArray::draw(PainterInfo & pi, int x, int y) const
93 {
94         setPosCache(pi, x, y);
95         ArrayChanger dummy(pi.base);
96         InsetMathGrid::drawWithMargin(pi, x, y, 4, 2);
97 }
98
99
100 void InsetMathArray::write(WriteStream & os) const
101 {
102         if (os.fragile())
103                 os << "\\protect";
104         os << "\\begin{" << name_ << '}';
105
106         if (v_align_ == 't' || v_align_ == 'b')
107                 os << '[' << char(v_align_) << ']';
108         os << '{' << halign() << "}\n";
109
110         InsetMathGrid::write(os);
111
112         if (os.fragile())
113                 os << "\\protect";
114         os << "\\end{" << name_ << '}';
115         // adding a \n here is bad if the array is the last item
116         // in an \eqnarray...
117 }
118
119
120 void InsetMathArray::infoize(odocstream & os) const
121 {
122         docstring name = name_;
123         name[0] = support::uppercase(name[0]);
124         os << name << ' ';
125 }
126
127
128 void InsetMathArray::normalize(NormalStream & os) const
129 {
130         os << '[' << name_ << ' ';
131         InsetMathGrid::normalize(os);
132         os << ']';
133 }
134
135
136 void InsetMathArray::maple(MapleStream & os) const
137 {
138         os << "array(";
139         InsetMathGrid::maple(os);
140         os << ')';
141 }
142
143
144 void InsetMathArray::validate(LaTeXFeatures & features) const
145 {
146         if (name_ == "subarray")
147                 features.require("amsmath");
148         InsetMathGrid::validate(features);
149 }
150
151
152 } // namespace lyx