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.
15 #include "wine/winuser16.h"
20 #include "debugtools.h"
23 DEFAULT_DEBUG_CHANNEL(palette
)
25 PALETTE_DRIVER
*PALETTE_Driver
= NULL
;
27 FARPROC pfnSelectPalette
= NULL
;
28 FARPROC pfnRealizePalette
= NULL
;
30 static UINT SystemPaletteUse
= SYSPAL_STATIC
; /* currently not considered */
32 static HPALETTE16 hPrimaryPalette
= 0; /* used for WM_PALETTECHANGED */
33 static HPALETTE16 hLastRealizedPalette
= 0; /* UnrealizeObject() needs it */
36 /***********************************************************************
39 * Create the system palette.
41 HPALETTE16
PALETTE_Init(void)
47 const PALETTEENTRY
* __sysPalTemplate
= COLOR_GetSystemPaletteTemplate();
49 /* create default palette (20 system colors) */
51 palPtr
= HeapAlloc( GetProcessHeap(), 0,
52 sizeof(LOGPALETTE
) + (NB_RESERVED_COLORS
-1)*sizeof(PALETTEENTRY
));
53 if (!palPtr
) return FALSE
;
55 palPtr
->palVersion
= 0x300;
56 palPtr
->palNumEntries
= NB_RESERVED_COLORS
;
57 for( i
= 0; i
< NB_RESERVED_COLORS
; i
++ )
59 palPtr
->palPalEntry
[i
].peRed
= __sysPalTemplate
[i
].peRed
;
60 palPtr
->palPalEntry
[i
].peGreen
= __sysPalTemplate
[i
].peGreen
;
61 palPtr
->palPalEntry
[i
].peBlue
= __sysPalTemplate
[i
].peBlue
;
62 palPtr
->palPalEntry
[i
].peFlags
= 0;
64 hpalette
= CreatePalette16( palPtr
);
66 palObj
= (PALETTEOBJ
*) GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
69 palObj
->mapping
= xmalloc( sizeof(int) * 20 );
71 GDI_HEAP_UNLOCK( hpalette
);
73 HeapFree( GetProcessHeap(), 0, palPtr
);
79 /***********************************************************************
80 * PALETTE_ValidateFlags
82 void PALETTE_ValidateFlags(PALETTEENTRY
* lpPalE
, int size
)
86 lpPalE
[i
].peFlags
= PC_SYS_USED
| (lpPalE
[i
].peFlags
& 0x07);
90 /***********************************************************************
91 * CreatePalette16 (GDI.360)
93 HPALETTE16 WINAPI
CreatePalette16( const LOGPALETTE
* palette
)
95 return CreatePalette( palette
);
99 /***********************************************************************
100 * CreatePalette32 [GDI32.53] Creates a logical color palette
103 * Success: Handle to logical palette
106 HPALETTE WINAPI
CreatePalette(
107 const LOGPALETTE
* palette
) /* [in] Pointer to logical color palette */
109 PALETTEOBJ
* palettePtr
;
113 if (!palette
) return 0;
114 TRACE("entries=%i\n", palette
->palNumEntries
);
116 size
= sizeof(LOGPALETTE
) + (palette
->palNumEntries
- 1) * sizeof(PALETTEENTRY
);
118 hpalette
= GDI_AllocObject( size
+ sizeof(int*) +sizeof(GDIOBJHDR
) , PALETTE_MAGIC
);
119 if (!hpalette
) return 0;
121 palettePtr
= (PALETTEOBJ
*) GDI_HEAP_LOCK( hpalette
);
122 memcpy( &palettePtr
->logpalette
, palette
, size
);
123 PALETTE_ValidateFlags(palettePtr
->logpalette
.palPalEntry
,
124 palettePtr
->logpalette
.palNumEntries
);
125 palettePtr
->mapping
= NULL
;
126 GDI_HEAP_UNLOCK( hpalette
);
128 TRACE(" returning %04x\n", hpalette
);
133 /***********************************************************************
134 * CreateHalftonePalette16 [GDI.?] Creates a halftone palette
137 * Success: Handle to logical halftone palette
140 HPALETTE16 WINAPI
CreateHalftonePalette16(
141 HDC16 hdc
) /* [in] Handle to device context */
143 return CreateHalftonePalette(hdc
);
147 /***********************************************************************
148 * CreateHalftonePalette32 [GDI32.47] Creates a halftone palette
151 * Success: Handle to logical halftone palette
154 * FIXME: not truly tested
156 HPALETTE WINAPI
CreateHalftonePalette(
157 HDC hdc
) /* [in] Handle to device context */
162 WORD NumberOfEntries
;
163 PALETTEENTRY aEntries
[256];
168 GetSystemPaletteEntries(hdc
, 0, 256, Palette
.aEntries
);
169 return CreatePalette((LOGPALETTE
*)&Palette
);
171 for (r
= 0; r
< 6; r
++) {
172 for (g
= 0; g
< 6; g
++) {
173 for (b
= 0; b
< 6; b
++) {
174 i
= r
+ g
*6 + b
*36 + 10;
175 Palette
.aEntries
[i
].peRed
= r
* 51;
176 Palette
.aEntries
[i
].peGreen
= g
* 51;
177 Palette
.aEntries
[i
].peBlue
= b
* 51;
182 for (i
= 216; i
< 246; i
++) {
183 int v
= (i
- 216) * 8;
184 Palette
.aEntries
[i
].peRed
= v
;
185 Palette
.aEntries
[i
].peGreen
= v
;
186 Palette
.aEntries
[i
].peBlue
= v
;
189 return CreatePalette((LOGPALETTE
*)&Palette
);
193 /***********************************************************************
194 * GetPaletteEntries16 (GDI.363)
196 UINT16 WINAPI
GetPaletteEntries16( HPALETTE16 hpalette
, UINT16 start
,
197 UINT16 count
, LPPALETTEENTRY entries
)
199 return GetPaletteEntries( hpalette
, start
, count
, entries
);
203 /***********************************************************************
204 * GetPaletteEntries32 [GDI32.209] Retrieves palette entries
207 * Success: Number of entries from logical palette
210 UINT WINAPI
GetPaletteEntries(
211 HPALETTE hpalette
, /* [in] Handle of logical palette */
212 UINT start
, /* [in] First entry to receive */
213 UINT count
, /* [in] Number of entries to receive */
214 LPPALETTEENTRY entries
) /* [out] Address of array receiving entries */
219 TRACE("hpal = %04x, count=%i\n", hpalette
, count
);
221 palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
222 if (!palPtr
) return 0;
224 numEntries
= palPtr
->logpalette
.palNumEntries
;
225 if (start
+count
> numEntries
) count
= numEntries
- start
;
228 if (start
>= numEntries
)
230 GDI_HEAP_UNLOCK( hpalette
);
233 memcpy( entries
, &palPtr
->logpalette
.palPalEntry
[start
],
234 count
* sizeof(PALETTEENTRY
) );
235 for( numEntries
= 0; numEntries
< count
; numEntries
++ )
236 if (entries
[numEntries
].peFlags
& 0xF0)
237 entries
[numEntries
].peFlags
= 0;
238 GDI_HEAP_UNLOCK( hpalette
);
245 /***********************************************************************
246 * SetPaletteEntries16 (GDI.364)
248 UINT16 WINAPI
SetPaletteEntries16( HPALETTE16 hpalette
, UINT16 start
,
249 UINT16 count
, LPPALETTEENTRY entries
)
251 return SetPaletteEntries( hpalette
, start
, count
, entries
);
255 /***********************************************************************
256 * SetPaletteEntries32 [GDI32.326] Sets color values for range in palette
259 * Success: Number of entries that were set
262 UINT WINAPI
SetPaletteEntries(
263 HPALETTE hpalette
, /* [in] Handle of logical palette */
264 UINT start
, /* [in] Index of first entry to set */
265 UINT count
, /* [in] Number of entries to set */
266 LPPALETTEENTRY entries
) /* [in] Address of array of structures */
271 TRACE("hpal=%04x,start=%i,count=%i\n",hpalette
,start
,count
);
273 palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
274 if (!palPtr
) return 0;
276 numEntries
= palPtr
->logpalette
.palNumEntries
;
277 if (start
>= numEntries
)
279 GDI_HEAP_UNLOCK( hpalette
);
282 if (start
+count
> numEntries
) count
= numEntries
- start
;
283 memcpy( &palPtr
->logpalette
.palPalEntry
[start
], entries
,
284 count
* sizeof(PALETTEENTRY
) );
285 PALETTE_ValidateFlags(palPtr
->logpalette
.palPalEntry
,
286 palPtr
->logpalette
.palNumEntries
);
287 free(palPtr
->mapping
);
288 palPtr
->mapping
= NULL
;
289 GDI_HEAP_UNLOCK( hpalette
);
294 /***********************************************************************
295 * ResizePalette16 (GDI.368)
297 BOOL16 WINAPI
ResizePalette16( HPALETTE16 hPal
, UINT16 cEntries
)
299 return ResizePalette( hPal
, cEntries
);
303 /***********************************************************************
304 * ResizePalette32 [GDI32.289] Resizes logical palette
310 BOOL WINAPI
ResizePalette(
311 HPALETTE hPal
, /* [in] Handle of logical palette */
312 UINT cEntries
) /* [in] Number of entries in logical palette */
314 PALETTEOBJ
* palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hPal
, PALETTE_MAGIC
);
315 UINT cPrevEnt
, prevVer
;
316 int prevsize
, size
= sizeof(LOGPALETTE
) + (cEntries
- 1) * sizeof(PALETTEENTRY
);
319 TRACE("hpal = %04x, prev = %i, new = %i\n",
320 hPal
, palPtr
? palPtr
->logpalette
.palNumEntries
: -1,
322 if( !palPtr
) return FALSE
;
323 cPrevEnt
= palPtr
->logpalette
.palNumEntries
;
324 prevVer
= palPtr
->logpalette
.palVersion
;
325 prevsize
= sizeof(LOGPALETTE
) + (cPrevEnt
- 1) * sizeof(PALETTEENTRY
) +
326 sizeof(int*) + sizeof(GDIOBJHDR
);
327 size
+= sizeof(int*) + sizeof(GDIOBJHDR
);
328 mapping
= palPtr
->mapping
;
330 GDI_HEAP_UNLOCK( hPal
);
332 hPal
= GDI_HEAP_REALLOC( hPal
, size
);
333 palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hPal
, PALETTE_MAGIC
);
334 if( !palPtr
) return FALSE
;
337 palPtr
->mapping
= (int*) xrealloc( mapping
, cEntries
* sizeof(int) );
338 if( cEntries
> cPrevEnt
)
341 memset(palPtr
->mapping
+ cPrevEnt
, 0, (cEntries
- cPrevEnt
)*sizeof(int));
342 memset( (BYTE
*)palPtr
+ prevsize
, 0, size
- prevsize
);
343 PALETTE_ValidateFlags((PALETTEENTRY
*)((BYTE
*)palPtr
+ prevsize
),
344 cEntries
- cPrevEnt
);
346 palPtr
->logpalette
.palNumEntries
= cEntries
;
347 palPtr
->logpalette
.palVersion
= prevVer
;
348 GDI_HEAP_UNLOCK( hPal
);
353 /***********************************************************************
354 * AnimatePalette16 (GDI.367)
356 void WINAPI
AnimatePalette16( HPALETTE16 hPal
, UINT16 StartIndex
,
357 UINT16 NumEntries
, const PALETTEENTRY
* PaletteColors
)
359 AnimatePalette( hPal
, StartIndex
, NumEntries
, PaletteColors
);
363 /***********************************************************************
364 * AnimatePalette32 [GDI32.6] Replaces entries in logical palette
371 * Should use existing mapping when animating a primary palette
373 BOOL WINAPI
AnimatePalette(
374 HPALETTE hPal
, /* [in] Handle to logical palette */
375 UINT StartIndex
, /* [in] First entry in palette */
376 UINT NumEntries
, /* [in] Count of entries in palette */
377 const PALETTEENTRY
* PaletteColors
) /* [in] Pointer to first replacement */
379 TRACE("%04x (%i - %i)\n", hPal
, StartIndex
,StartIndex
+NumEntries
);
381 if( hPal
!= STOCK_DEFAULT_PALETTE
)
383 PALETTEOBJ
* palPtr
= (PALETTEOBJ
*)GDI_GetObjPtr(hPal
, PALETTE_MAGIC
);
384 if (!palPtr
) return FALSE
;
386 if( (StartIndex
+ NumEntries
) <= palPtr
->logpalette
.palNumEntries
)
389 for( u
= 0; u
< NumEntries
; u
++ )
390 palPtr
->logpalette
.palPalEntry
[u
+ StartIndex
] = PaletteColors
[u
];
392 pSetMapping(palPtr
, StartIndex
, NumEntries
,
393 hPal
!= hPrimaryPalette
);
394 GDI_HEAP_UNLOCK( hPal
);
402 /***********************************************************************
403 * SetSystemPaletteUse16 (GDI.373)
405 UINT16 WINAPI
SetSystemPaletteUse16( HDC16 hdc
, UINT16 use
)
407 return SetSystemPaletteUse( hdc
, use
);
411 /***********************************************************************
412 * SetSystemPaletteUse32 [GDI32.335]
415 * Success: Previous system palette
416 * Failure: SYSPAL_ERROR
418 UINT WINAPI
SetSystemPaletteUse(
419 HDC hdc
, /* [in] Handle of device context */
420 UINT use
) /* [in] Palette-usage flag */
422 UINT old
= SystemPaletteUse
;
423 FIXME("(%04x,%04x): stub\n", hdc
, use
);
424 SystemPaletteUse
= use
;
429 /***********************************************************************
430 * GetSystemPaletteUse16 (GDI.374)
432 UINT16 WINAPI
GetSystemPaletteUse16( HDC16 hdc
)
434 return SystemPaletteUse
;
438 /***********************************************************************
439 * GetSystemPaletteUse32 [GDI32.223] Gets state of system palette
442 * Current state of system palette
444 UINT WINAPI
GetSystemPaletteUse(
445 HDC hdc
) /* [in] Handle of device context */
447 return SystemPaletteUse
;
451 /***********************************************************************
452 * GetSystemPaletteEntries16 (GDI.375)
454 UINT16 WINAPI
GetSystemPaletteEntries16( HDC16 hdc
, UINT16 start
, UINT16 count
,
455 LPPALETTEENTRY entries
)
457 return GetSystemPaletteEntries( hdc
, start
, count
, entries
);
461 /***********************************************************************
462 * GetSystemPaletteEntries32 [GDI32.222] Gets range of palette entries
465 * Success: Number of entries retrieved from palette
468 UINT WINAPI
GetSystemPaletteEntries(
469 HDC hdc
, /* [in] Handle of device context */
470 UINT start
, /* [in] Index of first entry to be retrieved */
471 UINT count
, /* [in] Number of entries to be retrieved */
472 LPPALETTEENTRY entries
) /* [out] Array receiving system-palette entries */
477 TRACE("hdc=%04x,start=%i,count=%i\n", hdc
,start
,count
);
479 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
))) return 0;
480 if (!entries
) return dc
->w
.devCaps
->sizePalette
;
481 if (start
>= dc
->w
.devCaps
->sizePalette
)
483 GDI_HEAP_UNLOCK( hdc
);
486 if (start
+count
>= dc
->w
.devCaps
->sizePalette
)
487 count
= dc
->w
.devCaps
->sizePalette
- start
;
488 for (i
= 0; i
< count
; i
++)
490 *(COLORREF
*)(entries
+ i
) = COLOR_GetSystemPaletteEntry( start
+ i
);
492 TRACE("\tidx(%02x) -> RGB(%08lx)\n",
493 start
+ i
, *(COLORREF
*)(entries
+ i
) );
495 GDI_HEAP_UNLOCK( hdc
);
500 /***********************************************************************
501 * GetNearestPaletteIndex16 (GDI.370)
503 UINT16 WINAPI
GetNearestPaletteIndex16( HPALETTE16 hpalette
, COLORREF color
)
505 return GetNearestPaletteIndex( hpalette
, color
);
509 /***********************************************************************
510 * GetNearestPaletteIndex32 [GDI32.203] Gets palette index for color
513 * Should index be initialized to CLR_INVALID instead of 0?
516 * Success: Index of entry in logical palette
517 * Failure: CLR_INVALID
519 UINT WINAPI
GetNearestPaletteIndex(
520 HPALETTE hpalette
, /* [in] Handle of logical color palette */
521 COLORREF color
) /* [in] Color to be matched */
523 PALETTEOBJ
* palObj
= (PALETTEOBJ
*)GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
527 index
= COLOR_PaletteLookupPixel(palObj
->logpalette
.palPalEntry
,
528 palObj
->logpalette
.palNumEntries
,
529 NULL
, color
, FALSE
);
531 TRACE("(%04x,%06lx): returning %d\n", hpalette
, color
, index
);
532 GDI_HEAP_UNLOCK( hpalette
);
537 /***********************************************************************
538 * GetNearestColor16 (GDI.154)
540 COLORREF WINAPI
GetNearestColor16( HDC16 hdc
, COLORREF color
)
542 return GetNearestColor( hdc
, color
);
546 /***********************************************************************
547 * GetNearestColor32 [GDI32.202] Gets a system color to match
550 * Should this return CLR_INVALID instead of FadeCafe?
553 * Success: Color from system palette that corresponds to given color
554 * Failure: CLR_INVALID
556 COLORREF WINAPI
GetNearestColor(
557 HDC hdc
, /* [in] Handle of device context */
558 COLORREF color
) /* [in] Color to be matched */
560 COLORREF nearest
= 0xFADECAFE;
564 if ( (dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
)) )
566 palObj
= (PALETTEOBJ
*)
567 GDI_GetObjPtr( (dc
->w
.hPalette
)? dc
->w
.hPalette
568 : STOCK_DEFAULT_PALETTE
, PALETTE_MAGIC
);
569 if (!palObj
) return nearest
;
571 nearest
= COLOR_LookupNearestColor( palObj
->logpalette
.palPalEntry
,
572 palObj
->logpalette
.palNumEntries
, color
);
573 GDI_HEAP_UNLOCK( dc
->w
.hPalette
);
576 TRACE("(%06lx): returning %06lx\n", color
, nearest
);
577 GDI_HEAP_UNLOCK( hdc
);
582 /***********************************************************************
585 int PALETTE_GetObject( PALETTEOBJ
* palette
, int count
, LPSTR buffer
)
587 if (count
> sizeof(WORD
)) count
= sizeof(WORD
);
588 memcpy( buffer
, &palette
->logpalette
.palNumEntries
, count
);
593 /***********************************************************************
594 * PALETTE_UnrealizeObject
596 BOOL
PALETTE_UnrealizeObject( HPALETTE16 hpalette
, PALETTEOBJ
*palette
)
598 if (palette
->mapping
)
600 free( palette
->mapping
);
601 palette
->mapping
= NULL
;
603 if (hLastRealizedPalette
== hpalette
) hLastRealizedPalette
= 0;
608 /***********************************************************************
609 * PALETTE_DeleteObject
611 BOOL
PALETTE_DeleteObject( HPALETTE16 hpalette
, PALETTEOBJ
*palette
)
613 free( palette
->mapping
);
614 if (hLastRealizedPalette
== hpalette
) hLastRealizedPalette
= 0;
615 return GDI_FreeObject( hpalette
);
619 /***********************************************************************
620 * GDISelectPalette (GDI.361)
622 HPALETTE16 WINAPI
GDISelectPalette16( HDC16 hdc
, HPALETTE16 hpal
, WORD wBkg
)
627 TRACE("%04x %04x\n", hdc
, hpal
);
629 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
632 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
635 prev
= dc
->w
.hPalette
;
636 dc
->w
.hPalette
= hpal
;
637 GDI_HEAP_UNLOCK( hdc
);
638 if (!wBkg
) hPrimaryPalette
= hpal
;
643 /***********************************************************************
644 * GDIRealizePalette (GDI.362)
646 UINT16 WINAPI
GDIRealizePalette16( HDC16 hdc
)
650 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
653 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
657 TRACE("%04x...\n", hdc
);
659 if( dc
&& dc
->w
.hPalette
!= hLastRealizedPalette
)
661 if( dc
->w
.hPalette
== STOCK_DEFAULT_PALETTE
)
662 return RealizeDefaultPalette16( hdc
);
664 palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( dc
->w
.hPalette
, PALETTE_MAGIC
);
667 FIXME("invalid selected palette %04x\n",dc
->w
.hPalette
);
671 realized
= PALETTE_Driver
->
672 pSetMapping(palPtr
,0,palPtr
->logpalette
.palNumEntries
,
673 (dc
->w
.hPalette
!= hPrimaryPalette
) ||
674 (dc
->w
.hPalette
== STOCK_DEFAULT_PALETTE
));
675 GDI_HEAP_UNLOCK( dc
->w
.hPalette
);
676 hLastRealizedPalette
= dc
->w
.hPalette
;
678 else TRACE(" skipping (hLastRealizedPalette = %04x)\n",
679 hLastRealizedPalette
);
680 GDI_HEAP_UNLOCK( hdc
);
682 TRACE(" realized %i colors.\n", realized
);
683 return (UINT16
)realized
;
687 /***********************************************************************
688 * RealizeDefaultPalette (GDI.365)
690 UINT16 WINAPI
RealizeDefaultPalette16( HDC16 hdc
)
695 TRACE("%04x\n", hdc
);
697 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
700 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
704 if ( dc
->w
.flags
& DC_MEMORY
)
706 GDI_HEAP_UNLOCK( hdc
);
710 hPrimaryPalette
= STOCK_DEFAULT_PALETTE
;
711 hLastRealizedPalette
= STOCK_DEFAULT_PALETTE
;
713 palPtr
= (PALETTEOBJ
*)GDI_GetObjPtr(STOCK_DEFAULT_PALETTE
, PALETTE_MAGIC
);
714 if (!palPtr
) return 0;
716 /* lookup is needed to account for SetSystemPaletteUse() stuff */
718 return PALETTE_Driver
->pUpdateMapping(palPtr
);
721 /***********************************************************************
722 * IsDCCurrentPalette (GDI.412)
724 BOOL16 WINAPI
IsDCCurrentPalette16(HDC16 hDC
)
726 DC
* dc
= (DC
*)GDI_GetObjPtr( hDC
, DC_MAGIC
);
729 GDI_HEAP_UNLOCK( hDC
);
730 return dc
->w
.hPalette
== hPrimaryPalette
;
736 /***********************************************************************
737 * SelectPalette16 (USER.282)
739 HPALETTE16 WINAPI
SelectPalette16( HDC16 hDC
, HPALETTE16 hPal
,
740 BOOL16 bForceBackground
)
742 return SelectPalette( hDC
, hPal
, bForceBackground
);
746 /***********************************************************************
747 * SelectPalette32 [GDI32.300] Selects logical palette into DC
750 * Success: Previous logical palette
753 HPALETTE WINAPI
SelectPalette(
754 HDC hDC
, /* [in] Handle of device context */
755 HPALETTE hPal
, /* [in] Handle of logical color palette */
756 BOOL bForceBackground
) /* [in] Foreground/background mode */
758 WORD wBkgPalette
= 1;
759 PALETTEOBJ
* lpt
= (PALETTEOBJ
*) GDI_GetObjPtr( hPal
, PALETTE_MAGIC
);
761 TRACE("dc=%04x,pal=%04x,force=%i\n", hDC
, hPal
, bForceBackground
);
764 TRACE(" entries = %d\n", lpt
->logpalette
.palNumEntries
);
765 GDI_HEAP_UNLOCK( hPal
);
767 if( hPal
!= STOCK_DEFAULT_PALETTE
)
769 HWND hWnd
= WindowFromDC( hDC
);
770 HWND hActive
= GetActiveWindow();
772 /* set primary palette if it's related to current active */
774 if((!hWnd
|| (hActive
== hWnd
|| IsChild16(hActive
,hWnd
))) &&
778 return GDISelectPalette16( hDC
, hPal
, wBkgPalette
);
782 /***********************************************************************
783 * RealizePalette16 (USER.283)
785 UINT16 WINAPI
RealizePalette16( HDC16 hDC
)
787 return RealizePalette( hDC
);
791 /***********************************************************************
792 * RealizePalette32 [GDI32.280] Maps palette entries to system palette
795 * Success: Number of entries in logical palette
798 UINT WINAPI
RealizePalette(
799 HDC hDC
) /* [in] Handle of device context */
804 if (!(dc
= (DC
*) GDI_GetObjPtr( hDC
, DC_MAGIC
))) return 0;
806 realized
= GDIRealizePalette16( hDC
);
808 /* do not send anything if no colors were changed */
810 if( IsDCCurrentPalette16( hDC
) && realized
&&
811 dc
->w
.devCaps
->sizePalette
)
813 /* Send palette change notification */
816 if( (hWnd
= WindowFromDC( hDC
)) )
817 SendMessage16( HWND_BROADCAST
, WM_PALETTECHANGED
, hWnd
, 0L);
820 GDI_HEAP_UNLOCK( hDC
);
825 /**********************************************************************
826 * UpdateColors16 (GDI.366)
828 INT16 WINAPI
UpdateColors16( HDC16 hDC
)
833 if (!(dc
= (DC
*) GDI_GetObjPtr( hDC
, DC_MAGIC
))) return 0;
835 hWnd
= WindowFromDC( hDC
);
837 /* Docs say that we have to remap current drawable pixel by pixel
838 * but it would take forever given the speed of XGet/PutPixel.
840 if (hWnd
&& dc
->w
.devCaps
->sizePalette
)
841 InvalidateRect( hWnd
, NULL
, FALSE
);
843 GDI_HEAP_UNLOCK( hDC
);
849 /**********************************************************************
850 * UpdateColors32 [GDI32.359] Remaps current colors to logical palette
856 BOOL WINAPI
UpdateColors(
857 HDC hDC
) /* [in] Handle of device context */
859 UpdateColors16( hDC
);
864 /*********************************************************************
865 * SetMagicColors16 (GDI.606)
867 VOID WINAPI
SetMagicColors16(HDC16 hDC
, COLORREF color
, UINT16 index
)
869 FIXME("(hDC %04x, color %04x, index %04x): stub\n", hDC
, (int)color
, index
);
873 /**********************************************************************
874 * GetICMProfileA [GDI32.316]
876 * Returns the filename of the specified device context's color
877 * management profile, even if color management is not enabled
881 * TRUE if name copied succesfully OR lpszFilename is NULL
882 * FALSE if the buffer length pointed to by lpcbName is too small
885 * The buffer length pointed to by lpcbName is ALWAYS updated to
886 * the length required regardless of other actions this function
890 * How does Windows assign these? Some registry key?
893 #define WINEICM "winefake.icm" /* easy-to-identify fake filename */
895 BOOL WINAPI
GetICMProfileA(HDC hDC
, LPDWORD lpcbName
, LPSTR lpszFilename
)
899 FIXME("(%04x, %p, %p): partial stub\n", hDC
, lpcbName
, lpszFilename
);
901 callerLen
= *lpcbName
;
903 /* all 3 behaviors require the required buffer size to be set */
904 *lpcbName
= strlen(WINEICM
);
906 /* behavior 1: if lpszFilename is NULL, return size of string and no error */
907 if ((DWORD
)lpszFilename
== (DWORD
)0x00000000)
910 /* behavior 2: if buffer size too small, return size of string and error */
911 if (callerLen
< strlen(WINEICM
))
913 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
917 /* behavior 3: if buffer size OK and pointer not NULL, copy and return size */
918 lstrcpyA(lpszFilename
, WINEICM
);