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
This commit is contained in:
Vadim Zeitlin 2014-08-03 12:47:26 +00:00
parent b932b899af
commit f88585b4ab
3 changed files with 28 additions and 0 deletions

View File

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

View File

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

View File

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