From 59704b49c212e24f0292b6d1470fc1cd9d4afd3e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 14 Dec 2008 23:12:30 +0000 Subject: [PATCH] don't mistake a simple click on a column for a reordering drag git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57344 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/headerctrlg.h | 6 +++- src/generic/headerctrlg.cpp | 51 ++++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/include/wx/generic/headerctrlg.h b/include/wx/generic/headerctrlg.h index 3550f179ca..28a73c24b0 100644 --- a/include/wx/generic/headerctrlg.h +++ b/include/wx/generic/headerctrlg.h @@ -127,7 +127,11 @@ private: // same functions as above but for column moving/reordering instead of // resizing void StartReordering(unsigned int col, int xPhysical); - void EndReordering(int xPhysical); + + // returns true if we did drag the column somewhere else or false if we + // didn't really move it -- in this case we consider that no reordering + // took place and that a normal column click event should be generated + bool EndReordering(int xPhysical); // constrain the given position to be larger than the start position of the // given column plus its minimal width and return the effective width diff --git a/src/generic/headerctrlg.cpp b/src/generic/headerctrlg.cpp index 5d040b69d9..4bac640faa 100644 --- a/src/generic/headerctrlg.cpp +++ b/src/generic/headerctrlg.cpp @@ -413,10 +413,12 @@ void wxHeaderCtrl::StartReordering(unsigned int col, int xPhysical) SetCursor(wxCursor(wxCURSOR_HAND)); CaptureMouse(); - UpdateReorderingMarker(xPhysical); + // do not call UpdateReorderingMarker() here: we don't want to give + // feedback for reordering until the user starts to really move the mouse + // as he might want to just click on the column and not move it at all } -void wxHeaderCtrl::EndReordering(int xPhysical) +bool wxHeaderCtrl::EndReordering(int xPhysical) { wxASSERT_MSG( IsReordering(), "shouldn't be called if we're not reordering" ); @@ -424,20 +426,33 @@ void wxHeaderCtrl::EndReordering(int xPhysical) ReleaseMouse(); - wxHeaderCtrlEvent event(wxEVT_COMMAND_HEADER_END_REORDER, GetId()); - event.SetEventObject(this); - event.SetColumn(m_colBeingReordered); + const int colOld = m_colBeingReordered, + colNew = FindColumnAtPoint(xPhysical); - const unsigned pos = GetColumnPos(FindColumnAtPoint(xPhysical)); - event.SetNewOrder(pos); + m_colBeingReordered = COL_NONE; - if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() ) + if ( xPhysical - GetColStart(colOld) == m_dragOffset ) + return false; + + if ( colNew != colOld ) { - // do reorder the columns - DoMoveCol(m_colBeingReordered, pos); + wxHeaderCtrlEvent event(wxEVT_COMMAND_HEADER_END_REORDER, GetId()); + event.SetEventObject(this); + event.SetColumn(colOld); + + const unsigned pos = GetColumnPos(FindColumnAtPoint(xPhysical)); + event.SetNewOrder(pos); + + if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() ) + { + // do reorder the columns + DoMoveCol(colOld, pos); + } } - m_colBeingReordered = COL_NONE; + // whether we moved the column or not, the user did move the mouse and so + // did try to do it so return true + return true; } // ---------------------------------------------------------------------------- @@ -588,12 +603,18 @@ void wxHeaderCtrl::OnMouse(wxMouseEvent& mevent) if ( IsReordering() ) { - if ( mevent.LeftUp() ) - EndReordering(xPhysical); - else // update the column position + if ( !mevent.LeftUp() ) + { + // update the column position UpdateReorderingMarker(xPhysical); - return; + return; + } + + // finish reordering and continue to generate a click event below if we + // didn't really reorder anything + if ( EndReordering(xPhysical) ) + return; } -- 2.45.2