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.
This commit is contained in:
Artur Wieczorek 2017-05-18 23:55:02 +02:00
parent a647b6da72
commit 3eb650972a
2 changed files with 17 additions and 3 deletions

View File

@ -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
////////////////////////////////////////////////////////////////////////////

View File

@ -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