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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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"
36 #include "gdi_private.h"
38 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(palette
);
43 static INT
PALETTE_GetObject( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
);
44 static BOOL
PALETTE_UnrealizeObject( HGDIOBJ handle
, void *obj
);
45 static BOOL
PALETTE_DeleteObject( HGDIOBJ handle
, void *obj
);
47 static const struct gdi_obj_funcs palette_funcs
=
49 NULL
, /* pSelectObject */
50 PALETTE_GetObject
, /* pGetObject16 */
51 PALETTE_GetObject
, /* pGetObjectA */
52 PALETTE_GetObject
, /* pGetObjectW */
53 PALETTE_UnrealizeObject
, /* pUnrealizeObject */
54 PALETTE_DeleteObject
/* pDeleteObject */
57 /* Pointers to USER implementation of SelectPalette/RealizePalette */
58 /* they will be patched by USER on startup */
59 HPALETTE (WINAPI
*pfnSelectPalette
)(HDC hdc
, HPALETTE hpal
, WORD bkgnd
) = GDISelectPalette
;
60 UINT (WINAPI
*pfnRealizePalette
)(HDC hdc
) = GDIRealizePalette
;
62 static UINT SystemPaletteUse
= SYSPAL_STATIC
; /* currently not considered */
64 static HPALETTE hPrimaryPalette
= 0; /* used for WM_PALETTECHANGED */
65 static HPALETTE hLastRealizedPalette
= 0; /* UnrealizeObject() needs it */
66 static const DC_FUNCTIONS
*pLastRealizedDC
;
68 static const PALETTEENTRY sys_pal_template
[NB_RESERVED_COLORS
] =
70 /* first 10 entries in the system palette */
71 /* red green blue flags */
72 { 0x00, 0x00, 0x00, 0 },
73 { 0x80, 0x00, 0x00, 0 },
74 { 0x00, 0x80, 0x00, 0 },
75 { 0x80, 0x80, 0x00, 0 },
76 { 0x00, 0x00, 0x80, 0 },
77 { 0x80, 0x00, 0x80, 0 },
78 { 0x00, 0x80, 0x80, 0 },
79 { 0xc0, 0xc0, 0xc0, 0 },
80 { 0xc0, 0xdc, 0xc0, 0 },
81 { 0xa6, 0xca, 0xf0, 0 },
83 /* ... c_min/2 dynamic colorcells */
85 /* ... gap (for sparse palettes) */
87 /* ... c_min/2 dynamic colorcells */
89 { 0xff, 0xfb, 0xf0, 0 },
90 { 0xa0, 0xa0, 0xa4, 0 },
91 { 0x80, 0x80, 0x80, 0 },
92 { 0xff, 0x00, 0x00, 0 },
93 { 0x00, 0xff, 0x00, 0 },
94 { 0xff, 0xff, 0x00, 0 },
95 { 0x00, 0x00, 0xff, 0 },
96 { 0xff, 0x00, 0xff, 0 },
97 { 0x00, 0xff, 0xff, 0 },
98 { 0xff, 0xff, 0xff, 0 } /* last 10 */
101 /***********************************************************************
104 * Create the system palette.
106 HPALETTE
PALETTE_Init(void)
112 /* create default palette (20 system colors) */
114 palPtr
= HeapAlloc( GetProcessHeap(), 0,
115 sizeof(LOGPALETTE
) + (NB_RESERVED_COLORS
-1)*sizeof(PALETTEENTRY
));
116 if (!palPtr
) return FALSE
;
118 palPtr
->palVersion
= 0x300;
119 palPtr
->palNumEntries
= NB_RESERVED_COLORS
;
120 memcpy( palPtr
->palPalEntry
, sys_pal_template
, sizeof(sys_pal_template
) );
121 hpalette
= CreatePalette( palPtr
);
122 HeapFree( GetProcessHeap(), 0, palPtr
);
124 palObj
= (PALETTEOBJ
*) GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
127 if (!(palObj
->mapping
= HeapAlloc( GetProcessHeap(), 0, sizeof(int) * NB_RESERVED_COLORS
)))
128 ERR("Can not create palette mapping -- out of memory!\n");
129 GDI_ReleaseObj( hpalette
);
134 /***********************************************************************
135 * PALETTE_ValidateFlags
137 static void PALETTE_ValidateFlags(PALETTEENTRY
* lpPalE
, int size
)
140 for( ; i
<size
; i
++ )
141 lpPalE
[i
].peFlags
= PC_SYS_USED
| (lpPalE
[i
].peFlags
& 0x07);
145 /***********************************************************************
146 * CreatePalette [GDI32.@]
148 * Creates a logical color palette.
151 * Success: Handle to logical palette
154 HPALETTE WINAPI
CreatePalette(
155 const LOGPALETTE
* palette
) /* [in] Pointer to logical color palette */
157 PALETTEOBJ
* palettePtr
;
161 if (!palette
) return 0;
162 TRACE("entries=%i\n", palette
->palNumEntries
);
164 size
= sizeof(LOGPALETTE
) + (palette
->palNumEntries
- 1) * sizeof(PALETTEENTRY
);
166 if (!(palettePtr
= GDI_AllocObject( size
+ sizeof(int*) +sizeof(GDIOBJHDR
),
167 PALETTE_MAGIC
, (HGDIOBJ
*)&hpalette
,
168 &palette_funcs
))) return 0;
169 memcpy( &palettePtr
->logpalette
, palette
, size
);
170 PALETTE_ValidateFlags(palettePtr
->logpalette
.palPalEntry
,
171 palettePtr
->logpalette
.palNumEntries
);
172 palettePtr
->mapping
= NULL
;
173 GDI_ReleaseObj( hpalette
);
175 TRACE(" returning %p\n", hpalette
);
180 /***********************************************************************
181 * CreateHalftonePalette [GDI32.@]
183 * Creates a halftone palette.
186 * Success: Handle to logical halftone palette
189 * FIXME: This simply creates the halftone palette derived from running
190 * tests on an windows NT machine. this is assuming a color depth
191 * of greater that 256 color. On a 256 color device the halftone
192 * palette will be different and this function will be incorrect
194 HPALETTE WINAPI
CreateHalftonePalette(
195 HDC hdc
) /* [in] Handle to device context */
200 WORD NumberOfEntries
;
201 PALETTEENTRY aEntries
[256];
204 Palette
.Version
= 0x300;
205 Palette
.NumberOfEntries
= 256;
206 GetSystemPaletteEntries(hdc
, 0, 256, Palette
.aEntries
);
208 Palette
.NumberOfEntries
= 20;
210 for (i
= 0; i
< Palette
.NumberOfEntries
; i
++)
212 Palette
.aEntries
[i
].peRed
=0xff;
213 Palette
.aEntries
[i
].peGreen
=0xff;
214 Palette
.aEntries
[i
].peBlue
=0xff;
215 Palette
.aEntries
[i
].peFlags
=0x00;
218 Palette
.aEntries
[0].peRed
=0x00;
219 Palette
.aEntries
[0].peBlue
=0x00;
220 Palette
.aEntries
[0].peGreen
=0x00;
223 for (i
=1; i
<= 6; i
++)
225 Palette
.aEntries
[i
].peRed
=(i
%2)?0x80:0;
226 Palette
.aEntries
[i
].peGreen
=(i
==2)?0x80:(i
==3)?0x80:(i
==6)?0x80:0;
227 Palette
.aEntries
[i
].peBlue
=(i
>3)?0x80:0;
230 for (i
=7; i
<= 12; i
++)
235 Palette
.aEntries
[i
].peRed
=0xc0;
236 Palette
.aEntries
[i
].peBlue
=0xc0;
237 Palette
.aEntries
[i
].peGreen
=0xc0;
240 Palette
.aEntries
[i
].peRed
=0xc0;
241 Palette
.aEntries
[i
].peGreen
=0xdc;
242 Palette
.aEntries
[i
].peBlue
=0xc0;
245 Palette
.aEntries
[i
].peRed
=0xa6;
246 Palette
.aEntries
[i
].peGreen
=0xca;
247 Palette
.aEntries
[i
].peBlue
=0xf0;
250 Palette
.aEntries
[i
].peRed
=0xff;
251 Palette
.aEntries
[i
].peGreen
=0xfb;
252 Palette
.aEntries
[i
].peBlue
=0xf0;
255 Palette
.aEntries
[i
].peRed
=0xa0;
256 Palette
.aEntries
[i
].peGreen
=0xa0;
257 Palette
.aEntries
[i
].peBlue
=0xa4;
260 Palette
.aEntries
[i
].peRed
=0x80;
261 Palette
.aEntries
[i
].peGreen
=0x80;
262 Palette
.aEntries
[i
].peBlue
=0x80;
266 for (i
=13; i
<= 18; i
++)
268 Palette
.aEntries
[i
].peRed
=(i
%2)?0xff:0;
269 Palette
.aEntries
[i
].peGreen
=(i
==14)?0xff:(i
==15)?0xff:(i
==18)?0xff:0;
270 Palette
.aEntries
[i
].peBlue
=(i
>15)?0xff:0x00;
273 return CreatePalette((LOGPALETTE
*)&Palette
);
277 /***********************************************************************
278 * GetPaletteEntries [GDI32.@]
280 * Retrieves palette entries.
283 * Success: Number of entries from logical palette
286 UINT WINAPI
GetPaletteEntries(
287 HPALETTE hpalette
, /* [in] Handle of logical palette */
288 UINT start
, /* [in] First entry to receive */
289 UINT count
, /* [in] Number of entries to receive */
290 LPPALETTEENTRY entries
) /* [out] Address of array receiving entries */
295 TRACE("hpal = %p, count=%i\n", hpalette
, count
);
297 palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
298 if (!palPtr
) return 0;
300 /* NOTE: not documented but test show this to be the case */
303 int rc
= palPtr
->logpalette
.palNumEntries
;
304 GDI_ReleaseObj( hpalette
);
308 numEntries
= palPtr
->logpalette
.palNumEntries
;
309 if (start
+count
> numEntries
) count
= numEntries
- start
;
312 if (start
>= numEntries
)
314 GDI_ReleaseObj( hpalette
);
317 memcpy( entries
, &palPtr
->logpalette
.palPalEntry
[start
],
318 count
* sizeof(PALETTEENTRY
) );
319 for( numEntries
= 0; numEntries
< count
; numEntries
++ )
320 if (entries
[numEntries
].peFlags
& 0xF0)
321 entries
[numEntries
].peFlags
= 0;
324 GDI_ReleaseObj( hpalette
);
329 /***********************************************************************
330 * SetPaletteEntries [GDI32.@]
332 * Sets color values for range in palette.
335 * Success: Number of entries that were set
338 UINT WINAPI
SetPaletteEntries(
339 HPALETTE hpalette
, /* [in] Handle of logical palette */
340 UINT start
, /* [in] Index of first entry to set */
341 UINT count
, /* [in] Number of entries to set */
342 const PALETTEENTRY
*entries
) /* [in] Address of array of structures */
347 TRACE("hpal=%p,start=%i,count=%i\n",hpalette
,start
,count
);
349 if (hpalette
== GetStockObject(DEFAULT_PALETTE
)) return 0;
350 palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
351 if (!palPtr
) return 0;
353 numEntries
= palPtr
->logpalette
.palNumEntries
;
354 if (start
>= numEntries
)
356 GDI_ReleaseObj( hpalette
);
359 if (start
+count
> numEntries
) count
= numEntries
- start
;
360 memcpy( &palPtr
->logpalette
.palPalEntry
[start
], entries
,
361 count
* sizeof(PALETTEENTRY
) );
362 PALETTE_ValidateFlags(palPtr
->logpalette
.palPalEntry
,
363 palPtr
->logpalette
.palNumEntries
);
364 UnrealizeObject( hpalette
);
365 GDI_ReleaseObj( hpalette
);
370 /***********************************************************************
371 * ResizePalette [GDI32.@]
373 * Resizes logical palette.
379 BOOL WINAPI
ResizePalette(
380 HPALETTE hPal
, /* [in] Handle of logical palette */
381 UINT cEntries
) /* [in] Number of entries in logical palette */
383 PALETTEOBJ
* palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hPal
, PALETTE_MAGIC
);
384 UINT cPrevEnt
, prevVer
;
385 int prevsize
, size
= sizeof(LOGPALETTE
) + (cEntries
- 1) * sizeof(PALETTEENTRY
);
388 TRACE("hpal = %p, prev = %i, new = %i\n",
389 hPal
, palPtr
? palPtr
->logpalette
.palNumEntries
: -1, cEntries
);
390 if( !palPtr
) return FALSE
;
391 cPrevEnt
= palPtr
->logpalette
.palNumEntries
;
392 prevVer
= palPtr
->logpalette
.palVersion
;
393 prevsize
= sizeof(LOGPALETTE
) + (cPrevEnt
- 1) * sizeof(PALETTEENTRY
) +
394 sizeof(int*) + sizeof(GDIOBJHDR
);
395 size
+= sizeof(int*) + sizeof(GDIOBJHDR
);
396 mapping
= palPtr
->mapping
;
398 if (!(palPtr
= GDI_ReallocObject( size
, hPal
, palPtr
))) return FALSE
;
402 int *newMap
= (int*) HeapReAlloc(GetProcessHeap(), 0,
403 mapping
, cEntries
* sizeof(int) );
406 ERR("Can not resize mapping -- out of memory!\n");
407 GDI_ReleaseObj( hPal
);
410 palPtr
->mapping
= newMap
;
413 if( cEntries
> cPrevEnt
)
416 memset(palPtr
->mapping
+ cPrevEnt
, 0, (cEntries
- cPrevEnt
)*sizeof(int));
417 memset( (BYTE
*)palPtr
+ prevsize
, 0, size
- prevsize
);
418 PALETTE_ValidateFlags((PALETTEENTRY
*)((BYTE
*)palPtr
+ prevsize
),
419 cEntries
- cPrevEnt
);
421 palPtr
->logpalette
.palNumEntries
= cEntries
;
422 palPtr
->logpalette
.palVersion
= prevVer
;
423 GDI_ReleaseObj( hPal
);
428 /***********************************************************************
429 * AnimatePalette [GDI32.@]
431 * Replaces entries in logical palette.
438 * Should use existing mapping when animating a primary palette
440 BOOL WINAPI
AnimatePalette(
441 HPALETTE hPal
, /* [in] Handle to logical palette */
442 UINT StartIndex
, /* [in] First entry in palette */
443 UINT NumEntries
, /* [in] Count of entries in palette */
444 const PALETTEENTRY
* PaletteColors
) /* [in] Pointer to first replacement */
446 TRACE("%p (%i - %i)\n", hPal
, StartIndex
,StartIndex
+NumEntries
);
448 if( hPal
!= GetStockObject(DEFAULT_PALETTE
) )
450 if (!SetPaletteEntries( hPal
, StartIndex
, NumEntries
, PaletteColors
)) return FALSE
;
452 if (pLastRealizedDC
&& pLastRealizedDC
->pRealizePalette
)
453 pLastRealizedDC
->pRealizePalette( NULL
, hPal
, hPal
== hPrimaryPalette
);
459 /***********************************************************************
460 * SetSystemPaletteUse [GDI32.@]
463 * Success: Previous system palette
464 * Failure: SYSPAL_ERROR
466 UINT WINAPI
SetSystemPaletteUse(
467 HDC hdc
, /* [in] Handle of device context */
468 UINT use
) /* [in] Palette-usage flag */
470 UINT old
= SystemPaletteUse
;
472 /* Device doesn't support colour palettes */
473 if (!(GetDeviceCaps(hdc
, RASTERCAPS
) & RC_PALETTE
)) {
478 case SYSPAL_NOSTATIC
:
479 case SYSPAL_NOSTATIC256
: /* WINVER >= 0x0500 */
481 SystemPaletteUse
= use
;
489 /***********************************************************************
490 * GetSystemPaletteUse [GDI32.@]
492 * Gets state of system palette.
495 * Current state of system palette
497 UINT WINAPI
GetSystemPaletteUse(
498 HDC hdc
) /* [in] Handle of device context */
500 return SystemPaletteUse
;
504 /***********************************************************************
505 * GetSystemPaletteEntries [GDI32.@]
507 * Gets range of palette entries.
510 * Success: Number of entries retrieved from palette
513 UINT WINAPI
GetSystemPaletteEntries(
514 HDC hdc
, /* [in] Handle of device context */
515 UINT start
, /* [in] Index of first entry to be retrieved */
516 UINT count
, /* [in] Number of entries to be retrieved */
517 LPPALETTEENTRY entries
) /* [out] Array receiving system-palette entries */
522 TRACE("hdc=%p,start=%i,count=%i\n", hdc
,start
,count
);
524 if ((dc
= DC_GetDCPtr( hdc
)))
526 if (dc
->funcs
->pGetSystemPaletteEntries
)
527 ret
= dc
->funcs
->pGetSystemPaletteEntries( dc
->physDev
, start
, count
, entries
);
528 GDI_ReleaseObj( hdc
);
534 /***********************************************************************
535 * GetNearestPaletteIndex [GDI32.@]
537 * Gets palette index for color.
540 * Should index be initialized to CLR_INVALID instead of 0?
543 * Success: Index of entry in logical palette
544 * Failure: CLR_INVALID
546 UINT WINAPI
GetNearestPaletteIndex(
547 HPALETTE hpalette
, /* [in] Handle of logical color palette */
548 COLORREF color
) /* [in] Color to be matched */
550 PALETTEOBJ
* palObj
= (PALETTEOBJ
*)GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
555 int i
, diff
= 0x7fffffff;
557 PALETTEENTRY
* entry
= palObj
->logpalette
.palPalEntry
;
559 for( i
= 0; i
< palObj
->logpalette
.palNumEntries
&& diff
; i
++, entry
++)
561 if (!(entry
->peFlags
& PC_SYS_USED
)) continue;
563 r
= entry
->peRed
- GetRValue(color
);
564 g
= entry
->peGreen
- GetGValue(color
);
565 b
= entry
->peBlue
- GetBValue(color
);
569 if( r
< diff
) { index
= i
; diff
= r
; }
571 GDI_ReleaseObj( hpalette
);
573 TRACE("(%p,%06lx): returning %d\n", hpalette
, color
, index
);
578 /***********************************************************************
579 * GetNearestColor [GDI32.@]
581 * Gets a system color to match.
584 * Success: Color from system palette that corresponds to given color
585 * Failure: CLR_INVALID
587 COLORREF WINAPI
GetNearestColor(
588 HDC hdc
, /* [in] Handle of device context */
589 COLORREF color
) /* [in] Color to be matched */
591 unsigned char spec_type
;
595 if (!(dc
= DC_GetDCPtr( hdc
))) return CLR_INVALID
;
597 if (dc
->funcs
->pGetNearestColor
)
599 nearest
= dc
->funcs
->pGetNearestColor( dc
->physDev
, color
);
600 GDI_ReleaseObj( hdc
);
604 if (!(GetDeviceCaps(hdc
, RASTERCAPS
) & RC_PALETTE
))
606 GDI_ReleaseObj( hdc
);
610 spec_type
= color
>> 24;
611 if (spec_type
== 1 || spec_type
== 2)
613 /* we need logical palette for PALETTERGB and PALETTEINDEX colorrefs */
617 HPALETTE hpal
= dc
->hPalette
? dc
->hPalette
: GetStockObject( DEFAULT_PALETTE
);
619 if (spec_type
== 2) /* PALETTERGB */
620 index
= GetNearestPaletteIndex( hpal
, color
);
621 else /* PALETTEINDEX */
622 index
= LOWORD(color
);
624 if (!GetPaletteEntries( hpal
, index
, 1, &entry
))
626 WARN("RGB(%lx) : idx %d is out of bounds, assuming NULL\n", color
, index
);
627 if (!GetPaletteEntries( hpal
, 0, 1, &entry
))
629 GDI_ReleaseObj( hdc
);
633 color
= RGB( entry
.peRed
, entry
.peGreen
, entry
.peBlue
);
635 nearest
= color
& 0x00ffffff;
636 GDI_ReleaseObj( hdc
);
638 TRACE("(%06lx): returning %06lx\n", color
, nearest
);
643 /***********************************************************************
646 static INT
PALETTE_GetObject( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
)
648 PALETTEOBJ
*palette
= obj
;
653 if (count
> sizeof(WORD
)) count
= sizeof(WORD
);
654 memcpy( buffer
, &palette
->logpalette
.palNumEntries
, count
);
659 /***********************************************************************
660 * PALETTE_UnrealizeObject
662 static BOOL
PALETTE_UnrealizeObject( HGDIOBJ handle
, void *obj
)
664 PALETTEOBJ
*palette
= obj
;
666 if (palette
->mapping
)
668 HeapFree( GetProcessHeap(), 0, palette
->mapping
);
669 palette
->mapping
= NULL
;
671 if (hLastRealizedPalette
== handle
)
673 hLastRealizedPalette
= 0;
674 pLastRealizedDC
= NULL
;
680 /***********************************************************************
681 * PALETTE_DeleteObject
683 static BOOL
PALETTE_DeleteObject( HGDIOBJ handle
, void *obj
)
685 PALETTEOBJ
*palette
= obj
;
687 HeapFree( GetProcessHeap(), 0, palette
->mapping
);
688 if (hLastRealizedPalette
== handle
)
690 hLastRealizedPalette
= 0;
691 pLastRealizedDC
= NULL
;
693 return GDI_FreeObject( handle
, obj
);
697 /***********************************************************************
698 * GDISelectPalette (Not a Windows API)
700 HPALETTE WINAPI
GDISelectPalette( HDC hdc
, HPALETTE hpal
, WORD wBkg
)
705 TRACE("%p %p\n", hdc
, hpal
);
707 if (GetObjectType(hpal
) != OBJ_PAL
)
709 WARN("invalid selected palette %p\n",hpal
);
712 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
714 if (dc
->funcs
->pSelectPalette
) hpal
= dc
->funcs
->pSelectPalette( dc
->physDev
, hpal
, FALSE
);
718 if (!wBkg
) hPrimaryPalette
= hpal
;
721 GDI_ReleaseObj( hdc
);
726 /***********************************************************************
727 * GDIRealizePalette (Not a Windows API)
729 UINT WINAPI
GDIRealizePalette( HDC hdc
)
732 DC
* dc
= DC_GetDCPtr( hdc
);
736 TRACE("%p...\n", hdc
);
738 if( dc
->hPalette
== GetStockObject( DEFAULT_PALETTE
))
740 if (dc
->funcs
->pRealizeDefaultPalette
)
741 realized
= dc
->funcs
->pRealizeDefaultPalette( dc
->physDev
);
743 else if(dc
->hPalette
!= hLastRealizedPalette
)
745 if (dc
->funcs
->pRealizePalette
)
746 realized
= dc
->funcs
->pRealizePalette( dc
->physDev
, dc
->hPalette
,
747 (dc
->hPalette
== hPrimaryPalette
) );
748 hLastRealizedPalette
= dc
->hPalette
;
749 pLastRealizedDC
= dc
->funcs
;
751 else TRACE(" skipping (hLastRealizedPalette = %p)\n", hLastRealizedPalette
);
753 GDI_ReleaseObj( hdc
);
754 TRACE(" realized %i colors.\n", realized
);
759 /***********************************************************************
760 * RealizeDefaultPalette (GDI.365)
762 UINT16 WINAPI
RealizeDefaultPalette16( HDC16 hdc
)
767 TRACE("%04x\n", hdc
);
769 if (!(dc
= DC_GetDCPtr( HDC_32(hdc
) ))) return 0;
771 if (dc
->funcs
->pRealizeDefaultPalette
) ret
= dc
->funcs
->pRealizeDefaultPalette( dc
->physDev
);
772 GDI_ReleaseObj( HDC_32(hdc
) );
776 /***********************************************************************
777 * IsDCCurrentPalette (GDI.412)
779 BOOL16 WINAPI
IsDCCurrentPalette16(HDC16 hDC
)
781 DC
*dc
= DC_GetDCPtr( HDC_32(hDC
) );
784 BOOL bRet
= dc
->hPalette
== hPrimaryPalette
;
785 GDI_ReleaseObj( HDC_32(hDC
) );
792 /***********************************************************************
793 * SelectPalette [GDI32.@]
795 * Selects logical palette into DC.
798 * Success: Previous logical palette
801 HPALETTE WINAPI
SelectPalette(
802 HDC hDC
, /* [in] Handle of device context */
803 HPALETTE hPal
, /* [in] Handle of logical color palette */
804 BOOL bForceBackground
) /* [in] Foreground/background mode */
806 return pfnSelectPalette( hDC
, hPal
, bForceBackground
);
810 /***********************************************************************
811 * RealizePalette [GDI32.@]
813 * Maps palette entries to system palette.
816 * Success: Number of entries in logical palette
819 UINT WINAPI
RealizePalette(
820 HDC hDC
) /* [in] Handle of device context */
822 return pfnRealizePalette( hDC
);
826 typedef HWND (WINAPI
*WindowFromDC_funcptr
)( HDC
);
827 typedef BOOL (WINAPI
*RedrawWindow_funcptr
)( HWND
, const RECT
*, HRGN
, UINT
);
829 /**********************************************************************
830 * UpdateColors [GDI32.@]
832 * Remaps current colors to logical palette.
838 BOOL WINAPI
UpdateColors(
839 HDC hDC
) /* [in] Handle of device context */
842 int size
= GetDeviceCaps( hDC
, SIZEPALETTE
);
846 mod
= GetModuleHandleA("user32.dll");
849 WindowFromDC_funcptr pWindowFromDC
= (WindowFromDC_funcptr
)GetProcAddress(mod
,"WindowFromDC");
852 HWND hWnd
= pWindowFromDC( hDC
);
854 /* Docs say that we have to remap current drawable pixel by pixel
855 * but it would take forever given the speed of XGet/PutPixel.
859 RedrawWindow_funcptr pRedrawWindow
= GetProcAddress( mod
, "RedrawWindow" );
860 if (pRedrawWindow
) pRedrawWindow( hWnd
, NULL
, 0, RDW_INVALIDATE
);
868 /*********************************************************************
869 * SetMagicColors (GDI.606)
871 VOID WINAPI
SetMagicColors16(HDC16 hDC
, COLORREF color
, UINT16 index
)
873 FIXME("(hDC %04x, color %04x, index %04x): stub\n", hDC
, (int)color
, index
);
877 /**********************************************************************
878 * GetICMProfileA [GDI32.@]
880 * Returns the filename of the specified device context's color
881 * management profile, even if color management is not enabled
885 * TRUE if name copied successfully OR lpszFilename is NULL
886 * FALSE if the buffer length pointed to by lpcbName is too small
889 * The buffer length pointed to by lpcbName is ALWAYS updated to
890 * the length required regardless of other actions this function
894 * How does Windows assign these? Some registry key?
897 #define WINEICM "winefake.icm" /* easy-to-identify fake filename */
899 /*********************************************************************/
901 BOOL WINAPI
GetICMProfileA(HDC hDC
, LPDWORD lpcbName
, LPSTR lpszFilename
)
905 FIXME("(%p, %p, %p): partial stub\n", hDC
, lpcbName
, lpszFilename
);
907 callerLen
= *lpcbName
;
909 /* all 3 behaviors require the required buffer size to be set */
910 *lpcbName
= strlen(WINEICM
);
912 /* behavior 1: if lpszFilename is NULL, return size of string and no error */
913 if ((DWORD
)lpszFilename
== (DWORD
)0x00000000)
916 /* behavior 2: if buffer size too small, return size of string and error */
917 if (callerLen
< strlen(WINEICM
))
919 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
923 /* behavior 3: if buffer size OK and pointer not NULL, copy and return size */
924 strcpy(lpszFilename
, WINEICM
);