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> |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 13 | #include "ts_xlib.h" |
Alexandre Julliard | 59730ae | 1996-03-24 16:20:51 +0000 | [diff] [blame] | 14 | |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 15 | #include "gdi.h" |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 16 | #include "color.h" |
Alexandre Julliard | 7cbe657 | 1995-01-09 18:21:16 +0000 | [diff] [blame] | 17 | #include "palette.h" |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 18 | #include "xmalloc.h" |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 19 | #include "debug.h" |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 20 | |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 21 | static UINT32 SystemPaletteUse = SYSPAL_STATIC; /* currently not considered */ |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 22 | |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 23 | static HPALETTE16 hPrimaryPalette = 0; /* used for WM_PALETTECHANGED */ |
| 24 | static HPALETTE16 hLastRealizedPalette = 0; /* UnrealizeObject() needs it */ |
| 25 | |
Alexandre Julliard | 902da69 | 1995-11-05 14:39:02 +0000 | [diff] [blame] | 26 | |
| 27 | /*********************************************************************** |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 28 | * PALETTE_Init |
| 29 | * |
| 30 | * Create the system palette. |
| 31 | */ |
| 32 | HPALETTE16 PALETTE_Init(void) |
| 33 | { |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 34 | int i; |
| 35 | HPALETTE16 hpalette; |
| 36 | LOGPALETTE * palPtr; |
| 37 | PALETTEOBJ* palObj; |
| 38 | const PALETTEENTRY* __sysPalTemplate = COLOR_GetSystemPaletteTemplate(); |
| 39 | |
| 40 | /* create default palette (20 system colors) */ |
| 41 | |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 42 | palPtr = HeapAlloc( GetProcessHeap(), 0, |
| 43 | sizeof(LOGPALETTE) + (NB_RESERVED_COLORS-1)*sizeof(PALETTEENTRY)); |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 44 | if (!palPtr) return FALSE; |
| 45 | |
| 46 | palPtr->palVersion = 0x300; |
| 47 | palPtr->palNumEntries = NB_RESERVED_COLORS; |
| 48 | for( i = 0; i < NB_RESERVED_COLORS; i ++ ) |
| 49 | { |
| 50 | palPtr->palPalEntry[i].peRed = __sysPalTemplate[i].peRed; |
| 51 | palPtr->palPalEntry[i].peGreen = __sysPalTemplate[i].peGreen; |
| 52 | palPtr->palPalEntry[i].peBlue = __sysPalTemplate[i].peBlue; |
| 53 | palPtr->palPalEntry[i].peFlags = 0; |
| 54 | } |
| 55 | hpalette = CreatePalette16( palPtr ); |
| 56 | |
| 57 | palObj = (PALETTEOBJ*) GDI_GetObjPtr( hpalette, PALETTE_MAGIC ); |
| 58 | |
| 59 | palObj->mapping = xmalloc( sizeof(int) * 20 ); |
| 60 | |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 61 | GDI_HEAP_UNLOCK( hpalette ); |
| 62 | |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 63 | HeapFree( GetProcessHeap(), 0, palPtr ); |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 64 | return hpalette; |
| 65 | } |
| 66 | |
| 67 | /*********************************************************************** |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 68 | * PALETTE_ValidateFlags |
| 69 | */ |
| 70 | void PALETTE_ValidateFlags(PALETTEENTRY* lpPalE, int size) |
| 71 | { |
| 72 | int i = 0; |
| 73 | for( ; i<size ; i++ ) |
| 74 | lpPalE[i].peFlags = PC_SYS_USED | (lpPalE[i].peFlags & 0x07); |
| 75 | } |
| 76 | |
| 77 | |
| 78 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 79 | * CreatePalette16 (GDI.360) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 80 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 81 | HPALETTE16 WINAPI CreatePalette16( const LOGPALETTE* palette ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 82 | { |
| 83 | return CreatePalette32( palette ); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 88 | * CreatePalette32 [GDI32.53] Creates a logical color palette |
| 89 | * |
| 90 | * RETURNS |
| 91 | * Success: Handle to logical palette |
| 92 | * Failure: NULL |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 93 | */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 94 | HPALETTE32 WINAPI CreatePalette32( |
| 95 | const LOGPALETTE* palette) /* [in] Pointer to logical color palette */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 96 | { |
| 97 | PALETTEOBJ * palettePtr; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 98 | HPALETTE32 hpalette; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 99 | int size = sizeof(LOGPALETTE) + (palette->palNumEntries - 1) * sizeof(PALETTEENTRY); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 100 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 101 | TRACE(palette,"entries=%i\n", palette->palNumEntries); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 102 | |
| 103 | hpalette = GDI_AllocObject( size + sizeof(int*) +sizeof(GDIOBJHDR) , PALETTE_MAGIC ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 104 | if (!hpalette) return 0; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 105 | |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 106 | palettePtr = (PALETTEOBJ *) GDI_HEAP_LOCK( hpalette ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 107 | memcpy( &palettePtr->logpalette, palette, size ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 108 | PALETTE_ValidateFlags(palettePtr->logpalette.palPalEntry, |
| 109 | palettePtr->logpalette.palNumEntries); |
| 110 | palettePtr->mapping = NULL; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 111 | GDI_HEAP_UNLOCK( hpalette ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 112 | |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 113 | TRACE(palette," returning %04x\n", hpalette); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 114 | return hpalette; |
| 115 | } |
| 116 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 117 | |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 118 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 119 | * CreateHalftonePalette [GDI32.47] Creates a halftone palette |
| 120 | * |
| 121 | * RETURNS |
| 122 | * Success: Handle to logical halftone palette |
| 123 | * Failure: 0 |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 124 | */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 125 | HPALETTE32 WINAPI CreateHalftonePalette( |
| 126 | HDC32 hdc) /* [in] Handle to device context */ |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 127 | { |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 128 | FIXME(palette,"(%x): stub\n", hdc); |
| 129 | return NULL; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 130 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 131 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 132 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 133 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 134 | * GetPaletteEntries16 (GDI.363) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 135 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 136 | UINT16 WINAPI GetPaletteEntries16( HPALETTE16 hpalette, UINT16 start, |
| 137 | UINT16 count, LPPALETTEENTRY entries ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 138 | { |
| 139 | return GetPaletteEntries32( hpalette, start, count, entries ); |
| 140 | } |
| 141 | |
| 142 | |
| 143 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 144 | * GetPaletteEntries32 [GDI32.209] Retrieves palette entries |
| 145 | * |
| 146 | * RETURNS |
| 147 | * Success: Number of entries from logical palette |
| 148 | * Failure: 0 |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 149 | */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 150 | UINT32 WINAPI GetPaletteEntries32( |
| 151 | HPALETTE32 hpalette, /* [in] Handle of logical palette */ |
| 152 | UINT32 start, /* [in] First entry to receive */ |
| 153 | UINT32 count, /* [in] Number of entries to receive */ |
| 154 | LPPALETTEENTRY entries) /* [out] Address of array receiving entries */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 155 | { |
| 156 | PALETTEOBJ * palPtr; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 157 | INT32 numEntries; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 158 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 159 | TRACE(palette,"hpal = %04x, count=%i\n", hpalette, count ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 160 | |
| 161 | palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC ); |
| 162 | if (!palPtr) return 0; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 163 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 164 | numEntries = palPtr->logpalette.palNumEntries; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 165 | if (start >= numEntries) |
| 166 | { |
| 167 | GDI_HEAP_UNLOCK( hpalette ); |
| 168 | return 0; |
| 169 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 170 | if (start+count > numEntries) count = numEntries - start; |
| 171 | memcpy( entries, &palPtr->logpalette.palPalEntry[start], |
| 172 | count * sizeof(PALETTEENTRY) ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 173 | for( numEntries = 0; numEntries < count ; numEntries++ ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 174 | if (entries[numEntries].peFlags & 0xF0) |
| 175 | entries[numEntries].peFlags = 0; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 176 | GDI_HEAP_UNLOCK( hpalette ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 177 | return count; |
| 178 | } |
| 179 | |
| 180 | |
| 181 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 182 | * SetPaletteEntries16 (GDI.364) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 183 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 184 | UINT16 WINAPI SetPaletteEntries16( HPALETTE16 hpalette, UINT16 start, |
| 185 | UINT16 count, LPPALETTEENTRY entries ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 186 | { |
| 187 | return SetPaletteEntries32( hpalette, start, count, entries ); |
| 188 | } |
| 189 | |
| 190 | |
| 191 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 192 | * SetPaletteEntries32 [GDI32.326] Sets color values for range in palette |
| 193 | * |
| 194 | * RETURNS |
| 195 | * Success: Number of entries that were set |
| 196 | * Failure: 0 |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 197 | */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 198 | UINT32 WINAPI SetPaletteEntries32( |
| 199 | HPALETTE32 hpalette, /* [in] Handle of logical palette */ |
| 200 | UINT32 start, /* [in] Index of first entry to set */ |
| 201 | UINT32 count, /* [in] Number of entries to set */ |
| 202 | LPPALETTEENTRY entries) /* [in] Address of array of structures */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 203 | { |
| 204 | PALETTEOBJ * palPtr; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 205 | INT32 numEntries; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 206 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 207 | TRACE(palette,"hpal=%04x,start=%i,count=%i\n",hpalette,start,count ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 208 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 209 | palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC ); |
| 210 | if (!palPtr) return 0; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 211 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 212 | numEntries = palPtr->logpalette.palNumEntries; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 213 | if (start >= numEntries) |
| 214 | { |
| 215 | GDI_HEAP_UNLOCK( hpalette ); |
| 216 | return 0; |
| 217 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 218 | if (start+count > numEntries) count = numEntries - start; |
| 219 | memcpy( &palPtr->logpalette.palPalEntry[start], entries, |
| 220 | count * sizeof(PALETTEENTRY) ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 221 | PALETTE_ValidateFlags(palPtr->logpalette.palPalEntry, |
| 222 | palPtr->logpalette.palNumEntries); |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 223 | free(palPtr->mapping); |
| 224 | palPtr->mapping = NULL; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 225 | GDI_HEAP_UNLOCK( hpalette ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 226 | return count; |
| 227 | } |
| 228 | |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 229 | |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 230 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 231 | * ResizePalette16 (GDI.368) |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 232 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 233 | BOOL16 WINAPI ResizePalette16( HPALETTE16 hPal, UINT16 cEntries ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 234 | { |
| 235 | return ResizePalette32( hPal, cEntries ); |
| 236 | } |
| 237 | |
| 238 | |
| 239 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 240 | * ResizePalette32 [GDI32.289] Resizes logical palette |
| 241 | * |
| 242 | * RETURNS |
| 243 | * Success: TRUE |
| 244 | * Failure: FALSE |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 245 | */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 246 | BOOL32 WINAPI ResizePalette32( |
| 247 | HPALETTE32 hPal, /* [in] Handle of logical palette */ |
| 248 | UINT32 cEntries) /* [in] Number of entries in logical palette */ |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 249 | { |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 250 | PALETTEOBJ * palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 251 | UINT32 cPrevEnt, prevVer; |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 252 | int prevsize, size = sizeof(LOGPALETTE) + (cEntries - 1) * sizeof(PALETTEENTRY); |
| 253 | int* mapping = NULL; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 254 | |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 255 | TRACE(palette,"hpal = %04x, prev = %i, new = %i\n", |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 256 | hPal, palPtr ? palPtr->logpalette.palNumEntries : -1, |
| 257 | cEntries ); |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 258 | if( !palPtr ) return FALSE; |
| 259 | cPrevEnt = palPtr->logpalette.palNumEntries; |
| 260 | prevVer = palPtr->logpalette.palVersion; |
| 261 | prevsize = sizeof(LOGPALETTE) + (cPrevEnt - 1) * sizeof(PALETTEENTRY) + |
| 262 | sizeof(int*) + sizeof(GDIOBJHDR); |
| 263 | size += sizeof(int*) + sizeof(GDIOBJHDR); |
| 264 | mapping = palPtr->mapping; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 265 | |
| 266 | GDI_HEAP_UNLOCK( hPal ); |
| 267 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 268 | hPal = GDI_HEAP_REALLOC( hPal, size ); |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 269 | palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC ); |
| 270 | if( !palPtr ) return FALSE; |
| 271 | |
| 272 | if( mapping ) |
| 273 | palPtr->mapping = (int*) xrealloc( mapping, cEntries * sizeof(int) ); |
| 274 | if( cEntries > cPrevEnt ) |
| 275 | { |
| 276 | if( mapping ) |
| 277 | memset(palPtr->mapping + cPrevEnt, 0, (cEntries - cPrevEnt)*sizeof(int)); |
| 278 | memset( (BYTE*)palPtr + prevsize, 0, size - prevsize ); |
| 279 | PALETTE_ValidateFlags((PALETTEENTRY*)((BYTE*)palPtr + prevsize), |
| 280 | cEntries - cPrevEnt ); |
| 281 | } |
| 282 | palPtr->logpalette.palNumEntries = cEntries; |
| 283 | palPtr->logpalette.palVersion = prevVer; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 284 | GDI_HEAP_UNLOCK( hPal ); |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 285 | return TRUE; |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 288 | |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 289 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 290 | * AnimatePalette16 (GDI.367) |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 291 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 292 | void WINAPI AnimatePalette16( HPALETTE16 hPal, UINT16 StartIndex, |
| 293 | UINT16 NumEntries, LPPALETTEENTRY PaletteColors) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 294 | { |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 295 | AnimatePalette32( hPal, StartIndex, NumEntries, PaletteColors ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | |
| 299 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 300 | * AnimatePalette32 [GDI32.6] Replaces entries in logical palette |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 301 | * |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 302 | * RETURNS |
| 303 | * Success: TRUE |
| 304 | * Failure: FALSE |
| 305 | * |
| 306 | * FIXME |
| 307 | * Should use existing mapping when animating a primary palette |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 308 | */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 309 | BOOL32 WINAPI AnimatePalette32( |
| 310 | HPALETTE32 hPal, /* [in] Handle to logical palette */ |
| 311 | UINT32 StartIndex, /* [in] First entry in palette */ |
| 312 | UINT32 NumEntries, /* [in] Count of entries in palette */ |
| 313 | LPPALETTEENTRY PaletteColors) /* [in] Pointer to first replacement */ |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 314 | { |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 315 | TRACE(palette, "%04x (%i - %i)\n", hPal, StartIndex,StartIndex+NumEntries); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 316 | |
| 317 | if( hPal != STOCK_DEFAULT_PALETTE ) |
| 318 | { |
| 319 | PALETTEOBJ* palPtr = (PALETTEOBJ *)GDI_GetObjPtr(hPal, PALETTE_MAGIC); |
| 320 | |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 321 | if( (StartIndex + NumEntries) <= palPtr->logpalette.palNumEntries ) |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 322 | { |
| 323 | UINT32 u; |
| 324 | for( u = 0; u < NumEntries; u++ ) |
| 325 | palPtr->logpalette.palPalEntry[u + StartIndex] = PaletteColors[u]; |
| 326 | COLOR_SetMapping(palPtr, StartIndex, NumEntries, |
| 327 | hPal != hPrimaryPalette ); |
| 328 | GDI_HEAP_UNLOCK( hPal ); |
| 329 | return TRUE; |
| 330 | } |
| 331 | } |
| 332 | return FALSE; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 333 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 334 | |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 335 | |
| 336 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 337 | * SetSystemPaletteUse16 (GDI.373) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 338 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 339 | UINT16 WINAPI SetSystemPaletteUse16( HDC16 hdc, UINT16 use ) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 340 | { |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 341 | return SetSystemPaletteUse32( hdc, use ); |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | |
| 345 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 346 | * SetSystemPaletteUse32 [GDI32.335] |
| 347 | * |
| 348 | * RETURNS |
| 349 | * Success: Previous system palette |
| 350 | * Failure: SYSPAL_ERROR |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 351 | */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 352 | UINT32 WINAPI SetSystemPaletteUse32( |
| 353 | HDC32 hdc, /* [in] Handle of device context */ |
| 354 | UINT32 use) /* [in] Palette-usage flag */ |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 355 | { |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 356 | UINT32 old = SystemPaletteUse; |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 357 | FIXME(palette,"(%04x,%04x): stub\n", hdc, use ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 358 | SystemPaletteUse = use; |
| 359 | return old; |
| 360 | } |
| 361 | |
| 362 | |
| 363 | /*********************************************************************** |
| 364 | * GetSystemPaletteUse16 (GDI.374) |
| 365 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 366 | UINT16 WINAPI GetSystemPaletteUse16( HDC16 hdc ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 367 | { |
| 368 | return SystemPaletteUse; |
| 369 | } |
| 370 | |
| 371 | |
| 372 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 373 | * GetSystemPaletteUse32 [GDI32.223] Gets state of system palette |
| 374 | * |
| 375 | * RETURNS |
| 376 | * Current state of system palette |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 377 | */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 378 | UINT32 WINAPI GetSystemPaletteUse32( |
| 379 | HDC32 hdc) /* [in] Handle of device context */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 380 | { |
| 381 | return SystemPaletteUse; |
| 382 | } |
| 383 | |
| 384 | |
| 385 | /*********************************************************************** |
| 386 | * GetSystemPaletteEntries16 (GDI.375) |
| 387 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 388 | UINT16 WINAPI GetSystemPaletteEntries16( HDC16 hdc, UINT16 start, UINT16 count, |
| 389 | LPPALETTEENTRY entries ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 390 | { |
| 391 | return GetSystemPaletteEntries32( hdc, start, count, entries ); |
| 392 | } |
| 393 | |
| 394 | |
| 395 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 396 | * GetSystemPaletteEntries32 [GDI32.222] Gets range of palette entries |
| 397 | * |
| 398 | * RETURNS |
| 399 | * Success: Number of entries retrieved from palette |
| 400 | * Failure: 0 |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 401 | */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 402 | UINT32 WINAPI GetSystemPaletteEntries32( |
| 403 | HDC32 hdc, /* [in] Handle of device context */ |
| 404 | UINT32 start, /* [in] Index of first entry to be retrieved */ |
| 405 | UINT32 count, /* [in] Number of entries to be retrieved */ |
| 406 | LPPALETTEENTRY entries) /* [out] Array receiving system-palette entries */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 407 | { |
| 408 | UINT32 i; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 409 | DC *dc; |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 410 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 411 | TRACE(palette, "hdc=%04x,start=%i,count=%i\n", hdc,start,count); |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 412 | |
| 413 | if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return 0; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 414 | if (start >= dc->w.devCaps->sizePalette) |
| 415 | { |
| 416 | GDI_HEAP_UNLOCK( hdc ); |
| 417 | return 0; |
| 418 | } |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 419 | if (start+count >= dc->w.devCaps->sizePalette) |
| 420 | count = dc->w.devCaps->sizePalette - start; |
| 421 | for (i = 0; i < count; i++) |
| 422 | { |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 423 | *(COLORREF*)(entries + i) = COLOR_GetSystemPaletteEntry( start + i ); |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 424 | |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 425 | TRACE(palette,"\tidx(%02x) -> RGB(%08lx)\n", |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 426 | start + i, *(COLORREF*)(entries + i) ); |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 427 | } |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 428 | GDI_HEAP_UNLOCK( hdc ); |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 429 | return count; |
| 430 | } |
| 431 | |
| 432 | |
| 433 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 434 | * GetNearestPaletteIndex16 (GDI.370) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 435 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 436 | UINT16 WINAPI GetNearestPaletteIndex16( HPALETTE16 hpalette, COLORREF color ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 437 | { |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 438 | return GetNearestPaletteIndex32( hpalette, color ); |
| 439 | } |
| 440 | |
| 441 | |
| 442 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 443 | * GetNearestPaletteIndex32 [GDI32.203] Gets palette index for color |
| 444 | * |
| 445 | * NOTES |
| 446 | * Should index be initialized to CLR_INVALID instead of 0? |
| 447 | * |
| 448 | * RETURNS |
| 449 | * Success: Index of entry in logical palette |
| 450 | * Failure: CLR_INVALID |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 451 | */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 452 | UINT32 WINAPI GetNearestPaletteIndex32( |
| 453 | HPALETTE32 hpalette, /* [in] Handle of logical color palette */ |
| 454 | COLORREF color) /* [in] Color to be matched */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 455 | { |
| 456 | PALETTEOBJ* palObj = (PALETTEOBJ*)GDI_GetObjPtr( hpalette, PALETTE_MAGIC ); |
| 457 | UINT32 index = 0; |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 458 | |
| 459 | if( palObj ) |
| 460 | index = COLOR_PaletteLookupPixel( palObj->logpalette.palPalEntry, |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 461 | palObj->logpalette.palNumEntries, |
| 462 | NULL, color, FALSE ); |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 463 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 464 | TRACE(palette,"(%04x,%06lx): returning %d\n", hpalette, color, index ); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 465 | GDI_HEAP_UNLOCK( hpalette ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 466 | return index; |
| 467 | } |
| 468 | |
| 469 | |
| 470 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 471 | * GetNearestColor16 (GDI.154) |
Alexandre Julliard | 902da69 | 1995-11-05 14:39:02 +0000 | [diff] [blame] | 472 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 473 | COLORREF WINAPI GetNearestColor16( HDC16 hdc, COLORREF color ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 474 | { |
| 475 | return GetNearestColor32( hdc, color ); |
| 476 | } |
| 477 | |
| 478 | |
| 479 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 480 | * GetNearestColor32 [GDI32.202] Gets a system color to match |
| 481 | * |
| 482 | * NOTES |
| 483 | * Should this return CLR_INVALID instead of FadeCafe? |
| 484 | * |
| 485 | * RETURNS |
| 486 | * Success: Color from system palette that corresponds to given color |
| 487 | * Failure: CLR_INVALID |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 488 | */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 489 | COLORREF WINAPI GetNearestColor32( |
| 490 | HDC32 hdc, /* [in] Handle of device context */ |
| 491 | COLORREF color) /* [in] Color to be matched */ |
Alexandre Julliard | 902da69 | 1995-11-05 14:39:02 +0000 | [diff] [blame] | 492 | { |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 493 | COLORREF nearest = 0xFADECAFE; |
| 494 | DC *dc; |
| 495 | PALETTEOBJ *palObj; |
Alexandre Julliard | 902da69 | 1995-11-05 14:39:02 +0000 | [diff] [blame] | 496 | |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 497 | if ( (dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC )) ) |
| 498 | { |
| 499 | palObj = (PALETTEOBJ*) |
| 500 | GDI_GetObjPtr( (dc->w.hPalette)? dc->w.hPalette |
| 501 | : STOCK_DEFAULT_PALETTE, PALETTE_MAGIC ); |
| 502 | |
| 503 | nearest = COLOR_LookupNearestColor( palObj->logpalette.palPalEntry, |
| 504 | palObj->logpalette.palNumEntries, color ); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 505 | GDI_HEAP_UNLOCK( dc->w.hPalette ); |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 508 | TRACE(palette,"(%06lx): returning %06lx\n", color, nearest ); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 509 | GDI_HEAP_UNLOCK( hdc ); |
Alexandre Julliard | 902da69 | 1995-11-05 14:39:02 +0000 | [diff] [blame] | 510 | return nearest; |
| 511 | } |
| 512 | |
| 513 | |
| 514 | /*********************************************************************** |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 515 | * PALETTE_GetObject |
| 516 | */ |
| 517 | int PALETTE_GetObject( PALETTEOBJ * palette, int count, LPSTR buffer ) |
| 518 | { |
| 519 | if (count > sizeof(WORD)) count = sizeof(WORD); |
| 520 | memcpy( buffer, &palette->logpalette.palNumEntries, count ); |
| 521 | return count; |
| 522 | } |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 523 | |
| 524 | |
| 525 | /*********************************************************************** |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 526 | * PALETTE_UnrealizeObject |
| 527 | */ |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 528 | BOOL32 PALETTE_UnrealizeObject( HPALETTE16 hpalette, PALETTEOBJ *palette ) |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 529 | { |
| 530 | if (palette->mapping) |
| 531 | { |
| 532 | free( palette->mapping ); |
| 533 | palette->mapping = NULL; |
| 534 | } |
| 535 | if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0; |
| 536 | return TRUE; |
| 537 | } |
| 538 | |
| 539 | |
| 540 | /*********************************************************************** |
| 541 | * PALETTE_DeleteObject |
| 542 | */ |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 543 | BOOL32 PALETTE_DeleteObject( HPALETTE16 hpalette, PALETTEOBJ *palette ) |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 544 | { |
| 545 | free( palette->mapping ); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 546 | if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 547 | return GDI_FreeObject( hpalette ); |
| 548 | } |
| 549 | |
| 550 | |
| 551 | /*********************************************************************** |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 552 | * GDISelectPalette (GDI.361) |
| 553 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 554 | HPALETTE16 WINAPI GDISelectPalette( HDC16 hdc, HPALETTE16 hpal, WORD wBkg) |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 555 | { |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 556 | HPALETTE16 prev; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 557 | DC *dc; |
| 558 | |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 559 | TRACE(palette, "%04x %04x\n", hdc, hpal ); |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 560 | |
| 561 | dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ); |
| 562 | if (!dc) |
| 563 | { |
| 564 | dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC); |
| 565 | if (!dc) return 0; |
| 566 | } |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 567 | prev = dc->w.hPalette; |
| 568 | dc->w.hPalette = hpal; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 569 | GDI_HEAP_UNLOCK( hdc ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 570 | if (!wBkg) hPrimaryPalette = hpal; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 571 | return prev; |
| 572 | } |
| 573 | |
| 574 | |
| 575 | /*********************************************************************** |
| 576 | * GDIRealizePalette (GDI.362) |
| 577 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 578 | UINT16 WINAPI GDIRealizePalette( HDC16 hdc ) |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 579 | { |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 580 | PALETTEOBJ* palPtr; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 581 | int realized = 0; |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 582 | DC* dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ); |
| 583 | if (!dc) |
| 584 | { |
| 585 | dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC); |
| 586 | if (!dc) return 0; |
| 587 | } |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 588 | |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 589 | TRACE(palette, "%04x...\n", hdc ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 590 | |
| 591 | if( dc && dc->w.hPalette != hLastRealizedPalette ) |
| 592 | { |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 593 | if( dc->w.hPalette == STOCK_DEFAULT_PALETTE ) |
| 594 | return RealizeDefaultPalette( hdc ); |
| 595 | |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 596 | palPtr = (PALETTEOBJ *) GDI_GetObjPtr( dc->w.hPalette, PALETTE_MAGIC ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 597 | |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 598 | realized = COLOR_SetMapping(palPtr,0,palPtr->logpalette.palNumEntries, |
| 599 | (dc->w.hPalette != hPrimaryPalette) || |
| 600 | (dc->w.hPalette == STOCK_DEFAULT_PALETTE)); |
| 601 | GDI_HEAP_UNLOCK( dc->w.hPalette ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 602 | hLastRealizedPalette = dc->w.hPalette; |
| 603 | } |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 604 | else TRACE(palette, " skipping (hLastRealizedPalette = %04x)\n", |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 605 | hLastRealizedPalette); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 606 | GDI_HEAP_UNLOCK( hdc ); |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 607 | |
| 608 | TRACE(palette, " realized %i colors.\n", realized ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 609 | return (UINT16)realized; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | |
| 613 | /*********************************************************************** |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 614 | * RealizeDefaultPalette (GDI.365) |
| 615 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 616 | UINT16 WINAPI RealizeDefaultPalette( HDC16 hdc ) |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 617 | { |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 618 | DC *dc; |
| 619 | PALETTEOBJ* palPtr; |
| 620 | int i, index, realized = 0; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 621 | |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 622 | TRACE(palette,"%04x\n", hdc ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 623 | |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 624 | dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ); |
| 625 | if (!dc) |
| 626 | { |
| 627 | dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC); |
| 628 | if (!dc) return 0; |
| 629 | } |
| 630 | |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 631 | if ( dc->w.flags & DC_MEMORY ) |
| 632 | { |
| 633 | GDI_HEAP_UNLOCK( hdc ); |
| 634 | return 0; |
| 635 | } |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 636 | |
| 637 | hPrimaryPalette = STOCK_DEFAULT_PALETTE; |
| 638 | hLastRealizedPalette = STOCK_DEFAULT_PALETTE; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 639 | |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 640 | palPtr = (PALETTEOBJ*)GDI_GetObjPtr(STOCK_DEFAULT_PALETTE, PALETTE_MAGIC ); |
| 641 | |
| 642 | /* lookup is needed to account for SetSystemPaletteUse() stuff */ |
| 643 | |
| 644 | for( i = 0; i < 20; i++ ) |
| 645 | { |
| 646 | index = COLOR_LookupSystemPixel(*(COLORREF*)(palPtr->logpalette.palPalEntry + i)); |
| 647 | |
| 648 | /* mapping is allocated in COLOR_InitPalette() */ |
| 649 | |
| 650 | if( index != palPtr->mapping[i] ) { palPtr->mapping[i]=index; realized++; } |
| 651 | } |
| 652 | return realized; |
| 653 | } |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 654 | |
| 655 | /*********************************************************************** |
| 656 | * IsDCCurrentPalette (GDI.412) |
| 657 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 658 | BOOL16 WINAPI IsDCCurrentPalette(HDC16 hDC) |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 659 | { |
| 660 | DC* dc = (DC *)GDI_GetObjPtr( hDC, DC_MAGIC ); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 661 | if (dc) |
| 662 | { |
| 663 | GDI_HEAP_UNLOCK( hDC ); |
| 664 | return dc->w.hPalette == hPrimaryPalette; |
| 665 | } |
| 666 | return FALSE; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 667 | } |
| 668 | |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 669 | |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 670 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 671 | * SelectPalette16 (USER.282) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 672 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 673 | HPALETTE16 WINAPI SelectPalette16( HDC16 hDC, HPALETTE16 hPal, |
| 674 | BOOL16 bForceBackground ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 675 | { |
| 676 | return SelectPalette32( hDC, hPal, bForceBackground ); |
| 677 | } |
| 678 | |
| 679 | |
| 680 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 681 | * SelectPalette32 [GDI32.300] Selects logical palette into DC |
| 682 | * |
| 683 | * RETURNS |
| 684 | * Success: Previous logical palette |
| 685 | * Failure: NULL |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 686 | */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 687 | HPALETTE32 WINAPI SelectPalette32( |
| 688 | HDC32 hDC, /* [in] Handle of device context */ |
| 689 | HPALETTE32 hPal, /* [in] Handle of logical color palette */ |
| 690 | BOOL32 bForceBackground) /* [in] Foreground/background mode */ |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 691 | { |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 692 | WORD wBkgPalette = 1; |
| 693 | PALETTEOBJ* lpt = (PALETTEOBJ*) GDI_GetObjPtr( hPal, PALETTE_MAGIC ); |
| 694 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 695 | TRACE(palette,"dc=%04x,pal=%04x,force=%i\n", hDC, hPal, bForceBackground); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 696 | if( !lpt ) return 0; |
| 697 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 698 | TRACE(palette," entries = %d\n", lpt->logpalette.palNumEntries); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 699 | GDI_HEAP_UNLOCK( hPal ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 700 | |
| 701 | if( hPal != STOCK_DEFAULT_PALETTE ) |
| 702 | { |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 703 | HWND32 hWnd = WindowFromDC32( hDC ); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 704 | HWND32 hActive = GetActiveWindow32(); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 705 | |
| 706 | /* set primary palette if it's related to current active */ |
| 707 | |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 708 | if((!hWnd || (hActive == hWnd || IsChild16(hActive,hWnd))) && |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 709 | !bForceBackground ) |
| 710 | wBkgPalette = 0; |
| 711 | } |
| 712 | return GDISelectPalette( hDC, hPal, wBkgPalette); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 713 | } |
| 714 | |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 715 | |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 716 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 717 | * RealizePalette16 (USER.283) |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 718 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 719 | UINT16 WINAPI RealizePalette16( HDC16 hDC ) |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 720 | { |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 721 | return RealizePalette32( hDC ); |
| 722 | } |
| 723 | |
| 724 | |
| 725 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 726 | * RealizePalette32 [GDI32.280] Maps palette entries to system palette |
| 727 | * |
| 728 | * RETURNS |
| 729 | * Success: Number of entries in logical palette |
| 730 | * Failure: GDI_ERROR |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 731 | */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 732 | UINT32 WINAPI RealizePalette32( |
| 733 | HDC32 hDC) /* [in] Handle of device context */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 734 | { |
| 735 | UINT32 realized = GDIRealizePalette( hDC ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 736 | |
| 737 | /* do not send anything if no colors were changed */ |
| 738 | |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 739 | if( IsDCCurrentPalette( hDC ) && realized && |
| 740 | !(COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL) ) |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 741 | { |
| 742 | /* Send palette change notification */ |
| 743 | |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 744 | HWND32 hWnd; |
| 745 | if( (hWnd = WindowFromDC32( hDC )) ) |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 746 | SendMessage16( HWND_BROADCAST, WM_PALETTECHANGED, hWnd, 0L); |
| 747 | } |
| 748 | return realized; |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 752 | /********************************************************************** |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 753 | * UpdateColors16 (GDI.366) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 754 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 755 | INT16 WINAPI UpdateColors16( HDC16 hDC ) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 756 | { |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 757 | HWND32 hWnd = WindowFromDC32( hDC ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 758 | |
| 759 | /* Docs say that we have to remap current drawable pixel by pixel |
| 760 | * but it would take forever given the speed of XGet/PutPixel. |
| 761 | */ |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 762 | if (hWnd && !(COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL) ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 763 | InvalidateRect32( hWnd, NULL, FALSE ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 764 | return 0x666; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 765 | } |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 766 | |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 767 | |
| 768 | /********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 769 | * UpdateColors32 [GDI32.359] Remaps current colors to logical palette |
| 770 | * |
| 771 | * RETURNS |
| 772 | * Success: TRUE |
| 773 | * Failure: FALSE |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 774 | */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 775 | BOOL32 WINAPI UpdateColors32( |
| 776 | HDC32 hDC) /* [in] Handle of device context */ |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 777 | { |
| 778 | UpdateColors16( hDC ); |
| 779 | return TRUE; |
| 780 | } |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame^] | 781 | |