From f88585b4ab538dc638094aa4ba04bda848add9fa Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 3 Aug 2014 12:47:26 +0000 Subject: [PATCH] Update wxSlider background when its parent background changes in wxMSW. The native control doesn't redraw itself, so force it to do it from the overridden DoMSWControlColor() which is called every time the background colour might have changed. See #12271. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76985 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/msw/slider.h | 6 ++++++ src/msw/slider.cpp | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index 0e5aade106..0ec75366c8 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -87,6 +87,7 @@ wxMSW: - Keep menu item icon after removing and adding it back (Artur Wieczorek). - Add wxThread::MSWGetHandle() (troelsk). - Allow using sizers for laying out wxMDIClientWindow (Artur Wieczorek). +- Fix updating wxSlider background when its parent background changes. wxOSX/Cocoa: diff --git a/include/wx/msw/slider.h b/include/wx/msw/slider.h index a16c5952e0..b210d1acf1 100644 --- a/include/wx/msw/slider.h +++ b/include/wx/msw/slider.h @@ -118,9 +118,15 @@ protected: virtual void DoMoveWindow(int x, int y, int width, int height); virtual wxSize DoGetBestSize() const; + WXHBRUSH DoMSWControlColor(WXHDC pDC, wxColour colBg, WXHWND hWnd) wxOVERRIDE; + + // the labels windows, if any wxSubwindows *m_labels; + // Last background brush we returned from DoMSWControlColor(), see there. + WXHBRUSH m_hBrushBg; + int m_rangeMin; int m_rangeMax; int m_pageSize; diff --git a/src/msw/slider.cpp b/src/msw/slider.cpp index 992497c498..c59c668a3d 100644 --- a/src/msw/slider.cpp +++ b/src/msw/slider.cpp @@ -74,6 +74,8 @@ void wxSlider::Init() { m_labels = NULL; + m_hBrushBg = NULL; + m_pageSize = 1; m_lineSize = 1; m_rangeMax = 0; @@ -567,6 +569,25 @@ wxSize wxSlider::DoGetBestSize() const return size; } +WXHBRUSH wxSlider::DoMSWControlColor(WXHDC pDC, wxColour colBg, WXHWND hWnd) +{ + const WXHBRUSH hBrush = wxSliderBase::DoMSWControlColor(pDC, colBg, hWnd); + + // The native control doesn't repaint itself when it's invalidated, so we + // do it explicitly from here, as this is the only way to propagate the + // parent background colour to the slider when it changes. + if ( hWnd == GetHwnd() && hBrush != m_hBrushBg ) + { + m_hBrushBg = hBrush; + + // Anything really refreshing the slider would work here, we use a + // dummy WM_ENABLE but using TBM_SETPOS would work too, for example. + ::PostMessage(hWnd, WM_ENABLE, (BOOL)IsEnabled(), 0); + } + + return hBrush; +} + // ---------------------------------------------------------------------------- // slider-specific methods // ----------------------------------------------------------------------------