blob: e47114854998bf349164c3747121d197733e990c [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>
Alexandre Julliard60ce85c1998-02-01 18:33:27 +000013#include "ts_xlib.h"
Alexandre Julliard59730ae1996-03-24 16:20:51 +000014
Alexandre Julliard75d86e11996-11-17 18:59:11 +000015#include "gdi.h"
Alexandre Julliard234bc241994-12-10 13:02:28 +000016#include "color.h"
Alexandre Julliard7cbe6571995-01-09 18:21:16 +000017#include "palette.h"
Alexandre Julliard75d86e11996-11-17 18:59:11 +000018#include "xmalloc.h"
Alexandre Julliardaca05781994-10-17 18:12:41 +000019#include "debug.h"
Alexandre Julliard401710d1993-09-04 10:09:32 +000020
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000021static UINT32 SystemPaletteUse = SYSPAL_STATIC; /* currently not considered */
Alexandre Julliarda2f2e011995-06-06 16:40:35 +000022
Alexandre Julliard18f92e71996-07-17 20:02:21 +000023static HPALETTE16 hPrimaryPalette = 0; /* used for WM_PALETTECHANGED */
24static HPALETTE16 hLastRealizedPalette = 0; /* UnrealizeObject() needs it */
25
Alexandre Julliard902da691995-11-05 14:39:02 +000026
27/***********************************************************************
Alexandre Julliard23946ad1997-06-16 17:43:53 +000028 * PALETTE_Init
29 *
30 * Create the system palette.
31 */
32HPALETTE16 PALETTE_Init(void)
33{
Alexandre Julliard23946ad1997-06-16 17:43:53 +000034 int i;
35 HPALETTE16 hpalette;
36 LOGPALETTE * palPtr;
37 PALETTEOBJ* palObj;
38 const PALETTEENTRY* __sysPalTemplate = COLOR_GetSystemPaletteTemplate();
39
40 /* create default palette (20 system colors) */
41
Alexandre Julliard491502b1997-11-01 19:08:16 +000042 palPtr = HeapAlloc( GetProcessHeap(), 0,
43 sizeof(LOGPALETTE) + (NB_RESERVED_COLORS-1)*sizeof(PALETTEENTRY));
Alexandre Julliard23946ad1997-06-16 17:43:53 +000044 if (!palPtr) return FALSE;
45
46 palPtr->palVersion = 0x300;
47 palPtr->palNumEntries = NB_RESERVED_COLORS;
48 for( i = 0; i < NB_RESERVED_COLORS; i ++ )
49 {
50 palPtr->palPalEntry[i].peRed = __sysPalTemplate[i].peRed;
51 palPtr->palPalEntry[i].peGreen = __sysPalTemplate[i].peGreen;
52 palPtr->palPalEntry[i].peBlue = __sysPalTemplate[i].peBlue;
53 palPtr->palPalEntry[i].peFlags = 0;
54 }
55 hpalette = CreatePalette16( palPtr );
56
57 palObj = (PALETTEOBJ*) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
58
59 palObj->mapping = xmalloc( sizeof(int) * 20 );
60
Alexandre Julliard670cdc41997-08-24 16:00:30 +000061 GDI_HEAP_UNLOCK( hpalette );
62
Alexandre Julliard491502b1997-11-01 19:08:16 +000063 HeapFree( GetProcessHeap(), 0, palPtr );
Alexandre Julliard23946ad1997-06-16 17:43:53 +000064 return hpalette;
65}
66
67/***********************************************************************
Alexandre Julliard18f92e71996-07-17 20:02:21 +000068 * PALETTE_ValidateFlags
69 */
70void PALETTE_ValidateFlags(PALETTEENTRY* lpPalE, int size)
71{
72 int i = 0;
73 for( ; i<size ; i++ )
74 lpPalE[i].peFlags = PC_SYS_USED | (lpPalE[i].peFlags & 0x07);
75}
76
77
78/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000079 * CreatePalette16 (GDI.360)
Alexandre Julliard401710d1993-09-04 10:09:32 +000080 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +000081HPALETTE16 WINAPI CreatePalette16( const LOGPALETTE* palette )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000082{
83 return CreatePalette32( palette );
84}
85
86
87/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +000088 * CreatePalette32 [GDI32.53] Creates a logical color palette
89 *
90 * RETURNS
91 * Success: Handle to logical palette
92 * Failure: NULL
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000093 */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +000094HPALETTE32 WINAPI CreatePalette32(
95 const LOGPALETTE* palette) /* [in] Pointer to logical color palette */
Alexandre Julliard401710d1993-09-04 10:09:32 +000096{
97 PALETTEOBJ * palettePtr;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000098 HPALETTE32 hpalette;
Alexandre Julliard18f92e71996-07-17 20:02:21 +000099 int size = sizeof(LOGPALETTE) + (palette->palNumEntries - 1) * sizeof(PALETTEENTRY);
Alexandre Julliard401710d1993-09-04 10:09:32 +0000100
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000101 TRACE(palette,"entries=%i\n", palette->palNumEntries);
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000102
103 hpalette = GDI_AllocObject( size + sizeof(int*) +sizeof(GDIOBJHDR) , PALETTE_MAGIC );
Alexandre Julliard401710d1993-09-04 10:09:32 +0000104 if (!hpalette) return 0;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000105
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000106 palettePtr = (PALETTEOBJ *) GDI_HEAP_LOCK( hpalette );
Alexandre Julliard401710d1993-09-04 10:09:32 +0000107 memcpy( &palettePtr->logpalette, palette, size );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000108 PALETTE_ValidateFlags(palettePtr->logpalette.palPalEntry,
109 palettePtr->logpalette.palNumEntries);
110 palettePtr->mapping = NULL;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000111 GDI_HEAP_UNLOCK( hpalette );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000112
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000113 TRACE(palette," returning %04x\n", hpalette);
Alexandre Julliard401710d1993-09-04 10:09:32 +0000114 return hpalette;
115}
116
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000117
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000118/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000119 * CreateHalftonePalette [GDI32.47] Creates a halftone palette
120 *
121 * RETURNS
122 * Success: Handle to logical halftone palette
123 * Failure: 0
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000124 */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000125HPALETTE32 WINAPI CreateHalftonePalette(
126 HDC32 hdc) /* [in] Handle to device context */
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000127{
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000128 FIXME(palette,"(%x): stub\n", hdc);
129 return NULL;
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000130}
Alexandre Julliard401710d1993-09-04 10:09:32 +0000131
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000132
Alexandre Julliard401710d1993-09-04 10:09:32 +0000133/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000134 * GetPaletteEntries16 (GDI.363)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000135 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000136UINT16 WINAPI GetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
137 UINT16 count, LPPALETTEENTRY entries )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000138{
139 return GetPaletteEntries32( hpalette, start, count, entries );
140}
141
142
143/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000144 * GetPaletteEntries32 [GDI32.209] Retrieves palette entries
145 *
146 * RETURNS
147 * Success: Number of entries from logical palette
148 * Failure: 0
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000149 */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000150UINT32 WINAPI GetPaletteEntries32(
151 HPALETTE32 hpalette, /* [in] Handle of logical palette */
152 UINT32 start, /* [in] First entry to receive */
153 UINT32 count, /* [in] Number of entries to receive */
154 LPPALETTEENTRY entries) /* [out] Address of array receiving entries */
Alexandre Julliard401710d1993-09-04 10:09:32 +0000155{
156 PALETTEOBJ * palPtr;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000157 INT32 numEntries;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000158
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000159 TRACE(palette,"hpal = %04x, count=%i\n", hpalette, count );
Alexandre Julliard401710d1993-09-04 10:09:32 +0000160
161 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
162 if (!palPtr) return 0;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000163
Alexandre Julliard401710d1993-09-04 10:09:32 +0000164 numEntries = palPtr->logpalette.palNumEntries;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000165 if (start >= numEntries)
166 {
167 GDI_HEAP_UNLOCK( hpalette );
168 return 0;
169 }
Alexandre Julliard401710d1993-09-04 10:09:32 +0000170 if (start+count > numEntries) count = numEntries - start;
171 memcpy( entries, &palPtr->logpalette.palPalEntry[start],
172 count * sizeof(PALETTEENTRY) );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000173 for( numEntries = 0; numEntries < count ; numEntries++ )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000174 if (entries[numEntries].peFlags & 0xF0)
175 entries[numEntries].peFlags = 0;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000176 GDI_HEAP_UNLOCK( hpalette );
Alexandre Julliard401710d1993-09-04 10:09:32 +0000177 return count;
178}
179
180
181/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000182 * SetPaletteEntries16 (GDI.364)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000183 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000184UINT16 WINAPI SetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
185 UINT16 count, LPPALETTEENTRY entries )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000186{
187 return SetPaletteEntries32( hpalette, start, count, entries );
188}
189
190
191/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000192 * SetPaletteEntries32 [GDI32.326] Sets color values for range in palette
193 *
194 * RETURNS
195 * Success: Number of entries that were set
196 * Failure: 0
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000197 */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000198UINT32 WINAPI SetPaletteEntries32(
199 HPALETTE32 hpalette, /* [in] Handle of logical palette */
200 UINT32 start, /* [in] Index of first entry to set */
201 UINT32 count, /* [in] Number of entries to set */
202 LPPALETTEENTRY entries) /* [in] Address of array of structures */
Alexandre Julliard401710d1993-09-04 10:09:32 +0000203{
204 PALETTEOBJ * palPtr;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000205 INT32 numEntries;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000206
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000207 TRACE(palette,"hpal=%04x,start=%i,count=%i\n",hpalette,start,count );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000208
Alexandre Julliard401710d1993-09-04 10:09:32 +0000209 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
210 if (!palPtr) return 0;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000211
Alexandre Julliard401710d1993-09-04 10:09:32 +0000212 numEntries = palPtr->logpalette.palNumEntries;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000213 if (start >= numEntries)
214 {
215 GDI_HEAP_UNLOCK( hpalette );
216 return 0;
217 }
Alexandre Julliard401710d1993-09-04 10:09:32 +0000218 if (start+count > numEntries) count = numEntries - start;
219 memcpy( &palPtr->logpalette.palPalEntry[start], entries,
220 count * sizeof(PALETTEENTRY) );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000221 PALETTE_ValidateFlags(palPtr->logpalette.palPalEntry,
222 palPtr->logpalette.palNumEntries);
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000223 free(palPtr->mapping);
224 palPtr->mapping = NULL;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000225 GDI_HEAP_UNLOCK( hpalette );
Alexandre Julliard401710d1993-09-04 10:09:32 +0000226 return count;
227}
228
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000229
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000230/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000231 * ResizePalette16 (GDI.368)
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000232 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000233BOOL16 WINAPI ResizePalette16( HPALETTE16 hPal, UINT16 cEntries )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000234{
235 return ResizePalette32( hPal, cEntries );
236}
237
238
239/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000240 * ResizePalette32 [GDI32.289] Resizes logical palette
241 *
242 * RETURNS
243 * Success: TRUE
244 * Failure: FALSE
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000245 */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000246BOOL32 WINAPI ResizePalette32(
247 HPALETTE32 hPal, /* [in] Handle of logical palette */
248 UINT32 cEntries) /* [in] Number of entries in logical palette */
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000249{
Alexandre Julliard75d86e11996-11-17 18:59:11 +0000250 PALETTEOBJ * palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000251 UINT32 cPrevEnt, prevVer;
Alexandre Julliard75d86e11996-11-17 18:59:11 +0000252 int prevsize, size = sizeof(LOGPALETTE) + (cEntries - 1) * sizeof(PALETTEENTRY);
253 int* mapping = NULL;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000254
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000255 TRACE(palette,"hpal = %04x, prev = %i, new = %i\n",
Alexandre Julliard889f7421997-04-15 17:19:52 +0000256 hPal, palPtr ? palPtr->logpalette.palNumEntries : -1,
257 cEntries );
Alexandre Julliard75d86e11996-11-17 18:59:11 +0000258 if( !palPtr ) return FALSE;
259 cPrevEnt = palPtr->logpalette.palNumEntries;
260 prevVer = palPtr->logpalette.palVersion;
261 prevsize = sizeof(LOGPALETTE) + (cPrevEnt - 1) * sizeof(PALETTEENTRY) +
262 sizeof(int*) + sizeof(GDIOBJHDR);
263 size += sizeof(int*) + sizeof(GDIOBJHDR);
264 mapping = palPtr->mapping;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000265
266 GDI_HEAP_UNLOCK( hPal );
267
Alexandre Julliard889f7421997-04-15 17:19:52 +0000268 hPal = GDI_HEAP_REALLOC( hPal, size );
Alexandre Julliard75d86e11996-11-17 18:59:11 +0000269 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
270 if( !palPtr ) return FALSE;
271
272 if( mapping )
273 palPtr->mapping = (int*) xrealloc( mapping, cEntries * sizeof(int) );
274 if( cEntries > cPrevEnt )
275 {
276 if( mapping )
277 memset(palPtr->mapping + cPrevEnt, 0, (cEntries - cPrevEnt)*sizeof(int));
278 memset( (BYTE*)palPtr + prevsize, 0, size - prevsize );
279 PALETTE_ValidateFlags((PALETTEENTRY*)((BYTE*)palPtr + prevsize),
280 cEntries - cPrevEnt );
281 }
282 palPtr->logpalette.palNumEntries = cEntries;
283 palPtr->logpalette.palVersion = prevVer;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000284 GDI_HEAP_UNLOCK( hPal );
Alexandre Julliard75d86e11996-11-17 18:59:11 +0000285 return TRUE;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000286}
287
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000288
Alexandre Julliardade697e1995-11-26 13:59:11 +0000289/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000290 * AnimatePalette16 (GDI.367)
Alexandre Julliardade697e1995-11-26 13:59:11 +0000291 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000292void WINAPI AnimatePalette16( HPALETTE16 hPal, UINT16 StartIndex,
293 UINT16 NumEntries, LPPALETTEENTRY PaletteColors)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000294{
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000295 AnimatePalette32( hPal, StartIndex, NumEntries, PaletteColors );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000296}
297
298
299/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000300 * AnimatePalette32 [GDI32.6] Replaces entries in logical palette
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000301 *
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000302 * RETURNS
303 * Success: TRUE
304 * Failure: FALSE
305 *
306 * FIXME
307 * Should use existing mapping when animating a primary palette
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000308 */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000309BOOL32 WINAPI AnimatePalette32(
310 HPALETTE32 hPal, /* [in] Handle to logical palette */
311 UINT32 StartIndex, /* [in] First entry in palette */
312 UINT32 NumEntries, /* [in] Count of entries in palette */
313 LPPALETTEENTRY PaletteColors) /* [in] Pointer to first replacement */
Alexandre Julliardade697e1995-11-26 13:59:11 +0000314{
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000315 TRACE(palette, "%04x (%i - %i)\n", hPal, StartIndex,StartIndex+NumEntries);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000316
317 if( hPal != STOCK_DEFAULT_PALETTE )
318 {
319 PALETTEOBJ* palPtr = (PALETTEOBJ *)GDI_GetObjPtr(hPal, PALETTE_MAGIC);
320
Alexandre Julliard02e90081998-01-04 17:49:09 +0000321 if( (StartIndex + NumEntries) <= palPtr->logpalette.palNumEntries )
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000322 {
323 UINT32 u;
324 for( u = 0; u < NumEntries; u++ )
325 palPtr->logpalette.palPalEntry[u + StartIndex] = PaletteColors[u];
326 COLOR_SetMapping(palPtr, StartIndex, NumEntries,
327 hPal != hPrimaryPalette );
328 GDI_HEAP_UNLOCK( hPal );
329 return TRUE;
330 }
331 }
332 return FALSE;
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000333}
Alexandre Julliard401710d1993-09-04 10:09:32 +0000334
Alexandre Julliarda2f2e011995-06-06 16:40:35 +0000335
336/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000337 * SetSystemPaletteUse16 (GDI.373)
Alexandre Julliard2787be81995-05-22 18:23:01 +0000338 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000339UINT16 WINAPI SetSystemPaletteUse16( HDC16 hdc, UINT16 use )
Alexandre Julliard2787be81995-05-22 18:23:01 +0000340{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000341 return SetSystemPaletteUse32( hdc, use );
Alexandre Julliard2787be81995-05-22 18:23:01 +0000342}
343
344
345/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000346 * SetSystemPaletteUse32 [GDI32.335]
347 *
348 * RETURNS
349 * Success: Previous system palette
350 * Failure: SYSPAL_ERROR
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000351 */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000352UINT32 WINAPI SetSystemPaletteUse32(
353 HDC32 hdc, /* [in] Handle of device context */
354 UINT32 use) /* [in] Palette-usage flag */
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000355{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000356 UINT32 old = SystemPaletteUse;
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000357 FIXME(palette,"(%04x,%04x): stub\n", hdc, use );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000358 SystemPaletteUse = use;
359 return old;
360}
361
362
363/***********************************************************************
364 * GetSystemPaletteUse16 (GDI.374)
365 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000366UINT16 WINAPI GetSystemPaletteUse16( HDC16 hdc )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000367{
368 return SystemPaletteUse;
369}
370
371
372/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000373 * GetSystemPaletteUse32 [GDI32.223] Gets state of system palette
374 *
375 * RETURNS
376 * Current state of system palette
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000377 */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000378UINT32 WINAPI GetSystemPaletteUse32(
379 HDC32 hdc) /* [in] Handle of device context */
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000380{
381 return SystemPaletteUse;
382}
383
384
385/***********************************************************************
386 * GetSystemPaletteEntries16 (GDI.375)
387 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000388UINT16 WINAPI GetSystemPaletteEntries16( HDC16 hdc, UINT16 start, UINT16 count,
389 LPPALETTEENTRY entries )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000390{
391 return GetSystemPaletteEntries32( hdc, start, count, entries );
392}
393
394
395/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000396 * GetSystemPaletteEntries32 [GDI32.222] Gets range of palette entries
397 *
398 * RETURNS
399 * Success: Number of entries retrieved from palette
400 * Failure: 0
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000401 */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000402UINT32 WINAPI GetSystemPaletteEntries32(
403 HDC32 hdc, /* [in] Handle of device context */
404 UINT32 start, /* [in] Index of first entry to be retrieved */
405 UINT32 count, /* [in] Number of entries to be retrieved */
406 LPPALETTEENTRY entries) /* [out] Array receiving system-palette entries */
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000407{
408 UINT32 i;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000409 DC *dc;
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000410
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000411 TRACE(palette, "hdc=%04x,start=%i,count=%i\n", hdc,start,count);
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000412
413 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return 0;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000414 if (start >= dc->w.devCaps->sizePalette)
415 {
416 GDI_HEAP_UNLOCK( hdc );
417 return 0;
418 }
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000419 if (start+count >= dc->w.devCaps->sizePalette)
420 count = dc->w.devCaps->sizePalette - start;
421 for (i = 0; i < count; i++)
422 {
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000423 *(COLORREF*)(entries + i) = COLOR_GetSystemPaletteEntry( start + i );
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000424
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000425 TRACE(palette,"\tidx(%02x) -> RGB(%08lx)\n",
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000426 start + i, *(COLORREF*)(entries + i) );
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000427 }
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000428 GDI_HEAP_UNLOCK( hdc );
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000429 return count;
430}
431
432
433/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000434 * GetNearestPaletteIndex16 (GDI.370)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000435 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000436UINT16 WINAPI GetNearestPaletteIndex16( HPALETTE16 hpalette, COLORREF color )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000437{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000438 return GetNearestPaletteIndex32( hpalette, color );
439}
440
441
442/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000443 * GetNearestPaletteIndex32 [GDI32.203] Gets palette index for color
444 *
445 * NOTES
446 * Should index be initialized to CLR_INVALID instead of 0?
447 *
448 * RETURNS
449 * Success: Index of entry in logical palette
450 * Failure: CLR_INVALID
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000451 */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000452UINT32 WINAPI GetNearestPaletteIndex32(
453 HPALETTE32 hpalette, /* [in] Handle of logical color palette */
454 COLORREF color) /* [in] Color to be matched */
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000455{
456 PALETTEOBJ* palObj = (PALETTEOBJ*)GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
457 UINT32 index = 0;
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000458
459 if( palObj )
460 index = COLOR_PaletteLookupPixel( palObj->logpalette.palPalEntry,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000461 palObj->logpalette.palNumEntries,
462 NULL, color, FALSE );
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000463
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000464 TRACE(palette,"(%04x,%06lx): returning %d\n", hpalette, color, index );
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000465 GDI_HEAP_UNLOCK( hpalette );
Alexandre Julliard401710d1993-09-04 10:09:32 +0000466 return index;
467}
468
469
470/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000471 * GetNearestColor16 (GDI.154)
Alexandre Julliard902da691995-11-05 14:39:02 +0000472 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000473COLORREF WINAPI GetNearestColor16( HDC16 hdc, COLORREF color )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000474{
475 return GetNearestColor32( hdc, color );
476}
477
478
479/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000480 * GetNearestColor32 [GDI32.202] Gets a system color to match
481 *
482 * NOTES
483 * Should this return CLR_INVALID instead of FadeCafe?
484 *
485 * RETURNS
486 * Success: Color from system palette that corresponds to given color
487 * Failure: CLR_INVALID
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000488 */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000489COLORREF WINAPI GetNearestColor32(
490 HDC32 hdc, /* [in] Handle of device context */
491 COLORREF color) /* [in] Color to be matched */
Alexandre Julliard902da691995-11-05 14:39:02 +0000492{
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000493 COLORREF nearest = 0xFADECAFE;
494 DC *dc;
495 PALETTEOBJ *palObj;
Alexandre Julliard902da691995-11-05 14:39:02 +0000496
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000497 if ( (dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC )) )
498 {
499 palObj = (PALETTEOBJ*)
500 GDI_GetObjPtr( (dc->w.hPalette)? dc->w.hPalette
501 : STOCK_DEFAULT_PALETTE, PALETTE_MAGIC );
502
503 nearest = COLOR_LookupNearestColor( palObj->logpalette.palPalEntry,
504 palObj->logpalette.palNumEntries, color );
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000505 GDI_HEAP_UNLOCK( dc->w.hPalette );
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000506 }
507
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000508 TRACE(palette,"(%06lx): returning %06lx\n", color, nearest );
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000509 GDI_HEAP_UNLOCK( hdc );
Alexandre Julliard902da691995-11-05 14:39:02 +0000510 return nearest;
511}
512
513
514/***********************************************************************
Alexandre Julliard401710d1993-09-04 10:09:32 +0000515 * PALETTE_GetObject
516 */
517int PALETTE_GetObject( PALETTEOBJ * palette, int count, LPSTR buffer )
518{
519 if (count > sizeof(WORD)) count = sizeof(WORD);
520 memcpy( buffer, &palette->logpalette.palNumEntries, count );
521 return count;
522}
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000523
524
525/***********************************************************************
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000526 * PALETTE_UnrealizeObject
527 */
Alexandre Julliard0e270f41996-08-24 18:26:35 +0000528BOOL32 PALETTE_UnrealizeObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000529{
530 if (palette->mapping)
531 {
532 free( palette->mapping );
533 palette->mapping = NULL;
534 }
535 if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0;
536 return TRUE;
537}
538
539
540/***********************************************************************
541 * PALETTE_DeleteObject
542 */
Alexandre Julliard0e270f41996-08-24 18:26:35 +0000543BOOL32 PALETTE_DeleteObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000544{
545 free( palette->mapping );
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000546 if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000547 return GDI_FreeObject( hpalette );
548}
549
550
551/***********************************************************************
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000552 * GDISelectPalette (GDI.361)
553 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000554HPALETTE16 WINAPI GDISelectPalette( HDC16 hdc, HPALETTE16 hpal, WORD wBkg)
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000555{
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000556 HPALETTE16 prev;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000557 DC *dc;
558
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000559 TRACE(palette, "%04x %04x\n", hdc, hpal );
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000560
561 dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
562 if (!dc)
563 {
564 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
565 if (!dc) return 0;
566 }
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000567 prev = dc->w.hPalette;
568 dc->w.hPalette = hpal;
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000569 GDI_HEAP_UNLOCK( hdc );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000570 if (!wBkg) hPrimaryPalette = hpal;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000571 return prev;
572}
573
574
575/***********************************************************************
576 * GDIRealizePalette (GDI.362)
577 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000578UINT16 WINAPI GDIRealizePalette( HDC16 hdc )
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000579{
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000580 PALETTEOBJ* palPtr;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000581 int realized = 0;
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000582 DC* dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
583 if (!dc)
584 {
585 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
586 if (!dc) return 0;
587 }
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000588
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000589 TRACE(palette, "%04x...\n", hdc );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000590
591 if( dc && dc->w.hPalette != hLastRealizedPalette )
592 {
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000593 if( dc->w.hPalette == STOCK_DEFAULT_PALETTE )
594 return RealizeDefaultPalette( hdc );
595
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000596 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( dc->w.hPalette, PALETTE_MAGIC );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000597
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000598 realized = COLOR_SetMapping(palPtr,0,palPtr->logpalette.palNumEntries,
599 (dc->w.hPalette != hPrimaryPalette) ||
600 (dc->w.hPalette == STOCK_DEFAULT_PALETTE));
601 GDI_HEAP_UNLOCK( dc->w.hPalette );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000602 hLastRealizedPalette = dc->w.hPalette;
603 }
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000604 else TRACE(palette, " skipping (hLastRealizedPalette = %04x)\n",
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000605 hLastRealizedPalette);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000606 GDI_HEAP_UNLOCK( hdc );
Alexandre Julliard54c27111998-03-29 19:44:57 +0000607
608 TRACE(palette, " realized %i colors.\n", realized );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000609 return (UINT16)realized;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000610}
611
612
613/***********************************************************************
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000614 * RealizeDefaultPalette (GDI.365)
615 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000616UINT16 WINAPI RealizeDefaultPalette( HDC16 hdc )
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000617{
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000618 DC *dc;
619 PALETTEOBJ* palPtr;
620 int i, index, realized = 0;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000621
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000622 TRACE(palette,"%04x\n", hdc );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000623
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000624 dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
625 if (!dc)
626 {
627 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
628 if (!dc) return 0;
629 }
630
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000631 if ( dc->w.flags & DC_MEMORY )
632 {
633 GDI_HEAP_UNLOCK( hdc );
634 return 0;
635 }
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000636
637 hPrimaryPalette = STOCK_DEFAULT_PALETTE;
638 hLastRealizedPalette = STOCK_DEFAULT_PALETTE;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000639
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000640 palPtr = (PALETTEOBJ*)GDI_GetObjPtr(STOCK_DEFAULT_PALETTE, PALETTE_MAGIC );
641
642 /* lookup is needed to account for SetSystemPaletteUse() stuff */
643
644 for( i = 0; i < 20; i++ )
645 {
646 index = COLOR_LookupSystemPixel(*(COLORREF*)(palPtr->logpalette.palPalEntry + i));
647
648 /* mapping is allocated in COLOR_InitPalette() */
649
650 if( index != palPtr->mapping[i] ) { palPtr->mapping[i]=index; realized++; }
651 }
652 return realized;
653}
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000654
655/***********************************************************************
656 * IsDCCurrentPalette (GDI.412)
657 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000658BOOL16 WINAPI IsDCCurrentPalette(HDC16 hDC)
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000659{
660 DC* dc = (DC *)GDI_GetObjPtr( hDC, DC_MAGIC );
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000661 if (dc)
662 {
663 GDI_HEAP_UNLOCK( hDC );
664 return dc->w.hPalette == hPrimaryPalette;
665 }
666 return FALSE;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000667}
668
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000669
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000670/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000671 * SelectPalette16 (USER.282)
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000672 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000673HPALETTE16 WINAPI SelectPalette16( HDC16 hDC, HPALETTE16 hPal,
674 BOOL16 bForceBackground )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000675{
676 return SelectPalette32( hDC, hPal, bForceBackground );
677}
678
679
680/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000681 * SelectPalette32 [GDI32.300] Selects logical palette into DC
682 *
683 * RETURNS
684 * Success: Previous logical palette
685 * Failure: NULL
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000686 */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000687HPALETTE32 WINAPI SelectPalette32(
688 HDC32 hDC, /* [in] Handle of device context */
689 HPALETTE32 hPal, /* [in] Handle of logical color palette */
690 BOOL32 bForceBackground) /* [in] Foreground/background mode */
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000691{
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000692 WORD wBkgPalette = 1;
693 PALETTEOBJ* lpt = (PALETTEOBJ*) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
694
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000695 TRACE(palette,"dc=%04x,pal=%04x,force=%i\n", hDC, hPal, bForceBackground);
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000696 if( !lpt ) return 0;
697
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000698 TRACE(palette," entries = %d\n", lpt->logpalette.palNumEntries);
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000699 GDI_HEAP_UNLOCK( hPal );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000700
701 if( hPal != STOCK_DEFAULT_PALETTE )
702 {
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000703 HWND32 hWnd = WindowFromDC32( hDC );
Alexandre Julliard01d63461997-01-20 19:43:45 +0000704 HWND32 hActive = GetActiveWindow32();
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000705
706 /* set primary palette if it's related to current active */
707
Alexandre Julliard01d63461997-01-20 19:43:45 +0000708 if((!hWnd || (hActive == hWnd || IsChild16(hActive,hWnd))) &&
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000709 !bForceBackground )
710 wBkgPalette = 0;
711 }
712 return GDISelectPalette( hDC, hPal, wBkgPalette);
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000713}
714
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000715
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000716/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000717 * RealizePalette16 (USER.283)
Alexandre Julliardca22b331996-07-12 19:02:39 +0000718 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000719UINT16 WINAPI RealizePalette16( HDC16 hDC )
Alexandre Julliardca22b331996-07-12 19:02:39 +0000720{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000721 return RealizePalette32( hDC );
722}
723
724
725/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000726 * RealizePalette32 [GDI32.280] Maps palette entries to system palette
727 *
728 * RETURNS
729 * Success: Number of entries in logical palette
730 * Failure: GDI_ERROR
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000731 */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000732UINT32 WINAPI RealizePalette32(
733 HDC32 hDC) /* [in] Handle of device context */
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000734{
735 UINT32 realized = GDIRealizePalette( hDC );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000736
737 /* do not send anything if no colors were changed */
738
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000739 if( IsDCCurrentPalette( hDC ) && realized &&
740 !(COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL) )
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000741 {
742 /* Send palette change notification */
743
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000744 HWND32 hWnd;
745 if( (hWnd = WindowFromDC32( hDC )) )
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000746 SendMessage16( HWND_BROADCAST, WM_PALETTECHANGED, hWnd, 0L);
747 }
748 return realized;
Alexandre Julliardca22b331996-07-12 19:02:39 +0000749}
750
751
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000752/**********************************************************************
Alexandre Julliard21979011997-03-05 08:22:35 +0000753 * UpdateColors16 (GDI.366)
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000754 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000755INT16 WINAPI UpdateColors16( HDC16 hDC )
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000756{
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000757 HWND32 hWnd = WindowFromDC32( hDC );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000758
759 /* Docs say that we have to remap current drawable pixel by pixel
760 * but it would take forever given the speed of XGet/PutPixel.
761 */
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000762 if (hWnd && !(COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL) )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000763 InvalidateRect32( hWnd, NULL, FALSE );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000764 return 0x666;
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000765}
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000766
Alexandre Julliard21979011997-03-05 08:22:35 +0000767
768/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000769 * UpdateColors32 [GDI32.359] Remaps current colors to logical palette
770 *
771 * RETURNS
772 * Success: TRUE
773 * Failure: FALSE
Alexandre Julliard21979011997-03-05 08:22:35 +0000774 */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000775BOOL32 WINAPI UpdateColors32(
776 HDC32 hDC) /* [in] Handle of device context */
Alexandre Julliard21979011997-03-05 08:22:35 +0000777{
778 UpdateColors16( hDC );
779 return TRUE;
780}
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000781