X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f69306fe61bfce53b6261f18967cceaefd919d90..4a2d030adfa836f6ada1830c9057170d053bcc64:/src/msw/headerctrl.cpp?ds=sidebyside diff --git a/src/msw/headerctrl.cpp b/src/msw/headerctrl.cpp index b68b51ee1a..1fdebf74d8 100644 --- a/src/msw/headerctrl.cpp +++ b/src/msw/headerctrl.cpp @@ -3,7 +3,6 @@ // Purpose: implementation of wxHeaderCtrl for wxMSW // Author: Vadim Zeitlin // Created: 2008-12-01 -// RCS-ID: $Id$ // Copyright: (c) 2008 Vadim Zeitlin // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -64,6 +63,7 @@ void wxHeaderCtrl::Init() m_numColumns = 0; m_imageList = NULL; m_scrollOffset = 0; + m_colBeingDragged = -1; } bool wxHeaderCtrl::Create(wxWindow *parent, @@ -474,18 +474,18 @@ wxEventType wxHeaderCtrl::GetClickEventType(bool dblclk, int button) switch ( button ) { case 0: - evtType = dblclk ? wxEVT_COMMAND_HEADER_DCLICK - : wxEVT_COMMAND_HEADER_CLICK; + evtType = dblclk ? wxEVT_HEADER_DCLICK + : wxEVT_HEADER_CLICK; break; case 1: - evtType = dblclk ? wxEVT_COMMAND_HEADER_RIGHT_DCLICK - : wxEVT_COMMAND_HEADER_RIGHT_CLICK; + evtType = dblclk ? wxEVT_HEADER_RIGHT_DCLICK + : wxEVT_HEADER_RIGHT_CLICK; break; case 2: - evtType = dblclk ? wxEVT_COMMAND_HEADER_MIDDLE_DCLICK - : wxEVT_COMMAND_HEADER_MIDDLE_CLICK; + evtType = dblclk ? wxEVT_HEADER_MIDDLE_DCLICK + : wxEVT_HEADER_MIDDLE_CLICK; break; default: @@ -525,6 +525,9 @@ bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) case HDN_ITEMCLICK: case HDN_ITEMDBLCLICK: evtType = GetClickEventType(code == HDN_ITEMDBLCLICK, nmhdr->iButton); + + // We're not dragging any more. + m_colBeingDragged = -1; break; // although we should get the notifications about the right clicks @@ -550,7 +553,7 @@ bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) break; case HDN_DIVIDERDBLCLICK: - evtType = wxEVT_COMMAND_HEADER_SEPARATOR_DCLICK; + evtType = wxEVT_HEADER_SEPARATOR_DCLICK; break; @@ -569,7 +572,7 @@ bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) break; } - evtType = wxEVT_COMMAND_HEADER_BEGIN_RESIZE; + evtType = wxEVT_HEADER_BEGIN_RESIZE; // fall through case HDN_ENDTRACKA: @@ -578,7 +581,7 @@ bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) if ( evtType == wxEVT_NULL ) { - evtType = wxEVT_COMMAND_HEADER_END_RESIZE; + evtType = wxEVT_HEADER_END_RESIZE; // don't generate events with invalid width const int minWidth = GetColumn(idx).GetMinWidth(); @@ -608,7 +611,7 @@ bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) // generate the resizing event from here as we don't seem // to be getting HDN_TRACK events at all, at least with // comctl32.dll v6 - evtType = wxEVT_COMMAND_HEADER_RESIZING; + evtType = wxEVT_HEADER_RESIZING; } } break; @@ -622,14 +625,24 @@ bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) if ( nmhdr->iItem == -1 ) break; + // If we are dragging a column that is not draggable and the mouse + // is moved over a different column then we get the column number from + // the column under the mouse. This results in an unexpected behaviour + // if this column is draggable. To prevent this remember the column we + // are dragging for the complete drag and drop cycle. + if ( m_colBeingDragged == -1 ) + { + m_colBeingDragged = idx; + } + // column must have the appropriate flag to be draggable - if ( !GetColumn(idx).IsReorderable() ) + if ( !GetColumn(m_colBeingDragged).IsReorderable() ) { veto = true; break; } - evtType = wxEVT_COMMAND_HEADER_BEGIN_REORDER; + evtType = wxEVT_HEADER_BEGIN_REORDER; break; case HDN_ENDDRAG: @@ -643,11 +656,17 @@ bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) order = MSWFromNativeOrder(order); - evtType = wxEVT_COMMAND_HEADER_END_REORDER; + evtType = wxEVT_HEADER_END_REORDER; + + // We (successfully) ended dragging the column. + m_colBeingDragged = -1; break; case NM_RELEASEDCAPTURE: - evtType = wxEVT_COMMAND_HEADER_DRAGGING_CANCELLED; + evtType = wxEVT_HEADER_DRAGGING_CANCELLED; + + // Dragging the column was cancelled. + m_colBeingDragged = -1; break; } @@ -672,7 +691,7 @@ bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) // special post-processing for HDN_ENDDRAG: we need to update the // internal column indices array if this is allowed to go ahead as // the native control is going to reorder its columns now - if ( evtType == wxEVT_COMMAND_HEADER_END_REORDER ) + if ( evtType == wxEVT_HEADER_END_REORDER ) MoveColumnInOrderArray(m_colIndices, idx, order); if ( processed )