From 1033a1636d00ed8709cce219323f33c7dfb4676c Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Mon, 20 Nov 2017 21:32:08 +0100 Subject: [PATCH] Process HDN_ITEMCHANGING notifications only when column is being resized When column resizing is finished, after HDN_ENDTRACK notification there is also sent one (and last) HDN_ITEMCHANGING notification. We have to skip it to prevent from sending EVT_HEADER_RESIZING after EVT_HEADER_END_RESIZE because EVT_HEADER_END_RESIZE should be really the last one event in the sequence of resizing events (like it's assumed in wxGrid). Closes #16390. --- include/wx/msw/headerctrl.h | 3 +++ src/msw/headerctrl.cpp | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/include/wx/msw/headerctrl.h b/include/wx/msw/headerctrl.h index 43c4da2de3..c261ee1ac7 100644 --- a/include/wx/msw/headerctrl.h +++ b/include/wx/msw/headerctrl.h @@ -139,6 +139,9 @@ private: // actual column we are dragging or -1 if not dragging anything int m_colBeingDragged; + // a column is currently being resized + bool m_isColBeingResized; + // the custom draw helper: initially NULL, created on demand, use // GetCustomDraw() to do it wxMSWHeaderCtrlCustomDraw *m_customDraw; diff --git a/src/msw/headerctrl.cpp b/src/msw/headerctrl.cpp index b03245ef5b..f8c04f94c5 100644 --- a/src/msw/headerctrl.cpp +++ b/src/msw/headerctrl.cpp @@ -95,6 +95,7 @@ void wxHeaderCtrl::Init() m_imageList = NULL; m_scrollOffset = 0; m_colBeingDragged = -1; + m_isColBeingResized = false; m_customDraw = NULL; } @@ -695,8 +696,9 @@ bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) break; } + m_isColBeingResized = true; evtType = wxEVT_HEADER_BEGIN_RESIZE; - // fall through + wxFALLTHROUGH; case HDN_ENDTRACKA: case HDN_ENDTRACKW: @@ -710,6 +712,8 @@ bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) const int minWidth = GetColumn(idx).GetMinWidth(); if ( width < minWidth ) width = minWidth; + + m_isColBeingResized = false; } break; @@ -719,7 +723,31 @@ bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) // 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) ) + // With "Show window contents while dragging" option enabled + // the sequence of notifications is as follows: + // HDN_BEGINTRACK + // HDN_ITEMCHANGING + // HDN_ITEMCHANGED + // ... + // HDN_ITEMCHANGING + // HDN_ITEMCHANGED + // HDN_ENDTRACK + // HDN_ITEMCHANGING + // HDN_ITEMCHANGED + // With "Show window contents while dragging" option disabled + // the sequence looks in turn like this: + // HDN_BEGINTRACK + // HDN_ITEMTRACK + // HDN_ITEMCHANGING + // ... + // HDN_ITEMTRACK + // HDN_ITEMCHANGING + // HDN_ENDTRACK + // HDN_ITEMCHANGING + // HDN_ITEMCHANGED + // In both cases last HDN_ITEMCHANGING notification is sent + // after HDN_ENDTRACK so we have to skip it. + if ( nmhdr->pitem && (nmhdr->pitem->mask & HDI_WIDTH) && m_isColBeingResized ) { // prevent the column from being shrunk beneath its min width width = nmhdr->pitem->cxy;