+#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);
+
+
+ // apparently DrawThemeBackground() modifies the rect passed to it and if we
+ // don't do these adjustments, there are some drawing artifacts which are
+ // only visible with some non default themes; so modify the rect here using
+ // the magic numbers below so that it still paints the correct area
+ rc.left -= 2;
+ rc.top -= 2;
+ rc.right += 4;
+ rc.bottom += 5;
+
+
+ wxUxThemeEngine::Get()->DrawThemeBackground
+ (
+ theme,
+ 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();
+}
+