int wxHeaderCtrl::GetColStart(unsigned int idx) const
{
- wxHeaderCtrl * const self = const_cast<wxHeaderCtrl *>(this);
-
int pos = m_scrollOffset;
for ( unsigned n = 0; ; n++ )
{
if ( i == idx )
break;
- const wxHeaderColumn& col = self->GetColumn(i);
+ const wxHeaderColumn& col = GetColumn(i);
if ( col.IsShown() )
pos += col.GetWidth();
}
{
int x = GetColStart(idx);
- return x + const_cast<wxHeaderCtrl *>(this)->GetColumn(idx).GetWidth();
+ return x + GetColumn(idx).GetWidth();
}
unsigned int wxHeaderCtrl::FindColumnAtPoint(int x, bool *onSeparator) const
{
- wxHeaderCtrl * const self = const_cast<wxHeaderCtrl *>(this);
-
int pos = 0;
const unsigned count = GetColumnCount();
for ( unsigned n = 0; n < count; n++ )
{
const unsigned idx = m_colIndices[n];
- const wxHeaderColumn& col = self->GetColumn(idx);
+ const wxHeaderColumn& col = GetColumn(idx);
if ( col.IsHidden() )
continue;
}
}
+ if ( onSeparator )
+ *onSeparator = false;
return COL_NONE;
}
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" );
ReleaseMouse();
- wxHeaderCtrlEvent event(wxEVT_COMMAND_HEADER_END_REORDER, GetId());
- event.SetEventObject(this);
- event.SetColumn(m_colBeingReordered);
+ const int colOld = m_colBeingReordered,
+ colNew = FindColumnAtPoint(xPhysical);
+
+ m_colBeingReordered = COL_NONE;
- const unsigned pos = GetColumnPos(FindColumnAtPoint(xPhysical));
- event.SetNewOrder(pos);
+ if ( xPhysical - GetColStart(colOld) == m_dragOffset )
+ return false;
- if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() )
+ 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;
}
// ----------------------------------------------------------------------------
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;
}