2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file math_arrayinset.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
2001-12-05 08:04:20 +00:00
|
|
|
|
|
2003-08-19 13:00:56 +00:00
|
|
|
|
#include <config.h>
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2005-03-30 09:05:30 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "math_arrayinset.h"
|
2003-09-07 21:25:37 +00:00
|
|
|
|
#include "math_data.h"
|
2001-11-07 13:15:59 +00:00
|
|
|
|
#include "math_parser.h"
|
2001-11-08 12:06:56 +00:00
|
|
|
|
#include "math_mathmlstream.h"
|
2001-12-05 08:04:20 +00:00
|
|
|
|
#include "math_streamstr.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2005-04-03 12:07:49 +00:00
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
2001-12-05 08:04:20 +00:00
|
|
|
|
#include <iterator>
|
2004-07-24 10:55:30 +00:00
|
|
|
|
#include <sstream>
|
2001-12-05 08:04:20 +00:00
|
|
|
|
|
2001-11-20 16:05:17 +00:00
|
|
|
|
using std::getline;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using std::auto_ptr;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::istringstream;
|
|
|
|
|
using std::istream_iterator;
|
|
|
|
|
using std::vector;
|
2001-11-08 06:42:20 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2002-02-14 14:52:23 +00:00
|
|
|
|
MathArrayInset::MathArrayInset(string const & name, int m, int n)
|
|
|
|
|
: MathGridInset(m, n), name_(name)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2002-02-14 14:52:23 +00:00
|
|
|
|
MathArrayInset::MathArrayInset(string const & name, int m, int n,
|
|
|
|
|
char valign, string const & halign)
|
|
|
|
|
: MathGridInset(m, n, valign, halign), name_(name)
|
2001-10-12 12:02:49 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2002-02-14 14:52:23 +00:00
|
|
|
|
MathArrayInset::MathArrayInset(string const & name, char valign,
|
|
|
|
|
string const & halign)
|
|
|
|
|
: MathGridInset(valign, halign), name_(name)
|
2001-11-28 13:09:40 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2002-02-14 14:52:23 +00:00
|
|
|
|
MathArrayInset::MathArrayInset(string const & name, string const & str)
|
|
|
|
|
: MathGridInset(1, 1), name_(name)
|
2001-11-07 13:15:59 +00:00
|
|
|
|
{
|
|
|
|
|
vector< vector<string> > dat;
|
2003-09-15 11:00:00 +00:00
|
|
|
|
istringstream is(str);
|
2002-04-26 06:13:30 +00:00
|
|
|
|
string line;
|
|
|
|
|
while (getline(is, line)) {
|
2003-09-15 11:00:00 +00:00
|
|
|
|
istringstream ls(line);
|
2002-02-16 15:59:55 +00:00
|
|
|
|
typedef istream_iterator<string> iter;
|
2001-11-07 13:15:59 +00:00
|
|
|
|
vector<string> v = vector<string>(iter(ls), iter());
|
|
|
|
|
if (v.size())
|
|
|
|
|
dat.push_back(v);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (row_type row = 1; row < dat.size(); ++row)
|
|
|
|
|
addRow(0);
|
|
|
|
|
for (col_type col = 1; col < dat[0].size(); ++col)
|
|
|
|
|
addCol(0);
|
|
|
|
|
for (row_type row = 0; row < dat.size(); ++row)
|
2002-04-25 05:58:55 +00:00
|
|
|
|
for (col_type col = 0; col < dat[0].size(); ++col)
|
2001-11-07 13:15:59 +00:00
|
|
|
|
mathed_parse_cell(cell(index(row, col)), dat[row][col]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-23 23:04:52 +00:00
|
|
|
|
auto_ptr<InsetBase> MathArrayInset::doClone() const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new MathArrayInset(*this));
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
void MathArrayInset::metrics(MetricsInfo & mi, Dimension & dim) const
|
2001-11-09 08:35:57 +00:00
|
|
|
|
{
|
2003-03-21 14:20:48 +00:00
|
|
|
|
ArrayChanger dummy(mi.base);
|
2004-04-06 19:25:39 +00:00
|
|
|
|
MathGridInset::metrics(mi, dim);
|
2005-04-26 11:12:20 +00:00
|
|
|
|
dim.wid += 6;
|
2005-04-04 22:11:53 +00:00
|
|
|
|
dim_ = dim;
|
2002-10-02 06:38:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
void MathArrayInset::draw(PainterInfo & pi, int x, int y) const
|
2002-10-02 06:38:49 +00:00
|
|
|
|
{
|
2004-04-07 16:54:15 +00:00
|
|
|
|
setPosCache(pi, x, y);
|
2003-03-21 14:20:48 +00:00
|
|
|
|
ArrayChanger dummy(pi.base);
|
2005-04-04 22:11:53 +00:00
|
|
|
|
MathGridInset::drawWithMargin(pi, x, y, 4, 2);
|
2001-11-09 08:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathArrayInset::write(WriteStream & os) const
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
|
if (os.fragile())
|
2001-06-25 00:06:33 +00:00
|
|
|
|
os << "\\protect";
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "\\begin{" << name_ << '}';
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
|
if (v_align_ == 't' || v_align_ == 'b')
|
2001-06-25 00:06:33 +00:00
|
|
|
|
os << '[' << char(v_align_) << ']';
|
2001-12-05 08:04:20 +00:00
|
|
|
|
os << '{' << halign() << "}\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2001-10-19 11:25:48 +00:00
|
|
|
|
MathGridInset::write(os);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
|
if (os.fragile())
|
2001-06-25 00:06:33 +00:00
|
|
|
|
os << "\\protect";
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "\\end{" << name_ << '}';
|
2002-09-25 12:49:55 +00:00
|
|
|
|
// adding a \n here is bad if the array is the last item
|
|
|
|
|
// in an \eqnarray...
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
2001-09-10 09:35:12 +00:00
|
|
|
|
|
|
|
|
|
|
2003-05-02 07:42:08 +00:00
|
|
|
|
void MathArrayInset::infoize(std::ostream & os) const
|
|
|
|
|
{
|
2005-04-03 12:07:49 +00:00
|
|
|
|
string name = name_;
|
|
|
|
|
name[0] = lyx::support::uppercase(name[0]);
|
|
|
|
|
os << name << ' ';
|
2003-05-02 07:42:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
|
void MathArrayInset::normalize(NormalStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '[' << name_ << ' ';
|
2001-11-09 08:35:57 +00:00
|
|
|
|
MathGridInset::normalize(os);
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << ']';
|
2001-11-07 08:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-14 14:30:09 +00:00
|
|
|
|
void MathArrayInset::maple(MapleStream & os) const
|
2001-09-10 09:35:12 +00:00
|
|
|
|
{
|
2001-11-09 08:35:57 +00:00
|
|
|
|
os << "array(";
|
2003-02-14 14:30:09 +00:00
|
|
|
|
MathGridInset::maple(os);
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << ')';
|
2001-09-10 09:35:12 +00:00
|
|
|
|
}
|
2005-03-30 09:05:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MathArrayInset::validate(LaTeXFeatures & features) const
|
|
|
|
|
{
|
|
|
|
|
if (name_ == "subarray")
|
|
|
|
|
features.require("amsmath");
|
|
|
|
|
MathGridInset::validate(features);
|
|
|
|
|
}
|