+#if wxUSE_UXTHEME
+
+bool wxNotebook::DoDrawBackground(WXHDC hDC, wxWindow *child)
+{
+    wxUxThemeHandle theme(child ? child : this, L"TAB");
+    if ( !theme )
+        return false;
+
+    // get the notebook client rect (we're not interested in drawing tabs
+    // themselves)
+    wxRect r = GetPageSize();
+    if ( r.IsEmpty() )
+        return false;
+
+    RECT rc;
+    wxCopyRectToRECT(r, rc);
+
+    // map rect to the coords of the window we're drawing in
+    if ( child )
+        ::MapWindowPoints(GetHwnd(), GetHwndOf(child), (POINT *)&rc, 2);
+
+    // we have the content area (page size), but we need to draw all of the
+    // background for it to be aligned correctly
+    wxUxThemeEngine::Get()->GetThemeBackgroundExtent
+                            (
+                                theme,
+                                (HDC) hDC,
+                                9 /* TABP_PANE */,
+                                0,
+                                &rc,
+                                &rc
+                            );
+    wxUxThemeEngine::Get()->DrawThemeBackground
+                            (
+                                theme,
+                                (HDC) hDC,
+                                9 /* TABP_PANE */,
+                                0,
+                                &rc,
+                                NULL
+                            );
+
+    return true;
+}
+
+WXHBRUSH wxNotebook::QueryBgBitmap()
+{
+    wxRect r = GetPageSize();
+    if ( r.IsEmpty() )
+        return 0;
+
+    WindowHDC hDC(GetHwnd());
+    MemoryHDC hDCMem(hDC);
+    CompatibleBitmap hBmp(hDC, r.x + r.width, r.y + r.height);
+
+    SelectInHDC selectBmp(hDCMem, hBmp);
+
+    if ( !DoDrawBackground((WXHDC)(HDC)hDCMem) )
+        return 0;
+
+    return (WXHBRUSH)::CreatePatternBrush(hBmp);
+}
+
+void wxNotebook::UpdateBgBrush()
+{
+    if ( m_hbrBackground )
+        ::DeleteObject((HBRUSH)m_hbrBackground);
+
+    if ( !m_hasBgCol && wxUxThemeEngine::GetIfActive() )
+    {
+        m_hbrBackground = QueryBgBitmap();
+    }
+    else // no themes or we've got user-defined solid colour
+    {
+        m_hbrBackground = NULL;
+    }
+}
+
+WXHBRUSH wxNotebook::MSWGetBgBrushForChild(WXHDC hDC, WXHWND hWnd)
+{
+    if ( m_hbrBackground )
+    {
+        // before drawing with the background brush, we need to position it
+        // correctly
+        RECT rc;
+        ::GetWindowRect((HWND)hWnd, &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;
+    }
+
+    return wxNotebookBase::MSWGetBgBrushForChild(hDC, hWnd);
+}
+
+bool wxNotebook::MSWPrintChild(WXHDC hDC, wxWindow *child)
+{
+    // solid background colour overrides themed background drawing
+    if ( !UseBgCol() && DoDrawBackground(hDC, child) )
+        return true;
+
+    // If we're using a solid colour (for example if we've switched off
+    // theming for this notebook), paint it
+    if (UseBgCol())
+    {
+        wxRect r = GetPageSize();
+        if ( r.IsEmpty() )
+            return false;
+
+        RECT rc;
+        wxCopyRectToRECT(r, rc);
+
+        // map rect to the coords of the window we're drawing in
+        if ( child )
+            ::MapWindowPoints(GetHwnd(), GetHwndOf(child), (POINT *)&rc, 2);
+
+        wxBrush brush(GetBackgroundColour());
+        HBRUSH hbr = GetHbrushOf(brush);
+
+        ::FillRect((HDC) hDC, &rc, hbr);
+
+        return true;
+    }
+
+    return wxNotebookBase::MSWPrintChild(hDC, child);
+}
+
+#endif // wxUSE_UXTHEME
+
+// Windows only: attempts to get colour for UX theme page background
+wxColour wxNotebook::GetThemeBackgroundColour() const
+{
+#if wxUSE_UXTHEME
+    if (wxUxThemeEngine::Get())
+    {
+        wxUxThemeHandle hTheme((wxNotebook*) this, L"TAB");
+        if (hTheme)
+        {
+            // This is total guesswork.
+            // See PlatformSDK\Include\Tmschema.h for values
+            COLORREF themeColor;
+            wxUxThemeEngine::Get()->GetThemeColor(
+                                        hTheme,
+                                        10 /* TABP_BODY */,
+                                        1 /* NORMAL */,
+                                        3821 /* FILLCOLORHINT */,
+                                        &themeColor);
+
+            /*
+            [DS] Workaround for WindowBlinds:
+            Some themes return a near black theme color using FILLCOLORHINT,
+            this makes notebook pages have an ugly black background and makes
+            text (usually black) unreadable. Retry again with FILLCOLOR.
+
+            This workaround potentially breaks appearance of some themes,
+            but in practice it already fixes some themes.
+            */
+            if (themeColor == 1)
+            {
+                wxUxThemeEngine::Get()->GetThemeColor(
+                                            hTheme,
+                                            10 /* TABP_BODY */,
+                                            1 /* NORMAL */,
+                                            3802 /* FILLCOLOR */,
+                                            &themeColor);
+            }
+
+            return wxRGBToColour(themeColor);
+        }
+    }
+#endif // wxUSE_UXTHEME
+
+    return GetBackgroundColour();
+}
+