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