+ // do default background painting
+ if ( !DoEraseBackground(GetHdcOf(*event.GetDC())) )
+ {
+ // let the system paint the background
+ event.Skip();
+ }
+}
+
+bool wxWindowMSW::DoEraseBackground(WXHDC hDC)
+{
+ HBRUSH hbr = (HBRUSH)MSWGetBgBrush(hDC);
+ if ( !hbr )
+ return false;
+
+ wxFillRect(GetHwnd(), (HDC)hDC, hbr);
+
+ return true;
+}
+
+WXHBRUSH
+wxWindowMSW::MSWGetBgBrushForChild(WXHDC WXUNUSED(hDC), WXHWND hWnd)
+{
+ if ( m_hasBgCol )
+ {
+ // our background colour applies to:
+ // 1. this window itself, always
+ // 2. all children unless the colour is "not inheritable"
+ // 3. even if it is not inheritable, our immediate transparent
+ // children should still inherit it -- but not any transparent
+ // children because it would look wrong if a child of non
+ // transparent child would show our bg colour when the child itself
+ // does not
+ wxWindow *win = wxFindWinFromHandle(hWnd);
+ if ( win == this ||
+ m_inheritBgCol ||
+ (win && win->HasTransparentBackground() &&
+ win->GetParent() == this) )
+ {
+ // draw children with the same colour as the parent
+ wxBrush *
+ brush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour());
+
+ return (WXHBRUSH)GetHbrushOf(*brush);
+ }
+ }
+
+ return 0;
+}
+
+WXHBRUSH wxWindowMSW::MSWGetBgBrush(WXHDC hDC, WXHWND hWndToPaint)
+{
+ if ( !hWndToPaint )
+ hWndToPaint = GetHWND();
+
+ for ( wxWindowMSW *win = this; win; win = win->GetParent() )
+ {
+ WXHBRUSH hBrush = win->MSWGetBgBrushForChild(hDC, hWndToPaint);
+ if ( hBrush )
+ return hBrush;
+
+ // background is not inherited beyond top level windows
+ if ( win->IsTopLevel() )
+ break;
+ }
+
+ return 0;
+}
+
+bool wxWindowMSW::HandlePrintClient(WXHDC hDC)
+{
+ // we receive this message when DrawThemeParentBackground() is
+ // called from def window proc of several controls under XP and we
+ // must draw properly themed background here
+ //
+ // note that naively I'd expect filling the client rect with the
+ // brush returned by MSWGetBgBrush() work -- but for some reason it
+ // doesn't and we have to call parents MSWPrintChild() which is
+ // supposed to call DrawThemeBackground() with appropriate params
+ //
+ // also note that in this case lParam == PRF_CLIENT but we're
+ // clearly expected to paint the background and nothing else!
+ for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
+ {
+ if ( win->MSWPrintChild(hDC, (wxWindow *)this) )
+ return true;
+
+ if ( win->IsTopLevel() || win->InheritsBackgroundColour() )
+ break;
+ }
+
+ return false;