- nonum_.push_back(!numberedType());
- label_.push_back(string());
- MathGridInset::appendRow();
-}
-
-
-void MathMatrixInset::delRow(int row)
-{
- MathGridInset::delRow(row);
- nonum_.erase(nonum_.begin() + row);
- label_.erase(label_.begin() + row);
-}
-
-void MathMatrixInset::addCol(int col)
-{
- switch (getType()) {
- case LM_OT_EQUATION:
- mutate(LM_OT_EQNARRAY);
- break;
-
- case LM_OT_EQNARRAY:
- mutate(LM_OT_ALIGN);
- addCol(col);
- break;
-
- case LM_OT_ALIGN:
- case LM_OT_ALIGNAT:
- MathGridInset::addCol(col);
- halign(col, 'l');
- MathGridInset::addCol(col);
- halign(col, 'r');
- break;
-
- default:
- break;
- }
-}
-
-void MathMatrixInset::delCol(int col)
-{
- switch (getType()) {
- case LM_OT_ALIGN:
- MathGridInset::delCol(col);
- break;
-
- default:
- break;
- }
-}
-
-
-string MathMatrixInset::nicelabel(int row) const
-{
- if (nonum_[row])
- return string();
- if (label_[row].empty())
- return string("(#)");
- return "(" + label_[row] + ")";
-}
-
-
-namespace {
- short 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 == "xalign")
- return LM_OT_XALIGN;
- if (s == "xxalign")
- return LM_OT_XXALIGN;
- if (s == "multline")
- return LM_OT_MULTLINE;
- return LM_OT_SIMPLE;
- }
-}
-
-void MathMatrixInset::mutate(string const & newtype)
-{
- if (newtype == "dump") {
- dump();
- return;
- }
- //lyxerr << "mutating from '" << getType() << "' to '" << newtype << "'\n";
- mutate(typecode(newtype));
-}
-
-void MathMatrixInset::glueall()
-{
- MathArray ar;
- for (int i = 0; i < nargs(); ++i)
- ar.push_back(cell(i));
- *this = MathMatrixInset(LM_OT_SIMPLE);
- cell(0) = ar;
-}
-
-
-MathInsetTypes MathMatrixInset::getType() const
-{
- return objtype_;
-}
-
-
-void MathMatrixInset::setType(MathInsetTypes t)
-{
- objtype_ = t;
-}
-
-
-
-void MathMatrixInset::mutate(short newtype)
-{
- //lyxerr << "mutating from '" << getType() << "' to '" << newtype << "'\n";
-
- if (newtype == getType())
- return;
-
- switch (getType()) {
- case LM_OT_SIMPLE:
- setType(LM_OT_EQUATION);
- numbered(0, false);
- mutate(newtype);
- break;
-
- case LM_OT_EQUATION:
- switch (newtype) {
- case LM_OT_SIMPLE:
- setType(LM_OT_SIMPLE);
- break;
-
- case LM_OT_ALIGN: {
- MathGridInset::addCol(1);
-
- // split it "nicely"
- int pos = firstRelOp(cell(0));
- cell(1) = cell(0);
- cell(0).erase(pos, cell(0).size());
- cell(1).erase(0, pos);
-
- halign("rl");
- setType(LM_OT_ALIGN);
- break;
- }
-
- case LM_OT_EQNARRAY:
- default:
- MathGridInset::addCol(1);
- MathGridInset::addCol(1);
-
- // split it "nicely" on the firest relop
- int pos1 = firstRelOp(cell(0));
- cell(1) = cell(0);
- cell(0).erase(pos1, cell(0).size());
- cell(1).erase(0, pos1);
- int pos2 = 0;
- cell(1).next(pos2);
- cell(2) = cell(1);
- cell(1).erase(pos2, cell(1).size());
- cell(2).erase(0, pos2);
-
- halign("rcl");
- setType(LM_OT_EQNARRAY);
- mutate(newtype);
- break;
- }
- break;
-
- case LM_OT_EQNARRAY:
- switch (newtype) {
- case LM_OT_SIMPLE:
- case LM_OT_EQUATION: {
- // set correct (no)numbering
- bool allnonum = true;
- for (int r = 0; r < nrows(); ++r) {
- if (!nonum_[r])
- allnonum = false;
- }
-
- // set first non-empty label
- string label;
- for (int r = 0; r < nrows(); ++r) {
- if (!label_[r].empty()) {
- label = label_[r];
- break;
- }
- }
-
- glueall();
-
- nonum_[0] = allnonum;
- label_[0] = label;
- mutate(newtype);
- break;
- }
-
- case LM_OT_ALIGN:
- default: {
- for (int row = 0; row < nrows(); ++row) {
- int c = 3 * row + 1;
- cell(c).push_back(cell(c + 1));
- }
- MathGridInset::delCol(2);
- setType(LM_OT_ALIGN);
- halign("rl");
- mutate(newtype);
- break;
- }
- }
- break;
-
- case LM_OT_ALIGN:
- switch (newtype) {
- case LM_OT_SIMPLE:
- case LM_OT_EQUATION:
- case LM_OT_EQNARRAY:
- MathGridInset::addCol(1);
- setType(LM_OT_EQNARRAY);
- halign("rcl");
- mutate(newtype);
- break;
-
- default:
- lyxerr << "mutation from '" << getType()
- << "' to '" << newtype << "' not implemented\n";
- break;
- }
- break;
-
- default:
- lyxerr << "mutation from '" << getType()
- << "' to '" << newtype << "' not implemented\n";