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