2001-02-26 12:53:35 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-06-27 15:33:55 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
#include "math_matrixinset.h"
|
2001-08-09 09:19:18 +00:00
|
|
|
#include "support.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "debug.h"
|
2001-02-14 15:00:50 +00:00
|
|
|
#include "support/LOstream.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "Painter.h"
|
|
|
|
#include "LaTeXFeatures.h"
|
2001-02-14 15:00:50 +00:00
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
namespace {
|
|
|
|
|
2001-10-18 13:21:21 +00:00
|
|
|
int getCols(MathInsetTypes type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case LM_OT_EQNARRAY:
|
|
|
|
return 3;
|
|
|
|
case LM_OT_ALIGN:
|
|
|
|
case LM_OT_ALIGNAT:
|
|
|
|
case LM_OT_XALIGNAT:
|
|
|
|
case LM_OT_XXALIGNAT:
|
|
|
|
return 2;
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2001-10-18 13:21:21 +00:00
|
|
|
|
|
|
|
// returns position of first relation operator in the array
|
|
|
|
// used for "intelligent splitting"
|
|
|
|
int firstRelOp(MathArray const & ar)
|
|
|
|
{
|
|
|
|
for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
|
|
|
|
if ((*it)->isRelOp())
|
|
|
|
return it - ar.begin();
|
|
|
|
return ar.size();
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
|
2001-10-18 13:21:21 +00:00
|
|
|
char const * star(bool numbered)
|
|
|
|
{
|
|
|
|
return numbered ? "" : "*";
|
|
|
|
}
|
2001-07-09 16:59:57 +00:00
|
|
|
|
2001-10-18 13:21:21 +00:00
|
|
|
MathInsetTypes typecode(string const & s)
|
|
|
|
{
|
|
|
|
if (s == "equation") return LM_OT_EQUATION;
|
|
|
|
if (s == "display") return LM_OT_EQUATION;
|
|
|
|
if (s == "eqnarray") return LM_OT_EQNARRAY;
|
|
|
|
if (s == "align") return LM_OT_ALIGN;
|
|
|
|
if (s == "alignat") return LM_OT_ALIGNAT;
|
|
|
|
if (s == "xalignat") return LM_OT_XALIGNAT;
|
|
|
|
if (s == "xxalignat") return LM_OT_XXALIGNAT;
|
|
|
|
if (s == "multline") return LM_OT_MULTLINE;
|
|
|
|
if (s == "gather") return LM_OT_GATHER;
|
|
|
|
return LM_OT_SIMPLE;
|
|
|
|
}
|
2001-09-04 13:32:06 +00:00
|
|
|
|
|
|
|
|
2001-10-18 13:21:21 +00:00
|
|
|
string normalName(MathInsetTypes t)
|
|
|
|
{
|
|
|
|
switch (t) {
|
|
|
|
case LM_OT_EQUATION: return "equation";
|
|
|
|
case LM_OT_EQNARRAY: return "eqnarray";
|
|
|
|
case LM_OT_ALIGN: return "align";
|
|
|
|
case LM_OT_ALIGNAT: return "alignat";
|
|
|
|
case LM_OT_XALIGNAT: return "xalignat";
|
|
|
|
case LM_OT_XXALIGNAT: return "xxalignat";
|
|
|
|
case LM_OT_MULTLINE: return "multline";
|
|
|
|
case LM_OT_GATHER: return "gather";
|
|
|
|
case LM_OT_SIMPLE: return "simple";
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end anon namespace
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-09-04 08:48:23 +00:00
|
|
|
|
|
|
|
MathMatrixInset::MathMatrixInset()
|
|
|
|
: MathGridInset(1, 1), objtype_(LM_OT_SIMPLE), nonum_(1), label_(1)
|
2001-09-04 13:32:06 +00:00
|
|
|
{
|
|
|
|
setDefaults();
|
|
|
|
}
|
2001-09-04 08:48:23 +00:00
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathMatrixInset::MathMatrixInset(MathInsetTypes t)
|
2001-08-08 17:26:30 +00:00
|
|
|
: MathGridInset(getCols(t), 1), objtype_(t), nonum_(1), label_(1)
|
2001-08-02 09:59:09 +00:00
|
|
|
{
|
2001-09-04 13:32:06 +00:00
|
|
|
setDefaults();
|
2001-08-02 09:59:09 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
MathMatrixInset::MathMatrixInset(MathInsetTypes t, col_type cols)
|
2001-09-04 08:48:23 +00:00
|
|
|
: MathGridInset(cols, 1), objtype_(t), nonum_(1), label_(1)
|
|
|
|
{
|
2001-09-04 13:32:06 +00:00
|
|
|
setDefaults();
|
2001-09-04 08:48:23 +00:00
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
MathInset * MathMatrixInset::clone() const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return new MathMatrixInset(*this);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
char MathMatrixInset::defaultColAlign(col_type col)
|
2001-09-04 13:32:06 +00:00
|
|
|
{
|
|
|
|
switch (getType()) {
|
|
|
|
case LM_OT_ALIGN:
|
|
|
|
case LM_OT_ALIGNAT:
|
|
|
|
case LM_OT_XALIGNAT:
|
|
|
|
case LM_OT_XXALIGNAT:
|
|
|
|
return "rl"[col & 1];
|
|
|
|
case LM_OT_EQNARRAY:
|
|
|
|
return "rcl"[col];
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
return 'c';
|
|
|
|
}
|
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
int MathMatrixInset::defaultColSpace(col_type col)
|
2001-09-04 13:32:06 +00:00
|
|
|
{
|
|
|
|
switch (getType()) {
|
|
|
|
case LM_OT_ALIGN:
|
|
|
|
case LM_OT_ALIGNAT:
|
|
|
|
return 0;
|
|
|
|
case LM_OT_XALIGNAT:
|
|
|
|
return (col & 1) ? 20 : 0;
|
|
|
|
case LM_OT_XXALIGNAT:
|
|
|
|
return (col & 1) ? 40 : 0;
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-22 15:37:49 +00:00
|
|
|
void MathMatrixInset::metrics(MathMetricsInfo const & mi) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-10-22 15:37:49 +00:00
|
|
|
mi_ = mi;
|
|
|
|
mi_.style = (getType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY;
|
2001-07-06 12:09:32 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
// let the cells adjust themselves
|
2001-10-22 15:37:49 +00:00
|
|
|
MathGridInset::metrics(mi_);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
if (display()) {
|
|
|
|
ascent_ += 12;
|
|
|
|
descent_ += 12;
|
|
|
|
}
|
2001-03-06 17:44:53 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
if (numberedType()) {
|
|
|
|
int l = 0;
|
2001-09-26 16:52:34 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
2001-10-22 15:37:49 +00:00
|
|
|
l = std::max(l, mathed_string_width(LM_TC_BF, mi_, nicelabel(row)));
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
if (l)
|
|
|
|
width_ += 30 + l;
|
2001-02-16 09:25:43 +00:00
|
|
|
}
|
2001-09-03 11:38:04 +00:00
|
|
|
|
|
|
|
// make it at least as high as the current font
|
|
|
|
int asc = 0;
|
|
|
|
int des = 0;
|
2001-10-22 15:37:49 +00:00
|
|
|
math_font_max_dim(LM_TC_TEXTRM, mi_, asc, des);
|
2001-09-03 11:38:04 +00:00
|
|
|
ascent_ = std::max(ascent_, asc);
|
|
|
|
descent_ = std::max(descent_, des);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2001-08-06 17:20:26 +00:00
|
|
|
void MathMatrixInset::draw(Painter & pain, int x, int y) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
MathGridInset::draw(pain, x, y);
|
|
|
|
|
|
|
|
if (numberedType()) {
|
2001-10-19 17:46:13 +00:00
|
|
|
int const xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20;
|
2001-09-26 16:52:34 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
2001-10-19 17:46:13 +00:00
|
|
|
int const yy = y + rowinfo_[row].offset_;
|
2001-10-22 15:37:49 +00:00
|
|
|
drawStr(pain, LM_TC_BF, mi_, xx, yy, nicelabel(row));
|
2001-07-20 14:54:13 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-19 11:25:48 +00:00
|
|
|
void MathMatrixInset::write(MathWriteInfo & os) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-10-19 11:25:48 +00:00
|
|
|
header_write(os.os);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
bool n = numberedType();
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
2001-10-19 11:25:48 +00:00
|
|
|
for (col_type col = 0; col < ncols(); ++col)
|
|
|
|
os << cell(index(row, col)) << eocString(col);
|
2001-06-25 00:06:33 +00:00
|
|
|
if (n) {
|
|
|
|
if (!label_[row].empty())
|
|
|
|
os << "\\label{" << label_[row] << "}";
|
|
|
|
if (nonum_[row])
|
|
|
|
os << "\\nonumber ";
|
2001-02-16 09:25:43 +00:00
|
|
|
}
|
2001-08-10 10:39:56 +00:00
|
|
|
os << eolString(row);
|
2001-02-16 09:25:43 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-10-19 11:25:48 +00:00
|
|
|
footer_write(os.os);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-18 13:21:21 +00:00
|
|
|
void MathMatrixInset::writeNormal(std::ostream & os) const
|
|
|
|
{
|
|
|
|
os << "[formula " << normalName(getType()) << " ";
|
|
|
|
MathGridInset::writeNormal(os);
|
|
|
|
os << "] ";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
string MathMatrixInset::label(row_type row) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
return label_[row];
|
|
|
|
}
|
|
|
|
|
2001-09-04 08:48:23 +00:00
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
void MathMatrixInset::label(row_type row, string const & label)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
label_[row] = label;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
void MathMatrixInset::numbered(row_type row, bool num)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
nonum_[row] = !num;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
bool MathMatrixInset::numbered(row_type row) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
return !nonum_[row];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathMatrixInset::ams() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathMatrixInset::display() const
|
|
|
|
{
|
2001-07-26 06:56:43 +00:00
|
|
|
return getType() != LM_OT_SIMPLE;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 15:33:55 +00:00
|
|
|
std::vector<string> const MathMatrixInset::getLabelList() const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
std::vector<string> res;
|
2001-09-26 16:52:34 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!label_[row].empty() && nonum_[row] != 1)
|
|
|
|
res.push_back(label_[row]);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathMatrixInset::numberedType() const
|
|
|
|
{
|
2001-09-04 14:56:30 +00:00
|
|
|
if (getType() == LM_OT_SIMPLE || getType() == LM_OT_XXALIGNAT)
|
2001-06-25 00:06:33 +00:00
|
|
|
return false;
|
2001-09-26 16:52:34 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
2001-06-25 00:06:33 +00:00
|
|
|
if (!nonum_[row])
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
void MathMatrixInset::validate(LaTeXFeatures & features) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
features.amsstyle = ams();
|
|
|
|
|
|
|
|
// Validation is necessary only if not using AMS math.
|
2001-07-26 06:56:43 +00:00
|
|
|
// To be safe, we will always run mathedvalidate.
|
2001-06-25 00:06:33 +00:00
|
|
|
//if (features.amsstyle)
|
|
|
|
// return;
|
|
|
|
|
|
|
|
features.boldsymbol = true;
|
2001-07-13 14:54:56 +00:00
|
|
|
//features.binom = true;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-08-03 17:10:22 +00:00
|
|
|
MathNestInset::validate(features);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 15:33:55 +00:00
|
|
|
void MathMatrixInset::header_write(std::ostream & os) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
bool n = numberedType();
|
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
switch (getType()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
case LM_OT_SIMPLE:
|
2001-07-27 09:55:44 +00:00
|
|
|
os << '$';
|
|
|
|
if (cell(0).empty())
|
|
|
|
os << ' ';
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_EQUATION:
|
|
|
|
if (n)
|
|
|
|
os << "\\begin{equation" << star(n) << "}\n";
|
|
|
|
else
|
|
|
|
os << "\\[\n";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_EQNARRAY:
|
|
|
|
os << "\\begin{eqnarray" << star(n) << "}\n";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_ALIGN:
|
2001-09-28 20:23:49 +00:00
|
|
|
os << "\\begin{align" << star(n) << "}\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_ALIGNAT:
|
2001-09-04 13:32:06 +00:00
|
|
|
os << "\\begin{alignat" << star(n) << "}" << "{" << ncols()/2 << "}\n";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_XALIGNAT:
|
|
|
|
os << "\\begin{xalignat" << star(n) << "}" << "{" << ncols()/2 << "}\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
2001-09-04 13:32:06 +00:00
|
|
|
|
|
|
|
case LM_OT_XXALIGNAT:
|
|
|
|
os << "\\begin{xxalignat}" << "{" << ncols()/2 << "}\n";
|
|
|
|
break;
|
|
|
|
|
2001-09-04 14:56:30 +00:00
|
|
|
case LM_OT_MULTLINE:
|
|
|
|
os << "\\begin{multline}\n";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_GATHER:
|
|
|
|
os << "\\begin{gather}\n";
|
|
|
|
break;
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
default:
|
|
|
|
os << "\\begin{unknown" << star(n) << "}";
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 15:33:55 +00:00
|
|
|
void MathMatrixInset::footer_write(std::ostream & os) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
bool n = numberedType();
|
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
switch (getType()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
case LM_OT_SIMPLE:
|
2001-07-27 09:55:44 +00:00
|
|
|
os << '$';
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_EQUATION:
|
|
|
|
if (n)
|
|
|
|
os << "\\end{equation" << star(n) << "}\n";
|
|
|
|
else
|
|
|
|
os << "\\]\n";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_EQNARRAY:
|
2001-09-28 20:23:49 +00:00
|
|
|
os << "\n\\end{eqnarray" << star(n) << "}\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_ALIGN:
|
2001-09-28 20:23:49 +00:00
|
|
|
os << "\n\\end{align" << star(n) << "}\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_ALIGNAT:
|
2001-09-28 20:23:49 +00:00
|
|
|
os << "\n\\end{alignat" << star(n) << "}\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
2001-07-06 12:09:32 +00:00
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
case LM_OT_XALIGNAT:
|
2001-09-28 20:23:49 +00:00
|
|
|
os << "\n\\end{xalignat" << star(n) << "}\n";
|
2001-09-04 13:32:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_XXALIGNAT:
|
2001-09-28 20:23:49 +00:00
|
|
|
os << "\n\\end{xxalignat}\n";
|
2001-09-04 13:32:06 +00:00
|
|
|
break;
|
|
|
|
|
2001-09-04 14:56:30 +00:00
|
|
|
case LM_OT_MULTLINE:
|
2001-09-28 20:23:49 +00:00
|
|
|
os << "\n\\end{multline}\n";
|
2001-09-04 14:56:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_GATHER:
|
2001-09-28 20:23:49 +00:00
|
|
|
os << "\n\\end{gather}\n";
|
2001-09-04 14:56:30 +00:00
|
|
|
break;
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
default:
|
|
|
|
os << "\\end{unknown" << star(n) << "}";
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
void MathMatrixInset::addRow(row_type row)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
nonum_.insert(nonum_.begin() + row + 1, !numberedType());
|
|
|
|
label_.insert(label_.begin() + row + 1, string());
|
|
|
|
MathGridInset::addRow(row);
|
|
|
|
}
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathMatrixInset::appendRow()
|
|
|
|
{
|
|
|
|
nonum_.push_back(!numberedType());
|
|
|
|
label_.push_back(string());
|
|
|
|
MathGridInset::appendRow();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
void MathMatrixInset::delRow(row_type row)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
MathGridInset::delRow(row);
|
|
|
|
nonum_.erase(nonum_.begin() + row);
|
|
|
|
label_.erase(label_.begin() + row);
|
|
|
|
}
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
void MathMatrixInset::addCol(col_type col)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-26 06:56:43 +00:00
|
|
|
switch (getType()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
case LM_OT_EQUATION:
|
|
|
|
mutate(LM_OT_EQNARRAY);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_EQNARRAY:
|
|
|
|
mutate(LM_OT_ALIGN);
|
|
|
|
addCol(col);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_ALIGN:
|
2001-09-04 13:32:06 +00:00
|
|
|
mutate(LM_OT_ALIGNAT);
|
|
|
|
addCol(col);
|
|
|
|
break;
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
case LM_OT_ALIGNAT:
|
2001-09-04 13:32:06 +00:00
|
|
|
case LM_OT_XALIGNAT:
|
|
|
|
case LM_OT_XXALIGNAT:
|
2001-06-25 00:06:33 +00:00
|
|
|
MathGridInset::addCol(col);
|
2001-09-04 13:32:06 +00:00
|
|
|
MathGridInset::addCol(col + 1);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
void MathMatrixInset::delCol(col_type col)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-26 06:56:43 +00:00
|
|
|
switch (getType()) {
|
2001-09-04 13:32:06 +00:00
|
|
|
case LM_OT_ALIGNAT:
|
|
|
|
case LM_OT_XALIGNAT:
|
|
|
|
case LM_OT_XXALIGNAT:
|
|
|
|
MathGridInset::delCol(col + 1);
|
2001-06-25 00:06:33 +00:00
|
|
|
MathGridInset::delCol(col);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-26 16:52:34 +00:00
|
|
|
string MathMatrixInset::nicelabel(row_type row) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
if (nonum_[row])
|
|
|
|
return string();
|
|
|
|
if (label_[row].empty())
|
|
|
|
return string("(#)");
|
|
|
|
return "(" + label_[row] + ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathMatrixInset::mutate(string const & newtype)
|
|
|
|
{
|
|
|
|
if (newtype == "dump") {
|
|
|
|
dump();
|
|
|
|
return;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
2001-07-26 06:56:43 +00:00
|
|
|
//lyxerr << "mutating from '" << getType() << "' to '" << newtype << "'\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
mutate(typecode(newtype));
|
|
|
|
}
|
|
|
|
|
2001-09-26 15:20:45 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathMatrixInset::glueall()
|
|
|
|
{
|
|
|
|
MathArray ar;
|
2001-09-26 16:52:34 +00:00
|
|
|
for (idx_type i = 0; i < nargs(); ++i)
|
2001-06-25 00:06:33 +00:00
|
|
|
ar.push_back(cell(i));
|
|
|
|
*this = MathMatrixInset(LM_OT_SIMPLE);
|
|
|
|
cell(0) = ar;
|
|
|
|
}
|
|
|
|
|
2001-08-01 13:28:45 +00:00
|
|
|
|
|
|
|
MathInsetTypes MathMatrixInset::getType() const
|
|
|
|
{
|
|
|
|
return objtype_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathMatrixInset::setType(MathInsetTypes t)
|
|
|
|
{
|
|
|
|
objtype_ = t;
|
2001-09-04 13:32:06 +00:00
|
|
|
setDefaults();
|
2001-08-01 13:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
void MathMatrixInset::mutate(MathInsetTypes newtype)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2001-07-26 06:56:43 +00:00
|
|
|
//lyxerr << "mutating from '" << getType() << "' to '" << newtype << "'\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
if (newtype == getType())
|
2001-06-25 00:06:33 +00:00
|
|
|
return;
|
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
switch (getType()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
case LM_OT_SIMPLE:
|
2001-07-26 06:56:43 +00:00
|
|
|
setType(LM_OT_EQUATION);
|
2001-07-13 12:43:24 +00:00
|
|
|
numbered(0, false);
|
2001-06-25 00:06:33 +00:00
|
|
|
mutate(newtype);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_EQUATION:
|
|
|
|
switch (newtype) {
|
|
|
|
case LM_OT_SIMPLE:
|
2001-07-26 06:56:43 +00:00
|
|
|
setType(LM_OT_SIMPLE);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
case LM_OT_ALIGN:
|
|
|
|
case LM_OT_ALIGNAT:
|
|
|
|
case LM_OT_XALIGNAT:
|
|
|
|
case LM_OT_XXALIGNAT: {
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathGridInset::addCol(1);
|
2001-07-09 16:59:57 +00:00
|
|
|
|
|
|
|
// split it "nicely"
|
2001-09-26 16:52:34 +00:00
|
|
|
pos_type pos = firstRelOp(cell(0));
|
2001-07-09 16:59:57 +00:00
|
|
|
cell(1) = cell(0);
|
|
|
|
cell(0).erase(pos, cell(0).size());
|
|
|
|
cell(1).erase(0, pos);
|
2001-07-26 06:56:43 +00:00
|
|
|
setType(LM_OT_ALIGN);
|
2001-09-04 13:32:06 +00:00
|
|
|
mutate(newtype);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
2001-07-09 16:59:57 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-07-09 16:59:57 +00:00
|
|
|
case LM_OT_EQNARRAY:
|
2001-06-25 00:06:33 +00:00
|
|
|
default:
|
|
|
|
MathGridInset::addCol(1);
|
|
|
|
MathGridInset::addCol(1);
|
2001-07-09 16:59:57 +00:00
|
|
|
|
|
|
|
// split it "nicely" on the firest relop
|
2001-09-26 16:52:34 +00:00
|
|
|
pos_type pos = firstRelOp(cell(0));
|
2001-07-09 16:59:57 +00:00
|
|
|
cell(1) = cell(0);
|
2001-08-07 12:02:21 +00:00
|
|
|
cell(0).erase(pos, cell(0).size());
|
|
|
|
cell(1).erase(0, pos);
|
|
|
|
|
|
|
|
if (cell(1).size()) {
|
|
|
|
cell(2) = cell(1);
|
|
|
|
cell(1).erase(1, cell(1).size());
|
|
|
|
cell(2).erase(0);
|
|
|
|
}
|
2001-07-09 16:59:57 +00:00
|
|
|
|
2001-07-26 06:56:43 +00:00
|
|
|
setType(LM_OT_EQNARRAY);
|
2001-06-25 00:06:33 +00:00
|
|
|
mutate(newtype);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_EQNARRAY:
|
|
|
|
switch (newtype) {
|
|
|
|
case LM_OT_SIMPLE:
|
2001-07-09 10:19:50 +00:00
|
|
|
case LM_OT_EQUATION: {
|
2001-07-09 16:59:57 +00:00
|
|
|
// set correct (no)numbering
|
2001-07-09 10:19:50 +00:00
|
|
|
bool allnonum = true;
|
2001-09-26 16:52:34 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
2001-09-26 15:20:45 +00:00
|
|
|
if (!nonum_[row])
|
2001-07-09 10:19:50 +00:00
|
|
|
allnonum = false;
|
|
|
|
}
|
2001-07-09 16:42:22 +00:00
|
|
|
|
2001-07-09 16:59:57 +00:00
|
|
|
// set first non-empty label
|
2001-07-09 16:42:22 +00:00
|
|
|
string label;
|
2001-09-26 16:52:34 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
2001-09-26 15:20:45 +00:00
|
|
|
if (!label_[row].empty()) {
|
|
|
|
label = label_[row];
|
2001-07-09 16:42:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
glueall();
|
2001-07-10 10:40:23 +00:00
|
|
|
|
|
|
|
nonum_[0] = allnonum;
|
|
|
|
label_[0] = label;
|
2001-07-06 12:09:32 +00:00
|
|
|
mutate(newtype);
|
2001-06-25 00:06:33 +00:00
|
|
|
break;
|
2001-07-09 10:19:50 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
case LM_OT_ALIGN:
|
2001-09-04 13:32:06 +00:00
|
|
|
case LM_OT_ALIGNAT:
|
|
|
|
case LM_OT_XALIGNAT:
|
|
|
|
case LM_OT_XXALIGNAT:
|
2001-07-09 16:59:57 +00:00
|
|
|
default: {
|
2001-09-26 16:52:34 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
idx_type c = 3 * row + 1;
|
2001-06-25 00:06:33 +00:00
|
|
|
cell(c).push_back(cell(c + 1));
|
|
|
|
}
|
|
|
|
MathGridInset::delCol(2);
|
2001-07-26 06:56:43 +00:00
|
|
|
setType(LM_OT_ALIGN);
|
2001-06-25 00:06:33 +00:00
|
|
|
mutate(newtype);
|
|
|
|
break;
|
2001-07-09 16:59:57 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LM_OT_ALIGN:
|
|
|
|
switch (newtype) {
|
|
|
|
case LM_OT_SIMPLE:
|
|
|
|
case LM_OT_EQUATION:
|
|
|
|
case LM_OT_EQNARRAY:
|
|
|
|
MathGridInset::addCol(1);
|
2001-07-26 06:56:43 +00:00
|
|
|
setType(LM_OT_EQNARRAY);
|
2001-06-25 00:06:33 +00:00
|
|
|
mutate(newtype);
|
|
|
|
break;
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
case LM_OT_ALIGNAT:
|
|
|
|
case LM_OT_XALIGNAT:
|
|
|
|
case LM_OT_XXALIGNAT:
|
|
|
|
setType(newtype);
|
|
|
|
break;
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
default:
|
2001-07-26 06:56:43 +00:00
|
|
|
lyxerr << "mutation from '" << getType()
|
2001-06-25 00:06:33 +00:00
|
|
|
<< "' to '" << newtype << "' not implemented\n";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-09-04 14:56:30 +00:00
|
|
|
case LM_OT_MULTLINE:
|
|
|
|
switch (newtype) {
|
|
|
|
case LM_OT_GATHER:
|
|
|
|
setType(LM_OT_GATHER);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lyxerr << "mutation from '" << getType()
|
|
|
|
<< "' to '" << newtype << "' not implemented\n";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LM_OT_GATHER:
|
|
|
|
switch (newtype) {
|
|
|
|
case LM_OT_MULTLINE:
|
|
|
|
setType(LM_OT_MULTLINE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lyxerr << "mutation from '" << getType()
|
|
|
|
<< "' to '" << newtype << "' not implemented\n";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
default:
|
2001-07-26 06:56:43 +00:00
|
|
|
lyxerr << "mutation from '" << getType()
|
2001-06-25 00:06:33 +00:00
|
|
|
<< "' to '" << newtype << "' not implemented\n";
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
}
|