]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
ws changes only
[lyx.git] / src / text3.C
index 1b3d0b1875aab8e56bb749a498cb086e7656cca0..35380d1f2740ae243ce0789661b8b57ef5ab83ee 100644 (file)
@@ -1,56 +1,66 @@
-/* This file is part of
- * ======================================================
+/**
+ * \file text3.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author Asger Alstrup
+ * \author Lars Gullik Bjønnes
+ * \author Alfredo Braunstein
+ * \author Angus Leeming
+ * \author John Levon
+ * \author André Pönitz
  *
- *           Copyright 1995 Matthias Ettrich
- *           Copyright 1995-2002 The LyX Team.
- *
- * ====================================================== */
+ * Full author contact details are available in file CREDITS.
+ */
 
 #include <config.h>
 
 #include "lyxtext.h"
-#include "paragraph.h"
+
+#include "buffer.h"
+#include "bufferparams.h"
 #include "BufferView.h"
-#include "funcrequest.h"
-#include "lyxrc.h"
-#include "Lsstream.h"
 #include "debug.h"
-#include "bufferparams.h"
-#include "buffer.h"
-#include "bufferview_funcs.h"
-#include "ParagraphParameters.h"
-#include "gettext.h"
 #include "factory.h"
+#include "funcrequest.h"
+#include "gettext.h"
 #include "intl.h"
-#include "box.h"
 #include "language.h"
-#include "support/tostr.h"
-#include "support/lstrings.h"
-#include "support/LAssert.h"
-#include "frontends/LyXView.h"
-#include "frontends/screen.h"
+#include "lyxrc.h"
+#include "lyxrow.h"
+#include "paragraph.h"
+#include "ParagraphParameters.h"
+#include "text_funcs.h"
+#include "undo_funcs.h"
+#include "vspace.h"
+
 #include "frontends/Dialogs.h"
-#include "insets/insetspecialchar.h"
-#include "insets/insettext.h"
-#include "insets/insetquotes.h"
+#include "frontends/LyXView.h"
+
 #include "insets/insetcommand.h"
 #include "insets/insetnewline.h"
-#include "undo_funcs.h"
-#include "text_funcs.h"
-#include "Lsstream.h"
+#include "insets/insetspecialchar.h"
+#include "insets/insettext.h"
+
+#include "support/lstrings.h"
+#include "support/tostr.h"
 
-#include <ctime>
+#include "support/std_sstream.h"
 #include <clocale>
 
-using namespace lyx::support;
-using namespace bv_funcs;
+using bv_funcs::replaceSelection;
+
+using lyx::pos_type;
+
+using lyx::support::isStrUnsignedInt;
+using lyx::support::strToUnsignedInt;
 
 using std::endl;
 using std::find;
+using std::string;
+using std::istringstream;
 using std::vector;
-using lyx::pos_type;
+
 
 extern string current_layout;
 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
@@ -90,11 +100,11 @@ namespace {
        // check if the given co-ordinates are inside an inset at the
        // given cursor, if one exists. If so, the inset is returned,
        // and the co-ordinates are made relative. Otherwise, 0 is returned.
-       InsetOld * checkInset(BufferView * /*bv*/, LyXText & text,
+       InsetOld * checkInset(LyXText & text,
                LyXCursor const & cur, int & x, int & y)
        {
                lyx::pos_type const pos = cur.pos();
-               ParagraphList::iterator par = cur.par();
+               ParagraphList::iterator par = text.getPar(cur);
 
                if (pos >= par->size() || !par->isInset(pos))
                        return 0;
@@ -105,33 +115,33 @@ namespace {
                        return 0;
 
                // get inset dimensions
-               Assert(par->getInset(pos));
+               BOOST_ASSERT(par->getInset(pos));
 
                LyXFont const & font = text.getFont(par, pos);
 
                int const width = inset->width();
                int const inset_x = font.isVisibleRightToLeft()
-                       ? (cur.ix() - width) : cur.ix();
+                       ? (cur.x() - width) : cur.x();
 
                Box b(
                        inset_x + inset->scroll(),
                        inset_x + width,
-                       cur.iy() - inset->ascent(),
-                       cur.iy() + inset->descent()
+                       cur.y() - inset->ascent(),
+                       cur.y() + inset->descent()
                );
 
-               if (!b.contained(x, y)) {
+               if (!b.contains(x, y)) {
                        lyxerr[Debug::GUI] << "Missed inset at x,y "
                                           << x << ',' << y
                                           << " box " << b << endl;
                        return 0;
                }
 
-               text.setCursor(par, pos, true);
+               text.setCursor(cur.par(), pos, true);
 
                x -= b.x1;
                // The origin of an inset is on the baseline
-               y -= text.cursor.iy();
+               y -= text.cursor.y();
 
                return inset;
        }
@@ -141,12 +151,12 @@ namespace {
 
 InsetOld * LyXText::checkInsetHit(int & x, int & y)
 {
-       int y_tmp = y + top_y();
+       int y_tmp = y + bv_owner->top_y();
 
        LyXCursor cur;
        setCursorFromCoordinates(cur, x, y_tmp);
 
-       InsetOld * inset = checkInset(bv(), *this, cur, x, y_tmp);
+       InsetOld * inset = checkInset(*this, cur, x, y_tmp);
        if (inset) {
                y = y_tmp;
                return inset;
@@ -159,7 +169,7 @@ InsetOld * LyXText::checkInsetHit(int & x, int & y)
        // move back one
        setCursor(cur, cur.par(), cur.pos() - 1, true);
 
-       inset = checkInset(bv(), *this, cur, x, y_tmp);
+       inset = checkInset(*this, cur, x, y_tmp);
        if (inset)
                y = y_tmp;
        return inset;
@@ -170,7 +180,7 @@ bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
                            string const & contents)
 {
        ParagraphList::iterator end = ownerParagraphs().end();
-       ParagraphList::iterator pit = cursor.par();
+       ParagraphList::iterator pit = cursorPar();
        pos_type pos = cursor.pos();
 
        InsetOld * inset;
@@ -190,11 +200,11 @@ bool LyXText::gotoNextInset(vector<InsetOld::Code> const & codes,
                    static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
                    == contents)));
 
-       if (pit != end) {
-               setCursor(pit, pos, false);
-               return true;
-       }
-       return false;
+       if (pit == end)
+               return false;
+
+       setCursor(parOffset(pit), pos, false);
+       return true;
 }
 
 
@@ -204,18 +214,18 @@ void LyXText::gotoInset(vector<InsetOld::Code> const & codes,
        bv()->beforeChange(this);
 
        string contents;
-       if (same_content && cursor.pos() < cursor.par()->size()
-           && cursor.par()->isInset(cursor.pos())) {
-               InsetOld const * inset = cursor.par()->getInset(cursor.pos());
+       if (same_content && cursor.pos() < cursorPar()->size()
+           && cursorPar()->isInset(cursor.pos())) {
+               InsetOld const * inset = cursorPar()->getInset(cursor.pos());
                if (find(codes.begin(), codes.end(), inset->lyxCode())
                    != codes.end())
                        contents = static_cast<InsetCommand const *>(inset)->getContents();
        }
 
        if (!gotoNextInset(codes, contents)) {
-               if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
+               if (cursor.pos() || cursorPar() != ownerParagraphs().begin()) {
                        LyXCursor tmp = cursor;
-                       cursor.par(ownerParagraphs().begin());
+                       cursor.par(0);
                        cursor.pos(0);
                        if (!gotoNextInset(codes, contents)) {
                                cursor = tmp;
@@ -238,7 +248,7 @@ void LyXText::gotoInset(InsetOld::Code code, bool same_content)
 
 void LyXText::cursorPrevious()
 {
-       int y = top_y();
+       int y = bv_owner->top_y();
 
        RowList::iterator rit = cursorRow();
 
@@ -261,7 +271,7 @@ void LyXText::cursorPrevious()
                // tall rows, but it's not working right now.
        } else {
                if (inset_owner) {
-                       new_y = bv()->text->cursor.iy()
+                       new_y = bv()->text->cursor.y()
                                + bv()->theLockingInset()->insetInInsetY() + y
                                + rit->height()
                                - bv()->workHeight() + 1;
@@ -274,10 +284,10 @@ void LyXText::cursorPrevious()
        }
 
        LyXCursor cur;
-       ParagraphList::iterator pit = cursor.par();
+       ParagraphList::iterator pit = cursorPar();
        previousRow(pit, rit);
-       setCursor(cur, pit, rit->pos(), false);
-       if (cur.y() > top_y())
+       setCursor(cur, parOffset(pit), rit->pos(), false);
+       if (cur.y() > bv_owner->top_y())
                cursorUp(true);
        bv()->updateScrollbar();
 }
@@ -285,32 +295,32 @@ void LyXText::cursorPrevious()
 
 void LyXText::cursorNext()
 {
-       int topy = top_y();
+       int topy = bv_owner->top_y();
 
        RowList::iterator rit = cursorRow();
        if (rit == lastRow()) {
                int y = cursor.y() - rit->baseline() + cursorRow()->height();
                if (y > topy + bv()->workHeight())
-                       bv()->updateScrollbar();
+                       bv_owner->updateScrollbar();
                return;
        }
 
-       int y = topy + bv()->workHeight();
+       int y = topy + bv_owner->workHeight();
        if (inset_owner && !topy) {
-               y -= (bv()->text->cursor.iy()
-                         - bv()->text->top_y()
-                         + bv()->theLockingInset()->insetInInsetY());
+               y -= (bv_owner->text->cursor.y()
+                         - bv_owner->top_y()
+                         + bv_owner->theLockingInset()->insetInInsetY());
        }
 
        ParagraphList::iterator dummypit;
-       getRowNearY(y, dummypit);
+       y = getRowNearY(y, dummypit)->y();
 
        setCursorFromCoordinates(cursor.x_fix(), y);
        // + bv->workHeight());
        finishUndo();
 
        int new_y;
-       if (rit == bv()->text->cursorRow()) {
+       if (rit == bv_owner->text->cursorRow()) {
                // we have a row which is taller than the workarea. The
                // simplest solution is to move to the next row instead.
                cursorDown(true);
@@ -318,11 +328,11 @@ void LyXText::cursorNext()
                // This is what we used to do, so we wouldn't skip right past
                // tall rows, but it's not working right now.
 #if 0
-               new_y = bv->text->top_y() + bv->workHeight();
+               new_y = bv->top_y() + bv->workHeight();
 #endif
        } else {
                if (inset_owner) {
-                       new_y = bv()->text->cursor.iy()
+                       new_y = bv()->text->cursor.y()
                                + bv()->theLockingInset()->insetInInsetY()
                                + y - rit->baseline();
                } else {
@@ -330,11 +340,11 @@ void LyXText::cursorNext()
                }
        }
 
-       ParagraphList::iterator pit = cursor.par();
-       nextRow(pit, rit);      
+       ParagraphList::iterator pit = cursorPar();
+       nextRow(pit, rit);
        LyXCursor cur;
-       setCursor(cur, pit, rit->pos(), false);
-       if (cur.y() < top_y() + bv()->workHeight())
+       setCursor(cur, parOffset(pit), rit->pos(), false);
+       if (cur.y() < bv_owner->top_y() + bv()->workHeight())
                cursorDown(true);
        bv()->updateScrollbar();
 }
@@ -350,7 +360,7 @@ void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
        if (!bv->insertInset(new_inset))
                delete new_inset;
        else
-               bv->updateInset();
+               bv->updateInset(new_inset);
 }
 
 
@@ -379,19 +389,21 @@ void doInsertInset(LyXText * lt, FuncRequest const & cmd,
        }
 }
 
-}
+} // anon namespace
 
-InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
+
+dispatch_result LyXText::dispatch(FuncRequest const & cmd)
 {
-       lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << cmd.action
-                             <<"] arg[" << cmd.argument << ']' << endl;
+       lyxerr[Debug::ACTION] << "LyXText::dispatch: action[" << cmd.action
+                             <<"] arg[" << cmd.argument << ']' << "xy[" <<
+                                 cmd.x << ',' << cmd.y << ']' << endl;
 
        BufferView * bv = cmd.view();
 
        switch (cmd.action) {
 
        case LFUN_APPENDIX: {
-               ParagraphList::iterator pit = cursor.par();
+               ParagraphList::iterator pit = cursorPar();
                bool start = !pit->params().startOfAppendix();
 
                // ensure that we have only one start_of_appendix in this document
@@ -402,7 +414,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        if (tmp->params().startOfAppendix()) {
                                recordUndo(bv, Undo::ATOMIC, tmp);
                                tmp->params().startOfAppendix(false);
-                               setHeightOfRow(tmp, getRow(tmp, 0));
+                               redoParagraph(tmp);
                                break;
                        }
                }
@@ -412,8 +424,8 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
                // we can set the refreshing parameters now
                updateCounters();
-               redoParagraph(cursor.par());
-               setCursor(cursor.par(), cursor.pos());
+               redoParagraph(cursorPar());
+               setCursor(cursorPar(), cursor.pos());
                bv->update();
                break;
        }
@@ -439,7 +451,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_WORDRIGHT:
                if (!selection.mark())
                        bv->beforeChange(this);
-               if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
+               if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
                        cursorLeftOneWord();
                else
                        cursorRightOneWord();
@@ -449,7 +461,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_WORDLEFT:
                if (!selection.mark())
                        bv->beforeChange(this);
-               if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
+               if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
                        cursorRightOneWord();
                else
                        cursorLeftOneWord();
@@ -473,7 +485,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_RIGHTSEL:
                if (!selection.set())
                        selection.cursor = cursor;
-               if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
+               if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
                        cursorLeft(bv);
                else
                        cursorRight(bv);
@@ -483,7 +495,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_LEFTSEL:
                if (!selection.set())
                        selection.cursor = cursor;
-               if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
+               if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
                        cursorRight(bv);
                else
                        cursorLeft(bv);
@@ -547,7 +559,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_WORDRIGHTSEL:
-               if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
+               if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
                        cursorLeftOneWord();
                else
                        cursorRightOneWord();
@@ -555,7 +567,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_WORDLEFTSEL:
-               if (cursor.par()->isRightToLeftPar(bv->buffer()->params))
+               if (cursorPar()->isRightToLeftPar(bv->buffer()->params()))
                        cursorRightOneWord();
                else
                        cursorLeftOneWord();
@@ -565,7 +577,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_WORDSEL: {
                LyXCursor cur1 = cursor;
                LyXCursor cur2;
-               ::getWord(cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
+               ::getWord(*this, cur1, cur2, lyx::WHOLE_WORD, ownerParagraphs());
                setCursor(cur1.par(), cur1.pos());
                bv->beforeChange(this);
                setCursor(cur2.par(), cur2.pos());
@@ -574,15 +586,15 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        }
 
        case LFUN_RIGHT: {
-               bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
+               bool is_rtl = cursorPar()->isRightToLeftPar(bv->buffer()->params());
                if (!selection.mark())
                        bv->beforeChange(this);
                if (is_rtl)
                        cursorLeft(false);
-               if (cursor.pos() < cursor.par()->size()
-                   && cursor.par()->isInset(cursor.pos())
-                   && isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
-                       InsetOld * tmpinset = cursor.par()->getInset(cursor.pos());
+               if (cursor.pos() < cursorPar()->size()
+                   && cursorPar()->isInset(cursor.pos())
+                   && isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
+                       InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
                        cmd.message(tmpinset->editMessage());
                        FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "right" : "left");
                        tmpinset->localDispatch(cmd1);
@@ -597,17 +609,17 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_LEFT: {
                // This is soooo ugly. Isn`t it possible to make
                // it simpler? (Lgb)
-               bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
+               bool const is_rtl = cursorPar()->isRightToLeftPar(bv->buffer()->params());
                if (!selection.mark())
                        bv->beforeChange(this);
                LyXCursor const cur = cursor;
                if (!is_rtl)
                        cursorLeft(false);
                if ((is_rtl || cur != cursor) && // only if really moved!
-                   cursor.pos() < cursor.par()->size() &&
-                   cursor.par()->isInset(cursor.pos()) &&
-                   isHighlyEditableInset(cursor.par()->getInset(cursor.pos()))) {
-                       InsetOld * tmpinset = cursor.par()->getInset(cursor.pos());
+                   cursor.pos() < cursorPar()->size() &&
+                   cursorPar()->isInset(cursor.pos()) &&
+                   isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
+                       InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
                        cmd.message(tmpinset->editMessage());
                        FuncRequest cmd1(bv, LFUN_INSET_EDIT, is_rtl ? "left" : "right");
                        tmpinset->localDispatch(cmd1);
@@ -676,7 +688,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_BREAKLINE: {
-               lyx::pos_type body = cursor.par()->beginningOfBody();
+               lyx::pos_type body = cursorPar()->beginningOfBody();
 
                // Not allowed by LaTeX (labels or empty par)
                if (cursor.pos() <= body)
@@ -684,7 +696,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
                replaceSelection(bv->getLyXText());
                insertInset(new InsetNewline);
-               setCursor(cursor.par(), cursor.pos());
+               setCursor(cursorPar(), cursor.pos());
                moveCursorUpdate(bv, false);
                break;
        }
@@ -705,23 +717,21 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_DELETE_SKIP:
                // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
                if (!selection.set()) {
-                       LyXCursor cur = cursor;
-                       if (cur.pos() == cur.par()->size()) {
+                       if (cursor.pos() == cursorPar()->size()) {
                                cursorRight(bv);
-                               cur = cursor;
-                               if (cur.pos() == 0
-                                   && !(cur.par()->params().spaceTop()
-                                        == VSpace (VSpace::NONE))) {
+                               ParagraphParameters & params = cursorPar()->params();
+                               if (cursor.pos() == 0
+                                   && !(params.spaceTop() == VSpace (VSpace::NONE))) {
                                        setParagraph(
-                                                cur.par()->params().lineTop(),
-                                                cur.par()->params().lineBottom(),
-                                                cur.par()->params().pagebreakTop(),
-                                                cur.par()->params().pagebreakBottom(),
+                                                params.lineTop(),
+                                                params.lineBottom(),
+                                                params.pagebreakTop(),
+                                                params.pagebreakBottom(),
                                                 VSpace(VSpace::NONE),
-                                                cur.par()->params().spaceBottom(),
-                                                cur.par()->params().spacing(),
-                                                cur.par()->params().align(),
-                                                cur.par()->params().labelWidthString(), 0);
+                                                params.spaceBottom(),
+                                                params.spacing(),
+                                                params.align(),
+                                                params.labelWidthString(), 0);
                                        cursorLeft(bv);
                                } else {
                                        cursorLeft(bv);
@@ -758,20 +768,20 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_BACKSPACE_SKIP:
                // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
                if (!selection.set()) {
-                       LyXCursor cur = cursor;
-                       if (cur.pos() == 0
-                           && !(cur.par()->params().spaceTop() == VSpace(VSpace::NONE))) {
+                       ParagraphParameters & params = cursorPar()->params();
+                       if (cursor.pos() == 0 && !(params.spaceTop() == VSpace(VSpace::NONE))) {
                                setParagraph(
-                                        cur.par()->params().lineTop(),
-                                        cur.par()->params().lineBottom(),
-                                        cur.par()->params().pagebreakTop(),
-                                        cur.par()->params().pagebreakBottom(),
+                                        params.lineTop(),
+                                        params.lineBottom(),
+                                        params.pagebreakTop(),
+                                        params.pagebreakBottom(),
                                         VSpace(VSpace::NONE),
-                                  cur.par()->params().spaceBottom(),
-                                        cur.par()->params().spacing(),
-                                        cur.par()->params().align(),
-                                        cur.par()->params().labelWidthString(), 0);
+                                  params.spaceBottom(),
+                                        params.spacing(),
+                                        params.align(),
+                                        params.labelWidthString(), 0);
                        } else {
+                               LyXCursor cur = cursor;
                                backspace();
                                selection.cursor = cur;
                        }
@@ -783,7 +793,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_BREAKPARAGRAPH:
                replaceSelection(bv->getLyXText());
-               breakParagraph(bv->buffer()->paragraphs, 0);
+               breakParagraph(bv->buffer()->paragraphs(), 0);
                bv->update();
                selection.cursor = cursor;
                bv->switchKeyMap();
@@ -792,7 +802,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
                replaceSelection(bv->getLyXText());
-               breakParagraph(bv->buffer()->paragraphs, 1);
+               breakParagraph(bv->buffer()->paragraphs(), 1);
                bv->update();
                selection.cursor = cursor;
                bv->switchKeyMap();
@@ -806,20 +816,21 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                LyXCursor cur = cursor;
                replaceSelection(bv->getLyXText());
                if (cur.pos() == 0) {
-                       if (cur.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
+                       ParagraphParameters & params = getPar(cur)->params();
+                       if (params.spaceTop() == VSpace(VSpace::NONE)) {
                                setParagraph(
-                                        cur.par()->params().lineTop(),
-                                        cur.par()->params().lineBottom(),
-                                        cur.par()->params().pagebreakTop(),
-                                        cur.par()->params().pagebreakBottom(),
-                                        VSpace(VSpace::DEFSKIP), cur.par()->params().spaceBottom(),
-                                        cur.par()->params().spacing(),
-                                        cur.par()->params().align(),
-                                        cur.par()->params().labelWidthString(), 1);
+                                        params.lineTop(),
+                                        params.lineBottom(),
+                                        params.pagebreakTop(),
+                                        params.pagebreakBottom(),
+                                        VSpace(VSpace::DEFSKIP), params.spaceBottom(),
+                                        params.spacing(),
+                                        params.align(),
+                                        params.labelWidthString(), 1);
                        }
                }
                else {
-                       breakParagraph(bv->buffer()->paragraphs, 0);
+                       breakParagraph(bv->buffer()->paragraphs(), 0);
                }
                bv->update();
                selection.cursor = cur;
@@ -829,13 +840,13 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        }
 
        case LFUN_PARAGRAPH_SPACING: {
-               ParagraphList::iterator pit = cursor.par();
+               ParagraphList::iterator pit = cursorPar();
                Spacing::Space cur_spacing = pit->params().spacing().getSpace();
                float cur_value = 1.0;
                if (cur_spacing == Spacing::Other)
                        cur_value = pit->params().spacing().getValue();
 
-               istringstream is(STRCONV(cmd.argument));
+               istringstream is(cmd.argument);
                string tmp;
                is >> tmp;
                Spacing::Space new_spacing = cur_spacing;
@@ -871,7 +882,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        }
 
        case LFUN_INSET_SETTINGS:
-               Assert(bv->theLockingInset());
+               BOOST_ASSERT(bv->theLockingInset());
                bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
                break;
 
@@ -883,7 +894,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_SPACE_INSERT:
-               if (cursor.par()->layout()->free_spacing)
+               if (cursorPar()->layout()->free_spacing)
                        insertChar(' ');
                else
                        doInsertInset(this, cmd, false, false);
@@ -953,27 +964,24 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_TRANSPOSE_CHARS:
-               recordUndo(bv, Undo::ATOMIC, cursor.par());
+               recordUndo(bv, Undo::ATOMIC, cursorPar());
                redoParagraph();
                bv->update();
                break;
 
-       case LFUN_PASTE: {
+       case LFUN_PASTE:
                cmd.message(_("Paste"));
                replaceSelection(bv->getLyXText());
-               size_t sel_index = 0;
-               string const & arg = cmd.argument;
-               if (isStrUnsignedInt(arg)) {
-                       size_t const paste_arg = strToUnsignedInt(arg);
 #warning FIXME Check if the arg is in the domain of available selections.
-                       sel_index = paste_arg;
-               }
-               pasteSelection(sel_index);
+               if (isStrUnsignedInt(cmd.argument))
+                       pasteSelection(strToUnsignedInt(cmd.argument));
+               else
+                       pasteSelection(0);
                clearSelection(); // bug 393
                bv->update();
                bv->switchKeyMap();
+               finishUndo();
                break;
-       }
 
        case LFUN_CUT:
                cutSelection(true, true);
@@ -1007,7 +1015,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_SETXY: {
                int x = 0;
                int y = 0;
-               istringstream is(STRCONV(cmd.argument));
+               istringstream is(cmd.argument);
                is >> x >> y;
                if (!is)
                        lyxerr << "SETXY: Could not parse coordinates in '"
@@ -1027,7 +1035,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_GETLAYOUT:
-               cmd.message(tostr(cursor.par()->layout()));
+               cmd.message(tostr(cursorPar()->layout()));
                break;
 
        case LFUN_LAYOUT: {
@@ -1046,7 +1054,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
                // Derive layout number from given argument (string)
                // and current buffer's textclass (number)
-               LyXTextClass const & tclass = bv->buffer()->params.getLyXTextClass();
+               LyXTextClass const & tclass = bv->buffer()->params().getLyXTextClass();
                bool hasLayout = tclass.hasLayout(cmd.argument);
                string layout = cmd.argument;
 
@@ -1068,8 +1076,8 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                if (!change_layout && selection.set() &&
                        selection.start.par() != selection.end.par())
                {
-                       ParagraphList::iterator spit = selection.start.par();
-                       ParagraphList::iterator epit = boost::next(selection.end.par());
+                       ParagraphList::iterator spit = getPar(selection.start);
+                       ParagraphList::iterator epit = boost::next(getPar(selection.end));
                        while (spit != epit) {
                                if (spit->layout()->name() != current_layout) {
                                        change_layout = true;
@@ -1124,7 +1132,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_QUOTE: {
                replaceSelection(bv->getLyXText());
-               ParagraphList::iterator pit = cursor.par();
+               ParagraphList::iterator pit = cursorPar();
                lyx::pos_type pos = cursor.pos();
                char c;
                if (!pos)
@@ -1136,10 +1144,10 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
                LyXLayout_ptr const & style = pit->layout();
 
+               BufferParams const & bufparams = bv->buffer()->params();
                if (style->pass_thru ||
-                               pit->getFontSettings(bv->buffer()->params,
-                                        pos).language()->lang() == "hebrew" ||
-                       (!bv->insertInset(new InsetQuotes(c, bv->buffer()->params))))
+                   pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew" ||
+                   !bv->insertInset(new InsetQuotes(c, bufparams)))
                        bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
                break;
        }
@@ -1172,14 +1180,10 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                if (!isInInset() && bv->theLockingInset())
                        break;
                if (cmd.button() == mouse_button::button1) {
-                       if (!isInInset())
-                               bv->screen().toggleSelection(this, bv);
                        cursorHome();
                        selection.cursor = cursor;
                        cursorEnd();
                        setSelection();
-                       if (!isInInset())
-                               bv->screen().toggleSelection(this, bv, false);
                        bv->update();
                        bv->haveSelection(selection.set());
                }
@@ -1191,13 +1195,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                if (!isInInset() && bv->theLockingInset())
                        break;
                if (cmd.button() == mouse_button::button1) {
-                       if (!isInInset()) {
-                               bv->screen().toggleSelection(this, bv);
-                               selectWord(lyx::WHOLE_WORD_STRICT);
-                               bv->screen().toggleSelection(this, bv, false);
-                       } else {
-                               selectWord(lyx::WHOLE_WORD_STRICT);
-                       }
+                       selectWord(lyx::WHOLE_WORD_STRICT);
                        bv->update();
                        bv->haveSelection(selection.set());
                }
@@ -1216,14 +1214,14 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                if (bv->theLockingInset()) {
                        InsetOld * tli = bv->theLockingInset();
                        LyXCursor cursor = bv->text->cursor;
-                       LyXFont font = bv->text->getFont(cursor.par(), cursor.pos());
+                       LyXFont font = bv->text->getFont(cursorPar(), cursor.pos());
                        int width = tli->width();
                        int inset_x = font.isVisibleRightToLeft()
-                               ? cursor.ix() - width : cursor.ix();
+                               ? cursor.x() - width : cursor.x();
                        int start_x = inset_x + tli->scroll();
                        FuncRequest cmd1 = cmd;
                        cmd1.x = cmd.x - start_x;
-                       cmd1.y = cmd.y - cursor.iy() + bv->text->top_y();
+                       cmd1.y = cmd.y - cursor.y() + bv->top_y();
                        tli->localDispatch(cmd1);
                        break;
                }
@@ -1238,7 +1236,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                }
 
                RowList::iterator cursorrow = bv->text->cursorRow();
-               bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->text->top_y());
+               bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->top_y());
        #if 0
                // sorry for this but I have a strange error that the y value jumps at
                // a certain point. This seems like an error in my xforms library or
@@ -1258,7 +1256,6 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
                bv->text->setSelection();
                bv->update();
-               bv->fitCursor();
                break;
        }
 
@@ -1295,7 +1292,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        paste_internally = true;
                }
 
-               int const screen_first = bv->text->top_y();
+               int const screen_first = bv->top_y();
 
                if (bv->theLockingInset()) {
                        // We are in inset locking mode
@@ -1314,7 +1311,6 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        selection_possible = true;
 
                // Clear the selection
-               bv->screen().toggleSelection(bv->text, bv);
                bv->text->clearSelection();
                bv->update();
                bv->updateScrollbar();
@@ -1435,7 +1431,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        // stack. They don't *have* to
                        // alter the document...
                        // (Joacim)
-                       // ...or maybe the SetCursorParUndo()
+                       // ...or maybe the recordUndo()
                        // below isn't necessary at all anylonger?
                        if (inset_hit->lyxCode() == InsetOld::REF_CODE)
                                recordUndo(bv, Undo::ATOMIC);
@@ -1466,7 +1462,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                }
 
                bv->beforeChange(this);
-               LyXFont const old_font(real_current_font);
+               LyXFont const old_font = real_current_font;
 
                string::const_iterator cit = cmd.argument.begin();
                string::const_iterator end = cmd.argument.end();
@@ -1481,6 +1477,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                // update the minibuffer
                if (old_font != real_current_font)
                        bv->owner()->view_state_changed();
+               bv->updateScrollbar();
                break;
        }
 
@@ -1505,6 +1502,8 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_INSET_CAPTION:
 #endif
        case LFUN_INSERT_NOTE:
+       case LFUN_INSERT_BOX:
+       case LFUN_INSERT_BRANCH:
        case LFUN_INSERT_BIBITEM:
        case LFUN_INSET_ERT:
        case LFUN_INSET_FLOAT:
@@ -1533,6 +1532,19 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                doInsertInset(this, cmd, false, false);
                break;
 
+       case LFUN_DEPTH_MIN:
+               bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH, false);
+               clearSelection();
+               bv->update();
+               break;
+
+       case LFUN_DEPTH_PLUS:
+               clearSelection();
+               bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH, false);
+               clearSelection();
+               bv->update();
+               break;
+
        default:
                return UNDISPATCHED;
        }