]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathGrid.cpp
Do not throw exceptions here either. See r22806.
[lyx.git] / src / mathed / InsetMathGrid.cpp
index 2753dc8e40bb561cf6af8659be66164b6998592d..19c9d8c54b79ccc11848f348ca7a76d24212dd51 100644 (file)
@@ -635,11 +635,11 @@ void InsetMathGrid::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
 }
 
 
-void InsetMathGrid::updateLabels(ParIterator const & it, UpdateType utype)
+void InsetMathGrid::updateBuffer(ParIterator const & it, UpdateType utype)
 {
        // pass down
        for (idx_type idx = 0; idx < nargs(); ++idx)
-               cell(idx).updateLabels(it, utype);
+               cell(idx).updateBuffer(it, utype);
 }
 
 
@@ -998,6 +998,35 @@ void InsetMathGrid::mathmlize(MathStream & os) const
 }
 
 
+// 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());
@@ -1097,7 +1126,8 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        Parse::flags parseflg = Parse::QUIET | Parse::USETEXT;
 
-       switch (cmd.action) {
+       FuncCode const act = cmd.action();
+       switch (act) {
 
        // insert file functions
        case LFUN_LINE_DELETE:
@@ -1336,10 +1366,10 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                                        cell(i).append(grid.cell(grid.index(r, c)));
                }
                cur.clearSelection(); // bug 393
-               // FIXME audit setBuffer/updateLabels calls
+               // FIXME audit setBuffer/updateBuffer calls
                cur.inset().setBuffer(*buffer_);
-               // FIXME audit setBuffer/updateLabels calls
-               cur.buffer()->updateLabels();
+               // FIXME audit setBuffer/updateBuffer calls
+               cur.buffer()->updateBuffer();
                cur.finishUndo();
                break;
        }
@@ -1350,9 +1380,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;
@@ -1374,9 +1404,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()) {
@@ -1402,13 +1432,22 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
 bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
                FuncStatus & status) const
 {
-       switch (cmd.action) {
+       switch (cmd.action()) {
        case LFUN_INSET_MODIFY: {
                istringstream is(to_utf8(cmd.argument()));
                string s;
                is >> s;
-               if (s != "tabular")
-                       return InsetMathNest::getStatus(cur, cmd, status);
+               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.setEnabled(false);
@@ -1499,8 +1538,9 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
                return true;
 
        default:
-               return InsetMathNest::getStatus(cur, cmd, status);
+               break;
        }
+       return InsetMathNest::getStatus(cur, cmd, status);
 }