+#if wxUSE_UXTHEME
+
+void wxNotebook::UpdateBgBrush()
+{
+ if ( m_hbrBackground )
+ ::DeleteObject((HBRUSH)m_hbrBackground);
+
+ if ( wxUxThemeEngine::GetIfActive() )
+ {
+ RECT rc;
+ GetWindowRect(GetHwnd(), &rc);
+
+ WindowHDC hDC(GetHwnd());
+ MemoryHDC hDCMem(hDC);
+ CompatibleBitmap hBmp(hDC, rc.right - rc.left, rc.bottom - rc.top);
+
+ SelectInHDC selectBmp(hDCMem, hBmp);
+
+ SendMessage(GetHwnd(), WM_PRINTCLIENT, (WPARAM)(HDC)hDCMem,
+ PRF_ERASEBKGND | PRF_CLIENT | PRF_NONCLIENT);
+
+ m_hbrBackground = (WXHBRUSH)::CreatePatternBrush(hBmp);
+ }
+ else // no themes
+ {
+ m_hbrBackground = NULL;
+ }
+}
+
+WXHBRUSH wxNotebook::GetThemeBackgroundBrush(WXHDC hDC, wxWindow *win) const
+{
+ if ( m_hbrBackground )
+ {
+ // before drawing with the background brush, we need to position it
+ // correctly
+ RECT rc;
+ ::GetWindowRect(GetHwndOf(win), &rc);
+
+ ::MapWindowPoints(NULL, GetHwnd(), (POINT *)&rc, 1);
+
+ if ( !::SetBrushOrgEx((HDC)hDC, -rc.left, -rc.top, NULL) )
+ {
+ wxLogLastError(_T("SetBrushOrgEx(notebook bg brush)"));
+ }
+ }
+
+ return m_hbrBackground;
+}
+
+void wxNotebook::DoEraseBackground(wxEraseEvent& event)
+{
+ DoEraseBackground((wxWindow *)event.GetEventObject(),
+ (WXHDC)GetHdcOf(*event.GetDC()));
+}
+
+void wxNotebook::DoEraseBackground(wxWindow *win, WXHDC hDC)
+{
+ // we can either draw the background ourselves or let DrawThemeBackground()
+ // do it, but as we already have the correct brush, let's do it ourselves
+ // (note that we use the same code in wxControl::MSWControlColor(), so if
+ // it breaks, it should at least break in consistent way)
+ WXHBRUSH hbr = GetThemeBackgroundBrush(hDC, win);
+ if ( hbr )
+ {
+ RECT rectClient;
+ ::GetClientRect(GetHwndOf(win), &rectClient);
+ ::FillRect((HDC)hDC, &rectClient, (HBRUSH)hbr);
+ }
+}
+
+#endif // wxUSE_UXTHEME
+