Module: wine Branch: master Commit: 4b0c0a6b23378d46f580591655c7e613a6808afc URL: https://source.winehq.org/git/wine.git/?a=commit;h=4b0c0a6b23378d46f58059165...
Author: Jacek Caban jacek@codeweavers.com Date: Thu Feb 17 15:43:40 2022 +0100
win32u: Move primary palette handling from user32.
Signed-off-by: Jacek Caban jacek@codeweavers.com Signed-off-by: Huw Davies huw@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/user32/user_main.c | 72 +++----------------------------------------- dlls/win32u/ntuser_private.h | 1 + dlls/win32u/palette.c | 26 ++++++++++++++-- 3 files changed, 29 insertions(+), 70 deletions(-)
diff --git a/dlls/user32/user_main.c b/dlls/user32/user_main.c index 8ca55b283f7..ea30772067d 100644 --- a/dlls/user32/user_main.c +++ b/dlls/user32/user_main.c @@ -44,10 +44,6 @@ static CRITICAL_SECTION_DEBUG critsect_debug = }; static CRITICAL_SECTION user_section = { &critsect_debug, -1, 0, 0, 0, 0 };
-static HPALETTE (WINAPI *pfnGDISelectPalette)( HDC hdc, HPALETTE hpal, WORD bkgnd ); -static UINT (WINAPI *pfnGDIRealizePalette)( HDC hdc ); -static HPALETTE hPrimaryPalette; - static DWORD exiting_thread_id;
extern void WDML_NotifyThreadDetach(void); @@ -86,69 +82,11 @@ void USER_CheckNotLock(void)
/*********************************************************************** - * UserSelectPalette (Not a Windows API) + * UserRealizePalette (USER32.@) */ -static HPALETTE WINAPI UserSelectPalette( HDC hDC, HPALETTE hPal, BOOL bForceBackground ) +UINT WINAPI UserRealizePalette( HDC hdc ) { - WORD wBkgPalette = 1; - - if (!bForceBackground && (hPal != GetStockObject(DEFAULT_PALETTE))) - { - HWND hwnd = WindowFromDC( hDC ); - if (hwnd) - { - HWND hForeground = NtUserGetForegroundWindow(); - /* set primary palette if it's related to current active */ - if (hForeground == hwnd || IsChild(hForeground,hwnd)) - { - wBkgPalette = 0; - hPrimaryPalette = hPal; - } - } - } - return pfnGDISelectPalette( hDC, hPal, wBkgPalette); -} - - -/*********************************************************************** - * UserRealizePalette (USER32.@) - */ -UINT WINAPI UserRealizePalette( HDC hDC ) -{ - UINT realized = pfnGDIRealizePalette( hDC ); - - /* do not send anything if no colors were changed */ - if (realized && GetCurrentObject( hDC, OBJ_PAL ) == hPrimaryPalette) - { - /* send palette change notification */ - HWND hWnd = WindowFromDC( hDC ); - if (hWnd) SendMessageTimeoutW( HWND_BROADCAST, WM_PALETTECHANGED, (WPARAM)hWnd, 0, - SMTO_ABORTIFHUNG, 2000, NULL ); - } - return realized; -} - - -/*********************************************************************** - * palette_init - * - * Patch the function pointers in GDI for SelectPalette and RealizePalette - */ -static void palette_init(void) -{ - void **ptr; - HMODULE module = GetModuleHandleA( "gdi32" ); - if (!module) - { - ERR( "cannot get GDI32 handle\n" ); - return; - } - if ((ptr = (void**)GetProcAddress( module, "pfnSelectPalette" ))) - pfnGDISelectPalette = InterlockedExchangePointer( ptr, UserSelectPalette ); - else ERR( "cannot find pfnSelectPalette in GDI32\n" ); - if ((ptr = (void**)GetProcAddress( module, "pfnRealizePalette" ))) - pfnGDIRealizePalette = InterlockedExchangePointer( ptr, UserRealizePalette ); - else ERR( "cannot find pfnRealizePalette in GDI32\n" ); + return NtUserCallOneParam( HandleToUlong(hdc), NtUserRealizePalette ); }
@@ -212,6 +150,7 @@ static const struct user_callbacks user_funcs = { GetDesktopWindow, GetWindowRect, + IsChild, RedrawWindow, SendMessageTimeoutW, WindowFromDC, @@ -240,9 +179,6 @@ static BOOL process_attach(void) /* Initialize system colors and metrics */ SYSPARAMS_Init();
- /* Setup palette function pointers */ - palette_init(); - return TRUE; }
diff --git a/dlls/win32u/ntuser_private.h b/dlls/win32u/ntuser_private.h index f0e0f8835bf..e9d19744976 100644 --- a/dlls/win32u/ntuser_private.h +++ b/dlls/win32u/ntuser_private.h @@ -28,6 +28,7 @@ struct user_callbacks { HWND (WINAPI *pGetDesktopWindow)(void); BOOL (WINAPI *pGetWindowRect)( HWND hwnd, LPRECT rect ); + BOOL (WINAPI *pIsChild)( HWND, HWND ); BOOL (WINAPI *pRedrawWindow)( HWND, const RECT*, HRGN, UINT ); LRESULT (WINAPI *pSendMessageTimeoutW)( HWND, UINT, WPARAM, LPARAM, UINT, UINT, PDWORD_PTR ); HWND (WINAPI *pWindowFromDC)( HDC ); diff --git a/dlls/win32u/palette.c b/dlls/win32u/palette.c index 1c2f2c70434..d09fc9d4d73 100644 --- a/dlls/win32u/palette.c +++ b/dlls/win32u/palette.c @@ -508,12 +508,22 @@ static BOOL PALETTE_DeleteObject( HGDIOBJ handle ) */ HPALETTE WINAPI NtUserSelectPalette( HDC hdc, HPALETTE hpal, WORD bkg ) { + BOOL is_primary = FALSE; HPALETTE ret = 0; DC *dc;
TRACE("%p %p\n", hdc, hpal );
- /* FIXME: move primary palette handling from user32 */ + if (!bkg && hpal != get_stock_object( DEFAULT_PALETTE )) + { + HWND hwnd = user_callbacks->pWindowFromDC( hdc ); + if (hwnd) + { + /* set primary palette if it's related to current active */ + HWND foreground = NtUserGetForegroundWindow(); + is_primary = foreground == hwnd || user_callbacks->pIsChild( foreground, hwnd ); + } + }
if (get_gdi_object_type(hpal) != NTGDI_OBJ_PAL) { @@ -524,7 +534,7 @@ HPALETTE WINAPI NtUserSelectPalette( HDC hdc, HPALETTE hpal, WORD bkg ) { ret = dc->hPalette; dc->hPalette = hpal; - if (!bkg) hPrimaryPalette = hpal; + if (is_primary) hPrimaryPalette = hpal; release_dc_ptr( dc ); } return ret; @@ -536,6 +546,7 @@ HPALETTE WINAPI NtUserSelectPalette( HDC hdc, HPALETTE hpal, WORD bkg ) */ UINT realize_palette( HDC hdc ) { + BOOL is_primary = FALSE; UINT realized = 0; DC* dc = get_dc_ptr( hdc );
@@ -559,12 +570,23 @@ UINT realize_palette( HDC hdc ) (dc->hPalette == hPrimaryPalette) ); palPtr->unrealize = physdev->funcs->pUnrealizePalette; GDI_ReleaseObj( dc->hPalette ); + is_primary = dc->hPalette == hPrimaryPalette; } } else TRACE(" skipping (hLastRealizedPalette = %p)\n", hLastRealizedPalette);
release_dc_ptr( dc ); TRACE(" realized %i colors.\n", realized ); + + /* do not send anything if no colors were changed */ + if (realized && is_primary) + { + /* send palette change notification */ + HWND hwnd = user_callbacks->pWindowFromDC( hdc ); + if (hwnd) user_callbacks->pSendMessageTimeoutW( HWND_BROADCAST, WM_PALETTECHANGED, + HandleToUlong(hwnd), 0, SMTO_ABORTIFHUNG, + 2000, NULL ); + } return realized; }