+
+WXHBRUSH wxToolBar::MSWGetToolbarBgBrush()
+{
+ // we conservatively use a solid brush here but we could also use a themed
+ // brush by using DrawThemeBackground() to create a bitmap brush (it'd need
+ // to be invalidated whenever the toolbar is resized and, also, correctly
+ // aligned using SetBrushOrgEx() before each use -- there is code for doing
+ // this in wxNotebook already so it'd need to be refactored into wxWindow)
+ //
+ // however inasmuch as there is a default background for the toolbar at all
+ // (and this is not a trivial question as different applications use very
+ // different colours), it seems to be a solid one and using REBAR
+ // background brush as we used to do before doesn't look good at all under
+ // Windows 7 (and probably Vista too), so for now we just keep it simple
+ wxColour const
+ colBg = m_hasBgCol ? GetBackgroundColour()
+ : wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
+ wxBrush * const
+ brush = wxTheBrushList->FindOrCreateBrush(colBg);
+
+ return brush ? static_cast<WXHBRUSH>(brush->GetResourceHandle()) : 0;
+}
+
+WXHBRUSH wxToolBar::MSWGetBgBrushForChild(WXHDC hDC, wxWindowMSW *child)
+{
+ WXHBRUSH hbr = wxToolBarBase::MSWGetBgBrushForChild(hDC, child);
+ if ( hbr )
+ return hbr;
+
+ // the base class version only returns a brush for erasing children
+ // background if we have a non-default background colour but as the toolbar
+ // doesn't erase its own background by default, we need to always do it for
+ // (semi-)transparent children
+ if ( child->GetParent() == this && child->HasTransparentBackground() )
+ return MSWGetToolbarBgBrush();
+
+ return 0;
+}
+
+void wxToolBar::MSWDoEraseBackground(WXHDC hDC)
+{
+ wxFillRect(GetHwnd(), (HDC)hDC, (HBRUSH)MSWGetToolbarBgBrush());
+}
+
+bool wxToolBar::MSWEraseBgHook(WXHDC hDC)
+{
+ // toolbar WM_PAINT handler offsets the DC origin before sending
+ // WM_ERASEBKGND to the parent but as we handle it in the toolbar itself,
+ // we need to reset it back
+ HDC hdc = (HDC)hDC;
+ POINT ptOldOrg;
+ if ( !::SetWindowOrgEx(hdc, 0, 0, &ptOldOrg) )
+ {
+ wxLogLastError(wxT("SetWindowOrgEx(tbar-bg-hdc)"));
+ return false;
+ }
+
+ MSWDoEraseBackground(hDC);
+
+ ::SetWindowOrgEx(hdc, ptOldOrg.x, ptOldOrg.y, NULL);
+
+ return true;
+}
+
+#endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK