[PATCH 8/9] uxtheme: Do not hook DefDlgProc() for theming.

Zhiyi Zhang zzhang at codeweavers.com
Tue Dec 7 03:13:19 CST 2021


Currently there is no need to hook DefDlgProc(). Tests show that dialog theming shouldn't be
implemented in DefDlgProc().

Also fix a double free bug because WM_DESTROY in UXTHEME_DefDlgProc() calls CloseThemeData() even
when the theme handle is not opened when handling WM_CREATE in UXTHEME_DefDlgProc(). The bug can
be demonstrated by running comctl32/tests/propsheet.c tests with Light theme.

Signed-off-by: Zhiyi Zhang <zzhang at codeweavers.com>
---
 dlls/comctl32/tests/propsheet.c |  9 ++---
 dlls/comctl32/tests/static.c    |  5 +--
 dlls/user32/defdlg.c            | 34 +++++--------------
 dlls/user32/hook.c              |  1 -
 dlls/user32/user_private.h      |  1 -
 dlls/uxtheme/Makefile.in        |  1 -
 dlls/uxtheme/dialog.c           | 59 ---------------------------------
 dlls/uxtheme/system.c           |  1 -
 dlls/uxtheme/uxthemedll.h       |  1 -
 include/winuser.h               |  1 -
 10 files changed, 11 insertions(+), 102 deletions(-)
 delete mode 100644 dlls/uxtheme/dialog.c

diff --git a/dlls/comctl32/tests/propsheet.c b/dlls/comctl32/tests/propsheet.c
index 199b280879e..0b012df1cca 100644
--- a/dlls/comctl32/tests/propsheet.c
+++ b/dlls/comctl32/tests/propsheet.c
@@ -1320,9 +1320,7 @@ static void test_WM_CTLCOLORSTATIC(void)
         todo_wine
         ok(count == sizeof(bmp), "GetObjectA failed, error %u.\n", GetLastError());
 
-        todo_wine_if(pGetWindowTheme(hdlg) != NULL)
         ok(pGetWindowTheme(hdlg) == NULL, "Expected NULL theme handle.\n");
-        todo_wine_if(pGetWindowTheme(sheethwnd) != NULL)
         ok(pGetWindowTheme(sheethwnd) == NULL, "Expected NULL theme handle.\n");
 
         memset(&cls, 0, sizeof(cls));
@@ -1336,18 +1334,15 @@ static void test_WM_CTLCOLORSTATIC(void)
         hwnd = CreateWindowA("TestClass", "test", WS_POPUP | WS_VISIBLE, 0, 0, 4, 4, 0, 0, 0, NULL);
         ok(hwnd != NULL, "CreateWindowA failed, error %d.\n", GetLastError());
         theme = pOpenThemeData(hwnd, L"Tab");
-        /* Light theme triggers a double free bug in uxtheme */
-        todo_wine_if(!theme)
         ok(theme != NULL, "OpenThemeData failed.\n");
 
         size.cx = 0;
         size.cy = 0;
         hr = pGetThemePartSize(theme, NULL, TABP_BODY, 0, NULL, TS_TRUE, &size);
-        todo_wine_if(!theme)
         ok(hr == S_OK, "GetThemePartSize failed, hr %#x.\n", hr);
-        todo_wine_if(theme)
+        todo_wine
         ok(bmp.bmWidth == size.cx, "Expected width %d, got %d.\n", size.cx, bmp.bmWidth);
-        todo_wine_if(theme)
+        todo_wine
         ok(bmp.bmHeight == size.cy, "Expected height %d, got %d.\n", size.cy, bmp.bmHeight);
 
         pCloseThemeData(theme);
diff --git a/dlls/comctl32/tests/static.c b/dlls/comctl32/tests/static.c
index b507cf1e02b..529396b3f0d 100644
--- a/dlls/comctl32/tests/static.c
+++ b/dlls/comctl32/tests/static.c
@@ -408,11 +408,11 @@ static void test_WM_CTLCOLORSTATIC(void)
     HWND parent, dialog, child;
     COLORREF color, old_color;
     HDC child_hdc, dialog_hdc;
-    BOOL ret, todo = FALSE;
     int mode, old_mode;
     HBRUSH brush;
     HRESULT hr;
     POINT org;
+    BOOL ret;
 
     struct
     {
@@ -434,8 +434,6 @@ static void test_WM_CTLCOLORSTATIC(void)
     child = GetDlgItem(dialog, 100);
     ok(child != NULL, "Failed to get child static control, error %d.\n", GetLastError());
 
-    todo = !!pGetWindowTheme(dialog);
-
     dialog_hdc = GetDC(dialog);
     child_hdc = GetDC(child);
     PatBlt(dialog_hdc, 0, 0, 80, 80, BLACKNESS);
@@ -447,7 +445,6 @@ static void test_WM_CTLCOLORSTATIC(void)
 
     ret = pIsThemeDialogTextureEnabled(dialog);
     ok(ret, "Expected theme dialog texture supported.\n");
-    todo_wine_if(todo)
     ok(pGetWindowTheme(dialog) == NULL, "Expected NULL theme handle.\n");
 
     brush = (HBRUSH)SendMessageW(dialog, WM_CTLCOLORSTATIC, (WPARAM)child_hdc, (LPARAM)child);
diff --git a/dlls/user32/defdlg.c b/dlls/user32/defdlg.c
index 4f44a93cd49..81c7cb0f207 100644
--- a/dlls/user32/defdlg.c
+++ b/dlls/user32/defdlg.c
@@ -354,7 +354,10 @@ out:
     return dlgInfo;
 }
 
-static LRESULT USER_DefDlgProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
+/***********************************************************************
+ *              DefDlgProcA (USER32.@)
+ */
+LRESULT WINAPI DefDlgProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
 {
     DIALOGINFO *dlgInfo;
     DLGPROC dlgproc;
@@ -408,7 +411,10 @@ static LRESULT USER_DefDlgProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar
     return GetWindowLongPtrW( hwnd, DWLP_MSGRESULT );
 }
 
-static LRESULT USER_DefDlgProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
+/***********************************************************************
+ *              DefDlgProcW (USER32.@)
+ */
+LRESULT WINAPI DefDlgProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
 {
     DIALOGINFO *dlgInfo;
     DLGPROC dlgproc;
@@ -461,27 +467,3 @@ static LRESULT USER_DefDlgProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar
 
     return GetWindowLongPtrW( hwnd, DWLP_MSGRESULT );
 }
-
-LRESULT WINAPI USER_DefDlgProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
-{
-    if (unicode)
-        return USER_DefDlgProcW( hwnd, msg, wParam, lParam );
-    else
-        return USER_DefDlgProcA( hwnd, msg, wParam, lParam );
-}
-
-/***********************************************************************
- *              DefDlgProcA (USER32.@)
- */
-LRESULT WINAPI DefDlgProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
-{
-    return user_api->pDefDlgProc( hwnd, msg, wParam, lParam, FALSE );
-}
-
-/***********************************************************************
- *              DefDlgProcW (USER32.@)
- */
-LRESULT WINAPI DefDlgProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
-{
-    return user_api->pDefDlgProc( hwnd, msg, wParam, lParam, TRUE );
-}
diff --git a/dlls/user32/hook.c b/dlls/user32/hook.c
index f5b4c6ab8a1..159797020f2 100644
--- a/dlls/user32/hook.c
+++ b/dlls/user32/hook.c
@@ -83,7 +83,6 @@ WINE_DECLARE_DEBUG_CHANNEL(relay);
 
 static struct user_api_hook original_user_api =
 {
-    USER_DefDlgProc,
     USER_ScrollBarDraw,
     USER_ScrollBarProc,
 };
diff --git a/dlls/user32/user_private.h b/dlls/user32/user_private.h
index c2152900a9b..96704ac68ae 100644
--- a/dlls/user32/user_private.h
+++ b/dlls/user32/user_private.h
@@ -302,7 +302,6 @@ extern BOOL get_icon_size( HICON handle, SIZE *size ) DECLSPEC_HIDDEN;
 #endif
 
 extern struct user_api_hook *user_api DECLSPEC_HIDDEN;
-LRESULT WINAPI USER_DefDlgProc(HWND, UINT, WPARAM, LPARAM, BOOL) DECLSPEC_HIDDEN;
 LRESULT WINAPI USER_ScrollBarProc(HWND, UINT, WPARAM, LPARAM, BOOL) DECLSPEC_HIDDEN;
 void WINAPI USER_ScrollBarDraw(HWND, HDC, INT, enum SCROLL_HITTEST,
                                const struct SCROLL_TRACKING_INFO *, BOOL, BOOL, RECT *, INT, INT,
diff --git a/dlls/uxtheme/Makefile.in b/dlls/uxtheme/Makefile.in
index 933650f4261..01751d3243a 100644
--- a/dlls/uxtheme/Makefile.in
+++ b/dlls/uxtheme/Makefile.in
@@ -5,7 +5,6 @@ DELAYIMPORTS = msimg32
 
 C_SRCS = \
 	buffer.c \
-	dialog.c \
 	draw.c \
 	main.c \
 	metric.c \
diff --git a/dlls/uxtheme/dialog.c b/dlls/uxtheme/dialog.c
deleted file mode 100644
index 776f54e1d31..00000000000
--- a/dlls/uxtheme/dialog.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Theming - Dialogs
- *
- * Copyright (c) 2005 by Frank Richter
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- *
- */
-
-#include <stdarg.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include "windef.h"
-#include "winbase.h"
-#include "wingdi.h"
-#include "winuser.h"
-#include "uxtheme.h"
-#include "uxthemedll.h"
-#include "vssym32.h"
-#include "wine/debug.h"
-
-LRESULT WINAPI UXTHEME_DefDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode)
-{
-    HTHEME theme = GetWindowTheme ( hWnd );
-    static const WCHAR themeClass[] = L"Window";
-    LRESULT result;
-
-    switch (msg)
-    {
-    case WM_CREATE:
-        result = user_api.pDefDlgProc(hWnd, msg, wParam, lParam, unicode);
-	theme = OpenThemeData( hWnd, themeClass );
-	return result;
-    
-    case WM_DESTROY:
-        CloseThemeData ( theme );
-        SetWindowTheme( hWnd, NULL, NULL );
-        OpenThemeData( hWnd, NULL );
-        return user_api.pDefDlgProc(hWnd, msg, wParam, lParam, unicode);
-
-    default: 
-	/* Call old proc */
-        return user_api.pDefDlgProc(hWnd, msg, wParam, lParam, unicode);
-    }
-    return 0;
-}
diff --git a/dlls/uxtheme/system.c b/dlls/uxtheme/system.c
index 37c484387ec..61a608e5962 100644
--- a/dlls/uxtheme/system.c
+++ b/dlls/uxtheme/system.c
@@ -1245,7 +1245,6 @@ BOOL WINAPI ThemeHooksInstall(void)
 {
     struct user_api_hook hooks;
 
-    hooks.pDefDlgProc = UXTHEME_DefDlgProc;
     hooks.pScrollBarDraw = UXTHEME_ScrollBarDraw;
     hooks.pScrollBarWndProc = UXTHEME_ScrollbarWndProc;
     return RegisterUserApiHook(&hooks, &user_api);
diff --git a/dlls/uxtheme/uxthemedll.h b/dlls/uxtheme/uxthemedll.h
index 67130774392..c43ad703884 100644
--- a/dlls/uxtheme/uxthemedll.h
+++ b/dlls/uxtheme/uxthemedll.h
@@ -106,7 +106,6 @@ extern HRESULT UXTHEME_SetActiveTheme(PTHEME_FILE tf) DECLSPEC_HIDDEN;
 extern void UXTHEME_UninitSystem(void) DECLSPEC_HIDDEN;
 
 extern struct user_api_hook user_api DECLSPEC_HIDDEN;
-LRESULT WINAPI UXTHEME_DefDlgProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam, BOOL unicode) DECLSPEC_HIDDEN;
 void WINAPI UXTHEME_ScrollBarDraw(HWND hwnd, HDC dc, INT bar, enum SCROLL_HITTEST hit_test,
                                   const struct SCROLL_TRACKING_INFO *tracking_info,
                                   BOOL draw_arrows, BOOL draw_interior, RECT *rect, INT arrowsize,
diff --git a/include/winuser.h b/include/winuser.h
index 898c9034e33..1d37bd44344 100644
--- a/include/winuser.h
+++ b/include/winuser.h
@@ -4435,7 +4435,6 @@ struct SCROLL_TRACKING_INFO
 
 struct user_api_hook
 {
-    LRESULT (WINAPI *pDefDlgProc)(HWND, UINT, WPARAM, LPARAM, BOOL);
     void (WINAPI *pScrollBarDraw)(HWND, HDC, INT, enum SCROLL_HITTEST,
                                   const struct SCROLL_TRACKING_INFO *, BOOL, BOOL, RECT *, INT, INT,
                                   INT, BOOL);
-- 
2.32.0




More information about the wine-devel mailing list