From: Vadim Zeitlin Date: Sun, 8 Jan 2012 14:52:51 +0000 (+0000) Subject: Don't generate drag events without valid item in wxGenericListCtrl. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/becc95d84b957a9e32305a92e4253a623ba53983 Don't generate drag events without valid item in wxGenericListCtrl. 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 --- diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index d66bb508bf..f95abdb06f 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -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()) {