]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
the spellcheck cleanup
[lyx.git] / src / text3.C
index 7c4430b526b41b278140c3537dedbb579a478f7d..5635facaa402ba1f98555c350f29ff7e2ded670f 100644 (file)
@@ -21,6 +21,7 @@
 #include "bufferparams.h"
 #include "BufferView.h"
 #include "debug.h"
+#include "dispatchresult.h"
 #include "factory.h"
 #include "funcrequest.h"
 #include "gettext.h"
@@ -76,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();
@@ -248,50 +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
-                       + rit->height()
-                       - bv()->workHeight() + 1;
+               new_y += bv()->text->cursor.y()
+                       + bv()->theLockingInset()->insetInInsetY() + y;
        } 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 = cursorPar();
-       rit = cursorRow();
-       if (isFirstRow(pit, *rit))
-               return;
-
-       previousRow(pit, rit);
-       setCursor(cur, parOffset(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();
 }
@@ -299,33 +290,35 @@ void LyXText::cursorPrevious()
 
 void LyXText::cursorNext()
 {
-       int topy = bv_owner->top_y();
+       int topy = bv()->top_y();
+
+       ParagraphList::iterator cpit = cursorPar();
+       RowList::iterator crit = cpit->getRow(cursor.pos());
 
-       RowList::iterator rit = cursorRow();
-       if (rit == lastRow()) {
-               int y = cursor.y() - rit->baseline() + cursorRow()->height();
+       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;
        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);
@@ -335,21 +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 = cursorPar();
-       rit = cursorRow();
-       nextRow(pit, rit);
+
+       nextRow(cpit, crit);
        LyXCursor cur;
-       setCursor(cur, parOffset(pit), rit->pos(), false);
+       setCursor(cur, parOffset(cpit), crit->pos(), false);
        if (cur.y() < bv_owner->top_y() + bv()->workHeight())
                cursorDown(true);
        bv()->updateScrollbar();
@@ -398,7 +390,7 @@ void doInsertInset(LyXText * lt, FuncRequest const & cmd,
 } // anon namespace
 
 
-dispatch_result LyXText::dispatch(FuncRequest const & cmd)
+DispatchResult LyXText::dispatch(FuncRequest const & cmd)
 {
        lyxerr[Debug::ACTION] << "LyXText::dispatch: action[" << cmd.action
                              <<"] arg[" << cmd.argument << ']' << "xy[" <<
@@ -729,10 +721,6 @@ dispatch_result LyXText::dispatch(FuncRequest const & cmd)
                                if (cursor.pos() == 0
                                    && !(params.spaceTop() == VSpace (VSpace::NONE))) {
                                        setParagraph(
-                                                params.lineTop(),
-                                                params.lineBottom(),
-                                                params.pagebreakTop(),
-                                                params.pagebreakBottom(),
                                                 VSpace(VSpace::NONE),
                                                 params.spaceBottom(),
                                                 params.spacing(),
@@ -777,10 +765,6 @@ dispatch_result LyXText::dispatch(FuncRequest const & cmd)
                        ParagraphParameters & params = cursorPar()->params();
                        if (cursor.pos() == 0 && !(params.spaceTop() == VSpace(VSpace::NONE))) {
                                setParagraph(
-                                        params.lineTop(),
-                                        params.lineBottom(),
-                                        params.pagebreakTop(),
-                                        params.pagebreakBottom(),
                                         VSpace(VSpace::NONE),
                                   params.spaceBottom(),
                                         params.spacing(),
@@ -825,10 +809,6 @@ dispatch_result LyXText::dispatch(FuncRequest const & cmd)
                        ParagraphParameters & params = getPar(cur)->params();
                        if (params.spaceTop() == VSpace(VSpace::NONE)) {
                                setParagraph(
-                                        params.lineTop(),
-                                        params.lineBottom(),
-                                        params.pagebreakTop(),
-                                        params.pagebreakBottom(),
                                         VSpace(VSpace::DEFSKIP), params.spaceBottom(),
                                         params.spacing(),
                                         params.align(),
@@ -1002,14 +982,14 @@ dispatch_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;
@@ -1346,7 +1326,7 @@ dispatch_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;
@@ -1534,6 +1514,8 @@ dispatch_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;
@@ -1552,8 +1534,8 @@ dispatch_result LyXText::dispatch(FuncRequest const & cmd)
                break;
 
        default:
-               return UNDISPATCHED;
+               return DispatchResult(false);
        }
 
-       return DISPATCHED;
+       return DispatchResult(true, true);
 }