Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * GDI palette objects |
| 3 | * |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 4 | * Copyright 1993,1994 Alexandre Julliard |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 5 | * Copyright 1996 Alex Korobka |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 6 | * |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 7 | * PALETTEOBJ is documented in the Dr. Dobbs Journal May 1993. |
| 8 | * Information in the "Undocumented Windows" is incorrect. |
Alexandre Julliard | 59730ae | 1996-03-24 16:20:51 +0000 | [diff] [blame] | 9 | */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 10 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 11 | #include <stdlib.h> |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 12 | #include <string.h> |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 13 | |
Michael Veksler | 92ae219 | 1999-05-02 11:39:09 +0000 | [diff] [blame] | 14 | #include "winbase.h" |
Jeremy White | d3e22d9 | 2000-02-10 19:03:02 +0000 | [diff] [blame] | 15 | #include "windef.h" |
| 16 | #include "wingdi.h" |
Michael Veksler | 92ae219 | 1999-05-02 11:39:09 +0000 | [diff] [blame] | 17 | #include "wine/winuser16.h" |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 18 | #include "gdi.h" |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 19 | #include "color.h" |
Alexandre Julliard | 7cbe657 | 1995-01-09 18:21:16 +0000 | [diff] [blame] | 20 | #include "palette.h" |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 21 | #include "debugtools.h" |
Ian Schmidt | 31b4721 | 1999-09-22 15:12:41 +0000 | [diff] [blame] | 22 | #include "winerror.h" |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 23 | |
Alexandre Julliard | 3993216 | 2000-09-16 20:57:39 +0000 | [diff] [blame] | 24 | DEFAULT_DEBUG_CHANNEL(palette); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 25 | |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 26 | PALETTE_DRIVER *PALETTE_Driver = NULL; |
| 27 | |
Alexandre Julliard | 3993216 | 2000-09-16 20:57:39 +0000 | [diff] [blame] | 28 | /* Pointers to USER implementation of SelectPalette/RealizePalette */ |
| 29 | /* they will be patched by USER on startup */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 30 | FARPROC pfnSelectPalette = NULL; |
| 31 | FARPROC pfnRealizePalette = NULL; |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 32 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 33 | static UINT SystemPaletteUse = SYSPAL_STATIC; /* currently not considered */ |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 34 | |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 35 | static HPALETTE16 hPrimaryPalette = 0; /* used for WM_PALETTECHANGED */ |
| 36 | static HPALETTE16 hLastRealizedPalette = 0; /* UnrealizeObject() needs it */ |
| 37 | |
Alexandre Julliard | 902da69 | 1995-11-05 14:39:02 +0000 | [diff] [blame] | 38 | |
| 39 | /*********************************************************************** |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 40 | * PALETTE_Init |
| 41 | * |
| 42 | * Create the system palette. |
| 43 | */ |
| 44 | HPALETTE16 PALETTE_Init(void) |
| 45 | { |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 46 | int i; |
| 47 | HPALETTE16 hpalette; |
| 48 | LOGPALETTE * palPtr; |
| 49 | PALETTEOBJ* palObj; |
| 50 | const PALETTEENTRY* __sysPalTemplate = COLOR_GetSystemPaletteTemplate(); |
| 51 | |
| 52 | /* create default palette (20 system colors) */ |
| 53 | |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 54 | palPtr = HeapAlloc( GetProcessHeap(), 0, |
| 55 | sizeof(LOGPALETTE) + (NB_RESERVED_COLORS-1)*sizeof(PALETTEENTRY)); |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 56 | if (!palPtr) return FALSE; |
| 57 | |
| 58 | palPtr->palVersion = 0x300; |
| 59 | palPtr->palNumEntries = NB_RESERVED_COLORS; |
| 60 | for( i = 0; i < NB_RESERVED_COLORS; i ++ ) |
| 61 | { |
| 62 | palPtr->palPalEntry[i].peRed = __sysPalTemplate[i].peRed; |
| 63 | palPtr->palPalEntry[i].peGreen = __sysPalTemplate[i].peGreen; |
| 64 | palPtr->palPalEntry[i].peBlue = __sysPalTemplate[i].peBlue; |
| 65 | palPtr->palPalEntry[i].peFlags = 0; |
| 66 | } |
| 67 | hpalette = CreatePalette16( palPtr ); |
Dimitrie O. Paun | 9ad9636 | 2000-03-19 14:29:50 +0000 | [diff] [blame] | 68 | HeapFree( GetProcessHeap(), 0, palPtr ); |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 69 | |
| 70 | palObj = (PALETTEOBJ*) GDI_GetObjPtr( hpalette, PALETTE_MAGIC ); |
Juergen Schmied | 58b2f0a | 1999-01-23 12:09:30 +0000 | [diff] [blame] | 71 | if (palObj) |
| 72 | { |
Dimitrie O. Paun | 9ad9636 | 2000-03-19 14:29:50 +0000 | [diff] [blame] | 73 | if (!(palObj->mapping = HeapAlloc( GetProcessHeap(), 0, sizeof(int) * 20 ))) |
Francois Gouget | e76218d | 2001-05-09 17:31:31 +0000 | [diff] [blame] | 74 | ERR("Can not create palette mapping -- out of memory!\n"); |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 75 | GDI_ReleaseObj( hpalette ); |
Juergen Schmied | 58b2f0a | 1999-01-23 12:09:30 +0000 | [diff] [blame] | 76 | } |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 77 | return hpalette; |
| 78 | } |
| 79 | |
| 80 | /*********************************************************************** |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 81 | * PALETTE_ValidateFlags |
| 82 | */ |
| 83 | void PALETTE_ValidateFlags(PALETTEENTRY* lpPalE, int size) |
| 84 | { |
| 85 | int i = 0; |
| 86 | for( ; i<size ; i++ ) |
| 87 | lpPalE[i].peFlags = PC_SYS_USED | (lpPalE[i].peFlags & 0x07); |
| 88 | } |
| 89 | |
| 90 | |
| 91 | /*********************************************************************** |
Patrik Stridvall | 17fd4e3 | 2001-06-28 18:04:41 +0000 | [diff] [blame] | 92 | * CreatePalette (GDI.360) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 93 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 94 | HPALETTE16 WINAPI CreatePalette16( const LOGPALETTE* palette ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 95 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 96 | return CreatePalette( palette ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | |
| 100 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 101 | * CreatePalette [GDI32.@] Creates a logical color palette |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 102 | * |
| 103 | * RETURNS |
| 104 | * Success: Handle to logical palette |
| 105 | * Failure: NULL |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 106 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 107 | HPALETTE WINAPI CreatePalette( |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 108 | const LOGPALETTE* palette) /* [in] Pointer to logical color palette */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 109 | { |
| 110 | PALETTEOBJ * palettePtr; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 111 | HPALETTE hpalette; |
Juergen Schmied | c509615 | 1998-11-22 16:16:58 +0000 | [diff] [blame] | 112 | int size; |
| 113 | |
| 114 | if (!palette) return 0; |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 115 | TRACE("entries=%i\n", palette->palNumEntries); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 116 | |
Juergen Schmied | c509615 | 1998-11-22 16:16:58 +0000 | [diff] [blame] | 117 | size = sizeof(LOGPALETTE) + (palette->palNumEntries - 1) * sizeof(PALETTEENTRY); |
| 118 | |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 119 | if (!(palettePtr = GDI_AllocObject( size + sizeof(int*) +sizeof(GDIOBJHDR), |
| 120 | PALETTE_MAGIC, &hpalette ))) return 0; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 121 | memcpy( &palettePtr->logpalette, palette, size ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 122 | PALETTE_ValidateFlags(palettePtr->logpalette.palPalEntry, |
| 123 | palettePtr->logpalette.palNumEntries); |
| 124 | palettePtr->mapping = NULL; |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 125 | GDI_ReleaseObj( hpalette ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 126 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 127 | TRACE(" returning %04x\n", hpalette); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 128 | return hpalette; |
| 129 | } |
| 130 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 131 | |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 132 | /*********************************************************************** |
Patrik Stridvall | 17fd4e3 | 2001-06-28 18:04:41 +0000 | [diff] [blame] | 133 | * CreateHalftonePalette [GDI.529] Creates a halftone palette |
Brad Pepers | 0bdff36 | 1999-02-09 15:37:16 +0000 | [diff] [blame] | 134 | * |
| 135 | * RETURNS |
| 136 | * Success: Handle to logical halftone palette |
| 137 | * Failure: 0 |
| 138 | */ |
| 139 | HPALETTE16 WINAPI CreateHalftonePalette16( |
| 140 | HDC16 hdc) /* [in] Handle to device context */ |
| 141 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 142 | return CreateHalftonePalette(hdc); |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 143 | } |
Brad Pepers | 0bdff36 | 1999-02-09 15:37:16 +0000 | [diff] [blame] | 144 | |
| 145 | |
| 146 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 147 | * CreateHalftonePalette [GDI32.@] Creates a halftone palette |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 148 | * |
| 149 | * RETURNS |
| 150 | * Success: Handle to logical halftone palette |
| 151 | * Failure: 0 |
Juergen Schmied | 58b2f0a | 1999-01-23 12:09:30 +0000 | [diff] [blame] | 152 | * |
Aric Stewart | ae7fe2d | 2002-01-29 02:53:43 +0000 | [diff] [blame] | 153 | * FIXME: This simply creates the halftone palette dirived from runing |
| 154 | * tests on an windows NT machine. this is assuming a color depth |
| 155 | * of greater that 256 color. On a 256 color device the halftone |
| 156 | * palette will be differnt and this funtion will be incorrect |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 157 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 158 | HPALETTE WINAPI CreateHalftonePalette( |
| 159 | HDC hdc) /* [in] Handle to device context */ |
Brad Pepers | 0bdff36 | 1999-02-09 15:37:16 +0000 | [diff] [blame] | 160 | { |
Aric Stewart | ae7fe2d | 2002-01-29 02:53:43 +0000 | [diff] [blame] | 161 | int i; |
Brad Pepers | 0bdff36 | 1999-02-09 15:37:16 +0000 | [diff] [blame] | 162 | struct { |
| 163 | WORD Version; |
| 164 | WORD NumberOfEntries; |
| 165 | PALETTEENTRY aEntries[256]; |
Patrik Stridvall | f87b96e | 2000-10-24 02:20:31 +0000 | [diff] [blame] | 166 | } Palette; |
Juergen Schmied | 58b2f0a | 1999-01-23 12:09:30 +0000 | [diff] [blame] | 167 | |
Patrik Stridvall | f87b96e | 2000-10-24 02:20:31 +0000 | [diff] [blame] | 168 | Palette.Version = 0x300; |
| 169 | Palette.NumberOfEntries = 256; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 170 | GetSystemPaletteEntries(hdc, 0, 256, Palette.aEntries); |
Juergen Schmied | 58b2f0a | 1999-01-23 12:09:30 +0000 | [diff] [blame] | 171 | |
Aric Stewart | ae7fe2d | 2002-01-29 02:53:43 +0000 | [diff] [blame] | 172 | Palette.NumberOfEntries = 20; |
| 173 | |
| 174 | for (i = 0; i < Palette.NumberOfEntries; i++) |
| 175 | { |
| 176 | Palette.aEntries[i].peRed=0xff; |
| 177 | Palette.aEntries[i].peGreen=0xff; |
| 178 | Palette.aEntries[i].peBlue=0xff; |
| 179 | Palette.aEntries[i].peFlags=0x00; |
| 180 | } |
| 181 | |
| 182 | Palette.aEntries[0].peRed=0x00; |
| 183 | Palette.aEntries[0].peBlue=0x00; |
| 184 | Palette.aEntries[0].peGreen=0x00; |
| 185 | |
| 186 | /* the first 6 */ |
| 187 | for (i=1; i <= 6; i++) |
| 188 | { |
| 189 | Palette.aEntries[i].peRed=(i%2)?0x80:0; |
| 190 | Palette.aEntries[i].peGreen=(i==2)?0x80:(i==3)?0x80:(i==6)?0x80:0; |
| 191 | Palette.aEntries[i].peBlue=(i>3)?0x80:0; |
| 192 | } |
| 193 | |
| 194 | for (i=7; i <= 12; i++) |
| 195 | { |
| 196 | switch(i) |
| 197 | { |
| 198 | case 7: |
| 199 | Palette.aEntries[i].peRed=0xc0; |
| 200 | Palette.aEntries[i].peBlue=0xc0; |
| 201 | Palette.aEntries[i].peGreen=0xc0; |
| 202 | break; |
| 203 | case 8: |
| 204 | Palette.aEntries[i].peRed=0xc0; |
| 205 | Palette.aEntries[i].peGreen=0xdc; |
| 206 | Palette.aEntries[i].peBlue=0xc0; |
| 207 | break; |
| 208 | case 9: |
| 209 | Palette.aEntries[i].peRed=0xa6; |
| 210 | Palette.aEntries[i].peGreen=0xca; |
| 211 | Palette.aEntries[i].peBlue=0xf0; |
| 212 | break; |
| 213 | case 10: |
| 214 | Palette.aEntries[i].peRed=0xff; |
| 215 | Palette.aEntries[i].peGreen=0xfb; |
| 216 | Palette.aEntries[i].peBlue=0xf0; |
| 217 | break; |
| 218 | case 11: |
| 219 | Palette.aEntries[i].peRed=0xa0; |
| 220 | Palette.aEntries[i].peGreen=0xa0; |
| 221 | Palette.aEntries[i].peBlue=0xa4; |
| 222 | break; |
| 223 | case 12: |
| 224 | Palette.aEntries[i].peRed=0x80; |
| 225 | Palette.aEntries[i].peGreen=0x80; |
| 226 | Palette.aEntries[i].peBlue=0x80; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | for (i=13; i <= 18; i++) |
| 231 | { |
| 232 | Palette.aEntries[i].peRed=(i%2)?0xff:0; |
| 233 | Palette.aEntries[i].peGreen=(i==14)?0xff:(i==15)?0xff:(i==18)?0xff:0; |
| 234 | Palette.aEntries[i].peBlue=(i>15)?0xff:0x00; |
| 235 | } |
| 236 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 237 | return CreatePalette((LOGPALETTE *)&Palette); |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 238 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 239 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 240 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 241 | /*********************************************************************** |
Patrik Stridvall | 17fd4e3 | 2001-06-28 18:04:41 +0000 | [diff] [blame] | 242 | * GetPaletteEntries (GDI.363) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 243 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 244 | UINT16 WINAPI GetPaletteEntries16( HPALETTE16 hpalette, UINT16 start, |
| 245 | UINT16 count, LPPALETTEENTRY entries ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 246 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 247 | return GetPaletteEntries( hpalette, start, count, entries ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | |
| 251 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 252 | * GetPaletteEntries [GDI32.@] Retrieves palette entries |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 253 | * |
| 254 | * RETURNS |
| 255 | * Success: Number of entries from logical palette |
| 256 | * Failure: 0 |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 257 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 258 | UINT WINAPI GetPaletteEntries( |
| 259 | HPALETTE hpalette, /* [in] Handle of logical palette */ |
| 260 | UINT start, /* [in] First entry to receive */ |
| 261 | UINT count, /* [in] Number of entries to receive */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 262 | LPPALETTEENTRY entries) /* [out] Address of array receiving entries */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 263 | { |
| 264 | PALETTEOBJ * palPtr; |
Joerg Mayer | 4d75640 | 2001-01-10 22:45:33 +0000 | [diff] [blame] | 265 | UINT numEntries; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 266 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 267 | TRACE("hpal = %04x, count=%i\n", hpalette, count ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 268 | |
| 269 | palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC ); |
| 270 | if (!palPtr) return 0; |
Aric Stewart | ae7fe2d | 2002-01-29 02:53:43 +0000 | [diff] [blame] | 271 | |
| 272 | /* NOTE: not documented but test show this to be the case */ |
| 273 | if (count == 0) |
| 274 | { |
| 275 | int rc = palPtr->logpalette.palNumEntries; |
| 276 | GDI_ReleaseObj( hpalette ); |
| 277 | return rc; |
| 278 | } |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 279 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 280 | numEntries = palPtr->logpalette.palNumEntries; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 281 | if (start+count > numEntries) count = numEntries - start; |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 282 | if (entries) |
| 283 | { |
| 284 | if (start >= numEntries) |
| 285 | { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 286 | GDI_ReleaseObj( hpalette ); |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 287 | return 0; |
| 288 | } |
| 289 | memcpy( entries, &palPtr->logpalette.palPalEntry[start], |
| 290 | count * sizeof(PALETTEENTRY) ); |
| 291 | for( numEntries = 0; numEntries < count ; numEntries++ ) |
| 292 | if (entries[numEntries].peFlags & 0xF0) |
| 293 | entries[numEntries].peFlags = 0; |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 296 | GDI_ReleaseObj( hpalette ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 297 | return count; |
| 298 | } |
| 299 | |
| 300 | |
| 301 | /*********************************************************************** |
Patrik Stridvall | 17fd4e3 | 2001-06-28 18:04:41 +0000 | [diff] [blame] | 302 | * SetPaletteEntries (GDI.364) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 303 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 304 | UINT16 WINAPI SetPaletteEntries16( HPALETTE16 hpalette, UINT16 start, |
| 305 | UINT16 count, LPPALETTEENTRY entries ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 306 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 307 | return SetPaletteEntries( hpalette, start, count, entries ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | |
| 311 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 312 | * SetPaletteEntries [GDI32.@] Sets color values for range in palette |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 313 | * |
| 314 | * RETURNS |
| 315 | * Success: Number of entries that were set |
| 316 | * Failure: 0 |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 317 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 318 | UINT WINAPI SetPaletteEntries( |
| 319 | HPALETTE hpalette, /* [in] Handle of logical palette */ |
| 320 | UINT start, /* [in] Index of first entry to set */ |
| 321 | UINT count, /* [in] Number of entries to set */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 322 | LPPALETTEENTRY entries) /* [in] Address of array of structures */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 323 | { |
| 324 | PALETTEOBJ * palPtr; |
Joerg Mayer | 4d75640 | 2001-01-10 22:45:33 +0000 | [diff] [blame] | 325 | UINT numEntries; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 326 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 327 | TRACE("hpal=%04x,start=%i,count=%i\n",hpalette,start,count ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 328 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 329 | palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC ); |
| 330 | if (!palPtr) return 0; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 331 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 332 | numEntries = palPtr->logpalette.palNumEntries; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 333 | if (start >= numEntries) |
| 334 | { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 335 | GDI_ReleaseObj( hpalette ); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 336 | return 0; |
| 337 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 338 | if (start+count > numEntries) count = numEntries - start; |
| 339 | memcpy( &palPtr->logpalette.palPalEntry[start], entries, |
| 340 | count * sizeof(PALETTEENTRY) ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 341 | PALETTE_ValidateFlags(palPtr->logpalette.palPalEntry, |
| 342 | palPtr->logpalette.palNumEntries); |
Alexandre Julliard | a7116b0 | 2000-03-28 20:02:37 +0000 | [diff] [blame] | 343 | HeapFree( GetProcessHeap(), 0, palPtr->mapping ); |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 344 | palPtr->mapping = NULL; |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 345 | GDI_ReleaseObj( hpalette ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 346 | return count; |
| 347 | } |
| 348 | |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 349 | |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 350 | /*********************************************************************** |
Patrik Stridvall | 17fd4e3 | 2001-06-28 18:04:41 +0000 | [diff] [blame] | 351 | * ResizePalette (GDI.368) |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 352 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 353 | BOOL16 WINAPI ResizePalette16( HPALETTE16 hPal, UINT16 cEntries ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 354 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 355 | return ResizePalette( hPal, cEntries ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | |
| 359 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 360 | * ResizePalette [GDI32.@] Resizes logical palette |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 361 | * |
| 362 | * RETURNS |
| 363 | * Success: TRUE |
| 364 | * Failure: FALSE |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 365 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 366 | BOOL WINAPI ResizePalette( |
| 367 | HPALETTE hPal, /* [in] Handle of logical palette */ |
| 368 | UINT cEntries) /* [in] Number of entries in logical palette */ |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 369 | { |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 370 | PALETTEOBJ * palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 371 | UINT cPrevEnt, prevVer; |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 372 | int prevsize, size = sizeof(LOGPALETTE) + (cEntries - 1) * sizeof(PALETTEENTRY); |
| 373 | int* mapping = NULL; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 374 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 375 | TRACE("hpal = %04x, prev = %i, new = %i\n", |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 376 | hPal, palPtr ? palPtr->logpalette.palNumEntries : -1, |
| 377 | cEntries ); |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 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; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 385 | |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 386 | if (!(palPtr = GDI_ReallocObject( size, hPal, palPtr ))) return FALSE; |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 387 | |
Dimitrie O. Paun | 9ad9636 | 2000-03-19 14:29:50 +0000 | [diff] [blame] | 388 | if( mapping ) |
| 389 | { |
| 390 | int *newMap = (int*) HeapReAlloc(GetProcessHeap(), 0, |
| 391 | mapping, cEntries * sizeof(int) ); |
| 392 | if(newMap == NULL) |
| 393 | { |
Francois Gouget | e76218d | 2001-05-09 17:31:31 +0000 | [diff] [blame] | 394 | ERR("Can not resize mapping -- out of memory!\n"); |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 395 | GDI_ReleaseObj( hPal ); |
Dimitrie O. Paun | 9ad9636 | 2000-03-19 14:29:50 +0000 | [diff] [blame] | 396 | return FALSE; |
| 397 | } |
| 398 | palPtr->mapping = newMap; |
| 399 | } |
| 400 | |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 401 | if( cEntries > cPrevEnt ) |
| 402 | { |
| 403 | if( mapping ) |
| 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 ); |
| 408 | } |
| 409 | palPtr->logpalette.palNumEntries = cEntries; |
| 410 | palPtr->logpalette.palVersion = prevVer; |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 411 | GDI_ReleaseObj( hPal ); |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 412 | return TRUE; |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 415 | |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 416 | /*********************************************************************** |
Patrik Stridvall | 17fd4e3 | 2001-06-28 18:04:41 +0000 | [diff] [blame] | 417 | * AnimatePalette (GDI.367) |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 418 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 419 | void WINAPI AnimatePalette16( HPALETTE16 hPal, UINT16 StartIndex, |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 420 | UINT16 NumEntries, const PALETTEENTRY* PaletteColors) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 421 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 422 | AnimatePalette( hPal, StartIndex, NumEntries, PaletteColors ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | |
| 426 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 427 | * AnimatePalette [GDI32.@] Replaces entries in logical palette |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 428 | * |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 429 | * RETURNS |
| 430 | * Success: TRUE |
| 431 | * Failure: FALSE |
| 432 | * |
| 433 | * FIXME |
| 434 | * Should use existing mapping when animating a primary palette |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 435 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 436 | BOOL WINAPI AnimatePalette( |
| 437 | HPALETTE hPal, /* [in] Handle to logical palette */ |
| 438 | UINT StartIndex, /* [in] First entry in palette */ |
| 439 | UINT NumEntries, /* [in] Count of entries in palette */ |
François Gouget | 241c730 | 1998-10-28 10:47:09 +0000 | [diff] [blame] | 440 | const PALETTEENTRY* PaletteColors) /* [in] Pointer to first replacement */ |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 441 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 442 | TRACE("%04x (%i - %i)\n", hPal, StartIndex,StartIndex+NumEntries); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 443 | |
Alexandre Julliard | 4c18636 | 2000-10-29 01:22:15 +0000 | [diff] [blame] | 444 | if( hPal != GetStockObject(DEFAULT_PALETTE) ) |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 445 | { |
| 446 | PALETTEOBJ* palPtr = (PALETTEOBJ *)GDI_GetObjPtr(hPal, PALETTE_MAGIC); |
Juergen Schmied | 58b2f0a | 1999-01-23 12:09:30 +0000 | [diff] [blame] | 447 | if (!palPtr) return FALSE; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 448 | |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 449 | if( (StartIndex + NumEntries) <= palPtr->logpalette.palNumEntries ) |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 450 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 451 | UINT u; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 452 | for( u = 0; u < NumEntries; u++ ) |
| 453 | palPtr->logpalette.palPalEntry[u + StartIndex] = PaletteColors[u]; |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 454 | PALETTE_Driver-> |
| 455 | pSetMapping(palPtr, StartIndex, NumEntries, |
| 456 | hPal != hPrimaryPalette ); |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 457 | GDI_ReleaseObj( hPal ); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 458 | return TRUE; |
| 459 | } |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 460 | GDI_ReleaseObj( hPal ); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 461 | } |
| 462 | return FALSE; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 463 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 464 | |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 465 | |
| 466 | /*********************************************************************** |
Patrik Stridvall | 17fd4e3 | 2001-06-28 18:04:41 +0000 | [diff] [blame] | 467 | * SetSystemPaletteUse (GDI.373) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 468 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 469 | UINT16 WINAPI SetSystemPaletteUse16( HDC16 hdc, UINT16 use ) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 470 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 471 | return SetSystemPaletteUse( hdc, use ); |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | |
| 475 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 476 | * SetSystemPaletteUse [GDI32.@] |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 477 | * |
| 478 | * RETURNS |
| 479 | * Success: Previous system palette |
| 480 | * Failure: SYSPAL_ERROR |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 481 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 482 | UINT WINAPI SetSystemPaletteUse( |
| 483 | HDC hdc, /* [in] Handle of device context */ |
| 484 | UINT use) /* [in] Palette-usage flag */ |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 485 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 486 | UINT old = SystemPaletteUse; |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 487 | FIXME("(%04x,%04x): stub\n", hdc, use ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 488 | SystemPaletteUse = use; |
| 489 | return old; |
| 490 | } |
| 491 | |
| 492 | |
| 493 | /*********************************************************************** |
Patrik Stridvall | 17fd4e3 | 2001-06-28 18:04:41 +0000 | [diff] [blame] | 494 | * GetSystemPaletteUse (GDI.374) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 495 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 496 | UINT16 WINAPI GetSystemPaletteUse16( HDC16 hdc ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 497 | { |
| 498 | return SystemPaletteUse; |
| 499 | } |
| 500 | |
| 501 | |
| 502 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 503 | * GetSystemPaletteUse [GDI32.@] Gets state of system palette |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 504 | * |
| 505 | * RETURNS |
| 506 | * Current state of system palette |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 507 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 508 | UINT WINAPI GetSystemPaletteUse( |
| 509 | HDC hdc) /* [in] Handle of device context */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 510 | { |
| 511 | return SystemPaletteUse; |
| 512 | } |
| 513 | |
| 514 | |
| 515 | /*********************************************************************** |
Patrik Stridvall | 17fd4e3 | 2001-06-28 18:04:41 +0000 | [diff] [blame] | 516 | * GetSystemPaletteEntries (GDI.375) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 517 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 518 | UINT16 WINAPI GetSystemPaletteEntries16( HDC16 hdc, UINT16 start, UINT16 count, |
| 519 | LPPALETTEENTRY entries ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 520 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 521 | return GetSystemPaletteEntries( hdc, start, count, entries ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | |
| 525 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 526 | * GetSystemPaletteEntries [GDI32.@] Gets range of palette entries |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 527 | * |
| 528 | * RETURNS |
| 529 | * Success: Number of entries retrieved from palette |
| 530 | * Failure: 0 |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 531 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 532 | UINT WINAPI GetSystemPaletteEntries( |
| 533 | HDC hdc, /* [in] Handle of device context */ |
| 534 | UINT start, /* [in] Index of first entry to be retrieved */ |
| 535 | UINT count, /* [in] Number of entries to be retrieved */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 536 | LPPALETTEENTRY entries) /* [out] Array receiving system-palette entries */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 537 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 538 | UINT i; |
Alexandre Julliard | 99bb9f9 | 2001-07-28 00:18:02 +0000 | [diff] [blame] | 539 | INT sizePalette = GetDeviceCaps( hdc, SIZEPALETTE ); |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 540 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 541 | TRACE("hdc=%04x,start=%i,count=%i\n", hdc,start,count); |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 542 | |
Alexandre Julliard | 99bb9f9 | 2001-07-28 00:18:02 +0000 | [diff] [blame] | 543 | if (!entries) return sizePalette; |
| 544 | if (start >= sizePalette) return 0; |
| 545 | if (start+count >= sizePalette) count = sizePalette - start; |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 546 | |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 547 | for (i = 0; i < count; i++) |
| 548 | { |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 549 | *(COLORREF*)(entries + i) = COLOR_GetSystemPaletteEntry( start + i ); |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 550 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 551 | TRACE("\tidx(%02x) -> RGB(%08lx)\n", |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 552 | start + i, *(COLORREF*)(entries + i) ); |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 553 | } |
| 554 | return count; |
| 555 | } |
| 556 | |
| 557 | |
| 558 | /*********************************************************************** |
Patrik Stridvall | 17fd4e3 | 2001-06-28 18:04:41 +0000 | [diff] [blame] | 559 | * GetNearestPaletteIndex (GDI.370) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 560 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 561 | UINT16 WINAPI GetNearestPaletteIndex16( HPALETTE16 hpalette, COLORREF color ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 562 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 563 | return GetNearestPaletteIndex( hpalette, color ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | |
| 567 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 568 | * GetNearestPaletteIndex [GDI32.@] Gets palette index for color |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 569 | * |
| 570 | * NOTES |
| 571 | * Should index be initialized to CLR_INVALID instead of 0? |
| 572 | * |
| 573 | * RETURNS |
| 574 | * Success: Index of entry in logical palette |
| 575 | * Failure: CLR_INVALID |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 576 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 577 | UINT WINAPI GetNearestPaletteIndex( |
| 578 | HPALETTE hpalette, /* [in] Handle of logical color palette */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 579 | COLORREF color) /* [in] Color to be matched */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 580 | { |
| 581 | PALETTEOBJ* palObj = (PALETTEOBJ*)GDI_GetObjPtr( hpalette, PALETTE_MAGIC ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 582 | UINT index = 0; |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 583 | |
| 584 | if( palObj ) |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 585 | { |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 586 | index = COLOR_PaletteLookupPixel(palObj->logpalette.palPalEntry, |
| 587 | palObj->logpalette.palNumEntries, |
| 588 | NULL, color, FALSE ); |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 589 | |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 590 | GDI_ReleaseObj( hpalette ); |
| 591 | } |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 592 | TRACE("(%04x,%06lx): returning %d\n", hpalette, color, index ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 593 | return index; |
| 594 | } |
| 595 | |
| 596 | |
| 597 | /*********************************************************************** |
Patrik Stridvall | 17fd4e3 | 2001-06-28 18:04:41 +0000 | [diff] [blame] | 598 | * GetNearestColor (GDI.154) |
Alexandre Julliard | 902da69 | 1995-11-05 14:39:02 +0000 | [diff] [blame] | 599 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 600 | COLORREF WINAPI GetNearestColor16( HDC16 hdc, COLORREF color ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 601 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 602 | return GetNearestColor( hdc, color ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | |
| 606 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 607 | * GetNearestColor [GDI32.@] Gets a system color to match |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 608 | * |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 609 | * RETURNS |
| 610 | * Success: Color from system palette that corresponds to given color |
| 611 | * Failure: CLR_INVALID |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 612 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 613 | COLORREF WINAPI GetNearestColor( |
| 614 | HDC hdc, /* [in] Handle of device context */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 615 | COLORREF color) /* [in] Color to be matched */ |
Alexandre Julliard | 902da69 | 1995-11-05 14:39:02 +0000 | [diff] [blame] | 616 | { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 617 | COLORREF nearest = CLR_INVALID; |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 618 | DC *dc; |
| 619 | PALETTEOBJ *palObj; |
Alexandre Julliard | 902da69 | 1995-11-05 14:39:02 +0000 | [diff] [blame] | 620 | |
Dave Hawkes | 314b9fd | 2002-02-05 19:44:07 +0000 | [diff] [blame] | 621 | if(!(GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE)) { |
| 622 | return color; |
| 623 | } |
Alexandre Julliard | 2239abb | 2000-11-05 02:05:07 +0000 | [diff] [blame] | 624 | if ( (dc = DC_GetDCPtr( hdc )) ) |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 625 | { |
Alexandre Julliard | 2239abb | 2000-11-05 02:05:07 +0000 | [diff] [blame] | 626 | HPALETTE hpal = (dc->hPalette)? dc->hPalette : GetStockObject( DEFAULT_PALETTE ); |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 627 | palObj = GDI_GetObjPtr( hpal, PALETTE_MAGIC ); |
| 628 | if (!palObj) { |
| 629 | GDI_ReleaseObj( hdc ); |
| 630 | return nearest; |
| 631 | } |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 632 | |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 633 | nearest = COLOR_LookupNearestColor( palObj->logpalette.palPalEntry, |
| 634 | palObj->logpalette.palNumEntries, color ); |
| 635 | GDI_ReleaseObj( hpal ); |
| 636 | GDI_ReleaseObj( hdc ); |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 637 | } |
| 638 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 639 | TRACE("(%06lx): returning %06lx\n", color, nearest ); |
Alexandre Julliard | 902da69 | 1995-11-05 14:39:02 +0000 | [diff] [blame] | 640 | return nearest; |
| 641 | } |
| 642 | |
| 643 | |
| 644 | /*********************************************************************** |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 645 | * PALETTE_GetObject |
| 646 | */ |
| 647 | int PALETTE_GetObject( PALETTEOBJ * palette, int count, LPSTR buffer ) |
| 648 | { |
| 649 | if (count > sizeof(WORD)) count = sizeof(WORD); |
| 650 | memcpy( buffer, &palette->logpalette.palNumEntries, count ); |
| 651 | return count; |
| 652 | } |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 653 | |
| 654 | |
| 655 | /*********************************************************************** |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 656 | * PALETTE_UnrealizeObject |
| 657 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 658 | BOOL PALETTE_UnrealizeObject( HPALETTE16 hpalette, PALETTEOBJ *palette ) |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 659 | { |
| 660 | if (palette->mapping) |
| 661 | { |
Alexandre Julliard | a7116b0 | 2000-03-28 20:02:37 +0000 | [diff] [blame] | 662 | HeapFree( GetProcessHeap(), 0, palette->mapping ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 663 | palette->mapping = NULL; |
| 664 | } |
| 665 | if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0; |
| 666 | return TRUE; |
| 667 | } |
| 668 | |
| 669 | |
| 670 | /*********************************************************************** |
| 671 | * PALETTE_DeleteObject |
| 672 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 673 | BOOL PALETTE_DeleteObject( HPALETTE16 hpalette, PALETTEOBJ *palette ) |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 674 | { |
Alexandre Julliard | a7116b0 | 2000-03-28 20:02:37 +0000 | [diff] [blame] | 675 | HeapFree( GetProcessHeap(), 0, palette->mapping ); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 676 | if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0; |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 677 | return GDI_FreeObject( hpalette, palette ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | |
| 681 | /*********************************************************************** |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 682 | * GDISelectPalette (GDI.361) |
| 683 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 684 | HPALETTE16 WINAPI GDISelectPalette16( HDC16 hdc, HPALETTE16 hpal, WORD wBkg) |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 685 | { |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 686 | HPALETTE16 prev; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 687 | DC *dc; |
| 688 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 689 | TRACE("%04x %04x\n", hdc, hpal ); |
Alexandre Julliard | 3993216 | 2000-09-16 20:57:39 +0000 | [diff] [blame] | 690 | |
Andreas Mohr | ea8795b | 2000-09-29 01:03:57 +0000 | [diff] [blame] | 691 | if (GetObjectType(hpal) != OBJ_PAL) |
Alexandre Julliard | 3993216 | 2000-09-16 20:57:39 +0000 | [diff] [blame] | 692 | { |
| 693 | WARN("invalid selected palette %04x\n",hpal); |
| 694 | return 0; |
| 695 | } |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 696 | if (!(dc = DC_GetDCPtr( hdc ))) return 0; |
Alexandre Julliard | 2239abb | 2000-11-05 02:05:07 +0000 | [diff] [blame] | 697 | prev = dc->hPalette; |
| 698 | dc->hPalette = hpal; |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 699 | GDI_ReleaseObj( hdc ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 700 | if (!wBkg) hPrimaryPalette = hpal; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 701 | return prev; |
| 702 | } |
| 703 | |
| 704 | |
| 705 | /*********************************************************************** |
| 706 | * GDIRealizePalette (GDI.362) |
| 707 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 708 | UINT16 WINAPI GDIRealizePalette16( HDC16 hdc ) |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 709 | { |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 710 | PALETTEOBJ* palPtr; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 711 | int realized = 0; |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 712 | DC* dc = DC_GetDCPtr( hdc ); |
| 713 | |
| 714 | if (!dc) return 0; |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 715 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 716 | TRACE("%04x...\n", hdc ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 717 | |
Alexandre Julliard | 2239abb | 2000-11-05 02:05:07 +0000 | [diff] [blame] | 718 | if(dc->hPalette != hLastRealizedPalette ) |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 719 | { |
Alexandre Julliard | 2239abb | 2000-11-05 02:05:07 +0000 | [diff] [blame] | 720 | if( dc->hPalette == GetStockObject( DEFAULT_PALETTE )) { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 721 | realized = RealizeDefaultPalette16( hdc ); |
| 722 | GDI_ReleaseObj( hdc ); |
| 723 | return (UINT16)realized; |
| 724 | } |
| 725 | |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 726 | |
Alexandre Julliard | 2239abb | 2000-11-05 02:05:07 +0000 | [diff] [blame] | 727 | palPtr = (PALETTEOBJ *) GDI_GetObjPtr( dc->hPalette, PALETTE_MAGIC ); |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 728 | |
| 729 | if (!palPtr) { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 730 | GDI_ReleaseObj( hdc ); |
Alexandre Julliard | 2239abb | 2000-11-05 02:05:07 +0000 | [diff] [blame] | 731 | FIXME("invalid selected palette %04x\n",dc->hPalette); |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 732 | return 0; |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 733 | } |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 734 | |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 735 | realized = PALETTE_Driver-> |
| 736 | pSetMapping(palPtr,0,palPtr->logpalette.palNumEntries, |
Alexandre Julliard | 2239abb | 2000-11-05 02:05:07 +0000 | [diff] [blame] | 737 | (dc->hPalette != hPrimaryPalette) || |
| 738 | (dc->hPalette == GetStockObject( DEFAULT_PALETTE ))); |
| 739 | hLastRealizedPalette = dc->hPalette; |
| 740 | GDI_ReleaseObj( dc->hPalette ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 741 | } |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 742 | else TRACE(" skipping (hLastRealizedPalette = %04x)\n", |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 743 | hLastRealizedPalette); |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 744 | GDI_ReleaseObj( hdc ); |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 745 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 746 | TRACE(" realized %i colors.\n", realized ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 747 | return (UINT16)realized; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | |
| 751 | /*********************************************************************** |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 752 | * RealizeDefaultPalette (GDI.365) |
| 753 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 754 | UINT16 WINAPI RealizeDefaultPalette16( HDC16 hdc ) |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 755 | { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 756 | UINT16 ret = 0; |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 757 | DC *dc; |
| 758 | PALETTEOBJ* palPtr; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 759 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 760 | TRACE("%04x\n", hdc ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 761 | |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 762 | if (!(dc = DC_GetDCPtr( hdc ))) return 0; |
| 763 | |
Alexandre Julliard | 2239abb | 2000-11-05 02:05:07 +0000 | [diff] [blame] | 764 | if (!(dc->flags & DC_MEMORY)) |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 765 | { |
Alexandre Julliard | 4c18636 | 2000-10-29 01:22:15 +0000 | [diff] [blame] | 766 | palPtr = (PALETTEOBJ*)GDI_GetObjPtr( GetStockObject(DEFAULT_PALETTE), PALETTE_MAGIC ); |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 767 | if (palPtr) |
| 768 | { |
| 769 | /* lookup is needed to account for SetSystemPaletteUse() stuff */ |
| 770 | ret = PALETTE_Driver->pUpdateMapping(palPtr); |
Alexandre Julliard | 4c18636 | 2000-10-29 01:22:15 +0000 | [diff] [blame] | 771 | GDI_ReleaseObj( GetStockObject(DEFAULT_PALETTE) ); |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 772 | } |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 773 | } |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 774 | GDI_ReleaseObj( hdc ); |
| 775 | return ret; |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 776 | } |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 777 | |
| 778 | /*********************************************************************** |
| 779 | * IsDCCurrentPalette (GDI.412) |
| 780 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 781 | BOOL16 WINAPI IsDCCurrentPalette16(HDC16 hDC) |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 782 | { |
Alexandre Julliard | 2239abb | 2000-11-05 02:05:07 +0000 | [diff] [blame] | 783 | DC *dc = DC_GetDCPtr( hDC ); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 784 | if (dc) |
| 785 | { |
Alexandre Julliard | 2239abb | 2000-11-05 02:05:07 +0000 | [diff] [blame] | 786 | BOOL bRet = dc->hPalette == hPrimaryPalette; |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 787 | GDI_ReleaseObj( hDC ); |
| 788 | return bRet; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 789 | } |
| 790 | return FALSE; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 791 | } |
| 792 | |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 793 | |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 794 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 795 | * SelectPalette [GDI32.@] Selects logical palette into DC |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 796 | * |
| 797 | * RETURNS |
| 798 | * Success: Previous logical palette |
| 799 | * Failure: NULL |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 800 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 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 */ |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 805 | { |
Alexandre Julliard | 3993216 | 2000-09-16 20:57:39 +0000 | [diff] [blame] | 806 | return pfnSelectPalette( hDC, hPal, bForceBackground ); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 807 | } |
| 808 | |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 809 | |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 810 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 811 | * RealizePalette [GDI32.@] Maps palette entries to system palette |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 812 | * |
| 813 | * RETURNS |
| 814 | * Success: Number of entries in logical palette |
| 815 | * Failure: GDI_ERROR |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 816 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 817 | UINT WINAPI RealizePalette( |
| 818 | HDC hDC) /* [in] Handle of device context */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 819 | { |
Alexandre Julliard | 3993216 | 2000-09-16 20:57:39 +0000 | [diff] [blame] | 820 | return pfnRealizePalette( hDC ); |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | |
Patrik Stridvall | 57e5784 | 2002-02-02 18:42:11 +0000 | [diff] [blame] | 824 | typedef HWND (WINAPI *WindowFromDC_funcptr)( HDC ); |
| 825 | typedef BOOL (WINAPI *RedrawWindow_funcptr)( HWND, const RECT *, HRGN, UINT ); |
Alexandre Julliard | ea2a9a8 | 2001-02-20 00:55:17 +0000 | [diff] [blame] | 826 | |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 827 | /********************************************************************** |
Dmitry Timoshkov | 56a1992 | 2001-07-02 01:21:26 +0000 | [diff] [blame] | 828 | * UpdateColors [GDI32.@] Remaps current colors to logical palette |
| 829 | * |
| 830 | * RETURNS |
| 831 | * Success: TRUE |
| 832 | * Failure: FALSE |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 833 | */ |
Dmitry Timoshkov | 56a1992 | 2001-07-02 01:21:26 +0000 | [diff] [blame] | 834 | BOOL WINAPI UpdateColors( |
| 835 | HDC hDC) /* [in] Handle of device context */ |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 836 | { |
Alexandre Julliard | ea2a9a8 | 2001-02-20 00:55:17 +0000 | [diff] [blame] | 837 | HMODULE mod; |
Alexandre Julliard | 99bb9f9 | 2001-07-28 00:18:02 +0000 | [diff] [blame] | 838 | int size = GetDeviceCaps( hDC, SIZEPALETTE ); |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 839 | |
Alexandre Julliard | 99bb9f9 | 2001-07-28 00:18:02 +0000 | [diff] [blame] | 840 | if (!size) return 0; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 841 | |
Alexandre Julliard | ea2a9a8 | 2001-02-20 00:55:17 +0000 | [diff] [blame] | 842 | mod = GetModuleHandleA("user32.dll"); |
| 843 | if (mod) |
| 844 | { |
| 845 | WindowFromDC_funcptr pWindowFromDC = (WindowFromDC_funcptr)GetProcAddress(mod,"WindowFromDC"); |
| 846 | if (pWindowFromDC) |
| 847 | { |
| 848 | HWND hWnd = pWindowFromDC( hDC ); |
| 849 | |
| 850 | /* Docs say that we have to remap current drawable pixel by pixel |
| 851 | * but it would take forever given the speed of XGet/PutPixel. |
| 852 | */ |
| 853 | if (hWnd && size) |
| 854 | { |
| 855 | RedrawWindow_funcptr pRedrawWindow = GetProcAddress( mod, "RedrawWindow" ); |
| 856 | if (pRedrawWindow) pRedrawWindow( hWnd, NULL, 0, RDW_INVALIDATE ); |
| 857 | } |
| 858 | } |
Alexandre Julliard | 4e951ea | 2000-11-08 22:47:53 +0000 | [diff] [blame] | 859 | } |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 860 | return 0x666; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 861 | } |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 862 | |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 863 | |
| 864 | /********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 865 | * UpdateColors (GDI.366) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 866 | */ |
Dmitry Timoshkov | 56a1992 | 2001-07-02 01:21:26 +0000 | [diff] [blame] | 867 | INT16 WINAPI UpdateColors16( HDC16 hDC ) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 868 | { |
Dmitry Timoshkov | 56a1992 | 2001-07-02 01:21:26 +0000 | [diff] [blame] | 869 | UpdateColors( hDC ); |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 870 | return TRUE; |
| 871 | } |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 872 | |
Ian Schmidt | 8150b52 | 1998-11-22 12:54:38 +0000 | [diff] [blame] | 873 | |
| 874 | /********************************************************************* |
Patrik Stridvall | 17fd4e3 | 2001-06-28 18:04:41 +0000 | [diff] [blame] | 875 | * SetMagicColors (GDI.606) |
Ian Schmidt | 8150b52 | 1998-11-22 12:54:38 +0000 | [diff] [blame] | 876 | */ |
| 877 | VOID WINAPI SetMagicColors16(HDC16 hDC, COLORREF color, UINT16 index) |
| 878 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 879 | FIXME("(hDC %04x, color %04x, index %04x): stub\n", hDC, (int)color, index); |
Ian Schmidt | 8150b52 | 1998-11-22 12:54:38 +0000 | [diff] [blame] | 880 | |
| 881 | } |
Ian Schmidt | 31b4721 | 1999-09-22 15:12:41 +0000 | [diff] [blame] | 882 | |
| 883 | /********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 884 | * GetICMProfileA [GDI32.@] |
Ian Schmidt | 31b4721 | 1999-09-22 15:12:41 +0000 | [diff] [blame] | 885 | * |
| 886 | * Returns the filename of the specified device context's color |
| 887 | * management profile, even if color management is not enabled |
| 888 | * for that DC. |
| 889 | * |
| 890 | * RETURNS |
| 891 | * TRUE if name copied succesfully OR lpszFilename is NULL |
| 892 | * FALSE if the buffer length pointed to by lpcbName is too small |
| 893 | * |
| 894 | * NOTE |
| 895 | * The buffer length pointed to by lpcbName is ALWAYS updated to |
| 896 | * the length required regardless of other actions this function |
| 897 | * may take. |
| 898 | * |
| 899 | * FIXME |
| 900 | * How does Windows assign these? Some registry key? |
| 901 | */ |
| 902 | |
| 903 | #define WINEICM "winefake.icm" /* easy-to-identify fake filename */ |
| 904 | |
Patrik Stridvall | 2b3aa61 | 2000-12-01 23:58:28 +0000 | [diff] [blame] | 905 | /*********************************************************************/ |
| 906 | |
Ian Schmidt | 31b4721 | 1999-09-22 15:12:41 +0000 | [diff] [blame] | 907 | BOOL WINAPI GetICMProfileA(HDC hDC, LPDWORD lpcbName, LPSTR lpszFilename) |
| 908 | { |
| 909 | DWORD callerLen; |
| 910 | |
| 911 | FIXME("(%04x, %p, %p): partial stub\n", hDC, lpcbName, lpszFilename); |
| 912 | |
| 913 | callerLen = *lpcbName; |
| 914 | |
| 915 | /* all 3 behaviors require the required buffer size to be set */ |
| 916 | *lpcbName = strlen(WINEICM); |
| 917 | |
| 918 | /* behavior 1: if lpszFilename is NULL, return size of string and no error */ |
| 919 | if ((DWORD)lpszFilename == (DWORD)0x00000000) |
| 920 | return TRUE; |
| 921 | |
| 922 | /* behavior 2: if buffer size too small, return size of string and error */ |
| 923 | if (callerLen < strlen(WINEICM)) |
| 924 | { |
| 925 | SetLastError(ERROR_INSUFFICIENT_BUFFER); |
| 926 | return FALSE; |
| 927 | } |
| 928 | |
| 929 | /* behavior 3: if buffer size OK and pointer not NULL, copy and return size */ |
Alexandre Julliard | c7e7df8 | 2000-08-14 14:41:19 +0000 | [diff] [blame] | 930 | strcpy(lpszFilename, WINEICM); |
Ian Schmidt | 31b4721 | 1999-09-22 15:12:41 +0000 | [diff] [blame] | 931 | return TRUE; |
| 932 | } |