2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file InsetMathArray.cpp
|
2003-08-19 13:00:56 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-08-19 13:00:56 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathArray.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
|
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 16:05:57 +00:00
|
|
|
#include "MathData.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "MathParser.h"
|
2006-10-22 10:15:23 +00:00
|
|
|
#include "MathStream.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
#include "MetricsInfo.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
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathArray::InsetMathArray(Buffer * buf, docstring const & name, int m,
|
|
|
|
int n)
|
|
|
|
: InsetMathGrid(buf, m, n), name_(name)
|
2001-06-25 00:06:33 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathArray::InsetMathArray(Buffer * buf, docstring const & name, int m,
|
|
|
|
int n, char valign, docstring const & halign)
|
|
|
|
: InsetMathGrid(buf, m, n, valign, halign), name_(name)
|
2001-10-12 12:02:49 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathArray::InsetMathArray(Buffer * buf, docstring const & name,
|
|
|
|
docstring const & str)
|
|
|
|
: InsetMathGrid(buf, 1, 1), name_(name)
|
2001-11-07 13:15:59 +00:00
|
|
|
{
|
|
|
|
vector< vector<string> > dat;
|
2006-10-22 10:15:23 +00:00
|
|
|
istringstream is(to_utf8(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());
|
2012-05-28 20:41:32 +00:00
|
|
|
if (!v.empty())
|
2001-11-07 13:15:59 +00:00
|
|
|
dat.push_back(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (row_type row = 1; row < dat.size(); ++row)
|
2007-11-05 20:54:28 +00:00
|
|
|
addRow(0);
|
2001-11-07 13:15:59 +00:00
|
|
|
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)
|
2009-11-06 15:18:48 +00:00
|
|
|
mathed_parse_cell(cell(index(row, col)),
|
2009-11-08 11:45:46 +00:00
|
|
|
from_utf8(dat[row][col]), Parse::NORMAL);
|
2001-11-07 13:15:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
Inset * InsetMathArray::clone() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
return new InsetMathArray(*this);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetMathArray::metrics(MetricsInfo & mi, Dimension & dim) const
|
2001-11-09 08:35:57 +00:00
|
|
|
{
|
2016-11-20 18:53:16 +00:00
|
|
|
Changer dummy = mi.base.changeArray();
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::metrics(mi, dim);
|
2002-10-02 06:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathArray::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);
|
2016-11-20 18:53:16 +00:00
|
|
|
Changer dummy = pi.base.changeArray();
|
2016-09-29 18:20:33 +00:00
|
|
|
InsetMathGrid::draw(pi, x, y);
|
2001-11-09 08:35:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathArray::write(WriteStream & os) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2008-06-17 11:10:43 +00:00
|
|
|
MathEnsurer ensurer(os);
|
2008-06-16 01:21:17 +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_ << '}';
|
2015-10-07 03:13:21 +00:00
|
|
|
bool open = os.startOuterRow();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2008-03-15 08:43:16 +00:00
|
|
|
char const v = verticalAlignment();
|
|
|
|
if (v == 't' || v == 'b')
|
|
|
|
os << '[' << v << ']';
|
|
|
|
os << '{' << horizontalAlignments() << "}\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::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_ << '}';
|
2015-10-07 03:13:21 +00:00
|
|
|
if (open)
|
|
|
|
os.startOuterRow();
|
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
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
void InsetMathArray::infoize(odocstream & os) const
|
2003-05-02 07:42:08 +00:00
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring name = name_;
|
2006-10-21 00:16:43 +00:00
|
|
|
name[0] = support::uppercase(name[0]);
|
2005-04-03 12:07:49 +00:00
|
|
|
os << name << ' ';
|
2003-05-02 07:42:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathArray::normalize(NormalStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
os << '[' << name_ << ' ';
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::normalize(os);
|
2002-11-27 10:30:28 +00:00
|
|
|
os << ']';
|
2001-11-07 08:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathArray::maple(MapleStream & os) const
|
2001-09-10 09:35:12 +00:00
|
|
|
{
|
2001-11-09 08:35:57 +00:00
|
|
|
os << "array(";
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::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
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathArray::validate(LaTeXFeatures & features) const
|
2005-03-30 09:05:30 +00:00
|
|
|
{
|
|
|
|
if (name_ == "subarray")
|
|
|
|
features.require("amsmath");
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::validate(features);
|
2005-03-30 09:05:30 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|