comctl32/listview: fix mouse message sequences

Daniel Jelinski djelinski1 at gmail.com
Sat Feb 23 15:33:07 CST 2013


-------------- next part --------------
From c58f4db0d3459e885e1c2f97643bc90edf694318 Mon Sep 17 00:00:00 2001
From: Daniel Jelinski <djelinski1 at gmail.com>
Date: Thu, 27 Sep 2012 21:04:46 +0200
Subject: [PATCH 2/2] comctl32/listview: fix mouse message sequences

fixes bug 23774 and part of bug 9932 - allows selecting items in delphi listviews with DragMode = dmAutomatic.
Fixes two message sequences - when clicking on an item and when clicking between items.
Still left to fix: marquee selection should also be done in LButtonDown.
Not sure if any apps depend on this though.
---
 dlls/comctl32/listview.c |   76 +++++++++++++++++++++-------------------------
 1 files changed, 35 insertions(+), 41 deletions(-)

diff --git a/dlls/comctl32/listview.c b/dlls/comctl32/listview.c
index a22b2da..9014640 100644
--- a/dlls/comctl32/listview.c
+++ b/dlls/comctl32/listview.c
@@ -463,6 +463,7 @@ static HIMAGELIST LISTVIEW_SetImageList(LISTVIEW_INFO *, INT, HIMAGELIST);
 static INT LISTVIEW_HitTest(const LISTVIEW_INFO *, LPLVHITTESTINFO, BOOL, BOOL);
 static BOOL LISTVIEW_EndEditLabelT(LISTVIEW_INFO *, BOOL, BOOL);
 static BOOL LISTVIEW_Scroll(LISTVIEW_INFO *, INT, INT);
+static LRESULT LISTVIEW_LButtonUp(LISTVIEW_INFO *infoPtr, WORD wKey, INT x, INT y);
 
 /******** Text handling functions *************************************/
 
@@ -4081,46 +4082,6 @@ static LRESULT LISTVIEW_MouseMove(LISTVIEW_INFO *infoPtr, WORD fwKeys, INT x, IN
                 infoPtr->nLButtonDownItem = -1;
             }
 
-            if (!infoPtr->bDragging)
-            {
-                ht.pt = infoPtr->ptClickPos;
-                LISTVIEW_HitTest(infoPtr, &ht, TRUE, TRUE);
-
-                /* If the click is outside the range of an item, begin a
-                   highlight. If not, begin an item drag. */
-                if (ht.iItem == -1)
-                {
-                    NMHDR hdr;
-
-                    /* If we're allowing multiple selections, send notification.
-                       If return value is non-zero, cancel. */
-                    if (!(infoPtr->dwStyle & LVS_SINGLESEL) && (notify_hdr(infoPtr, LVN_MARQUEEBEGIN, &hdr) == 0))
-                    {
-                        /* Store the absolute coordinates of the click */
-                        POINT offset;
-                        LISTVIEW_GetOrigin(infoPtr, &offset);
-
-                        infoPtr->marqueeOrigin.x = infoPtr->ptClickPos.x - offset.x;
-                        infoPtr->marqueeOrigin.y = infoPtr->ptClickPos.y - offset.y;
-
-                        /* Begin selection and capture mouse */
-                        infoPtr->bMarqueeSelect = TRUE;
-                        SetCapture(infoPtr->hwndSelf);
-                    }
-                }
-                else
-                {
-                    NMLISTVIEW nmlv;
-
-                    ZeroMemory(&nmlv, sizeof(nmlv));
-                    nmlv.iItem = ht.iItem;
-                    nmlv.ptAction = infoPtr->ptClickPos;
-
-                    notify_listview(infoPtr, LVN_BEGINDRAG, &nmlv);
-                    infoPtr->bDragging = TRUE;
-                }
-            }
-
             return 0;
         }
     }
@@ -10178,6 +10139,19 @@ static LRESULT LISTVIEW_LButtonDown(LISTVIEW_INFO *infoPtr, WORD wKey, INT x, IN
 
     if (infoPtr->dwLvExStyle & LVS_EX_ONECLICKACTIVATE)
         if(lvHitTestInfo.iItem != -1) notify_itemactivate(infoPtr,&lvHitTestInfo);
+    if (LISTVIEW_TrackMouse(infoPtr, pt))
+    {
+        NMLISTVIEW nmlv;
+
+        ZeroMemory(&nmlv, sizeof(nmlv));
+        nmlv.iItem = lvHitTestInfo.iItem;
+        nmlv.ptAction = infoPtr->ptClickPos;
+
+        notify_listview(infoPtr, LVN_BEGINDRAG, &nmlv);
+        infoPtr->bDragging = TRUE;
+    }
+    else
+        LISTVIEW_LButtonUp(infoPtr,0,x,y);
   }
   else
   {
@@ -10187,7 +10161,27 @@ static LRESULT LISTVIEW_LButtonDown(LISTVIEW_INFO *infoPtr, WORD wKey, INT x, IN
     /* remove all selections */
     if (!(wKey & MK_CONTROL) && !(wKey & MK_SHIFT))
         LISTVIEW_DeselectAll(infoPtr);
-    ReleaseCapture();
+    if (!(infoPtr->dwStyle & LVS_SINGLESEL) && LISTVIEW_TrackMouse(infoPtr, pt))
+    {
+        NMHDR hdr;
+        /* If we're allowing multiple selections, send notification.
+           If return value is non-zero, cancel. */
+        if (notify_hdr(infoPtr, LVN_MARQUEEBEGIN, &hdr) == 0)
+        {
+            /* Store the absolute coordinates of the click */
+            POINT offset;
+            LISTVIEW_GetOrigin(infoPtr, &offset);
+
+            infoPtr->marqueeOrigin.x = infoPtr->ptClickPos.x - offset.x;
+            infoPtr->marqueeOrigin.y = infoPtr->ptClickPos.y - offset.y;
+
+            /* Begin selection and capture mouse */
+            infoPtr->bMarqueeSelect = TRUE;
+            SetCapture(infoPtr->hwndSelf);
+        }
+    }
+    else
+        LISTVIEW_LButtonUp(infoPtr,0,x,y);
   }
   
   return 0;
-- 
1.7.5.4


More information about the wine-patches mailing list