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
This commit is contained in:
Vadim Zeitlin
2008-12-14 23:12:30 +00:00
parent 2e733ec74c
commit 59704b49c2
2 changed files with 44 additions and 19 deletions

View File

@@ -127,7 +127,11 @@ private:
// same functions as above but for column moving/reordering instead of // same functions as above but for column moving/reordering instead of
// resizing // resizing
void StartReordering(unsigned int col, int xPhysical); 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 // constrain the given position to be larger than the start position of the
// given column plus its minimal width and return the effective width // given column plus its minimal width and return the effective width

View File

@@ -413,10 +413,12 @@ void wxHeaderCtrl::StartReordering(unsigned int col, int xPhysical)
SetCursor(wxCursor(wxCURSOR_HAND)); SetCursor(wxCursor(wxCURSOR_HAND));
CaptureMouse(); 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" ); wxASSERT_MSG( IsReordering(), "shouldn't be called if we're not reordering" );
@@ -424,9 +426,19 @@ void wxHeaderCtrl::EndReordering(int xPhysical)
ReleaseMouse(); ReleaseMouse();
const int colOld = m_colBeingReordered,
colNew = FindColumnAtPoint(xPhysical);
m_colBeingReordered = COL_NONE;
if ( xPhysical - GetColStart(colOld) == m_dragOffset )
return false;
if ( colNew != colOld )
{
wxHeaderCtrlEvent event(wxEVT_COMMAND_HEADER_END_REORDER, GetId()); wxHeaderCtrlEvent event(wxEVT_COMMAND_HEADER_END_REORDER, GetId());
event.SetEventObject(this); event.SetEventObject(this);
event.SetColumn(m_colBeingReordered); event.SetColumn(colOld);
const unsigned pos = GetColumnPos(FindColumnAtPoint(xPhysical)); const unsigned pos = GetColumnPos(FindColumnAtPoint(xPhysical));
event.SetNewOrder(pos); event.SetNewOrder(pos);
@@ -434,10 +446,13 @@ void wxHeaderCtrl::EndReordering(int xPhysical)
if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() ) if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() )
{ {
// do reorder the columns // do reorder the columns
DoMoveCol(m_colBeingReordered, pos); 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,14 +603,20 @@ void wxHeaderCtrl::OnMouse(wxMouseEvent& mevent)
if ( IsReordering() ) if ( IsReordering() )
{ {
if ( mevent.LeftUp() ) if ( !mevent.LeftUp() )
EndReordering(xPhysical); {
else // update the column position // update the column position
UpdateReorderingMarker(xPhysical); 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;
}
// find if the event is over a column at all // find if the event is over a column at all
bool onSeparator; bool onSeparator;