]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettabular.C
std:: changes, stupid stuff
[lyx.git] / src / insets / insettabular.C
index f00f825910de8f8fb64083c21020304bd8c168f0..83b8483d498d519308ce0bb2d279c8b4609ced99 100644 (file)
@@ -47,14 +47,15 @@ using lyx::support::ltrim;
 using lyx::support::strToInt;
 using lyx::support::strToDbl;
 
+using std::auto_ptr;
 using std::endl;
 using std::max;
-using std::swap;
 using std::string;
-using std::auto_ptr;
 using std::istringstream;
 using std::ostream;
 using std::ostringstream;
+using std::swap;
+using std::vector;
 
 
 namespace {
@@ -375,174 +376,166 @@ string const InsetTabular::editMessage() const
 }
 
 
-void InsetTabular::updateLocal(BufferView * bv) const
+void InsetTabular::updateLocal(LCursor & cur) const
 {
-       bv->update();
-       resetPos(bv);
+       cur.bv().update();
+       resetPos(cur);
 }
 
-extern LCursor theTempCursor;
 
+extern CursorBase theTempCursor;
 
 
-void InsetTabular::lfunMousePress(FuncRequest const & cmd)
+void InsetTabular::lfunMousePress(LCursor & cur, FuncRequest const & cmd)
 {
        if (hasSelection() && cmd.button() == mouse_button::button3)
                return;
 
-       BufferView * bv = cmd.view();
-
        int cell = getCell(cmd.x + xo_, cmd.y + yo_);
        clearSelection();
 
        lyxerr << "# InsetTabular::lfunMousePress cell: " << cell << endl;
        if (cell == -1) {
                tablemode = true;
-               bv->fullCursor(theTempCursor);
-               bv->fullCursor().push(this);
-               bv->fullCursor().cell(cell);
+               cur.cursor_ = theTempCursor;
+               cur.push(this);
+               cur.idx() = cell;
        } else {
                tablemode = false;
-               setPos(bv, cmd.x, cmd.y);
-               bv->fullCursor(theTempCursor);
-               bv->fullCursor().cell(cell);
+               setPos(cur.bv(), cmd.x, cmd.y);
+               cur.cursor_ = theTempCursor;
+               cur.idx() = cell;
        }
-       lyxerr << bv->cursor() << endl;
+       cur.resetAnchor();
+       lyxerr << cur << endl;
 
        if (cmd.button() == mouse_button::button2)
-               dispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
+               dispatch(cur, FuncRequest(LFUN_PASTESELECTION, "paragraph"));
 }
 
 
-void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
+void InsetTabular::lfunMouseMotion(LCursor & cur, FuncRequest const & cmd)
 {
-       BufferView * bv = cmd.view();
        int const actcell = getCell(cmd.x + xo_, cmd.y + yo_);
        lyxerr << "# InsetTabular::lfunMouseMotion cell: " << actcell << endl;
 
-       setPos(bv, cmd.x, cmd.y);
+       setPos(cur.bv(), cmd.x, cmd.y);
        if (!hasSelection()) {
                setSelection(actcell, actcell);
-               bv->setSelection();
+               cur.setSelection();
        } else {
-               bv->cursor().cell(actcell);
+               cur.idx() = actcell;
                setSelection(sel_cell_start, actcell);
                tablemode = (sel_cell_start != actcell);
        }
 }
 
 
-void InsetTabular::lfunMouseRelease(FuncRequest const & cmd)
+void InsetTabular::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
 {
        int const actcell = getCell(cmd.x + xo_, cmd.y + yo_);
        lyxerr << "# InsetTabular::lfunMouseRelease cell: " << actcell << endl;
        if (cmd.button() == mouse_button::button3)
-               InsetTabularMailer(*this).showDialog(cmd.view());
+               InsetTabularMailer(*this).showDialog(&cur.bv());
 }
 
 
-void InsetTabular::edit(BufferView * bv, bool left)
+void InsetTabular::edit(LCursor & cur, bool left)
 {
        lyxerr << "InsetTabular::edit: " << this << endl;
        finishUndo();
        //tablemode = false;
        int cell;
        if (left) {
-               if (isRightToLeft(bv))
+               if (isRightToLeft(cur))
                        cell = tabular.getLastCellInRow(0);
                else
                        cell = 0;
        } else {
-               if (isRightToLeft(bv))
+               if (isRightToLeft(cur))
                        cell = tabular.getFirstCellInRow(tabular.rows()-1);
                else
                        cell = tabular.getNumberOfCells() - 1;
        }
        clearSelection();
-       resetPos(bv);
-       bv->fitCursor();
-       bv->fullCursor().push(this);
-       bv->fullCursor().cell(cell);
-       lyxerr << bv->cursor() << endl;
+       resetPos(cur);
+       cur.bv().fitCursor();
+       cur.push(this);
+       cur.idx() = cell;
 }
 
 
-void InsetTabular::edit(BufferView * bv, int x, int y)
+void InsetTabular::edit(LCursor & cur, int x, int y)
 {
        lyxerr << "InsetTabular::edit: " << this << " first cell "
                << &tabular.cell_info[0][0].inset << endl;
 
        finishUndo();
-       setPos(bv, x, y);
+       setPos(cur.bv(), x, y);
        clearSelection();
        finishUndo();
        //int xx = cursorx_ - xo_ + tabular.getBeginningOfTextInCell(actcell);
-       bv->fullCursor().push(this);
+       cur.push(this);
        //if (x > xx)
        //      activateCellInset(bv, cell, x - xx, y - cursory_);
 }
 
 
 DispatchResult
-InsetTabular::priv_dispatch(FuncRequest const & cmd,
-       idx_type & idx, pos_type & pos)
+InsetTabular::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        lyxerr << "# InsetTabular::dispatch: " << cmd
                << " tablemode: " << tablemode << endl;
 
        DispatchResult result(true, true);
-       BufferView * bv = cmd.view();
-
        switch (cmd.action) {
 
        case LFUN_MOUSE_PRESS:
-               lfunMousePress(cmd);
+               lfunMousePress(cur, cmd);
                return DispatchResult(true, true);
 
        case LFUN_MOUSE_MOTION:
-               lfunMouseMotion(cmd);
+               lfunMouseMotion(cur, cmd);
                return DispatchResult(true, true);
 
        case LFUN_MOUSE_RELEASE:
-               lfunMouseRelease(cmd);
+               lfunMouseRelease(cur, cmd);
                return DispatchResult(true, true);
 
        default:
                break;
        }
 
-       CursorSlice & cur = bv->cursor();
-
        if (!tablemode) {
-               
-               int cell = cur.idx_;
+
+               int cell = cur.idx();
                lyxerr << "# InsetTabular::dispatch: A " << cur << endl;
-               result = tabular.getCellInset(cell).dispatch(cmd, idx, pos);
+               result = tabular.getCellInset(cell).dispatch(cur, cmd);
 
                switch (result.val()) {
                case FINISHED:
-                       if (movePrevCell(bv, cur))
+                       if (movePrevCell(cur))
                                result = DispatchResult(true, true);
                        else
                                result = DispatchResult(false, FINISHED);
                        break;
 
                case FINISHED_RIGHT:
-                       if (moveNextCell(bv, cur))
+                       if (moveNextCell(cur))
                                result = DispatchResult(true, true);
                        else
                                result = DispatchResult(false, FINISHED_RIGHT);
                        break;
 
                case FINISHED_UP:
-                       if (moveUpLock(bv, cur))
+                       if (moveUpLock(cur))
                                result = DispatchResult(true, true);
                        else
                                result = DispatchResult(false, FINISHED_UP);
                        break;
 
                case FINISHED_DOWN:
-                       if (moveDownLock(bv, cur))
+                       if (moveDownLock(cur))
                                result = DispatchResult(true, true);
                        else
                                result = DispatchResult(false, FINISHED_UP);
@@ -562,79 +555,80 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd,
                case LFUN_CELL_BACKWARD:
                case LFUN_CELL_FORWARD:
                        if (cmd.action == LFUN_CELL_FORWARD)
-                               moveNextCell(bv, cur);
+                               moveNextCell(cur);
                        else
-                               movePrevCell(bv, cur);
+                               movePrevCell(cur);
                        clearSelection();
                        return result;
 
                case LFUN_SCROLL_INSET:
                        if (!cmd.argument.empty()) {
                                if (cmd.argument.find('.') != cmd.argument.npos)
-                                       scroll(cmd.view(), static_cast<float>(strToDbl(cmd.argument)));
+                                       scroll(cur.bv(), static_cast<float>(strToDbl(cmd.argument)));
                                else
-                                       scroll(cmd.view(), strToInt(cmd.argument));
-                               cmd.view()->update();
+                                       scroll(cur.bv(), strToInt(cmd.argument));
+                               cur.bv().update();
                                return DispatchResult(true, true);
                        }
 
                case LFUN_RIGHTSEL: {
-                       int const start = hasSelection() ? sel_cell_start : cur.idx_;
-                       if (tabular.isLastCellInRow(cur.idx_)) {
-                               setSelection(start, cur.idx_);
+                       int const start = hasSelection() ? sel_cell_start : cur.idx();
+                       if (tabular.isLastCellInRow(cur.idx())) {
+                               setSelection(start, cur.idx());
                                break;
                        }
 
-                       int end = cur.idx_;
+                       int end = cur.idx();
                        // if we are starting a selection, only select
                        // the current cell at the beginning
                        if (hasSelection()) {
-                               moveRight(bv, cur);
-                               end = cur.idx_;
+                               moveRight(cur);
+                               end = cur.idx();
                        }
                        setSelection(start, end);
                        break;
                }
 
                case LFUN_RIGHT:
-                       if (!moveRightLock(bv, cur))
+                       if (!moveRightLock(cur))
                                result = DispatchResult(false, FINISHED_RIGHT);
                        clearSelection();
                        break;
 
                case LFUN_LEFTSEL: {
-                       int const start = hasSelection() ? sel_cell_start : cur.idx_;
-                       if (tabular.isFirstCellInRow(cur.idx_)) {
-                               setSelection(start, cur.idx_);
+                       int const start = hasSelection() ? sel_cell_start : cur.idx();
+                       if (tabular.isFirstCellInRow(cur.idx())) {
+                               setSelection(start, cur.idx());
                                break;
                        }
 
-                       int end = cur.idx_;
+                       int end = cur.idx();
                        // if we are starting a selection, only select
                        // the current cell at the beginning
                        if (hasSelection()) {
-                               moveLeft(bv, cur);
-                               end = cur.idx_;
+                               moveLeft(cur);
+                               end = cur.idx();
                        }
                        setSelection(start, end);
                        break;
                }
 
                case LFUN_LEFT:
-                       if (!moveLeftLock(bv, cur))
+                       if (!moveLeftLock(cur))
                                result = DispatchResult(false, FINISHED);
                        clearSelection();
                        break;
 
                case LFUN_DOWNSEL: {
-                       int const start = hasSelection() ? sel_cell_start : cur.idx_;
-                       int const ocell = cur.idx_;
+                       int const start = hasSelection() ? sel_cell_start : cur.idx();
+                       int const ocell = cur.idx();
                        // if we are starting a selection, only select
                        // the current cell at the beginning
                        if (hasSelection()) {
-                               moveDown(bv, cur);
+                               moveDown(cur);
                                if (ocell == sel_cell_end ||
-                                               tabular.column_of_cell(ocell) > tabular.column_of_cell(cur.idx_))
+                                               tabular.column_of_cell(ocell) >
+tabular.column_of_cell(cur.idx()))
                                        setSelection(start, tabular.getCellBelow(sel_cell_end));
                                else
                                        setSelection(start, tabular.getLastCellBelow(sel_cell_end));
@@ -645,20 +639,21 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd,
                }
 
                case LFUN_DOWN:
-                       if (!moveDown(bv, cur))
+                       if (!moveDown(cur))
                                result = DispatchResult(false, FINISHED_DOWN);
                        clearSelection();
                        break;
 
                case LFUN_UPSEL: {
-                       int const start = hasSelection() ? sel_cell_start : cur.idx_;
-                       int const ocell = cur.idx_;
+                       int const start = hasSelection() ? sel_cell_start : cur.idx();
+                       int const ocell = cur.idx();
                        // if we are starting a selection, only select
                        // the current cell at the beginning
                        if (hasSelection()) {
-                               moveUp(bv, cur);
+                               moveUp(cur);
                                if (ocell == sel_cell_end ||
-                                               tabular.column_of_cell(ocell) > tabular.column_of_cell(cur.idx_))
+                                               tabular.column_of_cell(ocell) >
+tabular.column_of_cell(cur.idx()))
                                        setSelection(start, tabular.getCellAbove(sel_cell_end));
                                else
                                        setSelection(start, tabular.getLastCellAbove(sel_cell_end));
@@ -669,7 +664,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd,
                }
 
                case LFUN_UP:
-                       if (!moveUp(bv, cur))
+                       if (!moveUp(cur))
                                result = DispatchResult(false, FINISHED_DOWN);
                        clearSelection();
                        break;
@@ -677,37 +672,37 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd,
                case LFUN_NEXT: {
                        if (hasSelection())
                                clearSelection();
-                       int actcell = bv->cursor().idx();
+                       int actcell = cur.idx();
                        int actcol = tabular.column_of_cell(actcell);
                        int column = actcol;
-                       if (bv->top_y() + bv->painter().paperHeight()
+                       if (cur.bv().top_y() + cur.bv().painter().paperHeight()
                                        < yo_ + tabular.getHeightOfTabular())
                        {
-                               bv->scrollDocView(bv->top_y() + bv->painter().paperHeight());
-                               cur.idx_ = tabular.getCellBelow(first_visible_cell) + column;
+                               cur.bv().scrollDocView(
+                                       cur.bv().top_y() + cur.bv().painter().paperHeight());
+                               cur.idx() = tabular.getCellBelow(first_visible_cell) + column;
                        } else {
-                               cur.idx_ = tabular.getFirstCellInRow(tabular.rows() - 1) + column;
+                               cur.idx() = tabular.getFirstCellInRow(tabular.rows() - 1) + column;
                        }
-                       resetPos(bv);
+                       resetPos(cur);
                        break;
                }
 
                case LFUN_PRIOR: {
                        if (hasSelection())
                                clearSelection();
-                       int actcell = bv->cursor().idx();
-                       int actcol = tabular.column_of_cell(actcell);
-                       int column = actcol;
+                       int column = tabular.column_of_cell(cur.idx());
                        if (yo_ < 0) {
-                               bv->scrollDocView(bv->top_y() - bv->painter().paperHeight());
+                               cur.bv().scrollDocView(
+                                       cur.bv().top_y() - cur.bv().painter().paperHeight());
                                if (yo_ > 0)
-                                       cur.idx_ = column;
+                                       cur.idx() = column;
                                else
-                                       cur.idx_ = tabular.getCellBelow(first_visible_cell) + column;
+                                       cur.idx() = tabular.getCellBelow(first_visible_cell) + column;
                        } else {
-                               cur.idx_ = column;
+                               cur.idx() = column;
                        }
-                       resetPos(bv);
+                       resetPos(cur);
                        break;
                }
 
@@ -737,23 +732,23 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd,
                        break;
 
                case LFUN_LAYOUT_TABULAR:
-                       InsetTabularMailer(*this).showDialog(bv);
+                       InsetTabularMailer(*this).showDialog(&cur.bv());
                        break;
 
                case LFUN_INSET_DIALOG_UPDATE:
-                       InsetTabularMailer(*this).updateDialog(bv);
+                       InsetTabularMailer(*this).updateDialog(&cur.bv());
                        break;
 
                case LFUN_TABULAR_FEATURE:
-                       if (!tabularFeatures(bv, cmd.argument))
+                       if (!tabularFeatures(cur, cmd.argument))
                                result = DispatchResult(false);
                        break;
 
                // insert file functions
                case LFUN_FILE_INSERT_ASCII_PARA:
                case LFUN_FILE_INSERT_ASCII: {
-                       string tmpstr = getContentsOfAsciiFile(bv, cmd.argument, false);
-                       if (!tmpstr.empty() && !insertAsciiString(bv, tmpstr, false))
+                       string tmpstr = getContentsOfAsciiFile(&cur.bv(), cmd.argument, false);
+                       if (!tmpstr.empty() && !insertAsciiString(cur.bv(), tmpstr, false))
                                result = DispatchResult(false);
                        break;
                }
@@ -772,26 +767,26 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd,
                        break;
 
                case LFUN_CUT:
-                       if (copySelection(bv)) {
-                               recordUndo(bv, Undo::DELETE);
-                               cutSelection(bv->buffer()->params());
+                       if (copySelection(cur.bv())) {
+                               recordUndo(cur, Undo::DELETE);
+                               cutSelection(cur.bv().buffer()->params());
                        }
                        break;
 
                case LFUN_DELETE:
-                       recordUndo(bv, Undo::DELETE);
-                       cutSelection(bv->buffer()->params());
+                       recordUndo(cur, Undo::DELETE);
+                       cutSelection(cur.bv().buffer()->params());
                        break;
 
                case LFUN_COPY:
                        if (!hasSelection())
                                break;
                        finishUndo();
-                       copySelection(bv);
+                       copySelection(cur.bv());
                        break;
 
                case LFUN_PASTESELECTION: {
-                       string const clip = bv->getClipboard();
+                       string const clip = cur.bv().getClipboard();
                        if (clip.empty())
                                break;
                        if (clip.find('\t') != string::npos) {
@@ -819,7 +814,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd,
                                maxCols = max(cols, maxCols);
 
                                paste_tabular.reset(
-                                       new LyXTabular(bv->buffer()->params(), rows, maxCols));
+                                       new LyXTabular(cur.bv().buffer()->params(), rows, maxCols));
 
                                string::size_type op = 0;
                                int cell = 0;
@@ -853,7 +848,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd,
                                if (cell < cells && op < len)
                                        paste_tabular->getCellInset(cell).
                                                setText(clip.substr(op, len-op), font);
-                       } else if (!insertAsciiString(bv, clip, true))
+                       } else if (!insertAsciiString(cur.bv(), clip, true))
                        {
                                // so that the clipboard is used and it goes on
                                // to default
@@ -865,8 +860,8 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd,
 
                case LFUN_PASTE:
                        if (hasPasteBuffer()) {
-                               recordUndo(bv, Undo::INSERT);
-                               pasteSelection(bv);
+                               recordUndo(cur, Undo::INSERT);
+                               pasteSelection(cur.bv());
                                break;
                        }
                        // fall through
@@ -882,8 +877,8 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd,
                        break;
                }
 
-               updateLocal(bv);
-               InsetTabularMailer(*this).updateDialog(bv);
+               updateLocal(cur);
+               InsetTabularMailer(*this).updateDialog(&cur.bv());
        }
 
        if (cmd.action == LFUN_INSET_TOGGLE) {
@@ -985,7 +980,7 @@ void InsetTabular::getCursorPos(int cell, int & x, int & y) const
 }
 
 
-void InsetTabular::setPos(BufferView * bv, int x, int y) const
+void InsetTabular::setPos(BufferView & bv, int x, int y) const
 {
        int const cell = getCell(x + xo_, y + yo_);
        lyxerr << "# InsetTabular::setPos()  cell: " << cell << endl;
@@ -1018,7 +1013,7 @@ void InsetTabular::setPos(BufferView * bv, int x, int y) const
 
        cursorx_ = lx - tabular.getWidthOfColumn(actcell) + xo_ + 2;
 #endif
-       resetPos(bv);
+       resetPos(bv.cursor());
 }
 
 
@@ -1036,7 +1031,7 @@ int InsetTabular::getCellXPos(int cell) const
 }
 
 
-void InsetTabular::resetPos(BufferView *) const
+void InsetTabular::resetPos(LCursor &) const
 {
 #if 0
 #ifdef WITH_WARNINGS
@@ -1046,8 +1041,9 @@ void InsetTabular::resetPos(BufferView *) const
        if (in_reset_pos > 0)
                return;
 
+       BufferView & bv = cur.bv();
        int cell = 0;
-       int actcell = bv->cursor().cell();
+       int actcell = cur.cell();
        int actcol = tabular.column_of_cell(actcell);
        int actrow = 0;
        cursory_ = 0;
@@ -1071,19 +1067,19 @@ void InsetTabular::resetPos(BufferView *) const
                tabular.getWidthOfTabular() < bv->workWidth()-20)
        {
                scroll(bv, 0.0F);
-               updateLocal(bv);
+               updateLocal(cur);
        } else if (cursorx_ - offset > 20 &&
                   cursorx_ - offset + tabular.getWidthOfColumn(actcell)
-                  > bv->workWidth() - 20) {
-               scroll(bv, - tabular.getWidthOfColumn(actcell) - 20);
-               updateLocal(bv);
+                  > bv.workWidth() - 20) {
+               scroll(&bv, - tabular.getWidthOfColumn(actcell) - 20);
+               updateLocal(cur);
        } else if (cursorx_ - offset < 20) {
-               scroll(bv, 20 - cursorx_ + offset);
-               updateLocal(bv);
+               scroll(&bv, 20 - cursorx_ + offset);
+               updateLocal(cur);
        } else if (scroll() && xo_ > 20 &&
                   xo_ + tabular.getWidthOfTabular() > bv->workWidth() - 20) {
-               scroll(bv, old_x - cursorx_);
-               updateLocal(bv);
+               scroll(&bv, old_x - cursorx_);
+               updateLocal(cur);
        }
        InsetTabularMailer(*this).updateDialog(bv);
        in_reset_pos = 0;
@@ -1091,147 +1087,143 @@ void InsetTabular::resetPos(BufferView *) const
 }
 
 
-bool InsetTabular::moveRight(BufferView * bv, CursorSlice & cur)
+bool InsetTabular::moveRight(LCursor & cur)
 {
-       bool moved = isRightToLeft(bv)
-               ? movePrevCell(bv, cur) : moveNextCell(bv, cur);
+       bool moved = isRightToLeft(cur) ? movePrevCell(cur) : moveNextCell(cur);
        if (!moved)
                return false;
-       resetPos(bv);
+       resetPos(cur);
        return true;
 }
 
 
-bool InsetTabular::moveRightLock(BufferView * bv, CursorSlice & cur)
+bool InsetTabular::moveRightLock(LCursor & cur)
 {
-       bool moved = isRightToLeft(bv)
-               ? movePrevCell(bv, cur) : moveNextCell(bv, cur);
+       bool moved = isRightToLeft(cur) ? movePrevCell(cur) : moveNextCell(cur);
        if (!moved)
                return false;
-       activateCellInset(bv, cur.idx_, false);
+       activateCellInset(cur, cur.idx(), false);
        return true;
 }
 
 
-bool InsetTabular::moveLeft(BufferView * bv, CursorSlice & cur)
+bool InsetTabular::moveLeft(LCursor & cur)
 {
-       bool moved = isRightToLeft(bv)
-               ? moveNextCell(bv, cur) : movePrevCell(bv, cur);
+       bool moved = isRightToLeft(cur) ? moveNextCell(cur) : movePrevCell(cur);
        if (!moved)
                return false;
-       resetPos(bv);
+       resetPos(cur);
        return true;
 }
 
 
-bool InsetTabular::moveLeftLock(BufferView * bv, CursorSlice & cur)
+bool InsetTabular::moveLeftLock(LCursor & cur)
 {
-       bool moved = isRightToLeft(bv)
-               ? moveNextCell(bv, cur) : movePrevCell(bv, cur);
+       bool moved = isRightToLeft(cur) ? moveNextCell(cur) : movePrevCell(cur);
        if (!moved)
                return false;
-       activateCellInset(bv, cur.idx_, true);
+       activateCellInset(cur, cur.idx(), true);
        return true;
 }
 
 
-bool InsetTabular::moveUp(BufferView * bv, CursorSlice & cur)
+bool InsetTabular::moveUp(LCursor & cur)
 {
-       if (tabular.row_of_cell(cur.idx_) == 0)
+       if (tabular.row_of_cell(cur.idx()) == 0)
                return false;
-       cur.idx_ = tabular.getCellAbove(cur.idx_);
-       resetPos(bv);
+       cur.idx() = tabular.getCellAbove(cur.idx());
+       resetPos(cur);
        return true;
 }
 
 
-bool InsetTabular::moveUpLock(BufferView * bv, CursorSlice & cur)
+bool InsetTabular::moveUpLock(LCursor & cur)
 {
-       if (tabular.row_of_cell(cur.idx_) == 0)
+       if (tabular.row_of_cell(cur.idx()) == 0)
                return false;
-       cur.idx_ = tabular.getCellAbove(cur.idx_);
-       resetPos(bv);
-       activateCellInset(bv, cur.idx_, bv->x_target(), 0);
+       cur.idx() = tabular.getCellAbove(cur.idx());
+       resetPos(cur);
+       activateCellInset(cur, cur.idx(), cur.x_target(), 0);
        return true;
 }
 
 
-bool InsetTabular::moveDown(BufferView * bv, CursorSlice & cur)
+bool InsetTabular::moveDown(LCursor & cur)
 {
-       if (tabular.row_of_cell(cur.idx_) == tabular.rows() - 1)
+       if (tabular.row_of_cell(cur.idx()) == tabular.rows() - 1)
                return false;
-       cur.idx_ = tabular.getCellBelow(cur.idx_);
-       resetPos(bv);
+       cur.idx() = tabular.getCellBelow(cur.idx());
+       resetPos(cur);
        return true;
 }
 
 
-bool InsetTabular::moveDownLock(BufferView * bv, CursorSlice & cur)
+bool InsetTabular::moveDownLock(LCursor & cur)
 {
-       if (tabular.row_of_cell(cur.idx_) == tabular.rows() - 1)
+       if (tabular.row_of_cell(cur.idx()) == tabular.rows() - 1)
                return false;
-       cur.idx_ = tabular.getCellBelow(cur.idx_);
-       resetPos(bv);
-       activateCellInset(bv, cur.idx_, bv->x_target());
+       cur.idx() = tabular.getCellBelow(cur.idx());
+       resetPos(cur);
+       activateCellInset(cur, cur.idx(), cur.x_target());
        return true;
 }
 
 
-bool InsetTabular::moveNextCell(BufferView * bv, CursorSlice & cur)
+bool InsetTabular::moveNextCell(LCursor & cur)
 {
        lyxerr << "InsetTabular::moveNextCell 1 cur: " << cur << endl;
-       if (isRightToLeft(bv)) {
-               if (tabular.isFirstCellInRow(cur.idx_)) {
-                       int row = tabular.row_of_cell(cur.idx_);
+       if (isRightToLeft(cur)) {
+               if (tabular.isFirstCellInRow(cur.idx())) {
+                       int row = tabular.row_of_cell(cur.idx());
                        if (row == tabular.rows() - 1)
                                return false;
-                       cur.idx_ = tabular.getLastCellInRow(row);
-                       cur.idx_ = tabular.getCellBelow(cur.idx_);
+                       cur.idx() = tabular.getLastCellInRow(row);
+                       cur.idx() = tabular.getCellBelow(cur.idx());
                } else {
-                       if (cur.idx_ == 0)
+                       if (cur.idx() == 0)
                                return false;
-                       --cur.idx_;
+                       --cur.idx();
                }
        } else {
-               if (tabular.isLastCell(cur.idx_))
+               if (tabular.isLastCell(cur.idx()))
                        return false;
-               ++cur.idx_;
+               ++cur.idx();
        }
-       cur.par_ = 0;
-       cur.pos_ = 0;
+       cur.par() = 0;
+       cur.pos() = 0;
        lyxerr << "InsetTabular::moveNextCell 2 cur: " << cur << endl;
-       resetPos(bv);
+       resetPos(cur);
        return true;
 }
 
 
-bool InsetTabular::movePrevCell(BufferView * bv, CursorSlice & cur)
+bool InsetTabular::movePrevCell(LCursor & cur)
 {
-       if (isRightToLeft(bv)) {
-               if (tabular.isLastCellInRow(cur.idx_)) {
-                       int row = tabular.row_of_cell(cur.idx_);
+       if (isRightToLeft(cur)) {
+               if (tabular.isLastCellInRow(cur.idx())) {
+                       int row = tabular.row_of_cell(cur.idx());
                        if (row == 0)
                                return false;
-                       cur.idx_ = tabular.getFirstCellInRow(row);
-                       cur.idx_ = tabular.getCellAbove(cur.idx_);
+                       cur.idx() = tabular.getFirstCellInRow(row);
+                       cur.idx() = tabular.getCellAbove(cur.idx());
                } else {
-                       if (tabular.isLastCell(cur.idx_))
+                       if (tabular.isLastCell(cur.idx()))
                                return false;
-                       ++cur.idx_;
+                       ++cur.idx();
                }
        } else {
-               if (cur.idx_ == 0) // first cell
+               if (cur.idx() == 0) // first cell
                        return false;
-               --cur.idx_;
+               --cur.idx();
        }
-       cur.par_ = 0;
-       cur.pos_ = 0;
-       resetPos(bv);
+       cur.par() = 0;
+       cur.pos() = 0;
+       resetPos(cur);
        return true;
 }
 
 
-bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
+bool InsetTabular::tabularFeatures(LCursor & cur, string const & what)
 {
        LyXTabular::Feature action = LyXTabular::LAST_ACTION;
 
@@ -1251,7 +1243,7 @@ bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
 
        string const val =
                ltrim(what.substr(tabularFeature[i].feature.length()));
-       tabularFeatures(bv, action, val);
+       tabularFeatures(cur, action, val);
        return true;
 }
 
@@ -1279,10 +1271,11 @@ void checkLongtableSpecial(LyXTabular::ltType & ltt,
 } // anon namespace
 
 
-void InsetTabular::tabularFeatures(BufferView * bv,
+void InsetTabular::tabularFeatures(LCursor & cur,
        LyXTabular::Feature feature, string const & value)
 {
-       int actcell = bv->cursor().idx();
+       BufferView & bv = cur.bv();
+       int actcell = cur.idx();
        int sel_col_start;
        int sel_col_end;
        int sel_row_start;
@@ -1337,7 +1330,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);
        }
-       recordUndo(bv, Undo::ATOMIC);
+       recordUndo(cur, Undo::ATOMIC);
 
        int row =  tabular.row_of_cell(actcell);
        int column = tabular.column_of_cell(actcell);
@@ -1351,10 +1344,10 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                tabular.setColumnPWidth(actcell, len);
                if (len.zero()
                    && tabular.getAlignment(actcell, true) == LYX_ALIGN_BLOCK)
-                       tabularFeatures(bv, LyXTabular::ALIGN_CENTER, string());
+                       tabularFeatures(cur, LyXTabular::ALIGN_CENTER, string());
                else if (!len.zero()
                         && tabular.getAlignment(actcell, true) != LYX_ALIGN_BLOCK)
-                       tabularFeatures(bv, LyXTabular::ALIGN_BLOCK, string());
+                       tabularFeatures(cur, LyXTabular::ALIGN_BLOCK, string());
                break;
        }
 
@@ -1369,13 +1362,13 @@ void InsetTabular::tabularFeatures(BufferView * bv,
 
        case LyXTabular::APPEND_ROW:
                // append the row into the tabular
-               tabular.appendRow(bv->buffer()->params(), actcell);
+               tabular.appendRow(bv.buffer()->params(), actcell);
                tabular.setOwner(this);
                break;
 
        case LyXTabular::APPEND_COLUMN:
                // append the column into the tabular
-               tabular.appendColumn(bv->buffer()->params(), actcell);
+               tabular.appendColumn(bv.buffer()->params(), actcell);
                tabular.setOwner(this);
                actcell = tabular.getCellNumber(row, column);
                break;
@@ -1494,7 +1487,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                        if (tabular.isMultiColumn(actcell))
                                tabular.unsetMultiColumn(actcell);
                        else
-                               tabular.setMultiColumn(bv->buffer(), actcell, 1);
+                               tabular.setMultiColumn(bv.buffer(), actcell, 1);
                        break;
                }
                // we have a selection so this means we just add all this
@@ -1509,7 +1502,7 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                        s_start = sel_cell_start;
                        s_end = sel_cell_end;
                }
-               tabular.setMultiColumn(bv->buffer(), s_start, s_end - s_start + 1);
+               tabular.setMultiColumn(bv.buffer(), s_start, s_end - s_start + 1);
                actcell = s_start;
                clearSelection();
                break;
@@ -1605,24 +1598,24 @@ void InsetTabular::tabularFeatures(BufferView * bv,
                break;
        }
 
-       updateLocal(bv);
-       InsetTabularMailer(*this).updateDialog(bv);
+       updateLocal(cur);
+       InsetTabularMailer(*this).updateDialog(&bv);
 }
 
 
-void InsetTabular::activateCellInset(BufferView * bv, int cell, int x, int y)
+void InsetTabular::activateCellInset(LCursor & cur, int cell, int x, int y)
 {
-       tabular.getCellInset(cell).edit(bv, x, y);
-       bv->cursor().cell(cell);
-       updateLocal(bv);
+       tabular.getCellInset(cell).edit(cur, x, y);
+       cur.idx() = cell;
+       updateLocal(cur);
 }
 
 
-void InsetTabular::activateCellInset(BufferView * bv, int cell, bool behind)
+void InsetTabular::activateCellInset(LCursor & cur, int cell, bool behind)
 {
-       tabular.getCellInset(cell).edit(bv, behind);
-       bv->cursor().cell(cell);
-       updateLocal(bv);
+       tabular.getCellInset(cell).edit(cur, behind);
+       cur.idx() = cell;
+       updateLocal(cur);
 }
 
 
@@ -1653,7 +1646,7 @@ FuncStatus InsetTabular::getStatus(string const & what, int actcell) const
                string const tmp = tabularFeature[i].feature;
                if (tmp == what.substr(0, tmp.length())) {
                        //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
-                       //   tabularFeatures[i].feature.length())) 
+                       //   tabularFeatures[i].feature.length()))
                        action = tabularFeature[i].action;
                        break;
                }
@@ -1822,13 +1815,13 @@ FuncStatus InsetTabular::getStatus(string const & what, int actcell) const
 
 
 void InsetTabular::getLabelList(Buffer const & buffer,
-                               std::vector<string> & list) const
+                               vector<string> & list) const
 {
        tabular.getLabelList(buffer, list);
 }
 
 
-bool InsetTabular::copySelection(BufferView * bv)
+bool InsetTabular::copySelection(BufferView & bv)
 {
        if (!hasSelection())
                return false;
@@ -1874,18 +1867,18 @@ bool InsetTabular::copySelection(BufferView * bv)
 
        ostringstream os;
        OutputParams const runparams;
-       paste_tabular->plaintext(*bv->buffer(), os, runparams,
-                                ownerPar(*bv->buffer(), this).params().depth(), true, '\t');
-       bv->stuffClipboard(os.str());
+       paste_tabular->plaintext(*bv.buffer(), os, runparams,
+                                ownerPar(*bv.buffer(), this).params().depth(), true, '\t');
+       bv.stuffClipboard(os.str());
        return true;
 }
 
 
-bool InsetTabular::pasteSelection(BufferView * bv)
+bool InsetTabular::pasteSelection(BufferView & bv)
 {
        if (!paste_tabular)
                return false;
-       int actcell = bv->cursor().idx();
+       int actcell = bv.cursor().idx();
        int actcol = tabular.column_of_cell(actcell);
        int actrow = tabular.row_of_cell(actcell);
        for (int r1 = 0, r2 = actrow;
@@ -1946,9 +1939,9 @@ bool InsetTabular::cutSelection(BufferParams const & bp)
 }
 
 
-bool InsetTabular::isRightToLeft(BufferView * bv)
+bool InsetTabular::isRightToLeft(LCursor & cur)
 {
-       return bv->getParentLanguage(this)->RightToLeft();
+       return cur.bv().getParentLanguage(this)->RightToLeft();
 }
 
 
@@ -1993,7 +1986,7 @@ void InsetTabular::markErased()
 }
 
 
-bool InsetTabular::forceDefaultParagraphs(InsetOld const * in) const
+bool InsetTabular::forceDefaultParagraphs(InsetBase const * in) const
 {
        const int cell = tabular.getCellFromInset(in);
 
@@ -2011,7 +2004,7 @@ bool InsetTabular::forceDefaultParagraphs(InsetOld const * in) const
 }
 
 
-bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
+bool InsetTabular::insertAsciiString(BufferView & bv, string const & buf,
                                     bool usePaste)
 {
        if (buf.length() <= 0)
@@ -2023,7 +2016,7 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
        string::size_type len = buf.length();
        string::size_type p = 0;
 
-       int actcell = bv->cursor().idx();
+       int actcell = bv.cursor().idx();
        int actcol = tabular.column_of_cell(actcell);
        int actrow = tabular.row_of_cell(actcell);
 
@@ -2048,9 +2041,7 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf,
        int row = 0;
        if (usePaste) {
                paste_tabular.reset(
-                       new LyXTabular(bv->buffer()->params(), rows, maxCols)
-                       );
-
+                       new LyXTabular(bv.buffer()->params(), rows, maxCols));
                paste_tabular->setOwner(this);
                loctab = paste_tabular.get();
                cols = 0;