Prepare switching to unicode of builtin widgets.
[wine.git] / objects / palette.c
blob3a634aa6a27dbf21f555828c36d555caf49b863c
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 /* Pointers to USER implementation of SelectPalette/RealizePalette */
30 /* they will be patched by USER on startup */
31 FARPROC pfnSelectPalette = NULL;
32 FARPROC pfnRealizePalette = NULL;
34 static UINT SystemPaletteUse = SYSPAL_STATIC; /* currently not considered */
36 static HPALETTE16 hPrimaryPalette = 0; /* used for WM_PALETTECHANGED */
37 static HPALETTE16 hLastRealizedPalette = 0; /* UnrealizeObject() needs it */
40 /***********************************************************************
41 * PALETTE_Init
43 * Create the system palette.
45 HPALETTE16 PALETTE_Init(void)
47 int i;
48 HPALETTE16 hpalette;
49 LOGPALETTE * palPtr;
50 PALETTEOBJ* palObj;
51 const PALETTEENTRY* __sysPalTemplate = COLOR_GetSystemPaletteTemplate();
53 /* create default palette (20 system colors) */
55 palPtr = HeapAlloc( GetProcessHeap(), 0,
56 sizeof(LOGPALETTE) + (NB_RESERVED_COLORS-1)*sizeof(PALETTEENTRY));
57 if (!palPtr) return FALSE;
59 palPtr->palVersion = 0x300;
60 palPtr->palNumEntries = NB_RESERVED_COLORS;
61 for( i = 0; i < NB_RESERVED_COLORS; i ++ )
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;
68 hpalette = CreatePalette16( palPtr );
69 HeapFree( GetProcessHeap(), 0, palPtr );
71 palObj = (PALETTEOBJ*) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
72 if (palObj)
74 if (!(palObj->mapping = HeapAlloc( GetProcessHeap(), 0, sizeof(int) * 20 )))
75 ERR("Can not create palette mapping -- out of memory!");
76 GDI_ReleaseObj( hpalette );
78 return hpalette;
81 /***********************************************************************
82 * PALETTE_ValidateFlags
84 void PALETTE_ValidateFlags(PALETTEENTRY* lpPalE, int size)
86 int i = 0;
87 for( ; i<size ; i++ )
88 lpPalE[i].peFlags = PC_SYS_USED | (lpPalE[i].peFlags & 0x07);
92 /***********************************************************************
93 * CreatePalette16 (GDI.360)
95 HPALETTE16 WINAPI CreatePalette16( const LOGPALETTE* palette )
97 return CreatePalette( palette );
101 /***********************************************************************
102 * CreatePalette [GDI32.53] Creates a logical color palette
104 * RETURNS
105 * Success: Handle to logical palette
106 * Failure: NULL
108 HPALETTE WINAPI CreatePalette(
109 const LOGPALETTE* palette) /* [in] Pointer to logical color palette */
111 PALETTEOBJ * palettePtr;
112 HPALETTE hpalette;
113 int size;
115 if (!palette) return 0;
116 TRACE("entries=%i\n", palette->palNumEntries);
118 size = sizeof(LOGPALETTE) + (palette->palNumEntries - 1) * sizeof(PALETTEENTRY);
120 if (!(palettePtr = GDI_AllocObject( size + sizeof(int*) +sizeof(GDIOBJHDR),
121 PALETTE_MAGIC, &hpalette ))) return 0;
122 memcpy( &palettePtr->logpalette, palette, size );
123 PALETTE_ValidateFlags(palettePtr->logpalette.palPalEntry,
124 palettePtr->logpalette.palNumEntries);
125 palettePtr->mapping = NULL;
126 GDI_ReleaseObj( hpalette );
128 TRACE(" returning %04x\n", hpalette);
129 return hpalette;
133 /***********************************************************************
134 * CreateHalftonePalette16 [GDI.?] Creates a halftone palette
136 * RETURNS
137 * Success: Handle to logical halftone palette
138 * Failure: 0
140 HPALETTE16 WINAPI CreateHalftonePalette16(
141 HDC16 hdc) /* [in] Handle to device context */
143 return CreateHalftonePalette(hdc);
147 /***********************************************************************
148 * CreateHalftonePalette [GDI32.47] Creates a halftone palette
150 * RETURNS
151 * Success: Handle to logical halftone palette
152 * Failure: 0
154 * FIXME: not truly tested
156 HPALETTE WINAPI CreateHalftonePalette(
157 HDC hdc) /* [in] Handle to device context */
159 int i, r, g, b;
160 struct {
161 WORD Version;
162 WORD NumberOfEntries;
163 PALETTEENTRY aEntries[256];
164 } Palette;
166 Palette.Version = 0x300;
167 Palette.NumberOfEntries = 256;
168 GetSystemPaletteEntries(hdc, 0, 256, Palette.aEntries);
170 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;
181 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;
188 return CreatePalette((LOGPALETTE *)&Palette);
192 /***********************************************************************
193 * GetPaletteEntries16 (GDI.363)
195 UINT16 WINAPI GetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
196 UINT16 count, LPPALETTEENTRY entries )
198 return GetPaletteEntries( hpalette, start, count, entries );
202 /***********************************************************************
203 * GetPaletteEntries [GDI32.209] Retrieves palette entries
205 * RETURNS
206 * Success: Number of entries from logical palette
207 * Failure: 0
209 UINT 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 */
213 LPPALETTEENTRY entries) /* [out] Address of array receiving entries */
215 PALETTEOBJ * palPtr;
216 INT numEntries;
218 TRACE("hpal = %04x, count=%i\n", hpalette, count );
220 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
221 if (!palPtr) return 0;
223 numEntries = palPtr->logpalette.palNumEntries;
224 if (start+count > numEntries) count = numEntries - start;
225 if (entries)
227 if (start >= numEntries)
229 GDI_ReleaseObj( hpalette );
230 return 0;
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;
239 GDI_ReleaseObj( hpalette );
240 return count;
244 /***********************************************************************
245 * SetPaletteEntries16 (GDI.364)
247 UINT16 WINAPI SetPaletteEntries16( HPALETTE16 hpalette, UINT16 start,
248 UINT16 count, LPPALETTEENTRY entries )
250 return SetPaletteEntries( hpalette, start, count, entries );
254 /***********************************************************************
255 * SetPaletteEntries [GDI32.326] Sets color values for range in palette
257 * RETURNS
258 * Success: Number of entries that were set
259 * Failure: 0
261 UINT 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 */
265 LPPALETTEENTRY entries) /* [in] Address of array of structures */
267 PALETTEOBJ * palPtr;
268 INT numEntries;
270 TRACE("hpal=%04x,start=%i,count=%i\n",hpalette,start,count );
272 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
273 if (!palPtr) return 0;
275 numEntries = palPtr->logpalette.palNumEntries;
276 if (start >= numEntries)
278 GDI_ReleaseObj( hpalette );
279 return 0;
281 if (start+count > numEntries) count = numEntries - start;
282 memcpy( &palPtr->logpalette.palPalEntry[start], entries,
283 count * sizeof(PALETTEENTRY) );
284 PALETTE_ValidateFlags(palPtr->logpalette.palPalEntry,
285 palPtr->logpalette.palNumEntries);
286 HeapFree( GetProcessHeap(), 0, palPtr->mapping );
287 palPtr->mapping = NULL;
288 GDI_ReleaseObj( hpalette );
289 return count;
293 /***********************************************************************
294 * ResizePalette16 (GDI.368)
296 BOOL16 WINAPI ResizePalette16( HPALETTE16 hPal, UINT16 cEntries )
298 return ResizePalette( hPal, cEntries );
302 /***********************************************************************
303 * ResizePalette [GDI32.289] Resizes logical palette
305 * RETURNS
306 * Success: TRUE
307 * Failure: FALSE
309 BOOL WINAPI ResizePalette(
310 HPALETTE hPal, /* [in] Handle of logical palette */
311 UINT cEntries) /* [in] Number of entries in logical palette */
313 PALETTEOBJ * palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC );
314 UINT cPrevEnt, prevVer;
315 int prevsize, size = sizeof(LOGPALETTE) + (cEntries - 1) * sizeof(PALETTEENTRY);
316 int* mapping = NULL;
318 TRACE("hpal = %04x, prev = %i, new = %i\n",
319 hPal, palPtr ? palPtr->logpalette.palNumEntries : -1,
320 cEntries );
321 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;
329 if (!(palPtr = GDI_ReallocObject( size, hPal, palPtr ))) return FALSE;
331 if( mapping )
333 int *newMap = (int*) HeapReAlloc(GetProcessHeap(), 0,
334 mapping, cEntries * sizeof(int) );
335 if(newMap == NULL)
337 ERR("Can not resize mapping -- out of memory!");
338 GDI_ReleaseObj( hPal );
339 return FALSE;
341 palPtr->mapping = newMap;
344 if( cEntries > cPrevEnt )
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 );
352 palPtr->logpalette.palNumEntries = cEntries;
353 palPtr->logpalette.palVersion = prevVer;
354 GDI_ReleaseObj( hPal );
355 return TRUE;
359 /***********************************************************************
360 * AnimatePalette16 (GDI.367)
362 void WINAPI AnimatePalette16( HPALETTE16 hPal, UINT16 StartIndex,
363 UINT16 NumEntries, const PALETTEENTRY* PaletteColors)
365 AnimatePalette( hPal, StartIndex, NumEntries, PaletteColors );
369 /***********************************************************************
370 * AnimatePalette [GDI32.6] Replaces entries in logical palette
372 * RETURNS
373 * Success: TRUE
374 * Failure: FALSE
376 * FIXME
377 * Should use existing mapping when animating a primary palette
379 BOOL 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 */
383 const PALETTEENTRY* PaletteColors) /* [in] Pointer to first replacement */
385 TRACE("%04x (%i - %i)\n", hPal, StartIndex,StartIndex+NumEntries);
387 if( hPal != GetStockObject(DEFAULT_PALETTE) )
389 PALETTEOBJ* palPtr = (PALETTEOBJ *)GDI_GetObjPtr(hPal, PALETTE_MAGIC);
390 if (!palPtr) return FALSE;
392 if( (StartIndex + NumEntries) <= palPtr->logpalette.palNumEntries )
394 UINT u;
395 for( u = 0; u < NumEntries; u++ )
396 palPtr->logpalette.palPalEntry[u + StartIndex] = PaletteColors[u];
397 PALETTE_Driver->
398 pSetMapping(palPtr, StartIndex, NumEntries,
399 hPal != hPrimaryPalette );
400 GDI_ReleaseObj( hPal );
401 return TRUE;
403 GDI_ReleaseObj( hPal );
405 return FALSE;
409 /***********************************************************************
410 * SetSystemPaletteUse16 (GDI.373)
412 UINT16 WINAPI SetSystemPaletteUse16( HDC16 hdc, UINT16 use )
414 return SetSystemPaletteUse( hdc, use );
418 /***********************************************************************
419 * SetSystemPaletteUse [GDI32.335]
421 * RETURNS
422 * Success: Previous system palette
423 * Failure: SYSPAL_ERROR
425 UINT WINAPI SetSystemPaletteUse(
426 HDC hdc, /* [in] Handle of device context */
427 UINT use) /* [in] Palette-usage flag */
429 UINT old = SystemPaletteUse;
430 FIXME("(%04x,%04x): stub\n", hdc, use );
431 SystemPaletteUse = use;
432 return old;
436 /***********************************************************************
437 * GetSystemPaletteUse16 (GDI.374)
439 UINT16 WINAPI GetSystemPaletteUse16( HDC16 hdc )
441 return SystemPaletteUse;
445 /***********************************************************************
446 * GetSystemPaletteUse [GDI32.223] Gets state of system palette
448 * RETURNS
449 * Current state of system palette
451 UINT WINAPI GetSystemPaletteUse(
452 HDC hdc) /* [in] Handle of device context */
454 return SystemPaletteUse;
458 /***********************************************************************
459 * GetSystemPaletteEntries16 (GDI.375)
461 UINT16 WINAPI GetSystemPaletteEntries16( HDC16 hdc, UINT16 start, UINT16 count,
462 LPPALETTEENTRY entries )
464 return GetSystemPaletteEntries( hdc, start, count, entries );
468 /***********************************************************************
469 * GetSystemPaletteEntries [GDI32.222] Gets range of palette entries
471 * RETURNS
472 * Success: Number of entries retrieved from palette
473 * Failure: 0
475 UINT 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 */
479 LPPALETTEENTRY entries) /* [out] Array receiving system-palette entries */
481 UINT i;
482 DC *dc;
484 TRACE("hdc=%04x,start=%i,count=%i\n", hdc,start,count);
486 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
488 if (!entries)
490 count = dc->devCaps->sizePalette;
491 goto done;
494 if (start >= dc->devCaps->sizePalette)
496 count = 0;
497 goto done;
500 if (start+count >= dc->devCaps->sizePalette)
501 count = dc->devCaps->sizePalette - start;
502 for (i = 0; i < count; i++)
504 *(COLORREF*)(entries + i) = COLOR_GetSystemPaletteEntry( start + i );
506 TRACE("\tidx(%02x) -> RGB(%08lx)\n",
507 start + i, *(COLORREF*)(entries + i) );
509 done:
510 GDI_ReleaseObj( hdc );
511 return count;
515 /***********************************************************************
516 * GetNearestPaletteIndex16 (GDI.370)
518 UINT16 WINAPI GetNearestPaletteIndex16( HPALETTE16 hpalette, COLORREF color )
520 return GetNearestPaletteIndex( hpalette, color );
524 /***********************************************************************
525 * GetNearestPaletteIndex [GDI32.203] Gets palette index for color
527 * NOTES
528 * Should index be initialized to CLR_INVALID instead of 0?
530 * RETURNS
531 * Success: Index of entry in logical palette
532 * Failure: CLR_INVALID
534 UINT WINAPI GetNearestPaletteIndex(
535 HPALETTE hpalette, /* [in] Handle of logical color palette */
536 COLORREF color) /* [in] Color to be matched */
538 PALETTEOBJ* palObj = (PALETTEOBJ*)GDI_GetObjPtr( hpalette, PALETTE_MAGIC );
539 UINT index = 0;
541 if( palObj )
543 index = COLOR_PaletteLookupPixel(palObj->logpalette.palPalEntry,
544 palObj->logpalette.palNumEntries,
545 NULL, color, FALSE );
547 GDI_ReleaseObj( hpalette );
549 TRACE("(%04x,%06lx): returning %d\n", hpalette, color, index );
550 return index;
554 /***********************************************************************
555 * GetNearestColor16 (GDI.154)
557 COLORREF WINAPI GetNearestColor16( HDC16 hdc, COLORREF color )
559 return GetNearestColor( hdc, color );
563 /***********************************************************************
564 * GetNearestColor [GDI32.202] Gets a system color to match
566 * RETURNS
567 * Success: Color from system palette that corresponds to given color
568 * Failure: CLR_INVALID
570 COLORREF WINAPI GetNearestColor(
571 HDC hdc, /* [in] Handle of device context */
572 COLORREF color) /* [in] Color to be matched */
574 COLORREF nearest = CLR_INVALID;
575 DC *dc;
576 PALETTEOBJ *palObj;
578 if ( (dc = DC_GetDCPtr( hdc )) )
580 HPALETTE hpal = (dc->hPalette)? dc->hPalette : GetStockObject( DEFAULT_PALETTE );
581 palObj = GDI_GetObjPtr( hpal, PALETTE_MAGIC );
582 if (!palObj) {
583 GDI_ReleaseObj( hdc );
584 return nearest;
587 nearest = COLOR_LookupNearestColor( palObj->logpalette.palPalEntry,
588 palObj->logpalette.palNumEntries, color );
589 GDI_ReleaseObj( hpal );
590 GDI_ReleaseObj( hdc );
593 TRACE("(%06lx): returning %06lx\n", color, nearest );
594 return nearest;
598 /***********************************************************************
599 * PALETTE_GetObject
601 int PALETTE_GetObject( PALETTEOBJ * palette, int count, LPSTR buffer )
603 if (count > sizeof(WORD)) count = sizeof(WORD);
604 memcpy( buffer, &palette->logpalette.palNumEntries, count );
605 return count;
609 /***********************************************************************
610 * PALETTE_UnrealizeObject
612 BOOL PALETTE_UnrealizeObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
614 if (palette->mapping)
616 HeapFree( GetProcessHeap(), 0, palette->mapping );
617 palette->mapping = NULL;
619 if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0;
620 return TRUE;
624 /***********************************************************************
625 * PALETTE_DeleteObject
627 BOOL PALETTE_DeleteObject( HPALETTE16 hpalette, PALETTEOBJ *palette )
629 HeapFree( GetProcessHeap(), 0, palette->mapping );
630 if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0;
631 return GDI_FreeObject( hpalette, palette );
635 /***********************************************************************
636 * GDISelectPalette (GDI.361)
638 HPALETTE16 WINAPI GDISelectPalette16( HDC16 hdc, HPALETTE16 hpal, WORD wBkg)
640 HPALETTE16 prev;
641 DC *dc;
643 TRACE("%04x %04x\n", hdc, hpal );
645 if (GetObjectType(hpal) != OBJ_PAL)
647 WARN("invalid selected palette %04x\n",hpal);
648 return 0;
650 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
651 prev = dc->hPalette;
652 dc->hPalette = hpal;
653 GDI_ReleaseObj( hdc );
654 if (!wBkg) hPrimaryPalette = hpal;
655 return prev;
659 /***********************************************************************
660 * GDIRealizePalette (GDI.362)
662 UINT16 WINAPI GDIRealizePalette16( HDC16 hdc )
664 PALETTEOBJ* palPtr;
665 int realized = 0;
666 DC* dc = DC_GetDCPtr( hdc );
668 if (!dc) return 0;
670 TRACE("%04x...\n", hdc );
672 if(dc->hPalette != hLastRealizedPalette )
674 if( dc->hPalette == GetStockObject( DEFAULT_PALETTE )) {
675 realized = RealizeDefaultPalette16( hdc );
676 GDI_ReleaseObj( hdc );
677 return (UINT16)realized;
681 palPtr = (PALETTEOBJ *) GDI_GetObjPtr( dc->hPalette, PALETTE_MAGIC );
683 if (!palPtr) {
684 GDI_ReleaseObj( hdc );
685 FIXME("invalid selected palette %04x\n",dc->hPalette);
686 return 0;
689 realized = PALETTE_Driver->
690 pSetMapping(palPtr,0,palPtr->logpalette.palNumEntries,
691 (dc->hPalette != hPrimaryPalette) ||
692 (dc->hPalette == GetStockObject( DEFAULT_PALETTE )));
693 hLastRealizedPalette = dc->hPalette;
694 GDI_ReleaseObj( dc->hPalette );
696 else TRACE(" skipping (hLastRealizedPalette = %04x)\n",
697 hLastRealizedPalette);
698 GDI_ReleaseObj( hdc );
700 TRACE(" realized %i colors.\n", realized );
701 return (UINT16)realized;
705 /***********************************************************************
706 * RealizeDefaultPalette (GDI.365)
708 UINT16 WINAPI RealizeDefaultPalette16( HDC16 hdc )
710 UINT16 ret = 0;
711 DC *dc;
712 PALETTEOBJ* palPtr;
714 TRACE("%04x\n", hdc );
716 if (!(dc = DC_GetDCPtr( hdc ))) return 0;
718 if (!(dc->flags & DC_MEMORY))
720 palPtr = (PALETTEOBJ*)GDI_GetObjPtr( GetStockObject(DEFAULT_PALETTE), PALETTE_MAGIC );
721 if (palPtr)
723 /* lookup is needed to account for SetSystemPaletteUse() stuff */
724 ret = PALETTE_Driver->pUpdateMapping(palPtr);
725 GDI_ReleaseObj( GetStockObject(DEFAULT_PALETTE) );
728 GDI_ReleaseObj( hdc );
729 return ret;
732 /***********************************************************************
733 * IsDCCurrentPalette (GDI.412)
735 BOOL16 WINAPI IsDCCurrentPalette16(HDC16 hDC)
737 DC *dc = DC_GetDCPtr( hDC );
738 if (dc)
740 BOOL bRet = dc->hPalette == hPrimaryPalette;
741 GDI_ReleaseObj( hDC );
742 return bRet;
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 return pfnSelectPalette( hDC, hPal, bForceBackground );
764 /***********************************************************************
765 * RealizePalette [GDI32.280] Maps palette entries to system palette
767 * RETURNS
768 * Success: Number of entries in logical palette
769 * Failure: GDI_ERROR
771 UINT WINAPI RealizePalette(
772 HDC hDC) /* [in] Handle of device context */
774 return pfnRealizePalette( hDC );
778 /**********************************************************************
779 * UpdateColors16 (GDI.366)
781 INT16 WINAPI UpdateColors16( HDC16 hDC )
783 DC *dc;
784 HWND hWnd;
785 int size;
787 if (!(dc = DC_GetDCPtr( hDC ))) return 0;
788 size = dc->devCaps->sizePalette;
789 GDI_ReleaseObj( hDC );
790 if (Callout.WindowFromDC)
792 hWnd = Callout.WindowFromDC( hDC );
794 /* Docs say that we have to remap current drawable pixel by pixel
795 * but it would take forever given the speed of XGet/PutPixel.
797 if (hWnd && size)
798 Callout.RedrawWindow( hWnd, NULL, 0, RDW_INVALIDATE );
800 return 0x666;
804 /**********************************************************************
805 * UpdateColors [GDI32.359] Remaps current colors to logical palette
807 * RETURNS
808 * Success: TRUE
809 * Failure: FALSE
811 BOOL WINAPI UpdateColors(
812 HDC hDC) /* [in] Handle of device context */
814 UpdateColors16( hDC );
815 return TRUE;
819 /*********************************************************************
820 * SetMagicColors16 (GDI.606)
822 VOID WINAPI SetMagicColors16(HDC16 hDC, COLORREF color, UINT16 index)
824 FIXME("(hDC %04x, color %04x, index %04x): stub\n", hDC, (int)color, index);
828 /**********************************************************************
829 * GetICMProfileA [GDI32.316]
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.
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
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.
844 * FIXME
845 * How does Windows assign these? Some registry key?
848 #define WINEICM "winefake.icm" /* easy-to-identify fake filename */
850 BOOL WINAPI GetICMProfileA(HDC hDC, LPDWORD lpcbName, LPSTR lpszFilename)
852 DWORD callerLen;
854 FIXME("(%04x, %p, %p): partial stub\n", hDC, lpcbName, lpszFilename);
856 callerLen = *lpcbName;
858 /* all 3 behaviors require the required buffer size to be set */
859 *lpcbName = strlen(WINEICM);
861 /* behavior 1: if lpszFilename is NULL, return size of string and no error */
862 if ((DWORD)lpszFilename == (DWORD)0x00000000)
863 return TRUE;
865 /* behavior 2: if buffer size too small, return size of string and error */
866 if (callerLen < strlen(WINEICM))
868 SetLastError(ERROR_INSUFFICIENT_BUFFER);
869 return FALSE;
872 /* behavior 3: if buffer size OK and pointer not NULL, copy and return size */
873 strcpy(lpszFilename, WINEICM);
874 return TRUE;