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.
18 #include "wine/winuser16.h"
20 FARPROC32 pfnSelectPalette
= NULL
;
21 FARPROC32 pfnRealizePalette
= NULL
;
23 static UINT32 SystemPaletteUse
= SYSPAL_STATIC
; /* currently not considered */
25 static HPALETTE16 hPrimaryPalette
= 0; /* used for WM_PALETTECHANGED */
26 static HPALETTE16 hLastRealizedPalette
= 0; /* UnrealizeObject() needs it */
29 /***********************************************************************
32 * Create the system palette.
34 HPALETTE16
PALETTE_Init(void)
40 const PALETTEENTRY
* __sysPalTemplate
= COLOR_GetSystemPaletteTemplate();
42 /* create default palette (20 system colors) */
44 palPtr
= HeapAlloc( GetProcessHeap(), 0,
45 sizeof(LOGPALETTE
) + (NB_RESERVED_COLORS
-1)*sizeof(PALETTEENTRY
));
46 if (!palPtr
) return FALSE
;
48 palPtr
->palVersion
= 0x300;
49 palPtr
->palNumEntries
= NB_RESERVED_COLORS
;
50 for( i
= 0; i
< NB_RESERVED_COLORS
; i
++ )
52 palPtr
->palPalEntry
[i
].peRed
= __sysPalTemplate
[i
].peRed
;
53 palPtr
->palPalEntry
[i
].peGreen
= __sysPalTemplate
[i
].peGreen
;
54 palPtr
->palPalEntry
[i
].peBlue
= __sysPalTemplate
[i
].peBlue
;
55 palPtr
->palPalEntry
[i
].peFlags
= 0;
57 hpalette
= CreatePalette16( palPtr
);
59 palObj
= (PALETTEOBJ
*) GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
62 palObj
->mapping
= xmalloc( sizeof(int) * 20 );
64 GDI_HEAP_UNLOCK( hpalette
);
66 HeapFree( GetProcessHeap(), 0, palPtr
);
72 /***********************************************************************
73 * PALETTE_ValidateFlags
75 void PALETTE_ValidateFlags(PALETTEENTRY
* lpPalE
, int size
)
79 lpPalE
[i
].peFlags
= PC_SYS_USED
| (lpPalE
[i
].peFlags
& 0x07);
83 /***********************************************************************
84 * CreatePalette16 (GDI.360)
86 HPALETTE16 WINAPI
CreatePalette16( const LOGPALETTE
* palette
)
88 return CreatePalette32( palette
);
92 /***********************************************************************
93 * CreatePalette32 [GDI32.53] Creates a logical color palette
96 * Success: Handle to logical palette
99 HPALETTE32 WINAPI
CreatePalette32(
100 const LOGPALETTE
* palette
) /* [in] Pointer to logical color palette */
102 PALETTEOBJ
* palettePtr
;
106 if (!palette
) return 0;
107 TRACE(palette
,"entries=%i\n", palette
->palNumEntries
);
109 size
= sizeof(LOGPALETTE
) + (palette
->palNumEntries
- 1) * sizeof(PALETTEENTRY
);
111 hpalette
= GDI_AllocObject( size
+ sizeof(int*) +sizeof(GDIOBJHDR
) , PALETTE_MAGIC
);
112 if (!hpalette
) return 0;
114 palettePtr
= (PALETTEOBJ
*) GDI_HEAP_LOCK( hpalette
);
115 memcpy( &palettePtr
->logpalette
, palette
, size
);
116 PALETTE_ValidateFlags(palettePtr
->logpalette
.palPalEntry
,
117 palettePtr
->logpalette
.palNumEntries
);
118 palettePtr
->mapping
= NULL
;
119 GDI_HEAP_UNLOCK( hpalette
);
121 TRACE(palette
," returning %04x\n", hpalette
);
126 /***********************************************************************
127 * CreateHalftonePalette16 [GDI.?] Creates a halftone palette
130 * Success: Handle to logical halftone palette
133 HPALETTE16 WINAPI
CreateHalftonePalette16(
134 HDC16 hdc
) /* [in] Handle to device context */
136 return CreateHalftonePalette32(hdc
);
140 /***********************************************************************
141 * CreateHalftonePalette32 [GDI32.47] Creates a halftone palette
144 * Success: Handle to logical halftone palette
147 * FIXME: not truly tested
149 HPALETTE32 WINAPI
CreateHalftonePalette32(
150 HDC32 hdc
) /* [in] Handle to device context */
155 WORD NumberOfEntries
;
156 PALETTEENTRY aEntries
[256];
161 GetSystemPaletteEntries32(hdc
, 0, 256, Palette
.aEntries
);
162 return CreatePalette32((LOGPALETTE
*)&Palette
);
164 for (r
= 0; r
< 6; r
++) {
165 for (g
= 0; g
< 6; g
++) {
166 for (b
= 0; b
< 6; b
++) {
167 i
= r
+ g
*6 + b
*36 + 10;
168 Palette
.aEntries
[i
].peRed
= r
* 51;
169 Palette
.aEntries
[i
].peGreen
= g
* 51;
170 Palette
.aEntries
[i
].peBlue
= b
* 51;
175 for (i
= 216; i
< 246; i
++) {
176 int v
= (i
- 216) * 8;
177 Palette
.aEntries
[i
].peRed
= v
;
178 Palette
.aEntries
[i
].peGreen
= v
;
179 Palette
.aEntries
[i
].peBlue
= v
;
182 return CreatePalette32((LOGPALETTE
*)&Palette
);
186 /***********************************************************************
187 * GetPaletteEntries16 (GDI.363)
189 UINT16 WINAPI
GetPaletteEntries16( HPALETTE16 hpalette
, UINT16 start
,
190 UINT16 count
, LPPALETTEENTRY entries
)
192 return GetPaletteEntries32( hpalette
, start
, count
, entries
);
196 /***********************************************************************
197 * GetPaletteEntries32 [GDI32.209] Retrieves palette entries
200 * Success: Number of entries from logical palette
203 UINT32 WINAPI
GetPaletteEntries32(
204 HPALETTE32 hpalette
, /* [in] Handle of logical palette */
205 UINT32 start
, /* [in] First entry to receive */
206 UINT32 count
, /* [in] Number of entries to receive */
207 LPPALETTEENTRY entries
) /* [out] Address of array receiving entries */
212 TRACE(palette
,"hpal = %04x, count=%i\n", hpalette
, count
);
214 palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
215 if (!palPtr
) return 0;
217 numEntries
= palPtr
->logpalette
.palNumEntries
;
218 if (start
+count
> numEntries
) count
= numEntries
- start
;
221 if (start
>= numEntries
)
223 GDI_HEAP_UNLOCK( hpalette
);
226 memcpy( entries
, &palPtr
->logpalette
.palPalEntry
[start
],
227 count
* sizeof(PALETTEENTRY
) );
228 for( numEntries
= 0; numEntries
< count
; numEntries
++ )
229 if (entries
[numEntries
].peFlags
& 0xF0)
230 entries
[numEntries
].peFlags
= 0;
231 GDI_HEAP_UNLOCK( hpalette
);
238 /***********************************************************************
239 * SetPaletteEntries16 (GDI.364)
241 UINT16 WINAPI
SetPaletteEntries16( HPALETTE16 hpalette
, UINT16 start
,
242 UINT16 count
, LPPALETTEENTRY entries
)
244 return SetPaletteEntries32( hpalette
, start
, count
, entries
);
248 /***********************************************************************
249 * SetPaletteEntries32 [GDI32.326] Sets color values for range in palette
252 * Success: Number of entries that were set
255 UINT32 WINAPI
SetPaletteEntries32(
256 HPALETTE32 hpalette
, /* [in] Handle of logical palette */
257 UINT32 start
, /* [in] Index of first entry to set */
258 UINT32 count
, /* [in] Number of entries to set */
259 LPPALETTEENTRY entries
) /* [in] Address of array of structures */
264 TRACE(palette
,"hpal=%04x,start=%i,count=%i\n",hpalette
,start
,count
);
266 palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
267 if (!palPtr
) return 0;
269 numEntries
= palPtr
->logpalette
.palNumEntries
;
270 if (start
>= numEntries
)
272 GDI_HEAP_UNLOCK( hpalette
);
275 if (start
+count
> numEntries
) count
= numEntries
- start
;
276 memcpy( &palPtr
->logpalette
.palPalEntry
[start
], entries
,
277 count
* sizeof(PALETTEENTRY
) );
278 PALETTE_ValidateFlags(palPtr
->logpalette
.palPalEntry
,
279 palPtr
->logpalette
.palNumEntries
);
280 free(palPtr
->mapping
);
281 palPtr
->mapping
= NULL
;
282 GDI_HEAP_UNLOCK( hpalette
);
287 /***********************************************************************
288 * ResizePalette16 (GDI.368)
290 BOOL16 WINAPI
ResizePalette16( HPALETTE16 hPal
, UINT16 cEntries
)
292 return ResizePalette32( hPal
, cEntries
);
296 /***********************************************************************
297 * ResizePalette32 [GDI32.289] Resizes logical palette
303 BOOL32 WINAPI
ResizePalette32(
304 HPALETTE32 hPal
, /* [in] Handle of logical palette */
305 UINT32 cEntries
) /* [in] Number of entries in logical palette */
307 PALETTEOBJ
* palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hPal
, PALETTE_MAGIC
);
308 UINT32 cPrevEnt
, prevVer
;
309 int prevsize
, size
= sizeof(LOGPALETTE
) + (cEntries
- 1) * sizeof(PALETTEENTRY
);
312 TRACE(palette
,"hpal = %04x, prev = %i, new = %i\n",
313 hPal
, palPtr
? palPtr
->logpalette
.palNumEntries
: -1,
315 if( !palPtr
) return FALSE
;
316 cPrevEnt
= palPtr
->logpalette
.palNumEntries
;
317 prevVer
= palPtr
->logpalette
.palVersion
;
318 prevsize
= sizeof(LOGPALETTE
) + (cPrevEnt
- 1) * sizeof(PALETTEENTRY
) +
319 sizeof(int*) + sizeof(GDIOBJHDR
);
320 size
+= sizeof(int*) + sizeof(GDIOBJHDR
);
321 mapping
= palPtr
->mapping
;
323 GDI_HEAP_UNLOCK( hPal
);
325 hPal
= GDI_HEAP_REALLOC( hPal
, size
);
326 palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hPal
, PALETTE_MAGIC
);
327 if( !palPtr
) return FALSE
;
330 palPtr
->mapping
= (int*) xrealloc( mapping
, cEntries
* sizeof(int) );
331 if( cEntries
> cPrevEnt
)
334 memset(palPtr
->mapping
+ cPrevEnt
, 0, (cEntries
- cPrevEnt
)*sizeof(int));
335 memset( (BYTE
*)palPtr
+ prevsize
, 0, size
- prevsize
);
336 PALETTE_ValidateFlags((PALETTEENTRY
*)((BYTE
*)palPtr
+ prevsize
),
337 cEntries
- cPrevEnt
);
339 palPtr
->logpalette
.palNumEntries
= cEntries
;
340 palPtr
->logpalette
.palVersion
= prevVer
;
341 GDI_HEAP_UNLOCK( hPal
);
346 /***********************************************************************
347 * AnimatePalette16 (GDI.367)
349 void WINAPI
AnimatePalette16( HPALETTE16 hPal
, UINT16 StartIndex
,
350 UINT16 NumEntries
, const PALETTEENTRY
* PaletteColors
)
352 AnimatePalette32( hPal
, StartIndex
, NumEntries
, PaletteColors
);
356 /***********************************************************************
357 * AnimatePalette32 [GDI32.6] Replaces entries in logical palette
364 * Should use existing mapping when animating a primary palette
366 BOOL32 WINAPI
AnimatePalette32(
367 HPALETTE32 hPal
, /* [in] Handle to logical palette */
368 UINT32 StartIndex
, /* [in] First entry in palette */
369 UINT32 NumEntries
, /* [in] Count of entries in palette */
370 const PALETTEENTRY
* PaletteColors
) /* [in] Pointer to first replacement */
372 TRACE(palette
, "%04x (%i - %i)\n", hPal
, StartIndex
,StartIndex
+NumEntries
);
374 if( hPal
!= STOCK_DEFAULT_PALETTE
)
376 PALETTEOBJ
* palPtr
= (PALETTEOBJ
*)GDI_GetObjPtr(hPal
, PALETTE_MAGIC
);
377 if (!palPtr
) return FALSE
;
379 if( (StartIndex
+ NumEntries
) <= palPtr
->logpalette
.palNumEntries
)
382 for( u
= 0; u
< NumEntries
; u
++ )
383 palPtr
->logpalette
.palPalEntry
[u
+ StartIndex
] = PaletteColors
[u
];
384 COLOR_SetMapping(palPtr
, StartIndex
, NumEntries
,
385 hPal
!= hPrimaryPalette
);
386 GDI_HEAP_UNLOCK( hPal
);
394 /***********************************************************************
395 * SetSystemPaletteUse16 (GDI.373)
397 UINT16 WINAPI
SetSystemPaletteUse16( HDC16 hdc
, UINT16 use
)
399 return SetSystemPaletteUse32( hdc
, use
);
403 /***********************************************************************
404 * SetSystemPaletteUse32 [GDI32.335]
407 * Success: Previous system palette
408 * Failure: SYSPAL_ERROR
410 UINT32 WINAPI
SetSystemPaletteUse32(
411 HDC32 hdc
, /* [in] Handle of device context */
412 UINT32 use
) /* [in] Palette-usage flag */
414 UINT32 old
= SystemPaletteUse
;
415 FIXME(palette
,"(%04x,%04x): stub\n", hdc
, use
);
416 SystemPaletteUse
= use
;
421 /***********************************************************************
422 * GetSystemPaletteUse16 (GDI.374)
424 UINT16 WINAPI
GetSystemPaletteUse16( HDC16 hdc
)
426 return SystemPaletteUse
;
430 /***********************************************************************
431 * GetSystemPaletteUse32 [GDI32.223] Gets state of system palette
434 * Current state of system palette
436 UINT32 WINAPI
GetSystemPaletteUse32(
437 HDC32 hdc
) /* [in] Handle of device context */
439 return SystemPaletteUse
;
443 /***********************************************************************
444 * GetSystemPaletteEntries16 (GDI.375)
446 UINT16 WINAPI
GetSystemPaletteEntries16( HDC16 hdc
, UINT16 start
, UINT16 count
,
447 LPPALETTEENTRY entries
)
449 return GetSystemPaletteEntries32( hdc
, start
, count
, entries
);
453 /***********************************************************************
454 * GetSystemPaletteEntries32 [GDI32.222] Gets range of palette entries
457 * Success: Number of entries retrieved from palette
460 UINT32 WINAPI
GetSystemPaletteEntries32(
461 HDC32 hdc
, /* [in] Handle of device context */
462 UINT32 start
, /* [in] Index of first entry to be retrieved */
463 UINT32 count
, /* [in] Number of entries to be retrieved */
464 LPPALETTEENTRY entries
) /* [out] Array receiving system-palette entries */
469 TRACE(palette
, "hdc=%04x,start=%i,count=%i\n", hdc
,start
,count
);
471 if (!(dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
))) return 0;
472 if (!entries
) return COLOR_GetSystemPaletteSize();
473 if (start
>= dc
->w
.devCaps
->sizePalette
)
475 GDI_HEAP_UNLOCK( hdc
);
478 if (start
+count
>= dc
->w
.devCaps
->sizePalette
)
479 count
= dc
->w
.devCaps
->sizePalette
- start
;
480 for (i
= 0; i
< count
; i
++)
482 *(COLORREF
*)(entries
+ i
) = COLOR_GetSystemPaletteEntry( start
+ i
);
484 TRACE(palette
,"\tidx(%02x) -> RGB(%08lx)\n",
485 start
+ i
, *(COLORREF
*)(entries
+ i
) );
487 GDI_HEAP_UNLOCK( hdc
);
492 /***********************************************************************
493 * GetNearestPaletteIndex16 (GDI.370)
495 UINT16 WINAPI
GetNearestPaletteIndex16( HPALETTE16 hpalette
, COLORREF color
)
497 return GetNearestPaletteIndex32( hpalette
, color
);
501 /***********************************************************************
502 * GetNearestPaletteIndex32 [GDI32.203] Gets palette index for color
505 * Should index be initialized to CLR_INVALID instead of 0?
508 * Success: Index of entry in logical palette
509 * Failure: CLR_INVALID
511 UINT32 WINAPI
GetNearestPaletteIndex32(
512 HPALETTE32 hpalette
, /* [in] Handle of logical color palette */
513 COLORREF color
) /* [in] Color to be matched */
515 PALETTEOBJ
* palObj
= (PALETTEOBJ
*)GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
519 index
= COLOR_PaletteLookupPixel( palObj
->logpalette
.palPalEntry
,
520 palObj
->logpalette
.palNumEntries
,
521 NULL
, color
, FALSE
);
523 TRACE(palette
,"(%04x,%06lx): returning %d\n", hpalette
, color
, index
);
524 GDI_HEAP_UNLOCK( hpalette
);
529 /***********************************************************************
530 * GetNearestColor16 (GDI.154)
532 COLORREF WINAPI
GetNearestColor16( HDC16 hdc
, COLORREF color
)
534 return GetNearestColor32( hdc
, color
);
538 /***********************************************************************
539 * GetNearestColor32 [GDI32.202] Gets a system color to match
542 * Should this return CLR_INVALID instead of FadeCafe?
545 * Success: Color from system palette that corresponds to given color
546 * Failure: CLR_INVALID
548 COLORREF WINAPI
GetNearestColor32(
549 HDC32 hdc
, /* [in] Handle of device context */
550 COLORREF color
) /* [in] Color to be matched */
552 COLORREF nearest
= 0xFADECAFE;
556 if ( (dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
)) )
558 palObj
= (PALETTEOBJ
*)
559 GDI_GetObjPtr( (dc
->w
.hPalette
)? dc
->w
.hPalette
560 : STOCK_DEFAULT_PALETTE
, PALETTE_MAGIC
);
561 if (!palObj
) return nearest
;
563 nearest
= COLOR_LookupNearestColor( palObj
->logpalette
.palPalEntry
,
564 palObj
->logpalette
.palNumEntries
, color
);
565 GDI_HEAP_UNLOCK( dc
->w
.hPalette
);
568 TRACE(palette
,"(%06lx): returning %06lx\n", color
, nearest
);
569 GDI_HEAP_UNLOCK( hdc
);
574 /***********************************************************************
577 int PALETTE_GetObject( PALETTEOBJ
* palette
, int count
, LPSTR buffer
)
579 if (count
> sizeof(WORD
)) count
= sizeof(WORD
);
580 memcpy( buffer
, &palette
->logpalette
.palNumEntries
, count
);
585 /***********************************************************************
586 * PALETTE_UnrealizeObject
588 BOOL32
PALETTE_UnrealizeObject( HPALETTE16 hpalette
, PALETTEOBJ
*palette
)
590 if (palette
->mapping
)
592 free( palette
->mapping
);
593 palette
->mapping
= NULL
;
595 if (hLastRealizedPalette
== hpalette
) hLastRealizedPalette
= 0;
600 /***********************************************************************
601 * PALETTE_DeleteObject
603 BOOL32
PALETTE_DeleteObject( HPALETTE16 hpalette
, PALETTEOBJ
*palette
)
605 free( palette
->mapping
);
606 if (hLastRealizedPalette
== hpalette
) hLastRealizedPalette
= 0;
607 return GDI_FreeObject( hpalette
);
611 /***********************************************************************
612 * GDISelectPalette (GDI.361)
614 HPALETTE16 WINAPI
GDISelectPalette( HDC16 hdc
, HPALETTE16 hpal
, WORD wBkg
)
619 TRACE(palette
, "%04x %04x\n", hdc
, hpal
);
621 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
624 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
627 prev
= dc
->w
.hPalette
;
628 dc
->w
.hPalette
= hpal
;
629 GDI_HEAP_UNLOCK( hdc
);
630 if (!wBkg
) hPrimaryPalette
= hpal
;
635 /***********************************************************************
636 * GDIRealizePalette (GDI.362)
638 UINT16 WINAPI
GDIRealizePalette( HDC16 hdc
)
642 DC
* dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
645 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
649 TRACE(palette
, "%04x...\n", hdc
);
651 if( dc
&& dc
->w
.hPalette
!= hLastRealizedPalette
)
653 if( dc
->w
.hPalette
== STOCK_DEFAULT_PALETTE
)
654 return RealizeDefaultPalette( hdc
);
656 palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( dc
->w
.hPalette
, PALETTE_MAGIC
);
659 FIXME(palette
,"invalid selected palette %04x\n",dc
->w
.hPalette
);
663 realized
= COLOR_SetMapping(palPtr
,0,palPtr
->logpalette
.palNumEntries
,
664 (dc
->w
.hPalette
!= hPrimaryPalette
) ||
665 (dc
->w
.hPalette
== STOCK_DEFAULT_PALETTE
));
666 GDI_HEAP_UNLOCK( dc
->w
.hPalette
);
667 hLastRealizedPalette
= dc
->w
.hPalette
;
669 else TRACE(palette
, " skipping (hLastRealizedPalette = %04x)\n",
670 hLastRealizedPalette
);
671 GDI_HEAP_UNLOCK( hdc
);
673 TRACE(palette
, " realized %i colors.\n", realized
);
674 return (UINT16
)realized
;
678 /***********************************************************************
679 * RealizeDefaultPalette (GDI.365)
681 UINT16 WINAPI
RealizeDefaultPalette( HDC16 hdc
)
685 int i
, index
, realized
= 0;
687 TRACE(palette
,"%04x\n", hdc
);
689 dc
= (DC
*) GDI_GetObjPtr( hdc
, DC_MAGIC
);
692 dc
= (DC
*)GDI_GetObjPtr(hdc
, METAFILE_DC_MAGIC
);
696 if ( dc
->w
.flags
& DC_MEMORY
)
698 GDI_HEAP_UNLOCK( hdc
);
702 hPrimaryPalette
= STOCK_DEFAULT_PALETTE
;
703 hLastRealizedPalette
= STOCK_DEFAULT_PALETTE
;
705 palPtr
= (PALETTEOBJ
*)GDI_GetObjPtr(STOCK_DEFAULT_PALETTE
, PALETTE_MAGIC
);
706 if (!palPtr
) return 0;
708 /* lookup is needed to account for SetSystemPaletteUse() stuff */
710 for( i
= 0; i
< 20; i
++ )
712 index
= COLOR_LookupSystemPixel(*(COLORREF
*)(palPtr
->logpalette
.palPalEntry
+ i
));
714 /* mapping is allocated in COLOR_InitPalette() */
716 if( index
!= palPtr
->mapping
[i
] ) { palPtr
->mapping
[i
]=index
; realized
++; }
721 /***********************************************************************
722 * IsDCCurrentPalette (GDI.412)
724 BOOL16 WINAPI
IsDCCurrentPalette(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 SelectPalette32( hDC
, hPal
, bForceBackground
);
746 /***********************************************************************
747 * SelectPalette32 [GDI32.300] Selects logical palette into DC
750 * Success: Previous logical palette
753 HPALETTE32 WINAPI
SelectPalette32(
754 HDC32 hDC
, /* [in] Handle of device context */
755 HPALETTE32 hPal
, /* [in] Handle of logical color palette */
756 BOOL32 bForceBackground
) /* [in] Foreground/background mode */
758 WORD wBkgPalette
= 1;
759 PALETTEOBJ
* lpt
= (PALETTEOBJ
*) GDI_GetObjPtr( hPal
, PALETTE_MAGIC
);
761 TRACE(palette
,"dc=%04x,pal=%04x,force=%i\n", hDC
, hPal
, bForceBackground
);
764 TRACE(palette
," entries = %d\n", lpt
->logpalette
.palNumEntries
);
765 GDI_HEAP_UNLOCK( hPal
);
767 if( hPal
!= STOCK_DEFAULT_PALETTE
)
769 HWND32 hWnd
= WindowFromDC32( hDC
);
770 HWND32 hActive
= GetActiveWindow32();
772 /* set primary palette if it's related to current active */
774 if((!hWnd
|| (hActive
== hWnd
|| IsChild16(hActive
,hWnd
))) &&
778 return GDISelectPalette( hDC
, hPal
, wBkgPalette
);
782 /***********************************************************************
783 * RealizePalette16 (USER.283)
785 UINT16 WINAPI
RealizePalette16( HDC16 hDC
)
787 return RealizePalette32( hDC
);
791 /***********************************************************************
792 * RealizePalette32 [GDI32.280] Maps palette entries to system palette
795 * Success: Number of entries in logical palette
798 UINT32 WINAPI
RealizePalette32(
799 HDC32 hDC
) /* [in] Handle of device context */
801 UINT32 realized
= GDIRealizePalette( hDC
);
803 /* do not send anything if no colors were changed */
805 if( IsDCCurrentPalette( hDC
) && realized
&&
806 !(COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL
) )
808 /* Send palette change notification */
811 if( (hWnd
= WindowFromDC32( hDC
)) )
812 SendMessage16( HWND_BROADCAST
, WM_PALETTECHANGED
, hWnd
, 0L);
818 /**********************************************************************
819 * UpdateColors16 (GDI.366)
821 INT16 WINAPI
UpdateColors16( HDC16 hDC
)
823 HWND32 hWnd
= WindowFromDC32( hDC
);
825 /* Docs say that we have to remap current drawable pixel by pixel
826 * but it would take forever given the speed of XGet/PutPixel.
828 if (hWnd
&& !(COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL
) )
829 InvalidateRect32( hWnd
, NULL
, FALSE
);
834 /**********************************************************************
835 * UpdateColors32 [GDI32.359] Remaps current colors to logical palette
841 BOOL32 WINAPI
UpdateColors32(
842 HDC32 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(palette
,"(hDC %04x, color %04x, index %04x): stub\n", hDC
, (int)color
, index
);