Moved Select/RealizePalette implementation to USER and use

pfnSelect/RealizePalette function pointers in GDI.
Make sure the palette handle is valid in GDISelectPalette16 (thanks to
Uwe Bonnes).
This commit is contained in:
Alexandre Julliard 2000-09-16 20:57:39 +00:00
parent 654fcc721b
commit 3993216776
4 changed files with 69 additions and 40 deletions

View File

@ -574,7 +574,7 @@ import kernel32.dll
@ stub UpdatePerUserSystemParameters @ stub UpdatePerUserSystemParameters
@ stdcall UpdateWindow(long) UpdateWindow @ stdcall UpdateWindow(long) UpdateWindow
@ stub UserClientDllInitialize @ stub UserClientDllInitialize
@ stub UserRealizePalette @ stdcall UserRealizePalette(long) UserRealizePalette
@ stub UserRegisterWowHandlers @ stub UserRegisterWowHandlers
@ stdcall ValidateRect(long ptr) ValidateRect @ stdcall ValidateRect(long ptr) ValidateRect
@ stdcall ValidateRgn(long long) ValidateRgn @ stdcall ValidateRgn(long long) ValidateRgn

View File

@ -7,6 +7,7 @@
#include "winuser.h" #include "winuser.h"
#include "winreg.h" #include "winreg.h"
#include "wine/winbase16.h" #include "wine/winbase16.h"
#include "wine/winuser16.h"
#include "dce.h" #include "dce.h"
#include "dialog.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 * USER initialisation routine
*/ */
@ -120,6 +142,9 @@ BOOL WINAPI USER_Init(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
SYSMETRICS_Init(); SYSMETRICS_Init();
SYSCOLOR_Init(); SYSCOLOR_Init();
/* Setup palette function pointers */
palette_init();
/* Create the DCEs */ /* Create the DCEs */
DCE_Init(); DCE_Init();

View File

@ -23,10 +23,12 @@
#include "callback.h" #include "callback.h"
#include "winerror.h" #include "winerror.h"
DEFAULT_DEBUG_CHANNEL(palette) DEFAULT_DEBUG_CHANNEL(palette);
PALETTE_DRIVER *PALETTE_Driver = NULL; PALETTE_DRIVER *PALETTE_Driver = NULL;
/* Pointers to USER implementation of SelectPalette/RealizePalette */
/* they will be patched by USER on startup */
FARPROC pfnSelectPalette = NULL; FARPROC pfnSelectPalette = NULL;
FARPROC pfnRealizePalette = NULL; FARPROC pfnRealizePalette = NULL;
@ -642,6 +644,11 @@ HPALETTE16 WINAPI GDISelectPalette16( HDC16 hdc, HPALETTE16 hpal, WORD wBkg)
TRACE("%04x %04x\n", hdc, hpal ); 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; if (!(dc = DC_GetDCPtr( hdc ))) return 0;
prev = dc->w.hPalette; prev = dc->w.hPalette;
dc->w.hPalette = hpal; dc->w.hPalette = hpal;
@ -752,19 +759,7 @@ HPALETTE WINAPI SelectPalette(
HPALETTE hPal, /* [in] Handle of logical color palette */ HPALETTE hPal, /* [in] Handle of logical color palette */
BOOL bForceBackground) /* [in] Foreground/background mode */ BOOL bForceBackground) /* [in] Foreground/background mode */
{ {
WORD wBkgPalette = 1; return pfnSelectPalette( hDC, hPal, bForceBackground );
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);
} }
@ -778,28 +773,7 @@ HPALETTE WINAPI SelectPalette(
UINT WINAPI RealizePalette( UINT WINAPI RealizePalette(
HDC hDC) /* [in] Handle of device context */ HDC hDC) /* [in] Handle of device context */
{ {
DC *dc; return pfnRealizePalette( hDC );
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;
} }

View File

@ -1681,7 +1681,19 @@ BOOL16 WINAPI DrawState16(HDC16 hdc, HBRUSH16 hbr,
HPALETTE16 WINAPI SelectPalette16( HDC16 hDC, HPALETTE16 hPal, HPALETTE16 WINAPI SelectPalette16( HDC16 hDC, HPALETTE16 hPal,
BOOL16 bForceBackground ) 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 ) 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 );
} }