4 * Copyright 1993,1994 Alexandre Julliard
5 * Copyright 1996 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * PALETTEOBJ is documented in the Dr. Dobbs Journal May 1993.
23 * Information in the "Undocumented Windows" is incorrect.
34 #include "wine/winuser16.h"
35 #include "gdi_private.h"
36 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(palette
);
41 typedef struct tagPALETTEOBJ
44 const DC_FUNCTIONS
*funcs
; /* DC function table */
45 LOGPALETTE logpalette
; /* _MUST_ be the last field */
48 static INT
PALETTE_GetObject( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
);
49 static BOOL
PALETTE_UnrealizeObject( HGDIOBJ handle
, void *obj
);
50 static BOOL
PALETTE_DeleteObject( HGDIOBJ handle
, void *obj
);
52 static const struct gdi_obj_funcs palette_funcs
=
54 NULL
, /* pSelectObject */
55 PALETTE_GetObject
, /* pGetObjectA */
56 PALETTE_GetObject
, /* pGetObjectW */
57 PALETTE_UnrealizeObject
, /* pUnrealizeObject */
58 PALETTE_DeleteObject
/* pDeleteObject */
61 /* Pointers to USER implementation of SelectPalette/RealizePalette */
62 /* they will be patched by USER on startup */
63 HPALETTE (WINAPI
*pfnSelectPalette
)(HDC hdc
, HPALETTE hpal
, WORD bkgnd
) = GDISelectPalette
;
64 UINT (WINAPI
*pfnRealizePalette
)(HDC hdc
) = GDIRealizePalette
;
66 static UINT SystemPaletteUse
= SYSPAL_STATIC
; /* currently not considered */
68 static HPALETTE hPrimaryPalette
= 0; /* used for WM_PALETTECHANGED */
69 static HPALETTE hLastRealizedPalette
= 0; /* UnrealizeObject() needs it */
71 #define NB_RESERVED_COLORS 20 /* number of fixed colors in system palette */
73 static const PALETTEENTRY sys_pal_template
[NB_RESERVED_COLORS
] =
75 /* first 10 entries in the system palette */
76 /* red green blue flags */
77 { 0x00, 0x00, 0x00, 0 },
78 { 0x80, 0x00, 0x00, 0 },
79 { 0x00, 0x80, 0x00, 0 },
80 { 0x80, 0x80, 0x00, 0 },
81 { 0x00, 0x00, 0x80, 0 },
82 { 0x80, 0x00, 0x80, 0 },
83 { 0x00, 0x80, 0x80, 0 },
84 { 0xc0, 0xc0, 0xc0, 0 },
85 { 0xc0, 0xdc, 0xc0, 0 },
86 { 0xa6, 0xca, 0xf0, 0 },
88 /* ... c_min/2 dynamic colorcells */
90 /* ... gap (for sparse palettes) */
92 /* ... c_min/2 dynamic colorcells */
94 { 0xff, 0xfb, 0xf0, 0 },
95 { 0xa0, 0xa0, 0xa4, 0 },
96 { 0x80, 0x80, 0x80, 0 },
97 { 0xff, 0x00, 0x00, 0 },
98 { 0x00, 0xff, 0x00, 0 },
99 { 0xff, 0xff, 0x00, 0 },
100 { 0x00, 0x00, 0xff, 0 },
101 { 0xff, 0x00, 0xff, 0 },
102 { 0x00, 0xff, 0xff, 0 },
103 { 0xff, 0xff, 0xff, 0 } /* last 10 */
106 /***********************************************************************
109 * Create the system palette.
111 HPALETTE
PALETTE_Init(void)
116 /* create default palette (20 system colors) */
118 palPtr
= HeapAlloc( GetProcessHeap(), 0,
119 sizeof(LOGPALETTE
) + (NB_RESERVED_COLORS
-1)*sizeof(PALETTEENTRY
));
120 if (!palPtr
) return FALSE
;
122 palPtr
->palVersion
= 0x300;
123 palPtr
->palNumEntries
= NB_RESERVED_COLORS
;
124 memcpy( palPtr
->palPalEntry
, sys_pal_template
, sizeof(sys_pal_template
) );
125 hpalette
= CreatePalette( palPtr
);
126 HeapFree( GetProcessHeap(), 0, palPtr
);
131 /***********************************************************************
132 * CreatePalette [GDI32.@]
134 * Creates a logical color palette.
137 * Success: Handle to logical palette
140 HPALETTE WINAPI
CreatePalette(
141 const LOGPALETTE
* palette
) /* [in] Pointer to logical color palette */
143 PALETTEOBJ
* palettePtr
;
147 if (!palette
) return 0;
148 TRACE("entries=%i\n", palette
->palNumEntries
);
150 size
= sizeof(LOGPALETTE
) + (palette
->palNumEntries
- 1) * sizeof(PALETTEENTRY
);
152 if (!(palettePtr
= GDI_AllocObject( size
+ sizeof(int*) +sizeof(GDIOBJHDR
),
153 PALETTE_MAGIC
, (HGDIOBJ
*)&hpalette
,
154 &palette_funcs
))) return 0;
155 memcpy( &palettePtr
->logpalette
, palette
, size
);
156 palettePtr
->funcs
= NULL
;
157 GDI_ReleaseObj( hpalette
);
159 TRACE(" returning %p\n", hpalette
);
164 /***********************************************************************
165 * CreateHalftonePalette [GDI32.@]
167 * Creates a halftone palette.
170 * Success: Handle to logical halftone palette
173 * FIXME: This simply creates the halftone palette derived from running
174 * tests on a windows NT machine. This is assuming a color depth
175 * of greater that 256 color. On a 256 color device the halftone
176 * palette will be different and this function will be incorrect
178 HPALETTE WINAPI
CreateHalftonePalette(
179 HDC hdc
) /* [in] Handle to device context */
184 WORD NumberOfEntries
;
185 PALETTEENTRY aEntries
[256];
188 Palette
.Version
= 0x300;
189 Palette
.NumberOfEntries
= 256;
190 GetSystemPaletteEntries(hdc
, 0, 256, Palette
.aEntries
);
192 Palette
.NumberOfEntries
= 20;
194 for (i
= 0; i
< Palette
.NumberOfEntries
; i
++)
196 Palette
.aEntries
[i
].peRed
=0xff;
197 Palette
.aEntries
[i
].peGreen
=0xff;
198 Palette
.aEntries
[i
].peBlue
=0xff;
199 Palette
.aEntries
[i
].peFlags
=0x00;
202 Palette
.aEntries
[0].peRed
=0x00;
203 Palette
.aEntries
[0].peBlue
=0x00;
204 Palette
.aEntries
[0].peGreen
=0x00;
207 for (i
=1; i
<= 6; i
++)
209 Palette
.aEntries
[i
].peRed
=(i
%2)?0x80:0;
210 Palette
.aEntries
[i
].peGreen
=(i
==2)?0x80:(i
==3)?0x80:(i
==6)?0x80:0;
211 Palette
.aEntries
[i
].peBlue
=(i
>3)?0x80:0;
214 for (i
=7; i
<= 12; i
++)
219 Palette
.aEntries
[i
].peRed
=0xc0;
220 Palette
.aEntries
[i
].peBlue
=0xc0;
221 Palette
.aEntries
[i
].peGreen
=0xc0;
224 Palette
.aEntries
[i
].peRed
=0xc0;
225 Palette
.aEntries
[i
].peGreen
=0xdc;
226 Palette
.aEntries
[i
].peBlue
=0xc0;
229 Palette
.aEntries
[i
].peRed
=0xa6;
230 Palette
.aEntries
[i
].peGreen
=0xca;
231 Palette
.aEntries
[i
].peBlue
=0xf0;
234 Palette
.aEntries
[i
].peRed
=0xff;
235 Palette
.aEntries
[i
].peGreen
=0xfb;
236 Palette
.aEntries
[i
].peBlue
=0xf0;
239 Palette
.aEntries
[i
].peRed
=0xa0;
240 Palette
.aEntries
[i
].peGreen
=0xa0;
241 Palette
.aEntries
[i
].peBlue
=0xa4;
244 Palette
.aEntries
[i
].peRed
=0x80;
245 Palette
.aEntries
[i
].peGreen
=0x80;
246 Palette
.aEntries
[i
].peBlue
=0x80;
250 for (i
=13; i
<= 18; i
++)
252 Palette
.aEntries
[i
].peRed
=(i
%2)?0xff:0;
253 Palette
.aEntries
[i
].peGreen
=(i
==14)?0xff:(i
==15)?0xff:(i
==18)?0xff:0;
254 Palette
.aEntries
[i
].peBlue
=(i
>15)?0xff:0x00;
257 return CreatePalette((LOGPALETTE
*)&Palette
);
261 /***********************************************************************
262 * GetPaletteEntries [GDI32.@]
264 * Retrieves palette entries.
267 * Success: Number of entries from logical palette
270 UINT WINAPI
GetPaletteEntries(
271 HPALETTE hpalette
, /* [in] Handle of logical palette */
272 UINT start
, /* [in] First entry to receive */
273 UINT count
, /* [in] Number of entries to receive */
274 LPPALETTEENTRY entries
) /* [out] Address of array receiving entries */
279 TRACE("hpal = %p, count=%i\n", hpalette
, count
);
281 palPtr
= GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
282 if (!palPtr
) return 0;
284 /* NOTE: not documented but test show this to be the case */
287 int rc
= palPtr
->logpalette
.palNumEntries
;
288 GDI_ReleaseObj( hpalette
);
292 numEntries
= palPtr
->logpalette
.palNumEntries
;
293 if (start
+count
> numEntries
) count
= numEntries
- start
;
296 if (start
>= numEntries
)
298 GDI_ReleaseObj( hpalette
);
301 memcpy( entries
, &palPtr
->logpalette
.palPalEntry
[start
],
302 count
* sizeof(PALETTEENTRY
) );
305 GDI_ReleaseObj( hpalette
);
310 /***********************************************************************
311 * SetPaletteEntries [GDI32.@]
313 * Sets color values for range in palette.
316 * Success: Number of entries that were set
319 UINT WINAPI
SetPaletteEntries(
320 HPALETTE hpalette
, /* [in] Handle of logical palette */
321 UINT start
, /* [in] Index of first entry to set */
322 UINT count
, /* [in] Number of entries to set */
323 const PALETTEENTRY
*entries
) /* [in] Address of array of structures */
328 TRACE("hpal=%p,start=%i,count=%i\n",hpalette
,start
,count
);
330 if (hpalette
== GetStockObject(DEFAULT_PALETTE
)) return 0;
331 palPtr
= GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
332 if (!palPtr
) return 0;
334 numEntries
= palPtr
->logpalette
.palNumEntries
;
335 if (start
>= numEntries
)
337 GDI_ReleaseObj( hpalette
);
340 if (start
+count
> numEntries
) count
= numEntries
- start
;
341 memcpy( &palPtr
->logpalette
.palPalEntry
[start
], entries
,
342 count
* sizeof(PALETTEENTRY
) );
343 UnrealizeObject( hpalette
);
344 GDI_ReleaseObj( hpalette
);
349 /***********************************************************************
350 * ResizePalette [GDI32.@]
352 * Resizes logical palette.
358 BOOL WINAPI
ResizePalette(
359 HPALETTE hPal
, /* [in] Handle of logical palette */
360 UINT cEntries
) /* [in] Number of entries in logical palette */
362 PALETTEOBJ
* palPtr
= GDI_GetObjPtr( hPal
, PALETTE_MAGIC
);
363 UINT cPrevEnt
, prevVer
;
364 int prevsize
, size
= sizeof(LOGPALETTE
) + (cEntries
- 1) * sizeof(PALETTEENTRY
);
366 TRACE("hpal = %p, prev = %i, new = %i\n",
367 hPal
, palPtr
? palPtr
->logpalette
.palNumEntries
: -1, cEntries
);
368 if( !palPtr
) return FALSE
;
369 cPrevEnt
= palPtr
->logpalette
.palNumEntries
;
370 prevVer
= palPtr
->logpalette
.palVersion
;
371 prevsize
= sizeof(LOGPALETTE
) + (cPrevEnt
- 1) * sizeof(PALETTEENTRY
) +
372 sizeof(int*) + sizeof(GDIOBJHDR
);
373 size
+= sizeof(int*) + sizeof(GDIOBJHDR
);
375 if (!(palPtr
= GDI_ReallocObject( size
, hPal
, palPtr
))) return FALSE
;
377 PALETTE_UnrealizeObject( hPal
, palPtr
);
379 if( cEntries
> cPrevEnt
) memset( (BYTE
*)palPtr
+ prevsize
, 0, size
- prevsize
);
380 palPtr
->logpalette
.palNumEntries
= cEntries
;
381 palPtr
->logpalette
.palVersion
= prevVer
;
382 GDI_ReleaseObj( hPal
);
387 /***********************************************************************
388 * AnimatePalette [GDI32.@]
390 * Replaces entries in logical palette.
397 * Should use existing mapping when animating a primary palette
399 BOOL WINAPI
AnimatePalette(
400 HPALETTE hPal
, /* [in] Handle to logical palette */
401 UINT StartIndex
, /* [in] First entry in palette */
402 UINT NumEntries
, /* [in] Count of entries in palette */
403 const PALETTEENTRY
* PaletteColors
) /* [in] Pointer to first replacement */
405 TRACE("%p (%i - %i)\n", hPal
, StartIndex
,StartIndex
+NumEntries
);
407 if( hPal
!= GetStockObject(DEFAULT_PALETTE
) )
411 const PALETTEENTRY
*pptr
= PaletteColors
;
413 palPtr
= GDI_GetObjPtr( hPal
, PALETTE_MAGIC
);
414 if (!palPtr
) return 0;
416 pal_entries
= palPtr
->logpalette
.palNumEntries
;
417 if (StartIndex
>= pal_entries
)
419 GDI_ReleaseObj( hPal
);
422 if (StartIndex
+NumEntries
> pal_entries
) NumEntries
= pal_entries
- StartIndex
;
424 for (NumEntries
+= StartIndex
; StartIndex
< NumEntries
; StartIndex
++, pptr
++) {
425 /* According to MSDN, only animate PC_RESERVED colours */
426 if (palPtr
->logpalette
.palPalEntry
[StartIndex
].peFlags
& PC_RESERVED
) {
427 TRACE("Animating colour (%d,%d,%d) to (%d,%d,%d)\n",
428 palPtr
->logpalette
.palPalEntry
[StartIndex
].peRed
,
429 palPtr
->logpalette
.palPalEntry
[StartIndex
].peGreen
,
430 palPtr
->logpalette
.palPalEntry
[StartIndex
].peBlue
,
431 pptr
->peRed
, pptr
->peGreen
, pptr
->peBlue
);
432 memcpy( &palPtr
->logpalette
.palPalEntry
[StartIndex
], pptr
,
433 sizeof(PALETTEENTRY
) );
435 TRACE("Not animating entry %d -- not PC_RESERVED\n", StartIndex
);
438 if (palPtr
->funcs
&& palPtr
->funcs
->pRealizePalette
)
439 palPtr
->funcs
->pRealizePalette( NULL
, hPal
, hPal
== hPrimaryPalette
);
441 GDI_ReleaseObj( hPal
);
447 /***********************************************************************
448 * SetSystemPaletteUse [GDI32.@]
450 * Specify whether the system palette contains 2 or 20 static colors.
453 * Success: Previous system palette
454 * Failure: SYSPAL_ERROR
456 UINT WINAPI
SetSystemPaletteUse(
457 HDC hdc
, /* [in] Handle of device context */
458 UINT use
) /* [in] Palette-usage flag */
460 UINT old
= SystemPaletteUse
;
462 /* Device doesn't support colour palettes */
463 if (!(GetDeviceCaps(hdc
, RASTERCAPS
) & RC_PALETTE
)) {
468 case SYSPAL_NOSTATIC
:
469 case SYSPAL_NOSTATIC256
: /* WINVER >= 0x0500 */
471 SystemPaletteUse
= use
;
479 /***********************************************************************
480 * GetSystemPaletteUse [GDI32.@]
482 * Gets state of system palette.
485 * Current state of system palette
487 UINT WINAPI
GetSystemPaletteUse(
488 HDC hdc
) /* [in] Handle of device context */
490 return SystemPaletteUse
;
494 /***********************************************************************
495 * GetSystemPaletteEntries [GDI32.@]
497 * Gets range of palette entries.
500 * Success: Number of entries retrieved from palette
503 UINT WINAPI
GetSystemPaletteEntries(
504 HDC hdc
, /* [in] Handle of device context */
505 UINT start
, /* [in] Index of first entry to be retrieved */
506 UINT count
, /* [in] Number of entries to be retrieved */
507 LPPALETTEENTRY entries
) /* [out] Array receiving system-palette entries */
512 TRACE("hdc=%p,start=%i,count=%i\n", hdc
,start
,count
);
514 if ((dc
= get_dc_ptr( hdc
)))
516 if (dc
->funcs
->pGetSystemPaletteEntries
)
517 ret
= dc
->funcs
->pGetSystemPaletteEntries( dc
->physDev
, start
, count
, entries
);
518 release_dc_ptr( dc
);
524 /***********************************************************************
525 * GetNearestPaletteIndex [GDI32.@]
527 * Gets palette index for color.
530 * Should index be initialized to CLR_INVALID instead of 0?
533 * Success: Index of entry in logical palette
534 * Failure: CLR_INVALID
536 UINT WINAPI
GetNearestPaletteIndex(
537 HPALETTE hpalette
, /* [in] Handle of logical color palette */
538 COLORREF color
) /* [in] Color to be matched */
540 PALETTEOBJ
* palObj
= GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
545 int i
, diff
= 0x7fffffff;
547 PALETTEENTRY
* entry
= palObj
->logpalette
.palPalEntry
;
549 for( i
= 0; i
< palObj
->logpalette
.palNumEntries
&& diff
; i
++, entry
++)
551 r
= entry
->peRed
- GetRValue(color
);
552 g
= entry
->peGreen
- GetGValue(color
);
553 b
= entry
->peBlue
- GetBValue(color
);
557 if( r
< diff
) { index
= i
; diff
= r
; }
559 GDI_ReleaseObj( hpalette
);
561 TRACE("(%p,%06x): returning %d\n", hpalette
, color
, index
);
566 /***********************************************************************
567 * GetNearestColor [GDI32.@]
569 * Gets a system color to match.
572 * Success: Color from system palette that corresponds to given color
573 * Failure: CLR_INVALID
575 COLORREF WINAPI
GetNearestColor(
576 HDC hdc
, /* [in] Handle of device context */
577 COLORREF color
) /* [in] Color to be matched */
579 unsigned char spec_type
;
583 if (!(dc
= get_dc_ptr( hdc
))) return CLR_INVALID
;
585 if (dc
->funcs
->pGetNearestColor
)
587 nearest
= dc
->funcs
->pGetNearestColor( dc
->physDev
, color
);
588 release_dc_ptr( dc
);
592 if (!(GetDeviceCaps(hdc
, RASTERCAPS
) & RC_PALETTE
))
594 release_dc_ptr( dc
);
598 spec_type
= color
>> 24;
599 if (spec_type
== 1 || spec_type
== 2)
601 /* we need logical palette for PALETTERGB and PALETTEINDEX colorrefs */
605 HPALETTE hpal
= dc
->hPalette
? dc
->hPalette
: GetStockObject( DEFAULT_PALETTE
);
607 if (spec_type
== 2) /* PALETTERGB */
608 index
= GetNearestPaletteIndex( hpal
, color
);
609 else /* PALETTEINDEX */
610 index
= LOWORD(color
);
612 if (!GetPaletteEntries( hpal
, index
, 1, &entry
))
614 WARN("RGB(%x) : idx %d is out of bounds, assuming NULL\n", color
, index
);
615 if (!GetPaletteEntries( hpal
, 0, 1, &entry
))
617 release_dc_ptr( dc
);
621 color
= RGB( entry
.peRed
, entry
.peGreen
, entry
.peBlue
);
623 nearest
= color
& 0x00ffffff;
624 release_dc_ptr( dc
);
626 TRACE("(%06x): returning %06x\n", color
, nearest
);
631 /***********************************************************************
634 static INT
PALETTE_GetObject( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
)
636 PALETTEOBJ
*palette
= obj
;
641 if (count
> sizeof(WORD
)) count
= sizeof(WORD
);
642 memcpy( buffer
, &palette
->logpalette
.palNumEntries
, count
);
647 /***********************************************************************
648 * PALETTE_UnrealizeObject
650 static BOOL
PALETTE_UnrealizeObject( HGDIOBJ handle
, void *obj
)
652 PALETTEOBJ
*palette
= obj
;
656 if (palette
->funcs
->pUnrealizePalette
)
657 palette
->funcs
->pUnrealizePalette( handle
);
658 palette
->funcs
= NULL
;
661 if (InterlockedCompareExchangePointer( (void **)&hLastRealizedPalette
, 0, handle
) == handle
)
662 TRACE("unrealizing palette %p\n", handle
);
668 /***********************************************************************
669 * PALETTE_DeleteObject
671 static BOOL
PALETTE_DeleteObject( HGDIOBJ handle
, void *obj
)
673 PALETTE_UnrealizeObject( handle
, obj
);
674 return GDI_FreeObject( handle
, obj
);
678 /***********************************************************************
679 * GDISelectPalette (Not a Windows API)
681 HPALETTE WINAPI
GDISelectPalette( HDC hdc
, HPALETTE hpal
, WORD wBkg
)
686 TRACE("%p %p\n", hdc
, hpal
);
688 if (GetObjectType(hpal
) != OBJ_PAL
)
690 WARN("invalid selected palette %p\n",hpal
);
693 if (!(dc
= get_dc_ptr( hdc
))) return 0;
695 if (dc
->funcs
->pSelectPalette
) hpal
= dc
->funcs
->pSelectPalette( dc
->physDev
, hpal
, FALSE
);
699 if (!wBkg
) hPrimaryPalette
= hpal
;
702 release_dc_ptr( dc
);
707 /***********************************************************************
708 * GDIRealizePalette (Not a Windows API)
710 UINT WINAPI
GDIRealizePalette( HDC hdc
)
713 DC
* dc
= get_dc_ptr( hdc
);
717 TRACE("%p...\n", hdc
);
719 if( dc
->hPalette
== GetStockObject( DEFAULT_PALETTE
))
721 if (dc
->funcs
->pRealizeDefaultPalette
)
722 realized
= dc
->funcs
->pRealizeDefaultPalette( dc
->physDev
);
724 else if (InterlockedExchangePointer( (void **)&hLastRealizedPalette
, dc
->hPalette
) != dc
->hPalette
)
726 if (dc
->funcs
->pRealizePalette
)
728 PALETTEOBJ
*palPtr
= GDI_GetObjPtr( dc
->hPalette
, PALETTE_MAGIC
);
731 realized
= dc
->funcs
->pRealizePalette( dc
->physDev
, dc
->hPalette
,
732 (dc
->hPalette
== hPrimaryPalette
) );
733 palPtr
->funcs
= dc
->funcs
;
734 GDI_ReleaseObj( dc
->hPalette
);
738 else TRACE(" skipping (hLastRealizedPalette = %p)\n", hLastRealizedPalette
);
740 release_dc_ptr( dc
);
741 TRACE(" realized %i colors.\n", realized
);
746 /***********************************************************************
747 * RealizeDefaultPalette (GDI.365)
749 UINT16 WINAPI
RealizeDefaultPalette16( HDC16 hdc
)
754 TRACE("%04x\n", hdc
);
756 if (!(dc
= get_dc_ptr( HDC_32(hdc
) ))) return 0;
758 if (dc
->funcs
->pRealizeDefaultPalette
) ret
= dc
->funcs
->pRealizeDefaultPalette( dc
->physDev
);
759 release_dc_ptr( dc
);
763 /***********************************************************************
764 * IsDCCurrentPalette (GDI.412)
766 BOOL16 WINAPI
IsDCCurrentPalette16(HDC16 hDC
)
768 DC
*dc
= get_dc_ptr( HDC_32(hDC
) );
771 BOOL bRet
= dc
->hPalette
== hPrimaryPalette
;
772 release_dc_ptr( dc
);
779 /***********************************************************************
780 * SelectPalette [GDI32.@]
782 * Selects logical palette into DC.
785 * Success: Previous logical palette
788 HPALETTE WINAPI
SelectPalette(
789 HDC hDC
, /* [in] Handle of device context */
790 HPALETTE hPal
, /* [in] Handle of logical color palette */
791 BOOL bForceBackground
) /* [in] Foreground/background mode */
793 return pfnSelectPalette( hDC
, hPal
, bForceBackground
);
797 /***********************************************************************
798 * RealizePalette [GDI32.@]
800 * Maps palette entries to system palette.
803 * Success: Number of entries in logical palette
806 UINT WINAPI
RealizePalette(
807 HDC hDC
) /* [in] Handle of device context */
809 return pfnRealizePalette( hDC
);
813 typedef HWND (WINAPI
*WindowFromDC_funcptr
)( HDC
);
814 typedef BOOL (WINAPI
*RedrawWindow_funcptr
)( HWND
, const RECT
*, HRGN
, UINT
);
816 /**********************************************************************
817 * UpdateColors [GDI32.@]
819 * Remaps current colors to logical palette.
825 BOOL WINAPI
UpdateColors(
826 HDC hDC
) /* [in] Handle of device context */
829 int size
= GetDeviceCaps( hDC
, SIZEPALETTE
);
833 mod
= GetModuleHandleA("user32.dll");
836 WindowFromDC_funcptr pWindowFromDC
= (WindowFromDC_funcptr
)GetProcAddress(mod
,"WindowFromDC");
839 HWND hWnd
= pWindowFromDC( hDC
);
841 /* Docs say that we have to remap current drawable pixel by pixel
842 * but it would take forever given the speed of XGet/PutPixel.
846 RedrawWindow_funcptr pRedrawWindow
= (void *)GetProcAddress( mod
, "RedrawWindow" );
847 if (pRedrawWindow
) pRedrawWindow( hWnd
, NULL
, 0, RDW_INVALIDATE
);
855 /*********************************************************************
856 * SetMagicColors (GDI.606)
858 VOID WINAPI
SetMagicColors16(HDC16 hDC
, COLORREF color
, UINT16 index
)
860 FIXME("(hDC %04x, color %04x, index %04x): stub\n", hDC
, (int)color
, index
);
864 /*********************************************************************
865 * SetMagicColors (GDI32.@)
867 BOOL WINAPI
SetMagicColors(HDC hdc
, ULONG u1
, ULONG u2
)
869 FIXME("(%p 0x%08x 0x%08x): stub\n", hdc
, u1
, u2
);