uxtheme: Do not hook DefDlgProc() for theming.

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@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zhiyi Zhang 2021-12-07 17:13:19 +08:00 committed by Alexandre Julliard
parent 7c5a62b4c5
commit 9c9274990e
10 changed files with 11 additions and 102 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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 );
}

View File

@ -83,7 +83,6 @@ WINE_DECLARE_DEBUG_CHANNEL(relay);
static struct user_api_hook original_user_api =
{
USER_DefDlgProc,
USER_ScrollBarDraw,
USER_ScrollBarProc,
};

View File

@ -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,

View File

@ -5,7 +5,6 @@ DELAYIMPORTS = msimg32
C_SRCS = \
buffer.c \
dialog.c \
draw.c \
main.c \
metric.c \

View File

@ -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;
}

View File

@ -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);

View File

@ -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,

View File

@ -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);