wine/objects/palette.c
Alexandre Julliard 60ce85c965 Release 980201
Sun Feb  1 13:24:54 1998  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [files/drive.c]
	Added Device= parameter to drive configuration.

	* [if1632/relay.c]
	Throw() and Catch() now use the correct CATCHBUF layout (untested).

	* [tools/build.c] [include/stackframe.h] [loader/task.c]
	Moved 16-bit stack pointer into thread database.
	Save current %fs while running 16-bit code.

Fri Jan 30 09:25:49 1998  Martin Boehme  <boehme@informatik.mu-luebeck.de>

	* [graphics/mapping.c]
	Made DPtoLP32 and LPtoDP32 respect world transforms.

	* [graphics/path.c] [graphics/painting.c] [if1632/gdi.spec]
	  [include/path.h]
	More path support.

	* [include/gdi.h] [include/windows.h] [objects/dc.c]
	  [relay/gdi32.spec]
	Support for Get/SetArcDirection and Get/SetWorldTransform

	* [windows/hook.c]
	Fixed a bug in HOOK_Map16To32Common.

Thu Jan 29 23:43:18 1998  Douglas Ridgway <ridgway@taiga.gmcl.com>

	* [graphics/metafiledrv/init.c] [objects/metafile.c]
	Documentation for metafile related API calls. Fixed a bug to avoid
	documenting it.

	* [include/windows.h]
	Declaration for LoadImage.

Thu Jan 29 21:44:45 1998  Huw D M Davies <h.davies1@physics.oxford.ac.uk>

	* [graphics/win16drv/*]
	Changes to printing code to enable use of printer fonts with the
	win3.1 postscript driver. Remember to add printer=on to [wine]
	section of wine.conf . You will also need to disable truetype
	fonts from control panel. Winword 6.0 and Write seem to be happy
	with this...

	* [include/bitmap.h]
	Fix Widthbytes for 15bpp displays.

Tue Jan 27 20:54:08 1998  Kristian Nielsen <kristian.nielsen@risoe.dk>

	* [tsx11/*] [include/ts*] [tools/make_X11wrappers]
	Implemented thread-safe X11 wrappers.

Tue Jan 27 13:54:09 1998  Constantine Sapuntzakis  <csapuntz@tma-1.lcs.mit.edu>

	* [windows/queue.c]
	Forgot to convert thdb to thread_id.

	* [misc/registry.c]
	Sped up Windows 95 registry reading. Changed code to traverse
	registry as a tree rather than read in all possible keys
	(including dead ones). 

Tue Jan 27 12:46:09 1998  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>

	* [loader/pe_image.c][Makefile.in][scheduler/thread.c]
	  [libtest/hello5.c]
	Don't exit() on failed to load referenced dlls.
	Fixed static tls allocation for multiple threads.
	WINELIB should now be able to load PE dlls. A sample
	winelib program, that dynamically loads a internal dll
	is included.

	* [graphics/ddraw.c][include/ddraw.h][include/d3d.h]
	Cleaned up and enhanced further. Added several DirectX5
	interface definitions and DirectSurface3 implementation.
	Stubs for D3D (NOT coming soon, just there so it fails safely).

	* [multimedia/dsound.c][include/dsound.h]
	Actually works now for a lot of cases. Some DirectX5 stuff
	added. Still lacking several features.

	* [windows/dinput.c][include/dinput.h]
	Started implementing DirectInput. Doesn't work yet, don't 
	know why.

	* [if1632/thunk.c][misc/callbacks.c]
	  [win32/kernel.c][include/callbacks.h]
	Added WOWCallback16Ex, WOWHandle32.

	* [misc/cpu.c]
	Fixed GetSystemInfo, IsProcessorFeaturePresent.

	* [multimedia/joystick.c][multimedia/time.c]
	Several fixes. Small hack to get timerevents in timeGetTime() loops.

Tue Jan 20 11:26:27 1998  Slaven Rezic  <eserte@cs.tu-berlin.de>

	* [configure.in]
	Fixed check for union semun on FreeBSD systems.

Sun Jan 18 23:05:04 1998  Karl Backström <karl_b@geocities.com>

	* [misc/ole2nls.c] [programs/progman/Sw.rc] [programs/winhelp/Sw.rc]
	  [resources/sysres_Sw.rc]
	Added/updated Swedish language support.

Sun Jan 18 18:49:01 1998  Alex Korobka <alex@trantor.pharm.sunysb.edu>

	* [misc/winsock.c] [misc/winsock_dns.c] [windows/event.c]
	  [windows/win.c] [windows/dce.c] [windows/winpos.c]
	Bug fixes.

Sun Jan 18 12:45:23 1997  Andreas Mohr <100.30936@germany.net>

	* [msdos/int25.c] [msdos/int26.c]
        Implemented "native" absolute disk read/write access.

	* [msdos/int13.c] [msdos/ioports.c]
	Enhanced GET DRIVE PARAMETERS (int13 AH=08).

	* [graphics/win16drv/prtdrv.c] [if1632/gdi.spec]
	Fixed typos, implemented dmEnumDFonts,
	Started implementation of dmRealizeObject.

	* [if1632/compobj.spec] [ole/compobj.c] [relay32/ole32.spec]
	Stubs CoCreateInstance, CoFreeUnusedLibraries, implemented
	CoFileTimeNow.

	* [if1632/kernel.spec] [include/windows.h] [memory/global.c]
	  [memory/string.c] [misc/kernel.c] [misc/Makefile.in]
	  [misc/toolhelp.c] [msdos/int21.c]
	Implemented GlobalHandleNoRIP, GetFreeMemInfo, DebugFillBuffer, 
	stubs GetSetKernelDOSProc, DiagQuery, DiagOutput, ToolHelpHook
	(Undocumented Windows).

	* [if1632/user.spec] [if1632/win32s16.spec] [misc/win32s16.c]
	Misc stubs.

	* [if1632/winaspi.spec] [misc/aspi.c]
	Implemented GetASPIDLLVersion.

	* [if1632/wprocs.spec] [msdos/int20.c] [msdos/Makefile.in]
	Added handler for Int 0x20 (terminate program, _very_ old-fashioned).

	* [misc/w32scomb.c]
	Implemented Get16DLLAddress() partially
	(big thanks to Marcus and Alexandre).

	* [relay32/Makefile.in] [relay32/builtin32.c] [relay32/dplay.spec]
	Added built-in DPLAY.DLL.

	* [relay32/winmm.spec] [multimedia/joystick.c]
	Added joySetThreshold.

	* [misc/windebug.c]
	Added WinNotify.

	* [win32/console.c]
	Stubs CreateConsoleScreenBuffer, SetConsoleActiveScreenBuffer,
	WriteConsoleOutput32A.

	* [windows/user.c]
	Stub SetEventHook.

Sat Jan 17 19:30:35 1998  Matthew Toseland  <Paul.Toseland@btinternet.com>

	* [windows/painting.c]
	Fixed broken restore-to-maximized.

Mon Jan 12 21:25:32 1998  Perceval - Marc Huguet Puig <mhp@tinet.fut.es>

	* [documentation/wine.man] [include/options.h]
	  [misc/main.c] [ole/ole2nls.c] [resources/sysres.c]
	  [resources/sysres_Ca.rc] [resources/Makefile.in]
	Added language catalan. (Afegit l'idioma català).
1998-02-01 18:33:27 +00:00

701 lines
20 KiB
C

/*
* GDI palette objects
*
* Copyright 1993,1994 Alexandre Julliard
* Copyright 1996 Alex Korobka
*
* PALETTEOBJ is documented in the Dr. Dobbs Journal May 1993.
* Information in the "Undocumented Windows" is incorrect.
*/
#include <stdlib.h>
#include <string.h>
#include "ts_xlib.h"
#include "gdi.h"
#include "color.h"
#include "palette.h"
#include "xmalloc.h"
#include "stddebug.h"
/* #define DEBUG_PALETTE */
#include "debug.h"
static UINT32 SystemPaletteUse = SYSPAL_STATIC; /* currently not considered */
static HPALETTE16 hPrimaryPalette = 0; /* used for WM_PALETTECHANGED */
static HPALETTE16 hLastRealizedPalette = 0; /* UnrealizeObject() needs it */
/***********************************************************************
* PALETTE_Init
*
* Create the system palette.
*/
HPALETTE16 PALETTE_Init(void)
{
int i;
HPALETTE16 hpalette;
LOGPALETTE * palPtr;
PALETTEOBJ* palObj;
const PALETTEENTRY* __sysPalTemplate = COLOR_GetSystemPaletteTemplate();
/* create default palette (20 system colors) */
palPtr = HeapAlloc( GetProcessHeap(), 0,
sizeof(LOGPALETTE) + (NB_RESERVED_COLORS-1)*sizeof(PALETTEENTRY));
if (!palPtr) return FALSE;
palPtr->palVersion = 0x300;
palPtr->palNumEntries = NB_RESERVED_COLORS;
for( i = 0; i < NB_RESERVED_COLORS; i ++ )
{
palPtr->palPalEntry[i].peRed = __sysPalTemplate[i].peRed;
palPtr->palPalEntry[i].peGreen = __sysPalTemplate[i].peGreen;
palPtr->palPalEntry[i].peBlue = __sysPalTemplate[i].peBlue;
palPtr->palPalEntry[i].peFlags = 0;
}
hpalette = CreatePalette16( palPtr );
palObj = (PALETTEOBJ*) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
palObj->mapping = xmalloc( sizeof(int) * 20 );
GDI_HEAP_UNLOCK( hpalette );
HeapFree( GetProcessHeap(), 0, palPtr );
return hpalette;
}
/***********************************************************************
* PALETTE_ValidateFlags
*/
void PALETTE_ValidateFlags(PALETTEENTRY* lpPalE, int size)
{
int i = 0;
for( ; i<size ; i++ )
lpPalE[i].peFlags = PC_SYS_USED | (lpPalE[i].peFlags & 0x07);
}
/***********************************************************************
* CreatePalette16 (GDI.360)
*/
HPALETTE16 WINAPI CreatePalette16( const LOGPALETTE* palette )
{
return CreatePalette32( palette );
}
/***********************************************************************
* CreatePalette32 (GDI32.53)
*/
HPALETTE32 WINAPI CreatePalette32( const LOGPALETTE* palette )
{
PALETTEOBJ * palettePtr;
HPALETTE32 hpalette;
int size = sizeof(LOGPALETTE) + (palette->palNumEntries - 1) * sizeof(PALETTEENTRY);
dprintf_palette(stddeb,"CreatePalette: %i entries, ",
palette->palNumEntries);
hpalette = GDI_AllocObject( size + sizeof(int*) +sizeof(GDIOBJHDR) , PALETTE_MAGIC );
if (!hpalette) return 0;
palettePtr = (PALETTEOBJ *) GDI_HEAP_LOCK( hpalette );
memcpy( &palettePtr->logpalette, palette, size );
PALETTE_ValidateFlags(palettePtr->logpalette.palPalEntry,
palettePtr->logpalette.palNumEntries);
palettePtr->mapping = NULL;
GDI_HEAP_UNLOCK( hpalette );
dprintf_palette(stddeb,"returning %04x\n", hpalette);
return hpalette;
}
/***********************************************************************
* CreateHalftonePalette (GDI32.47)
*/
HPALETTE32 WINAPI CreateHalftonePalette(HDC32 hdc)
{
fprintf(stdnimp,"CreateHalftonePalette: empty stub!\n");
return NULL;
}
/***********************************************************************
* GetPaletteEntries16 (GDI.363)
*/
UINT16 WINAPI GetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
UINT16 count, LPPALETTEENTRY entries )
{
return GetPaletteEntries32( hpalette, start, count, entries );
}
/***********************************************************************
* GetPaletteEntries32 (GDI32.209)
*/
UINT32 WINAPI GetPaletteEntries32( HPALETTE32 hpalette, UINT32 start,
UINT32 count, LPPALETTEENTRY entries )
{
PALETTEOBJ * palPtr;
INT32 numEntries;
dprintf_palette( stddeb,"GetPaletteEntries: hpal = %04x, %i entries\n",
hpalette, count );
palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
if (!palPtr) return 0;
numEntries = palPtr->logpalette.palNumEntries;
if (start >= numEntries)
{
GDI_HEAP_UNLOCK( hpalette );
return 0;
}
if (start+count > numEntries) count = numEntries - start;
memcpy( entries, &palPtr->logpalette.palPalEntry[start],
count * sizeof(PALETTEENTRY) );
for( numEntries = 0; numEntries < count ; numEntries++ )
if (entries[numEntries].peFlags & 0xF0)
entries[numEntries].peFlags = 0;
GDI_HEAP_UNLOCK( hpalette );
return count;
}
/***********************************************************************
* SetPaletteEntries16 (GDI.364)
*/
UINT16 WINAPI SetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
UINT16 count, LPPALETTEENTRY entries )
{
return SetPaletteEntries32( hpalette, start, count, entries );
}
/***********************************************************************
* SetPaletteEntries32 (GDI32.326)
*/
UINT32 WINAPI SetPaletteEntries32( HPALETTE32 hpalette, UINT32 start,
UINT32 count, LPPALETTEENTRY entries )
{
PALETTEOBJ * palPtr;
INT32 numEntries;
dprintf_palette( stddeb,"SetPaletteEntries: hpal = %04x, %i entries\n",
hpalette, count );
palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
if (!palPtr) return 0;
numEntries = palPtr->logpalette.palNumEntries;
if (start >= numEntries)
{
GDI_HEAP_UNLOCK( hpalette );
return 0;
}
if (start+count > numEntries) count = numEntries - start;
memcpy( &palPtr->logpalette.palPalEntry[start], entries,
count * sizeof(PALETTEENTRY) );
PALETTE_ValidateFlags(palPtr->logpalette.palPalEntry,
palPtr->logpalette.palNumEntries);
free(palPtr->mapping);
palPtr->mapping = NULL;
GDI_HEAP_UNLOCK( hpalette );
return count;
}
/***********************************************************************
* ResizePalette16 (GDI.368)
*/
BOOL16 WINAPI ResizePalette16( HPALETTE16 hPal, UINT16 cEntries )
{
return ResizePalette32( hPal, cEntries );
}
/***********************************************************************
* ResizePalette32 (GDI32.289)
*/
BOOL32 WINAPI ResizePalette32( HPALETTE32 hPal, UINT32 cEntries )
{
PALETTEOBJ * palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
UINT32 cPrevEnt, prevVer;
int prevsize, size = sizeof(LOGPALETTE) + (cEntries - 1) * sizeof(PALETTEENTRY);
int* mapping = NULL;
dprintf_palette(stddeb,"ResizePalette: hpal = %04x, prev = %i, new = %i\n",
hPal, palPtr ? palPtr->logpalette.palNumEntries : -1,
cEntries );
if( !palPtr ) return FALSE;
cPrevEnt = palPtr->logpalette.palNumEntries;
prevVer = palPtr->logpalette.palVersion;
prevsize = sizeof(LOGPALETTE) + (cPrevEnt - 1) * sizeof(PALETTEENTRY) +
sizeof(int*) + sizeof(GDIOBJHDR);
size += sizeof(int*) + sizeof(GDIOBJHDR);
mapping = palPtr->mapping;
GDI_HEAP_UNLOCK( hPal );
hPal = GDI_HEAP_REALLOC( hPal, size );
palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
if( !palPtr ) return FALSE;
if( mapping )
palPtr->mapping = (int*) xrealloc( mapping, cEntries * sizeof(int) );
if( cEntries > cPrevEnt )
{
if( mapping )
memset(palPtr->mapping + cPrevEnt, 0, (cEntries - cPrevEnt)*sizeof(int));
memset( (BYTE*)palPtr + prevsize, 0, size - prevsize );
PALETTE_ValidateFlags((PALETTEENTRY*)((BYTE*)palPtr + prevsize),
cEntries - cPrevEnt );
}
palPtr->logpalette.palNumEntries = cEntries;
palPtr->logpalette.palVersion = prevVer;
GDI_HEAP_UNLOCK( hPal );
return TRUE;
}
/***********************************************************************
* AnimatePalette16 (GDI.367)
*/
void WINAPI AnimatePalette16( HPALETTE16 hPal, UINT16 StartIndex,
UINT16 NumEntries, LPPALETTEENTRY PaletteColors)
{
AnimatePalette32( hPal, StartIndex, NumEntries, PaletteColors );
}
/***********************************************************************
* AnimatePalette32 (GDI32.6)
*
* FIXME: should use existing mapping when animating a primary palette
*/
BOOL32 WINAPI AnimatePalette32( HPALETTE32 hPal, UINT32 StartIndex,
UINT32 NumEntries, LPPALETTEENTRY PaletteColors)
{
dprintf_palette(stddeb, "AnimatePalette: %04x (%i - %i)", hPal,
StartIndex, StartIndex + NumEntries );
if( hPal != STOCK_DEFAULT_PALETTE )
{
PALETTEOBJ* palPtr = (PALETTEOBJ *)GDI_GetObjPtr(hPal, PALETTE_MAGIC);
if( (StartIndex + NumEntries) <= palPtr->logpalette.palNumEntries )
{
UINT32 u;
for( u = 0; u < NumEntries; u++ )
palPtr->logpalette.palPalEntry[u + StartIndex] = PaletteColors[u];
COLOR_SetMapping(palPtr, StartIndex, NumEntries,
hPal != hPrimaryPalette );
GDI_HEAP_UNLOCK( hPal );
return TRUE;
}
}
return FALSE;
}
/***********************************************************************
* SetSystemPaletteUse16 (GDI.373)
*/
UINT16 WINAPI SetSystemPaletteUse16( HDC16 hdc, UINT16 use )
{
return SetSystemPaletteUse32( hdc, use );
}
/***********************************************************************
* SetSystemPaletteUse32 (GDI32.335)
*/
UINT32 WINAPI SetSystemPaletteUse32( HDC32 hdc, UINT32 use )
{
UINT32 old = SystemPaletteUse;
fprintf( stdnimp,"SetSystemPaletteUse(%04x,%04x) // empty stub !!!\n",
hdc, use );
SystemPaletteUse = use;
return old;
}
/***********************************************************************
* GetSystemPaletteUse16 (GDI.374)
*/
UINT16 WINAPI GetSystemPaletteUse16( HDC16 hdc )
{
return SystemPaletteUse;
}
/***********************************************************************
* GetSystemPaletteUse32 (GDI32.223)
*/
UINT32 WINAPI GetSystemPaletteUse32( HDC32 hdc )
{
return SystemPaletteUse;
}
/***********************************************************************
* GetSystemPaletteEntries16 (GDI.375)
*/
UINT16 WINAPI GetSystemPaletteEntries16( HDC16 hdc, UINT16 start, UINT16 count,
LPPALETTEENTRY entries )
{
return GetSystemPaletteEntries32( hdc, start, count, entries );
}
/***********************************************************************
* GetSystemPaletteEntries32 (GDI32.222)
*/
UINT32 WINAPI GetSystemPaletteEntries32( HDC32 hdc, UINT32 start, UINT32 count,
LPPALETTEENTRY entries )
{
UINT32 i;
DC *dc;
dprintf_palette(stddeb,"GetSystemPaletteEntries: hdc = %04x, cound = %i", hdc, count );
if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return 0;
if (start >= dc->w.devCaps->sizePalette)
{
GDI_HEAP_UNLOCK( hdc );
return 0;
}
if (start+count >= dc->w.devCaps->sizePalette)
count = dc->w.devCaps->sizePalette - start;
for (i = 0; i < count; i++)
{
*(COLORREF*)(entries + i) = COLOR_GetSystemPaletteEntry( start + i );
dprintf_palette( stddeb,"\tidx(%02x) -> RGB(%08lx)\n",
start + i, *(COLORREF*)(entries + i) );
}
GDI_HEAP_UNLOCK( hdc );
return count;
}
/***********************************************************************
* GetNearestPaletteIndex16 (GDI.370)
*/
UINT16 WINAPI GetNearestPaletteIndex16( HPALETTE16 hpalette, COLORREF color )
{
return GetNearestPaletteIndex32( hpalette, color );
}
/***********************************************************************
* GetNearestPaletteIndex32 (GDI32.203)
*/
UINT32 WINAPI GetNearestPaletteIndex32( HPALETTE32 hpalette, COLORREF color )
{
PALETTEOBJ* palObj = (PALETTEOBJ*)GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
UINT32 index = 0;
if( palObj )
index = COLOR_PaletteLookupPixel( palObj->logpalette.palPalEntry,
palObj->logpalette.palNumEntries,
NULL, color, FALSE );
dprintf_palette(stddeb,"GetNearestPaletteIndex(%04x,%06lx): returning %d\n",
hpalette, color, index );
GDI_HEAP_UNLOCK( hpalette );
return index;
}
/***********************************************************************
* GetNearestColor16 (GDI.154)
*/
COLORREF WINAPI GetNearestColor16( HDC16 hdc, COLORREF color )
{
return GetNearestColor32( hdc, color );
}
/***********************************************************************
* GetNearestColor32 (GDI32.202)
*/
COLORREF WINAPI GetNearestColor32( HDC32 hdc, COLORREF color )
{
COLORREF nearest = 0xFADECAFE;
DC *dc;
PALETTEOBJ *palObj;
if ( (dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC )) )
{
palObj = (PALETTEOBJ*)
GDI_GetObjPtr( (dc->w.hPalette)? dc->w.hPalette
: STOCK_DEFAULT_PALETTE, PALETTE_MAGIC );
nearest = COLOR_LookupNearestColor( palObj->logpalette.palPalEntry,
palObj->logpalette.palNumEntries, color );
GDI_HEAP_UNLOCK( dc->w.hPalette );
}
dprintf_palette(stddeb,"GetNearestColor(%06lx): returning %06lx\n",
color, nearest );
GDI_HEAP_UNLOCK( hdc );
return nearest;
}
/***********************************************************************
* PALETTE_GetObject
*/
int PALETTE_GetObject( PALETTEOBJ * palette, int count, LPSTR buffer )
{
if (count > sizeof(WORD)) count = sizeof(WORD);
memcpy( buffer, &palette->logpalette.palNumEntries, count );
return count;
}
/***********************************************************************
* PALETTE_UnrealizeObject
*/
BOOL32 PALETTE_UnrealizeObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
{
if (palette->mapping)
{
free( palette->mapping );
palette->mapping = NULL;
}
if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0;
return TRUE;
}
/***********************************************************************
* PALETTE_DeleteObject
*/
BOOL32 PALETTE_DeleteObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
{
free( palette->mapping );
if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0;
return GDI_FreeObject( hpalette );
}
/***********************************************************************
* GDISelectPalette (GDI.361)
*/
HPALETTE16 WINAPI GDISelectPalette( HDC16 hdc, HPALETTE16 hpal, WORD wBkg)
{
HPALETTE16 prev;
DC *dc;
dprintf_palette(stddeb, "GDISelectPalette: %04x %04x\n", hdc, hpal );
dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
if (!dc)
{
dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
if (!dc) return 0;
}
prev = dc->w.hPalette;
dc->w.hPalette = hpal;
GDI_HEAP_UNLOCK( hdc );
if (!wBkg) hPrimaryPalette = hpal;
return prev;
}
/***********************************************************************
* GDIRealizePalette (GDI.362)
*/
UINT16 WINAPI GDIRealizePalette( HDC16 hdc )
{
PALETTEOBJ* palPtr;
int realized = 0;
DC* dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
if (!dc)
{
dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
if (!dc) return 0;
}
dprintf_palette(stddeb, "GDIRealizePalette: %04x...", hdc );
if( dc && dc->w.hPalette != hLastRealizedPalette )
{
if( dc->w.hPalette == STOCK_DEFAULT_PALETTE )
return RealizeDefaultPalette( hdc );
palPtr = (PALETTEOBJ *) GDI_GetObjPtr( dc->w.hPalette, PALETTE_MAGIC );
realized = COLOR_SetMapping(palPtr,0,palPtr->logpalette.palNumEntries,
(dc->w.hPalette != hPrimaryPalette) ||
(dc->w.hPalette == STOCK_DEFAULT_PALETTE));
GDI_HEAP_UNLOCK( dc->w.hPalette );
hLastRealizedPalette = dc->w.hPalette;
}
else dprintf_palette(stddeb, " skipping (hLastRealizedPalette = %04x) ",
hLastRealizedPalette);
GDI_HEAP_UNLOCK( hdc );
dprintf_palette(stdnimp, " realized %i colors\n", realized );
return (UINT16)realized;
}
/***********************************************************************
* RealizeDefaultPalette (GDI.365)
*/
UINT16 WINAPI RealizeDefaultPalette( HDC16 hdc )
{
DC *dc;
PALETTEOBJ* palPtr;
int i, index, realized = 0;
dprintf_palette(stddeb,"RealizeDefaultPalette: %04x\n", hdc );
dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
if (!dc)
{
dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
if (!dc) return 0;
}
if ( dc->w.flags & DC_MEMORY )
{
GDI_HEAP_UNLOCK( hdc );
return 0;
}
hPrimaryPalette = STOCK_DEFAULT_PALETTE;
hLastRealizedPalette = STOCK_DEFAULT_PALETTE;
palPtr = (PALETTEOBJ*)GDI_GetObjPtr(STOCK_DEFAULT_PALETTE, PALETTE_MAGIC );
/* lookup is needed to account for SetSystemPaletteUse() stuff */
for( i = 0; i < 20; i++ )
{
index = COLOR_LookupSystemPixel(*(COLORREF*)(palPtr->logpalette.palPalEntry + i));
/* mapping is allocated in COLOR_InitPalette() */
if( index != palPtr->mapping[i] ) { palPtr->mapping[i]=index; realized++; }
}
return realized;
}
/***********************************************************************
* IsDCCurrentPalette (GDI.412)
*/
BOOL16 WINAPI IsDCCurrentPalette(HDC16 hDC)
{
DC* dc = (DC *)GDI_GetObjPtr( hDC, DC_MAGIC );
if (dc)
{
GDI_HEAP_UNLOCK( hDC );
return dc->w.hPalette == hPrimaryPalette;
}
return FALSE;
}
/***********************************************************************
* SelectPalette16 (USER.282)
*/
HPALETTE16 WINAPI SelectPalette16( HDC16 hDC, HPALETTE16 hPal,
BOOL16 bForceBackground )
{
return SelectPalette32( hDC, hPal, bForceBackground );
}
/***********************************************************************
* SelectPalette32 (GDI32.300)
*/
HPALETTE32 WINAPI SelectPalette32( HDC32 hDC, HPALETTE32 hPal,
BOOL32 bForceBackground )
{
WORD wBkgPalette = 1;
PALETTEOBJ* lpt = (PALETTEOBJ*) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
dprintf_palette(stddeb,"SelectPalette: dc %04x pal %04x, force=%i ",
hDC, hPal, bForceBackground);
if( !lpt ) return 0;
dprintf_palette(stddeb," entries = %d\n",
lpt->logpalette.palNumEntries);
GDI_HEAP_UNLOCK( hPal );
if( hPal != STOCK_DEFAULT_PALETTE )
{
HWND32 hWnd = WindowFromDC32( hDC );
HWND32 hActive = GetActiveWindow32();
/* set primary palette if it's related to current active */
if((!hWnd || (hActive == hWnd || IsChild16(hActive,hWnd))) &&
!bForceBackground )
wBkgPalette = 0;
}
return GDISelectPalette( hDC, hPal, wBkgPalette);
}
/***********************************************************************
* RealizePalette16 (USER.283)
*/
UINT16 WINAPI RealizePalette16( HDC16 hDC )
{
return RealizePalette32( hDC );
}
/***********************************************************************
* RealizePalette32 (GDI32.280)
*/
UINT32 WINAPI RealizePalette32( HDC32 hDC )
{
UINT32 realized = GDIRealizePalette( hDC );
/* do not send anything if no colors were changed */
if( IsDCCurrentPalette( hDC ) && realized &&
!(COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL) )
{
/* Send palette change notification */
HWND32 hWnd;
if( (hWnd = WindowFromDC32( hDC )) )
SendMessage16( HWND_BROADCAST, WM_PALETTECHANGED, hWnd, 0L);
}
return realized;
}
/**********************************************************************
* UpdateColors16 (GDI.366)
*/
INT16 WINAPI UpdateColors16( HDC16 hDC )
{
HWND32 hWnd = WindowFromDC32( hDC );
/* Docs say that we have to remap current drawable pixel by pixel
* but it would take forever given the speed of XGet/PutPixel.
*/
if (hWnd && !(COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL) )
InvalidateRect32( hWnd, NULL, FALSE );
return 0x666;
}
/**********************************************************************
* UpdateColors32 (GDI32.359)
*/
BOOL32 WINAPI UpdateColors32( HDC32 hDC )
{
UpdateColors16( hDC );
return TRUE;
}