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
, /* pGetObject16 */
56 PALETTE_GetObject
, /* pGetObjectA */
57 PALETTE_GetObject
, /* pGetObjectW */
58 PALETTE_UnrealizeObject
, /* pUnrealizeObject */
59 PALETTE_DeleteObject
/* pDeleteObject */
62 /* Pointers to USER implementation of SelectPalette/RealizePalette */
63 /* they will be patched by USER on startup */
64 HPALETTE (WINAPI
*pfnSelectPalette
)(HDC hdc
, HPALETTE hpal
, WORD bkgnd
) = GDISelectPalette
;
65 UINT (WINAPI
*pfnRealizePalette
)(HDC hdc
) = GDIRealizePalette
;
67 static UINT SystemPaletteUse
= SYSPAL_STATIC
; /* currently not considered */
69 static HPALETTE hPrimaryPalette
= 0; /* used for WM_PALETTECHANGED */
70 static HPALETTE hLastRealizedPalette
= 0; /* UnrealizeObject() needs it */
72 #define NB_RESERVED_COLORS 20 /* number of fixed colors in system palette */
74 static const PALETTEENTRY sys_pal_template
[NB_RESERVED_COLORS
] =
76 /* first 10 entries in the system palette */
77 /* red green blue flags */
78 { 0x00, 0x00, 0x00, 0 },
79 { 0x80, 0x00, 0x00, 0 },
80 { 0x00, 0x80, 0x00, 0 },
81 { 0x80, 0x80, 0x00, 0 },
82 { 0x00, 0x00, 0x80, 0 },
83 { 0x80, 0x00, 0x80, 0 },
84 { 0x00, 0x80, 0x80, 0 },
85 { 0xc0, 0xc0, 0xc0, 0 },
86 { 0xc0, 0xdc, 0xc0, 0 },
87 { 0xa6, 0xca, 0xf0, 0 },
89 /* ... c_min/2 dynamic colorcells */
91 /* ... gap (for sparse palettes) */
93 /* ... c_min/2 dynamic colorcells */
95 { 0xff, 0xfb, 0xf0, 0 },
96 { 0xa0, 0xa0, 0xa4, 0 },
97 { 0x80, 0x80, 0x80, 0 },
98 { 0xff, 0x00, 0x00, 0 },
99 { 0x00, 0xff, 0x00, 0 },
100 { 0xff, 0xff, 0x00, 0 },
101 { 0x00, 0x00, 0xff, 0 },
102 { 0xff, 0x00, 0xff, 0 },
103 { 0x00, 0xff, 0xff, 0 },
104 { 0xff, 0xff, 0xff, 0 } /* last 10 */
107 /***********************************************************************
110 * Create the system palette.
112 HPALETTE
PALETTE_Init(void)
117 /* create default palette (20 system colors) */
119 palPtr
= HeapAlloc( GetProcessHeap(), 0,
120 sizeof(LOGPALETTE
) + (NB_RESERVED_COLORS
-1)*sizeof(PALETTEENTRY
));
121 if (!palPtr
) return FALSE
;
123 palPtr
->palVersion
= 0x300;
124 palPtr
->palNumEntries
= NB_RESERVED_COLORS
;
125 memcpy( palPtr
->palPalEntry
, sys_pal_template
, sizeof(sys_pal_template
) );
126 hpalette
= CreatePalette( palPtr
);
127 HeapFree( GetProcessHeap(), 0, palPtr
);
132 /***********************************************************************
133 * CreatePalette [GDI32.@]
135 * Creates a logical color palette.
138 * Success: Handle to logical palette
141 HPALETTE WINAPI
CreatePalette(
142 const LOGPALETTE
* palette
) /* [in] Pointer to logical color palette */
144 PALETTEOBJ
* palettePtr
;
148 if (!palette
) return 0;
149 TRACE("entries=%i\n", palette
->palNumEntries
);
151 size
= sizeof(LOGPALETTE
) + (palette
->palNumEntries
- 1) * sizeof(PALETTEENTRY
);
153 if (!(palettePtr
= GDI_AllocObject( size
+ sizeof(int*) +sizeof(GDIOBJHDR
),
154 PALETTE_MAGIC
, (HGDIOBJ
*)&hpalette
,
155 &palette_funcs
))) return 0;
156 memcpy( &palettePtr
->logpalette
, palette
, size
);
157 palettePtr
->funcs
= NULL
;
158 GDI_ReleaseObj( hpalette
);
160 TRACE(" returning %p\n", hpalette
);
165 /***********************************************************************
166 * CreateHalftonePalette [GDI32.@]
168 * Creates a halftone palette.
171 * Success: Handle to logical halftone palette
174 * FIXME: This simply creates the halftone palette derived from running
175 * tests on a windows NT machine. This is assuming a color depth
176 * of greater that 256 color. On a 256 color device the halftone
177 * palette will be different and this function will be incorrect
179 HPALETTE WINAPI
CreateHalftonePalette(
180 HDC hdc
) /* [in] Handle to device context */
185 WORD NumberOfEntries
;
186 PALETTEENTRY aEntries
[256];
189 Palette
.Version
= 0x300;
190 Palette
.NumberOfEntries
= 256;
191 GetSystemPaletteEntries(hdc
, 0, 256, Palette
.aEntries
);
193 Palette
.NumberOfEntries
= 20;
196 * CODEWEAVERS HACK - Huw says:
198 * Go back to using a 256 colour halftone palette, which is what my
199 * version of win2k returns.
201 * This fixes display of word drawings on 8bpp displays. However it
202 * reverts a patch by Aric which supposedly fixed some colour issues with
203 * office 97, so we need to watch out for these again.
205 return CreatePalette((LOGPALETTE
*)&Palette
);
207 for (i
= 0; i
< Palette
.NumberOfEntries
; i
++)
209 Palette
.aEntries
[i
].peRed
=0xff;
210 Palette
.aEntries
[i
].peGreen
=0xff;
211 Palette
.aEntries
[i
].peBlue
=0xff;
212 Palette
.aEntries
[i
].peFlags
=0x00;
215 Palette
.aEntries
[0].peRed
=0x00;
216 Palette
.aEntries
[0].peBlue
=0x00;
217 Palette
.aEntries
[0].peGreen
=0x00;
220 for (i
=1; i
<= 6; i
++)
222 Palette
.aEntries
[i
].peRed
=(i
%2)?0x80:0;
223 Palette
.aEntries
[i
].peGreen
=(i
==2)?0x80:(i
==3)?0x80:(i
==6)?0x80:0;
224 Palette
.aEntries
[i
].peBlue
=(i
>3)?0x80:0;
227 for (i
=7; i
<= 12; i
++)
232 Palette
.aEntries
[i
].peRed
=0xc0;
233 Palette
.aEntries
[i
].peBlue
=0xc0;
234 Palette
.aEntries
[i
].peGreen
=0xc0;
237 Palette
.aEntries
[i
].peRed
=0xc0;
238 Palette
.aEntries
[i
].peGreen
=0xdc;
239 Palette
.aEntries
[i
].peBlue
=0xc0;
242 Palette
.aEntries
[i
].peRed
=0xa6;
243 Palette
.aEntries
[i
].peGreen
=0xca;
244 Palette
.aEntries
[i
].peBlue
=0xf0;
247 Palette
.aEntries
[i
].peRed
=0xff;
248 Palette
.aEntries
[i
].peGreen
=0xfb;
249 Palette
.aEntries
[i
].peBlue
=0xf0;
252 Palette
.aEntries
[i
].peRed
=0xa0;
253 Palette
.aEntries
[i
].peGreen
=0xa0;
254 Palette
.aEntries
[i
].peBlue
=0xa4;
257 Palette
.aEntries
[i
].peRed
=0x80;
258 Palette
.aEntries
[i
].peGreen
=0x80;
259 Palette
.aEntries
[i
].peBlue
=0x80;
263 for (i
=13; i
<= 18; i
++)
265 Palette
.aEntries
[i
].peRed
=(i
%2)?0xff:0;
266 Palette
.aEntries
[i
].peGreen
=(i
==14)?0xff:(i
==15)?0xff:(i
==18)?0xff:0;
267 Palette
.aEntries
[i
].peBlue
=(i
>15)?0xff:0x00;
270 return CreatePalette((LOGPALETTE
*)&Palette
);
274 /***********************************************************************
275 * GetPaletteEntries [GDI32.@]
277 * Retrieves palette entries.
280 * Success: Number of entries from logical palette
283 UINT WINAPI
GetPaletteEntries(
284 HPALETTE hpalette
, /* [in] Handle of logical palette */
285 UINT start
, /* [in] First entry to receive */
286 UINT count
, /* [in] Number of entries to receive */
287 LPPALETTEENTRY entries
) /* [out] Address of array receiving entries */
292 TRACE("hpal = %p, count=%i\n", hpalette
, count
);
294 palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
295 if (!palPtr
) return 0;
297 /* NOTE: not documented but test show this to be the case */
300 int rc
= palPtr
->logpalette
.palNumEntries
;
301 GDI_ReleaseObj( hpalette
);
305 numEntries
= palPtr
->logpalette
.palNumEntries
;
306 if (start
+count
> numEntries
) count
= numEntries
- start
;
309 if (start
>= numEntries
)
311 GDI_ReleaseObj( hpalette
);
314 memcpy( entries
, &palPtr
->logpalette
.palPalEntry
[start
],
315 count
* sizeof(PALETTEENTRY
) );
316 for( numEntries
= 0; numEntries
< count
; numEntries
++ )
317 if (entries
[numEntries
].peFlags
& 0xF0)
318 entries
[numEntries
].peFlags
= 0;
321 GDI_ReleaseObj( hpalette
);
326 /***********************************************************************
327 * SetPaletteEntries [GDI32.@]
329 * Sets color values for range in palette.
332 * Success: Number of entries that were set
335 UINT WINAPI
SetPaletteEntries(
336 HPALETTE hpalette
, /* [in] Handle of logical palette */
337 UINT start
, /* [in] Index of first entry to set */
338 UINT count
, /* [in] Number of entries to set */
339 const PALETTEENTRY
*entries
) /* [in] Address of array of structures */
344 TRACE("hpal=%p,start=%i,count=%i\n",hpalette
,start
,count
);
346 if (hpalette
== GetStockObject(DEFAULT_PALETTE
)) return 0;
347 palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
348 if (!palPtr
) return 0;
350 numEntries
= palPtr
->logpalette
.palNumEntries
;
351 if (start
>= numEntries
)
353 GDI_ReleaseObj( hpalette
);
356 if (start
+count
> numEntries
) count
= numEntries
- start
;
357 memcpy( &palPtr
->logpalette
.palPalEntry
[start
], entries
,
358 count
* sizeof(PALETTEENTRY
) );
359 UnrealizeObject( hpalette
);
360 GDI_ReleaseObj( hpalette
);
365 /***********************************************************************
366 * ResizePalette [GDI32.@]
368 * Resizes logical palette.
374 BOOL WINAPI
ResizePalette(
375 HPALETTE hPal
, /* [in] Handle of logical palette */
376 UINT cEntries
) /* [in] Number of entries in logical palette */
378 PALETTEOBJ
* palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hPal
, PALETTE_MAGIC
);
379 UINT cPrevEnt
, prevVer
;
380 int prevsize
, size
= sizeof(LOGPALETTE
) + (cEntries
- 1) * sizeof(PALETTEENTRY
);
382 TRACE("hpal = %p, prev = %i, new = %i\n",
383 hPal
, palPtr
? palPtr
->logpalette
.palNumEntries
: -1, cEntries
);
384 if( !palPtr
) return FALSE
;
385 cPrevEnt
= palPtr
->logpalette
.palNumEntries
;
386 prevVer
= palPtr
->logpalette
.palVersion
;
387 prevsize
= sizeof(LOGPALETTE
) + (cPrevEnt
- 1) * sizeof(PALETTEENTRY
) +
388 sizeof(int*) + sizeof(GDIOBJHDR
);
389 size
+= sizeof(int*) + sizeof(GDIOBJHDR
);
391 if (!(palPtr
= GDI_ReallocObject( size
, hPal
, palPtr
))) return FALSE
;
393 PALETTE_UnrealizeObject( hPal
, palPtr
);
395 if( cEntries
> cPrevEnt
) memset( (BYTE
*)palPtr
+ prevsize
, 0, size
- prevsize
);
396 palPtr
->logpalette
.palNumEntries
= cEntries
;
397 palPtr
->logpalette
.palVersion
= prevVer
;
398 GDI_ReleaseObj( hPal
);
403 /***********************************************************************
404 * AnimatePalette [GDI32.@]
406 * Replaces entries in logical palette.
413 * Should use existing mapping when animating a primary palette
415 BOOL WINAPI
AnimatePalette(
416 HPALETTE hPal
, /* [in] Handle to logical palette */
417 UINT StartIndex
, /* [in] First entry in palette */
418 UINT NumEntries
, /* [in] Count of entries in palette */
419 const PALETTEENTRY
* PaletteColors
) /* [in] Pointer to first replacement */
421 TRACE("%p (%i - %i)\n", hPal
, StartIndex
,StartIndex
+NumEntries
);
423 if( hPal
!= GetStockObject(DEFAULT_PALETTE
) )
427 const PALETTEENTRY
*pptr
= PaletteColors
;
429 palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hPal
, PALETTE_MAGIC
);
430 if (!palPtr
) return 0;
432 pal_entries
= palPtr
->logpalette
.palNumEntries
;
433 if (StartIndex
>= pal_entries
)
435 GDI_ReleaseObj( hPal
);
438 if (StartIndex
+NumEntries
> pal_entries
) NumEntries
= pal_entries
- StartIndex
;
440 for (NumEntries
+= StartIndex
; StartIndex
< NumEntries
; StartIndex
++, pptr
++) {
441 /* According to MSDN, only animate PC_RESERVED colours */
442 if (palPtr
->logpalette
.palPalEntry
[StartIndex
].peFlags
& PC_RESERVED
) {
443 TRACE("Animating colour (%d,%d,%d) to (%d,%d,%d)\n",
444 palPtr
->logpalette
.palPalEntry
[StartIndex
].peRed
,
445 palPtr
->logpalette
.palPalEntry
[StartIndex
].peGreen
,
446 palPtr
->logpalette
.palPalEntry
[StartIndex
].peBlue
,
447 pptr
->peRed
, pptr
->peGreen
, pptr
->peBlue
);
448 memcpy( &palPtr
->logpalette
.palPalEntry
[StartIndex
], pptr
,
449 sizeof(PALETTEENTRY
) );
451 TRACE("Not animating entry %d -- not PC_RESERVED\n", StartIndex
);
454 if (palPtr
->funcs
&& palPtr
->funcs
->pRealizePalette
)
455 palPtr
->funcs
->pRealizePalette( NULL
, hPal
, hPal
== hPrimaryPalette
);
457 GDI_ReleaseObj( hPal
);
463 /***********************************************************************
464 * SetSystemPaletteUse [GDI32.@]
466 * Specify whether the system palette contains 2 or 20 static colors.
469 * Success: Previous system palette
470 * Failure: SYSPAL_ERROR
472 UINT WINAPI
SetSystemPaletteUse(
473 HDC hdc
, /* [in] Handle of device context */
474 UINT use
) /* [in] Palette-usage flag */
476 UINT old
= SystemPaletteUse
;
478 /* Device doesn't support colour palettes */
479 if (!(GetDeviceCaps(hdc
, RASTERCAPS
) & RC_PALETTE
)) {
484 case SYSPAL_NOSTATIC
:
485 case SYSPAL_NOSTATIC256
: /* WINVER >= 0x0500 */
487 SystemPaletteUse
= use
;
495 /***********************************************************************
496 * GetSystemPaletteUse [GDI32.@]
498 * Gets state of system palette.
501 * Current state of system palette
503 UINT WINAPI
GetSystemPaletteUse(
504 HDC hdc
) /* [in] Handle of device context */
506 return SystemPaletteUse
;
510 /***********************************************************************
511 * GetSystemPaletteEntries [GDI32.@]
513 * Gets range of palette entries.
516 * Success: Number of entries retrieved from palette
519 UINT WINAPI
GetSystemPaletteEntries(
520 HDC hdc
, /* [in] Handle of device context */
521 UINT start
, /* [in] Index of first entry to be retrieved */
522 UINT count
, /* [in] Number of entries to be retrieved */
523 LPPALETTEENTRY entries
) /* [out] Array receiving system-palette entries */
528 TRACE("hdc=%p,start=%i,count=%i\n", hdc
,start
,count
);
530 if ((dc
= DC_GetDCPtr( hdc
)))
532 if (dc
->funcs
->pGetSystemPaletteEntries
)
533 ret
= dc
->funcs
->pGetSystemPaletteEntries( dc
->physDev
, start
, count
, entries
);
534 GDI_ReleaseObj( hdc
);
540 /***********************************************************************
541 * GetNearestPaletteIndex [GDI32.@]
543 * Gets palette index for color.
546 * Should index be initialized to CLR_INVALID instead of 0?
549 * Success: Index of entry in logical palette
550 * Failure: CLR_INVALID
552 UINT WINAPI
GetNearestPaletteIndex(
553 HPALETTE hpalette
, /* [in] Handle of logical color palette */
554 COLORREF color
) /* [in] Color to be matched */
556 PALETTEOBJ
* palObj
= (PALETTEOBJ
*)GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
561 int i
, diff
= 0x7fffffff;
563 PALETTEENTRY
* entry
= palObj
->logpalette
.palPalEntry
;
565 for( i
= 0; i
< palObj
->logpalette
.palNumEntries
&& diff
; i
++, entry
++)
567 r
= entry
->peRed
- GetRValue(color
);
568 g
= entry
->peGreen
- GetGValue(color
);
569 b
= entry
->peBlue
- GetBValue(color
);
573 if( r
< diff
) { index
= i
; diff
= r
; }
575 GDI_ReleaseObj( hpalette
);
577 TRACE("(%p,%06x): returning %d\n", hpalette
, color
, index
);
582 /***********************************************************************
583 * GetNearestColor [GDI32.@]
585 * Gets a system color to match.
588 * Success: Color from system palette that corresponds to given color
589 * Failure: CLR_INVALID
591 COLORREF WINAPI
GetNearestColor(
592 HDC hdc
, /* [in] Handle of device context */
593 COLORREF color
) /* [in] Color to be matched */
595 unsigned char spec_type
;
599 if (!(dc
= DC_GetDCPtr( hdc
))) return CLR_INVALID
;
601 if (dc
->funcs
->pGetNearestColor
)
603 nearest
= dc
->funcs
->pGetNearestColor( dc
->physDev
, color
);
604 GDI_ReleaseObj( hdc
);
608 if (!(GetDeviceCaps(hdc
, RASTERCAPS
) & RC_PALETTE
))
610 GDI_ReleaseObj( hdc
);
614 spec_type
= color
>> 24;
615 if (spec_type
== 1 || spec_type
== 2)
617 /* we need logical palette for PALETTERGB and PALETTEINDEX colorrefs */
621 HPALETTE hpal
= dc
->hPalette
? dc
->hPalette
: GetStockObject( DEFAULT_PALETTE
);
623 if (spec_type
== 2) /* PALETTERGB */
624 index
= GetNearestPaletteIndex( hpal
, color
);
625 else /* PALETTEINDEX */
626 index
= LOWORD(color
);
628 if (!GetPaletteEntries( hpal
, index
, 1, &entry
))
630 WARN("RGB(%x) : idx %d is out of bounds, assuming NULL\n", color
, index
);
631 if (!GetPaletteEntries( hpal
, 0, 1, &entry
))
633 GDI_ReleaseObj( hdc
);
637 color
= RGB( entry
.peRed
, entry
.peGreen
, entry
.peBlue
);
639 nearest
= color
& 0x00ffffff;
640 GDI_ReleaseObj( hdc
);
642 TRACE("(%06x): returning %06x\n", color
, nearest
);
647 /***********************************************************************
650 static INT
PALETTE_GetObject( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
)
652 PALETTEOBJ
*palette
= obj
;
657 if (count
> sizeof(WORD
)) count
= sizeof(WORD
);
658 memcpy( buffer
, &palette
->logpalette
.palNumEntries
, count
);
663 /***********************************************************************
664 * PALETTE_UnrealizeObject
666 static BOOL
PALETTE_UnrealizeObject( HGDIOBJ handle
, void *obj
)
668 PALETTEOBJ
*palette
= obj
;
672 if (palette
->funcs
->pUnrealizePalette
)
673 palette
->funcs
->pUnrealizePalette( handle
);
674 palette
->funcs
= NULL
;
677 if (hLastRealizedPalette
== handle
)
679 TRACE("unrealizing palette %p\n", handle
);
680 hLastRealizedPalette
= 0;
686 /***********************************************************************
687 * PALETTE_DeleteObject
689 static BOOL
PALETTE_DeleteObject( HGDIOBJ handle
, void *obj
)
691 PALETTE_UnrealizeObject( handle
, obj
);
692 return GDI_FreeObject( handle
, obj
);
696 /***********************************************************************
697 * GDISelectPalette (Not a Windows API)
699 HPALETTE WINAPI
GDISelectPalette( HDC hdc
, HPALETTE hpal
, WORD wBkg
)
704 TRACE("%p %p\n", hdc
, hpal
);
706 if (GetObjectType(hpal
) != OBJ_PAL
)
708 WARN("invalid selected palette %p\n",hpal
);
711 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
713 if (dc
->funcs
->pSelectPalette
) hpal
= dc
->funcs
->pSelectPalette( dc
->physDev
, hpal
, FALSE
);
717 if (!wBkg
) hPrimaryPalette
= hpal
;
720 GDI_ReleaseObj( hdc
);
725 /***********************************************************************
726 * GDIRealizePalette (Not a Windows API)
728 UINT WINAPI
GDIRealizePalette( HDC hdc
)
731 DC
* dc
= DC_GetDCPtr( hdc
);
735 TRACE("%p...\n", hdc
);
737 if( dc
->hPalette
== GetStockObject( DEFAULT_PALETTE
))
739 if (dc
->funcs
->pRealizeDefaultPalette
)
740 realized
= dc
->funcs
->pRealizeDefaultPalette( dc
->physDev
);
742 else if(dc
->hPalette
!= hLastRealizedPalette
)
744 if (dc
->funcs
->pRealizePalette
)
746 PALETTEOBJ
*palPtr
= GDI_GetObjPtr( dc
->hPalette
, PALETTE_MAGIC
);
749 realized
= dc
->funcs
->pRealizePalette( dc
->physDev
, dc
->hPalette
,
750 (dc
->hPalette
== hPrimaryPalette
) );
751 palPtr
->funcs
= dc
->funcs
;
752 GDI_ReleaseObj( dc
->hPalette
);
755 hLastRealizedPalette
= dc
->hPalette
;
757 else TRACE(" skipping (hLastRealizedPalette = %p)\n", hLastRealizedPalette
);
759 GDI_ReleaseObj( hdc
);
760 TRACE(" realized %i colors.\n", realized
);
765 /***********************************************************************
766 * RealizeDefaultPalette (GDI.365)
768 UINT16 WINAPI
RealizeDefaultPalette16( HDC16 hdc
)
773 TRACE("%04x\n", hdc
);
775 if (!(dc
= DC_GetDCPtr( HDC_32(hdc
) ))) return 0;
777 if (dc
->funcs
->pRealizeDefaultPalette
) ret
= dc
->funcs
->pRealizeDefaultPalette( dc
->physDev
);
778 GDI_ReleaseObj( HDC_32(hdc
) );
782 /***********************************************************************
783 * IsDCCurrentPalette (GDI.412)
785 BOOL16 WINAPI
IsDCCurrentPalette16(HDC16 hDC
)
787 DC
*dc
= DC_GetDCPtr( HDC_32(hDC
) );
790 BOOL bRet
= dc
->hPalette
== hPrimaryPalette
;
791 GDI_ReleaseObj( HDC_32(hDC
) );
798 /***********************************************************************
799 * SelectPalette [GDI32.@]
801 * Selects logical palette into DC.
804 * Success: Previous logical palette
807 HPALETTE WINAPI
SelectPalette(
808 HDC hDC
, /* [in] Handle of device context */
809 HPALETTE hPal
, /* [in] Handle of logical color palette */
810 BOOL bForceBackground
) /* [in] Foreground/background mode */
812 return pfnSelectPalette( hDC
, hPal
, bForceBackground
);
816 /***********************************************************************
817 * RealizePalette [GDI32.@]
819 * Maps palette entries to system palette.
822 * Success: Number of entries in logical palette
825 UINT WINAPI
RealizePalette(
826 HDC hDC
) /* [in] Handle of device context */
828 return pfnRealizePalette( hDC
);
832 typedef HWND (WINAPI
*WindowFromDC_funcptr
)( HDC
);
833 typedef BOOL (WINAPI
*RedrawWindow_funcptr
)( HWND
, const RECT
*, HRGN
, UINT
);
835 /**********************************************************************
836 * UpdateColors [GDI32.@]
838 * Remaps current colors to logical palette.
844 BOOL WINAPI
UpdateColors(
845 HDC hDC
) /* [in] Handle of device context */
848 int size
= GetDeviceCaps( hDC
, SIZEPALETTE
);
852 mod
= GetModuleHandleA("user32.dll");
855 WindowFromDC_funcptr pWindowFromDC
= (WindowFromDC_funcptr
)GetProcAddress(mod
,"WindowFromDC");
858 HWND hWnd
= pWindowFromDC( hDC
);
860 /* Docs say that we have to remap current drawable pixel by pixel
861 * but it would take forever given the speed of XGet/PutPixel.
865 RedrawWindow_funcptr pRedrawWindow
= GetProcAddress( mod
, "RedrawWindow" );
866 if (pRedrawWindow
) pRedrawWindow( hWnd
, NULL
, 0, RDW_INVALIDATE
);
874 /*********************************************************************
875 * SetMagicColors (GDI.606)
877 VOID WINAPI
SetMagicColors16(HDC16 hDC
, COLORREF color
, UINT16 index
)
879 FIXME("(hDC %04x, color %04x, index %04x): stub\n", hDC
, (int)color
, index
);
883 /*********************************************************************
884 * SetMagicColors (GDI.@)
886 BOOL WINAPI
SetMagicColors(HDC hdc
, ULONG u1
, ULONG u2
)
888 FIXME("(%p 0x%08x 0x%08x): stub\n", hdc
, u1
, u2
);
892 /**********************************************************************
893 * GetICMProfileA [GDI32.@]
895 * Returns the filename of the specified device context's color
896 * management profile, even if color management is not enabled
900 * TRUE if name copied successfully OR lpszFilename is NULL
901 * FALSE if the buffer length pointed to by lpcbName is too small
904 * The buffer length pointed to by lpcbName is ALWAYS updated to
905 * the length required regardless of other actions this function
909 * How does Windows assign these? Some registry key?
913 /*********************************************************************/
915 BOOL WINAPI
GetICMProfileA(HDC hDC
, LPDWORD lpcbName
, LPSTR lpszFilename
)
918 static const char icm
[] = "winefake.icm";
920 FIXME("(%p, %p, %p): partial stub\n", hDC
, lpcbName
, lpszFilename
);
922 callerLen
= *lpcbName
;
924 /* all 3 behaviors require the required buffer size to be set */
925 *lpcbName
= sizeof(icm
);
927 /* behavior 1: if lpszFilename is NULL, return size of string and no error */
928 if (!lpszFilename
) return TRUE
;
930 /* behavior 2: if buffer size too small, return size of string and error */
931 if (callerLen
< sizeof(icm
))
933 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
937 /* behavior 3: if buffer size OK and pointer not NULL, copy and return size */
938 memcpy(lpszFilename
, icm
, sizeof(icm
));
942 /**********************************************************************
943 * GetICMProfileW [GDI32.@]
945 BOOL WINAPI
GetICMProfileW(HDC hDC
, LPDWORD lpcbName
, LPWSTR lpszFilename
)
948 static const WCHAR icm
[] = { 'w','i','n','e','f','a','k','e','.','i','c','m', 0 };
950 FIXME("(%p, %p, %p): partial stub\n", hDC
, lpcbName
, lpszFilename
);
952 callerLen
= *lpcbName
;
954 /* all 3 behaviors require the required buffer size to be set */
955 *lpcbName
= sizeof(icm
) / sizeof(WCHAR
);
957 /* behavior 1: if lpszFilename is NULL, return size of string and no error */
958 if (!lpszFilename
) return TRUE
;
960 /* behavior 2: if buffer size too small, return size of string and error */
961 if (callerLen
< sizeof(icm
)/sizeof(WCHAR
))
963 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
967 /* behavior 3: if buffer size OK and pointer not NULL, copy and return size */
968 memcpy(lpszFilename
, icm
, sizeof(icm
));
972 /**********************************************************************
973 * GetLogColorSpaceA [GDI32.@]
976 BOOL WINAPI
GetLogColorSpaceA(HCOLORSPACE hColorSpace
, LPLOGCOLORSPACEA lpBuffer
, DWORD nSize
)
978 FIXME("%p %p 0x%08x: stub!\n", hColorSpace
, lpBuffer
, nSize
);
982 /**********************************************************************
983 * GetLogColorSpaceW [GDI32.@]
986 BOOL WINAPI
GetLogColorSpaceW(HCOLORSPACE hColorSpace
, LPLOGCOLORSPACEW lpBuffer
, DWORD nSize
)
988 FIXME("%p %p 0x%08x: stub!\n", hColorSpace
, lpBuffer
, nSize
);
992 /**********************************************************************
993 * SetICMProfileA [GDI32.@]
996 BOOL WINAPI
SetICMProfileA(HDC hDC
, LPSTR lpszFilename
)
998 FIXME("hDC %p filename %s: stub!\n", hDC
, debugstr_a(lpszFilename
));
999 return TRUE
; /* success */
1002 /**********************************************************************
1003 * SetICMProfileA [GDI32.@]
1006 BOOL WINAPI
SetICMProfileW(HDC hDC
, LPWSTR lpszFilename
)
1008 FIXME("hDC %p filename %s: stub!\n", hDC
, debugstr_w(lpszFilename
));
1009 return TRUE
; /* success */
1012 /**********************************************************************
1013 * UpdateICMRegKeyA [GDI32.@]
1016 BOOL WINAPI
UpdateICMRegKeyA(DWORD dwReserved
, LPSTR lpszCMID
, LPSTR lpszFileName
, UINT nCommand
)
1018 FIXME("(0x%08x, %s, %s, 0x%08x): stub!\n", dwReserved
, debugstr_a(lpszCMID
),
1019 debugstr_a(lpszFileName
), nCommand
);
1020 return TRUE
; /* success */
1023 /**********************************************************************
1024 * UpdateICMRegKeyW [GDI32.@]
1027 BOOL WINAPI
UpdateICMRegKeyW(DWORD dwReserved
, LPWSTR lpszCMID
, LPWSTR lpszFileName
, UINT nCommand
)
1029 FIXME("(0x%08x, %s, %s, 0x%08x): stub!\n", dwReserved
, debugstr_w(lpszCMID
),
1030 debugstr_w(lpszFileName
), nCommand
);
1031 return TRUE
; /* success */