Commit 4b0c0a6b authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

win32u: Move primary palette handling from user32.

parent fa3bd8f4
......@@ -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;
}
......
......@@ -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 );
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment