Author: gadamopoulos
Date: Wed Apr 26 09:28:35 2017
New Revision: 74407
URL: 
http://svn.reactos.org/svn/reactos?rev=74407&view=rev
Log:
[UXTHEME] -Implement the tab background texture. NOTE: A hack was used to go around the
problem that SetBrushOrgEx doesn't really work. CORE-12978
Modified:
    trunk/reactos/dll/win32/uxtheme/draw.c
    trunk/reactos/dll/win32/uxtheme/themehooks.c
    trunk/reactos/dll/win32/uxtheme/uxthemep.h
Modified: trunk/reactos/dll/win32/uxtheme/draw.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/uxtheme/draw.c?r…
==============================================================================
--- trunk/reactos/dll/win32/uxtheme/draw.c      [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/uxtheme/draw.c      [iso-8859-1] Wed Apr 26 09:28:35 2017
@@ -61,7 +61,7 @@
     dwDialogTextureFlags = HandleToUlong( GetPropW( hwnd,
(LPCWSTR)MAKEINTATOM(atDialogThemeEnabled) ));
     if (dwDialogTextureFlags == 0)
         /* Means EnableThemeDialogTexture wasn't called for this dialog */
-        return TRUE;
+        return FALSE;
     return (dwDialogTextureFlags & ETDT_ENABLE) && !(dwDialogTextureFlags
& ETDT_DISABLE);
 }
@@ -224,7 +224,7 @@
  *
  * Load image for part/state
  */
-static HRESULT UXTHEME_LoadImage(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const
RECT *pRect, BOOL glyph,
+HRESULT UXTHEME_LoadImage(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT
*pRect, BOOL glyph,
                           HBITMAP *hBmp, RECT *bmpRect, BOOL* hasImageAlpha)
 {
     int imagelayout = IL_HORIZONTAL;
Modified: trunk/reactos/dll/win32/uxtheme/themehooks.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/uxtheme/themehoo…
==============================================================================
--- trunk/reactos/dll/win32/uxtheme/themehooks.c        [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/uxtheme/themehooks.c        [iso-8859-1] Wed Apr 26 09:28:35
2017
@@ -11,6 +11,7 @@
 USERAPIHOOK user32ApiHook;
 BYTE gabDWPmessages[UAHOWP_MAX_SIZE];
 BYTE gabMSGPmessages[UAHOWP_MAX_SIZE];
+BYTE gabDLGPmessages[UAHOWP_MAX_SIZE];
 BOOL gbThemeHooksActive = FALSE;
 PWND_CONTEXT ThemeGetWndContext(HWND hWnd)
@@ -56,7 +57,19 @@
     {
         user32ApiHook.SetWindowRgn(hWnd, 0, TRUE);
     }
-
+
+    if (pContext->hTabBackgroundBrush != NULL)
+    {
+        DeleteObject(pContext->hTabBackgroundBrush);
+        pContext->hTabBackgroundBrush = NULL;
+    }
+
+    if (pContext->hTabBackgroundBmp != NULL)
+    {
+        DeleteObject(pContext->hTabBackgroundBmp);
+        pContext->hTabBackgroundBmp = NULL;
+    }
+
     HeapFree(GetProcessHeap(), 0, pContext);
     SetPropW( hWnd, (LPCWSTR)MAKEINTATOM(atWndContext), NULL);
@@ -225,8 +238,27 @@
     switch(Msg)
     {
         case WM_THEMECHANGED:
+        {
+            PWND_CONTEXT pcontext = ThemeGetWndContext(hWnd);
+
             if (GetAncestor(hWnd, GA_PARENT) == GetDesktopWindow())
                 UXTHEME_LoadTheme(TRUE);
+
+            if (pcontext == NULL)
+                return 0;
+
+            if (pcontext->hTabBackgroundBrush != NULL)
+            {
+                DeleteObject(pcontext->hTabBackgroundBrush);
+                pcontext->hTabBackgroundBrush = NULL;
+            }
+
+            if (pcontext->hTabBackgroundBmp != NULL)
+            {
+                DeleteObject(pcontext->hTabBackgroundBmp);
+                pcontext->hTabBackgroundBmp = NULL;
+            }
+        }
         case WM_NCCREATE:
         {
             PWND_CONTEXT pcontext = ThemeGetWndContext(hWnd);
@@ -253,6 +285,126 @@
         {
             ThemeDestroyWndContext(hWnd);
             return 0;
+        }
+    }
+
+    return 0;
+}
+
+HRESULT GetDiaogTextureBrush(HTHEME theme, HWND hwnd, HDC hdc, HBRUSH* result, BOOL
changeOrigin)
+{
+    PWND_CONTEXT pcontext;
+
+    pcontext = ThemeGetWndContext(hwnd);
+    if (pcontext == NULL)
+        return E_FAIL;
+
+    if (pcontext->hTabBackgroundBrush == NULL)
+    {
+        HBITMAP hbmp;
+        RECT dummy, bmpRect;
+        BOOL hasImageAlpha;
+        //HTHEME theme = GetWindowTheme(hwnd);
+        theme = MSSTYLES_OpenThemeClass(ActiveThemeFile, NULL, L"TAB");
+        if (!theme)
+            return E_FAIL;
+
+        UXTHEME_LoadImage(theme, 0, TABP_BODY, 0, &dummy, FALSE, &hbmp,
&bmpRect, &hasImageAlpha);
+        if (changeOrigin)
+        {
+            /* Unfortunately SetBrushOrgEx doesn't work at all */
+            RECT rcWindow, rcParent;
+            POINT pt;
+            HDC hdcPattern, hdcHackPattern;
+            HBITMAP hbmpOld1, hbmpold2, hbmpHack;
+
+            GetWindowRect(hwnd, &rcWindow);
+            GetWindowRect(GetParent(hwnd), &rcParent);
+            pt.x = rcWindow.left - rcParent.left;
+            pt.y = rcWindow.top - rcParent.top;
+
+            hdcPattern = CreateCompatibleDC(hdc);
+            hbmpOld1 = (HBITMAP)SelectObject(hdcPattern, hbmp);
+
+            hdcHackPattern = CreateCompatibleDC(hdc);
+            hbmpHack = CreateCompatibleBitmap(hdc, bmpRect.right, bmpRect.bottom);
+            hbmpold2 = (HBITMAP)SelectObject(hdcHackPattern, hbmpHack);
+
+            BitBlt(hdcHackPattern, 0, 0, bmpRect.right, bmpRect.bottom - pt.y,
hdcPattern, 0, pt.y, SRCCOPY);
+            BitBlt(hdcHackPattern, 0, bmpRect.bottom - pt.y, bmpRect.right, pt.y,
hdcPattern, 0, 0, SRCCOPY);
+
+            hbmpold2 = (HBITMAP)SelectObject(hdcHackPattern, hbmpold2);
+            hbmpOld1 = (HBITMAP)SelectObject(hdcPattern, hbmpOld1);
+
+            DeleteDC(hdcPattern);
+            DeleteDC(hdcHackPattern);
+
+            /* Keep the handle of the bitmap we created so that it can be used later */
+            pcontext->hTabBackgroundBmp = hbmpHack;
+            hbmp = hbmpHack;
+        }
+
+        /* hbmp is cached so there is no need to free it */
+        pcontext->hTabBackgroundBrush = CreatePatternBrush(hbmp);
+    }
+
+    if (!pcontext->hTabBackgroundBrush)
+        return E_FAIL;
+
+    *result = pcontext->hTabBackgroundBrush;
+    return S_OK;
+}
+
+void HackFillStaticBg(HWND hwnd, HDC hdc, HBRUSH* result)
+{
+    RECT rcStatic;
+
+    GetClientRect(hwnd, &rcStatic);
+    FillRect(hdc, &rcStatic, *result);
+
+    SetBkMode (hdc, TRANSPARENT);
+    *result = GetStockObject (NULL_BRUSH);
+}
+
+static LRESULT CALLBACK
+ThemeDlgPreWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, ULONG_PTR
ret,PDWORD unknown)
+{
+    return 0;
+}
+
+static LRESULT CALLBACK
+ThemeDlgPostWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, ULONG_PTR
ret,PDWORD unknown)
+{
+    switch(Msg)
+    {
+        case WM_CTLCOLORDLG:
+        case WM_CTLCOLORBTN:
+        case WM_CTLCOLORSTATIC:
+        {
+            HWND hwndTarget = (HWND)lParam;
+            HDC hdc = (HDC)wParam;
+            HBRUSH* phbrush = (HBRUSH*)ret;
+            HTHEME theme = GetWindowTheme ( hWnd );
+
+            if (!IsAppThemed())
+                break;
+
+            if (!IsThemeDialogTextureEnabled (hWnd))
+                break;
+
+            GetDiaogTextureBrush(theme, hwndTarget, hdc, phbrush, Msg != WM_CTLCOLORDLG);
+
+#if 1
+            {
+                WCHAR controlClass[32];
+                GetClassNameW (hwndTarget, controlClass, sizeof(controlClass) /
sizeof(controlClass[0]));
+
+                /* This is a hack for the static class. Windows have a v6 static class
just for this. */
+                if (lstrcmpiW (controlClass, WC_STATICW) == 0)
+                    HackFillStaticBg(hwndTarget, hdc, phbrush);
+            }
+#endif
+            break;
         }
     }
@@ -333,8 +485,8 @@
     puah->DefWindowProcW = ThemeDefWindowProcW;
     puah->PreWndProc = ThemePreWindowProc;
     puah->PostWndProc = ThemePostWindowProc;
-    puah->PreDefDlgProc = ThemePreWindowProc;
-    puah->PostDefDlgProc = ThemePostWindowProc;
+    puah->PreDefDlgProc = ThemeDlgPreWindowProc;
+    puah->PostDefDlgProc = ThemeDlgPostWindowProc;
     puah->DefWndProcArray.MsgBitArray  = gabDWPmessages;
     puah->DefWndProcArray.Size = UAHOWP_MAX_SIZE;
     puah->WndProcArray.MsgBitArray = gabMSGPmessages;
@@ -380,6 +532,16 @@
     UAH_HOOK_MESSAGE(puah->WndProcArray, WM_THEMECHANGED);
     UAH_HOOK_MESSAGE(puah->WndProcArray, WM_UAHINIT);
+    puah->DlgProcArray.MsgBitArray = gabDLGPmessages;
+    puah->DlgProcArray.Size = UAHOWP_MAX_SIZE;
+
+    UAH_HOOK_MESSAGE(puah->DlgProcArray, WM_INITDIALOG);
+    UAH_HOOK_MESSAGE(puah->DlgProcArray, WM_CTLCOLORMSGBOX);
+    UAH_HOOK_MESSAGE(puah->DlgProcArray, WM_CTLCOLORBTN);
+    UAH_HOOK_MESSAGE(puah->DlgProcArray, WM_CTLCOLORDLG);
+    UAH_HOOK_MESSAGE(puah->DlgProcArray, WM_CTLCOLORSTATIC);
+    UAH_HOOK_MESSAGE(puah->DlgProcArray, WM_PRINTCLIENT);
+
     UXTHEME_LoadTheme(TRUE);
     return TRUE;
Modified: trunk/reactos/dll/win32/uxtheme/uxthemep.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/uxtheme/uxthemep…
==============================================================================
--- trunk/reactos/dll/win32/uxtheme/uxthemep.h  [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/uxtheme/uxthemep.h  [iso-8859-1] Wed Apr 26 09:28:35 2017
@@ -85,6 +85,9 @@
 typedef struct _UXINI_FILE *PUXINI_FILE;
+HRESULT UXTHEME_LoadImage(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT
*pRect, BOOL glyph,
+                          HBITMAP *hBmp, RECT *bmpRect, BOOL* hasImageAlpha);
+
 BOOL MSSTYLES_LookupProperty(LPCWSTR pszPropertyName, int *dwPrimitive, int *dwId);
 BOOL MSSTYLES_LookupEnum(LPCWSTR pszValueName, int dwEnum, int *dwValue);
 BOOL MSSTYLES_LookupPartState(LPCWSTR pszClass, LPCWSTR pszPart, LPCWSTR pszState, int
*iPartId, int *iStateId);
@@ -137,6 +140,8 @@
     BOOL HasThemeRgn;
     BOOL UpdatingRgn;
     BOOL DirtyThemeRegion;
+    HBRUSH hTabBackgroundBrush;
+    HBITMAP hTabBackgroundBmp;
     BOOL SCROLL_trackVertical;
     enum SCROLL_HITTEST SCROLL_trackHitTest;