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.
33 #include "wine/winuser16.h"
36 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(palette
);
41 static INT
PALETTE_GetObject( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
);
42 static BOOL
PALETTE_UnrealizeObject( HGDIOBJ handle
, void *obj
);
43 static BOOL
PALETTE_DeleteObject( HGDIOBJ handle
, void *obj
);
45 static const struct gdi_obj_funcs palette_funcs
=
47 NULL
, /* pSelectObject */
48 PALETTE_GetObject
, /* pGetObject16 */
49 PALETTE_GetObject
, /* pGetObjectA */
50 PALETTE_GetObject
, /* pGetObjectW */
51 PALETTE_UnrealizeObject
, /* pUnrealizeObject */
52 PALETTE_DeleteObject
/* pDeleteObject */
55 /* Pointers to USER implementation of SelectPalette/RealizePalette */
56 /* they will be patched by USER on startup */
57 HPALETTE (WINAPI
*pfnSelectPalette
)(HDC hdc
, HPALETTE hpal
, WORD bkgnd
) = GDISelectPalette
;
58 UINT (WINAPI
*pfnRealizePalette
)(HDC hdc
) = GDIRealizePalette
;
60 static UINT SystemPaletteUse
= SYSPAL_STATIC
; /* currently not considered */
62 static HPALETTE hPrimaryPalette
= 0; /* used for WM_PALETTECHANGED */
63 static HPALETTE hLastRealizedPalette
= 0; /* UnrealizeObject() needs it */
64 static const DC_FUNCTIONS
*pLastRealizedDC
;
66 static const PALETTEENTRY sys_pal_template
[NB_RESERVED_COLORS
] =
68 /* first 10 entries in the system palette */
69 /* red green blue flags */
70 { 0x00, 0x00, 0x00, 0 },
71 { 0x80, 0x00, 0x00, 0 },
72 { 0x00, 0x80, 0x00, 0 },
73 { 0x80, 0x80, 0x00, 0 },
74 { 0x00, 0x00, 0x80, 0 },
75 { 0x80, 0x00, 0x80, 0 },
76 { 0x00, 0x80, 0x80, 0 },
77 { 0xc0, 0xc0, 0xc0, 0 },
78 { 0xc0, 0xdc, 0xc0, 0 },
79 { 0xa6, 0xca, 0xf0, 0 },
81 /* ... c_min/2 dynamic colorcells */
83 /* ... gap (for sparse palettes) */
85 /* ... c_min/2 dynamic colorcells */
87 { 0xff, 0xfb, 0xf0, 0 },
88 { 0xa0, 0xa0, 0xa4, 0 },
89 { 0x80, 0x80, 0x80, 0 },
90 { 0xff, 0x00, 0x00, 0 },
91 { 0x00, 0xff, 0x00, 0 },
92 { 0xff, 0xff, 0x00, 0 },
93 { 0x00, 0x00, 0xff, 0 },
94 { 0xff, 0x00, 0xff, 0 },
95 { 0x00, 0xff, 0xff, 0 },
96 { 0xff, 0xff, 0xff, 0 } /* last 10 */
99 /***********************************************************************
102 * Create the system palette.
104 HPALETTE
PALETTE_Init(void)
110 /* create default palette (20 system colors) */
112 palPtr
= HeapAlloc( GetProcessHeap(), 0,
113 sizeof(LOGPALETTE
) + (NB_RESERVED_COLORS
-1)*sizeof(PALETTEENTRY
));
114 if (!palPtr
) return FALSE
;
116 palPtr
->palVersion
= 0x300;
117 palPtr
->palNumEntries
= NB_RESERVED_COLORS
;
118 memcpy( palPtr
->palPalEntry
, sys_pal_template
, sizeof(sys_pal_template
) );
119 hpalette
= CreatePalette( palPtr
);
120 HeapFree( GetProcessHeap(), 0, palPtr
);
122 palObj
= (PALETTEOBJ
*) GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
125 if (!(palObj
->mapping
= HeapAlloc( GetProcessHeap(), 0, sizeof(int) * NB_RESERVED_COLORS
)))
126 ERR("Can not create palette mapping -- out of memory!\n");
127 GDI_ReleaseObj( hpalette
);
132 /***********************************************************************
133 * PALETTE_ValidateFlags
135 static void PALETTE_ValidateFlags(PALETTEENTRY
* lpPalE
, int size
)
138 for( ; i
<size
; i
++ )
139 lpPalE
[i
].peFlags
= PC_SYS_USED
| (lpPalE
[i
].peFlags
& 0x07);
143 /***********************************************************************
144 * CreatePalette [GDI32.@] Creates a logical color palette
147 * Success: Handle to logical palette
150 HPALETTE WINAPI
CreatePalette(
151 const LOGPALETTE
* palette
) /* [in] Pointer to logical color palette */
153 PALETTEOBJ
* palettePtr
;
157 if (!palette
) return 0;
158 TRACE("entries=%i\n", palette
->palNumEntries
);
160 size
= sizeof(LOGPALETTE
) + (palette
->palNumEntries
- 1) * sizeof(PALETTEENTRY
);
162 if (!(palettePtr
= GDI_AllocObject( size
+ sizeof(int*) +sizeof(GDIOBJHDR
),
163 PALETTE_MAGIC
, (HGDIOBJ
*)&hpalette
,
164 &palette_funcs
))) return 0;
165 memcpy( &palettePtr
->logpalette
, palette
, size
);
166 PALETTE_ValidateFlags(palettePtr
->logpalette
.palPalEntry
,
167 palettePtr
->logpalette
.palNumEntries
);
168 palettePtr
->mapping
= NULL
;
169 GDI_ReleaseObj( hpalette
);
171 TRACE(" returning %p\n", hpalette
);
176 /***********************************************************************
177 * CreateHalftonePalette [GDI32.@] Creates a halftone palette
180 * Success: Handle to logical halftone palette
183 * FIXME: This simply creates the halftone palette dirived from runing
184 * tests on an windows NT machine. this is assuming a color depth
185 * of greater that 256 color. On a 256 color device the halftone
186 * palette will be differnt and this funtion will be incorrect
188 HPALETTE WINAPI
CreateHalftonePalette(
189 HDC hdc
) /* [in] Handle to device context */
194 WORD NumberOfEntries
;
195 PALETTEENTRY aEntries
[256];
198 Palette
.Version
= 0x300;
199 Palette
.NumberOfEntries
= 256;
200 GetSystemPaletteEntries(hdc
, 0, 256, Palette
.aEntries
);
202 Palette
.NumberOfEntries
= 20;
204 for (i
= 0; i
< Palette
.NumberOfEntries
; i
++)
206 Palette
.aEntries
[i
].peRed
=0xff;
207 Palette
.aEntries
[i
].peGreen
=0xff;
208 Palette
.aEntries
[i
].peBlue
=0xff;
209 Palette
.aEntries
[i
].peFlags
=0x00;
212 Palette
.aEntries
[0].peRed
=0x00;
213 Palette
.aEntries
[0].peBlue
=0x00;
214 Palette
.aEntries
[0].peGreen
=0x00;
217 for (i
=1; i
<= 6; i
++)
219 Palette
.aEntries
[i
].peRed
=(i
%2)?0x80:0;
220 Palette
.aEntries
[i
].peGreen
=(i
==2)?0x80:(i
==3)?0x80:(i
==6)?0x80:0;
221 Palette
.aEntries
[i
].peBlue
=(i
>3)?0x80:0;
224 for (i
=7; i
<= 12; i
++)
229 Palette
.aEntries
[i
].peRed
=0xc0;
230 Palette
.aEntries
[i
].peBlue
=0xc0;
231 Palette
.aEntries
[i
].peGreen
=0xc0;
234 Palette
.aEntries
[i
].peRed
=0xc0;
235 Palette
.aEntries
[i
].peGreen
=0xdc;
236 Palette
.aEntries
[i
].peBlue
=0xc0;
239 Palette
.aEntries
[i
].peRed
=0xa6;
240 Palette
.aEntries
[i
].peGreen
=0xca;
241 Palette
.aEntries
[i
].peBlue
=0xf0;
244 Palette
.aEntries
[i
].peRed
=0xff;
245 Palette
.aEntries
[i
].peGreen
=0xfb;
246 Palette
.aEntries
[i
].peBlue
=0xf0;
249 Palette
.aEntries
[i
].peRed
=0xa0;
250 Palette
.aEntries
[i
].peGreen
=0xa0;
251 Palette
.aEntries
[i
].peBlue
=0xa4;
254 Palette
.aEntries
[i
].peRed
=0x80;
255 Palette
.aEntries
[i
].peGreen
=0x80;
256 Palette
.aEntries
[i
].peBlue
=0x80;
260 for (i
=13; i
<= 18; i
++)
262 Palette
.aEntries
[i
].peRed
=(i
%2)?0xff:0;
263 Palette
.aEntries
[i
].peGreen
=(i
==14)?0xff:(i
==15)?0xff:(i
==18)?0xff:0;
264 Palette
.aEntries
[i
].peBlue
=(i
>15)?0xff:0x00;
267 return CreatePalette((LOGPALETTE
*)&Palette
);
271 /***********************************************************************
272 * GetPaletteEntries [GDI32.@] Retrieves palette entries
275 * Success: Number of entries from logical palette
278 UINT WINAPI
GetPaletteEntries(
279 HPALETTE hpalette
, /* [in] Handle of logical palette */
280 UINT start
, /* [in] First entry to receive */
281 UINT count
, /* [in] Number of entries to receive */
282 LPPALETTEENTRY entries
) /* [out] Address of array receiving entries */
287 TRACE("hpal = %p, count=%i\n", hpalette
, count
);
289 palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
290 if (!palPtr
) return 0;
292 /* NOTE: not documented but test show this to be the case */
295 int rc
= palPtr
->logpalette
.palNumEntries
;
296 GDI_ReleaseObj( hpalette
);
300 numEntries
= palPtr
->logpalette
.palNumEntries
;
301 if (start
+count
> numEntries
) count
= numEntries
- start
;
304 if (start
>= numEntries
)
306 GDI_ReleaseObj( hpalette
);
309 memcpy( entries
, &palPtr
->logpalette
.palPalEntry
[start
],
310 count
* sizeof(PALETTEENTRY
) );
311 for( numEntries
= 0; numEntries
< count
; numEntries
++ )
312 if (entries
[numEntries
].peFlags
& 0xF0)
313 entries
[numEntries
].peFlags
= 0;
316 GDI_ReleaseObj( hpalette
);
321 /***********************************************************************
322 * SetPaletteEntries [GDI32.@] Sets color values for range in palette
325 * Success: Number of entries that were set
328 UINT WINAPI
SetPaletteEntries(
329 HPALETTE hpalette
, /* [in] Handle of logical palette */
330 UINT start
, /* [in] Index of first entry to set */
331 UINT count
, /* [in] Number of entries to set */
332 const PALETTEENTRY
*entries
) /* [in] Address of array of structures */
337 TRACE("hpal=%p,start=%i,count=%i\n",hpalette
,start
,count
);
339 if (hpalette
== GetStockObject(DEFAULT_PALETTE
)) return 0;
340 palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
341 if (!palPtr
) return 0;
343 numEntries
= palPtr
->logpalette
.palNumEntries
;
344 if (start
>= numEntries
)
346 GDI_ReleaseObj( hpalette
);
349 if (start
+count
> numEntries
) count
= numEntries
- start
;
350 memcpy( &palPtr
->logpalette
.palPalEntry
[start
], entries
,
351 count
* sizeof(PALETTEENTRY
) );
352 PALETTE_ValidateFlags(palPtr
->logpalette
.palPalEntry
,
353 palPtr
->logpalette
.palNumEntries
);
354 UnrealizeObject( hpalette
);
355 GDI_ReleaseObj( hpalette
);
360 /***********************************************************************
361 * ResizePalette [GDI32.@] Resizes logical palette
367 BOOL WINAPI
ResizePalette(
368 HPALETTE hPal
, /* [in] Handle of logical palette */
369 UINT cEntries
) /* [in] Number of entries in logical palette */
371 PALETTEOBJ
* palPtr
= (PALETTEOBJ
*) GDI_GetObjPtr( hPal
, PALETTE_MAGIC
);
372 UINT cPrevEnt
, prevVer
;
373 int prevsize
, size
= sizeof(LOGPALETTE
) + (cEntries
- 1) * sizeof(PALETTEENTRY
);
376 TRACE("hpal = %p, prev = %i, new = %i\n",
377 hPal
, palPtr
? palPtr
->logpalette
.palNumEntries
: -1, cEntries
);
378 if( !palPtr
) return FALSE
;
379 cPrevEnt
= palPtr
->logpalette
.palNumEntries
;
380 prevVer
= palPtr
->logpalette
.palVersion
;
381 prevsize
= sizeof(LOGPALETTE
) + (cPrevEnt
- 1) * sizeof(PALETTEENTRY
) +
382 sizeof(int*) + sizeof(GDIOBJHDR
);
383 size
+= sizeof(int*) + sizeof(GDIOBJHDR
);
384 mapping
= palPtr
->mapping
;
386 if (!(palPtr
= GDI_ReallocObject( size
, hPal
, palPtr
))) return FALSE
;
390 int *newMap
= (int*) HeapReAlloc(GetProcessHeap(), 0,
391 mapping
, cEntries
* sizeof(int) );
394 ERR("Can not resize mapping -- out of memory!\n");
395 GDI_ReleaseObj( hPal
);
398 palPtr
->mapping
= newMap
;
401 if( cEntries
> cPrevEnt
)
404 memset(palPtr
->mapping
+ cPrevEnt
, 0, (cEntries
- cPrevEnt
)*sizeof(int));
405 memset( (BYTE
*)palPtr
+ prevsize
, 0, size
- prevsize
);
406 PALETTE_ValidateFlags((PALETTEENTRY
*)((BYTE
*)palPtr
+ prevsize
),
407 cEntries
- cPrevEnt
);
409 palPtr
->logpalette
.palNumEntries
= cEntries
;
410 palPtr
->logpalette
.palVersion
= prevVer
;
411 GDI_ReleaseObj( hPal
);
416 /***********************************************************************
417 * AnimatePalette [GDI32.@] Replaces entries in logical palette
424 * Should use existing mapping when animating a primary palette
426 BOOL WINAPI
AnimatePalette(
427 HPALETTE hPal
, /* [in] Handle to logical palette */
428 UINT StartIndex
, /* [in] First entry in palette */
429 UINT NumEntries
, /* [in] Count of entries in palette */
430 const PALETTEENTRY
* PaletteColors
) /* [in] Pointer to first replacement */
432 TRACE("%p (%i - %i)\n", hPal
, StartIndex
,StartIndex
+NumEntries
);
434 if( hPal
!= GetStockObject(DEFAULT_PALETTE
) )
436 if (!SetPaletteEntries( hPal
, StartIndex
, NumEntries
, PaletteColors
)) return FALSE
;
438 if (pLastRealizedDC
&& pLastRealizedDC
->pRealizePalette
)
439 pLastRealizedDC
->pRealizePalette( NULL
, hPal
, hPal
== hPrimaryPalette
);
445 /***********************************************************************
446 * SetSystemPaletteUse [GDI32.@]
449 * Success: Previous system palette
450 * Failure: SYSPAL_ERROR
452 UINT WINAPI
SetSystemPaletteUse(
453 HDC hdc
, /* [in] Handle of device context */
454 UINT use
) /* [in] Palette-usage flag */
456 UINT old
= SystemPaletteUse
;
457 FIXME("(%p,%04x): stub\n", hdc
, use
);
458 SystemPaletteUse
= use
;
463 /***********************************************************************
464 * GetSystemPaletteUse [GDI32.@] Gets state of system palette
467 * Current state of system palette
469 UINT WINAPI
GetSystemPaletteUse(
470 HDC hdc
) /* [in] Handle of device context */
472 return SystemPaletteUse
;
476 /***********************************************************************
477 * GetSystemPaletteEntries [GDI32.@] Gets range of palette entries
480 * Success: Number of entries retrieved from palette
483 UINT WINAPI
GetSystemPaletteEntries(
484 HDC hdc
, /* [in] Handle of device context */
485 UINT start
, /* [in] Index of first entry to be retrieved */
486 UINT count
, /* [in] Number of entries to be retrieved */
487 LPPALETTEENTRY entries
) /* [out] Array receiving system-palette entries */
492 TRACE("hdc=%p,start=%i,count=%i\n", hdc
,start
,count
);
494 if ((dc
= DC_GetDCPtr( hdc
)))
496 if (dc
->funcs
->pGetSystemPaletteEntries
)
497 ret
= dc
->funcs
->pGetSystemPaletteEntries( dc
->physDev
, start
, count
, entries
);
498 GDI_ReleaseObj( hdc
);
504 /***********************************************************************
505 * GetNearestPaletteIndex [GDI32.@] Gets palette index for color
508 * Should index be initialized to CLR_INVALID instead of 0?
511 * Success: Index of entry in logical palette
512 * Failure: CLR_INVALID
514 UINT WINAPI
GetNearestPaletteIndex(
515 HPALETTE hpalette
, /* [in] Handle of logical color palette */
516 COLORREF color
) /* [in] Color to be matched */
518 PALETTEOBJ
* palObj
= (PALETTEOBJ
*)GDI_GetObjPtr( hpalette
, PALETTE_MAGIC
);
523 int i
, diff
= 0x7fffffff;
525 PALETTEENTRY
* entry
= palObj
->logpalette
.palPalEntry
;
527 for( i
= 0; i
< palObj
->logpalette
.palNumEntries
&& diff
; i
++, entry
++)
529 if (!(entry
->peFlags
& PC_SYS_USED
)) continue;
531 r
= entry
->peRed
- GetRValue(color
);
532 g
= entry
->peGreen
- GetGValue(color
);
533 b
= entry
->peBlue
- GetBValue(color
);
537 if( r
< diff
) { index
= i
; diff
= r
; }
539 GDI_ReleaseObj( hpalette
);
541 TRACE("(%p,%06lx): returning %d\n", hpalette
, color
, index
);
546 /***********************************************************************
547 * GetNearestColor [GDI32.@] Gets a system color to match
550 * Success: Color from system palette that corresponds to given color
551 * Failure: CLR_INVALID
553 COLORREF WINAPI
GetNearestColor(
554 HDC hdc
, /* [in] Handle of device context */
555 COLORREF color
) /* [in] Color to be matched */
557 unsigned char spec_type
;
561 if (!(dc
= DC_GetDCPtr( hdc
))) return CLR_INVALID
;
563 if (dc
->funcs
->pGetNearestColor
)
565 nearest
= dc
->funcs
->pGetNearestColor( dc
->physDev
, color
);
566 GDI_ReleaseObj( hdc
);
570 if (!(GetDeviceCaps(hdc
, RASTERCAPS
) & RC_PALETTE
))
572 GDI_ReleaseObj( hdc
);
576 spec_type
= color
>> 24;
577 if (spec_type
== 1 || spec_type
== 2)
579 /* we need logical palette for PALETTERGB and PALETTEINDEX colorrefs */
583 HPALETTE hpal
= dc
->hPalette
? dc
->hPalette
: GetStockObject( DEFAULT_PALETTE
);
585 if (spec_type
== 2) /* PALETTERGB */
586 index
= GetNearestPaletteIndex( hpal
, color
);
587 else /* PALETTEINDEX */
588 index
= LOWORD(color
);
590 if (!GetPaletteEntries( hpal
, index
, 1, &entry
))
592 WARN("RGB(%lx) : idx %d is out of bounds, assuming NULL\n", color
, index
);
593 if (!GetPaletteEntries( hpal
, 0, 1, &entry
))
595 GDI_ReleaseObj( hdc
);
599 color
= RGB( entry
.peRed
, entry
.peGreen
, entry
.peBlue
);
601 nearest
= color
& 0x00ffffff;
602 GDI_ReleaseObj( hdc
);
604 TRACE("(%06lx): returning %06lx\n", color
, nearest
);
609 /***********************************************************************
612 static INT
PALETTE_GetObject( HGDIOBJ handle
, void *obj
, INT count
, LPVOID buffer
)
614 PALETTEOBJ
*palette
= obj
;
616 if (count
> sizeof(WORD
)) count
= sizeof(WORD
);
617 memcpy( buffer
, &palette
->logpalette
.palNumEntries
, count
);
622 /***********************************************************************
623 * PALETTE_UnrealizeObject
625 static BOOL
PALETTE_UnrealizeObject( HGDIOBJ handle
, void *obj
)
627 PALETTEOBJ
*palette
= obj
;
629 if (palette
->mapping
)
631 HeapFree( GetProcessHeap(), 0, palette
->mapping
);
632 palette
->mapping
= NULL
;
634 if (hLastRealizedPalette
== handle
)
636 hLastRealizedPalette
= 0;
637 pLastRealizedDC
= NULL
;
643 /***********************************************************************
644 * PALETTE_DeleteObject
646 static BOOL
PALETTE_DeleteObject( HGDIOBJ handle
, void *obj
)
648 PALETTEOBJ
*palette
= obj
;
650 HeapFree( GetProcessHeap(), 0, palette
->mapping
);
651 if (hLastRealizedPalette
== handle
)
653 hLastRealizedPalette
= 0;
654 pLastRealizedDC
= NULL
;
656 return GDI_FreeObject( handle
, obj
);
660 /***********************************************************************
661 * GDISelectPalette (Not a Windows API)
663 HPALETTE WINAPI
GDISelectPalette( HDC hdc
, HPALETTE hpal
, WORD wBkg
)
668 TRACE("%p %p\n", hdc
, hpal
);
670 if (GetObjectType(hpal
) != OBJ_PAL
)
672 WARN("invalid selected palette %p\n",hpal
);
675 if (!(dc
= DC_GetDCPtr( hdc
))) return 0;
678 GDI_ReleaseObj( hdc
);
679 if (!wBkg
) hPrimaryPalette
= hpal
;
684 /***********************************************************************
685 * GDIRealizePalette (Not a Windows API)
687 UINT WINAPI
GDIRealizePalette( HDC hdc
)
690 DC
* dc
= DC_GetDCPtr( hdc
);
694 TRACE("%p...\n", hdc
);
696 if( dc
->hPalette
== GetStockObject( DEFAULT_PALETTE
))
698 if (dc
->funcs
->pRealizeDefaultPalette
)
699 realized
= dc
->funcs
->pRealizeDefaultPalette( dc
->physDev
);
701 else if(dc
->hPalette
!= hLastRealizedPalette
)
703 if (dc
->funcs
->pRealizePalette
)
704 realized
= dc
->funcs
->pRealizePalette( dc
->physDev
, dc
->hPalette
,
705 (dc
->hPalette
== hPrimaryPalette
) );
706 hLastRealizedPalette
= dc
->hPalette
;
707 pLastRealizedDC
= dc
->funcs
;
709 else TRACE(" skipping (hLastRealizedPalette = %p)\n", hLastRealizedPalette
);
711 GDI_ReleaseObj( hdc
);
712 TRACE(" realized %i colors.\n", realized
);
717 /***********************************************************************
718 * RealizeDefaultPalette (GDI.365)
720 UINT16 WINAPI
RealizeDefaultPalette16( HDC16 hdc
)
725 TRACE("%04x\n", hdc
);
727 if (!(dc
= DC_GetDCPtr( HDC_32(hdc
) ))) return 0;
729 if (dc
->funcs
->pRealizeDefaultPalette
) ret
= dc
->funcs
->pRealizeDefaultPalette( dc
->physDev
);
730 GDI_ReleaseObj( HDC_32(hdc
) );
734 /***********************************************************************
735 * IsDCCurrentPalette (GDI.412)
737 BOOL16 WINAPI
IsDCCurrentPalette16(HDC16 hDC
)
739 DC
*dc
= DC_GetDCPtr( HDC_32(hDC
) );
742 BOOL bRet
= dc
->hPalette
== hPrimaryPalette
;
743 GDI_ReleaseObj( HDC_32(hDC
) );
750 /***********************************************************************
751 * SelectPalette [GDI32.@] Selects logical palette into DC
754 * Success: Previous logical palette
757 HPALETTE WINAPI
SelectPalette(
758 HDC hDC
, /* [in] Handle of device context */
759 HPALETTE hPal
, /* [in] Handle of logical color palette */
760 BOOL bForceBackground
) /* [in] Foreground/background mode */
762 return pfnSelectPalette( hDC
, hPal
, bForceBackground
);
766 /***********************************************************************
767 * RealizePalette [GDI32.@] Maps palette entries to system palette
770 * Success: Number of entries in logical palette
773 UINT WINAPI
RealizePalette(
774 HDC hDC
) /* [in] Handle of device context */
776 return pfnRealizePalette( hDC
);
780 typedef HWND (WINAPI
*WindowFromDC_funcptr
)( HDC
);
781 typedef BOOL (WINAPI
*RedrawWindow_funcptr
)( HWND
, const RECT
*, HRGN
, UINT
);
783 /**********************************************************************
784 * UpdateColors [GDI32.@] Remaps current colors to logical palette
790 BOOL WINAPI
UpdateColors(
791 HDC hDC
) /* [in] Handle of device context */
794 int size
= GetDeviceCaps( hDC
, SIZEPALETTE
);
798 mod
= GetModuleHandleA("user32.dll");
801 WindowFromDC_funcptr pWindowFromDC
= (WindowFromDC_funcptr
)GetProcAddress(mod
,"WindowFromDC");
804 HWND hWnd
= pWindowFromDC( hDC
);
806 /* Docs say that we have to remap current drawable pixel by pixel
807 * but it would take forever given the speed of XGet/PutPixel.
811 RedrawWindow_funcptr pRedrawWindow
= GetProcAddress( mod
, "RedrawWindow" );
812 if (pRedrawWindow
) pRedrawWindow( hWnd
, NULL
, 0, RDW_INVALIDATE
);
820 /*********************************************************************
821 * SetMagicColors (GDI.606)
823 VOID WINAPI
SetMagicColors16(HDC16 hDC
, COLORREF color
, UINT16 index
)
825 FIXME("(hDC %04x, color %04x, index %04x): stub\n", hDC
, (int)color
, index
);
829 /**********************************************************************
830 * GetICMProfileA [GDI32.@]
832 * Returns the filename of the specified device context's color
833 * management profile, even if color management is not enabled
837 * TRUE if name copied succesfully OR lpszFilename is NULL
838 * FALSE if the buffer length pointed to by lpcbName is too small
841 * The buffer length pointed to by lpcbName is ALWAYS updated to
842 * the length required regardless of other actions this function
846 * How does Windows assign these? Some registry key?
849 #define WINEICM "winefake.icm" /* easy-to-identify fake filename */
851 /*********************************************************************/
853 BOOL WINAPI
GetICMProfileA(HDC hDC
, LPDWORD lpcbName
, LPSTR lpszFilename
)
857 FIXME("(%p, %p, %p): partial stub\n", hDC
, lpcbName
, lpszFilename
);
859 callerLen
= *lpcbName
;
861 /* all 3 behaviors require the required buffer size to be set */
862 *lpcbName
= strlen(WINEICM
);
864 /* behavior 1: if lpszFilename is NULL, return size of string and no error */
865 if ((DWORD
)lpszFilename
== (DWORD
)0x00000000)
868 /* behavior 2: if buffer size too small, return size of string and error */
869 if (callerLen
< strlen(WINEICM
))
871 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
875 /* behavior 3: if buffer size OK and pointer not NULL, copy and return size */
876 strcpy(lpszFilename
, WINEICM
);