+#if wxUSE_UXTHEME
+
+WXHANDLE wxNotebook::QueryBgBitmap(wxWindow *win)
+{
+ 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);
+
+ if ( win )
+ {
+ RECT rc2;
+ ::GetWindowRect(GetHwndOf(win), &rc2);
+
+ COLORREF c = ::GetPixel(hDCMem, rc2.left - rc.left, rc2.top - rc.top);
+
+ return (WXHANDLE)c;
+ }
+ //else: we are asked to create the brush
+
+ return (WXHANDLE)::CreatePatternBrush(hBmp);
+}
+
+void wxNotebook::UpdateBgBrush()
+{
+ if ( m_hbrBackground )
+ ::DeleteObject((HBRUSH)m_hbrBackground);
+
+ if ( !m_hasBgCol && wxUxThemeEngine::GetIfActive() )
+ {
+ m_hbrBackground = (WXHBRUSH)QueryBgBitmap();
+ }
+ else // no themes
+ {
+ m_hbrBackground = NULL;
+ }
+}
+
+WXHBRUSH wxNotebook::MSWGetBgBrushForChild(WXHDC hDC, wxWindow *win)
+{
+ 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;
+ }
+
+ return wxNotebookBase::MSWGetBgBrushForChild(hDC, win);
+}
+
+wxColour wxNotebook::MSWGetBgColourForChild(wxWindow *win)
+{
+ if ( m_hasBgCol )
+ return GetBackgroundColour();
+
+ if ( !wxUxThemeEngine::GetIfActive() )
+ return wxNullColour;
+
+ COLORREF c = (COLORREF)QueryBgBitmap(win);
+
+ return c == CLR_INVALID ? wxNullColour : wxRGBToColour(c);
+}
+
+bool
+wxNotebook::MSWPrintChild(wxWindow *win,
+ WXWPARAM wParam,
+ WXLPARAM WXUNUSED(lParam))
+{
+ RECT rc;
+ ::GetClientRect(GetHwnd(), &rc);
+ TabCtrl_AdjustRect(GetHwnd(), true, &rc);
+ ::MapWindowPoints(GetHwnd(), GetHwndOf(win), (POINT *)&rc, 2);
+
+ wxUxThemeHandle theme(win, L"TAB");
+ if ( theme )
+ {
+ wxUxThemeEngine::Get()->DrawThemeBackground
+ (
+ theme,
+ (WXHDC)wParam,
+ 9 /* TABP_PANE */,
+ 0,
+ &rc,
+ NULL
+ );
+ }
+
+ return true;
+}
+
+#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);
+ }
+
+ wxColour colour(GetRValue(themeColor), GetGValue(themeColor), GetBValue(themeColor));
+ return colour;
+ }
+ }
+#endif // wxUSE_UXTHEME
+
+ return GetBackgroundColour();
+}
+