A bit more re-organization.
[lyx.git] / src / mathed / InsetMathArray.cpp
blobfd7ceebe31c8634089204d583bd4d1ee1bcdd985
1 /**
2 * \file InsetMathArray.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author André Pönitz
8 * Full author contact details are available in file CREDITS.
9 */
11 #include <config.h>
13 #include "InsetMathArray.h"
15 #include "LaTeXFeatures.h"
16 #include "MathData.h"
17 #include "MathParser.h"
18 #include "MathStream.h"
19 #include "MetricsInfo.h"
21 #include "support/lstrings.h"
23 #include <iterator>
24 #include <sstream>
26 using namespace std;
28 namespace lyx {
31 InsetMathArray::InsetMathArray(Buffer * buf, docstring const & name, int m,
32 int n)
33 : InsetMathGrid(buf, m, n), name_(name)
37 InsetMathArray::InsetMathArray(Buffer * buf, docstring const & name, int m,
38 int n, char valign, docstring const & halign)
39 : InsetMathGrid(buf, m, n, valign, halign), name_(name)
43 InsetMathArray::InsetMathArray(Buffer * buf, docstring const & name,
44 docstring const & str)
45 : InsetMathGrid(buf, 1, 1), name_(name)
47 vector< vector<string> > dat;
48 istringstream is(to_utf8(str));
49 string line;
50 while (getline(is, line)) {
51 istringstream ls(line);
52 typedef istream_iterator<string> iter;
53 vector<string> v = vector<string>(iter(ls), iter());
54 if (v.size())
55 dat.push_back(v);
58 for (row_type row = 1; row < dat.size(); ++row)
59 addRow(0);
60 for (col_type col = 1; col < dat[0].size(); ++col)
61 addCol(0);
62 for (row_type row = 0; row < dat.size(); ++row)
63 for (col_type col = 0; col < dat[0].size(); ++col)
64 mathed_parse_cell(cell(index(row, col)),
65 from_utf8(dat[row][col]), Parse::NORMAL);
69 Inset * InsetMathArray::clone() const
71 return new InsetMathArray(*this);
75 void InsetMathArray::metrics(MetricsInfo & mi, Dimension & dim) const
77 ArrayChanger dummy(mi.base);
78 InsetMathGrid::metrics(mi, dim);
79 dim.wid += 6;
83 Dimension const InsetMathArray::dimension(BufferView const & bv) const
85 Dimension dim = InsetMathGrid::dimension(bv);
86 dim.wid += 6;
87 return dim;
91 void InsetMathArray::draw(PainterInfo & pi, int x, int y) const
93 setPosCache(pi, x, y);
94 ArrayChanger dummy(pi.base);
95 InsetMathGrid::drawWithMargin(pi, x, y, 4, 2);
99 void InsetMathArray::write(WriteStream & os) const
101 MathEnsurer ensurer(os);
103 if (os.fragile())
104 os << "\\protect";
105 os << "\\begin{" << name_ << '}';
107 char const v = verticalAlignment();
108 if (v == 't' || v == 'b')
109 os << '[' << v << ']';
110 os << '{' << horizontalAlignments() << "}\n";
112 InsetMathGrid::write(os);
114 if (os.fragile())
115 os << "\\protect";
116 os << "\\end{" << name_ << '}';
117 // adding a \n here is bad if the array is the last item
118 // in an \eqnarray...
122 void InsetMathArray::infoize(odocstream & os) const
124 docstring name = name_;
125 name[0] = support::uppercase(name[0]);
126 os << name << ' ';
130 void InsetMathArray::normalize(NormalStream & os) const
132 os << '[' << name_ << ' ';
133 InsetMathGrid::normalize(os);
134 os << ']';
138 void InsetMathArray::maple(MapleStream & os) const
140 os << "array(";
141 InsetMathGrid::maple(os);
142 os << ')';
146 void InsetMathArray::validate(LaTeXFeatures & features) const
148 if (name_ == "subarray")
149 features.require("amsmath");
150 InsetMathGrid::validate(features);
154 } // namespace lyx