]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettabular.C
Enable the external inset to handle unknown templates gracefully.
[lyx.git] / src / insets / insettabular.C
index 7ed81140056a38756655b264983d68b0b5347931..0007786eb3eedbcb404262801403fe7acd21153e 100644 (file)
@@ -10,7 +10,6 @@
 
 #include <config.h>
 
-
 #include "insettabular.h"
 #include "insettext.h"
 
 #include "BufferView.h"
 #include "lfuns.h"
 #include "debug.h"
+#include "dimension.h"
 #include "funcrequest.h"
 #include "gettext.h"
 #include "language.h"
 #include "LaTeXFeatures.h"
+#include "Lsstream.h"
 #include "lyx_cb.h"
 #include "lyxfunc.h"
 #include "lyxlength.h"
@@ -30,6 +31,7 @@
 #include "ParagraphParameters.h"
 #include "undo_funcs.h"
 #include "WordLangTuple.h"
+#include "metricsinfo.h"
 
 #include "frontends/Alert.h"
 #include "frontends/Dialogs.h"
@@ -149,7 +151,7 @@ bool InsetTabular::hasPasteBuffer() const
 
 
 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
-       : buffer(&buf)
+       : buffer_(&buf)
 {
        if (rows <= 0)
                rows = 1;
@@ -172,12 +174,11 @@ InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
 }
 
 
-InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf,
-                                                  bool same_id)
-       : UpdatableInset(tab, same_id), buffer(&buf)
+InsetTabular::InsetTabular(InsetTabular const & tab)
+       : UpdatableInset(tab), buffer_(tab.buffer_)
 {
-       tabular.reset(new LyXTabular(buf.params,
-                                    this, *(tab.tabular), same_id));
+       tabular.reset(new LyXTabular(buffer_->params,
+                                    this, *(tab.tabular)));
        the_locking_inset = 0;
        old_locking_inset = 0;
        locked = false;
@@ -199,15 +200,21 @@ InsetTabular::~InsetTabular()
 }
 
 
-Inset * InsetTabular::clone(Buffer const & buf, bool same_id) const
+Inset * InsetTabular::clone() const
 {
-       return new InsetTabular(*this, buf, same_id);
+       return new InsetTabular(*this);
 }
 
 
 BufferView * InsetTabular::view() const
 {
-       return buffer->getUser();
+       return buffer_->getUser();
+}
+
+
+void InsetTabular::buffer(Buffer * b)
+{
+       buffer_ = b;
 }
 
 
@@ -242,58 +249,48 @@ void InsetTabular::read(Buffer const * buf, LyXLex & lex)
 }
 
 
-int InsetTabular::ascent(BufferView *, LyXFont const &) const
-{
-       return tabular->GetAscentOfRow(0);
-}
-
-
-int InsetTabular::descent(BufferView *, LyXFont const &) const
+void InsetTabular::metrics(MetricsInfo &,
+       Dimension & dim) const
 {
-       return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
+       dim.asc = tabular->GetAscentOfRow(0);
+       dim.des = tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
+       dim.wid = tabular->GetWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
 }
 
 
-int InsetTabular::width(BufferView *, LyXFont const &) const
-{
-       return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
-}
-
-
-void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
-                       float & x) const
+void InsetTabular::draw(PainterInfo & pi, int x, int y) const
 {
        if (nodraw()) {
                need_update = FULL;
                return;
        }
 
-       Painter & pain = bv->painter();
+       BufferView * bv = pi.base.bv;
        int i;
        int j;
        int nx;
 
 #if 0
-       UpdatableInset::draw(bv, font, baseline, x);
+       UpdatableInset::draw(pi, x, y);
 #else
        if (!owner())
-               x += static_cast<float>(scroll());
+               x += scroll();
 #endif
 
-       top_x = int(x);
-       top_baseline = baseline;
+       top_x = x;
+       top_baseline = y;
        x += ADD_TO_TABULAR_WIDTH;
 
        int cell = 0;
-       float cx;
+       int cx;
        first_visible_cell = -1;
        for (i = 0; i < tabular->rows(); ++i) {
-               nx = int(x);
+               nx = x;
                cell = tabular->GetCellNumber(i, 0);
-               if (!((baseline + tabular->GetDescentOfRow(i)) > 0) &&
-                       (baseline - tabular->GetAscentOfRow(i))<pain.paperHeight())
+               if (!((y + tabular->GetDescentOfRow(i)) > 0) &&
+                       (y - tabular->GetAscentOfRow(i)) < pi.pain.paperHeight())
                {
-               baseline += tabular->GetDescentOfRow(i) +
+               y += tabular->GetDescentOfRow(i) +
                                tabular->GetAscentOfRow(i + 1) +
                                tabular->GetAdditionalHeight(i + 1);
                        continue;
@@ -307,26 +304,36 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
                        if (first_visible_cell < 0)
                                first_visible_cell = cell;
                        if (hasSelection()) {
-                               drawCellSelection(pain, nx, baseline, i, j, cell);
+                               drawCellSelection(pi.pain, nx, y, i, j, cell);
                        }
 
-                       tabular->GetCellInset(cell)->draw(bv, font, baseline, cx);
-                       drawCellLines(pain, nx, baseline, i, cell);
+                       tabular->GetCellInset(cell)->draw(pi, cx, y);
+                       drawCellLines(pi.pain, nx, y, i, cell);
                        nx += tabular->GetWidthOfColumn(cell);
                        ++cell;
                }
-               baseline += tabular->GetDescentOfRow(i) +
+
+// Would be nice, but for some completely unfathomable reason,
+// on a col resize to a new fixed width, even though the insettexts
+// are resized, the cell isn't, but drawing all cells in a tall table
+// has the desired effect somehow. Complete dark magic.
+#if 0
+               // avoiding drawing the rest of a long table is
+               // a pretty big speedup
+               if (y > bv->workHeight())
+                       break;
+#endif
+
+               y += tabular->GetDescentOfRow(i) +
                        tabular->GetAscentOfRow(i + 1) +
                        tabular->GetAdditionalHeight(i + 1);
        }
 
-       x -= ADD_TO_TABULAR_WIDTH;
-       x += width(bv, font);
        need_update = NONE;
 }
 
 
-void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
+void InsetTabular::drawCellLines(Painter & pain, int x, int y,
                                 int row, int cell) const
 {
        int x2 = x + tabular->GetWidthOfColumn(cell);
@@ -334,34 +341,34 @@ void InsetTabular::drawCellLines(Painter & pain, int x, int baseline,
 
        if (!tabular->topAlreadyDrawn(cell)) {
                on_off = !tabular->TopLine(cell);
-               pain.line(x, baseline - tabular->GetAscentOfRow(row),
-                         x2, baseline -  tabular->GetAscentOfRow(row),
+               pain.line(x, y - tabular->GetAscentOfRow(row),
+                         x2, y -  tabular->GetAscentOfRow(row),
                          on_off ? LColor::tabularonoffline : LColor::tabularline,
                          on_off ? Painter::line_onoffdash : Painter::line_solid);
        }
        on_off = !tabular->BottomLine(cell);
-       pain.line(x, baseline + tabular->GetDescentOfRow(row),
-                 x2, baseline + tabular->GetDescentOfRow(row),
+       pain.line(x, y + tabular->GetDescentOfRow(row),
+                 x2, y + tabular->GetDescentOfRow(row),
                  on_off ? LColor::tabularonoffline : LColor::tabularline,
                  on_off ? Painter::line_onoffdash : Painter::line_solid);
        if (!tabular->leftAlreadyDrawn(cell)) {
                on_off = !tabular->LeftLine(cell);
-               pain.line(x, baseline -  tabular->GetAscentOfRow(row),
-                         x, baseline +  tabular->GetDescentOfRow(row),
+               pain.line(x, y -  tabular->GetAscentOfRow(row),
+                         x, y +  tabular->GetDescentOfRow(row),
                          on_off ? LColor::tabularonoffline : LColor::tabularline,
                          on_off ? Painter::line_onoffdash : Painter::line_solid);
        }
        on_off = !tabular->RightLine(cell);
        pain.line(x2 - tabular->GetAdditionalWidth(cell),
-                 baseline -  tabular->GetAscentOfRow(row),
+                 y -  tabular->GetAscentOfRow(row),
                  x2 - tabular->GetAdditionalWidth(cell),
-                 baseline +  tabular->GetDescentOfRow(row),
+                 y +  tabular->GetDescentOfRow(row),
                  on_off ? LColor::tabularonoffline : LColor::tabularline,
                  on_off ? Painter::line_onoffdash : Painter::line_solid);
 }
 
 
-void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
+void InsetTabular::drawCellSelection(Painter & pain, int x, int y,
                                     int row, int column, int cell) const
 {
        lyx::Assert(hasSelection());
@@ -382,7 +389,7 @@ void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
        if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
                int w = tabular->GetWidthOfColumn(cell);
                int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row)-1;
-               pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row) + 1,
+               pain.fillRectangle(x, y - tabular->GetAscentOfRow(row) + 1,
                                   w, h, LColor::selection);
        }
 }
@@ -437,58 +444,7 @@ void InsetTabular::update(BufferView * bv, bool reinit)
 
 string const InsetTabular::editMessage() const
 {
-       return _("Opened Tabular Inset");
-}
-
-
-void InsetTabular::edit(BufferView * bv, int x, int y, mouse_button::state button)
-{
-       UpdatableInset::edit(bv, x, y, button);
-
-       if (!bv->lockInset(this)) {
-               lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
-               return;
-       }
-       locked = true;
-       the_locking_inset = 0;
-       inset_x = 0;
-       inset_y = 0;
-       setPos(bv, x, y);
-       clearSelection();
-       finishUndo();
-       if (insetHit(bv, x, y) && (button != mouse_button::button3)) {
-               activateCellInsetAbs(bv, x, y, button);
-       }
-}
-
-
-void InsetTabular::edit(BufferView * bv, bool front)
-{
-       UpdatableInset::edit(bv, front);
-
-       if (!bv->lockInset(this)) {
-               lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
-               return;
-       }
-       finishUndo();
-       locked = true;
-       the_locking_inset = 0;
-       inset_x = 0;
-       inset_y = 0;
-       if (front) {
-               if (isRightToLeft(bv))
-                       actcell = tabular->GetLastCellInRow(0);
-               else
-                       actcell = 0;
-       } else {
-               if (isRightToLeft(bv))
-                       actcell = tabular->GetFirstCellInRow(tabular->rows()-1);
-               else
-                       actcell = tabular->GetNumberOfCells() - 1;
-       }
-       clearSelection();
-       resetPos(bv);
-       bv->fitCursor();
+       return _("Opened table");
 }
 
 
@@ -499,7 +455,6 @@ void InsetTabular::insetUnlock(BufferView * bv)
                updateLocal(bv, CELL);
                the_locking_inset = 0;
        }
-       hideInsetCursor(bv);
        actcell = 0;
        oldcell = -1;
        locked = false;
@@ -557,7 +512,7 @@ bool InsetTabular::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
                        }
                        if (in->getInsetFromID(id)) {
                                actcell = i;
-                               in->edit(bv);
+                               in->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
                                return the_locking_inset->lockInsetInInset(bv, inset);
                        }
                }
@@ -590,7 +545,6 @@ bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
                updateLocal(bv, CELL);
                // this has to be here otherwise we don't redraw the cell!
                the_locking_inset = 0;
-//             showInsetCursor(bv, false);
                return true;
        }
        if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
@@ -672,7 +626,6 @@ void InsetTabular::lfunMousePress(FuncRequest const & cmd)
        int const orow = actrow;
        BufferView * bv = cmd.view();
 
-       hideInsetCursor(bv);
        if (!locked) {
                locked = true;
                the_locking_inset = 0;
@@ -690,7 +643,6 @@ void InsetTabular::lfunMousePress(FuncRequest const & cmd)
                        updateLocal(bv, CELL);
                        the_locking_inset = 0;
                }
-               showInsetCursor(bv);
                return;
        }
 #endif
@@ -730,7 +682,6 @@ void InsetTabular::lfunMousePress(FuncRequest const & cmd)
                the_locking_inset->localDispatch(cmd1);
                return;
        }
-       showInsetCursor(bv);
 }
 
 
@@ -744,8 +695,7 @@ bool InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
                ret = the_locking_inset->localDispatch(cmd1);
        }
        if (cmd.button() == mouse_button::button3 && !ret) {
-               InsetTabularMailer mailer(*this);
-               mailer.showDialog(cmd.view());
+               InsetTabularMailer(*this).showDialog(cmd.view());
                return true;
        }
        return ret;
@@ -763,7 +713,6 @@ void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
        }
 
        BufferView * bv = cmd.view();
-       hideInsetCursor(bv);
        int const old_cell = actcell;
 
        setPos(bv, cmd.x, cmd.y);
@@ -774,7 +723,6 @@ void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
                setSelection(sel_cell_start, actcell);
                updateLocal(bv, SELECTION);
        }
-       showInsetCursor(bv);
 }
 
 
@@ -784,8 +732,49 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
        // the_locking_inset->localDispatch might unlock it.
        old_locking_inset = the_locking_inset;
        RESULT result = UpdatableInset::localDispatch(cmd);
-
        BufferView * bv = cmd.view();
+
+       if (cmd.action == LFUN_INSET_EDIT) {
+
+               if (!bv->lockInset(this)) {
+                       lyxerr[Debug::INSETTEXT] << "InsetTabular::Cannot lock inset" << endl;
+                       return DISPATCHED;
+               }
+
+               finishUndo();
+               locked = true;
+               the_locking_inset = 0;
+               inset_x = 0;
+               inset_y = 0;
+
+               if (cmd.argument.size()) {
+                       if (cmd.argument == "left") {
+                               if (isRightToLeft(bv))
+                                       actcell = tabular->GetLastCellInRow(0);
+                               else
+                                       actcell = 0;
+                       } else {
+                               if (isRightToLeft(bv))
+                                       actcell = tabular->GetFirstCellInRow(tabular->rows()-1);
+                               else
+                                       actcell = tabular->GetNumberOfCells() - 1;
+                       }
+                       clearSelection();
+                       resetPos(bv);
+                       bv->fitCursor();
+               }
+
+               else {
+                       setPos(bv, cmd.x, cmd.y);
+                       clearSelection();
+                       finishUndo();
+                       if (insetHit(bv, cmd.x, cmd.y) && cmd.button() != mouse_button::button3) {
+                               activateCellInsetAbs(bv, cmd.x, cmd.y, cmd.button());
+                       }
+               }
+               return DISPATCHED;
+       }
+
        if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
                resetPos(bv);
                return result;
@@ -814,7 +803,6 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
 
                case LFUN_CELL_BACKWARD:
                case LFUN_CELL_FORWARD:
-                       hideInsetCursor(bv);
                        unlockInsetInInset(bv, the_locking_inset);
                        if (cmd.action == LFUN_CELL_FORWARD)
                                moveNextCell(bv, old_locking_inset != 0);
@@ -824,7 +812,6 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                        if (hs)
                                updateLocal(bv, SELECTION);
                        if (!the_locking_inset) {
-                               showInsetCursor(bv);
                                return DISPATCHED_NOUPDATE;
                        }
                        return result;
@@ -842,15 +829,11 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                        int sc = scroll();
                        resetPos(bv);
                        if (sc != scroll()) { // inset has been scrolled
-                               the_locking_inset->toggleInsetCursor(bv);
                                updateLocal(bv, FULL);
-                               the_locking_inset->toggleInsetCursor(bv);
                        }
                        return result;
                } else if (result == DISPATCHED) {
-                       the_locking_inset->toggleInsetCursor(bv);
                        updateLocal(bv, CELL);
-                       the_locking_inset->toggleInsetCursor(bv);
                        return result;
                } else if (result == FINISHED_UP) {
                        action = LFUN_UP;
@@ -868,7 +851,6 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                }
        }
 
-       hideInsetCursor(bv);
        result = DISPATCHED;
        switch (action) {
                // --- Cursor Movements ----------------------------------
@@ -1069,9 +1051,7 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                        break;
                // no break here!
        case LFUN_DELETE:
-               setUndo(bv, Undo::DELETE,
-                       bv->text->cursor.par(),
-                       boost::next(bv->text->cursor.par()));
+               setUndo(bv, Undo::DELETE, bv->text->cursor.par());
                cutSelection(bv->buffer()->params);
                updateLocal(bv, INIT);
                break;
@@ -1154,9 +1134,7 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
        }
        case LFUN_PASTE:
                if (hasPasteBuffer()) {
-                       setUndo(bv, Undo::INSERT,
-                               bv->text->cursor.par(),
-                               boost::next(bv->text->cursor.par()));
+                       setUndo(bv, Undo::INSERT, bv->text->cursor.par());
                        pasteSelection(bv);
                        updateLocal(bv, INIT);
                        break;
@@ -1216,8 +1194,6 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                if (!the_locking_inset) {
                        if (bv->fitCursor())
                                updateLocal(bv, FULL);
-                       if (locked)
-                               showInsetCursor(bv);
                }
        } else
                bv->unlockInset(this);
@@ -1226,9 +1202,9 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
 
 
 int InsetTabular::latex(Buffer const * buf, ostream & os,
-                       bool fragile, bool fp) const
+                       LatexRunParams const & runparams) const
 {
-       return tabular->latex(buf, os, fragile, fp);
+       return tabular->latex(buf, os, runparams);
 }
 
 
@@ -1336,65 +1312,34 @@ bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) c
 }
 
 
-void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
+void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
 {
        if (the_locking_inset) {
-               the_locking_inset->getCursorPos(bv, x, y);
-               return;
-       }
-       x = cursor_.x() - top_x;
-       y = cursor_.y();
-}
-
-
-void InsetTabular::toggleInsetCursor(BufferView * bv)
-{
-       if (nodraw()) {
-               if (isCursorVisible())
-                       bv->hideLockedInsetCursor();
-               return;
-       }
-       if (the_locking_inset) {
-               the_locking_inset->toggleInsetCursor(bv);
+               the_locking_inset->getCursor(bv, x, y);
                return;
        }
 
-       LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
+       x = cursor_.x();
+       y = cursor_.y() + InsetTabular::y();
 
-       int const asc = font_metrics::maxAscent(font);
-       int const desc = font_metrics::maxDescent(font);
-
-       if (isCursorVisible())
-               bv->hideLockedInsetCursor();
-       else
-               bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
-       toggleCursorVisible();
+       // Fun stuff
+       int desc = tabular->GetDescentOfRow(actrow);
+       y += desc;
+       int ascdesc = tabular->GetAscentOfRow(actrow) + desc;
+       y -= ascdesc / 2;
+       y += ADD_TO_HEIGHT * 2;
+       y += TEXT_TO_INSET_OFFSET;
 }
 
 
-void InsetTabular::showInsetCursor(BufferView * bv, bool show)
+void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
 {
-       if (nodraw())
+       if (the_locking_inset) {
+               the_locking_inset->getCursorPos(bv, x, y);
                return;
-       if (!isCursorVisible()) {
-               LyXFont font; // = GetFont(par, cursor.pos);
-
-               int const asc = font_metrics::maxAscent(font);
-               int const desc = font_metrics::maxDescent(font);
-               bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
-               if (show)
-                       bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
-               setCursorVisible(true);
-       }
-}
-
-
-void InsetTabular::hideInsetCursor(BufferView * bv)
-{
-       if (isCursorVisible()) {
-               bv->hideLockedInsetCursor();
-               setCursorVisible(false);
        }
+       x = cursor_.x() - top_x;
+       y = cursor_.y();
 }
 
 
@@ -1683,9 +1628,7 @@ void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
                setSelection(0, tabular->GetNumberOfCells() - 1);
        }
        if (hasSelection()) {
-               setUndo(bv, Undo::EDIT,
-                       bv->text->cursor.par(),
-                       boost::next(bv->text->cursor.par()));
+               setUndo(bv, Undo::EDIT, bv->text->cursor.par());
                bool const frozen = undo_frozen;
                if (!frozen)
                        freezeUndo();
@@ -1807,9 +1750,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
                sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
        }
-       setUndo(bv, Undo::FINISH,
-               bv->text->cursor.par(),
-               boost::next(bv->text->cursor.par()));
+       setUndo(bv, Undo::FINISH, bv->text->cursor.par());
 
        int row =  tabular->row_of_cell(actcell);
        int column = tabular->column_of_cell(actcell);
@@ -1825,6 +1766,11 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                bool const update = (tmplen != vallen);
                tabular->SetColumnPWidth(actcell, vallen);
                if (update) {
+                       // We need this otherwise we won't resize
+                       // the insettext of the active cell (if any)
+                       // until later (see InsetText::do_resize)
+                       unlockInsetInInset(bv, the_locking_inset);
+
                        int cell;
                        for (int i = 0; i < tabular->rows(); ++i) {
                                cell = tabular->GetCellNumber(i,column);
@@ -1849,6 +1795,11 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                bool const update = (tmplen != vallen);
                tabular->SetMColumnPWidth(actcell, vallen);
                if (update) {
+                       // We need this otherwise we won't resize
+                       // the insettext of the active cell (if any)
+                       // until later (see InsetText::do_resize)
+                       unlockInsetInInset(bv, the_locking_inset);
+
                        for (int i = 0; i < tabular->rows(); ++i) {
                                tabular->GetCellInset(tabular->GetCellNumber(i, column))->
                                        resizeLyXText(bv);
@@ -2129,7 +2080,7 @@ bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, mouse_button
        }
        //inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
        //inset_y = cursor.y();
-       inset->edit(bv, x,  y, button);
+       inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT, x,  y, button));
        if (!the_locking_inset)
                return false;
        updateLocal(bv, CELL);
@@ -2569,18 +2520,10 @@ void InsetTabular::getSelection(int & srow, int & erow,
 }
 
 
-Paragraph * InsetTabular::firstParagraph() const
-{
-       if (the_locking_inset)
-               return the_locking_inset->firstParagraph();
-       return 0;
-}
-
-
-Paragraph * InsetTabular::getFirstParagraph(int i) const
+ParagraphList * InsetTabular::getParagraphs(int i) const
 {
        return (i < tabular->GetNumberOfCells())
-               ? tabular->GetCellInset(i)->getFirstParagraph(0)
+               ? tabular->GetCellInset(i)->getParagraphs(0)
                : 0;
 }
 
@@ -2629,7 +2572,7 @@ InsetTabular::selectNextWordToSpellcheck(BufferView * bv, float & value) const
        // otherwise we have to lock the next inset and ask for it's selecttion
        UpdatableInset * inset =
                static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
-       inset->edit(bv, 0,  0, mouse_button::none);
+       inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
        WordLangTuple word(selectNextWordInt(bv, value));
        nodraw(false);
        if (!word.word().empty())
@@ -2655,7 +2598,7 @@ WordLangTuple InsetTabular::selectNextWordInt(BufferView * bv, float & value) co
        // otherwise we have to lock the next inset and ask for it's selecttion
        UpdatableInset * inset =
                static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
-       inset->edit(bv);
+       inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
        return selectNextWordInt(bv, value);
 }
 
@@ -2861,7 +2804,7 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
                        if (cols < columns) {
                                InsetText * ti = loctab->GetCellInset(cell);
                                LyXFont const font = ti->getLyXText(bv)->
-                                       getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
+                                       getFont(bv->buffer(), ti->paragraphs.begin(), 0);
                                ti->setText(buf.substr(op, p - op), font);
                                ++cols;
                                ++cell;
@@ -2872,7 +2815,7 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
                        if (cols < columns) {
                                InsetText * ti = loctab->GetCellInset(cell);
                                LyXFont const font = ti->getLyXText(bv)->
-                                       getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
+                                       getFont(bv->buffer(), ti->paragraphs.begin(), 0);
                                ti->setText(buf.substr(op, p - op), font);
                        }
                        cols = ocol;
@@ -2888,7 +2831,7 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
        if ((cell < cells) && (op < len)) {
                InsetText * ti = loctab->GetCellInset(cell);
                LyXFont const font = ti->getLyXText(bv)->
-                       getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
+                       getFont(bv->buffer(), ti->paragraphs.begin(), 0);
                ti->setText(buf.substr(op, len - op), font);
        }
 
@@ -2923,7 +2866,7 @@ string const InsetTabularMailer::inset2string() const
 
 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
 {
-       istringstream data(in);
+       istringstream data(STRCONV(in));
        LyXLex lex(0,0);
        lex.setStream(data);
 
@@ -2960,6 +2903,7 @@ int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
        if (!lex.isOK())
                return -1;
 
+       // FIXME: even current_view would be better than this.
        BufferView * const bv = inset.view();
        Buffer const * const buffer = bv ? bv->buffer() : 0;
        if (buffer)
@@ -2971,9 +2915,9 @@ int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
 }
 
 
-string const
-InsetTabularMailer::params2string(InsetTabular const & inset)
+string const InsetTabularMailer::params2string(InsetTabular const & inset)
 {
+       // FIXME: even current_view would be better than this.
        BufferView * const bv = inset.view();
        Buffer const * const buffer = bv ? bv->buffer() : 0;
        if (!buffer)
@@ -2983,6 +2927,5 @@ InsetTabularMailer::params2string(InsetTabular const & inset)
        data << name_ << " \\active_cell " << inset.getActCell() << '\n';
        inset.write(buffer, data);
        data << "\\end_inset\n";
-
-       return data.str();
+       return STRCONV(data.str());
 }