]> git.lyx.org Git - features.git/commitdiff
mouse selection patch
authorAlfredo Braunstein <abraunst@lyx.org>
Mon, 17 Nov 2003 20:28:11 +0000 (20:28 +0000)
committerAlfredo Braunstein <abraunst@lyx.org>
Mon, 17 Nov 2003 20:28:11 +0000 (20:28 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8100 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
src/BufferView_pimpl.C
src/ChangeLog
src/insets/ChangeLog
src/insets/insetcollapsable.C
src/insets/insettext.C
src/insets/insettext.h
src/paragraph_funcs.C
src/paragraph_funcs.h
src/rowpainter.C
src/text2.C
src/text3.C
src/textcursor.C

index 5a284698f89063ffa172b83efed4553b70f23171..72bc9ec1547c28ea5f03a22292d927e250355138 100644 (file)
@@ -896,8 +896,28 @@ namespace {
 bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
 {
        switch (cmd.action) {
+       case LFUN_MOUSE_MOTION: {
+               FuncRequest cmd1(cmd, bv_);
+               UpdatableInset * inset = bv_->cursor().innerInset();
+               DispatchResult res;
+               if (inset) {
+                       cmd1.x -= inset->x();
+                       cmd1.y -= inset->y();
+                       res = inset->dispatch(cmd1);
+               } else {
+                       cmd1.y += bv_->top_y();
+                       res = bv_->cursor().innerText()->dispatch(cmd1);
+               }
+                       
+               if (bv_->fitCursor() || res.update()) {
+                       bv_->update();
+                       bv_->cursor().updatePos();
+               }
+               
+               return true;
+       }
+
        case LFUN_MOUSE_PRESS:
-       case LFUN_MOUSE_MOTION:
        case LFUN_MOUSE_RELEASE:
        case LFUN_MOUSE_DOUBLE:
        case LFUN_MOUSE_TRIPLE: {
@@ -925,7 +945,7 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
                if (inset) {
                        FuncRequest cmd2 = cmd1;
                        lyxerr << "dispatching action " << cmd2.action 
-                               << " to inset " << inset << endl;
+                              << " to inset " << inset << endl;
                        cmd2.x -= inset->x();
                        cmd2.y -= inset->y();
                        res = inset->dispatch(cmd2);
@@ -958,6 +978,7 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
                               << " to surrounding LyXText "
                               << theTempCursor.innerText() << endl;
                        bv_->cursor() = theTempCursor;
+                       cmd1.y += bv_->top_y();
                        res = bv_->cursor().innerText()->dispatch(cmd1);
                        if (bv_->fitCursor() || res.update())
                                bv_->update();
index 302cd62c17bda41cbe99d85207756e289c07607e..c816611866038e3bc0726bbc090124ccd44c03ba 100644 (file)
@@ -1,3 +1,13 @@
+2003-11-17  Alfredo Braunstein  <abraunst@lyx.org>
+
+       * BufferView_pimpl.C: send LFUN_MOUSE_MOTION to the cursor
+       * paragraph_funcs.[Ch]: correct comment
+       * rowpainter.C: do not paint selections away from bv->cursor()
+       Fix a long standing selection painting bug.
+       * text3.C: generalize mouse-selection code to LyXTexts other that
+       top one
+       * textcursor.C: do not use y coords if we can use par offsets
+
 2003-11-17  Alfredo Braunstein  <abraunst@lyx.org>
 
        * lyxfunc.C (dispatch): add a missing LCursor::updatePos (fix
index 74bde1ea83f8cb0a38ab810751f89b96876b374f..e190a40fb0734de51bdaae75fffbb407b7422c9c 100644 (file)
@@ -1,3 +1,9 @@
+2003-11-17  Alfredo Braunstein  <abraunst@lyx.org>
+
+       * insetcollapsable.C: 
+       * insettext.C:
+       * insettext.h: hand on MOUSE_* events to the LyXText when appropriate
+       remove mouse_x mouse_y etc.
 
 2003-11-17  André Pönitz  <poenitz@gmx.net>
 
index 6d406f74877df85f84d3b103e84dda2895ef445d..359ca632fca68782eb084f6ce50a370db6799688 100644 (file)
@@ -185,7 +185,7 @@ InsetOld::EDITABLE InsetCollapsable::editable() const
 FuncRequest InsetCollapsable::adjustCommand(FuncRequest const & cmd)
 {
        FuncRequest cmd1 = cmd;
-       cmd1.y = ascent() + cmd.y - height_collapsed() - inset.ascent();
+       cmd1.y += ascent() - height_collapsed();
        return cmd1;
 }
 
@@ -299,7 +299,7 @@ InsetCollapsable::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
                        return DispatchResult(true, true);
 
                case LFUN_MOUSE_MOTION:
-                       if (!collapsed_ && cmd.y > button_dim.y2)
+                       if (!collapsed_)
                                inset.dispatch(adjustCommand(cmd));
                        return DispatchResult(true, true);
 
@@ -311,7 +311,7 @@ InsetCollapsable::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
                        return DispatchResult(true, true);
 
                default:
-                       return inset.dispatch(cmd);
+                       return inset.dispatch(adjustCommand(cmd));
        }
        lyxerr << "InsetCollapsable::priv_dispatch (end)" << endl;
 }
index ffcfedcfa20df095ab00519bcafb533ad0a9a9f4..b1d559b739b1797cff72b2a7b71a1a222dc4e7be 100644 (file)
@@ -114,11 +114,8 @@ void InsetText::init()
        for (; pit != end; ++pit)
                pit->setInsetOwner(this);
        text_.paragraphs_ = &paragraphs;
-       no_selection = true;
        old_par = -1;
        in_insetAllowed = false;
-       mouse_x = 0;
-       mouse_y = 0;
 }
 
 
@@ -289,7 +286,6 @@ void InsetText::updateLocal(BufferView * bv, bool /*mark_dirty*/)
        if (!text_.selection.set())
                text_.selection.cursor = text_.cursor;
 
-//     bv->fitCursor();
        bv->owner()->view_state_changed();
        bv->owner()->updateMenubar();
        bv->owner()->updateToolbar();
@@ -320,49 +316,6 @@ void InsetText::sanitizeEmptyText(BufferView * bv)
 
 extern LCursor theTempCursor;
 
-void InsetText::lfunMousePress(FuncRequest const & cmd)
-{
-       lyxerr << "InsetText::lfunMousePress, inset: " << this << endl;
-       no_selection = true;
-
-       // use this to check mouse motion for selection
-       mouse_x = cmd.x;
-       mouse_y = cmd.y;
-
-       BufferView * bv = cmd.view();
-       no_selection = false;
-       text_.clearSelection();
-
-       // set global cursor
-       bv->cursor() = theTempCursor;
-       lyxerr << "new global cursor: \n" << bv->cursor() << endl;
-       text_.setCursorFromCoordinates(cmd.x, cmd.y);
-}
-
-
-void InsetText::lfunMouseMotion(FuncRequest const & cmd)
-{
-       lyxerr << "InsetText::lfunMouseMotion, inset: " << this << endl;
-       if (no_selection || (mouse_x == cmd.x && mouse_y == cmd.y))
-               return;
-
-       BufferView * bv = cmd.view();
-       LyXCursor cur = text_.cursor;
-       text_.setCursorFromCoordinates(cmd.x, cmd.y + dim_.asc);
-       bv->x_target(text_.cursor.x());
-       if (cur != text_.cursor) {
-               text_.setSelection();
-               updateLocal(bv, false);
-       }
-}
-
-
-void InsetText::lfunMouseRelease(FuncRequest const &)
-{
-       lyxerr << "InsetText::lfunMouseRelease, inset: " << this << endl;
-       no_selection = true;
-}
-
 
 void InsetText::edit(BufferView * bv, bool left)
 {
@@ -403,41 +356,28 @@ DispatchResult InsetText::priv_dispatch(FuncRequest const & cmd,
        idx_type &, pos_type &)
 {
        lyxerr << "InsetText::priv_dispatch (begin), act: "
-               << cmd.action << " " << endl;
+              << cmd.action << " " << endl;
+       
        BufferView * bv = cmd.view();
        setViewCache(bv);
+
        DispatchResult result;
        result.dispatched(true);
 
        bool was_empty = paragraphs.begin()->empty() && paragraphs.size() == 1;
-       if (cmd.action != LFUN_MOUSE_PRESS
-                       && cmd.action != LFUN_MOUSE_MOTION
-                       && cmd.action != LFUN_MOUSE_RELEASE)
-               no_selection = false;
 
        switch (cmd.action) {
        case LFUN_MOUSE_PRESS:
-               lfunMousePress(cmd);
-               result = DispatchResult(true, true);    
-               break;
-
-       case LFUN_MOUSE_MOTION:
-               lfunMouseMotion(cmd);
-               result = DispatchResult(true, true);
-               break;
-
-       case LFUN_MOUSE_RELEASE:
-               lfunMouseRelease(cmd);
-               result = DispatchResult(true, true);
-               break;
-
+               bv->cursor() = theTempCursor;
+               // fall through
        default:
                result = text_.dispatch(cmd);
                break;
        }
 
-       /// If the action has deleted all text in the inset, we need to change the
-       // language to the language of the surronding text.
+       // If the action has deleted all text in the inset, we need
+       // to change the language to the language of the surronding
+       // text.
        if (!was_empty && paragraphs.begin()->empty() &&
            paragraphs.size() == 1) {
                LyXFont font(LyXFont::ALL_IGNORE);
@@ -513,7 +453,6 @@ bool InsetText::insertInset(BufferView * bv, InsetOld * inset)
 {
        inset->setOwner(this);
        text_.insertInset(inset);
-//     bv->fitCursor();
        updateLocal(bv, true);
        return true;
 }
@@ -580,7 +519,6 @@ void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
        if (selectall)
                text_.clearSelection();
 
-//     bv->fitCursor();
        updateLocal(bv, true);
 }
 
index b0f63ea5af7fc002096d6dee08adc382d329c50f..c2584e5c40cf793f55402ce82d34f87eb2b32ce8 100644 (file)
@@ -177,12 +177,6 @@ protected:
 private:
        ///
        void init();
-       ///
-       void lfunMousePress(FuncRequest const &);
-       ///
-       void lfunMouseMotion(FuncRequest const &);
-       ///
-       void lfunMouseRelease(FuncRequest const &);
        // If the inset is empty set the language of the current font to the
        // language to the surronding text (if different).
        void sanitizeEmptyText(BufferView *);
@@ -217,15 +211,10 @@ private:
        ///
        mutable lyx::paroffset_type old_par;
 
-       ///
-       // to remember old painted frame dimensions to clear it on the right spot!
-       ///
+       /** to remember old painted frame dimensions to clear it on
+        *  the right spot!
+        */
        mutable bool in_insetAllowed;
-       ///
-       // these are used to check for mouse movement in Motion selection code
-       ///
-       int mouse_x;
-       int mouse_y;
 public:
        ///
        mutable LyXText text_;
index 74d52499166eae8dbd10bde2ae9126dfee66728f..6f369b341af6c01b750072c32c273ba42e622c1b 100644 (file)
@@ -612,8 +612,6 @@ Paragraph const & ownerPar(Buffer const & buf, InsetOld const * inset)
 }
 
 
-
-
 void getParsInRange(ParagraphList & pl,
                    int ystart, int yend,
                    ParagraphList::iterator & beg,
index 22be6f6668179bd670592c4bcdd398d535c58b55..3c0ea7e8bc30e2dfdd9e70f9bf418269b834a5fc 100644 (file)
@@ -75,7 +75,7 @@ ParagraphList::iterator outerPar(Buffer const & buf, InsetOld const * inset);
 /// find owning paragraph containing an inset
 Paragraph const & ownerPar(Buffer const & buf, InsetOld const * inset);
 
-/// stretch range beg,end to the minimum containing ystart, yend
+/// return the range of pars [beg, end[ owning the range of y [ystart, yend] 
 void getParsInRange(ParagraphList & pl,
                    int ystart, int yend,
                    ParagraphList::iterator & beg,
index 941c2b0eed834a1c93a0c32ba9e5431a8fc88996..4541b61b3936abdfd618476b71121fe182bb9ee8 100644 (file)
@@ -14,6 +14,7 @@
 #include "rowpainter.h"
 
 #include "buffer.h"
+#include "cursor.h"
 #include "debug.h"
 #include "bufferparams.h"
 #include "BufferView.h"
@@ -389,11 +390,12 @@ void RowPainter::paintSelection()
        RowList::iterator endrow = endpit->getRow(text_.selection.end.pos());
        int const h = row_.height();
 
+       int const row_y = pit_->y + row_.y_offset();
+       
        if (text_.bidi.same_direction()) {
                int x;
                int y = yo_;
                int w;
-
                if (startrow == rit_ && endrow == rit_) {
                        if (startx < endx) {
                                x = int(xo_) + startx;
@@ -411,7 +413,8 @@ void RowPainter::paintSelection()
                        int const x = is_rtl ? int(xo_ + endx) : int(xo_);
                        int const w = is_rtl ? (width_ - endx) : endx;
                        pain_.fillRectangle(x, y, w, h, LColor::selection);
-               } else if (y_ > starty && y_ < endy) {
+               } else if (row_y > starty && row_y < endy) {
+               
                        pain_.fillRectangle(int(xo_), y, width_, h, LColor::selection);
                }
                return;
@@ -945,7 +948,7 @@ void RowPainter::paint()
                paintBackground();
 
        // paint the selection background
-       if (text_.selection.set())
+       if (text_.selection.set() && &text_ == bv_.cursor().innerText())
                paintSelection();
 
        // vertical lines for appendix
index 58ca5969be49dcbfc33e7ca722c8138e80318bbf..1a4bd22f2fea47f1e1c6055dd4ae1c0f7d5e409d 100644 (file)
@@ -1031,6 +1031,7 @@ void LyXText::insertInset(InsetOld * inset)
        // does not return the inset!
        if (isHighlyEditableInset(inset))
                cursorLeft(true);
+       
        unFreezeUndo();
 }
 
index 7b4abae39cbb983ffbb0a0f46f4b2d7b082a65bd..e38fc138836766ca1a81efcf2a592eb0248654e1 100644 (file)
@@ -1289,55 +1289,27 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
 
                if (!bv->buffer())
                        break;
-
-               // Check for inset locking
-#ifdef LOCK
-               if (bv->innerInset()) {
-                       InsetOld * tli = bv->innerInset();
-                       LyXCursor cursor = bv->text->cursor;
-                       LyXFont font = bv->text->getFont(bv->text->cursorPar(), cursor.pos());
-                       int width = tli->width();
-                       int inset_x = font.isVisibleRightToLeft()
-                               ? cursor.x() - width : cursor.x();
-                       int start_x = inset_x + tli->scroll();
-                       FuncRequest cmd1 = cmd;
-                       cmd1.x = cmd.x - start_x;
-                       cmd1.y = cmd.y - cursor.y() + bv->top_y();
-                       tli->dispatch(cmd1);
-                       break;
-               }
-#endif
-
-               // The test for not selection possible is needed, that only motion
-               // events are used, where the bottom press event was on
-               //  the drawing area too
+               // The test for not selection possible is needed, that
+               // only motion events are used, where the bottom press
+               // event was on the drawing area too
                if (!selection_possible) {
-                       lyxerr[Debug::ACTION]
-                               << "BufferView::Pimpl::Dispatch: no selection possible\n";
+                       lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
+                               "Dispatch: no selection possible\n";
                        break;
                }
+               RowList::iterator cursorrow = cursorRow();
+
+               setCursorFromCoordinates(cmd.x, cmd.y);
 
-               RowList::iterator cursorrow = bv->text->cursorRow();
-               bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->top_y());
-       #if 0
-               // sorry for this but I have a strange error that the y value jumps at
-               // a certain point. This seems like an error in my xforms library or
-               // in some other local environment, but I would like to leave this here
-               // for the moment until I can remove this (Jug 20020418)
-               if (y_before < bv->text->cursor.y())
-                       lyxerr << y_before << ':'
-                              << bv->text->cursor.y() << endl;
-       #endif
                // This is to allow jumping over large insets
-               if (cursorrow == cursorRow()) {
-                       if (cmd.y >= bv->workHeight())
+               // FIXME: shouldn't be top-text-specific
+               if (cursorrow == cursorRow() && !in_inset_) {
+                       if (cmd.y - bv->top_y() >= bv->workHeight())
                                cursorDown(false);
-                       else if (cmd.y < 0)
+                       else if (cmd.y - bv->top_y() < 0)
                                cursorUp(false);
                }
-
-               bv->text->setSelection();
-//             bv->update();
+               setSelection();
                break;
        }
 
@@ -1369,24 +1341,21 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
                        paste_internally = true;
                }
 
-               int const screen_first = bv->top_y();
                selection_possible = true;
 
                // Clear the selection
-               bv->text->clearSelection();
-               bv->update();
-               bv->updateScrollbar();
-
+               clearSelection();
+       
                // Right click on a footnote flag opens float menu
                if (cmd.button() == mouse_button::button3) {
                        selection_possible = false;
                        break;
                }
 
-               bv->text->setCursorFromCoordinates(cmd.x, cmd.y + screen_first);
+               setCursorFromCoordinates(cmd.x, cmd.y);
+               selection.cursor = cursor;
                finishUndo();
-               bv->text->selection.cursor = bv->text->cursor;
-               bv->x_target(bv->text->cursor.x());
+               bv->x_target(cursor.x());
 
                if (bv->fitCursor())
                        selection_possible = false;
@@ -1414,7 +1383,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
                        return DispatchResult(true, false);
 
                selection_possible = false;
-
+               
                if (cmd.button() == mouse_button::button2)
                        break;
 
index 2b7238ccc67b9139809441f32c05c4be0950e485..875ea7170b2bb23d70f3006f0ef4835420076d10 100644 (file)
@@ -13,6 +13,7 @@
 #include "textcursor.h"
 #include "paragraph.h"
 #include "ParagraphList_fwd.h"
+#include "debug.h"
 
 #include <string>
 
@@ -37,9 +38,9 @@ void TextCursor::setSelection()
                        selection.end = selection.cursor;
                        selection.start = cursor;
                }
-       else if (selection.cursor.y() < cursor.y() ||
-                (selection.cursor.y() == cursor.y()
-                 && selection.cursor.x() < cursor.x())) {
+       else if (selection.cursor.par() < cursor.par() ||
+                (selection.cursor.par() == cursor.par()
+                 && selection.cursor.pos() < cursor.pos())) {
                selection.end = cursor;
                selection.start = selection.cursor;
        }