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.
17 #include "wine/winuser16.h"
21 #include "debugtools.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 /***********************************************************************
41 * Create the system palette.
43 HPALETTE16
PALETTE_Init(void)
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
);
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
);
80 /***********************************************************************
81 * PALETTE_ValidateFlags
83 void PALETTE_ValidateFlags(PALETTEENTRY
* lpPalE
, int size
)
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
104 * Success: Handle to logical palette
107 HPALETTE WINAPI
CreatePalette(
108 const LOGPALETTE
* palette
) /* [in] Pointer to logical color palette */
110 PALETTEOBJ
* palettePtr
;
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
);
134 /***********************************************************************
135 * CreateHalftonePalette16 [GDI.?] Creates a halftone palette
138 * Success: Handle to logical halftone palette
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
152 * Success: Handle to logical halftone palette
155 * FIXME: not truly tested
157 HPALETTE WINAPI
CreateHalftonePalette(
158 HDC hdc
) /* [in] Handle to device context */
163 WORD NumberOfEntries
;
164 PALETTEENTRY aEntries
[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
208 * Success: Number of entries from logical palette
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 */
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
;
229 if (start
>= numEntries
)
231 GDI_HEAP_UNLOCK( hpalette
);
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
);
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
260 * Success: Number of entries that were set
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 */
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
);
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
);
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
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
);
320 TRACE("hpal = %04x, prev = %i, new = %i\n",
321 hPal
, palPtr
? palPtr
->logpalette
.palNumEntries
: -1,
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
;
339 int *newMap
= (int*) HeapReAlloc(GetProcessHeap(), 0,
340 mapping
, cEntries
* sizeof(int) );
343 ERR("Can not resize mapping -- out of memory!");
344 GDI_HEAP_UNLOCK( hPal
);
347 palPtr
->mapping
= newMap
;
350 if( cEntries
> cPrevEnt
)
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
);
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
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
)
401 for( u
= 0; u
< NumEntries
; u
++ )
402 palPtr
->logpalette
.palPalEntry
[u
+ StartIndex
] = PaletteColors
[u
];
404 pSetMapping(palPtr
, StartIndex
, NumEntries
,
405 hPal
!= hPrimaryPalette
);
406 GDI_HEAP_UNLOCK( hPal
);
414 /***********************************************************************
415 * SetSystemPaletteUse16 (GDI.373)
417 UINT16 WINAPI
SetSystemPaletteUse16( HDC16 hdc
, UINT16 use
)
419 return SetSystemPaletteUse( hdc
, use
);
423 /***********************************************************************
424 * SetSystemPaletteUse [GDI32.335]
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
;
441 /***********************************************************************
442 * GetSystemPaletteUse16 (GDI.374)
444 UINT16 WINAPI
GetSystemPaletteUse16( HDC16 hdc
)
446 return SystemPaletteUse
;
450 /***********************************************************************
451 * GetSystemPaletteUse [GDI32.223] Gets state of system palette
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
477 * Success: Number of entries retrieved from palette
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 */
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
);
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
);
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
525 * Should index be initialized to CLR_INVALID instead of 0?
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
);
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
);
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
562 * Should this return CLR_INVALID instead of FadeCafe?
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;
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
);
594 /***********************************************************************
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
);
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;
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
)
639 TRACE("%04x %04x\n", hdc
, hpal
);
641 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
644 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
647 prev
= dc
->w
.hPalette
;
648 dc
->w
.hPalette
= hpal
;
649 GDI_HEAP_UNLOCK( hdc
);
650 if (!wBkg
) hPrimaryPalette
= hpal
;
655 /***********************************************************************
656 * GDIRealizePalette (GDI.362)
658 UINT16 WINAPI
GDIRealizePalette16( HDC16 hdc
)
662 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
665 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
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
);
679 FIXME("invalid selected palette %04x\n",dc
->w
.hPalette
);
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
)
707 TRACE("%04x\n", hdc
);
709 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
712 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
716 if ( dc
->w
.flags
& DC_MEMORY
)
718 GDI_HEAP_UNLOCK( hdc
);
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
);
741 GDI_HEAP_UNLOCK( hDC
);
742 return dc
->w
.hPalette
== hPrimaryPalette
;
748 /***********************************************************************
749 * SelectPalette [GDI32.300] Selects logical palette into DC
752 * Success: Previous logical palette
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
);
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
780 * Success: Number of entries in logical palette
783 UINT WINAPI
RealizePalette(
784 HDC hDC
) /* [in] Handle of device context */
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 */
801 if( (hWnd
= Callout
.WindowFromDC( hDC
)) )
802 Callout
.SendMessageA( HWND_BROADCAST
, WM_PALETTECHANGED
, hWnd
, 0L);
805 GDI_HEAP_UNLOCK( hDC
);
810 /**********************************************************************
811 * UpdateColors16 (GDI.366)
813 INT16 WINAPI
UpdateColors16( HDC16 hDC
)
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
);
834 /**********************************************************************
835 * UpdateColors [GDI32.359] Remaps current colors to logical palette
841 BOOL WINAPI
UpdateColors(
842 HDC hDC
) /* [in] Handle of device context */
844 UpdateColors16( hDC
);
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
866 * TRUE if name copied succesfully OR lpszFilename is NULL
867 * FALSE if the buffer length pointed to by lpcbName is too small
870 * The buffer length pointed to by lpcbName is ALWAYS updated to
871 * the length required regardless of other actions this function
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
)
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)
895 /* behavior 2: if buffer size too small, return size of string and error */
896 if (callerLen
< strlen(WINEICM
))
898 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
902 /* behavior 3: if buffer size OK and pointer not NULL, copy and return size */
903 strcpy(lpszFilename
, WINEICM
);