gdi32: Handle metafiles directly in SelectPalette.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2021-08-09 11:30:56 +02:00 committed by Alexandre Julliard
parent 0804dfd276
commit c589da991c
10 changed files with 42 additions and 52 deletions

View File

@ -102,7 +102,6 @@ extern BOOL CDECL EMFDRV_ScaleWindowExtEx( PHYSDEV dev, INT xNum, INT xDenom
extern HBITMAP CDECL EMFDRV_SelectBitmap( PHYSDEV dev, HBITMAP handle ) DECLSPEC_HIDDEN;
extern BOOL CDECL EMFDRV_SelectClipPath( PHYSDEV dev, INT iMode ) DECLSPEC_HIDDEN;
extern HFONT CDECL EMFDRV_SelectFont( PHYSDEV dev, HFONT handle, UINT *aa_flags ) DECLSPEC_HIDDEN;
extern HPALETTE CDECL EMFDRV_SelectPalette( PHYSDEV dev, HPALETTE hPal, BOOL force ) DECLSPEC_HIDDEN;
extern COLORREF CDECL EMFDRV_SetBkColor( PHYSDEV dev, COLORREF color ) DECLSPEC_HIDDEN;
extern COLORREF CDECL EMFDRV_SetDCBrushColor( PHYSDEV dev, COLORREF color ) DECLSPEC_HIDDEN;
extern COLORREF CDECL EMFDRV_SetDCPenColor( PHYSDEV dev, COLORREF color ) DECLSPEC_HIDDEN;

View File

@ -118,7 +118,7 @@ static const struct gdi_dc_funcs emfdrv_driver =
NULL, /* pSelectBrush */
EMFDRV_SelectClipPath, /* pSelectClipPath */
EMFDRV_SelectFont, /* pSelectFont */
EMFDRV_SelectPalette, /* pSelectPalette */
NULL, /* pSelectPalette */
NULL, /* pSelectPen */
EMFDRV_SetBkColor, /* pSetBkColor */
NULL, /* pSetBoundsRect */

View File

@ -422,33 +422,31 @@ static DWORD EMFDRV_CreatePalette(PHYSDEV dev, HPALETTE hPal)
}
/******************************************************************
* EMFDRV_SelectPalette
* EMFDC_SelectPalette
*/
HPALETTE CDECL EMFDRV_SelectPalette( PHYSDEV dev, HPALETTE hPal, BOOL force )
BOOL EMFDC_SelectPalette( DC_ATTR *dc_attr, HPALETTE palette )
{
EMFDRV_PDEVICE *physDev = get_emf_physdev( dev );
EMFDRV_PDEVICE *emf = dc_attr->emf;
EMRSELECTPALETTE emr;
DWORD index;
if (physDev->restoring) return hPal; /* don't output SelectObject records during RestoreDC */
if (hPal == GetStockObject( DEFAULT_PALETTE ))
if (palette == GetStockObject( DEFAULT_PALETTE ))
{
index = DEFAULT_PALETTE | 0x80000000;
goto found;
}
if ((index = EMFDRV_FindObject( dev, hPal )) != 0)
if ((index = EMFDRV_FindObject( &emf->dev, palette )) != 0)
goto found;
if (!(index = EMFDRV_CreatePalette( dev, hPal ))) return 0;
GDI_hdc_using_object( hPal, dev->hdc, EMFDC_DeleteObject );
if (!(index = EMFDRV_CreatePalette( &emf->dev, palette ))) return 0;
GDI_hdc_using_object( palette, dc_attr->hdc, EMFDC_DeleteObject );
found:
emr.emr.iType = EMR_SELECTPALETTE;
emr.emr.nSize = sizeof(emr);
emr.ihPal = index;
return EMFDRV_WriteRecord( dev, &emr.emr ) ? hPal : 0;
return EMFDRV_WriteRecord( &emf->dev, &emr.emr );
}
BOOL EMFDC_SelectObject( DC_ATTR *dc_attr, HGDIOBJ obj )

View File

@ -84,6 +84,7 @@ extern BOOL METADC_ScaleViewportExtEx( HDC hdc, INT x_num, INT x_denom, INT y_nu
extern BOOL METADC_ScaleWindowExtEx( HDC hdc, INT x_num, INT x_denom, INT y_num,
INT y_denom ) DECLSPEC_HIDDEN;
extern HGDIOBJ METADC_SelectObject( HDC hdc, HGDIOBJ obj ) DECLSPEC_HIDDEN;
extern BOOL METADC_SelectPalette( HDC hdc, HPALETTE palette ) DECLSPEC_HIDDEN;
extern BOOL METADC_SetBkMode( HDC hdc, INT mode ) DECLSPEC_HIDDEN;
extern BOOL METADC_SetLayout( HDC hdc, DWORD layout ) DECLSPEC_HIDDEN;
extern BOOL METADC_SetTextCharacterExtra( HDC hdc, INT extra ) DECLSPEC_HIDDEN;
@ -150,6 +151,7 @@ extern BOOL EMFDC_ScaleViewportExtEx( DC_ATTR *dc_attr, INT x_num, INT x_denom,
extern BOOL EMFDC_ScaleWindowExtEx( DC_ATTR *dc_attr, INT x_num, INT x_denom, INT y_num,
INT y_denom ) DECLSPEC_HIDDEN;
extern BOOL EMFDC_SelectObject( DC_ATTR *dc_attr, HGDIOBJ obj ) DECLSPEC_HIDDEN;
extern BOOL EMFDC_SelectPalette( DC_ATTR *dc_attr, HPALETTE palette ) DECLSPEC_HIDDEN;
extern BOOL EMFDC_SetArcDirection( DC_ATTR *dc_attr, INT dir ) DECLSPEC_HIDDEN;
extern BOOL EMFDC_SetBkMode( DC_ATTR *dc_attr, INT mode ) DECLSPEC_HIDDEN;
extern BOOL EMFDC_SetLayout( DC_ATTR *dc_attr, DWORD layout ) DECLSPEC_HIDDEN;

View File

@ -1262,6 +1262,24 @@ BOOL WINAPI ScaleWindowExtEx( HDC hdc, INT x_num, INT x_denom,
return NtGdiScaleWindowExtEx( hdc, x_num, x_denom, y_num, y_denom, size );
}
/* Pointers to USER implementation of SelectPalette/RealizePalette */
/* they will be patched by USER on startup */
extern HPALETTE WINAPI GDISelectPalette( HDC hdc, HPALETTE hpal, WORD wBkg );
HPALETTE (WINAPI *pfnSelectPalette)( HDC hdc, HPALETTE hpal, WORD bkgnd ) = GDISelectPalette;
/***********************************************************************
* SelectPalette (GDI32.@)
*/
HPALETTE WINAPI SelectPalette( HDC hdc, HPALETTE palette, BOOL force_background )
{
DC_ATTR *dc_attr;
if (is_meta_dc( hdc )) return ULongToHandle( METADC_SelectPalette( hdc, palette ) );
if (!(dc_attr = get_dc_attr( hdc ))) return FALSE;
if (dc_attr->emf && !EMFDC_SelectPalette( dc_attr, palette )) return 0;
return pfnSelectPalette( hdc, palette, force_background );
}
/***********************************************************************
* GdiSetPixelFormat (GDI32.@)
*/

View File

@ -789,7 +789,7 @@ BOOL WINAPI PlayMetaFileRecord( HDC hdc, HANDLETABLE *ht, METARECORD *mr, UINT
break;
case META_SELECTPALETTE:
GDISelectPalette(hdc, *(ht->objectHandle + mr->rdParm[1]), mr->rdParm[0]);
SelectPalette( hdc, *(ht->objectHandle + mr->rdParm[1]), mr->rdParm[0] );
break;
case META_SETMAPPERFLAGS:

View File

@ -183,7 +183,7 @@ static const struct gdi_dc_funcs MFDRV_Funcs =
NULL, /* pSelectBrush */
MFDRV_SelectClipPath, /* pSelectClipPath */
NULL, /* pSelectFont */
MFDRV_SelectPalette, /* pSelectPalette */
NULL, /* pSelectPalette */
NULL, /* pSelectPen */
MFDRV_SetBkColor, /* pSetBkColor */
MFDRV_SetBoundsRect, /* pSetBoundsRect */

View File

@ -95,7 +95,6 @@ extern BOOL CDECL MFDRV_PolyBezierTo( PHYSDEV dev, const POINT* pt, DWORD count
extern BOOL CDECL MFDRV_RestoreDC( PHYSDEV dev, INT level ) DECLSPEC_HIDDEN;
extern BOOL CDECL MFDRV_ScaleWindowExtEx( PHYSDEV dev, INT xNum, INT xDenom, INT yNum, INT yDenom, SIZE *size ) DECLSPEC_HIDDEN;
extern BOOL CDECL MFDRV_SelectClipPath( PHYSDEV dev, INT iMode ) DECLSPEC_HIDDEN;
extern HPALETTE CDECL MFDRV_SelectPalette( PHYSDEV dev, HPALETTE hPalette, BOOL bForceBackground) DECLSPEC_HIDDEN;
extern UINT CDECL MFDRV_RealizePalette(PHYSDEV dev, HPALETTE hPalette, BOOL primary) DECLSPEC_HIDDEN;
extern COLORREF CDECL MFDRV_SetBkColor( PHYSDEV dev, COLORREF color ) DECLSPEC_HIDDEN;
extern COLORREF CDECL MFDRV_SetDCBrushColor( PHYSDEV dev, COLORREF color ) DECLSPEC_HIDDEN;

View File

@ -411,18 +411,20 @@ static BOOL MFDRV_CreatePalette(PHYSDEV dev, HPALETTE hPalette, LOGPALETTE* logP
/***********************************************************************
* MFDRV_SelectPalette
* METADC_SelectPalette
*/
HPALETTE CDECL MFDRV_SelectPalette( PHYSDEV dev, HPALETTE hPalette, BOOL bForceBackground )
BOOL METADC_SelectPalette( HDC hdc, HPALETTE palette )
{
#define PALVERSION 0x0300
METAFILEDRV_PDEVICE *metadc;
PLOGPALETTE logPalette;
WORD wNumEntries = 0;
BOOL creationSucceed;
BOOL ret;
int sizeofPalette;
GetObjectA(hPalette, sizeof(WORD), &wNumEntries);
if (!(metadc = get_metadc_ptr( hdc ))) return FALSE;
GetObjectA( palette, sizeof(WORD), &wNumEntries );
if (wNumEntries == 0) return 0;
@ -434,16 +436,12 @@ HPALETTE CDECL MFDRV_SelectPalette( PHYSDEV dev, HPALETTE hPalette, BOOL bForceB
logPalette->palVersion = PALVERSION;
logPalette->palNumEntries = wNumEntries;
GetPaletteEntries(hPalette, 0, wNumEntries, logPalette->palPalEntry);
GetPaletteEntries( palette, 0, wNumEntries, logPalette->palPalEntry );
creationSucceed = MFDRV_CreatePalette( dev, hPalette, logPalette, sizeofPalette );
ret = MFDRV_CreatePalette( &metadc->dev, palette, logPalette, sizeofPalette );
HeapFree( GetProcessHeap(), 0, logPalette );
if (creationSucceed)
return hPalette;
return 0;
return ret;
}
/***********************************************************************

View File

@ -62,7 +62,6 @@ static const struct gdi_obj_funcs palette_funcs =
/* Pointers to USER implementation of SelectPalette/RealizePalette */
/* they will be patched by USER on startup */
HPALETTE (WINAPI *pfnSelectPalette)(HDC hdc, HPALETTE hpal, WORD bkgnd ) = GDISelectPalette;
UINT (WINAPI *pfnRealizePalette)(HDC hdc) = GDIRealizePalette;
static UINT SystemPaletteUse = SYSPAL_STATIC; /* currently not considered */
@ -632,14 +631,9 @@ HPALETTE WINAPI GDISelectPalette( HDC hdc, HPALETTE hpal, WORD wBkg)
}
if ((dc = get_dc_ptr( hdc )))
{
PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSelectPalette );
ret = dc->hPalette;
if (physdev->funcs->pSelectPalette( physdev, hpal, FALSE ))
{
dc->hPalette = hpal;
if (!wBkg) hPrimaryPalette = hpal;
}
else ret = 0;
dc->hPalette = hpal;
if (!wBkg) hPrimaryPalette = hpal;
release_dc_ptr( dc );
}
return ret;
@ -683,24 +677,6 @@ UINT WINAPI GDIRealizePalette( HDC hdc )
}
/***********************************************************************
* SelectPalette [GDI32.@]
*
* Selects logical palette into DC.
*
* RETURNS
* Success: Previous logical palette
* Failure: NULL
*/
HPALETTE WINAPI SelectPalette(
HDC hDC, /* [in] Handle of device context */
HPALETTE hPal, /* [in] Handle of logical color palette */
BOOL bForceBackground) /* [in] Foreground/background mode */
{
return pfnSelectPalette( hDC, hPal, bForceBackground );
}
/***********************************************************************
* RealizePalette [GDI32.@]
*