Clean out the hack on BASS/TREBLE and suppress them in the mask as was
[wine/testsucceed.git] / objects / palette.c
blobd8e995c485f86093a03731797938a59da569dd95
1 /*
2 * GDI palette objects
4 * Copyright 1993,1994 Alexandre Julliard
5 * Copyright 1996 Alex Korobka
7 * PALETTEOBJ is documented in the Dr. Dobbs Journal May 1993.
8 * Information in the "Undocumented Windows" is incorrect.
9 */
11 #include <stdlib.h>
12 #include <string.h>
14 #include "winbase.h"
15 #include "windef.h"
16 #include "wingdi.h"
17 #include "wine/winuser16.h"
18 #include "gdi.h"
19 #include "color.h"
20 #include "palette.h"
21 #include "debugtools.h"
22 #include "callback.h"
23 #include "winerror.h"
25 DEFAULT_DEBUG_CHANNEL(palette)
27 PALETTE_DRIVER *PALETTE_Driver = NULL;
29 FARPROC pfnSelectPalette = NULL;
30 FARPROC pfnRealizePalette = NULL;
32 static UINT SystemPaletteUse = SYSPAL_STATIC; /* currently not considered */
34 static HPALETTE16 hPrimaryPalette = 0; /* used for WM_PALETTECHANGED */
35 static HPALETTE16 hLastRealizedPalette = 0; /* UnrealizeObject() needs it */
38 /***********************************************************************
39 * PALETTE_Init
41 * Create the system palette.
43 HPALETTE16 PALETTE_Init(void)
45 int i;
46 HPALETTE16 hpalette;
47 LOGPALETTE * palPtr;
48 PALETTEOBJ* palObj;
49 const PALETTEENTRY* __sysPalTemplate = COLOR_GetSystemPaletteTemplate();
51 /* create default palette (20 system colors) */
53 palPtr = HeapAlloc( GetProcessHeap(), 0,
54 sizeof(LOGPALETTE) + (NB_RESERVED_COLORS-1)*sizeof(PALETTEENTRY));
55 if (!palPtr) return FALSE;
57 palPtr->palVersion = 0x300;
58 palPtr->palNumEntries = NB_RESERVED_COLORS;
59 for( i = 0; i < NB_RESERVED_COLORS; i ++ )
61 palPtr->palPalEntry[i].peRed = __sysPalTemplate[i].peRed;
62 palPtr->palPalEntry[i].peGreen = __sysPalTemplate[i].peGreen;
63 palPtr->palPalEntry[i].peBlue = __sysPalTemplate[i].peBlue;
64 palPtr->palPalEntry[i].peFlags = 0;
66 hpalette = CreatePalette16( palPtr );
67 HeapFree( GetProcessHeap(), 0, palPtr );
69 palObj = (PALETTEOBJ*) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
70 if (palObj)
72 if (!(palObj->mapping = HeapAlloc( GetProcessHeap(), 0, sizeof(int) * 20 )))
73 ERR("Can not create palette mapping -- out of memory!");
74 GDI_HEAP_UNLOCK( hpalette );
77 return hpalette;
80 /***********************************************************************
81 * PALETTE_ValidateFlags
83 void PALETTE_ValidateFlags(PALETTEENTRY* lpPalE, int size)
85 int i = 0;
86 for( ; i<size ; i++ )
87 lpPalE[i].peFlags = PC_SYS_USED | (lpPalE[i].peFlags & 0x07);
91 /***********************************************************************
92 * CreatePalette16 (GDI.360)
94 HPALETTE16 WINAPI CreatePalette16( const LOGPALETTE* palette )
96 return CreatePalette( palette );
100 /***********************************************************************
101 * CreatePalette [GDI32.53] Creates a logical color palette
103 * RETURNS
104 * Success: Handle to logical palette
105 * Failure: NULL
107 HPALETTE WINAPI CreatePalette(
108 const LOGPALETTE* palette) /* [in] Pointer to logical color palette */
110 PALETTEOBJ * palettePtr;
111 HPALETTE hpalette;
112 int size;
114 if (!palette) return 0;
115 TRACE("entries=%i\n", palette->palNumEntries);
117 size = sizeof(LOGPALETTE) + (palette->palNumEntries - 1) * sizeof(PALETTEENTRY);
119 hpalette = GDI_AllocObject( size + sizeof(int*) +sizeof(GDIOBJHDR) , PALETTE_MAGIC );
120 if (!hpalette) return 0;
122 palettePtr = (PALETTEOBJ *) GDI_HEAP_LOCK( hpalette );
123 memcpy( &palettePtr->logpalette, palette, size );
124 PALETTE_ValidateFlags(palettePtr->logpalette.palPalEntry,
125 palettePtr->logpalette.palNumEntries);
126 palettePtr->mapping = NULL;
127 GDI_HEAP_UNLOCK( hpalette );
129 TRACE(" returning %04x\n", hpalette);
130 return hpalette;
134 /***********************************************************************
135 * CreateHalftonePalette16 [GDI.?] Creates a halftone palette
137 * RETURNS
138 * Success: Handle to logical halftone palette
139 * Failure: 0
141 HPALETTE16 WINAPI CreateHalftonePalette16(
142 HDC16 hdc) /* [in] Handle to device context */
144 return CreateHalftonePalette(hdc);
148 /***********************************************************************
149 * CreateHalftonePalette [GDI32.47] Creates a halftone palette
151 * RETURNS
152 * Success: Handle to logical halftone palette
153 * Failure: 0
155 * FIXME: not truly tested
157 HPALETTE WINAPI CreateHalftonePalette(
158 HDC hdc) /* [in] Handle to device context */
160 int i, r, g, b;
161 struct {
162 WORD Version;
163 WORD NumberOfEntries;
164 PALETTEENTRY aEntries[256];
165 } Palette = {
166 0x300, 256
169 GetSystemPaletteEntries(hdc, 0, 256, Palette.aEntries);
170 return CreatePalette((LOGPALETTE *)&Palette);
172 for (r = 0; r < 6; r++) {
173 for (g = 0; g < 6; g++) {
174 for (b = 0; b < 6; b++) {
175 i = r + g*6 + b*36 + 10;
176 Palette.aEntries[i].peRed = r * 51;
177 Palette.aEntries[i].peGreen = g * 51;
178 Palette.aEntries[i].peBlue = b * 51;
183 for (i = 216; i < 246; i++) {
184 int v = (i - 216) * 8;
185 Palette.aEntries[i].peRed = v;
186 Palette.aEntries[i].peGreen = v;
187 Palette.aEntries[i].peBlue = v;
190 return CreatePalette((LOGPALETTE *)&Palette);
194 /***********************************************************************
195 * GetPaletteEntries16 (GDI.363)
197 UINT16 WINAPI GetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
198 UINT16 count, LPPALETTEENTRY entries )
200 return GetPaletteEntries( hpalette, start, count, entries );
204 /***********************************************************************
205 * GetPaletteEntries [GDI32.209] Retrieves palette entries
207 * RETURNS
208 * Success: Number of entries from logical palette
209 * Failure: 0
211 UINT WINAPI GetPaletteEntries(
212 HPALETTE hpalette, /* [in] Handle of logical palette */
213 UINT start, /* [in] First entry to receive */
214 UINT count, /* [in] Number of entries to receive */
215 LPPALETTEENTRY entries) /* [out] Address of array receiving entries */
217 PALETTEOBJ * palPtr;
218 INT numEntries;
220 TRACE("hpal = %04x, count=%i\n", hpalette, count );
222 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
223 if (!palPtr) return 0;
225 numEntries = palPtr->logpalette.palNumEntries;
226 if (start+count > numEntries) count = numEntries - start;
227 if (entries)
229 if (start >= numEntries)
231 GDI_HEAP_UNLOCK( hpalette );
232 return 0;
234 memcpy( entries, &palPtr->logpalette.palPalEntry[start],
235 count * sizeof(PALETTEENTRY) );
236 for( numEntries = 0; numEntries < count ; numEntries++ )
237 if (entries[numEntries].peFlags & 0xF0)
238 entries[numEntries].peFlags = 0;
239 GDI_HEAP_UNLOCK( hpalette );
242 return count;
246 /***********************************************************************
247 * SetPaletteEntries16 (GDI.364)
249 UINT16 WINAPI SetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
250 UINT16 count, LPPALETTEENTRY entries )
252 return SetPaletteEntries( hpalette, start, count, entries );
256 /***********************************************************************
257 * SetPaletteEntries [GDI32.326] Sets color values for range in palette
259 * RETURNS
260 * Success: Number of entries that were set
261 * Failure: 0
263 UINT WINAPI SetPaletteEntries(
264 HPALETTE hpalette, /* [in] Handle of logical palette */
265 UINT start, /* [in] Index of first entry to set */
266 UINT count, /* [in] Number of entries to set */
267 LPPALETTEENTRY entries) /* [in] Address of array of structures */
269 PALETTEOBJ * palPtr;
270 INT numEntries;
272 TRACE("hpal=%04x,start=%i,count=%i\n",hpalette,start,count );
274 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
275 if (!palPtr) return 0;
277 numEntries = palPtr->logpalette.palNumEntries;
278 if (start >= numEntries)
280 GDI_HEAP_UNLOCK( hpalette );
281 return 0;
283 if (start+count > numEntries) count = numEntries - start;
284 memcpy( &palPtr->logpalette.palPalEntry[start], entries,
285 count * sizeof(PALETTEENTRY) );
286 PALETTE_ValidateFlags(palPtr->logpalette.palPalEntry,
287 palPtr->logpalette.palNumEntries);
288 HeapFree( GetProcessHeap(), 0, palPtr->mapping );
289 palPtr->mapping = NULL;
290 GDI_HEAP_UNLOCK( hpalette );
291 return count;
295 /***********************************************************************
296 * ResizePalette16 (GDI.368)
298 BOOL16 WINAPI ResizePalette16( HPALETTE16 hPal, UINT16 cEntries )
300 return ResizePalette( hPal, cEntries );
304 /***********************************************************************
305 * ResizePalette [GDI32.289] Resizes logical palette
307 * RETURNS
308 * Success: TRUE
309 * Failure: FALSE
311 BOOL WINAPI ResizePalette(
312 HPALETTE hPal, /* [in] Handle of logical palette */
313 UINT cEntries) /* [in] Number of entries in logical palette */
315 PALETTEOBJ * palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
316 UINT cPrevEnt, prevVer;
317 int prevsize, size = sizeof(LOGPALETTE) + (cEntries - 1) * sizeof(PALETTEENTRY);
318 int* mapping = NULL;
320 TRACE("hpal = %04x, prev = %i, new = %i\n",
321 hPal, palPtr ? palPtr->logpalette.palNumEntries : -1,
322 cEntries );
323 if( !palPtr ) return FALSE;
324 cPrevEnt = palPtr->logpalette.palNumEntries;
325 prevVer = palPtr->logpalette.palVersion;
326 prevsize = sizeof(LOGPALETTE) + (cPrevEnt - 1) * sizeof(PALETTEENTRY) +
327 sizeof(int*) + sizeof(GDIOBJHDR);
328 size += sizeof(int*) + sizeof(GDIOBJHDR);
329 mapping = palPtr->mapping;
331 GDI_HEAP_UNLOCK( hPal );
333 hPal = GDI_HEAP_REALLOC( hPal, size );
334 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
335 if( !palPtr ) return FALSE;
337 if( mapping )
339 int *newMap = (int*) HeapReAlloc(GetProcessHeap(), 0,
340 mapping, cEntries * sizeof(int) );
341 if(newMap == NULL)
343 ERR("Can not resize mapping -- out of memory!");
344 GDI_HEAP_UNLOCK( hPal );
345 return FALSE;
347 palPtr->mapping = newMap;
350 if( cEntries > cPrevEnt )
352 if( mapping )
353 memset(palPtr->mapping + cPrevEnt, 0, (cEntries - cPrevEnt)*sizeof(int));
354 memset( (BYTE*)palPtr + prevsize, 0, size - prevsize );
355 PALETTE_ValidateFlags((PALETTEENTRY*)((BYTE*)palPtr + prevsize),
356 cEntries - cPrevEnt );
358 palPtr->logpalette.palNumEntries = cEntries;
359 palPtr->logpalette.palVersion = prevVer;
360 GDI_HEAP_UNLOCK( hPal );
361 return TRUE;
365 /***********************************************************************
366 * AnimatePalette16 (GDI.367)
368 void WINAPI AnimatePalette16( HPALETTE16 hPal, UINT16 StartIndex,
369 UINT16 NumEntries, const PALETTEENTRY* PaletteColors)
371 AnimatePalette( hPal, StartIndex, NumEntries, PaletteColors );
375 /***********************************************************************
376 * AnimatePalette [GDI32.6] Replaces entries in logical palette
378 * RETURNS
379 * Success: TRUE
380 * Failure: FALSE
382 * FIXME
383 * Should use existing mapping when animating a primary palette
385 BOOL WINAPI AnimatePalette(
386 HPALETTE hPal, /* [in] Handle to logical palette */
387 UINT StartIndex, /* [in] First entry in palette */
388 UINT NumEntries, /* [in] Count of entries in palette */
389 const PALETTEENTRY* PaletteColors) /* [in] Pointer to first replacement */
391 TRACE("%04x (%i - %i)\n", hPal, StartIndex,StartIndex+NumEntries);
393 if( hPal != STOCK_DEFAULT_PALETTE )
395 PALETTEOBJ* palPtr = (PALETTEOBJ *)GDI_GetObjPtr(hPal, PALETTE_MAGIC);
396 if (!palPtr) return FALSE;
398 if( (StartIndex + NumEntries) <= palPtr->logpalette.palNumEntries )
400 UINT u;
401 for( u = 0; u < NumEntries; u++ )
402 palPtr->logpalette.palPalEntry[u + StartIndex] = PaletteColors[u];
403 PALETTE_Driver->
404 pSetMapping(palPtr, StartIndex, NumEntries,
405 hPal != hPrimaryPalette );
406 GDI_HEAP_UNLOCK( hPal );
407 return TRUE;
410 return FALSE;
414 /***********************************************************************
415 * SetSystemPaletteUse16 (GDI.373)
417 UINT16 WINAPI SetSystemPaletteUse16( HDC16 hdc, UINT16 use )
419 return SetSystemPaletteUse( hdc, use );
423 /***********************************************************************
424 * SetSystemPaletteUse [GDI32.335]
426 * RETURNS
427 * Success: Previous system palette
428 * Failure: SYSPAL_ERROR
430 UINT WINAPI SetSystemPaletteUse(
431 HDC hdc, /* [in] Handle of device context */
432 UINT use) /* [in] Palette-usage flag */
434 UINT old = SystemPaletteUse;
435 FIXME("(%04x,%04x): stub\n", hdc, use );
436 SystemPaletteUse = use;
437 return old;
441 /***********************************************************************
442 * GetSystemPaletteUse16 (GDI.374)
444 UINT16 WINAPI GetSystemPaletteUse16( HDC16 hdc )
446 return SystemPaletteUse;
450 /***********************************************************************
451 * GetSystemPaletteUse [GDI32.223] Gets state of system palette
453 * RETURNS
454 * Current state of system palette
456 UINT WINAPI GetSystemPaletteUse(
457 HDC hdc) /* [in] Handle of device context */
459 return SystemPaletteUse;
463 /***********************************************************************
464 * GetSystemPaletteEntries16 (GDI.375)
466 UINT16 WINAPI GetSystemPaletteEntries16( HDC16 hdc, UINT16 start, UINT16 count,
467 LPPALETTEENTRY entries )
469 return GetSystemPaletteEntries( hdc, start, count, entries );
473 /***********************************************************************
474 * GetSystemPaletteEntries [GDI32.222] Gets range of palette entries
476 * RETURNS
477 * Success: Number of entries retrieved from palette
478 * Failure: 0
480 UINT WINAPI GetSystemPaletteEntries(
481 HDC hdc, /* [in] Handle of device context */
482 UINT start, /* [in] Index of first entry to be retrieved */
483 UINT count, /* [in] Number of entries to be retrieved */
484 LPPALETTEENTRY entries) /* [out] Array receiving system-palette entries */
486 UINT i;
487 DC *dc;
489 TRACE("hdc=%04x,start=%i,count=%i\n", hdc,start,count);
491 if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return 0;
492 if (!entries) return dc->w.devCaps->sizePalette;
493 if (start >= dc->w.devCaps->sizePalette)
495 GDI_HEAP_UNLOCK( hdc );
496 return 0;
498 if (start+count >= dc->w.devCaps->sizePalette)
499 count = dc->w.devCaps->sizePalette - start;
500 for (i = 0; i < count; i++)
502 *(COLORREF*)(entries + i) = COLOR_GetSystemPaletteEntry( start + i );
504 TRACE("\tidx(%02x) -> RGB(%08lx)\n",
505 start + i, *(COLORREF*)(entries + i) );
507 GDI_HEAP_UNLOCK( hdc );
508 return count;
512 /***********************************************************************
513 * GetNearestPaletteIndex16 (GDI.370)
515 UINT16 WINAPI GetNearestPaletteIndex16( HPALETTE16 hpalette, COLORREF color )
517 return GetNearestPaletteIndex( hpalette, color );
521 /***********************************************************************
522 * GetNearestPaletteIndex [GDI32.203] Gets palette index for color
524 * NOTES
525 * Should index be initialized to CLR_INVALID instead of 0?
527 * RETURNS
528 * Success: Index of entry in logical palette
529 * Failure: CLR_INVALID
531 UINT WINAPI GetNearestPaletteIndex(
532 HPALETTE hpalette, /* [in] Handle of logical color palette */
533 COLORREF color) /* [in] Color to be matched */
535 PALETTEOBJ* palObj = (PALETTEOBJ*)GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
536 UINT index = 0;
538 if( palObj )
539 index = COLOR_PaletteLookupPixel(palObj->logpalette.palPalEntry,
540 palObj->logpalette.palNumEntries,
541 NULL, color, FALSE );
543 TRACE("(%04x,%06lx): returning %d\n", hpalette, color, index );
544 GDI_HEAP_UNLOCK( hpalette );
545 return index;
549 /***********************************************************************
550 * GetNearestColor16 (GDI.154)
552 COLORREF WINAPI GetNearestColor16( HDC16 hdc, COLORREF color )
554 return GetNearestColor( hdc, color );
558 /***********************************************************************
559 * GetNearestColor [GDI32.202] Gets a system color to match
561 * NOTES
562 * Should this return CLR_INVALID instead of FadeCafe?
564 * RETURNS
565 * Success: Color from system palette that corresponds to given color
566 * Failure: CLR_INVALID
568 COLORREF WINAPI GetNearestColor(
569 HDC hdc, /* [in] Handle of device context */
570 COLORREF color) /* [in] Color to be matched */
572 COLORREF nearest = 0xFADECAFE;
573 DC *dc;
574 PALETTEOBJ *palObj;
576 if ( (dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC )) )
578 palObj = (PALETTEOBJ*)
579 GDI_GetObjPtr( (dc->w.hPalette)? dc->w.hPalette
580 : STOCK_DEFAULT_PALETTE, PALETTE_MAGIC );
581 if (!palObj) return nearest;
583 nearest = COLOR_LookupNearestColor( palObj->logpalette.palPalEntry,
584 palObj->logpalette.palNumEntries, color );
585 GDI_HEAP_UNLOCK( dc->w.hPalette );
588 TRACE("(%06lx): returning %06lx\n", color, nearest );
589 GDI_HEAP_UNLOCK( hdc );
590 return nearest;
594 /***********************************************************************
595 * PALETTE_GetObject
597 int PALETTE_GetObject( PALETTEOBJ * palette, int count, LPSTR buffer )
599 if (count > sizeof(WORD)) count = sizeof(WORD);
600 memcpy( buffer, &palette->logpalette.palNumEntries, count );
601 return count;
605 /***********************************************************************
606 * PALETTE_UnrealizeObject
608 BOOL PALETTE_UnrealizeObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
610 if (palette->mapping)
612 HeapFree( GetProcessHeap(), 0, palette->mapping );
613 palette->mapping = NULL;
615 if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0;
616 return TRUE;
620 /***********************************************************************
621 * PALETTE_DeleteObject
623 BOOL PALETTE_DeleteObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
625 HeapFree( GetProcessHeap(), 0, palette->mapping );
626 if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0;
627 return GDI_FreeObject( hpalette );
631 /***********************************************************************
632 * GDISelectPalette (GDI.361)
634 HPALETTE16 WINAPI GDISelectPalette16( HDC16 hdc, HPALETTE16 hpal, WORD wBkg)
636 HPALETTE16 prev;
637 DC *dc;
639 TRACE("%04x %04x\n", hdc, hpal );
641 dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
642 if (!dc)
644 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
645 if (!dc) return 0;
647 prev = dc->w.hPalette;
648 dc->w.hPalette = hpal;
649 GDI_HEAP_UNLOCK( hdc );
650 if (!wBkg) hPrimaryPalette = hpal;
651 return prev;
655 /***********************************************************************
656 * GDIRealizePalette (GDI.362)
658 UINT16 WINAPI GDIRealizePalette16( HDC16 hdc )
660 PALETTEOBJ* palPtr;
661 int realized = 0;
662 DC* dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
663 if (!dc)
665 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
666 if (!dc) return 0;
669 TRACE("%04x...\n", hdc );
671 if( dc && dc->w.hPalette != hLastRealizedPalette )
673 if( dc->w.hPalette == STOCK_DEFAULT_PALETTE )
674 return RealizeDefaultPalette16( hdc );
676 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( dc->w.hPalette, PALETTE_MAGIC );
678 if (!palPtr) {
679 FIXME("invalid selected palette %04x\n",dc->w.hPalette);
680 return 0;
683 realized = PALETTE_Driver->
684 pSetMapping(palPtr,0,palPtr->logpalette.palNumEntries,
685 (dc->w.hPalette != hPrimaryPalette) ||
686 (dc->w.hPalette == STOCK_DEFAULT_PALETTE));
687 GDI_HEAP_UNLOCK( dc->w.hPalette );
688 hLastRealizedPalette = dc->w.hPalette;
690 else TRACE(" skipping (hLastRealizedPalette = %04x)\n",
691 hLastRealizedPalette);
692 GDI_HEAP_UNLOCK( hdc );
694 TRACE(" realized %i colors.\n", realized );
695 return (UINT16)realized;
699 /***********************************************************************
700 * RealizeDefaultPalette (GDI.365)
702 UINT16 WINAPI RealizeDefaultPalette16( HDC16 hdc )
704 DC *dc;
705 PALETTEOBJ* palPtr;
707 TRACE("%04x\n", hdc );
709 dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
710 if (!dc)
712 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
713 if (!dc) return 0;
716 if ( dc->w.flags & DC_MEMORY )
718 GDI_HEAP_UNLOCK( hdc );
719 return 0;
722 hPrimaryPalette = STOCK_DEFAULT_PALETTE;
723 hLastRealizedPalette = STOCK_DEFAULT_PALETTE;
725 palPtr = (PALETTEOBJ*)GDI_GetObjPtr(STOCK_DEFAULT_PALETTE, PALETTE_MAGIC );
726 if (!palPtr) return 0;
728 /* lookup is needed to account for SetSystemPaletteUse() stuff */
730 return PALETTE_Driver->pUpdateMapping(palPtr);
733 /***********************************************************************
734 * IsDCCurrentPalette (GDI.412)
736 BOOL16 WINAPI IsDCCurrentPalette16(HDC16 hDC)
738 DC* dc = (DC *)GDI_GetObjPtr( hDC, DC_MAGIC );
739 if (dc)
741 GDI_HEAP_UNLOCK( hDC );
742 return dc->w.hPalette == hPrimaryPalette;
744 return FALSE;
748 /***********************************************************************
749 * SelectPalette [GDI32.300] Selects logical palette into DC
751 * RETURNS
752 * Success: Previous logical palette
753 * Failure: NULL
755 HPALETTE 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 */
760 WORD wBkgPalette = 1;
762 if (!bForceBackground && (hPal != STOCK_DEFAULT_PALETTE))
764 HWND hwnd = Callout.WindowFromDC( hDC );
765 if (hwnd)
767 HWND hForeground = Callout.GetForegroundWindow();
768 /* set primary palette if it's related to current active */
769 if (hForeground == hwnd || Callout.IsChild(hForeground,hwnd)) wBkgPalette = 0;
772 return GDISelectPalette16( hDC, hPal, wBkgPalette);
776 /***********************************************************************
777 * RealizePalette [GDI32.280] Maps palette entries to system palette
779 * RETURNS
780 * Success: Number of entries in logical palette
781 * Failure: GDI_ERROR
783 UINT WINAPI RealizePalette(
784 HDC hDC) /* [in] Handle of device context */
786 DC *dc;
787 UINT realized;
789 if (!(dc = (DC *) GDI_GetObjPtr( hDC, DC_MAGIC ))) return 0;
791 realized = GDIRealizePalette16( hDC );
793 /* do not send anything if no colors were changed */
795 if( IsDCCurrentPalette16( hDC ) && realized &&
796 dc->w.devCaps->sizePalette )
798 /* Send palette change notification */
800 HWND hWnd;
801 if( (hWnd = Callout.WindowFromDC( hDC )) )
802 Callout.SendMessageA( HWND_BROADCAST, WM_PALETTECHANGED, hWnd, 0L);
805 GDI_HEAP_UNLOCK( hDC );
806 return realized;
810 /**********************************************************************
811 * UpdateColors16 (GDI.366)
813 INT16 WINAPI UpdateColors16( HDC16 hDC )
815 DC *dc;
816 HWND hWnd;
818 if (!(dc = (DC *) GDI_GetObjPtr( hDC, DC_MAGIC ))) return 0;
820 hWnd = Callout.WindowFromDC( hDC );
822 /* Docs say that we have to remap current drawable pixel by pixel
823 * but it would take forever given the speed of XGet/PutPixel.
825 if (hWnd && dc->w.devCaps->sizePalette )
826 Callout.RedrawWindow( hWnd, NULL, 0, RDW_INVALIDATE );
828 GDI_HEAP_UNLOCK( hDC );
830 return 0x666;
834 /**********************************************************************
835 * UpdateColors [GDI32.359] Remaps current colors to logical palette
837 * RETURNS
838 * Success: TRUE
839 * Failure: FALSE
841 BOOL WINAPI UpdateColors(
842 HDC hDC) /* [in] Handle of device context */
844 UpdateColors16( hDC );
845 return TRUE;
849 /*********************************************************************
850 * SetMagicColors16 (GDI.606)
852 VOID WINAPI SetMagicColors16(HDC16 hDC, COLORREF color, UINT16 index)
854 FIXME("(hDC %04x, color %04x, index %04x): stub\n", hDC, (int)color, index);
858 /**********************************************************************
859 * GetICMProfileA [GDI32.316]
861 * Returns the filename of the specified device context's color
862 * management profile, even if color management is not enabled
863 * for that DC.
865 * RETURNS
866 * TRUE if name copied succesfully OR lpszFilename is NULL
867 * FALSE if the buffer length pointed to by lpcbName is too small
869 * NOTE
870 * The buffer length pointed to by lpcbName is ALWAYS updated to
871 * the length required regardless of other actions this function
872 * may take.
874 * FIXME
875 * How does Windows assign these? Some registry key?
878 #define WINEICM "winefake.icm" /* easy-to-identify fake filename */
880 BOOL WINAPI GetICMProfileA(HDC hDC, LPDWORD lpcbName, LPSTR lpszFilename)
882 DWORD callerLen;
884 FIXME("(%04x, %p, %p): partial stub\n", hDC, lpcbName, lpszFilename);
886 callerLen = *lpcbName;
888 /* all 3 behaviors require the required buffer size to be set */
889 *lpcbName = strlen(WINEICM);
891 /* behavior 1: if lpszFilename is NULL, return size of string and no error */
892 if ((DWORD)lpszFilename == (DWORD)0x00000000)
893 return TRUE;
895 /* behavior 2: if buffer size too small, return size of string and error */
896 if (callerLen < strlen(WINEICM))
898 SetLastError(ERROR_INSUFFICIENT_BUFFER);
899 return FALSE;
902 /* behavior 3: if buffer size OK and pointer not NULL, copy and return size */
903 strcpy(lpszFilename, WINEICM);
904 return TRUE;