]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
more cursor dispatch
[lyx.git] / src / text3.C
index eadbe33e905af6829b667501a83b4bbff3776ffc..ca40002a96bcbb4a3ab84564e511a76c51165dfb 100644 (file)
@@ -252,8 +252,8 @@ InsetBase * LyXText::checkInsetHit(int x, int y)
        ParagraphList::iterator end;
 
        getParsInRange(paragraphs(),
-                      bv()->top_y() - yo_,
-                      bv()->top_y() - yo_ + bv()->workHeight(),
+                      bv()->top_y(),
+                      bv()->top_y() + bv()->workHeight(),
                       pit, end);
 
        lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
@@ -262,17 +262,14 @@ InsetBase * LyXText::checkInsetHit(int x, int y)
                InsetList::iterator iend = pit->insetlist.end();
                for ( ; iit != iend; ++iit) {
                        InsetBase * inset = iit->inset;
-                       //lyxerr << "examining inset " << inset
-                       //      << " xy: " << inset->x() << "/" << inset->y()
-                       //      << " x: " << inset->x() << "..." << inset->x() + inset->width()
-                       //      << " y: " << inset->y() - inset->ascent() << "..."
-                       //      << inset->y() + inset->descent()
-                       //      << endl;
-                       if (x >= inset->x()
-                           && x <= inset->x() + inset->width()
-                           && y >= inset->y() - inset->ascent()
-                           && y <= inset->y() + inset->descent())
-                       {
+#if 1
+                       lyxerr << "examining inset " << inset
+                       //<< " xo/yo: " << inset->xo() << "/" << inset->yo()
+                               << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
+                               << " yo: " << inset->yo() - inset->ascent() << "..."
+                               << inset->yo() + inset->descent() << endl;
+#endif
+                       if (inset->covers(x, y - bv()->top_y())) {
                                lyxerr << "Hit inset: " << inset << endl;
                                return inset;
                        }
@@ -357,14 +354,14 @@ void LyXText::gotoInset(InsetOld_code code, bool same_content)
 void LyXText::cursorPrevious()
 {
        LCursor & cur = bv()->cursor();
-       RowList::iterator crit = cursorRow();
+       pos_type cpos = cur.pos();
        lyx::paroffset_type cpar = cur.par();
 
-       int x = bv()->cursor().x_target() - xo_;
-       int y = bv()->top_y() - yo_;
+       int x = bv()->cursor().x_target();
+       int y = bv()->top_y();
        setCursorFromCoordinates(x, y);
 
-       if (cpar == cur.par() && crit == cursorRow()) {
+       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(true);
@@ -377,14 +374,15 @@ void LyXText::cursorPrevious()
 
 void LyXText::cursorNext()
 {
-       RowList::iterator crit = cursorRow();
-       ParagraphList::iterator cpar = cursorPar();
+       LCursor & cur = bv()->cursor();
+       pos_type cpos = cur.pos();
+       lyx::paroffset_type cpar = cur.par();
 
-       int x = bv()->cursor().x_target() - xo_;
-       int y = bv()->top_y() + bv()->workHeight() - yo_;
+       int x = cur.x_target();
+       int y = bv()->top_y() + bv()->workHeight();
        setCursorFromCoordinates(x, y);
 
-       if (cpar == cursorPar() && crit == cursorRow()) {
+       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(true);
@@ -397,11 +395,11 @@ void LyXText::cursorNext()
 
 namespace {
 
-void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
+void specialChar(LyXText * text, BufferView * bv, InsetSpecialChar::Kind kind)
 {
        bv->update();
        InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
-       replaceSelection(lt);
+       replaceSelection(text);
        if (!bv->insertInset(new_inset))
                delete new_inset;
        else
@@ -450,7 +448,8 @@ bool LyXText::rtl() const
 
 DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
 {
-       //lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
+       lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
+       //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
 
        BufferView * bv = &cur.bv();
 
@@ -671,7 +670,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                if (!cur.mark())
                        cur.clearSelection();
                finishChange(bv, false);
-               if (cursorPar() == firstPar() && cursorRow() == firstRow())
+               if (cur.par() == 0 && cursorRow() == firstRow())
                        return DispatchResult(false, FINISHED_UP);
                cursorPrevious();
                break;
@@ -680,7 +679,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                if (!cur.mark())
                        cur.clearSelection();
                finishChange(bv, false);
-               if (cursorPar() == lastPar() && cursorRow() == lastRow())
+               if (cur.par() == cur.lastpar() && cursorRow() == lastRow())
                        return DispatchResult(false, FINISHED_DOWN);
                cursorNext();
                break;
@@ -763,9 +762,10 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
        case LFUN_BACKSPACE_SKIP:
                // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
                if (!cur.selection()) {
-                       CursorSlice cur = cursor();
+#warning look here
+                       //CursorSlice cur = cursor();
                        backspace();
-                       anchor() = cur;
+                       //anchor() = cur;
                } else {
                        cutSelection(true, false);
                }
@@ -794,10 +794,11 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                // When at the beginning of a paragraph, remove
                // indentation and add a "defskip" at the top.
                // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
-               CursorSlice cur = cursor();
+#warning look here
+//             CursorSlice cur = cursor();
                replaceSelection(bv->getLyXText());
                if (cur.pos() == 0) {
-                       ParagraphParameters & params = getPar(cur)->params();
+                       ParagraphParameters & params = getPar(cur.current())->params();
                        setParagraph(
                                        params.spacing(),
                                        params.align(),
@@ -806,7 +807,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                        breakParagraph(bv->buffer()->paragraphs(), 0);
                }
                bv->update();
-               anchor() = cur;
+//     anchor() = cur;
                bv->switchKeyMap();
                bv->owner()->view_state_changed();
                break;
@@ -934,7 +935,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                break;
 
        case LFUN_PASTE:
-               cmd.message(_("Paste"));
+               cur.message(_("Paste"));
                replaceSelection(bv->getLyXText());
 #warning FIXME Check if the arg is in the domain of available selections.
                if (isStrUnsignedInt(cmd.argument))
@@ -949,13 +950,13 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
 
        case LFUN_CUT:
                cutSelection(true, true);
-               cmd.message(_("Cut"));
+               cur.message(_("Cut"));
                bv->update();
                break;
 
        case LFUN_COPY:
                copySelection();
-               cmd.message(_("Copy"));
+               cur.message(_("Copy"));
                break;
 
        case LFUN_BEGINNINGBUFSEL:
@@ -977,7 +978,8 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                break;
 
        case LFUN_GETXY:
-               cmd.message(tostr(cursorX()) + ' ' + tostr(cursorY()));
+               cur.message(tostr(cursorX(cur.current())) + ' '
+                         + tostr(cursorY(cur.current())));
                break;
 
        case LFUN_SETXY: {
@@ -995,15 +997,15 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
 
        case LFUN_GETFONT:
                if (current_font.shape() == LyXFont::ITALIC_SHAPE)
-                       cmd.message("E");
+                       cur.message("E");
                else if (current_font.shape() == LyXFont::SMALLCAPS_SHAPE)
-                       cmd.message("N");
+                       cur.message("N");
                else
-                       cmd.message("0");
+                       cur.message("0");
                break;
 
        case LFUN_GETLAYOUT:
-               cmd.message(cursorPar()->layout()->name());
+               cur.message(cursorPar()->layout()->name());
                break;
 
        case LFUN_LAYOUT: {
@@ -1016,7 +1018,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                // function list/array with information about what
                // functions needs arguments and their type.
                if (cmd.argument.empty()) {
-                       cmd.errorMessage(_("LyX function 'layout' needs an argument."));
+                       cur.errorMessage(_("LyX function 'layout' needs an argument."));
                        break;
                }
 
@@ -1034,7 +1036,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                }
 
                if (!hasLayout) {
-                       cmd.errorMessage(string(N_("Layout ")) + cmd.argument +
+                       cur.errorMessage(string(N_("Layout ")) + cmd.argument +
                                N_(" not known"));
                        break;
                }
@@ -1158,9 +1160,12 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                break;
 
        case LFUN_MOUSE_MOTION: {
+#if 0
                // Only use motion with button 1
                //if (ev.button() != mouse_button::button1)
                //      return false;
+               // don't set anchor_
+               bv->cursor().cursor_ = cur.cursor_;
 
                if (!bv->buffer())
                        break;
@@ -1185,6 +1190,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                                cursorUp(true);
                }
                cur.setSelection();
+#endif
                break;
        }
 
@@ -1227,10 +1233,13 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                        break;
                }
 
-               setCursorFromCoordinates(cmd.x, cmd.y);
+               setCursorFromCoordinates(cur.current(), cmd.x, cmd.y);
                cur.resetAnchor();
                finishUndo();
-               cur.x_target(cursorX() + xo_);
+               cur.x_target() = cursorX(cur.current());
+
+               // set cursor and anchor to this position
+               bv->cursor() = cur;
 
                if (bv->fitCursor())
                        selection_possible = false;
@@ -1455,24 +1464,32 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                break;
 
        case LFUN_FINISHED_LEFT:
-               lyxerr << "swallow LFUN_FINISHED_LEFT" << endl;
+               lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
+               cur.pop(cur.currentDepth());
+               cur.bv().cursor() = cur;
                if (rtl())
                        cursorLeft(true);
                break;
 
        case LFUN_FINISHED_RIGHT:
-               lyxerr << "swallow LFUN_FINISHED_RIGHT" << endl;
+               lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
+               cur.pop(cur.currentDepth());
+               cur.bv().cursor() = cur;
                if (!rtl())
                        cursorRight(true);
                break;
 
        case LFUN_FINISHED_UP:
-               lyxerr << "swallow LFUN_FINISHED_UP" << endl;
+               lyxerr << "handle LFUN_FINISHED_UP" << endl;
+               cur.pop(cur.currentDepth());
+               cur.bv().cursor() = cur;
                cursorUp(true);
                break;
 
        case LFUN_FINISHED_DOWN:
-               lyxerr << "swallow LFUN_FINISHED_DOWN" << endl;
+               lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
+               cur.pop(cur.currentDepth());
+               cur.bv().cursor() = cur;
                cursorDown(true);
                break;