diff --git a/dlls/user/user32.spec b/dlls/user/user32.spec index 456f033463c..918a404bc20 100644 --- a/dlls/user/user32.spec +++ b/dlls/user/user32.spec @@ -574,7 +574,7 @@ import kernel32.dll @ stub UpdatePerUserSystemParameters @ stdcall UpdateWindow(long) UpdateWindow @ stub UserClientDllInitialize -@ stub UserRealizePalette +@ stdcall UserRealizePalette(long) UserRealizePalette @ stub UserRegisterWowHandlers @ stdcall ValidateRect(long ptr) ValidateRect @ stdcall ValidateRgn(long long) ValidateRgn diff --git a/dlls/user/user_main.c b/dlls/user/user_main.c index 3d717ee1297..21e5e06ce7b 100644 --- a/dlls/user/user_main.c +++ b/dlls/user/user_main.c @@ -7,6 +7,7 @@ #include "winuser.h" #include "winreg.h" #include "wine/winbase16.h" +#include "wine/winuser16.h" #include "dce.h" #include "dialog.h" @@ -93,6 +94,27 @@ static BOOL load_driver(void) } +/*********************************************************************** + * 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" ))) *ptr = SelectPalette16; + else ERR( "cannot find pfnSelectPalette in GDI32\n" ); + if ((ptr = (void**)GetProcAddress( module, "pfnRealizePalette" ))) *ptr = UserRealizePalette; + else ERR( "cannot find pfnRealizePalette in GDI32\n" ); +} + + /*********************************************************************** * USER initialisation routine */ @@ -120,6 +142,9 @@ BOOL WINAPI USER_Init(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) SYSMETRICS_Init(); SYSCOLOR_Init(); + /* Setup palette function pointers */ + palette_init(); + /* Create the DCEs */ DCE_Init(); diff --git a/objects/palette.c b/objects/palette.c index 6b1c2eea323..b5dd0c5fbe8 100644 --- a/objects/palette.c +++ b/objects/palette.c @@ -23,10 +23,12 @@ #include "callback.h" #include "winerror.h" -DEFAULT_DEBUG_CHANNEL(palette) +DEFAULT_DEBUG_CHANNEL(palette); PALETTE_DRIVER *PALETTE_Driver = NULL; +/* Pointers to USER implementation of SelectPalette/RealizePalette */ +/* they will be patched by USER on startup */ FARPROC pfnSelectPalette = NULL; FARPROC pfnRealizePalette = NULL; @@ -641,7 +643,12 @@ HPALETTE16 WINAPI GDISelectPalette16( HDC16 hdc, HPALETTE16 hpal, WORD wBkg) DC *dc; TRACE("%04x %04x\n", hdc, hpal ); - + + if (GetObjectType(hpal) != PALETTE_MAGIC) + { + WARN("invalid selected palette %04x\n",hpal); + return 0; + } if (!(dc = DC_GetDCPtr( hdc ))) return 0; prev = dc->w.hPalette; dc->w.hPalette = hpal; @@ -752,19 +759,7 @@ HPALETTE WINAPI SelectPalette( HPALETTE hPal, /* [in] Handle of logical color palette */ BOOL bForceBackground) /* [in] Foreground/background mode */ { - WORD wBkgPalette = 1; - - if (!bForceBackground && (hPal != STOCK_DEFAULT_PALETTE)) - { - HWND hwnd = Callout.WindowFromDC( hDC ); - if (hwnd) - { - HWND hForeground = Callout.GetForegroundWindow(); - /* set primary palette if it's related to current active */ - if (hForeground == hwnd || Callout.IsChild(hForeground,hwnd)) wBkgPalette = 0; - } - } - return GDISelectPalette16( hDC, hPal, wBkgPalette); + return pfnSelectPalette( hDC, hPal, bForceBackground ); } @@ -778,28 +773,7 @@ HPALETTE WINAPI SelectPalette( UINT WINAPI RealizePalette( HDC hDC) /* [in] Handle of device context */ { - DC *dc; - UINT realized; - - if (!(dc = (DC *) GDI_GetObjPtr( hDC, DC_MAGIC ))) return 0; - - realized = GDIRealizePalette16( hDC ); - - /* do not send anything if no colors were changed */ - - if( IsDCCurrentPalette16( hDC ) && realized && - dc->w.devCaps->sizePalette ) - { - /* Send palette change notification */ - - HWND hWnd; - GDI_ReleaseObj( hDC ); - if( (hWnd = Callout.WindowFromDC( hDC )) ) - Callout.SendMessageA( HWND_BROADCAST, WM_PALETTECHANGED, hWnd, 0L); - } - else GDI_ReleaseObj( hDC ); - - return realized; + return pfnRealizePalette( hDC ); } diff --git a/windows/painting.c b/windows/painting.c index a8eea979ab6..5578add6a8c 100644 --- a/windows/painting.c +++ b/windows/painting.c @@ -1681,7 +1681,19 @@ BOOL16 WINAPI DrawState16(HDC16 hdc, HBRUSH16 hbr, HPALETTE16 WINAPI SelectPalette16( HDC16 hDC, HPALETTE16 hPal, BOOL16 bForceBackground ) { - return SelectPalette( hDC, hPal, bForceBackground ); + WORD wBkgPalette = 1; + + if (!bForceBackground && (hPal != STOCK_DEFAULT_PALETTE)) + { + HWND hwnd = WindowFromDC( hDC ); + if (hwnd) + { + HWND hForeground = GetForegroundWindow(); + /* set primary palette if it's related to current active */ + if (hForeground == hwnd || IsChild(hForeground,hwnd)) wBkgPalette = 0; + } + } + return GDISelectPalette16( hDC, hPal, wBkgPalette); } @@ -1690,5 +1702,23 @@ HPALETTE16 WINAPI SelectPalette16( HDC16 hDC, HPALETTE16 hPal, */ UINT16 WINAPI RealizePalette16( HDC16 hDC ) { - return RealizePalette( hDC ); + UINT16 realized = GDIRealizePalette16( hDC ); + + /* do not send anything if no colors were changed */ + if (realized && IsDCCurrentPalette16( hDC )) + { + /* send palette change notification */ + HWND hWnd = WindowFromDC( hDC ); + if (hWnd) SendMessageA( HWND_BROADCAST, WM_PALETTECHANGED, hWnd, 0L); + } + return realized; +} + + +/*********************************************************************** + * UserRealizePalette (USER32.@) + */ +UINT WINAPI UserRealizePalette( HDC hDC ) +{ + return RealizePalette16( hDC ); }