]> git.lyx.org Git - features.git/commitdiff
Fix bug 4166: Crash when middle button click on inset label
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 12 Aug 2008 14:13:16 +0000 (14:13 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 12 Aug 2008 14:13:16 +0000 (14:13 +0000)
http://bugzilla.lyx.org/show_bug.cgi?id=4662

* InsetCollapsable.cpp (doDispatch): cleanup the handling of mouse-
related lfuns. The new behavior is as follows:
- everything that does not touch the button is sent to the insettext,
if it is visible, and delegated to enclosing inset instead
- mouse1-press is delegated to enclosing inset (which will set the
cursor)
- the rest is either acted upon or results on a mere cur.noUpdate().

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26122 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/InsetCollapsable.cpp
src/insets/InsetCollapsable.h

index b31beff245beaa1ef2c5db5e60ce94baf7e4e177..221b8f3bbd0e5ea4aa7866e4fd4da0f1cebc7ff5 100644 (file)
@@ -425,7 +425,7 @@ void InsetCollapsable::cursorPos(BufferView const & bv,
 
 Inset::EDITABLE InsetCollapsable::editable() const
 {
-       return geometry() != ButtonOnly? HIGHLY_EDITABLE : IS_EDITABLE;
+       return geometry() != ButtonOnly ? HIGHLY_EDITABLE : IS_EDITABLE;
 }
 
 
@@ -489,28 +489,23 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        switch (cmd.action) {
        case LFUN_MOUSE_PRESS:
-               if (hitButton(cmd) && geometry() != NoButton) {
+               if (hitButton(cmd)) {
                        switch (cmd.button()) {
                        case mouse_button::button1:
-                               // reset selection if necessary (see bug 3060)
-                               if (cur.selection())
-                                       cur.bv().cursor().clearSelection();
-                               else
-                                       cur.noUpdate();
-                               cur.dispatched();
-                               return;
+                               // Pass the command to the enclosing InsetText,
+                               // so that the cursor gets set.
+                               cur.undispatched();
+                               break;
                        case mouse_button::none:
                        case mouse_button::button2:
                        case mouse_button::button3:
                        case mouse_button::button4:
                        case mouse_button::button5:
                                // Nothing to do.
-                               cur.undispatched();
-                               return;
+                               cur.noUpdate();
+                               break;
                        }
-               }
-               if (geometry() == NoButton 
-                       || (geometry() != ButtonOnly && !hitButton(cmd)))
+               } else if (geometry() != ButtonOnly)
                        InsetText::doDispatch(cur, cmd);
                else
                        cur.undispatched();
@@ -519,24 +514,26 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_MOUSE_MOTION:
        case LFUN_MOUSE_DOUBLE:
        case LFUN_MOUSE_TRIPLE:
-               if (geometry() == NoButton)
-                       InsetText::doDispatch(cur, cmd);
-               else if (geometry() != ButtonOnly
-                    && !hitButton(cmd))
+               if (hitButton(cmd)) 
+                       cur.noUpdate();
+               else if (geometry() != ButtonOnly)
                        InsetText::doDispatch(cur, cmd);
                else
                        cur.undispatched();
                break;
 
        case LFUN_MOUSE_RELEASE:
-               if (geometry() == NoButton 
-                       || (geometry() != ButtonOnly && !hitButton(cmd))) {
+               if (!hitButton(cmd)) {
                        // The mouse click has to be within the inset!
-                       InsetText::doDispatch(cur, cmd);
+                       if (geometry() != ButtonOnly)
+                               InsetText::doDispatch(cur, cmd);
+                       else
+                               cur.undispatched();                     
                        break;
                }
                if (cmd.button() != mouse_button::button1) {
-                       cur.dispatched();
+                       // Nothing to do.
+                       cur.noUpdate();
                        break;
                }
                // if we are selecting, we do not want to
index c447db086df4676e95bfab2bab6c750087b85c29..1ef00985b81d27b1ba497e8a6c3bc8d76f5a8f04 100644 (file)
@@ -68,7 +68,9 @@ public:
        void cursorPos(BufferView const & bv, CursorSlice const & sl,
        ///
        bool boundary, int & x, int & y) const;
-       ///
+       /// Returns true if (mouse) action is over the inset's button.
+       /// Always returns false when the inset does not have a
+       /// button.
        bool hitButton(FuncRequest const &) const;
        ///
        docstring const getNewLabel(docstring const & l) const;