X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5c858faa15b8bda0ce5d7e9a334da6c17c9c3b70..12bb29f5432174ecbd65549bda832d70d34a98ae:/src/msw/headerctrl.cpp diff --git a/src/msw/headerctrl.cpp b/src/msw/headerctrl.cpp index 4983a1dcf4..4845715d03 100644 --- a/src/msw/headerctrl.cpp +++ b/src/msw/headerctrl.cpp @@ -64,6 +64,7 @@ void wxHeaderCtrl::Init() m_numColumns = 0; m_imageList = NULL; m_scrollOffset = 0; + m_colBeingDragged = -1; } bool wxHeaderCtrl::Create(wxWindow *parent, @@ -268,7 +269,7 @@ void wxHeaderCtrl::DoInsertItem(const wxHeaderColumn& col, unsigned int idx) // notice that we need to store the string we use the pointer to until we // pass it to the control hdi.mask |= HDI_TEXT; - wxWxCharBuffer buf = col.GetTitle().wx_str(); + wxWxCharBuffer buf = col.GetTitle().t_str(); hdi.pszText = buf.data(); hdi.cchTextMax = wxStrlen(buf); @@ -474,18 +475,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 +526,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 +554,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; @@ -561,7 +565,7 @@ bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) // ASCII and Unicode versions of this message case HDN_BEGINTRACKA: case HDN_BEGINTRACKW: - // non-resizeable columns can't be resized no matter what, don't + // non-resizable columns can't be resized no matter what, don't // even generate any events for them if ( !GetColumn(idx).IsResizeable() ) { @@ -569,7 +573,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 +582,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(); @@ -587,6 +591,11 @@ bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) } break; + // The control is not supposed to send HDN_TRACK when using + // HDS_FULLDRAG (which we do use) but apparently some versions of + // comctl32.dll still do it, see #13506, so catch both messages + // just in case we are dealing with one of these buggy versions. + case HDN_TRACK: case HDN_ITEMCHANGING: if ( nmhdr->pitem && (nmhdr->pitem->mask & HDI_WIDTH) ) { @@ -603,7 +612,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; @@ -617,14 +626,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: @@ -638,11 +657,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; } @@ -657,22 +682,24 @@ bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) if ( order != -1 ) event.SetNewOrder(order); - if ( GetEventHandler()->ProcessEvent(event) ) - { - if ( event.IsAllowed() ) - return true; // skip default message handling below + const bool processed = GetEventHandler()->ProcessEvent(event); - // we need to veto the default handling of this message, don't - // return to execute the code in the "if veto" branch below + if ( processed && !event.IsAllowed() ) veto = true; - } - else // not processed + + if ( !veto ) { // 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 ) + { + // skip default processing below + return true; + } } }