]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettabular.C
Rename LatexRunParams::fragile as moving_arg.
[lyx.git] / src / insets / insettabular.C
index ece2cab22c324ba49536caea142b0c03c4e4a804..cec7de014a5e3d16e97a47c54161beccbf8c4a4b 100644 (file)
 
 #include <config.h>
 
-
 #include "insettabular.h"
 #include "insettext.h"
 
 #include "buffer.h"
 #include "BufferView.h"
-#include "commandtags.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 "Lsstream.h"
 
 #include "frontends/Alert.h"
 #include "frontends/Dialogs.h"
@@ -242,21 +244,12 @@ 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::dimension(BufferView *, LyXFont const &,
+       Dimension & dim) const
 {
-       return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
-}
-
-
-int InsetTabular::width(BufferView *, LyXFont const &) const
-{
-       return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
+       dim.a = tabular->GetAscentOfRow(0);
+       dim.d = tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
+       dim.w = tabular->GetWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
 }
 
 
@@ -281,7 +274,6 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
 #endif
 
        top_x = int(x);
-       topx_set = true;
        top_baseline = baseline;
        x += ADD_TO_TABULAR_WIDTH;
 
@@ -323,15 +315,7 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
 
        x -= ADD_TO_TABULAR_WIDTH;
        x += width(bv, font);
-       if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
-               int i = 0;
-               for(Inset * inset = owner(); inset; ++i)
-                       inset = inset->owner();
-               if (calculate_dimensions_of_cells(bv, font, false))
-                       need_update = INIT;
-       } else {
-               need_update = NONE;
-       }
+       need_update = NONE;
 }
 
 
@@ -397,30 +381,30 @@ void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline,
 }
 
 
-void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
+void InsetTabular::update(BufferView * bv, bool reinit)
 {
        if (in_update) {
                if (reinit) {
                        resetPos(bv);
                        if (owner())
-                               owner()->update(bv, font, true);
+                               owner()->update(bv, true);
                }
                return;
        }
        in_update = true;
        if (reinit) {
                need_update = INIT;
-               if (calculate_dimensions_of_cells(bv, font, true))
+               if (calculate_dimensions_of_cells(bv, true))
                        resetPos(bv);
                if (owner())
-                       owner()->update(bv, font, true);
+                       owner()->update(bv, true);
                in_update = false;
                return;
        }
        if (the_locking_inset)
-               the_locking_inset->update(bv, font, reinit);
+               the_locking_inset->update(bv, reinit);
        if (need_update < FULL &&
-               bv->text->status() == LyXText::NEED_MORE_REFRESH)
+               bv->text->refreshStatus() == LyXText::REFRESH_AREA)
        {
                need_update = FULL;
        }
@@ -429,7 +413,7 @@ void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
        case INIT:
        case FULL:
        case CELL:
-               if (calculate_dimensions_of_cells(bv, font, false)) {
+               if (calculate_dimensions_of_cells(bv, false)) {
                        need_update = INIT;
                        resetPos(bv);
                }
@@ -446,58 +430,7 @@ void InsetTabular::update(BufferView * bv, LyXFont const & font, 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");
 }
 
 
@@ -505,10 +438,9 @@ void InsetTabular::insetUnlock(BufferView * bv)
 {
        if (the_locking_inset) {
                the_locking_inset->insetUnlock(bv);
-               updateLocal(bv, CELL, false);
+               updateLocal(bv, CELL);
                the_locking_inset = 0;
        }
-       hideInsetCursor(bv);
        actcell = 0;
        oldcell = -1;
        locked = false;
@@ -517,17 +449,15 @@ void InsetTabular::insetUnlock(BufferView * bv)
                if (scroll(false)) {
                        scroll(bv, 0.0F);
                }
-               updateLocal(bv, FULL, false);
+               updateLocal(bv, FULL);
        }
 }
 
 
-void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
-                              bool mark_dirty) const
+void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what) const
 {
        if (what == INIT) {
-               LyXFont font;
-               calculate_dimensions_of_cells(bv, font, true);
+               calculate_dimensions_of_cells(bv, true);
        }
        if (!locked && what == CELL)
                what = FULL;
@@ -535,7 +465,7 @@ void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what,
                need_update = what;
        // Dirty Cast! (Lgb)
        if (need_update != NONE) {
-               bv->updateInset(const_cast<InsetTabular *>(this), mark_dirty);
+               bv->updateInset(const_cast<InsetTabular *>(this));
                if (locked)
                        resetPos(bv);
        }
@@ -568,7 +498,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);
                        }
                }
@@ -598,10 +528,9 @@ bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
                if (scroll(false))
                        scroll(bv, 0.0F);
 #endif
-               updateLocal(bv, CELL, false);
+               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)) {
@@ -631,7 +560,7 @@ bool InsetTabular::updateInsetInInset(BufferView * bv, Inset * inset)
                if (!static_cast<InsetText *>(tl_inset)->updateInsetInInset(bv, inset))
                        return false;
        }
-       updateLocal(bv, CELL, false);
+       updateLocal(bv, CELL);
        return true;
 }
 
@@ -676,14 +605,13 @@ void InsetTabular::lfunMousePress(FuncRequest const & cmd)
 
        if (hasSelection()) {
                clearSelection();
-               updateLocal(cmd.view(), SELECTION, false);
+               updateLocal(cmd.view(), SELECTION);
        }
 
        int const ocell = actcell;
        int const orow = actrow;
        BufferView * bv = cmd.view();
 
-       hideInsetCursor(bv);
        if (!locked) {
                locked = true;
                the_locking_inset = 0;
@@ -692,16 +620,15 @@ void InsetTabular::lfunMousePress(FuncRequest const & cmd)
        }
        setPos(bv, cmd.x, cmd.y);
        if (actrow != orow)
-               updateLocal(bv, NONE, false);
+               updateLocal(bv, NONE);
        clearSelection();
 #if 0
        if (cmd.button() == mouse_button::button3) {
                if ((ocell != actcell) && the_locking_inset) {
                        the_locking_inset->insetUnlock(bv);
-                       updateLocal(bv, CELL, false);
+                       updateLocal(bv, CELL);
                        the_locking_inset = 0;
                }
-               showInsetCursor(bv);
                return;
        }
 #endif
@@ -719,7 +646,7 @@ void InsetTabular::lfunMousePress(FuncRequest const & cmd)
 
        if (the_locking_inset) {
                the_locking_inset->insetUnlock(bv);
-               updateLocal(bv, CELL, false);
+               updateLocal(bv, CELL);
                the_locking_inset = 0;
        }
 
@@ -741,7 +668,6 @@ void InsetTabular::lfunMousePress(FuncRequest const & cmd)
                the_locking_inset->localDispatch(cmd1);
                return;
        }
-       showInsetCursor(bv);
 }
 
 
@@ -774,18 +700,16 @@ void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
        }
 
        BufferView * bv = cmd.view();
-       hideInsetCursor(bv);
        int const old_cell = actcell;
 
        setPos(bv, cmd.x, cmd.y);
        if (!hasSelection()) {
                setSelection(actcell, actcell);
-               updateLocal(bv, SELECTION, false);
+               updateLocal(bv, SELECTION);
        } else if (old_cell != actcell) {
                setSelection(sel_cell_start, actcell);
-               updateLocal(bv, SELECTION, false);
+               updateLocal(bv, SELECTION);
        }
-       showInsetCursor(bv);
 }
 
 
@@ -795,8 +719,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;
@@ -823,19 +788,17 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                case LFUN_MOUSE_RELEASE:
                        return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
 
-               case LFUN_SHIFT_TAB:
-               case LFUN_TAB:
-                       hideInsetCursor(bv);
+               case LFUN_CELL_BACKWARD:
+               case LFUN_CELL_FORWARD:
                        unlockInsetInInset(bv, the_locking_inset);
-                       if (cmd.action == LFUN_TAB)
+                       if (cmd.action == LFUN_CELL_FORWARD)
                                moveNextCell(bv, old_locking_inset != 0);
                        else
                                movePrevCell(bv, old_locking_inset != 0);
                        clearSelection();
                        if (hs)
-                               updateLocal(bv, SELECTION, false);
+                               updateLocal(bv, SELECTION);
                        if (!the_locking_inset) {
-                               showInsetCursor(bv);
                                return DISPATCHED_NOUPDATE;
                        }
                        return result;
@@ -853,26 +816,28 @@ 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, false);
-                               the_locking_inset->toggleInsetCursor(bv);
+                               updateLocal(bv, FULL);
                        }
                        return result;
                } else if (result == DISPATCHED) {
-                       the_locking_inset->toggleInsetCursor(bv);
-                       updateLocal(bv, CELL, false);
-                       the_locking_inset->toggleInsetCursor(bv);
+                       updateLocal(bv, CELL);
                        return result;
                } else if (result == FINISHED_UP) {
                        action = LFUN_UP;
+                       // Make sure to reset status message after
+                       // exiting, e.g. math inset
+                       bv->owner()->clearMessage();
                } else if (result == FINISHED_DOWN) {
                        action = LFUN_DOWN;
+                       bv->owner()->clearMessage();
                } else if (result == FINISHED_RIGHT) {
                        action = LFUN_RIGHT;
+                       bv->owner()->clearMessage();
+               } else if (result == FINISHED) {
+                       bv->owner()->clearMessage();
                }
        }
 
-       hideInsetCursor(bv);
        result = DISPATCHED;
        switch (action) {
                // --- Cursor Movements ----------------------------------
@@ -891,14 +856,14 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                        end = actcell;
                }
                setSelection(start, end);
-               updateLocal(bv, SELECTION, false);
+               updateLocal(bv, SELECTION);
                break;
        }
        case LFUN_RIGHT:
                result = moveRight(bv);
                clearSelection();
                if (hs)
-                       updateLocal(bv, SELECTION, false);
+                       updateLocal(bv, SELECTION);
                break;
        case LFUN_LEFTSEL: {
                int const start = hasSelection() ? sel_cell_start : actcell;
@@ -915,14 +880,14 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                        end = actcell;
                }
                setSelection(start, end);
-               updateLocal(bv, SELECTION, false);
+               updateLocal(bv, SELECTION);
                break;
        }
        case LFUN_LEFT:
                result = moveLeft(bv);
                clearSelection();
                if (hs)
-                       updateLocal(bv, SELECTION, false);
+                       updateLocal(bv, SELECTION);
                break;
        case LFUN_DOWNSEL: {
                int const start = hasSelection() ? sel_cell_start : actcell;
@@ -939,14 +904,14 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                } else {
                        setSelection(start, start);
                }
-               updateLocal(bv, SELECTION, false);
+               updateLocal(bv, SELECTION);
        }
        break;
        case LFUN_DOWN:
                result = moveDown(bv, old_locking_inset != 0);
                clearSelection();
                if (hs) {
-                       updateLocal(bv, SELECTION, false);
+                       updateLocal(bv, SELECTION);
                }
                break;
        case LFUN_UPSEL: {
@@ -964,14 +929,14 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                } else {
                        setSelection(start, start);
                }
-               updateLocal(bv, SELECTION, false);
+               updateLocal(bv, SELECTION);
        }
        break;
        case LFUN_UP:
                result = moveUp(bv, old_locking_inset != 0);
                clearSelection();
                if (hs)
-                       updateLocal(bv, SELECTION, false);
+                       updateLocal(bv, SELECTION);
                break;
        case LFUN_NEXT: {
                UpdateCodes code = CURSOR;
@@ -991,7 +956,7 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                                actcell = tabular->GetFirstCellInRow(tabular->rows() - 1) + column;
                        }
                resetPos(bv);
-               updateLocal(bv, code, false);
+               updateLocal(bv, code);
                break;
        }
        case LFUN_PRIOR: {
@@ -1013,7 +978,7 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                        actcell = column;
                }
                resetPos(bv);
-               updateLocal(bv, code, false);
+               updateLocal(bv, code);
                break;
        }
        // none of these make sense for insettabular,
@@ -1062,7 +1027,7 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                if (tmpstr.empty())
                        break;
                if (insertAsciiString(bv, tmpstr, false))
-                       updateLocal(bv, INIT, true);
+                       updateLocal(bv, INIT);
                else
                        result = UNDISPATCHED;
                break;
@@ -1075,9 +1040,9 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
        case LFUN_DELETE:
                setUndo(bv, Undo::DELETE,
                        bv->text->cursor.par(),
-                       bv->text->cursor.par()->next());
+                       boost::next(bv->text->cursor.par()));
                cutSelection(bv->buffer()->params);
-               updateLocal(bv, INIT, true);
+               updateLocal(bv, INIT);
                break;
        case LFUN_COPY:
                if (!hasSelection())
@@ -1160,9 +1125,9 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                if (hasPasteBuffer()) {
                        setUndo(bv, Undo::INSERT,
                                bv->text->cursor.par(),
-                               bv->text->cursor.par()->next());
+                               boost::next(bv->text->cursor.par()));
                        pasteSelection(bv);
-                       updateLocal(bv, INIT, true);
+                       updateLocal(bv, INIT);
                        break;
                }
                // ATTENTION: the function above has to be PASTE and PASTESELECTION!!!
@@ -1202,7 +1167,7 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                                unlockInsetInInset(bv, the_locking_inset);
                                nodraw(false);
                                // we need to update if this was requested before
-                               updateLocal(bv, NONE, false);
+                               updateLocal(bv, NONE);
                                return UNDISPATCHED;
                        } else if (hs) {
                                clearSelection();
@@ -1211,7 +1176,7 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                                need_update = SELECTION;
                        }
                        nodraw(false);
-                       updateLocal(bv, CELL, false);
+                       updateLocal(bv, CELL);
                        return result;
                }
                break;
@@ -1219,9 +1184,7 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
        if (result < FINISHED) {
                if (!the_locking_inset) {
                        if (bv->fitCursor())
-                               updateLocal(bv, FULL, false);
-                       if (locked)
-                               showInsetCursor(bv);
+                               updateLocal(bv, FULL);
                }
        } else
                bv->unlockInset(this);
@@ -1230,9 +1193,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);
 }
 
 
@@ -1290,9 +1253,7 @@ void InsetTabular::validate(LaTeXFeatures & features) const
 }
 
 
-bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
-                                                LyXFont const & font,
-                                                bool reinit) const
+bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) const
 {
        int cell = -1;
        int maxAsc = 0;
@@ -1300,6 +1261,10 @@ bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
        InsetText * inset;
        bool changed = false;
 
+       // FIXME: since InsetText ignores this anyway, it doesn't
+       // matter what we pass it. Ugly
+       LyXFont font;
+
        // if we have a locking_inset we should have to check only this cell for
        // change so I'll try this to have a boost, but who knows ;)
        if ((need_update != INIT) &&
@@ -1324,7 +1289,7 @@ bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
                        ++cell;
                        inset = tabular->GetCellInset(cell);
                        if (!reinit && !tabular->GetPWidth(cell).zero())
-                               inset->update(bv, font, false);
+                               inset->update(bv, false);
                        maxAsc = max(maxAsc, inset->ascent(bv, font));
                        maxDesc = max(maxDesc, inset->descent(bv, font));
                        changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
@@ -1338,65 +1303,34 @@ bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
 }
 
 
-void InsetTabular::getCursorPos(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)
+void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
 {
-       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();
 }
 
 
@@ -1501,34 +1435,34 @@ void InsetTabular::resetPos(BufferView * bv) const
                (tabular->GetWidthOfTabular() < bv->workWidth()-20))
        {
                scroll(bv, 0.0F);
-               updateLocal(bv, FULL, false);
+               updateLocal(bv, FULL);
        } else if (the_locking_inset &&
                 (tabular->GetWidthOfColumn(actcell) > bv->workWidth()-20))
        {
-               int xx = cursor_.x() - offset + bv->text->getRealCursorX(bv);
+               int xx = cursor_.x() - offset + bv->text->getRealCursorX();
                if (xx > (bv->workWidth()-20)) {
                        scroll(bv, -(xx - bv->workWidth() + 60));
-                       updateLocal(bv, FULL, false);
+                       updateLocal(bv, FULL);
                } else if (xx < 20) {
                        if (xx < 0)
                                xx = -xx + 60;
                        else
                                xx = 60;
                        scroll(bv, xx);
-                       updateLocal(bv, FULL, false);
+                       updateLocal(bv, FULL);
                }
        } else if ((cursor_.x() - offset) > 20 &&
                   (cursor_.x() - offset + tabular->GetWidthOfColumn(actcell))
                   > (bv->workWidth() - 20)) {
                scroll(bv, -tabular->GetWidthOfColumn(actcell) - 20);
-               updateLocal(bv, FULL, false);
+               updateLocal(bv, FULL);
        } else if ((cursor_.x() - offset) < 20) {
                scroll(bv, 20 - cursor_.x() + offset);
-               updateLocal(bv, FULL, false);
+               updateLocal(bv, FULL);
        } else if (scroll() && top_x > 20 &&
                   (top_x + tabular->GetWidthOfTabular()) > (bv->workWidth() - 20)) {
                scroll(bv, old_x - cursor_.x());
-               updateLocal(bv, FULL, false);
+               updateLocal(bv, FULL);
        }
        if (the_locking_inset) {
                inset_x = cursor_.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
@@ -1640,7 +1574,7 @@ bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
                ++actcell;
        }
        if (lock) {
-               bool rtl = tabular->GetCellInset(actcell)->paragraph()->
+               bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
                        isRightToLeftPar(bv->buffer()->params);
                activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
        }
@@ -1669,7 +1603,7 @@ bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
                --actcell;
        }
        if (lock) {
-               bool rtl = tabular->GetCellInset(actcell)->paragraph()->
+               bool rtl = tabular->GetCellInset(actcell)->paragraphs.begin()->
                        isRightToLeftPar(bv->buffer()->params);
                activateCellInset(bv, 0, 0, mouse_button::none, !rtl);
        }
@@ -1687,7 +1621,7 @@ void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
        if (hasSelection()) {
                setUndo(bv, Undo::EDIT,
                        bv->text->cursor.par(),
-                       bv->text->cursor.par()->next());
+                       boost::next(bv->text->cursor.par()));
                bool const frozen = undo_frozen;
                if (!frozen)
                        freezeUndo();
@@ -1706,7 +1640,7 @@ void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
                        unFreezeUndo();
                if (selectall)
                        clearSelection();
-               updateLocal(bv, INIT, true);
+               updateLocal(bv, INIT);
        }
        if (the_locking_inset)
                the_locking_inset->setFont(bv, font, tall);
@@ -1811,7 +1745,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
        }
        setUndo(bv, Undo::FINISH,
                bv->text->cursor.par(),
-               bv->text->cursor.par()->next());
+               boost::next(bv->text->cursor.par()));
 
        int row =  tabular->row_of_cell(actcell);
        int column = tabular->column_of_cell(actcell);
@@ -1832,7 +1766,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                                cell = tabular->GetCellNumber(i,column);
                                tabular->GetCellInset(cell)->resizeLyXText(bv);
                        }
-                       updateLocal(bv, INIT, true);
+                       updateLocal(bv, INIT);
                }
 
                if (vallen.zero()
@@ -1855,27 +1789,27 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                                tabular->GetCellInset(tabular->GetCellNumber(i, column))->
                                        resizeLyXText(bv);
                        }
-                       updateLocal(bv, INIT, true);
+                       updateLocal(bv, INIT);
                }
        }
        break;
        case LyXTabular::SET_SPECIAL_COLUMN:
        case LyXTabular::SET_SPECIAL_MULTI:
                tabular->SetAlignSpecial(actcell,value,feature);
-               updateLocal(bv, FULL, true);
+               updateLocal(bv, FULL);
                break;
        case LyXTabular::APPEND_ROW:
                // append the row into the tabular
                unlockInsetInInset(bv, the_locking_inset);
                tabular->AppendRow(bv->buffer()->params, actcell);
-               updateLocal(bv, INIT, true);
+               updateLocal(bv, INIT);
                break;
        case LyXTabular::APPEND_COLUMN:
                // append the column into the tabular
                unlockInsetInInset(bv, the_locking_inset);
                tabular->AppendColumn(bv->buffer()->params, actcell);
                actcell = tabular->GetCellNumber(row, column);
-               updateLocal(bv, INIT, true);
+               updateLocal(bv, INIT);
                break;
        case LyXTabular::DELETE_ROW:
                unlockInsetInInset(bv, the_locking_inset);
@@ -1886,7 +1820,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                        --sel_row_start;
                actcell = tabular->GetCellNumber(sel_row_start, column);
                clearSelection();
-               updateLocal(bv, INIT, true);
+               updateLocal(bv, INIT);
                break;
        case LyXTabular::DELETE_COLUMN:
                unlockInsetInInset(bv, the_locking_inset);
@@ -1897,7 +1831,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                        --sel_col_start;
                actcell = tabular->GetCellNumber(row, sel_col_start);
                clearSelection();
-               updateLocal(bv, INIT, true);
+               updateLocal(bv, INIT);
                break;
        case LyXTabular::M_TOGGLE_LINE_TOP:
                flag = false;
@@ -1909,7 +1843,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                                tabular->SetTopLine(
                                        tabular->GetCellNumber(i, j),
                                        lineSet, flag);
-               updateLocal(bv, INIT, true);
+               updateLocal(bv, INIT);
                break;
        }
 
@@ -1924,7 +1858,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                                        tabular->GetCellNumber(i, j),
                                        lineSet,
                                        flag);
-               updateLocal(bv, INIT, true);
+               updateLocal(bv, INIT);
                break;
        }
 
@@ -1939,7 +1873,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                                        tabular->GetCellNumber(i,j),
                                        lineSet,
                                        flag);
-               updateLocal(bv, INIT, true);
+               updateLocal(bv, INIT);
                break;
        }
 
@@ -1954,7 +1888,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                                        tabular->GetCellNumber(i,j),
                                        lineSet,
                                        flag);
-               updateLocal(bv, INIT, true);
+               updateLocal(bv, INIT);
                break;
        }
 
@@ -1972,7 +1906,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                                        tabular->GetCellNumber(i, j),
                                        setAlign,
                                        flag);
-               updateLocal(bv, INIT, true);
+               updateLocal(bv, INIT);
                break;
        case LyXTabular::M_VALIGN_TOP:
        case LyXTabular::M_VALIGN_BOTTOM:
@@ -1986,14 +1920,16 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                                tabular->SetVAlignment(
                                        tabular->GetCellNumber(i, j),
                                        setVAlign, flag);
-               updateLocal(bv, INIT, true);
+               updateLocal(bv, INIT);
                break;
        case LyXTabular::MULTICOLUMN:
        {
                if (sel_row_start != sel_row_end) {
-                       Alert::alert(_("Impossible operation!"),
-                                  _("Multicolumns can only be horizontally."),
-                                  _("Sorry."));
+#ifdef WITH_WARNINGS
+#warning Need I say it ? This is horrible.
+#endif
+                       Alert::error(_("Error setting multicolumn"),
+                                  _("You cannot set multicolumn vertically."));
                        return;
                }
                // just multicol for one Single Cell
@@ -2001,12 +1937,12 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                        // check wether we are completly in a multicol
                        if (tabular->IsMultiColumn(actcell)) {
                                tabular->UnsetMultiColumn(actcell);
-                               updateLocal(bv, INIT, true);
+                               updateLocal(bv, INIT);
                        } else {
                                tabular->SetMultiColumn(bv->buffer(), actcell, 1);
-                               updateLocal(bv, CELL, true);
+                               updateLocal(bv, CELL);
                        }
-                       return;
+                       break;
                }
                // we have a selection so this means we just add all this
                // cells to form a multicolumn cell
@@ -2023,7 +1959,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                tabular->SetMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
                actcell = s_start;
                clearSelection();
-               updateLocal(bv, INIT, true);
+               updateLocal(bv, INIT);
                break;
        }
        case LyXTabular::SET_ALL_LINES:
@@ -2033,15 +1969,15 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                        for (int j = sel_col_start; j <= sel_col_end; ++j)
                                tabular->SetAllLines(
                                        tabular->GetCellNumber(i,j), setLines);
-               updateLocal(bv, INIT, true);
+               updateLocal(bv, INIT);
                break;
        case LyXTabular::SET_LONGTABULAR:
                tabular->SetLongTabular(true);
-               updateLocal(bv, INIT, true); // because this toggles displayed
+               updateLocal(bv, INIT); // because this toggles displayed
                break;
        case LyXTabular::UNSET_LONGTABULAR:
                tabular->SetLongTabular(false);
-               updateLocal(bv, INIT, true); // because this toggles displayed
+               updateLocal(bv, INIT); // because this toggles displayed
                break;
        case LyXTabular::SET_ROTATE_TABULAR:
                tabular->SetRotateTabular(true);
@@ -2111,6 +2047,9 @@ void InsetTabular::tabularFeatures(BufferView * bv,
        case LyXTabular::LAST_ACTION:
                break;
        }
+
+       InsetTabularMailer mailer(*this);
+       mailer.updateDialog(bv);
 }
 
 
@@ -2126,10 +2065,10 @@ 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, false);
+       updateLocal(bv, CELL);
        return (the_locking_inset != 0);
 }
 
@@ -2291,8 +2230,6 @@ FuncStatus InsetTabular::getStatus(string const & what) const
        case LyXTabular::SET_MPWIDTH:
        case LyXTabular::SET_SPECIAL_COLUMN:
        case LyXTabular::SET_SPECIAL_MULTI:
-               return status.disabled(true);
-
        case LyXTabular::APPEND_ROW:
        case LyXTabular::APPEND_COLUMN:
        case LyXTabular::DELETE_ROW:
@@ -2568,18 +2505,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;
 }
 
@@ -2628,7 +2557,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())
@@ -2654,7 +2583,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);
 }
 
@@ -2693,7 +2622,7 @@ bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
 {
        if (the_locking_inset) {
                if (the_locking_inset->nextChange(bv, length)) {
-                       updateLocal(bv, CELL, false);
+                       updateLocal(bv, CELL);
                        return true;
                }
                if (tabular->IsLastCell(actcell))
@@ -2702,14 +2631,14 @@ bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
        }
        InsetText * inset = tabular->GetCellInset(actcell);
        if (inset->nextChange(bv, length)) {
-               updateLocal(bv, FULL, false);
+               updateLocal(bv, FULL);
                return true;
        }
        while (!tabular->IsLastCell(actcell)) {
                ++actcell;
                inset = tabular->GetCellInset(actcell);
                if (inset->nextChange(bv, length)) {
-                       updateLocal(bv, FULL, false);
+                       updateLocal(bv, FULL);
                        return true;
                }
        }
@@ -2720,25 +2649,26 @@ bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length)
 bool InsetTabular::searchForward(BufferView * bv, string const & str,
                                 bool cs, bool mw)
 {
+       int cell = 0;
        if (the_locking_inset) {
                if (the_locking_inset->searchForward(bv, str, cs, mw)) {
-                       updateLocal(bv, CELL, false);
+                       updateLocal(bv, CELL);
                        return true;
                }
                if (tabular->IsLastCell(actcell))
                        return false;
-               ++actcell;
+               cell = actcell + 1;
        }
-       InsetText * inset = tabular->GetCellInset(actcell);
+       InsetText * inset = tabular->GetCellInset(cell);
        if (inset->searchForward(bv, str, cs, mw)) {
-               updateLocal(bv, FULL, false);
+               updateLocal(bv, FULL);
                return true;
        }
-       while (!tabular->IsLastCell(actcell)) {
-               ++actcell;
-               inset = tabular->GetCellInset(actcell);
+       while (!tabular->IsLastCell(cell)) {
+               ++cell;
+               inset = tabular->GetCellInset(cell);
                if (inset->searchForward(bv, str, cs, mw)) {
-                       updateLocal(bv, FULL, false);
+                       updateLocal(bv, FULL);
                        return true;
                }
        }
@@ -2749,20 +2679,20 @@ bool InsetTabular::searchForward(BufferView * bv, string const & str,
 bool InsetTabular::searchBackward(BufferView * bv, string const & str,
                               bool cs, bool mw)
 {
+       int cell = tabular->GetNumberOfCells();
        if (the_locking_inset) {
                if (the_locking_inset->searchBackward(bv, str, cs, mw)) {
-                       updateLocal(bv, CELL, false);
+                       updateLocal(bv, CELL);
                        return true;
                }
+               cell = actcell;
        }
-       if (!locked)
-               actcell = tabular->GetNumberOfCells();
 
-       while (actcell) {
-               --actcell;
-               InsetText * inset = tabular->GetCellInset(actcell);
+       while (cell) {
+               --cell;
+               InsetText * inset = tabular->GetCellInset(cell);
                if (inset->searchBackward(bv, str, cs, mw)) {
-                       updateLocal(bv, CELL, false);
+                       updateLocal(bv, CELL);
                        return true;
                }
        }
@@ -2859,8 +2789,8 @@ 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->paragraph(), 0);
-                               ti->setText(buf.substr(op, p-op), font);
+                                       getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
+                               ti->setText(buf.substr(op, p - op), font);
                                ++cols;
                                ++cell;
                        }
@@ -2870,8 +2800,8 @@ 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->paragraph(), 0);
-                               ti->setText(buf.substr(op, p-op), font);
+                                       getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
+                               ti->setText(buf.substr(op, p - op), font);
                        }
                        cols = ocol;
                        ++row;
@@ -2886,8 +2816,8 @@ 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->paragraph(), 0);
-               ti->setText(buf.substr(op, len-op), font);
+                       getFont(bv->buffer(), &*ti->paragraphs.begin(), 0);
+               ti->setText(buf.substr(op, len - op), font);
        }
 
        return true;
@@ -2921,10 +2851,14 @@ 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);
 
+#warning CHECK verify that this is a sane value to return.
+       if (in.empty())
+               return -1;
+
        if (lex.isOK()) {
                lex.next();
                string const token = lex.getString();
@@ -2965,8 +2899,7 @@ int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
 }
 
 
-string const
-InsetTabularMailer::params2string(InsetTabular const & inset)
+string const InsetTabularMailer::params2string(InsetTabular const & inset)
 {
        BufferView * const bv = inset.view();
        Buffer const * const buffer = bv ? bv->buffer() : 0;
@@ -2977,6 +2910,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());
 }