blob: 764e9aaa647df71334964717b45e329bcea887b8 [file] [log] [blame]
Alexandre Julliard401710d1993-09-04 10:09:32 +00001/*
2 * GDI palette objects
3 *
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00004 * Copyright 1993,1994 Alexandre Julliard
Alexandre Julliard18f92e71996-07-17 20:02:21 +00005 * Copyright 1996 Alex Korobka
Alexandre Julliard234bc241994-12-10 13:02:28 +00006 *
Alexandre Julliard23946ad1997-06-16 17:43:53 +00007 * PALETTEOBJ is documented in the Dr. Dobbs Journal May 1993.
8 * Information in the "Undocumented Windows" is incorrect.
Alexandre Julliard59730ae1996-03-24 16:20:51 +00009 */
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000010
Alexandre Julliard401710d1993-09-04 10:09:32 +000011#include <stdlib.h>
Alexandre Julliard8d24ae61994-04-05 21:42:43 +000012#include <string.h>
Patrik Stridvallb87fe2e1999-04-01 08:16:08 +000013
Michael Veksler92ae2191999-05-02 11:39:09 +000014#include "winbase.h"
Jeremy Whited3e22d92000-02-10 19:03:02 +000015#include "windef.h"
16#include "wingdi.h"
Michael Veksler92ae2191999-05-02 11:39:09 +000017#include "wine/winuser16.h"
Alexandre Julliard75d86e11996-11-17 18:59:11 +000018#include "gdi.h"
Alexandre Julliard234bc241994-12-10 13:02:28 +000019#include "color.h"
Alexandre Julliard7cbe6571995-01-09 18:21:16 +000020#include "palette.h"
Alexandre Julliard15657091999-05-23 10:25:25 +000021#include "debugtools.h"
Alexandre Julliard946a4442000-07-30 13:50:27 +000022#include "callback.h"
Ian Schmidt31b47211999-09-22 15:12:41 +000023#include "winerror.h"
Alexandre Julliard401710d1993-09-04 10:09:32 +000024
Alexandre Julliard39932162000-09-16 20:57:39 +000025DEFAULT_DEBUG_CHANNEL(palette);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000026
Patrik Stridvallb87fe2e1999-04-01 08:16:08 +000027PALETTE_DRIVER *PALETTE_Driver = NULL;
28
Alexandre Julliard39932162000-09-16 20:57:39 +000029/* Pointers to USER implementation of SelectPalette/RealizePalette */
30/* they will be patched by USER on startup */
Alexandre Julliarda3960291999-02-26 11:11:13 +000031FARPROC pfnSelectPalette = NULL;
32FARPROC pfnRealizePalette = NULL;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000033
Alexandre Julliarda3960291999-02-26 11:11:13 +000034static UINT SystemPaletteUse = SYSPAL_STATIC; /* currently not considered */
Alexandre Julliarda2f2e011995-06-06 16:40:35 +000035
Alexandre Julliard18f92e71996-07-17 20:02:21 +000036static HPALETTE16 hPrimaryPalette = 0; /* used for WM_PALETTECHANGED */
37static HPALETTE16 hLastRealizedPalette = 0; /* UnrealizeObject() needs it */
38
Alexandre Julliard902da691995-11-05 14:39:02 +000039
40/***********************************************************************
Alexandre Julliard23946ad1997-06-16 17:43:53 +000041 * PALETTE_Init
42 *
43 * Create the system palette.
44 */
45HPALETTE16 PALETTE_Init(void)
46{
Alexandre Julliard23946ad1997-06-16 17:43:53 +000047 int i;
48 HPALETTE16 hpalette;
49 LOGPALETTE * palPtr;
50 PALETTEOBJ* palObj;
51 const PALETTEENTRY* __sysPalTemplate = COLOR_GetSystemPaletteTemplate();
52
53 /* create default palette (20 system colors) */
54
Alexandre Julliard491502b1997-11-01 19:08:16 +000055 palPtr = HeapAlloc( GetProcessHeap(), 0,
56 sizeof(LOGPALETTE) + (NB_RESERVED_COLORS-1)*sizeof(PALETTEENTRY));
Alexandre Julliard23946ad1997-06-16 17:43:53 +000057 if (!palPtr) return FALSE;
58
59 palPtr->palVersion = 0x300;
60 palPtr->palNumEntries = NB_RESERVED_COLORS;
61 for( i = 0; i < NB_RESERVED_COLORS; i ++ )
62 {
63 palPtr->palPalEntry[i].peRed = __sysPalTemplate[i].peRed;
64 palPtr->palPalEntry[i].peGreen = __sysPalTemplate[i].peGreen;
65 palPtr->palPalEntry[i].peBlue = __sysPalTemplate[i].peBlue;
66 palPtr->palPalEntry[i].peFlags = 0;
67 }
68 hpalette = CreatePalette16( palPtr );
Dimitrie O. Paun9ad96362000-03-19 14:29:50 +000069 HeapFree( GetProcessHeap(), 0, palPtr );
Alexandre Julliard23946ad1997-06-16 17:43:53 +000070
71 palObj = (PALETTEOBJ*) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
Juergen Schmied58b2f0a1999-01-23 12:09:30 +000072 if (palObj)
73 {
Dimitrie O. Paun9ad96362000-03-19 14:29:50 +000074 if (!(palObj->mapping = HeapAlloc( GetProcessHeap(), 0, sizeof(int) * 20 )))
75 ERR("Can not create palette mapping -- out of memory!");
Alexandre Julliard2a2321b2000-08-19 21:38:55 +000076 GDI_ReleaseObj( hpalette );
Juergen Schmied58b2f0a1999-01-23 12:09:30 +000077 }
Alexandre Julliard23946ad1997-06-16 17:43:53 +000078 return hpalette;
79}
80
81/***********************************************************************
Alexandre Julliard18f92e71996-07-17 20:02:21 +000082 * PALETTE_ValidateFlags
83 */
84void PALETTE_ValidateFlags(PALETTEENTRY* lpPalE, int size)
85{
86 int i = 0;
87 for( ; i<size ; i++ )
88 lpPalE[i].peFlags = PC_SYS_USED | (lpPalE[i].peFlags & 0x07);
89}
90
91
92/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000093 * CreatePalette16 (GDI.360)
Alexandre Julliard401710d1993-09-04 10:09:32 +000094 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +000095HPALETTE16 WINAPI CreatePalette16( const LOGPALETTE* palette )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000096{
Alexandre Julliarda3960291999-02-26 11:11:13 +000097 return CreatePalette( palette );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000098}
99
100
101/***********************************************************************
Alexandre Julliarda7116b02000-03-28 20:02:37 +0000102 * CreatePalette [GDI32.53] Creates a logical color palette
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000103 *
104 * RETURNS
105 * Success: Handle to logical palette
106 * Failure: NULL
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000107 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000108HPALETTE WINAPI CreatePalette(
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000109 const LOGPALETTE* palette) /* [in] Pointer to logical color palette */
Alexandre Julliard401710d1993-09-04 10:09:32 +0000110{
111 PALETTEOBJ * palettePtr;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000112 HPALETTE hpalette;
Juergen Schmiedc5096151998-11-22 16:16:58 +0000113 int size;
114
115 if (!palette) return 0;
Alexandre Julliard15657091999-05-23 10:25:25 +0000116 TRACE("entries=%i\n", palette->palNumEntries);
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000117
Juergen Schmiedc5096151998-11-22 16:16:58 +0000118 size = sizeof(LOGPALETTE) + (palette->palNumEntries - 1) * sizeof(PALETTEENTRY);
119
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000120 if (!(palettePtr = GDI_AllocObject( size + sizeof(int*) +sizeof(GDIOBJHDR),
121 PALETTE_MAGIC, &hpalette ))) return 0;
Alexandre Julliard401710d1993-09-04 10:09:32 +0000122 memcpy( &palettePtr->logpalette, palette, size );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000123 PALETTE_ValidateFlags(palettePtr->logpalette.palPalEntry,
124 palettePtr->logpalette.palNumEntries);
125 palettePtr->mapping = NULL;
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000126 GDI_ReleaseObj( hpalette );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000127
Alexandre Julliard15657091999-05-23 10:25:25 +0000128 TRACE(" returning %04x\n", hpalette);
Alexandre Julliard401710d1993-09-04 10:09:32 +0000129 return hpalette;
130}
131
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000132
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000133/***********************************************************************
Brad Pepers0bdff361999-02-09 15:37:16 +0000134 * CreateHalftonePalette16 [GDI.?] Creates a halftone palette
135 *
136 * RETURNS
137 * Success: Handle to logical halftone palette
138 * Failure: 0
139 */
140HPALETTE16 WINAPI CreateHalftonePalette16(
141 HDC16 hdc) /* [in] Handle to device context */
142{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000143 return CreateHalftonePalette(hdc);
Patrik Stridvallb87fe2e1999-04-01 08:16:08 +0000144}
Brad Pepers0bdff361999-02-09 15:37:16 +0000145
146
147/***********************************************************************
Alexandre Julliarda7116b02000-03-28 20:02:37 +0000148 * CreateHalftonePalette [GDI32.47] Creates a halftone palette
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000149 *
150 * RETURNS
151 * Success: Handle to logical halftone palette
152 * Failure: 0
Juergen Schmied58b2f0a1999-01-23 12:09:30 +0000153 *
154 * FIXME: not truly tested
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000155 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000156HPALETTE WINAPI CreateHalftonePalette(
157 HDC hdc) /* [in] Handle to device context */
Brad Pepers0bdff361999-02-09 15:37:16 +0000158{
159 int i, r, g, b;
160 struct {
161 WORD Version;
162 WORD NumberOfEntries;
163 PALETTEENTRY aEntries[256];
Patrik Stridvallf87b96e2000-10-24 02:20:31 +0000164 } Palette;
Juergen Schmied58b2f0a1999-01-23 12:09:30 +0000165
Patrik Stridvallf87b96e2000-10-24 02:20:31 +0000166 Palette.Version = 0x300;
167 Palette.NumberOfEntries = 256;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000168 GetSystemPaletteEntries(hdc, 0, 256, Palette.aEntries);
Juergen Schmied58b2f0a1999-01-23 12:09:30 +0000169
Brad Pepers0bdff361999-02-09 15:37:16 +0000170 for (r = 0; r < 6; r++) {
171 for (g = 0; g < 6; g++) {
172 for (b = 0; b < 6; b++) {
173 i = r + g*6 + b*36 + 10;
174 Palette.aEntries[i].peRed = r * 51;
175 Palette.aEntries[i].peGreen = g * 51;
176 Palette.aEntries[i].peBlue = b * 51;
Juergen Schmied58b2f0a1999-01-23 12:09:30 +0000177 }
178 }
179 }
Juergen Schmied58b2f0a1999-01-23 12:09:30 +0000180
Brad Pepers0bdff361999-02-09 15:37:16 +0000181 for (i = 216; i < 246; i++) {
182 int v = (i - 216) * 8;
183 Palette.aEntries[i].peRed = v;
184 Palette.aEntries[i].peGreen = v;
185 Palette.aEntries[i].peBlue = v;
Juergen Schmied58b2f0a1999-01-23 12:09:30 +0000186 }
187
Alexandre Julliarda3960291999-02-26 11:11:13 +0000188 return CreatePalette((LOGPALETTE *)&Palette);
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000189}
Alexandre Julliard401710d1993-09-04 10:09:32 +0000190
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000191
Alexandre Julliard401710d1993-09-04 10:09:32 +0000192/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000193 * GetPaletteEntries16 (GDI.363)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000194 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000195UINT16 WINAPI GetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
196 UINT16 count, LPPALETTEENTRY entries )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000197{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000198 return GetPaletteEntries( hpalette, start, count, entries );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000199}
200
201
202/***********************************************************************
Alexandre Julliarda7116b02000-03-28 20:02:37 +0000203 * GetPaletteEntries [GDI32.209] Retrieves palette entries
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000204 *
205 * RETURNS
206 * Success: Number of entries from logical palette
207 * Failure: 0
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000208 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000209UINT WINAPI GetPaletteEntries(
210 HPALETTE hpalette, /* [in] Handle of logical palette */
211 UINT start, /* [in] First entry to receive */
212 UINT count, /* [in] Number of entries to receive */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000213 LPPALETTEENTRY entries) /* [out] Address of array receiving entries */
Alexandre Julliard401710d1993-09-04 10:09:32 +0000214{
215 PALETTEOBJ * palPtr;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000216 INT numEntries;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000217
Alexandre Julliard15657091999-05-23 10:25:25 +0000218 TRACE("hpal = %04x, count=%i\n", hpalette, count );
Alexandre Julliard401710d1993-09-04 10:09:32 +0000219
220 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
221 if (!palPtr) return 0;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000222
Alexandre Julliard401710d1993-09-04 10:09:32 +0000223 numEntries = palPtr->logpalette.palNumEntries;
Alexandre Julliard401710d1993-09-04 10:09:32 +0000224 if (start+count > numEntries) count = numEntries - start;
Alexandre Julliard829fe321998-07-26 14:27:39 +0000225 if (entries)
226 {
227 if (start >= numEntries)
228 {
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000229 GDI_ReleaseObj( hpalette );
Alexandre Julliard829fe321998-07-26 14:27:39 +0000230 return 0;
231 }
232 memcpy( entries, &palPtr->logpalette.palPalEntry[start],
233 count * sizeof(PALETTEENTRY) );
234 for( numEntries = 0; numEntries < count ; numEntries++ )
235 if (entries[numEntries].peFlags & 0xF0)
236 entries[numEntries].peFlags = 0;
Alexandre Julliard829fe321998-07-26 14:27:39 +0000237 }
238
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000239 GDI_ReleaseObj( hpalette );
Alexandre Julliard401710d1993-09-04 10:09:32 +0000240 return count;
241}
242
243
244/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000245 * SetPaletteEntries16 (GDI.364)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000246 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000247UINT16 WINAPI SetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
248 UINT16 count, LPPALETTEENTRY entries )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000249{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000250 return SetPaletteEntries( hpalette, start, count, entries );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000251}
252
253
254/***********************************************************************
Alexandre Julliarda7116b02000-03-28 20:02:37 +0000255 * SetPaletteEntries [GDI32.326] Sets color values for range in palette
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000256 *
257 * RETURNS
258 * Success: Number of entries that were set
259 * Failure: 0
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000260 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000261UINT WINAPI SetPaletteEntries(
262 HPALETTE hpalette, /* [in] Handle of logical palette */
263 UINT start, /* [in] Index of first entry to set */
264 UINT count, /* [in] Number of entries to set */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000265 LPPALETTEENTRY entries) /* [in] Address of array of structures */
Alexandre Julliard401710d1993-09-04 10:09:32 +0000266{
267 PALETTEOBJ * palPtr;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000268 INT numEntries;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000269
Alexandre Julliard15657091999-05-23 10:25:25 +0000270 TRACE("hpal=%04x,start=%i,count=%i\n",hpalette,start,count );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000271
Alexandre Julliard401710d1993-09-04 10:09:32 +0000272 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
273 if (!palPtr) return 0;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000274
Alexandre Julliard401710d1993-09-04 10:09:32 +0000275 numEntries = palPtr->logpalette.palNumEntries;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000276 if (start >= numEntries)
277 {
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000278 GDI_ReleaseObj( hpalette );
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000279 return 0;
280 }
Alexandre Julliard401710d1993-09-04 10:09:32 +0000281 if (start+count > numEntries) count = numEntries - start;
282 memcpy( &palPtr->logpalette.palPalEntry[start], entries,
283 count * sizeof(PALETTEENTRY) );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000284 PALETTE_ValidateFlags(palPtr->logpalette.palPalEntry,
285 palPtr->logpalette.palNumEntries);
Alexandre Julliarda7116b02000-03-28 20:02:37 +0000286 HeapFree( GetProcessHeap(), 0, palPtr->mapping );
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000287 palPtr->mapping = NULL;
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000288 GDI_ReleaseObj( hpalette );
Alexandre Julliard401710d1993-09-04 10:09:32 +0000289 return count;
290}
291
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000292
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000293/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000294 * ResizePalette16 (GDI.368)
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000295 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000296BOOL16 WINAPI ResizePalette16( HPALETTE16 hPal, UINT16 cEntries )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000297{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000298 return ResizePalette( hPal, cEntries );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000299}
300
301
302/***********************************************************************
Alexandre Julliarda7116b02000-03-28 20:02:37 +0000303 * ResizePalette [GDI32.289] Resizes logical palette
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000304 *
305 * RETURNS
306 * Success: TRUE
307 * Failure: FALSE
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000308 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000309BOOL WINAPI ResizePalette(
310 HPALETTE hPal, /* [in] Handle of logical palette */
311 UINT cEntries) /* [in] Number of entries in logical palette */
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000312{
Alexandre Julliard75d86e11996-11-17 18:59:11 +0000313 PALETTEOBJ * palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000314 UINT cPrevEnt, prevVer;
Alexandre Julliard75d86e11996-11-17 18:59:11 +0000315 int prevsize, size = sizeof(LOGPALETTE) + (cEntries - 1) * sizeof(PALETTEENTRY);
316 int* mapping = NULL;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000317
Alexandre Julliard15657091999-05-23 10:25:25 +0000318 TRACE("hpal = %04x, prev = %i, new = %i\n",
Alexandre Julliard889f7421997-04-15 17:19:52 +0000319 hPal, palPtr ? palPtr->logpalette.palNumEntries : -1,
320 cEntries );
Alexandre Julliard75d86e11996-11-17 18:59:11 +0000321 if( !palPtr ) return FALSE;
322 cPrevEnt = palPtr->logpalette.palNumEntries;
323 prevVer = palPtr->logpalette.palVersion;
324 prevsize = sizeof(LOGPALETTE) + (cPrevEnt - 1) * sizeof(PALETTEENTRY) +
325 sizeof(int*) + sizeof(GDIOBJHDR);
326 size += sizeof(int*) + sizeof(GDIOBJHDR);
327 mapping = palPtr->mapping;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000328
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000329 if (!(palPtr = GDI_ReallocObject( size, hPal, palPtr ))) return FALSE;
Alexandre Julliard75d86e11996-11-17 18:59:11 +0000330
Dimitrie O. Paun9ad96362000-03-19 14:29:50 +0000331 if( mapping )
332 {
333 int *newMap = (int*) HeapReAlloc(GetProcessHeap(), 0,
334 mapping, cEntries * sizeof(int) );
335 if(newMap == NULL)
336 {
337 ERR("Can not resize mapping -- out of memory!");
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000338 GDI_ReleaseObj( hPal );
Dimitrie O. Paun9ad96362000-03-19 14:29:50 +0000339 return FALSE;
340 }
341 palPtr->mapping = newMap;
342 }
343
Alexandre Julliard75d86e11996-11-17 18:59:11 +0000344 if( cEntries > cPrevEnt )
345 {
346 if( mapping )
347 memset(palPtr->mapping + cPrevEnt, 0, (cEntries - cPrevEnt)*sizeof(int));
348 memset( (BYTE*)palPtr + prevsize, 0, size - prevsize );
349 PALETTE_ValidateFlags((PALETTEENTRY*)((BYTE*)palPtr + prevsize),
350 cEntries - cPrevEnt );
351 }
352 palPtr->logpalette.palNumEntries = cEntries;
353 palPtr->logpalette.palVersion = prevVer;
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000354 GDI_ReleaseObj( hPal );
Alexandre Julliard75d86e11996-11-17 18:59:11 +0000355 return TRUE;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000356}
357
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000358
Alexandre Julliardade697e1995-11-26 13:59:11 +0000359/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000360 * AnimatePalette16 (GDI.367)
Alexandre Julliardade697e1995-11-26 13:59:11 +0000361 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000362void WINAPI AnimatePalette16( HPALETTE16 hPal, UINT16 StartIndex,
François Gouget241c7301998-10-28 10:47:09 +0000363 UINT16 NumEntries, const PALETTEENTRY* PaletteColors)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000364{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000365 AnimatePalette( hPal, StartIndex, NumEntries, PaletteColors );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000366}
367
368
369/***********************************************************************
Alexandre Julliarda7116b02000-03-28 20:02:37 +0000370 * AnimatePalette [GDI32.6] Replaces entries in logical palette
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000371 *
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000372 * RETURNS
373 * Success: TRUE
374 * Failure: FALSE
375 *
376 * FIXME
377 * Should use existing mapping when animating a primary palette
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000378 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000379BOOL WINAPI AnimatePalette(
380 HPALETTE hPal, /* [in] Handle to logical palette */
381 UINT StartIndex, /* [in] First entry in palette */
382 UINT NumEntries, /* [in] Count of entries in palette */
François Gouget241c7301998-10-28 10:47:09 +0000383 const PALETTEENTRY* PaletteColors) /* [in] Pointer to first replacement */
Alexandre Julliardade697e1995-11-26 13:59:11 +0000384{
Alexandre Julliard15657091999-05-23 10:25:25 +0000385 TRACE("%04x (%i - %i)\n", hPal, StartIndex,StartIndex+NumEntries);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000386
Alexandre Julliard4c186362000-10-29 01:22:15 +0000387 if( hPal != GetStockObject(DEFAULT_PALETTE) )
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000388 {
389 PALETTEOBJ* palPtr = (PALETTEOBJ *)GDI_GetObjPtr(hPal, PALETTE_MAGIC);
Juergen Schmied58b2f0a1999-01-23 12:09:30 +0000390 if (!palPtr) return FALSE;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000391
Alexandre Julliard02e90081998-01-04 17:49:09 +0000392 if( (StartIndex + NumEntries) <= palPtr->logpalette.palNumEntries )
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000393 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000394 UINT u;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000395 for( u = 0; u < NumEntries; u++ )
396 palPtr->logpalette.palPalEntry[u + StartIndex] = PaletteColors[u];
Patrik Stridvallb87fe2e1999-04-01 08:16:08 +0000397 PALETTE_Driver->
398 pSetMapping(palPtr, StartIndex, NumEntries,
399 hPal != hPrimaryPalette );
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000400 GDI_ReleaseObj( hPal );
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000401 return TRUE;
402 }
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000403 GDI_ReleaseObj( hPal );
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000404 }
405 return FALSE;
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000406}
Alexandre Julliard401710d1993-09-04 10:09:32 +0000407
Alexandre Julliarda2f2e011995-06-06 16:40:35 +0000408
409/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000410 * SetSystemPaletteUse16 (GDI.373)
Alexandre Julliard2787be81995-05-22 18:23:01 +0000411 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000412UINT16 WINAPI SetSystemPaletteUse16( HDC16 hdc, UINT16 use )
Alexandre Julliard2787be81995-05-22 18:23:01 +0000413{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000414 return SetSystemPaletteUse( hdc, use );
Alexandre Julliard2787be81995-05-22 18:23:01 +0000415}
416
417
418/***********************************************************************
Alexandre Julliarda7116b02000-03-28 20:02:37 +0000419 * SetSystemPaletteUse [GDI32.335]
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000420 *
421 * RETURNS
422 * Success: Previous system palette
423 * Failure: SYSPAL_ERROR
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000424 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000425UINT WINAPI SetSystemPaletteUse(
426 HDC hdc, /* [in] Handle of device context */
427 UINT use) /* [in] Palette-usage flag */
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000428{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000429 UINT old = SystemPaletteUse;
Alexandre Julliard15657091999-05-23 10:25:25 +0000430 FIXME("(%04x,%04x): stub\n", hdc, use );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000431 SystemPaletteUse = use;
432 return old;
433}
434
435
436/***********************************************************************
437 * GetSystemPaletteUse16 (GDI.374)
438 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000439UINT16 WINAPI GetSystemPaletteUse16( HDC16 hdc )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000440{
441 return SystemPaletteUse;
442}
443
444
445/***********************************************************************
Alexandre Julliarda7116b02000-03-28 20:02:37 +0000446 * GetSystemPaletteUse [GDI32.223] Gets state of system palette
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000447 *
448 * RETURNS
449 * Current state of system palette
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000450 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000451UINT WINAPI GetSystemPaletteUse(
452 HDC hdc) /* [in] Handle of device context */
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000453{
454 return SystemPaletteUse;
455}
456
457
458/***********************************************************************
459 * GetSystemPaletteEntries16 (GDI.375)
460 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000461UINT16 WINAPI GetSystemPaletteEntries16( HDC16 hdc, UINT16 start, UINT16 count,
462 LPPALETTEENTRY entries )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000463{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000464 return GetSystemPaletteEntries( hdc, start, count, entries );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000465}
466
467
468/***********************************************************************
Alexandre Julliarda7116b02000-03-28 20:02:37 +0000469 * GetSystemPaletteEntries [GDI32.222] Gets range of palette entries
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000470 *
471 * RETURNS
472 * Success: Number of entries retrieved from palette
473 * Failure: 0
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000474 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000475UINT WINAPI GetSystemPaletteEntries(
476 HDC hdc, /* [in] Handle of device context */
477 UINT start, /* [in] Index of first entry to be retrieved */
478 UINT count, /* [in] Number of entries to be retrieved */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000479 LPPALETTEENTRY entries) /* [out] Array receiving system-palette entries */
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000480{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000481 UINT i;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000482 DC *dc;
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000483
Alexandre Julliard15657091999-05-23 10:25:25 +0000484 TRACE("hdc=%04x,start=%i,count=%i\n", hdc,start,count);
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000485
Alexandre Julliard2239abb2000-11-05 02:05:07 +0000486 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000487
488 if (!entries)
489 {
Alexandre Julliard2239abb2000-11-05 02:05:07 +0000490 count = dc->devCaps->sizePalette;
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000491 goto done;
492 }
493
Alexandre Julliard2239abb2000-11-05 02:05:07 +0000494 if (start >= dc->devCaps->sizePalette)
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000495 {
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000496 count = 0;
497 goto done;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000498 }
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000499
Alexandre Julliard2239abb2000-11-05 02:05:07 +0000500 if (start+count >= dc->devCaps->sizePalette)
501 count = dc->devCaps->sizePalette - start;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000502 for (i = 0; i < count; i++)
503 {
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000504 *(COLORREF*)(entries + i) = COLOR_GetSystemPaletteEntry( start + i );
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000505
Alexandre Julliard15657091999-05-23 10:25:25 +0000506 TRACE("\tidx(%02x) -> RGB(%08lx)\n",
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000507 start + i, *(COLORREF*)(entries + i) );
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000508 }
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000509 done:
510 GDI_ReleaseObj( hdc );
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000511 return count;
512}
513
514
515/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000516 * GetNearestPaletteIndex16 (GDI.370)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000517 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000518UINT16 WINAPI GetNearestPaletteIndex16( HPALETTE16 hpalette, COLORREF color )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000519{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000520 return GetNearestPaletteIndex( hpalette, color );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000521}
522
523
524/***********************************************************************
Alexandre Julliarda7116b02000-03-28 20:02:37 +0000525 * GetNearestPaletteIndex [GDI32.203] Gets palette index for color
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000526 *
527 * NOTES
528 * Should index be initialized to CLR_INVALID instead of 0?
529 *
530 * RETURNS
531 * Success: Index of entry in logical palette
532 * Failure: CLR_INVALID
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000533 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000534UINT WINAPI GetNearestPaletteIndex(
535 HPALETTE hpalette, /* [in] Handle of logical color palette */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000536 COLORREF color) /* [in] Color to be matched */
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000537{
538 PALETTEOBJ* palObj = (PALETTEOBJ*)GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000539 UINT index = 0;
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000540
541 if( palObj )
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000542 {
Patrik Stridvallb87fe2e1999-04-01 08:16:08 +0000543 index = COLOR_PaletteLookupPixel(palObj->logpalette.palPalEntry,
544 palObj->logpalette.palNumEntries,
545 NULL, color, FALSE );
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000546
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000547 GDI_ReleaseObj( hpalette );
548 }
Alexandre Julliard15657091999-05-23 10:25:25 +0000549 TRACE("(%04x,%06lx): returning %d\n", hpalette, color, index );
Alexandre Julliard401710d1993-09-04 10:09:32 +0000550 return index;
551}
552
553
554/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000555 * GetNearestColor16 (GDI.154)
Alexandre Julliard902da691995-11-05 14:39:02 +0000556 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000557COLORREF WINAPI GetNearestColor16( HDC16 hdc, COLORREF color )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000558{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000559 return GetNearestColor( hdc, color );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000560}
561
562
563/***********************************************************************
Alexandre Julliarda7116b02000-03-28 20:02:37 +0000564 * GetNearestColor [GDI32.202] Gets a system color to match
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000565 *
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000566 * RETURNS
567 * Success: Color from system palette that corresponds to given color
568 * Failure: CLR_INVALID
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000569 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000570COLORREF WINAPI GetNearestColor(
571 HDC hdc, /* [in] Handle of device context */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000572 COLORREF color) /* [in] Color to be matched */
Alexandre Julliard902da691995-11-05 14:39:02 +0000573{
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000574 COLORREF nearest = CLR_INVALID;
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000575 DC *dc;
576 PALETTEOBJ *palObj;
Alexandre Julliard902da691995-11-05 14:39:02 +0000577
Alexandre Julliard2239abb2000-11-05 02:05:07 +0000578 if ( (dc = DC_GetDCPtr( hdc )) )
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000579 {
Alexandre Julliard2239abb2000-11-05 02:05:07 +0000580 HPALETTE hpal = (dc->hPalette)? dc->hPalette : GetStockObject( DEFAULT_PALETTE );
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000581 palObj = GDI_GetObjPtr( hpal, PALETTE_MAGIC );
582 if (!palObj) {
583 GDI_ReleaseObj( hdc );
584 return nearest;
585 }
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000586
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000587 nearest = COLOR_LookupNearestColor( palObj->logpalette.palPalEntry,
588 palObj->logpalette.palNumEntries, color );
589 GDI_ReleaseObj( hpal );
590 GDI_ReleaseObj( hdc );
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000591 }
592
Alexandre Julliard15657091999-05-23 10:25:25 +0000593 TRACE("(%06lx): returning %06lx\n", color, nearest );
Alexandre Julliard902da691995-11-05 14:39:02 +0000594 return nearest;
595}
596
597
598/***********************************************************************
Alexandre Julliard401710d1993-09-04 10:09:32 +0000599 * PALETTE_GetObject
600 */
601int PALETTE_GetObject( PALETTEOBJ * palette, int count, LPSTR buffer )
602{
603 if (count > sizeof(WORD)) count = sizeof(WORD);
604 memcpy( buffer, &palette->logpalette.palNumEntries, count );
605 return count;
606}
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000607
608
609/***********************************************************************
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000610 * PALETTE_UnrealizeObject
611 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000612BOOL PALETTE_UnrealizeObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000613{
614 if (palette->mapping)
615 {
Alexandre Julliarda7116b02000-03-28 20:02:37 +0000616 HeapFree( GetProcessHeap(), 0, palette->mapping );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000617 palette->mapping = NULL;
618 }
619 if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0;
620 return TRUE;
621}
622
623
624/***********************************************************************
625 * PALETTE_DeleteObject
626 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000627BOOL PALETTE_DeleteObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000628{
Alexandre Julliarda7116b02000-03-28 20:02:37 +0000629 HeapFree( GetProcessHeap(), 0, palette->mapping );
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000630 if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0;
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000631 return GDI_FreeObject( hpalette, palette );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000632}
633
634
635/***********************************************************************
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000636 * GDISelectPalette (GDI.361)
637 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000638HPALETTE16 WINAPI GDISelectPalette16( HDC16 hdc, HPALETTE16 hpal, WORD wBkg)
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000639{
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000640 HPALETTE16 prev;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000641 DC *dc;
642
Alexandre Julliard15657091999-05-23 10:25:25 +0000643 TRACE("%04x %04x\n", hdc, hpal );
Alexandre Julliard39932162000-09-16 20:57:39 +0000644
Andreas Mohrea8795b2000-09-29 01:03:57 +0000645 if (GetObjectType(hpal) != OBJ_PAL)
Alexandre Julliard39932162000-09-16 20:57:39 +0000646 {
647 WARN("invalid selected palette %04x\n",hpal);
648 return 0;
649 }
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000650 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
Alexandre Julliard2239abb2000-11-05 02:05:07 +0000651 prev = dc->hPalette;
652 dc->hPalette = hpal;
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000653 GDI_ReleaseObj( hdc );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000654 if (!wBkg) hPrimaryPalette = hpal;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000655 return prev;
656}
657
658
659/***********************************************************************
660 * GDIRealizePalette (GDI.362)
661 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000662UINT16 WINAPI GDIRealizePalette16( HDC16 hdc )
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000663{
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000664 PALETTEOBJ* palPtr;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000665 int realized = 0;
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000666 DC* dc = DC_GetDCPtr( hdc );
667
668 if (!dc) return 0;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000669
Alexandre Julliard15657091999-05-23 10:25:25 +0000670 TRACE("%04x...\n", hdc );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000671
Alexandre Julliard2239abb2000-11-05 02:05:07 +0000672 if(dc->hPalette != hLastRealizedPalette )
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000673 {
Alexandre Julliard2239abb2000-11-05 02:05:07 +0000674 if( dc->hPalette == GetStockObject( DEFAULT_PALETTE )) {
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000675 realized = RealizeDefaultPalette16( hdc );
676 GDI_ReleaseObj( hdc );
677 return (UINT16)realized;
678 }
679
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000680
Alexandre Julliard2239abb2000-11-05 02:05:07 +0000681 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( dc->hPalette, PALETTE_MAGIC );
Alexandre Julliard642d3131998-07-12 19:29:36 +0000682
683 if (!palPtr) {
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000684 GDI_ReleaseObj( hdc );
Alexandre Julliard2239abb2000-11-05 02:05:07 +0000685 FIXME("invalid selected palette %04x\n",dc->hPalette);
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000686 return 0;
Alexandre Julliard642d3131998-07-12 19:29:36 +0000687 }
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000688
Patrik Stridvallb87fe2e1999-04-01 08:16:08 +0000689 realized = PALETTE_Driver->
690 pSetMapping(palPtr,0,palPtr->logpalette.palNumEntries,
Alexandre Julliard2239abb2000-11-05 02:05:07 +0000691 (dc->hPalette != hPrimaryPalette) ||
692 (dc->hPalette == GetStockObject( DEFAULT_PALETTE )));
693 hLastRealizedPalette = dc->hPalette;
694 GDI_ReleaseObj( dc->hPalette );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000695 }
Alexandre Julliard15657091999-05-23 10:25:25 +0000696 else TRACE(" skipping (hLastRealizedPalette = %04x)\n",
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000697 hLastRealizedPalette);
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000698 GDI_ReleaseObj( hdc );
Alexandre Julliard54c27111998-03-29 19:44:57 +0000699
Alexandre Julliard15657091999-05-23 10:25:25 +0000700 TRACE(" realized %i colors.\n", realized );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000701 return (UINT16)realized;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000702}
703
704
705/***********************************************************************
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000706 * RealizeDefaultPalette (GDI.365)
707 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000708UINT16 WINAPI RealizeDefaultPalette16( HDC16 hdc )
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000709{
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000710 UINT16 ret = 0;
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000711 DC *dc;
712 PALETTEOBJ* palPtr;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000713
Alexandre Julliard15657091999-05-23 10:25:25 +0000714 TRACE("%04x\n", hdc );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000715
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000716 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
717
Alexandre Julliard2239abb2000-11-05 02:05:07 +0000718 if (!(dc->flags & DC_MEMORY))
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000719 {
Alexandre Julliard4c186362000-10-29 01:22:15 +0000720 palPtr = (PALETTEOBJ*)GDI_GetObjPtr( GetStockObject(DEFAULT_PALETTE), PALETTE_MAGIC );
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000721 if (palPtr)
722 {
723 /* lookup is needed to account for SetSystemPaletteUse() stuff */
724 ret = PALETTE_Driver->pUpdateMapping(palPtr);
Alexandre Julliard4c186362000-10-29 01:22:15 +0000725 GDI_ReleaseObj( GetStockObject(DEFAULT_PALETTE) );
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000726 }
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000727 }
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000728 GDI_ReleaseObj( hdc );
729 return ret;
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000730}
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000731
732/***********************************************************************
733 * IsDCCurrentPalette (GDI.412)
734 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000735BOOL16 WINAPI IsDCCurrentPalette16(HDC16 hDC)
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000736{
Alexandre Julliard2239abb2000-11-05 02:05:07 +0000737 DC *dc = DC_GetDCPtr( hDC );
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000738 if (dc)
739 {
Alexandre Julliard2239abb2000-11-05 02:05:07 +0000740 BOOL bRet = dc->hPalette == hPrimaryPalette;
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000741 GDI_ReleaseObj( hDC );
742 return bRet;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000743 }
744 return FALSE;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000745}
746
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000747
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000748/***********************************************************************
Alexandre Julliarda7116b02000-03-28 20:02:37 +0000749 * SelectPalette [GDI32.300] Selects logical palette into DC
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000750 *
751 * RETURNS
752 * Success: Previous logical palette
753 * Failure: NULL
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000754 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000755HPALETTE WINAPI SelectPalette(
756 HDC hDC, /* [in] Handle of device context */
757 HPALETTE hPal, /* [in] Handle of logical color palette */
758 BOOL bForceBackground) /* [in] Foreground/background mode */
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000759{
Alexandre Julliard39932162000-09-16 20:57:39 +0000760 return pfnSelectPalette( hDC, hPal, bForceBackground );
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000761}
762
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000763
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000764/***********************************************************************
Alexandre Julliarda7116b02000-03-28 20:02:37 +0000765 * RealizePalette [GDI32.280] Maps palette entries to system palette
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000766 *
767 * RETURNS
768 * Success: Number of entries in logical palette
769 * Failure: GDI_ERROR
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000770 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000771UINT WINAPI RealizePalette(
772 HDC hDC) /* [in] Handle of device context */
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000773{
Alexandre Julliard39932162000-09-16 20:57:39 +0000774 return pfnRealizePalette( hDC );
Alexandre Julliardca22b331996-07-12 19:02:39 +0000775}
776
777
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000778/**********************************************************************
Alexandre Julliard21979011997-03-05 08:22:35 +0000779 * UpdateColors16 (GDI.366)
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000780 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000781INT16 WINAPI UpdateColors16( HDC16 hDC )
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000782{
Patrik Stridvallb87fe2e1999-04-01 08:16:08 +0000783 DC *dc;
784 HWND hWnd;
Alexandre Julliard2a2321b2000-08-19 21:38:55 +0000785 int size;
Patrik Stridvallb87fe2e1999-04-01 08:16:08 +0000786
Alexandre Julliard2239abb2000-11-05 02:05:07 +0000787 if (!(dc = DC_GetDCPtr( hDC ))) return 0;
788 size = dc->devCaps->sizePalette;
789 GDI_ReleaseObj( hDC );
Alexandre Julliard4e951ea2000-11-08 22:47:53 +0000790 if (Callout.WindowFromDC)
791 {
792 hWnd = Callout.WindowFromDC( hDC );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000793
Alexandre Julliard4e951ea2000-11-08 22:47:53 +0000794 /* Docs say that we have to remap current drawable pixel by pixel
795 * but it would take forever given the speed of XGet/PutPixel.
796 */
797 if (hWnd && size)
798 Callout.RedrawWindow( hWnd, NULL, 0, RDW_INVALIDATE );
799 }
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000800 return 0x666;
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000801}
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000802
Alexandre Julliard21979011997-03-05 08:22:35 +0000803
804/**********************************************************************
Alexandre Julliarda7116b02000-03-28 20:02:37 +0000805 * UpdateColors [GDI32.359] Remaps current colors to logical palette
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000806 *
807 * RETURNS
808 * Success: TRUE
809 * Failure: FALSE
Alexandre Julliard21979011997-03-05 08:22:35 +0000810 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000811BOOL WINAPI UpdateColors(
812 HDC hDC) /* [in] Handle of device context */
Alexandre Julliard21979011997-03-05 08:22:35 +0000813{
814 UpdateColors16( hDC );
815 return TRUE;
816}
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000817
Ian Schmidt8150b521998-11-22 12:54:38 +0000818
819/*********************************************************************
820 * SetMagicColors16 (GDI.606)
821 */
822VOID WINAPI SetMagicColors16(HDC16 hDC, COLORREF color, UINT16 index)
823{
Alexandre Julliard15657091999-05-23 10:25:25 +0000824 FIXME("(hDC %04x, color %04x, index %04x): stub\n", hDC, (int)color, index);
Ian Schmidt8150b521998-11-22 12:54:38 +0000825
826}
Ian Schmidt31b47211999-09-22 15:12:41 +0000827
828/**********************************************************************
829 * GetICMProfileA [GDI32.316]
830 *
831 * Returns the filename of the specified device context's color
832 * management profile, even if color management is not enabled
833 * for that DC.
834 *
835 * RETURNS
836 * TRUE if name copied succesfully OR lpszFilename is NULL
837 * FALSE if the buffer length pointed to by lpcbName is too small
838 *
839 * NOTE
840 * The buffer length pointed to by lpcbName is ALWAYS updated to
841 * the length required regardless of other actions this function
842 * may take.
843 *
844 * FIXME
845 * How does Windows assign these? Some registry key?
846 */
847
848#define WINEICM "winefake.icm" /* easy-to-identify fake filename */
849
Patrik Stridvall2b3aa612000-12-01 23:58:28 +0000850/*********************************************************************/
851
Ian Schmidt31b47211999-09-22 15:12:41 +0000852BOOL WINAPI GetICMProfileA(HDC hDC, LPDWORD lpcbName, LPSTR lpszFilename)
853{
854 DWORD callerLen;
855
856 FIXME("(%04x, %p, %p): partial stub\n", hDC, lpcbName, lpszFilename);
857
858 callerLen = *lpcbName;
859
860 /* all 3 behaviors require the required buffer size to be set */
861 *lpcbName = strlen(WINEICM);
862
863 /* behavior 1: if lpszFilename is NULL, return size of string and no error */
864 if ((DWORD)lpszFilename == (DWORD)0x00000000)
865 return TRUE;
866
867 /* behavior 2: if buffer size too small, return size of string and error */
868 if (callerLen < strlen(WINEICM))
869 {
870 SetLastError(ERROR_INSUFFICIENT_BUFFER);
871 return FALSE;
872 }
873
874 /* behavior 3: if buffer size OK and pointer not NULL, copy and return size */
Alexandre Julliardc7e7df82000-08-14 14:41:19 +0000875 strcpy(lpszFilename, WINEICM);
Ian Schmidt31b47211999-09-22 15:12:41 +0000876 return TRUE;
877}