[This contains the previously posted 'getStatus' 'infrastructure' and
...]

Fixes some of the cursor movements in tabulars and streamlines the
LyXText cursor movement handlers a bit.

It also renames 'FINISHED' to 'FINISHED_LEFT' (i.e. similar to
FINISHED_RIGHT/UP/DOWN)

Andre'

-- 
Those who desire to give up Freedom in order to gain Security, will not have,
nor do they deserve, either one.     (T. Jefferson or B. Franklin or both...)
Index: cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.C,v
retrieving revision 1.63
diff -u -p -r1.63 cursor.C
--- cursor.C    20 Feb 2004 11:00:40 -0000      1.63
+++ cursor.C    20 Feb 2004 16:40:40 -0000
@@ -98,7 +98,7 @@ DispatchResult LCursor::dispatch(FuncReq
                                // the inset handled the event fully
                                current_ = cursor_.size() - 1;
                                return DispatchResult(true, true);
-                       case FINISHED:
+                       case FINISHED_LEFT:
                                // the inset handled the event partially
                                cmd = FuncRequest(LFUN_FINISHED_LEFT);
                                break;
@@ -125,6 +125,30 @@ DispatchResult LCursor::dispatch(FuncReq
 }
 
 
+bool LCursor::getStatus(FuncRequest const & cmd, FuncStatus & status)
+{
+       lyxerr << "\nLCursor::getStatus: cmd: " << cmd << endl << *this << endl;
+       BOOST_ASSERT(pos() <= lastpos());
+       BOOST_ASSERT(idx() <= lastidx());
+       BOOST_ASSERT(par() <= lastpar());
+       for (current_ = cursor_.size() - 1; current_ >= 1; --current_) {
+               // the inset's getStatus() will return 'true' if it made
+               // a definitive decision on whether it want to handle the
+               // request or not. The result of this decision is put into
+               // the 'status' parameter.
+               bool const res = inset()->getStatus(*this, cmd, status);
+               if (res) {
+                       current_ = cursor_.size() - 1;
+                       return true;
+               }
+       }
+       BOOST_ASSERT(current_ == 0);
+       bool const res = bv_->text()->getStatus(*this, cmd, status);
+       current_ = cursor_.size() - 1;
+       return res;
+}
+
+
 void LCursor::push(InsetBase * inset)
 {
        lyxerr << "LCursor::push()  inset: " << inset << endl;
@@ -1936,7 +1960,7 @@ void LCursor::replaceWord(string const &
 
        // Go back so that replacement string is also spellchecked
        for (string::size_type i = 0; i < replacestring.length() + 1; ++i)
-               t->cursorLeft(*this, true);
+               t->cursorLeft(*this);
 }
 
 
Index: cursor.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.h,v
retrieving revision 1.38
diff -u -p -r1.38 cursor.h
--- cursor.h    20 Feb 2004 11:00:40 -0000      1.38
+++ cursor.h    20 Feb 2004 16:40:40 -0000
@@ -22,6 +22,7 @@ class BufferView;
 class UpdatableInset;
 class MathAtom;
 class DispatchResult;
+class FuncStatus;
 class FuncRequest;
 class InsetTabular;
 class LyXText;
@@ -74,6 +75,9 @@ public:
        explicit LCursor(BufferView & bv);
        /// dispatch from innermost inset upwards
        DispatchResult dispatch(FuncRequest const & cmd);
+       /// are we willing to handle this event?
+       bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
+
        /// add a new cursor slice
        void push(InsetBase * inset);
        /// add a new cursor slice, place cursor on left end
Index: dispatchresult.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/dispatchresult.h,v
retrieving revision 1.11
diff -u -p -r1.11 dispatchresult.h
--- dispatchresult.h    12 Nov 2003 14:38:24 -0000      1.11
+++ dispatchresult.h    20 Feb 2004 16:40:40 -0000
@@ -14,25 +14,19 @@
 #define DISPATCH_RESULT_H
 
 /** Dispatch result codes
-       DISPATCHED          = the inset caught the action
-       DISPATCHED_NOUPDATE = the inset caught the action and no update
-                       is needed to redraw the inset
-       FINISHED            = the inset must be unlocked as a result
-                       of the action
+       NONE                = no special action required
+       FINISHED_LEFT       = the cursor leaves the inset to the LEFT
+                             as consequence of this action
        FINISHED_RIGHT      = FINISHED, but move the cursor RIGHT from
                        the inset.
        FINISHED_UP         = FINISHED, but move the cursor UP from
                        the inset.
        FINISHED_DOWN       = FINISHED, but move the cursor DOWN from
                        the inset.
-       FINISHED_POP       = FINISHED, but move the cursor out the inset
-                       (possibly more than one level)
-       UNDISPATCHED        = the action was not caught, it should be
-                       dispatched by lower level insets
 */
 enum dispatch_result_t {
        NONE = 0,
-       FINISHED,
+       FINISHED_LEFT,
        FINISHED_RIGHT,
        FINISHED_UP,
        FINISHED_DOWN
Index: lyxtext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v
retrieving revision 1.293
diff -u -p -r1.293 lyxtext.h
--- lyxtext.h   16 Feb 2004 11:58:40 -0000      1.293
+++ lyxtext.h   20 Feb 2004 16:40:40 -0000
@@ -33,6 +33,7 @@ class Dimension;
 class InsetBase;
 class InsetOld_code;
 class FuncRequest;
+class FuncStatus;
 class LColor_color;
 class LCursor;
 class LyXTextClass;
@@ -129,7 +130,10 @@ public:
        int dist(int x, int y) const;
 
        /// try to handle that request
-       DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd);
+       void dispatch(LCursor & cur, FuncRequest const & cmd);
+       /// do we want to handle this event?
+       bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus & status);
+
        /// access to out BufferView. This should go...
        BufferView * bv();
        /// access to out BufferView. This should go...
@@ -194,13 +198,13 @@ public:
        ///
        InsetBase * editXY(LCursor & cur, int x, int y);
        ///
-       void cursorUp(LCursor & cur, bool selecting = false);
+       void cursorUp(LCursor & cur);
        ///
-       void cursorDown(LCursor & cur, bool selecting = false);
+       void cursorDown(LCursor & cur);
        ///
-       bool cursorLeft(LCursor & cur, bool internal = true);
+       void cursorLeft(LCursor & cur);
        ///
-       bool cursorRight(LCursor & cur, bool internal = true);
+       void cursorRight(LCursor & cur);
        ///
        void cursorLeftOneWord(LCursor & cur);
        ///
@@ -347,21 +351,6 @@ public:
        std::string getPossibleLabel(LCursor & cur) const;
        /// is this paragraph right-to-left?
        bool isRTL(Paragraph const & par) const;
-
-       ///
-       DispatchResult moveRight(LCursor & cur);
-       ///
-       DispatchResult moveLeft(LCursor & cur);
-       ///
-       DispatchResult moveRightIntern(LCursor & cur, bool front,
-               bool activate_inset, bool selecting);
-       ///
-       DispatchResult moveLeftIntern(LCursor & cur, bool front,
-               bool activate_inset, bool selecting);
-       ///
-       DispatchResult moveUp(LCursor & cur);
-       ///
-       DispatchResult moveDown(LCursor & cur);
        ///
        bool checkAndActivateInset(LCursor & cur, bool front);
 
Index: tabular.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/tabular.C,v
retrieving revision 1.204
diff -u -p -r1.204 tabular.C
--- tabular.C   16 Feb 2004 11:58:40 -0000      1.204
+++ tabular.C   20 Feb 2004 16:40:41 -0000
@@ -1999,7 +1999,6 @@ int LyXTabular::TeXRow(ostream & os, int
 {
        int ret = 0;
        int cell = getCellNumber(i, 0);
-       BufferParams const & bufferparams = buf.params();
 
        ret += TeXTopHLine(os, i);
        for (int j = 0; j < columns_; ++j) {
Index: text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.538
diff -u -p -r1.538 text.C
--- text.C      16 Feb 2004 11:58:40 -0000      1.538
+++ text.C      20 Feb 2004 16:40:41 -0000
@@ -877,7 +877,7 @@ void LyXText::breakParagraph(LCursor & c
        if (cur.pos() != 0 && cur.textRow().pos() == cur.pos()
            && !cpit->isNewline(cur.pos() - 1))
        {
-               cursorLeft(cur, true);
+               cursorLeft(cur);
        }
 
        while (!next_par->empty() && next_par->isNewline(0))
@@ -1254,7 +1254,7 @@ void LyXText::deleteWordForward(LCursor 
 {
        BOOST_ASSERT(this == cur.text());
        if (cur.lastpos() == 0)
-               cursorRight(cur, true);
+               cursorRight(cur);
        else {
                cur.resetAnchor();
                cur.selection() = true;
@@ -1270,7 +1270,7 @@ void LyXText::deleteWordBackward(LCursor
 {
        BOOST_ASSERT(this == cur.text());
        if (cur.lastpos() == 0)
-               cursorLeft(cur, true);
+               cursorLeft(cur);
        else {
                cur.resetAnchor();
                cur.selection() = true;
@@ -1287,7 +1287,7 @@ void LyXText::deleteLineForward(LCursor 
        BOOST_ASSERT(this == cur.text());
        if (cur.lastpos() == 0) {
                // Paragraph is empty, so we just go to the right
-               cursorRight(cur, true);
+               cursorRight(cur);
        } else {
                cur.resetAnchor();
                cur.selection() = true; // to avoid deletion
@@ -1355,12 +1355,11 @@ void LyXText::changeCase(LCursor & cur, 
 void LyXText::Delete(LCursor & cur)
 {
        BOOST_ASSERT(this == cur.text());
-       // this is a very simple implementation
-       // just move to the right
-       // if you had success make a backspace
-       size_t oldpar = cur.par();
-       if (cursorRight(cur, true)) {
-               recordUndo(cur, Undo::DELETE, oldpar);
+       // just move to the right, if we had success make a backspace
+       CursorSlice sl = cur.current();
+       cursorRight(cur);
+       if (sl == cur.current()) {
+               recordUndo(cur, Undo::DELETE, cur.par(), max(0, cur.par() - 1));
                backspace(cur);
        }
 }
@@ -1390,7 +1389,7 @@ void LyXText::backspace(LCursor & cur)
                        // handle the actual deletion of the paragraph.
 
                        if (cur.par() != 0) {
-                               cursorLeft(cur, true);
+                               cursorLeft(cur);
                                // the layout things can change the height of a row !
                                redoParagraph(cur);
                                return;
Index: text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.549
diff -u -p -r1.549 text2.C
--- text2.C     16 Feb 2004 17:26:08 -0000      1.549
+++ text2.C     20 Feb 2004 16:40:41 -0000
@@ -878,7 +878,7 @@ void LyXText::insertInset(LCursor & cur,
        // and fails if the cursor is behind the inset and getInset
        // does not return the inset!
        if (isHighlyEditableInset(inset))
-               cursorLeft(cur, true);
+               cursorLeft(cur);
        unFreezeUndo();
 }
 
@@ -1007,7 +1007,7 @@ void LyXText::setSelectionRange(LCursor 
                return;
        cur.resetAnchor();
        while (length--)
-               cursorRight(cur, true);
+               cursorRight(cur);
        cur.setSelection();
 }
 
@@ -1344,6 +1344,8 @@ InsetBase * LyXText::editXY(LCursor & cu
 
 bool LyXText::checkAndActivateInset(LCursor & cur, bool front)
 {
+       if (cur.selection())
+               return false;
        if (cur.pos() == cur.lastpos())
                return false;
        InsetBase * inset = cur.nextInset();
@@ -1354,125 +1356,56 @@ bool LyXText::checkAndActivateInset(LCur
 }
 
 
-DispatchResult LyXText::moveRight(LCursor & cur)
-{
-       if (isRTL(cur.paragraph()))
-               return moveLeftIntern(cur, false, true, false);
-       else
-               return moveRightIntern(cur, true, true, false);
-}
-
-
-DispatchResult LyXText::moveLeft(LCursor & cur)
-{
-       if (isRTL(cur.paragraph()))
-               return moveRightIntern(cur, true, true, false);
-       else
-               return moveLeftIntern(cur, false, true, false);
-}
-
-
-DispatchResult LyXText::moveRightIntern(LCursor & cur, 
-       bool front, bool activate_inset, bool selecting)
-{
-       if (cur.par() == cur.lastpar() && cur.pos() == cur.lastpos())
-               return DispatchResult(false, FINISHED_RIGHT);
-       if (activate_inset && checkAndActivateInset(cur, front))
-               return DispatchResult(true, true);
-       cursorRight(cur, true);
-       if (!selecting)
-               cur.clearSelection();
-       return DispatchResult(true);
-}
-
-
-DispatchResult LyXText::moveLeftIntern(LCursor & cur,
-       bool front, bool activate_inset, bool selecting)
-{
-       if (cur.par() == 0 && cur.pos() == 0)
-               return DispatchResult(false, FINISHED);
-       cursorLeft(cur, true);
-       if (!selecting)
-               cur.clearSelection();
-       if (activate_inset && checkAndActivateInset(cur, front))
-               return DispatchResult(true, true);
-       return DispatchResult(true);
-}
-
-
-DispatchResult LyXText::moveUp(LCursor & cur)
-{
-       if (cur.par() == 0 && cur.crow() == 0)
-               return DispatchResult(false, FINISHED_UP);
-       cursorUp(cur, false);
-       cur.clearSelection();
-       return DispatchResult(true);
-}
-
-
-DispatchResult LyXText::moveDown(LCursor & cur)
-{
-       if (cur.par() == cur.lastpar() && cur.textRow().endpos() == cur.lastpos())
-               return DispatchResult(false, FINISHED_DOWN);
-       cursorDown(cur, false);
-       cur.clearSelection();
-       return DispatchResult(true);
-}
-
-
-bool LyXText::cursorLeft(LCursor & cur, bool internal)
+void LyXText::cursorLeft(LCursor & cur)
 {
        if (cur.pos() != 0) {
                bool boundary = cur.boundary();
                setCursor(cur, cur.par(), cur.pos() - 1, true, false);
-               if (!internal && !boundary &&
-                   bidi.isBoundary(*bv()->buffer(), cur.paragraph(), cur.pos() + 1))
-                       setCursor(cur, cur.par(), cur.pos() + 1, true, true);
-               return true;
+               if (!checkAndActivateInset(cur, false)) {
+                       if (false && !boundary &&
+                                       bidi.isBoundary(*bv()->buffer(), 
cur.paragraph(), cur.pos() + 1))
+                               setCursor(cur, cur.par(), cur.pos() + 1, true, true);
+                       return;
+               }
        }
 
        if (cur.par() != 0) {
                // steps into the paragraph above
                setCursor(cur, cur.par() - 1, getPar(cur.par() - 1)->size());
-               return true;
        }
-
-       return false;
 }
 
 
-bool LyXText::cursorRight(LCursor & cur, bool internal)
+void LyXText::cursorRight(LCursor & cur)
 {
-       if (!internal && cur.boundary()) {
+       if (false && cur.boundary()) {
                setCursor(cur, cur.par(), cur.pos(), true, false);
-               return true;
+               return;
        }
 
        if (cur.pos() != cur.lastpos()) {
-               setCursor(cur, cur.par(), cur.pos() + 1, true, false);
-               if (!internal && bidi.isBoundary(*bv()->buffer(), cur.paragraph(),
-                                                cur.pos()))
-                       setCursor(cur, cur.par(), cur.pos(), true, true);
-               return true;
+               if (!checkAndActivateInset(cur, true)) { 
+                       setCursor(cur, cur.par(), cur.pos() + 1, true, false);
+                       if (false && bidi.isBoundary(*bv()->buffer(), cur.paragraph(),
+                                                        cur.pos()))
+                               setCursor(cur, cur.par(), cur.pos(), true, true);
+               }
+               return;
        }
 
-       if (cur.par() != cur.lastpar()) {
+       if (cur.par() != cur.lastpar())
                setCursor(cur, cur.par() + 1, 0);
-               return true;
-       }
-
-       return false;
 }
 
 
-void LyXText::cursorUp(LCursor & cur, bool selecting)
+void LyXText::cursorUp(LCursor & cur)
 {
        Row const & row = cur.textRow();
        int x = cur.x_target();
        int y = cursorY(cur.current()) - row.baseline() - 1;
        setCursorFromCoordinates(cur, x, y);
 
-       if (!selecting) {
+       if (!cur.selection()) {
                InsetBase * inset_hit = checkInsetHit(cur.x_target(), y);
                if (inset_hit && isHighlyEditableInset(inset_hit))
                        inset_hit->editXY(cur, cur.x_target(), y);
@@ -1480,14 +1413,14 @@ void LyXText::cursorUp(LCursor & cur, bo
 }
 
 
-void LyXText::cursorDown(LCursor & cur, bool selecting)
+void LyXText::cursorDown(LCursor & cur)
 {
        Row const & row = cur.textRow();
        int x = cur.x_target();
        int y = cursorY(cur.current()) - row.baseline() + row.height() + 1;
        setCursorFromCoordinates(cur, x, y);
 
-       if (!selecting) {
+       if (!cur.selection()) {
                InsetBase * inset_hit = checkInsetHit(cur.x_target(), y);
                if (inset_hit && isHighlyEditableInset(inset_hit))
                        inset_hit->editXY(cur, cur.x_target(), y);
Index: text3.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v
retrieving revision 1.227
diff -u -p -r1.227 text3.C
--- text3.C     16 Feb 2004 17:26:09 -0000      1.227
+++ text3.C     20 Feb 2004 16:40:41 -0000
@@ -298,7 +298,7 @@ void LyXText::cursorPrevious(LCursor & c
        if (cpar == cur.par() && cpos == cur.pos()) {
                // we have a row which is taller than the workarea. The
                // simplest solution is to move to the previous row instead.
-               cursorUp(cur, true);
+               cursorUp(cur);
        }
 
        bv()->updateScrollbar();
@@ -318,7 +318,7 @@ void LyXText::cursorNext(LCursor & cur)
        if (cpar == cur.par() && cpos == cur.pos()) {
                // we have a row which is taller than the workarea. The
                // simplest solution is to move to the next row instead.
-               cursorDown(cur, true);
+               cursorDown(cur);
        }
 
        bv()->updateScrollbar();
@@ -372,12 +372,13 @@ bool LyXText::isRTL(Paragraph const & pa
 }
 
 
-DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
+void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
        //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
 
        BufferView * bv = &cur.bv();
+       CursorSlice sl = cur.current();
 
        switch (cmd.action) {
 
@@ -460,38 +461,42 @@ DispatchResult LyXText::dispatch(LCursor
                finishChange(cur);
                break;
 
+       case LFUN_RIGHT:
        case LFUN_RIGHTSEL:
-               if (!cur.selection())
-                       cur.resetAnchor();
+               cur.selHandle(cmd.action == LFUN_RIGHTSEL);
                if (isRTL(cur.paragraph()))
-                       cursorLeft(cur, true);
+                       cursorLeft(cur);
                else
-                       cursorRight(cur, true);
-               finishChange(cur, true);
+                       cursorRight(cur);
+               if (sl == cur.current())
+                       cur.dispatched(FINISHED_RIGHT);
                break;
 
+       case LFUN_LEFT:
        case LFUN_LEFTSEL:
-               if (!cur.selection())
-                       cur.resetAnchor();
+               cur.selHandle(cmd.action == LFUN_LEFTSEL);
                if (isRTL(cur.paragraph()))
-                       cursorRight(cur, true);
+                       cursorRight(cur);
                else
-                       cursorLeft(cur, true);
-               finishChange(cur, true);
+                       cursorLeft(cur);
+               if (sl == cur.current())
+                       cur.dispatched(FINISHED_LEFT);
                break;
 
+       case LFUN_UP:
        case LFUN_UPSEL:
-               if (!cur.selection())
-                       cur.resetAnchor();
-               cursorUp(cur, true);
-               finishChange(cur, true);
+               cur.selHandle(cmd.action == LFUN_UPSEL);
+               cursorUp(cur);
+               if (sl == cur.current())
+                       cur.dispatched(FINISHED_UP);
                break;
 
+       case LFUN_DOWN:
        case LFUN_DOWNSEL:
-               if (!cur.selection())
-                       cur.resetAnchor();
-               cursorDown(cur, true);
-               finishChange(cur, true);
+               cur.selHandle(cmd.action == LFUN_DOWNSEL);
+               cursorDown(cur);
+               if (sl == cur.current())
+                       cur.dispatched(FINISHED_DOWN);
                break;
 
        case LFUN_UP_PARAGRAPHSEL:
@@ -562,22 +567,6 @@ DispatchResult LyXText::dispatch(LCursor
                break;
        }
 
-       case LFUN_RIGHT:
-               finishChange(cur);
-               return moveRight(cur);
-
-       case LFUN_LEFT:
-               finishChange(cur);
-               return moveLeft(cur);
-
-       case LFUN_UP:
-               finishChange(cur);
-               return moveUp(cur);
-
-       case LFUN_DOWN:
-               finishChange(cur);
-               return moveDown(cur);
-
        case LFUN_UP_PARAGRAPH:
                if (!cur.mark())
                        cur.clearSelection();
@@ -597,8 +586,9 @@ DispatchResult LyXText::dispatch(LCursor
                        cur.clearSelection();
                finishChange(cur, false);
                if (cur.par() == 0 && cur.textRow().pos() == 0)
-                       return DispatchResult(false, FINISHED_UP);
-               cursorPrevious(cur);
+                       cur.dispatched(FINISHED_UP);
+               else
+                       cursorPrevious(cur);
                break;
 
        case LFUN_NEXT:
@@ -607,8 +597,9 @@ DispatchResult LyXText::dispatch(LCursor
                finishChange(cur, false);
                if (cur.par() == cur.lastpar()
                          && cur.textRow().endpos() == cur.lastpos())
-                       return DispatchResult(false, FINISHED_DOWN);
-               cursorNext(cur);
+                       cur.dispatched(FINISHED_DOWN);
+               else
+                       cursorNext(cur);
                break;
 
        case LFUN_HOME:
@@ -652,8 +643,8 @@ DispatchResult LyXText::dispatch(LCursor
                // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
                if (!cur.selection()) {
                        if (cur.pos() == cur.lastpos()) {
-                               cursorRight(cur, true);
-                               cursorLeft(cur, true);
+                               cursorRight(cur);
+                               cursorLeft(cur);
                        }
                        Delete(cur);
                        cur.resetAnchor();
@@ -799,9 +790,9 @@ DispatchResult LyXText::dispatch(LCursor
        case LFUN_INSET_TOGGLE:
                cur.clearSelection();
                if (!toggleInset(cur))
-                       return DispatchResult(false);
-               cur.update();
-               bv->switchKeyMap();
+                       cur.notdispatched();
+               else
+                       bv->switchKeyMap();
                break;
 
        case LFUN_SPACE_INSERT:
@@ -879,21 +870,25 @@ DispatchResult LyXText::dispatch(LCursor
                break;
 
        case LFUN_BEGINNINGBUFSEL:
-               if (in_inset_)
-                       return DispatchResult(false);
-               if (!cur.selection())
-                       cur.resetAnchor();
-               cursorTop(cur);
-               finishChange(cur, true);
+               if (in_inset_) {
+                       cur.notdispatched();
+               } else {
+                       if (!cur.selection())
+                               cur.resetAnchor();
+                       cursorTop(cur);
+                       finishChange(cur, true);
+               }
                break;
 
        case LFUN_ENDBUFSEL:
-               if (in_inset_)
-                       return DispatchResult(false);
-               if (!cur.selection())
-                       cur.resetAnchor();
-               cursorBottom(cur);
-               finishChange(cur, true);
+               if (in_inset_) {
+                       cur.notdispatched();
+               } else {
+                       if (!cur.selection())
+                               cur.resetAnchor();
+                       cursorBottom(cur);
+                       finishChange(cur, true);
+               }
                break;
 
        case LFUN_GETXY:
@@ -1098,9 +1093,9 @@ DispatchResult LyXText::dispatch(LCursor
                // FIXME: shouldn't be top-text-specific
                if (!in_inset_ && cur.current() == old) {
                        if (cmd.y - bv->top_y() >= bv->workHeight())
-                               cursorDown(cur, true);
+                               cursorDown(cur);
                        else if (cmd.y - bv->top_y() < 0)
-                               cursorUp(cur, true);
+                               cursorUp(cur);
                }
 
                // don't set anchor_
@@ -1174,8 +1169,10 @@ DispatchResult LyXText::dispatch(LCursor
        case LFUN_MOUSE_RELEASE: {
                // do nothing if we used the mouse wheel
                if (cmd.button() == mouse_button::button4
-                || cmd.button() == mouse_button::button5)
-                       return DispatchResult(true, false);
+                || cmd.button() == mouse_button::button5) {
+                       cur.notdispatched();
+                       break;
+               }
 
                selection_possible = false;
 
@@ -1440,7 +1437,7 @@ DispatchResult LyXText::dispatch(LCursor
                lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
                cur.pop(cur.currentDepth());
                if (isRTL(cur.paragraph()))
-                       cursorLeft(cur, true);
+                       cursorLeft(cur);
                cur.bv().cursor() = cur;
                break;
 
@@ -1448,21 +1445,21 @@ DispatchResult LyXText::dispatch(LCursor
                lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
                cur.pop(cur.currentDepth());
                if (!isRTL(cur.paragraph()))
-                       cursorRight(cur, true);
+                       cursorRight(cur);
                cur.bv().cursor() = cur;
                break;
 
        case LFUN_FINISHED_UP:
                lyxerr << "handle LFUN_FINISHED_UP" << endl;
                cur.pop(cur.currentDepth());
-               cursorUp(cur, true);
+               cursorUp(cur);
                cur.bv().cursor() = cur;
                break;
 
        case LFUN_FINISHED_DOWN:
                lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
                cur.pop(cur.currentDepth());
-               cursorDown(cur, true);
+               cursorDown(cur);
                cur.bv().cursor() = cur;
                break;
 
@@ -1523,7 +1520,7 @@ DispatchResult LyXText::dispatch(LCursor
                        breakParagraph(cur);
 
                        if (cur.lastpos() != 0) {
-                               cursorLeft(cur, true);
+                               cursorLeft(cur);
                                breakParagraph(cur);
                        }
 
@@ -1584,9 +1581,20 @@ DispatchResult LyXText::dispatch(LCursor
                break;
        }
 
+       case LFUN_ESCAPE:
+               if (cur.selection())
+                       cur.selection() = false;
+               else
+                       cur.dispatched(FINISHED_LEFT);
+               break;
+
        default:
-               return DispatchResult(false);
+               return cur.notdispatched();
        }
+}
+
 
-       return DispatchResult(true, true);
+bool LyXText::getStatus(LCursor &, FuncRequest const &, FuncStatus &)
+{
+       return false;
 }
Index: insets/insetbase.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbase.C,v
retrieving revision 1.21
diff -u -p -r1.21 insetbase.C
--- insets/insetbase.C  16 Feb 2004 11:58:46 -0000      1.21
+++ insets/insetbase.C  20 Feb 2004 16:40:41 -0000
@@ -40,6 +40,12 @@ void InsetBase::priv_dispatch(LCursor & 
 }
 
 
+bool InsetBase::getStatus(LCursor &, FuncRequest const &, FuncStatus &)
+{
+       return false;
+}
+
+
 void InsetBase::edit(LCursor &, bool)
 {
        lyxerr << "InsetBase: edit left/right" << std::endl;
Index: insets/insetbase.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbase.h,v
retrieving revision 1.29
diff -u -p -r1.29 insetbase.h
--- insets/insetbase.h  16 Feb 2004 11:58:46 -0000      1.29
+++ insets/insetbase.h  20 Feb 2004 16:40:41 -0000
@@ -21,6 +21,7 @@ class BufferView;
 class CursorSlice;
 class DispatchResult;
 class FuncRequest;
+class FuncStatus;
 class LaTeXFeatures;
 class LCursor;
 class LyXLex;
@@ -69,6 +70,9 @@ public:
 
        // the real dispatcher
        void dispatch(LCursor & cur, FuncRequest const & cmd);
+       /// do we want to handle this event?
+       virtual bool getStatus(LCursor & cur, FuncRequest const & cmd,
+               FuncStatus & status);
 
        /// cursor enters
        virtual void edit(LCursor & cur, bool left);
Index: insets/insettabular.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.C,v
retrieving revision 1.406
diff -u -p -r1.406 insettabular.C
--- insets/insettabular.C       20 Feb 2004 11:00:41 -0000      1.406
+++ insets/insettabular.C       20 Feb 2004 16:40:41 -0000
@@ -470,6 +470,7 @@ void InsetTabular::priv_dispatch(LCursor
        case LFUN_RIGHTSEL:
        case LFUN_RIGHT:
                cell(cur.idx()).dispatch(cur, cmd);
+               cur.dispatched(NONE); // override the cell's result
                if (sl == cur.current())
                        isRightToLeft(cur) ? movePrevCell(cur) : moveNextCell(cur);
                if (sl == cur.current())
@@ -479,15 +480,17 @@ void InsetTabular::priv_dispatch(LCursor
        case LFUN_LEFTSEL: 
        case LFUN_LEFT:
                cell(cur.idx()).dispatch(cur, cmd);
+               cur.dispatched(NONE); // override the cell's result
                if (sl == cur.current())
                        isRightToLeft(cur) ? moveNextCell(cur) : movePrevCell(cur);
                if (sl == cur.current())
-                       cur.dispatched(FINISHED);
+                       cur.dispatched(FINISHED_LEFT);
                break;
 
        case LFUN_DOWNSEL:
        case LFUN_DOWN:
                cell(cur.idx()).dispatch(cur, cmd);
+               cur.dispatched(NONE); // override the cell's result
                if (sl == cur.current())
                        if (tabular.row_of_cell(cur.idx()) != tabular.rows() - 1) {
                                cur.idx() = tabular.getCellBelow(cur.idx());
@@ -502,6 +505,7 @@ void InsetTabular::priv_dispatch(LCursor
        case LFUN_UPSEL:
        case LFUN_UP:
                cell(cur.idx()).dispatch(cur, cmd);
+               cur.dispatched(NONE); // override the cell's result
                if (sl == cur.current())
                        if (tabular.row_of_cell(cur.idx()) != 0) {
                                cur.idx() = tabular.getCellAbove(cur.idx());
Index: mathed/math_gridinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_gridinset.C,v
retrieving revision 1.141
diff -u -p -r1.141 math_gridinset.C
--- mathed/math_gridinset.C     16 Feb 2004 11:58:51 -0000      1.141
+++ mathed/math_gridinset.C     20 Feb 2004 16:40:41 -0000
@@ -1031,7 +1031,7 @@ int MathGridInset::border() const
 
 void MathGridInset::splitCell(LCursor & cur)
 {
-       if (cur.idx() + 1 == nargs())
+       if (cur.idx() == cur.lastidx())
                return;
        MathArray ar = cur.cell();
        ar.erase(0, cur.pos());
@@ -1097,7 +1097,7 @@ void MathGridInset::priv_dispatch(LCurso
                        cur.idx() = cur.lastpos();
 
                        //mathcursor->normalize();
-                       cur.dispatched(FINISHED);
+                       cur.dispatched(FINISHED_LEFT);
                        return;
                }
 
@@ -1156,7 +1156,7 @@ void MathGridInset::priv_dispatch(LCurso
                                cur.notdispatched();
                                return;
                        }
-                       lyxerr << "returning DispatchResult(true, FINISHED)" << endl;
+                       lyxerr << "returning FINISHED_LEFT" << endl;
                        return;
                }
 
Index: mathed/math_nestinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_nestinset.C,v
retrieving revision 1.95
diff -u -p -r1.95 math_nestinset.C
--- mathed/math_nestinset.C     16 Feb 2004 11:58:51 -0000      1.95
+++ mathed/math_nestinset.C     20 Feb 2004 16:40:41 -0000
@@ -432,7 +432,7 @@ void MathNestInset::priv_dispatch(LCurso
        case LFUN_LEFT:
                cur.selHandle(cmd.action == LFUN_LEFTSEL);
                if (!cur.left())
-                       cur.dispatched(FINISHED);
+                       cur.dispatched(FINISHED_LEFT);
                break;
 
        case LFUN_UPSEL:
@@ -466,7 +466,7 @@ void MathNestInset::priv_dispatch(LCurso
        case LFUN_WORDLEFT:
                cur.selHandle(cmd.action == LFUN_WORDLEFTSEL);
                if (!cur.home())
-                       cur.dispatched(FINISHED);
+                       cur.dispatched(FINISHED_LEFT);
                break;
 
        case LFUN_WORDRIGHTSEL:
@@ -480,7 +480,7 @@ void MathNestInset::priv_dispatch(LCurso
        case LFUN_HOME:
                cur.selHandle(cmd.action == LFUN_HOMESEL);
                if (!cur.home())
-                       cur.dispatched(FINISHED_RIGHT);
+                       cur.dispatched(FINISHED_LEFT);
                break;
 
        case LFUN_ENDSEL:
@@ -494,7 +494,7 @@ void MathNestInset::priv_dispatch(LCurso
        case LFUN_PRIOR:
        case LFUN_BEGINNINGBUFSEL:
        case LFUN_BEGINNINGBUF:
-               cur.dispatched(FINISHED);
+               cur.dispatched(FINISHED_LEFT);
                break;
 
        case LFUN_NEXTSEL:
@@ -522,14 +522,14 @@ void MathNestInset::priv_dispatch(LCurso
        case LFUN_DELETE:
                //recordUndo(cur, Undo::ATOMIC);
                cur.erase();
-               cur.dispatched(FINISHED);
+               cur.dispatched(FINISHED_LEFT);
                break;
 
        case LFUN_ESCAPE:
                if (cur.selection()) 
                        cur.selClear();
                else 
-                       cur.dispatched(FINISHED);
+                       cur.dispatched(FINISHED_LEFT);
                break;
 
        case LFUN_INSET_TOGGLE:

Reply via email to