]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathGrid.cpp
New methods in LaTeXFeatures specifically for collection of CSS
[lyx.git] / src / mathed / InsetMathGrid.cpp
index 308e059fd7c3c7ec68cb5d3820bc3368b8c3b0ab..5b58f09a03eb1b746873057d84b00d19f985ac60 100644 (file)
@@ -3,12 +3,13 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author André Pönitz
+ * \author André Pönitz
  *
  * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
+#include <algorithm>
 
 #include "InsetMathGrid.h"
 
@@ -17,6 +18,7 @@
 #include "MathStream.h"
 #include "MetricsInfo.h"
 
+#include "Buffer.h"
 #include "BufferView.h"
 #include "CutAndPaste.h"
 #include "FuncStatus.h"
@@ -24,6 +26,7 @@
 #include "FuncRequest.h"
 
 #include "frontends/Clipboard.h"
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
 #include "support/debug.h"
@@ -31,7 +34,7 @@
 #include "support/gettext.h"
 #include "support/lstrings.h"
 
-#include <boost/assert.hpp>
+#include "support/lassert.h"
 
 #include <sstream>
 
@@ -39,6 +42,7 @@ using namespace std;
 using namespace lyx::support;
 
 
+
 namespace lyx {
 
 static docstring verboseHLine(int n)
@@ -60,6 +64,17 @@ static int extractInt(istream & is)
 }
 
 
+static void resetGrid(InsetMathGrid & grid)
+{
+       while (grid.ncols() > 1)
+               grid.delCol(grid.ncols() - 1);
+       while (grid.nrows() > 1)
+               grid.delRow(grid.nrows() - 1);
+       grid.cell(0).erase(0, grid.cell(0).size());
+       grid.setDefaults();
+}
+
+
 
 //////////////////////////////////////////////////////////////
 
@@ -79,9 +94,11 @@ InsetMathGrid::RowInfo::RowInfo()
 
 
 
-int InsetMathGrid::RowInfo::skipPixels() const
+int InsetMathGrid::RowInfo::skipPixels(MetricsInfo const & mi) const
 {
-       return crskip_.inBP();
+       frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
+       return crskip_.inPixels(mi.base.textwidth,
+                               fm.width(char_type('M')));
 }
 
 
@@ -97,8 +114,8 @@ InsetMathGrid::ColInfo::ColInfo()
 //////////////////////////////////////////////////////////////
 
 
-InsetMathGrid::InsetMathGrid()
-       : InsetMathNest(1),
+InsetMathGrid::InsetMathGrid(Buffer * buf)
+       : InsetMathNest(buf, 1),
          rowinfo_(1 + 1),
                colinfo_(1 + 1),
                cellinfo_(1),
@@ -108,8 +125,8 @@ InsetMathGrid::InsetMathGrid()
 }
 
 
-InsetMathGrid::InsetMathGrid(col_type m, row_type n)
-       : InsetMathNest(m * n),
+InsetMathGrid::InsetMathGrid(Buffer * buf, col_type m, row_type n)
+       : InsetMathNest(buf, m * n),
          rowinfo_(n + 1),
                colinfo_(m + 1),
                cellinfo_(m * n),
@@ -119,8 +136,9 @@ InsetMathGrid::InsetMathGrid(col_type m, row_type n)
 }
 
 
-InsetMathGrid::InsetMathGrid(col_type m, row_type n, char v, docstring const & h)
-       : InsetMathNest(m * n),
+InsetMathGrid::InsetMathGrid(Buffer * buf, col_type m, row_type n, char v,
+       docstring const & h)
+       : InsetMathNest(buf, m * n),
          rowinfo_(n + 1),
          colinfo_(m + 1),
                cellinfo_(m * n),
@@ -363,10 +381,10 @@ void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const
        // compute vertical offsets
        rowinfo_[0].offset_ = 0;
        for (row_type row = 1; row <= nrows(); ++row) {
-               rowinfo_[row].offset_  =
-                       rowinfo_[row - 1].offset_  +
+               rowinfo_[row].offset_ =
+                       rowinfo_[row - 1].offset_ +
                        rowinfo_[row - 1].descent_ +
-                       rowinfo_[row - 1].skipPixels() +
+                       rowinfo_[row - 1].skipPixels(mi) +
                        rowsep() +
                        rowinfo_[row].lines_ * hlinesep() +
                        rowinfo_[row].ascent_;
@@ -409,20 +427,20 @@ void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const
        }
 
 
-       dim.wid   =   colinfo_[ncols() - 1].offset_
-                      + colinfo_[ncols() - 1].width_
-                + vlinesep() * colinfo_[ncols()].lines_
-                      + border();
+       dim.wid = colinfo_[ncols() - 1].offset_
+               + colinfo_[ncols() - 1].width_
+               + vlinesep() * colinfo_[ncols()].lines_
+               + border();
 
-       dim.asc  = - rowinfo_[0].offset_
-                      + rowinfo_[0].ascent_
-                + hlinesep() * rowinfo_[0].lines_
-                      + border();
+       dim.asc = - rowinfo_[0].offset_
+               + rowinfo_[0].ascent_
+               + hlinesep() * rowinfo_[0].lines_
+               + border();
 
-       dim.des =   rowinfo_[nrows() - 1].offset_
-                      + rowinfo_[nrows() - 1].descent_
-                + hlinesep() * rowinfo_[nrows()].lines_
-                      + border();
+       dim.des = rowinfo_[nrows() - 1].offset_
+               + rowinfo_[nrows() - 1].descent_
+               + hlinesep() * rowinfo_[nrows()].lines_
+               + border();
 
 
 /*
@@ -476,7 +494,7 @@ void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const
        }
 */
        metricsMarkers2(dim);
-       // Cache the inset dimension. 
+       // Cache the inset dimension.
        setDimCache(mi, dim);
 }
 
@@ -549,7 +567,7 @@ void InsetMathGrid::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
                rowinfo_[row].offset_  =
                        rowinfo_[row - 1].offset_  +
                        rowinfo_[row - 1].descent_ +
-                       //rowinfo_[row - 1].skipPixels() +
+                       //rowinfo_[row - 1].skipPixels(mi) +
                        1 + //rowsep() +
                        //rowinfo_[row].lines_ * hlinesep() +
                        rowinfo_[row].ascent_;
@@ -618,7 +636,16 @@ void InsetMathGrid::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
 }
 
 
-docstring InsetMathGrid::eolString(row_type row, bool emptyline, bool fragile) const
+void InsetMathGrid::updateBuffer(ParIterator const & it, UpdateType utype)
+{
+       // pass down
+       for (idx_type idx = 0; idx < nargs(); ++idx)
+               cell(idx).updateBuffer(it, utype);
+}
+
+
+docstring InsetMathGrid::eolString(row_type row, bool fragile,
+               bool /*latex*/, bool last_eoln) const
 {
        docstring eol;
 
@@ -636,7 +663,7 @@ docstring InsetMathGrid::eolString(row_type row, bool emptyline, bool fragile) c
        }
 
        // only add \\ if necessary
-       if (eol.empty() && row + 1 == nrows() && (nrows() == 1 || !emptyline))
+       if (eol.empty() && row + 1 == nrows() && (nrows() == 1 || !last_eoln))
                return docstring();
 
        return (fragile ? "\\protect\\\\" : "\\\\") + eol;
@@ -661,17 +688,6 @@ void InsetMathGrid::addRow(row_type row)
 }
 
 
-void InsetMathGrid::appendRow()
-{
-       rowinfo_.push_back(RowInfo());
-       //cells_.insert(cells_.end(), ncols(), MathData());
-       for (col_type col = 0; col < ncols(); ++col) {
-               cells_.push_back(cells_type::value_type());
-               cellinfo_.push_back(CellInfo());
-       }
-}
-
-
 void InsetMathGrid::delRow(row_type row)
 {
        if (nrows() == 1)
@@ -751,7 +767,7 @@ void InsetMathGrid::delCol(col_type col)
 
 void InsetMathGrid::copyCol(col_type col)
 {
-       addCol(col);
+       addCol(col+1);
        for (row_type row = 0; row < nrows(); ++row)
                cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
 }
@@ -772,7 +788,7 @@ int InsetMathGrid::cellXOffset(BufferView const & bv, idx_type idx) const
 {
        col_type c = col(idx);
        int x = colinfo_[c].offset_;
-       char align = colinfo_[c].align_;
+       char align = displayColAlign(c, row(idx));
        Dimension const & celldim = cell(idx).dimension(bv);
        if (align == 'r' || align == 'R')
                x += colinfo_[c].width_ - celldim.wid;
@@ -953,39 +969,97 @@ void InsetMathGrid::normalize(NormalStream & os) const
 
 void InsetMathGrid::mathmlize(MathStream & os) const
 {
-       os << MTag("mtable");
+       bool const havetable = nrows() > 1 || ncols() > 1;
+       if (havetable)
+               os << MTag("mtable");
+       char const * const celltag = havetable ? "mtd" : "mrow";
        for (row_type row = 0; row < nrows(); ++row) {
-               os << MTag("mtr");
-               for (col_type col = 0; col < ncols(); ++col)
+               if (havetable)
+                       os << MTag("mtr");
+               for (col_type col = 0; col < ncols(); ++col) {
+                       os << MTag(celltag);
                        os << cell(index(row, col));
-               os << ETag("mtr");
+                       os << ETag(celltag);
+               }
+               if (havetable)
+                       os << ETag("mtr");
        }
-       os << ETag("mtable");
+       if (havetable)
+               os << ETag("mtable");
+}
+
+
+// FIXME XHTML
+// We need to do something about alignment here.
+void InsetMathGrid::htmlize(HtmlStream & os, string attrib) const
+{
+       bool const havetable = nrows() > 1 || ncols() > 1;
+       if (!havetable) {
+               os << cell(index(0, 0));
+               return;
+       }
+       os << MTag("table", attrib);
+       for (row_type row = 0; row < nrows(); ++row) {
+               os << MTag("tr");
+               for (col_type col = 0; col < ncols(); ++col) {
+                       os << MTag("td");
+                       os << cell(index(row, col));
+                       os << ETag("td");
+               }
+               os << ETag("tr");
+       }
+       os << ETag("table");
+}
+
+
+void InsetMathGrid::htmlize(HtmlStream & os) const
+{
+       htmlize(os, "class='mathtable'");
 }
 
 
 void InsetMathGrid::write(WriteStream & os) const
 {
+       write(os, 0, 0, nrows(), ncols());
+}
+
+void InsetMathGrid::write(WriteStream & os,
+                         row_type beg_row, col_type beg_col,
+                         row_type end_row, col_type end_col) const
+{
+       MathEnsurer ensurer(os, false);
        docstring eol;
-       for (row_type row = 0; row < nrows(); ++row) {
+       for (row_type row = beg_row; row < end_row; ++row) {
                os << verboseHLine(rowinfo_[row].lines_);
-               // don't write & and empty cells at end of line
+               // don't write & and empty cells at end of line,
+               // unless there are vertical lines
                col_type lastcol = 0;
                bool emptyline = true;
-               for (col_type col = 0; col < ncols(); ++col)
-                       if (!cell(index(row, col)).empty()) {
+               bool last_eoln = true;
+               for (col_type col = beg_col; col < end_col; ++col) {
+                       bool const empty_cell = cell(index(row, col)).empty();
+                       if (!empty_cell)
+                               last_eoln = false;
+                       if (!empty_cell || colinfo_[col + 1].lines_) {
                                lastcol = col + 1;
                                emptyline = false;
                        }
-               for (col_type col = 0; col < lastcol; ++col)
-                       os << cell(index(row, col)) << eocString(col, lastcol);
-               eol = eolString(row, emptyline, os.fragile());
+               }
+               for (col_type col = beg_col; col < lastcol; ++col) {
+                       os << cell(index(row, col));
+                       if (os.pendingBrace())
+                               ModeSpecifier specifier(os, TEXT_MODE);
+                       os << eocString(col, lastcol);
+               }
+               eol = eolString(row, os.fragile(), os.latex(), last_eoln);
                os << eol;
                // append newline only if line wasn't completely empty
-               // and this was not the last line in the grid
-               if (!emptyline && row + 1 < nrows())
+               // and the formula is not written on a single line
+               bool const empty = emptyline && eol.empty();
+               if (!empty && nrows() > 1)
                        os << "\n";
        }
+       // @TODO use end_row instead of nrows() ?
        docstring const s = verboseHLine(rowinfo_[nrows()].lines_);
        if (!s.empty()) {
                if (eol.empty()) {
@@ -1044,15 +1118,14 @@ void InsetMathGrid::splitCell(Cursor & cur)
 void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        //lyxerr << "*** InsetMathGrid: request: " << cmd << endl;
-       switch (cmd.action) {
+
+       Parse::flags parseflg = Parse::QUIET | Parse::USETEXT;
+
+       FuncCode const act = cmd.action();
+       switch (act) {
 
        // insert file functions
        case LFUN_LINE_DELETE:
-               // FIXME: We use recordUndoInset when a change reflects more
-               // than one cell, because recordUndo does not work for
-               // multiple cells. Unfortunately this puts the cursor in front
-               // of the inset after undo. This is (especilally for large
-               // grids) annoying.
                cur.recordUndoInset();
                //autocorrect_ = false;
                //macroModeClose();
@@ -1075,7 +1148,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_CELL_BACKWARD:
                // See below.
-               cur.selection() = false;
+               cur.setSelection(false);
                if (!idxPrev(cur)) {
                        cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
                        cur.undispatched();
@@ -1085,14 +1158,14 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_CELL_FORWARD:
                // Can't handle selection by additional 'shift' as this is
                // hard bound to LFUN_CELL_BACKWARD
-               cur.selection() = false;
+               cur.setSelection(false);
                if (!idxNext(cur)) {
                        cmd = FuncRequest(LFUN_FINISHED_FORWARD);
                        cur.undispatched();
                }
                break;
 
-       case LFUN_NEW_LINE: {
+       case LFUN_NEWLINE_INSERT: {
                cur.recordUndoInset();
                row_type const r = cur.row();
                addRow(r);
@@ -1107,18 +1180,23 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                if (cur.idx() > 0)
                        --cur.idx();
                cur.pos() = cur.lastpos();
-
+               cur.forceBufferUpdate();
                //mathcursor->normalize();
                //cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
                break;
        }
 
-       case LFUN_TABULAR_FEATURE: {
+       case LFUN_INSET_MODIFY: {
                cur.recordUndoInset();
                //lyxerr << "handling tabular-feature " << to_utf8(cmd.argument()) << endl;
                istringstream is(to_utf8(cmd.argument()));
                string s;
                is >> s;
+               if (s != "tabular") {
+                       InsetMathNest::doDispatch(cur, cmd);
+                       return;
+               }
+               is >> s;
                if (s == "valign-top")
                        setVerticalAlignment('t');
                else if (s == "valign-middle")
@@ -1207,7 +1285,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                        docstring & special = colinfo_[cur.col()].special_;
                        if (!special.empty()) {
                                docstring::size_type i = special.rfind('|');
-                               BOOST_ASSERT(i != docstring::npos);
+                               LASSERT(i != docstring::npos, /**/);
                                special.erase(i, 1);
                        }
                }
@@ -1216,7 +1294,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                        docstring & special = colinfo_[cur.col()+1].special_;
                        if (!special.empty()) {
                                docstring::size_type i = special.find('|');
-                               BOOST_ASSERT(i != docstring::npos);
+                               LASSERT(i != docstring::npos, /**/);
                                special.erase(i, 1);
                        }
                }
@@ -1225,11 +1303,16 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                        break;
                }
                // perhaps this should be FINISHED_BACKWARD -- just for clarity?
-               lyxerr << "returning FINISHED_LEFT" << endl;
+               //lyxerr << "returning FINISHED_LEFT" << endl;
                break;
        }
 
+       case LFUN_CLIPBOARD_PASTE:
+               parseflg |= Parse::VERBATIM;
+               // fall through
        case LFUN_PASTE: {
+               if (cur.currentMode() <= TEXT_MODE)
+                       parseflg |= Parse::TEXTMODE;
                cur.message(_("Paste"));
                cap::replaceSelection(cur);
                docstring topaste;
@@ -1241,9 +1324,13 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                        is >> n;
                        topaste = cap::selection(n);
                }
-               InsetMathGrid grid(1, 1);
+               InsetMathGrid grid(buffer_, 1, 1);
                if (!topaste.empty())
-                       mathed_parse_normal(grid, topaste);
+                       if ((topaste.size() == 1 && topaste.at(0) < 0x80)
+                           || !mathed_parse_normal(grid, topaste, parseflg)) {
+                               resetGrid(grid);
+                               mathed_parse_normal(grid, topaste, parseflg | Parse::VERBATIM);
+                       }
 
                if (grid.nargs() == 1) {
                        // single cell/part of cell
@@ -1274,6 +1361,9 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                                        cell(i).append(grid.cell(grid.index(r, c)));
                }
                cur.clearSelection(); // bug 393
+               // FIXME audit setBuffer calls
+               cur.inset().setBuffer(*buffer_);
+               cur.forceBufferUpdate();
                cur.finishUndo();
                break;
        }
@@ -1284,9 +1374,9 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_WORD_BACKWARD:
        case LFUN_WORD_LEFT_SELECT:
        case LFUN_WORD_LEFT:
-               cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT ||
-                               cmd.action == LFUN_WORD_LEFT_SELECT ||
-                               cmd.action == LFUN_LINE_BEGIN_SELECT);
+               cur.selHandle(act == LFUN_WORD_BACKWARD_SELECT ||
+                               act == LFUN_WORD_LEFT_SELECT ||
+                               act == LFUN_LINE_BEGIN_SELECT);
                cur.macroModeClose();
                if (cur.pos() != 0) {
                        cur.pos() = 0;
@@ -1308,9 +1398,9 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_WORD_RIGHT:
        case LFUN_LINE_END_SELECT:
        case LFUN_LINE_END:
-               cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT ||
-                               cmd.action == LFUN_WORD_RIGHT_SELECT ||
-                               cmd.action == LFUN_LINE_END_SELECT);
+               cur.selHandle(act == LFUN_WORD_FORWARD_SELECT ||
+                               act == LFUN_WORD_RIGHT_SELECT ||
+                               act == LFUN_LINE_END_SELECT);
                cur.macroModeClose();
                cur.clearTargetX();
                if (cur.pos() != cur.lastpos()) {
@@ -1336,17 +1426,31 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
 bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
                FuncStatus & status) const
 {
-       switch (cmd.action) {
-       case LFUN_TABULAR_FEATURE: {
-               string const s = to_utf8(cmd.argument());
+       switch (cmd.action()) {
+       case LFUN_INSET_MODIFY: {
+               istringstream is(to_utf8(cmd.argument()));
+               string s;
+               is >> s;
+               if (s != "tabular") {
+                       // We only now about table actions here.
+                       break;
+               }
+               if (&cur.inset() != this) {
+                       // Table actions requires that the cursor is _inside_ the
+                       // table.
+                       status.setEnabled(false);
+                       status.message(from_utf8(N_("Cursor not in table")));
+                       return true;
+               }
+               is >> s;
                if (nrows() <= 1 && (s == "delete-row" || s == "swap-row")) {
-                       status.enabled(false);
+                       status.setEnabled(false);
                        status.message(from_utf8(N_("Only one row")));
                        return true;
                }
                if (ncols() <= 1 &&
                    (s == "delete-column" || s == "swap-column")) {
-                       status.enabled(false);
+                       status.setEnabled(false);
                        status.message(from_utf8(N_("Only one column")));
                        return true;
                }
@@ -1354,7 +1458,7 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
                     s == "delete-hline-above") ||
                    (rowinfo_[cur.row() + 1].lines_ == 0 &&
                     s == "delete-hline-below")) {
-                       status.enabled(false);
+                       status.setEnabled(false);
                        status.message(from_utf8(N_("No hline to delete")));
                        return true;
                }
@@ -1363,37 +1467,39 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
                     s == "delete-vline-left") ||
                    (colinfo_[cur.col() + 1].lines_ == 0 &&
                     s == "delete-vline-right")) {
-                       status.enabled(false);
+                       status.setEnabled(false);
                        status.message(from_utf8(N_("No vline to delete")));
                        return true;
                }
                if (s == "valign-top" || s == "valign-middle" ||
                    s == "valign-bottom" || s == "align-left" ||
-                   s == "align-right" || s == "align-center" ||
-                   s == "append-row" || s == "delete-row" ||
+                   s == "align-right" || s == "align-center") {
+                       status.setEnabled(true);
+                       char const ha = horizontalAlignment(cur.col());
+                       char const va = verticalAlignment();
+                       status.setOnOff((s == "align-left" && ha == 'l')
+                                       || (s == "align-right"   && ha == 'r')
+                                       || (s == "align-center"  && ha == 'c')
+                                       || (s == "valign-top"    && va == 't')
+                                       || (s == "valign-bottom" && va == 'b')
+                                       || (s == "valign-middle" && va == 'c'));
+                       return true;
+               }
+               if (s == "append-row" || s == "delete-row" ||
                    s == "copy-row" || s == "swap-row" ||
                    s == "add-hline-above" || s == "add-hline-below" ||
                    s == "delete-hline-above" || s == "delete-hline-below" ||
                    s == "append-column" || s == "delete-column" ||
                    s == "copy-column" || s == "swap-column" ||
                    s == "add-vline-left" || s == "add-vline-right" ||
-                   s == "delete-vline-left" || s == "delete-vline-right")
-                       status.enabled(true);
-               else {
-                       status.enabled(false);
+                   s == "delete-vline-left" || s == "delete-vline-right") {
+                       status.setEnabled(true);
+               else {
+                       status.setEnabled(false);
                        status.message(bformat(
                                from_utf8(N_("Unknown tabular feature '%1$s'")), lyx::from_ascii(s)));
                }
 
-               char const ha = horizontalAlignment(cur.col());
-               char const va = verticalAlignment();
-               status.setOnOff((s == "align-left" && ha == 'l')
-                          || (s == "align-right"   && ha == 'r')
-                          || (s == "align-center"  && ha == 'c')
-                          || (s == "valign-top"    && va == 't')
-                          || (s == "valign-bottom" && va == 'b')
-                          || (s == "valign-middle" && va == 'm'));
-
 #if 0
                // FIXME: What did this code do?
                // Please check whether it is still needed!
@@ -1411,23 +1517,24 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
                        break;
                }
                status.setOnOff(cmd.argument()[0] == v_align_);
-               status.enabled(true);
+               status.setEnabled(true);
 #endif
                return true;
        }
 
        case LFUN_CELL_SPLIT:
-               status.enabled(true);
+               status.setEnabled(cur.idx() != cur.lastidx());
                return true;
 
        case LFUN_CELL_BACKWARD:
        case LFUN_CELL_FORWARD:
-               status.enabled(true);
+               status.setEnabled(true);
                return true;
 
        default:
-               return InsetMathNest::getStatus(cur, cmd, status);
+               break;
        }
+       return InsetMathNest::getStatus(cur, cmd, status);
 }