]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
the spellcheck cleanup
[lyx.git] / src / text3.C
index 5f6b325f1a5a7775e3b4d69b157f42cef6d4251a..5635facaa402ba1f98555c350f29ff7e2ded670f 100644 (file)
 #include <config.h>
 
 #include "lyxtext.h"
+
+#include "buffer.h"
+#include "bufferparams.h"
 #include "BufferView.h"
-#include "funcrequest.h"
-#include "lyxrc.h"
-#include "Lsstream.h"
 #include "debug.h"
-#include "buffer.h"
-#include "ParagraphParameters.h"
-#include "gettext.h"
+#include "dispatchresult.h"
 #include "factory.h"
+#include "funcrequest.h"
+#include "gettext.h"
 #include "intl.h"
 #include "language.h"
-#include "support/tostr.h"
-#include "support/lstrings.h"
-#include "support/LAssert.h"
-#include "frontends/LyXView.h"
+#include "lyxrc.h"
+#include "lyxrow.h"
+#include "paragraph.h"
+#include "ParagraphParameters.h"
+#include "text_funcs.h"
+#include "undo.h"
+#include "vspace.h"
+
 #include "frontends/Dialogs.h"
-#include "insets/insetspecialchar.h"
-#include "insets/insettext.h"
+#include "frontends/LyXView.h"
+
 #include "insets/insetcommand.h"
 #include "insets/insetnewline.h"
-#include "undo_funcs.h"
-#include "text_funcs.h"
+#include "insets/insetspecialchar.h"
+#include "insets/insettext.h"
 
+#include "support/lstrings.h"
+#include "support/tostr.h"
+
+#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 &);
@@ -62,8 +77,8 @@ namespace {
        {
                LyXText * lt = bv->getLyXText();
 
-               //if (!lt->selection.set())
-    // lt->selection.cursor = lt->cursor;
+//             if (!lt->selection.set())
+//                     lt->selection.cursor = lt->cursor;
 
                if (selecting || lt->selection.mark())
                        lt->setSelection();
@@ -86,11 +101,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;
@@ -101,7 +116,7 @@ namespace {
                        return 0;
 
                // get inset dimensions
-               Assert(par->getInset(pos));
+               BOOST_ASSERT(par->getInset(pos));
 
                LyXFont const & font = text.getFont(par, pos);
 
@@ -123,7 +138,7 @@ namespace {
                        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
@@ -142,7 +157,7 @@ InsetOld * LyXText::checkInsetHit(int & x, int & 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;
@@ -155,7 +170,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;
@@ -166,7 +181,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;
@@ -186,11 +201,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;
 }
 
 
@@ -200,18 +215,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;
@@ -234,46 +249,40 @@ void LyXText::gotoInset(InsetOld::Code code, bool same_content)
 
 void LyXText::cursorPrevious()
 {
-       int y = bv_owner->top_y();
+       int y = bv()->top_y();
 
-       RowList::iterator rit = cursorRow();
+       ParagraphList::iterator cpit = cursorPar();
+       RowList::iterator crit = cpit->getRow(cursor.pos());
 
-       if (rit == firstRow()) {
+       if (isFirstRow(cpit, *crit)) {
                if (y > 0)
                        bv()->updateScrollbar();
                return;
        }
 
-       setCursorFromCoordinates(cursor.x_fix(), y);
+       setCursorFromCoordinates(bv()->x_target(), y);
        finishUndo();
 
-       int new_y;
-       if (rit == bv()->text->cursorRow()) {
+       if (crit == bv()->text->cursorRow()) {
                // we have a row which is taller than the workarea. The
                // simplest solution is to move to the previous row instead.
                cursorUp(true);
                return;
-               // This is what we used to do, so we wouldn't skip right past
-               // tall rows, but it's not working right now.
+       }
+
+       int new_y = + crit->height() - bv()->workHeight() + 1;
+
+       if (inset_owner) {
+               new_y += bv()->text->cursor.y()
+                       + bv()->theLockingInset()->insetInInsetY() + y;
        } else {
-               if (inset_owner) {
-                       new_y = bv()->text->cursor.y()
-                               + bv()->theLockingInset()->insetInInsetY() + y
-                               + rit->height()
-                               - bv()->workHeight() + 1;
-               } else {
-                       new_y = cursor.y()
-                               - rit->baseline()
-                               + rit->height()
-                               - bv()->workHeight() + 1;
-               }
+               new_y += cursor.y() - crit->baseline();
        }
 
+       previousRow(cpit, crit);
        LyXCursor cur;
-       ParagraphList::iterator pit = cursor.par();
-       previousRow(pit, rit);
-       setCursor(cur, pit, rit->pos(), false);
-       if (cur.y() > bv_owner->top_y())
+       setCursor(cur, parOffset(cpit), crit->pos(), false);
+       if (cur.y() > bv()->top_y())
                cursorUp(true);
        bv()->updateScrollbar();
 }
@@ -281,32 +290,35 @@ void LyXText::cursorPrevious()
 
 void LyXText::cursorNext()
 {
-       int topy = bv_owner->top_y();
+       int topy = bv()->top_y();
 
-       RowList::iterator rit = cursorRow();
-       if (rit == lastRow()) {
-               int y = cursor.y() - rit->baseline() + cursorRow()->height();
+       ParagraphList::iterator cpit = cursorPar();
+       RowList::iterator crit = cpit->getRow(cursor.pos());
+
+       if (isLastRow(cpit, *crit)) {
+               int y = cursor.y() - crit->baseline() + crit->height();
                if (y > topy + bv()->workHeight())
-                       bv_owner->updateScrollbar();
+                       bv()->updateScrollbar();
                return;
        }
 
-       int y = topy + bv_owner->workHeight();
+       int y = topy + bv()->workHeight();
        if (inset_owner && !topy) {
-               y -= (bv_owner->text->cursor.y()
-                         - bv_owner->top_y()
-                         + bv_owner->theLockingInset()->insetInInsetY());
+               y -= (bv()->text->cursor.y()
+                         - bv()->top_y()
+                         + bv()->theLockingInset()->insetInInsetY());
        }
 
        ParagraphList::iterator dummypit;
-       y = getRowNearY(y, dummypit)->y();
+       Row const & rr = *getRowNearY(y, dummypit);
+       y = dummypit->y + rr.y_offset();
 
-       setCursorFromCoordinates(cursor.x_fix(), y);
+       setCursorFromCoordinates(bv()->x_target(), y);
        // + bv->workHeight());
        finishUndo();
 
        int new_y;
-       if (rit == bv_owner->text->cursorRow()) {
+       if (crit == bv()->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);
@@ -316,20 +328,20 @@ void LyXText::cursorNext()
 #if 0
                new_y = bv->top_y() + bv->workHeight();
 #endif
+       }
+
+       if (inset_owner) {
+               new_y = bv()->text->cursor.y()
+                       + bv()->theLockingInset()->insetInInsetY()
+                       + y - crit->baseline();
        } else {
-               if (inset_owner) {
-                       new_y = bv()->text->cursor.y()
-                               + bv()->theLockingInset()->insetInInsetY()
-                               + y - rit->baseline();
-               } else {
-                       new_y = cursor.y() - cursorRow()->baseline();
-               }
+               new_y = cursor.y() - crit->baseline();
        }
 
-       ParagraphList::iterator pit = cursor.par();
-       nextRow(pit, rit);
+
+       nextRow(cpit, crit);
        LyXCursor cur;
-       setCursor(cur, pit, rit->pos(), false);
+       setCursor(cur, parOffset(cpit), crit->pos(), false);
        if (cur.y() < bv_owner->top_y() + bv()->workHeight())
                cursorDown(true);
        bv()->updateScrollbar();
@@ -365,7 +377,7 @@ void doInsertInset(LyXText * lt, FuncRequest const & cmd,
                if (bv->insertInset(inset)) {
                        if (edit) {
                                FuncRequest cmd(bv, LFUN_INSET_EDIT, "left");
-                               inset->localDispatch(cmd);
+                               inset->dispatch(cmd);
                        }
                        if (gotsel && pastesel)
                                bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
@@ -375,9 +387,10 @@ void doInsertInset(LyXText * lt, FuncRequest const & cmd,
        }
 }
 
-}
+} // anon namespace
 
-InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
+
+DispatchResult LyXText::dispatch(FuncRequest const & cmd)
 {
        lyxerr[Debug::ACTION] << "LyXText::dispatch: action[" << cmd.action
                              <<"] arg[" << cmd.argument << ']' << "xy[" <<
@@ -388,7 +401,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        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
@@ -397,20 +410,20 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
                for (; tmp != end; ++tmp) {
                        if (tmp->params().startOfAppendix()) {
-                               recordUndo(bv, Undo::ATOMIC, tmp);
+                               recUndo(parOffset(tmp));
                                tmp->params().startOfAppendix(false);
                                redoParagraph(tmp);
                                break;
                        }
                }
 
-               recordUndo(bv, Undo::ATOMIC, pit);
+               recUndo(parOffset(pit));
                pit->params().startOfAppendix(start);
 
                // 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;
        }
@@ -436,7 +449,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();
@@ -446,7 +459,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();
@@ -470,7 +483,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);
@@ -480,7 +493,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);
@@ -544,7 +557,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();
@@ -552,7 +565,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();
@@ -562,7 +575,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());
@@ -571,18 +584,18 @@ 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);
+                       tmpinset->dispatch(cmd1);
                        break;
                }
                if (!is_rtl)
@@ -594,20 +607,20 @@ 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);
+                       tmpinset->dispatch(cmd1);
                        break;
                }
                if (is_rtl)
@@ -673,7 +686,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)
@@ -681,7 +694,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;
        }
@@ -702,23 +715,17 @@ 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(),
                                                 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);
@@ -755,20 +762,16 @@ 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(),
                                         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;
                        }
@@ -780,7 +783,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();
@@ -789,7 +792,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();
@@ -803,20 +806,17 @@ 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);
+                                        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;
@@ -826,13 +826,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;
@@ -868,7 +868,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;
 
@@ -880,7 +880,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);
@@ -950,27 +950,24 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_TRANSPOSE_CHARS:
-               recordUndo(bv, Undo::ATOMIC, cursor.par());
+               recUndo(cursor.par());
                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);
@@ -985,14 +982,14 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_BEGINNINGBUFSEL:
                if (inset_owner)
-                       return UNDISPATCHED;
+                       return DispatchResult(false);
                cursorTop();
                finishChange(bv, true);
                break;
 
        case LFUN_ENDBUFSEL:
                if (inset_owner)
-                       return UNDISPATCHED;
+                       return DispatchResult(false);
                cursorBottom();
                finishChange(bv, true);
                break;
@@ -1004,7 +1001,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 '"
@@ -1024,7 +1021,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: {
@@ -1043,7 +1040,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;
 
@@ -1065,8 +1062,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;
@@ -1121,7 +1118,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)
@@ -1133,10 +1130,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;
        }
@@ -1203,7 +1200,7 @@ 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(bv->text->cursorPar(), cursor.pos());
                        int width = tli->width();
                        int inset_x = font.isVisibleRightToLeft()
                                ? cursor.x() - width : cursor.x();
@@ -1211,7 +1208,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        FuncRequest cmd1 = cmd;
                        cmd1.x = cmd.x - start_x;
                        cmd1.y = cmd.y - cursor.y() + bv->top_y();
-                       tli->localDispatch(cmd1);
+                       tli->dispatch(cmd1);
                        break;
                }
 
@@ -1290,7 +1287,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        // otherwise give the event to the inset
                        if (inset_hit == bv->theLockingInset()) {
                                FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
-                               bv->theLockingInset()->localDispatch(cmd1);
+                               bv->theLockingInset()->dispatch(cmd1);
                                break;
                        }
                        bv->unlockInset(bv->theLockingInset());
@@ -1314,7 +1311,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        if (!bv->lockInset(inset))
                                lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
                        FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());
-                       inset->localDispatch(cmd1);
+                       inset->dispatch(cmd1);
                        break;
                }
                // I'm not sure we should continue here if we hit an inset (Jug20020403)
@@ -1329,7 +1326,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        bv->text->setCursorFromCoordinates(x, y + screen_first);
                finishUndo();
                bv->text->selection.cursor = bv->text->cursor;
-               bv->text->cursor.x_fix(bv->text->cursor.x());
+               bv->x_target(bv->text->cursor.x());
 
                if (bv->fitCursor())
                        selection_possible = false;
@@ -1371,7 +1368,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        // Only a ButtonPress FuncRequest outside the inset will
                        // force a insetUnlock.
                        FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
-                       bv->theLockingInset()->localDispatch(cmd1);
+                       bv->theLockingInset()->dispatch(cmd1);
                        break;
                }
 
@@ -1423,12 +1420,12 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        // ...or maybe the recordUndo()
                        // below isn't necessary at all anylonger?
                        if (inset_hit->lyxCode() == InsetOld::REF_CODE)
-                               recordUndo(bv, Undo::ATOMIC);
+                               recUndo(cursor.par());
 
                        bv->owner()->message(inset_hit->editMessage());
 
                        FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
-                       inset_hit->localDispatch(cmd1);
+                       inset_hit->dispatch(cmd1);
                }
 
                break;
@@ -1491,6 +1488,7 @@ 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:
@@ -1516,13 +1514,28 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_INDEX_PRINT:
        case LFUN_TOC_INSERT:
        case LFUN_HFILL:
+       case LFUN_INSERT_LINE:
+       case LFUN_INSERT_PAGEBREAK:
                // do nothing fancy
                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;
+               return DispatchResult(false);
        }
 
-       return DISPATCHED;
+       return DispatchResult(true, true);
 }