From 3eb650972acda88b8ada420903432f84b73e95a7 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Thu, 18 May 2017 23:55:02 +0200 Subject: [PATCH] Fix setting style flags in wxListCtrl (wxMSW) UpdateStyle() function was introduced in edccf428 to synchronize in SetWindowStyleFlag() style of the control with new style flags just stored in m_windowStyle. In 9a8d75f1, storing directly a new flags in m_windowStyle was replaced by the call to parent's SetWindowStyleFlag(). Because call to parent's SetWindowStyleFlag() updates both m_windowStyle and actual style of the control for common flags (WS_*, LVS_* flags), synchronizing the control again with UpdateStyles() is pointless (since this function does nothing in this context). Only wxSCROLL style flags need special care because wxListCtrl doesn't have these styles but the control itself may have them. In order to preserve them in the call to SetWindowStyleFlag(), we can do the trick and request the same new scroll style as the actual physical style. UpdateStyles() is useless now and can be deprecated. See #17059. --- include/wx/msw/listctrl.h | 3 +++ src/msw/listctrl.cpp | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/wx/msw/listctrl.h b/include/wx/msw/listctrl.h index 2a7286bdfb..c8b833419c 100644 --- a/include/wx/msw/listctrl.h +++ b/include/wx/msw/listctrl.h @@ -346,8 +346,11 @@ public: virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) wxOVERRIDE; virtual bool MSWShouldPreProcessMessage(WXMSG* msg) wxOVERRIDE; +#if WXWIN_COMPATIBILITY_3_0 // bring the control in sync with current m_windowStyle value + wxDEPRECATED_MSG("useless and will be removed in the future, use SetWindowStyleFlag() instead") void UpdateStyle(); +#endif // WXWIN_COMPATIBILITY_3_0 // Event handlers //////////////////////////////////////////////////////////////////////////// diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index a263a8e152..ad7db78eba 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -403,6 +403,8 @@ WXDWORD wxListCtrl::MSWGetStyle(long style, WXDWORD *exstyle) const return wstyle; } +#if WXWIN_COMPATIBILITY_3_0 +// Deprecated void wxListCtrl::UpdateStyle() { if ( GetHwnd() ) @@ -428,11 +430,12 @@ void wxListCtrl::UpdateStyle() // if we switched to the report view, set the extended styles for // it too - if ( !(dwStyleOld & LVS_REPORT) && (dwStyleNew & LVS_REPORT) ) + if ( (dwStyleOld & LVS_TYPEMASK) != LVS_REPORT && (dwStyleNew & LVS_TYPEMASK) == LVS_REPORT ) MSWSetExListStyles(); } } } +#endif // WXWIN_COMPATIBILITY_3_0 void wxListCtrl::FreeAllInternalData() { @@ -504,9 +507,17 @@ void wxListCtrl::SetWindowStyleFlag(long flag) { const bool wasInReportView = InReportView(); + // we don't have wxVSCROLL style, but the list control may have it, + // don't change it then in the call to parent's SetWindowStyleFlags() + DWORD dwStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE); + flag &= ~(wxHSCROLL | wxVSCROLL); + if ( dwStyle & WS_HSCROLL ) + flag |= wxHSCROLL; + if ( dwStyle & WS_VSCROLL ) + flag |= wxVSCROLL; wxListCtrlBase::SetWindowStyleFlag(flag); - - UpdateStyle(); + // As it was said, we don't have wxSCROLL style + m_windowStyle &= ~(wxHSCROLL | wxVSCROLL); // if we switched to the report view, set the extended styles for // it too