]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't generate drag events without valid item in wxGenericListCtrl.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 8 Jan 2012 14:52:51 +0000 (14:52 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 8 Jan 2012 14:52:51 +0000 (14:52 +0000)
Dragging the mouse from the empty area of the control must not generate any
drag events as there is nothing to drag there. Also, MSW version doesn't do
it.

So fix the generic version to avoid generating such invalid drag events too by
checking that we have a valid item before checking that we're dragging.

Closes #1619.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70296 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/generic/listctrl.cpp

index d66bb508bff1bb03b72bdd11e8547eb1e612dd6f..f95abdb06f02fd967c5860e19cb8dd21d1a34731 100644 (file)
@@ -2360,38 +2360,19 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
         }
     }
 
+    // Update drag events counter first as we must do it even if the mouse is
+    // not on any item right now as we must keep count in case we started
+    // dragging from the empty control area but continued to do it over a valid
+    // item -- in this situation we must not start dragging this item.
     if (event.Dragging())
-    {
-        if (m_dragCount == 0)
-        {
-            // we have to report the raw, physical coords as we want to be
-            // able to call HitTest(event.m_pointDrag) from the user code to
-            // get the item being dragged
-            m_dragStart = event.GetPosition();
-        }
-
         m_dragCount++;
-
-        if (m_dragCount != 3)
-            return;
-
-        int command = event.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
-                                          : wxEVT_COMMAND_LIST_BEGIN_DRAG;
-
-        wxListEvent le( command, GetParent()->GetId() );
-        le.SetEventObject( GetParent() );
-        le.m_item.m_itemId =
-        le.m_itemIndex = m_lineLastClicked;
-        le.m_pointDrag = m_dragStart;
-        GetParent()->GetEventHandler()->ProcessEvent( le );
-
-        return;
-    }
     else
-    {
         m_dragCount = 0;
-    }
 
+    // The only mouse event that can be generated without any valid item is
+    // wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK as it can be useful to have a global
+    // popup menu for the list control itself which should be shown even when
+    // the user clicks outside of any item.
     if ( !hitResult )
     {
         // outside of any item
@@ -2415,6 +2396,32 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
         return;
     }
 
+    if ( event.Dragging() )
+    {
+        if (m_dragCount == 1)
+        {
+            // we have to report the raw, physical coords as we want to be
+            // able to call HitTest(event.m_pointDrag) from the user code to
+            // get the item being dragged
+            m_dragStart = event.GetPosition();
+        }
+
+        if (m_dragCount != 3)
+            return;
+
+        int command = event.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
+                                          : wxEVT_COMMAND_LIST_BEGIN_DRAG;
+
+        wxListEvent le( command, GetParent()->GetId() );
+        le.SetEventObject( GetParent() );
+        le.m_item.m_itemId =
+        le.m_itemIndex = m_lineLastClicked;
+        le.m_pointDrag = m_dragStart;
+        GetParent()->GetEventHandler()->ProcessEvent( le );
+
+        return;
+    }
+
     bool forceClick = false;
     if (event.ButtonDClick())
     {