blob: 854322a544d0351b47c6c6c6b1f6331cd40b9ba3 [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 Julliard59730ae1996-03-24 16:20:51 +00007 */
Alexandre Julliard401710d1993-09-04 10:09:32 +00008#include <stdlib.h>
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00009#include <string.h>
Alexandre Julliard401710d1993-09-04 10:09:32 +000010#include <X11/Xlib.h>
Alexandre Julliard59730ae1996-03-24 16:20:51 +000011
Alexandre Julliard234bc241994-12-10 13:02:28 +000012#include "color.h"
Alexandre Julliard7cbe6571995-01-09 18:21:16 +000013#include "palette.h"
Alexandre Julliardaca05781994-10-17 18:12:41 +000014#include "stddebug.h"
Alexandre Julliardecc37121994-11-22 16:31:29 +000015/* #define DEBUG_PALETTE */
Alexandre Julliardaca05781994-10-17 18:12:41 +000016#include "debug.h"
Alexandre Julliard401710d1993-09-04 10:09:32 +000017
Alexandre Julliard18f92e71996-07-17 20:02:21 +000018extern HWND DCE_hDC2hWnd( HDC ); /* get associated window by
19 * walking DCE list */
Alexandre Julliardac9c9b01996-07-28 18:50:11 +000020extern int COLOR_LookupSystemPixel(COLORREF); /* lookup pixel among static entries
21 * of the system palette */
22extern COLORREF COLOR_GetSystemPaletteEntry(BYTE);
Alexandre Julliard18f92e71996-07-17 20:02:21 +000023
Alexandre Julliarda2f2e011995-06-06 16:40:35 +000024static WORD SystemPaletteUse = SYSPAL_STATIC; /* currently not considered */
25
Alexandre Julliard18f92e71996-07-17 20:02:21 +000026static HPALETTE16 hPrimaryPalette = 0; /* used for WM_PALETTECHANGED */
27static HPALETTE16 hLastRealizedPalette = 0; /* UnrealizeObject() needs it */
28
Alexandre Julliard902da691995-11-05 14:39:02 +000029
30/***********************************************************************
Alexandre Julliard18f92e71996-07-17 20:02:21 +000031 * PALETTE_ValidateFlags
32 */
33void PALETTE_ValidateFlags(PALETTEENTRY* lpPalE, int size)
34{
35 int i = 0;
36 for( ; i<size ; i++ )
37 lpPalE[i].peFlags = PC_SYS_USED | (lpPalE[i].peFlags & 0x07);
38}
39
40
41/***********************************************************************
Alexandre Julliard401710d1993-09-04 10:09:32 +000042 * CreatePalette (GDI.360)
43 */
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +000044HPALETTE16 CreatePalette( const LOGPALETTE* palette )
Alexandre Julliard401710d1993-09-04 10:09:32 +000045{
46 PALETTEOBJ * palettePtr;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +000047 HPALETTE16 hpalette;
Alexandre Julliard18f92e71996-07-17 20:02:21 +000048 int size = sizeof(LOGPALETTE) + (palette->palNumEntries - 1) * sizeof(PALETTEENTRY);
Alexandre Julliard401710d1993-09-04 10:09:32 +000049
Alexandre Julliard18f92e71996-07-17 20:02:21 +000050 dprintf_palette(stddeb,"CreatePalette: ");
51
52 dprintf_palette(stddeb,"%i entries, ", palette->palNumEntries);
53
54 hpalette = GDI_AllocObject( size + sizeof(int*) +sizeof(GDIOBJHDR) , PALETTE_MAGIC );
Alexandre Julliard401710d1993-09-04 10:09:32 +000055 if (!hpalette) return 0;
Alexandre Julliard18f92e71996-07-17 20:02:21 +000056
Alexandre Julliarde2abbb11995-03-19 17:39:39 +000057 palettePtr = (PALETTEOBJ *) GDI_HEAP_LIN_ADDR( hpalette );
Alexandre Julliard401710d1993-09-04 10:09:32 +000058 memcpy( &palettePtr->logpalette, palette, size );
Alexandre Julliard18f92e71996-07-17 20:02:21 +000059 PALETTE_ValidateFlags(palettePtr->logpalette.palPalEntry,
60 palettePtr->logpalette.palNumEntries);
61 palettePtr->mapping = NULL;
62
63 dprintf_palette(stddeb,"returning %04x\n", hpalette);
Alexandre Julliard401710d1993-09-04 10:09:32 +000064 return hpalette;
65}
66
67
68/***********************************************************************
69 * GetPaletteEntries (GDI.363)
70 */
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +000071WORD GetPaletteEntries( HPALETTE16 hpalette, WORD start, WORD count,
Alexandre Julliard401710d1993-09-04 10:09:32 +000072 LPPALETTEENTRY entries )
73{
74 PALETTEOBJ * palPtr;
75 int numEntries;
Alexandre Julliard18f92e71996-07-17 20:02:21 +000076
77 dprintf_palette(stddeb,"GetPaletteEntries: hpal = %04x, %i entries\n", hpalette, count);
Alexandre Julliard401710d1993-09-04 10:09:32 +000078
79 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
80 if (!palPtr) return 0;
Alexandre Julliard18f92e71996-07-17 20:02:21 +000081
Alexandre Julliard401710d1993-09-04 10:09:32 +000082 numEntries = palPtr->logpalette.palNumEntries;
83 if (start >= numEntries) return 0;
84 if (start+count > numEntries) count = numEntries - start;
85 memcpy( entries, &palPtr->logpalette.palPalEntry[start],
86 count * sizeof(PALETTEENTRY) );
Alexandre Julliard18f92e71996-07-17 20:02:21 +000087 for( numEntries = 0; numEntries < count ; numEntries++ )
88 if( entries[numEntries].peFlags & 0xF0 ) entries[numEntries].peFlags = 0;
Alexandre Julliard401710d1993-09-04 10:09:32 +000089 return count;
90}
91
92
93/***********************************************************************
94 * SetPaletteEntries (GDI.364)
95 */
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +000096WORD SetPaletteEntries( HPALETTE16 hpalette, WORD start, WORD count,
Alexandre Julliard401710d1993-09-04 10:09:32 +000097 LPPALETTEENTRY entries )
98{
99 PALETTEOBJ * palPtr;
100 int numEntries;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000101
102 dprintf_palette(stddeb,"SetPaletteEntries: hpal = %04x, %i entries\n", hpalette, count);
103
Alexandre Julliard401710d1993-09-04 10:09:32 +0000104 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
105 if (!palPtr) return 0;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000106
Alexandre Julliard401710d1993-09-04 10:09:32 +0000107 numEntries = palPtr->logpalette.palNumEntries;
108 if (start >= numEntries) return 0;
109 if (start+count > numEntries) count = numEntries - start;
110 memcpy( &palPtr->logpalette.palPalEntry[start], entries,
111 count * sizeof(PALETTEENTRY) );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000112 PALETTE_ValidateFlags(palPtr->logpalette.palPalEntry,
113 palPtr->logpalette.palNumEntries);
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000114 free(palPtr->mapping);
115 palPtr->mapping = NULL;
116
Alexandre Julliard401710d1993-09-04 10:09:32 +0000117 return count;
118}
119
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000120/***********************************************************************
121 * ResizePalette (GDI.368)
122 */
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000123BOOL ResizePalette(HPALETTE16 hPal, UINT cEntries)
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000124{
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000125
126 /* should simply realloc memory and zero out
127 * added entries, if any */
128
Alexandre Julliardade697e1995-11-26 13:59:11 +0000129 fprintf(stdnimp,"ResizePalette: empty stub! \n");
130 return FALSE;
131}
132
133/***********************************************************************
134 * AnimatePalette (GDI.367)
135 */
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000136BOOL AnimatePalette(HPALETTE16 hPal, UINT StartIndex, UINT NumEntries,
Alexandre Julliardade697e1995-11-26 13:59:11 +0000137 LPPALETTEENTRY PaletteColors)
138{
139 fprintf(stdnimp,"AnimatePalette: empty stub! \n");
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000140 return TRUE;
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000141}
Alexandre Julliard401710d1993-09-04 10:09:32 +0000142
143/***********************************************************************
Alexandre Julliarda2f2e011995-06-06 16:40:35 +0000144 * SetSystemPaletteUse (GDI.373)
Alexandre Julliarda2f2e011995-06-06 16:40:35 +0000145 */
146WORD SetSystemPaletteUse( HDC hdc, WORD use)
147{
148 WORD old=SystemPaletteUse;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000149 fprintf(stdnimp,"SetSystemPaletteUse(%04x,%04x) // empty stub !!!\n", hdc, use);
Alexandre Julliarda2f2e011995-06-06 16:40:35 +0000150 SystemPaletteUse=use;
151 return old;
152}
153
154/***********************************************************************
Alexandre Julliard2787be81995-05-22 18:23:01 +0000155 * GetSystemPaletteUse (GDI.374)
156 */
157WORD GetSystemPaletteUse( HDC hdc )
158{
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000159 fprintf(stdnimp,"GetSystemPaletteUse(%04x) // empty stub !!!\n", hdc);
Alexandre Julliarda2f2e011995-06-06 16:40:35 +0000160 return SystemPaletteUse;
Alexandre Julliard2787be81995-05-22 18:23:01 +0000161}
162
163
164/***********************************************************************
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000165 * GetSystemPaletteEntries (GDI.375)
166 */
167WORD GetSystemPaletteEntries( HDC hdc, WORD start, WORD count,
168 LPPALETTEENTRY entries )
169{
170 WORD i;
171 DC *dc;
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000172
173 dprintf_palette(stddeb,"GetSystemPaletteEntries: hdc = %04x, cound = %i", hdc, count );
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000174
175 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return 0;
176 if (start >= dc->w.devCaps->sizePalette) return 0;
177 if (start+count >= dc->w.devCaps->sizePalette)
178 count = dc->w.devCaps->sizePalette - start;
179 for (i = 0; i < count; i++)
180 {
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000181 *(COLORREF*)(entries + i) = COLOR_GetSystemPaletteEntry((BYTE)(start + i));
182
183 dprintf_palette(stddeb,"\tidx(%02x) -> RGB(%08lx)\n", (unsigned char)(start + i),
184 *(COLORREF*)(entries + i) );
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000185 }
186 return count;
187}
188
189
190/***********************************************************************
Alexandre Julliard401710d1993-09-04 10:09:32 +0000191 * GetNearestPaletteIndex (GDI.370)
192 */
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000193WORD GetNearestPaletteIndex( HPALETTE16 hpalette, COLORREF color )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000194{
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000195 PALETTEOBJ* palObj = (PALETTEOBJ*) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
196 WORD index = 0;
197
198 if( palObj )
199 index = COLOR_PaletteLookupPixel( palObj->logpalette.palPalEntry,
200 palObj->logpalette.palNumEntries, NULL,
201 color, FALSE );
202
Alexandre Julliard59730ae1996-03-24 16:20:51 +0000203 dprintf_palette(stddeb,"GetNearestPaletteIndex(%04x,%06lx): returning %d\n",
Alexandre Julliard902da691995-11-05 14:39:02 +0000204 hpalette, color, index );
Alexandre Julliard401710d1993-09-04 10:09:32 +0000205 return index;
206}
207
208
209/***********************************************************************
Alexandre Julliard902da691995-11-05 14:39:02 +0000210 * GetNearestColor (GDI.154)
211 */
212COLORREF GetNearestColor( HDC hdc, COLORREF color )
213{
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000214 COLORREF nearest = 0xFADECAFE;
215 DC *dc;
216 PALETTEOBJ *palObj;
Alexandre Julliard902da691995-11-05 14:39:02 +0000217
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000218 if ( (dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC )) )
219 {
220 palObj = (PALETTEOBJ*)
221 GDI_GetObjPtr( (dc->w.hPalette)? dc->w.hPalette
222 : STOCK_DEFAULT_PALETTE, PALETTE_MAGIC );
223
224 nearest = COLOR_LookupNearestColor( palObj->logpalette.palPalEntry,
225 palObj->logpalette.palNumEntries, color );
226 }
227
Alexandre Julliard902da691995-11-05 14:39:02 +0000228 dprintf_palette(stddeb,"GetNearestColor(%06lx): returning %06lx\n",
229 color, nearest );
230 return nearest;
231}
232
233
234/***********************************************************************
Alexandre Julliard401710d1993-09-04 10:09:32 +0000235 * PALETTE_GetObject
236 */
237int PALETTE_GetObject( PALETTEOBJ * palette, int count, LPSTR buffer )
238{
239 if (count > sizeof(WORD)) count = sizeof(WORD);
240 memcpy( buffer, &palette->logpalette.palNumEntries, count );
241 return count;
242}
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000243
244
245/***********************************************************************
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000246 * PALETTE_UnrealizeObject
247 */
248BOOL PALETTE_UnrealizeObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
249{
250 if (palette->mapping)
251 {
252 free( palette->mapping );
253 palette->mapping = NULL;
254 }
255 if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0;
256 return TRUE;
257}
258
259
260/***********************************************************************
261 * PALETTE_DeleteObject
262 */
263BOOL PALETTE_DeleteObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
264{
265 free( palette->mapping );
266 return GDI_FreeObject( hpalette );
267}
268
269
270/***********************************************************************
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000271 * GDISelectPalette (GDI.361)
272 */
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000273HPALETTE16 GDISelectPalette( HDC hdc, HPALETTE16 hpal, WORD wBkg)
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000274{
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000275 HPALETTE16 prev;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000276 DC *dc;
277
Alexandre Julliard59730ae1996-03-24 16:20:51 +0000278 dprintf_palette(stddeb, "GDISelectPalette: %04x %04x\n", hdc, hpal );
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000279
280 dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
281 if (!dc)
282 {
283 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
284 if (!dc) return 0;
285 }
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000286 prev = dc->w.hPalette;
287 dc->w.hPalette = hpal;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000288 if (!wBkg) hPrimaryPalette = hpal;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000289 return prev;
290}
291
292
293/***********************************************************************
294 * GDIRealizePalette (GDI.362)
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000295 *
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000296 */
297UINT GDIRealizePalette( HDC hdc )
298{
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000299 PALETTEOBJ* palPtr;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000300 int realized = 0;
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000301 DC* dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
302 if (!dc)
303 {
304 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
305 if (!dc) return 0;
306 }
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000307
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000308 dprintf_palette(stddeb, "GDIRealizePalette: %04x...", hdc );
309
310 if( dc && dc->w.hPalette != hLastRealizedPalette )
311 {
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000312 if( dc->w.hPalette == STOCK_DEFAULT_PALETTE )
313 return RealizeDefaultPalette( hdc );
314
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000315 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( dc->w.hPalette, PALETTE_MAGIC );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000316
317 realized = COLOR_SetMapping(palPtr, dc->w.hPalette != hPrimaryPalette
318 || dc->w.hPalette == STOCK_DEFAULT_PALETTE );
319 hLastRealizedPalette = dc->w.hPalette;
320 }
321 else dprintf_palette(stddeb, " skipping ");
322
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000323 dprintf_palette(stdnimp, " realized %i colors\n", realized );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000324 return (UINT)realized;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000325}
326
327
328/***********************************************************************
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000329 * RealizeDefaultPalette (GDI.365)
330 */
331WORD RealizeDefaultPalette( HDC hdc )
332{
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000333 DC *dc;
334 PALETTEOBJ* palPtr;
335 int i, index, realized = 0;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000336
337 dprintf_palette(stddeb,"RealizeDefaultPalette: %04x\n", hdc );
338
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000339 dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
340 if (!dc)
341 {
342 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
343 if (!dc) return 0;
344 }
345
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000346 if ( dc->w.flags & DC_MEMORY ) return 0;
347
348 hPrimaryPalette = STOCK_DEFAULT_PALETTE;
349 hLastRealizedPalette = STOCK_DEFAULT_PALETTE;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000350
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000351 palPtr = (PALETTEOBJ*)GDI_GetObjPtr(STOCK_DEFAULT_PALETTE, PALETTE_MAGIC );
352
353 /* lookup is needed to account for SetSystemPaletteUse() stuff */
354
355 for( i = 0; i < 20; i++ )
356 {
357 index = COLOR_LookupSystemPixel(*(COLORREF*)(palPtr->logpalette.palPalEntry + i));
358
359 /* mapping is allocated in COLOR_InitPalette() */
360
361 if( index != palPtr->mapping[i] ) { palPtr->mapping[i]=index; realized++; }
362 }
363 return realized;
364}
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000365
366/***********************************************************************
367 * IsDCCurrentPalette (GDI.412)
368 */
369BOOL IsDCCurrentPalette(HDC hDC)
370{
371 DC* dc = (DC *)GDI_GetObjPtr( hDC, DC_MAGIC );
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000372 return (dc)?(dc->w.hPalette == hPrimaryPalette):FALSE;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000373}
374
375/***********************************************************************
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000376 * SelectPalette (USER.282)
377 */
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000378HPALETTE16 SelectPalette( HDC hDC, HPALETTE16 hPal, BOOL bForceBackground )
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000379{
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000380 WORD wBkgPalette = 1;
381 PALETTEOBJ* lpt = (PALETTEOBJ*) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
382
383 dprintf_palette(stddeb,"SelectPalette: dc %04x pal %04x, force=%i ",
384 hDC, hPal, bForceBackground);
385 if( !lpt ) return 0;
386
387 dprintf_palette(stddeb," entries = %d\n",
388 lpt->logpalette.palNumEntries);
389
390 if( hPal != STOCK_DEFAULT_PALETTE )
391 {
392 HWND hWnd = DCE_hDC2hWnd( hDC );
393 HWND hActive = GetActiveWindow();
394
395 /* set primary palette if it's related to current active */
396
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000397 if((!hWnd || (hActive == hWnd || IsChild(hActive,hWnd))) &&
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000398 !bForceBackground )
399 wBkgPalette = 0;
400 }
401 return GDISelectPalette( hDC, hPal, wBkgPalette);
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000402}
403
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000404
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000405/***********************************************************************
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000406 * RealizePalette (USER.283) (GDI32.280)
Alexandre Julliardca22b331996-07-12 19:02:39 +0000407 */
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000408UINT16 RealizePalette( HDC32 hDC )
Alexandre Julliardca22b331996-07-12 19:02:39 +0000409{
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000410 UINT16 realized = GDIRealizePalette( hDC );
411
412 /* do not send anything if no colors were changed */
413
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000414 if( IsDCCurrentPalette( hDC ) && realized &&
415 !(COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL) )
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000416 {
417 /* Send palette change notification */
418
419 HWND hWnd;
420 if( (hWnd = DCE_hDC2hWnd( hDC )) )
421 SendMessage16( HWND_BROADCAST, WM_PALETTECHANGED, hWnd, 0L);
422 }
423 return realized;
Alexandre Julliardca22b331996-07-12 19:02:39 +0000424}
425
426
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000427/**********************************************************************
428 * UpdateColors (GDI.366)
429 *
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000430 */
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000431int UpdateColors( HDC hDC )
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000432{
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000433 HWND hWnd = DCE_hDC2hWnd( hDC );
434
435 /* Docs say that we have to remap current drawable pixel by pixel
436 * but it would take forever given the speed of XGet/PutPixel.
437 */
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000438 if (hWnd && !(COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL) )
439 InvalidateRect16( hWnd, NULL, FALSE );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000440 return 0x666;
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000441}
Alexandre Julliardac9c9b01996-07-28 18:50:11 +0000442