]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
the spellcheck cleanup
[lyx.git] / src / text3.C
index 200d8c949f353f93c631a14d0ce35600cf3fbef1..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,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 = cursorPar();
-       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();
 }
@@ -295,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);
@@ -330,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 = cursorPar();
-       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();
@@ -379,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));
@@ -392,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[" <<
@@ -597,7 +595,7 @@ dispatch_result LyXText::dispatch(FuncRequest const & cmd)
                        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)
@@ -622,7 +620,7 @@ dispatch_result LyXText::dispatch(FuncRequest const & cmd)
                        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)
@@ -723,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(),
@@ -771,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(),
@@ -819,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(),
@@ -996,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;
@@ -1214,7 +1200,7 @@ dispatch_result LyXText::dispatch(FuncRequest const & cmd)
                if (bv->theLockingInset()) {
                        InsetOld * tli = bv->theLockingInset();
                        LyXCursor cursor = bv->text->cursor;
-                       LyXFont font = bv->text->getFont(cursorPar(), 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();
@@ -1222,7 +1208,7 @@ dispatch_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;
                }
 
@@ -1301,7 +1287,7 @@ dispatch_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());
@@ -1325,7 +1311,7 @@ dispatch_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)
@@ -1340,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;
@@ -1382,7 +1368,7 @@ dispatch_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;
                }
 
@@ -1439,7 +1425,7 @@ dispatch_result LyXText::dispatch(FuncRequest const & cmd)
                        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;
@@ -1528,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;
@@ -1546,8 +1534,8 @@ dispatch_result LyXText::dispatch(FuncRequest const & cmd)
                break;
 
        default:
-               return UNDISPATCHED;
+               return DispatchResult(false);
        }
 
-       return DISPATCHED;
+       return DispatchResult(true, true);
 }