From 2820682202886cb1fc438ab55b3c39f13baef9bf Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Wed, 7 May 2008 20:35:04 +0900 Subject: [PATCH] gdi32: Implement EMFDRV_SelectPalette. --- dlls/gdi32/enhmfdrv/enhmetafiledrv.h | 1 + dlls/gdi32/enhmfdrv/init.c | 2 +- dlls/gdi32/enhmfdrv/objects.c | 55 ++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/dlls/gdi32/enhmfdrv/enhmetafiledrv.h b/dlls/gdi32/enhmfdrv/enhmetafiledrv.h index f1c81a2cabe..c00c65364a9 100644 --- a/dlls/gdi32/enhmfdrv/enhmetafiledrv.h +++ b/dlls/gdi32/enhmfdrv/enhmetafiledrv.h @@ -122,6 +122,7 @@ extern HBRUSH EMFDRV_SelectBrush( PHYSDEV dev, HBRUSH handle ) DECLSPEC_HIDDEN extern BOOL EMFDRV_SelectClipPath( PHYSDEV dev, INT iMode ) DECLSPEC_HIDDEN; extern HFONT EMFDRV_SelectFont( PHYSDEV dev, HFONT handle, HANDLE gdiFont ) DECLSPEC_HIDDEN; extern HPEN EMFDRV_SelectPen( PHYSDEV dev, HPEN handle ) DECLSPEC_HIDDEN; +extern HPALETTE EMFDRV_SelectPalette( PHYSDEV dev, HPALETTE hPal, BOOL force ) DECLSPEC_HIDDEN; extern INT EMFDRV_SetArcDirection( PHYSDEV dev, INT arcDirection ) DECLSPEC_HIDDEN; extern COLORREF EMFDRV_SetBkColor( PHYSDEV dev, COLORREF color ) DECLSPEC_HIDDEN; extern INT EMFDRV_SetBkMode( PHYSDEV dev, INT mode ) DECLSPEC_HIDDEN; diff --git a/dlls/gdi32/enhmfdrv/init.c b/dlls/gdi32/enhmfdrv/init.c index dafac60811e..de135d23420 100644 --- a/dlls/gdi32/enhmfdrv/init.c +++ b/dlls/gdi32/enhmfdrv/init.c @@ -114,7 +114,7 @@ static const DC_FUNCTIONS EMFDRV_Funcs = EMFDRV_SelectBrush, /* pSelectBrush */ EMFDRV_SelectClipPath, /* pSelectClipPath */ EMFDRV_SelectFont, /* pSelectFont */ - NULL, /* pSelectPalette */ + EMFDRV_SelectPalette, /* pSelectPalette */ EMFDRV_SelectPen, /* pSelectPen */ EMFDRV_SetArcDirection, /* pSetArcDirection */ NULL, /* pSetBitmapBits */ diff --git a/dlls/gdi32/enhmfdrv/objects.c b/dlls/gdi32/enhmfdrv/objects.c index c7ecd548af7..54c34bf55cd 100644 --- a/dlls/gdi32/enhmfdrv/objects.c +++ b/dlls/gdi32/enhmfdrv/objects.c @@ -465,6 +465,61 @@ HPEN EMFDRV_SelectPen(PHYSDEV dev, HPEN hPen ) /****************************************************************** + * EMFDRV_CreatePalette + */ +static DWORD EMFDRV_CreatePalette(PHYSDEV dev, HPALETTE hPal) +{ + WORD i; + struct { + EMRCREATEPALETTE hdr; + PALETTEENTRY entry[255]; + } pal; + + memset( &pal, 0, sizeof(pal) ); + + if (!GetObjectW( hPal, sizeof(pal.hdr.lgpl) + sizeof(pal.entry), &pal.hdr.lgpl )) + return 0; + + for (i = 0; i < pal.hdr.lgpl.palNumEntries; i++) + pal.hdr.lgpl.palPalEntry[i].peFlags = 0; + + pal.hdr.emr.iType = EMR_CREATEPALETTE; + pal.hdr.emr.nSize = sizeof(pal.hdr) + pal.hdr.lgpl.palNumEntries * sizeof(PALETTEENTRY); + pal.hdr.ihPal = EMFDRV_AddHandle( dev, hPal ); + + if (!EMFDRV_WriteRecord( dev, &pal.hdr.emr )) + pal.hdr.ihPal = 0; + return pal.hdr.ihPal; +} + +/****************************************************************** + * EMFDRV_SelectPalette + */ +HPALETTE EMFDRV_SelectPalette( PHYSDEV dev, HPALETTE hPal, BOOL force ) +{ + EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE*)dev; + EMRSELECTPALETTE emr; + DWORD index; + + if (hPal == GetStockObject( DEFAULT_PALETTE )) + index = DEFAULT_PALETTE | 0x80000000; + goto found; + + if ((index = EMFDRV_FindObject( dev, hPal )) != 0) + goto found; + + if (!(index = EMFDRV_CreatePalette( dev, hPal ))) return 0; + GDI_hdc_using_object( hPal, physDev->hdc ); + +found: + emr.emr.iType = EMR_SELECTPALETTE; + emr.emr.nSize = sizeof(emr); + emr.ihPal = index; + return EMFDRV_WriteRecord( dev, &emr.emr ) ? hPal : 0; +} + + +/****************************************************************** * EMFDRV_GdiComment */ BOOL EMFDRV_GdiComment(PHYSDEV dev, UINT bytes, CONST BYTE *buffer) -- 2.11.4.GIT