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 | 59730ae | 1996-03-24 16:20:51 +0000 | [diff] [blame] | 7 | */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 8 | #include <stdlib.h> |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 9 | #include <string.h> |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 10 | #include <X11/Xlib.h> |
Alexandre Julliard | 59730ae | 1996-03-24 16:20:51 +0000 | [diff] [blame] | 11 | |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 12 | #include "color.h" |
Alexandre Julliard | 7cbe657 | 1995-01-09 18:21:16 +0000 | [diff] [blame] | 13 | #include "palette.h" |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 14 | #include "stddebug.h" |
Alexandre Julliard | ecc3712 | 1994-11-22 16:31:29 +0000 | [diff] [blame] | 15 | /* #define DEBUG_PALETTE */ |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 16 | #include "debug.h" |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 17 | |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 18 | extern HWND DCE_hDC2hWnd( HDC ); /* get associated window by |
| 19 | * walking DCE list */ |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame^] | 20 | extern int COLOR_LookupSystemPixel(COLORREF); /* lookup pixel among static entries |
| 21 | * of the system palette */ |
| 22 | extern COLORREF COLOR_GetSystemPaletteEntry(BYTE); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 23 | |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 24 | static WORD SystemPaletteUse = SYSPAL_STATIC; /* currently not considered */ |
| 25 | |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 26 | static HPALETTE16 hPrimaryPalette = 0; /* used for WM_PALETTECHANGED */ |
| 27 | static HPALETTE16 hLastRealizedPalette = 0; /* UnrealizeObject() needs it */ |
| 28 | |
Alexandre Julliard | 902da69 | 1995-11-05 14:39:02 +0000 | [diff] [blame] | 29 | |
| 30 | /*********************************************************************** |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 31 | * PALETTE_ValidateFlags |
| 32 | */ |
| 33 | void PALETTE_ValidateFlags(PALETTEENTRY* lpPalE, int size) |
| 34 | { |
| 35 | int i = 0; |
| 36 | for( ; i<size ; i++ ) |
| 37 | lpPalE[i].peFlags = PC_SYS_USED | (lpPalE[i].peFlags & 0x07); |
| 38 | } |
| 39 | |
| 40 | |
| 41 | /*********************************************************************** |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 42 | * CreatePalette (GDI.360) |
| 43 | */ |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 44 | HPALETTE16 CreatePalette( const LOGPALETTE* palette ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 45 | { |
| 46 | PALETTEOBJ * palettePtr; |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 47 | HPALETTE16 hpalette; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 48 | int size = sizeof(LOGPALETTE) + (palette->palNumEntries - 1) * sizeof(PALETTEENTRY); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 49 | |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 50 | dprintf_palette(stddeb,"CreatePalette: "); |
| 51 | |
| 52 | dprintf_palette(stddeb,"%i entries, ", palette->palNumEntries); |
| 53 | |
| 54 | hpalette = GDI_AllocObject( size + sizeof(int*) +sizeof(GDIOBJHDR) , PALETTE_MAGIC ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 55 | if (!hpalette) return 0; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 56 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 57 | palettePtr = (PALETTEOBJ *) GDI_HEAP_LIN_ADDR( hpalette ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 58 | memcpy( &palettePtr->logpalette, palette, size ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 59 | PALETTE_ValidateFlags(palettePtr->logpalette.palPalEntry, |
| 60 | palettePtr->logpalette.palNumEntries); |
| 61 | palettePtr->mapping = NULL; |
| 62 | |
| 63 | dprintf_palette(stddeb,"returning %04x\n", hpalette); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 64 | return hpalette; |
| 65 | } |
| 66 | |
| 67 | |
| 68 | /*********************************************************************** |
| 69 | * GetPaletteEntries (GDI.363) |
| 70 | */ |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 71 | WORD GetPaletteEntries( HPALETTE16 hpalette, WORD start, WORD count, |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 72 | LPPALETTEENTRY entries ) |
| 73 | { |
| 74 | PALETTEOBJ * palPtr; |
| 75 | int numEntries; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 76 | |
| 77 | dprintf_palette(stddeb,"GetPaletteEntries: hpal = %04x, %i entries\n", hpalette, count); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 78 | |
| 79 | palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC ); |
| 80 | if (!palPtr) return 0; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 81 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 82 | numEntries = palPtr->logpalette.palNumEntries; |
| 83 | if (start >= numEntries) return 0; |
| 84 | if (start+count > numEntries) count = numEntries - start; |
| 85 | memcpy( entries, &palPtr->logpalette.palPalEntry[start], |
| 86 | count * sizeof(PALETTEENTRY) ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 87 | for( numEntries = 0; numEntries < count ; numEntries++ ) |
| 88 | if( entries[numEntries].peFlags & 0xF0 ) entries[numEntries].peFlags = 0; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 89 | return count; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | /*********************************************************************** |
| 94 | * SetPaletteEntries (GDI.364) |
| 95 | */ |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 96 | WORD SetPaletteEntries( HPALETTE16 hpalette, WORD start, WORD count, |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 97 | LPPALETTEENTRY entries ) |
| 98 | { |
| 99 | PALETTEOBJ * palPtr; |
| 100 | int numEntries; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 101 | |
| 102 | dprintf_palette(stddeb,"SetPaletteEntries: hpal = %04x, %i entries\n", hpalette, count); |
| 103 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 104 | palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hpalette, PALETTE_MAGIC ); |
| 105 | if (!palPtr) return 0; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 106 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 107 | numEntries = palPtr->logpalette.palNumEntries; |
| 108 | if (start >= numEntries) return 0; |
| 109 | if (start+count > numEntries) count = numEntries - start; |
| 110 | memcpy( &palPtr->logpalette.palPalEntry[start], entries, |
| 111 | count * sizeof(PALETTEENTRY) ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 112 | PALETTE_ValidateFlags(palPtr->logpalette.palPalEntry, |
| 113 | palPtr->logpalette.palNumEntries); |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame^] | 114 | free(palPtr->mapping); |
| 115 | palPtr->mapping = NULL; |
| 116 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 117 | return count; |
| 118 | } |
| 119 | |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 120 | /*********************************************************************** |
| 121 | * ResizePalette (GDI.368) |
| 122 | */ |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 123 | BOOL ResizePalette(HPALETTE16 hPal, UINT cEntries) |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 124 | { |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 125 | |
| 126 | /* should simply realloc memory and zero out |
| 127 | * added entries, if any */ |
| 128 | |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 129 | fprintf(stdnimp,"ResizePalette: empty stub! \n"); |
| 130 | return FALSE; |
| 131 | } |
| 132 | |
| 133 | /*********************************************************************** |
| 134 | * AnimatePalette (GDI.367) |
| 135 | */ |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 136 | BOOL AnimatePalette(HPALETTE16 hPal, UINT StartIndex, UINT NumEntries, |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 137 | LPPALETTEENTRY PaletteColors) |
| 138 | { |
| 139 | fprintf(stdnimp,"AnimatePalette: empty stub! \n"); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 140 | return TRUE; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 141 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 142 | |
| 143 | /*********************************************************************** |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 144 | * SetSystemPaletteUse (GDI.373) |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 145 | */ |
| 146 | WORD SetSystemPaletteUse( HDC hdc, WORD use) |
| 147 | { |
| 148 | WORD old=SystemPaletteUse; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 149 | fprintf(stdnimp,"SetSystemPaletteUse(%04x,%04x) // empty stub !!!\n", hdc, use); |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 150 | SystemPaletteUse=use; |
| 151 | return old; |
| 152 | } |
| 153 | |
| 154 | /*********************************************************************** |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 155 | * GetSystemPaletteUse (GDI.374) |
| 156 | */ |
| 157 | WORD GetSystemPaletteUse( HDC hdc ) |
| 158 | { |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 159 | fprintf(stdnimp,"GetSystemPaletteUse(%04x) // empty stub !!!\n", hdc); |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 160 | return SystemPaletteUse; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | |
| 164 | /*********************************************************************** |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 165 | * GetSystemPaletteEntries (GDI.375) |
| 166 | */ |
| 167 | WORD GetSystemPaletteEntries( HDC hdc, WORD start, WORD count, |
| 168 | LPPALETTEENTRY entries ) |
| 169 | { |
| 170 | WORD i; |
| 171 | DC *dc; |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame^] | 172 | |
| 173 | dprintf_palette(stddeb,"GetSystemPaletteEntries: hdc = %04x, cound = %i", hdc, count ); |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 174 | |
| 175 | if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return 0; |
| 176 | if (start >= dc->w.devCaps->sizePalette) return 0; |
| 177 | if (start+count >= dc->w.devCaps->sizePalette) |
| 178 | count = dc->w.devCaps->sizePalette - start; |
| 179 | for (i = 0; i < count; i++) |
| 180 | { |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame^] | 181 | *(COLORREF*)(entries + i) = COLOR_GetSystemPaletteEntry((BYTE)(start + i)); |
| 182 | |
| 183 | dprintf_palette(stddeb,"\tidx(%02x) -> RGB(%08lx)\n", (unsigned char)(start + i), |
| 184 | *(COLORREF*)(entries + i) ); |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 185 | } |
| 186 | return count; |
| 187 | } |
| 188 | |
| 189 | |
| 190 | /*********************************************************************** |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 191 | * GetNearestPaletteIndex (GDI.370) |
| 192 | */ |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 193 | WORD GetNearestPaletteIndex( HPALETTE16 hpalette, COLORREF color ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 194 | { |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame^] | 195 | PALETTEOBJ* palObj = (PALETTEOBJ*) GDI_GetObjPtr( hpalette, PALETTE_MAGIC ); |
| 196 | WORD index = 0; |
| 197 | |
| 198 | if( palObj ) |
| 199 | index = COLOR_PaletteLookupPixel( palObj->logpalette.palPalEntry, |
| 200 | palObj->logpalette.palNumEntries, NULL, |
| 201 | color, FALSE ); |
| 202 | |
Alexandre Julliard | 59730ae | 1996-03-24 16:20:51 +0000 | [diff] [blame] | 203 | dprintf_palette(stddeb,"GetNearestPaletteIndex(%04x,%06lx): returning %d\n", |
Alexandre Julliard | 902da69 | 1995-11-05 14:39:02 +0000 | [diff] [blame] | 204 | hpalette, color, index ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 205 | return index; |
| 206 | } |
| 207 | |
| 208 | |
| 209 | /*********************************************************************** |
Alexandre Julliard | 902da69 | 1995-11-05 14:39:02 +0000 | [diff] [blame] | 210 | * GetNearestColor (GDI.154) |
| 211 | */ |
| 212 | COLORREF GetNearestColor( HDC hdc, COLORREF color ) |
| 213 | { |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame^] | 214 | COLORREF nearest = 0xFADECAFE; |
| 215 | DC *dc; |
| 216 | PALETTEOBJ *palObj; |
Alexandre Julliard | 902da69 | 1995-11-05 14:39:02 +0000 | [diff] [blame] | 217 | |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame^] | 218 | if ( (dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC )) ) |
| 219 | { |
| 220 | palObj = (PALETTEOBJ*) |
| 221 | GDI_GetObjPtr( (dc->w.hPalette)? dc->w.hPalette |
| 222 | : STOCK_DEFAULT_PALETTE, PALETTE_MAGIC ); |
| 223 | |
| 224 | nearest = COLOR_LookupNearestColor( palObj->logpalette.palPalEntry, |
| 225 | palObj->logpalette.palNumEntries, color ); |
| 226 | } |
| 227 | |
Alexandre Julliard | 902da69 | 1995-11-05 14:39:02 +0000 | [diff] [blame] | 228 | dprintf_palette(stddeb,"GetNearestColor(%06lx): returning %06lx\n", |
| 229 | color, nearest ); |
| 230 | return nearest; |
| 231 | } |
| 232 | |
| 233 | |
| 234 | /*********************************************************************** |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 235 | * PALETTE_GetObject |
| 236 | */ |
| 237 | int PALETTE_GetObject( PALETTEOBJ * palette, int count, LPSTR buffer ) |
| 238 | { |
| 239 | if (count > sizeof(WORD)) count = sizeof(WORD); |
| 240 | memcpy( buffer, &palette->logpalette.palNumEntries, count ); |
| 241 | return count; |
| 242 | } |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 243 | |
| 244 | |
| 245 | /*********************************************************************** |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 246 | * PALETTE_UnrealizeObject |
| 247 | */ |
| 248 | BOOL PALETTE_UnrealizeObject( HPALETTE16 hpalette, PALETTEOBJ *palette ) |
| 249 | { |
| 250 | if (palette->mapping) |
| 251 | { |
| 252 | free( palette->mapping ); |
| 253 | palette->mapping = NULL; |
| 254 | } |
| 255 | if (hLastRealizedPalette == hpalette) hLastRealizedPalette = 0; |
| 256 | return TRUE; |
| 257 | } |
| 258 | |
| 259 | |
| 260 | /*********************************************************************** |
| 261 | * PALETTE_DeleteObject |
| 262 | */ |
| 263 | BOOL PALETTE_DeleteObject( HPALETTE16 hpalette, PALETTEOBJ *palette ) |
| 264 | { |
| 265 | free( palette->mapping ); |
| 266 | return GDI_FreeObject( hpalette ); |
| 267 | } |
| 268 | |
| 269 | |
| 270 | /*********************************************************************** |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 271 | * GDISelectPalette (GDI.361) |
| 272 | */ |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 273 | HPALETTE16 GDISelectPalette( HDC hdc, HPALETTE16 hpal, WORD wBkg) |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 274 | { |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 275 | HPALETTE16 prev; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 276 | DC *dc; |
| 277 | |
Alexandre Julliard | 59730ae | 1996-03-24 16:20:51 +0000 | [diff] [blame] | 278 | dprintf_palette(stddeb, "GDISelectPalette: %04x %04x\n", hdc, hpal ); |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame^] | 279 | |
| 280 | dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ); |
| 281 | if (!dc) |
| 282 | { |
| 283 | dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC); |
| 284 | if (!dc) return 0; |
| 285 | } |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 286 | prev = dc->w.hPalette; |
| 287 | dc->w.hPalette = hpal; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 288 | if (!wBkg) hPrimaryPalette = hpal; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 289 | return prev; |
| 290 | } |
| 291 | |
| 292 | |
| 293 | /*********************************************************************** |
| 294 | * GDIRealizePalette (GDI.362) |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 295 | * |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 296 | */ |
| 297 | UINT GDIRealizePalette( HDC hdc ) |
| 298 | { |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 299 | PALETTEOBJ* palPtr; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 300 | int realized = 0; |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame^] | 301 | DC* dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ); |
| 302 | if (!dc) |
| 303 | { |
| 304 | dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC); |
| 305 | if (!dc) return 0; |
| 306 | } |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 307 | |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 308 | dprintf_palette(stddeb, "GDIRealizePalette: %04x...", hdc ); |
| 309 | |
| 310 | if( dc && dc->w.hPalette != hLastRealizedPalette ) |
| 311 | { |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame^] | 312 | if( dc->w.hPalette == STOCK_DEFAULT_PALETTE ) |
| 313 | return RealizeDefaultPalette( hdc ); |
| 314 | |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 315 | palPtr = (PALETTEOBJ *) GDI_GetObjPtr( dc->w.hPalette, PALETTE_MAGIC ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 316 | |
| 317 | realized = COLOR_SetMapping(palPtr, dc->w.hPalette != hPrimaryPalette |
| 318 | || dc->w.hPalette == STOCK_DEFAULT_PALETTE ); |
| 319 | hLastRealizedPalette = dc->w.hPalette; |
| 320 | } |
| 321 | else dprintf_palette(stddeb, " skipping "); |
| 322 | |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 323 | dprintf_palette(stdnimp, " realized %i colors\n", realized ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 324 | return (UINT)realized; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | |
| 328 | /*********************************************************************** |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 329 | * RealizeDefaultPalette (GDI.365) |
| 330 | */ |
| 331 | WORD RealizeDefaultPalette( HDC hdc ) |
| 332 | { |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame^] | 333 | DC *dc; |
| 334 | PALETTEOBJ* palPtr; |
| 335 | int i, index, realized = 0; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 336 | |
| 337 | dprintf_palette(stddeb,"RealizeDefaultPalette: %04x\n", hdc ); |
| 338 | |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame^] | 339 | dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ); |
| 340 | if (!dc) |
| 341 | { |
| 342 | dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC); |
| 343 | if (!dc) return 0; |
| 344 | } |
| 345 | |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 346 | if ( dc->w.flags & DC_MEMORY ) return 0; |
| 347 | |
| 348 | hPrimaryPalette = STOCK_DEFAULT_PALETTE; |
| 349 | hLastRealizedPalette = STOCK_DEFAULT_PALETTE; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 350 | |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame^] | 351 | palPtr = (PALETTEOBJ*)GDI_GetObjPtr(STOCK_DEFAULT_PALETTE, PALETTE_MAGIC ); |
| 352 | |
| 353 | /* lookup is needed to account for SetSystemPaletteUse() stuff */ |
| 354 | |
| 355 | for( i = 0; i < 20; i++ ) |
| 356 | { |
| 357 | index = COLOR_LookupSystemPixel(*(COLORREF*)(palPtr->logpalette.palPalEntry + i)); |
| 358 | |
| 359 | /* mapping is allocated in COLOR_InitPalette() */ |
| 360 | |
| 361 | if( index != palPtr->mapping[i] ) { palPtr->mapping[i]=index; realized++; } |
| 362 | } |
| 363 | return realized; |
| 364 | } |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 365 | |
| 366 | /*********************************************************************** |
| 367 | * IsDCCurrentPalette (GDI.412) |
| 368 | */ |
| 369 | BOOL IsDCCurrentPalette(HDC hDC) |
| 370 | { |
| 371 | DC* dc = (DC *)GDI_GetObjPtr( hDC, DC_MAGIC ); |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame^] | 372 | return (dc)?(dc->w.hPalette == hPrimaryPalette):FALSE; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | /*********************************************************************** |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 376 | * SelectPalette (USER.282) |
| 377 | */ |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 378 | HPALETTE16 SelectPalette( HDC hDC, HPALETTE16 hPal, BOOL bForceBackground ) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 379 | { |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 380 | WORD wBkgPalette = 1; |
| 381 | PALETTEOBJ* lpt = (PALETTEOBJ*) GDI_GetObjPtr( hPal, PALETTE_MAGIC ); |
| 382 | |
| 383 | dprintf_palette(stddeb,"SelectPalette: dc %04x pal %04x, force=%i ", |
| 384 | hDC, hPal, bForceBackground); |
| 385 | if( !lpt ) return 0; |
| 386 | |
| 387 | dprintf_palette(stddeb," entries = %d\n", |
| 388 | lpt->logpalette.palNumEntries); |
| 389 | |
| 390 | if( hPal != STOCK_DEFAULT_PALETTE ) |
| 391 | { |
| 392 | HWND hWnd = DCE_hDC2hWnd( hDC ); |
| 393 | HWND hActive = GetActiveWindow(); |
| 394 | |
| 395 | /* set primary palette if it's related to current active */ |
| 396 | |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame^] | 397 | if((!hWnd || (hActive == hWnd || IsChild(hActive,hWnd))) && |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 398 | !bForceBackground ) |
| 399 | wBkgPalette = 0; |
| 400 | } |
| 401 | return GDISelectPalette( hDC, hPal, wBkgPalette); |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 402 | } |
| 403 | |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 404 | |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 405 | /*********************************************************************** |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 406 | * RealizePalette (USER.283) (GDI32.280) |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 407 | */ |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 408 | UINT16 RealizePalette( HDC32 hDC ) |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 409 | { |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 410 | UINT16 realized = GDIRealizePalette( hDC ); |
| 411 | |
| 412 | /* do not send anything if no colors were changed */ |
| 413 | |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame^] | 414 | if( IsDCCurrentPalette( hDC ) && realized && |
| 415 | !(COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL) ) |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 416 | { |
| 417 | /* Send palette change notification */ |
| 418 | |
| 419 | HWND hWnd; |
| 420 | if( (hWnd = DCE_hDC2hWnd( hDC )) ) |
| 421 | SendMessage16( HWND_BROADCAST, WM_PALETTECHANGED, hWnd, 0L); |
| 422 | } |
| 423 | return realized; |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 427 | /********************************************************************** |
| 428 | * UpdateColors (GDI.366) |
| 429 | * |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 430 | */ |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 431 | int UpdateColors( HDC hDC ) |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 432 | { |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 433 | HWND hWnd = DCE_hDC2hWnd( hDC ); |
| 434 | |
| 435 | /* Docs say that we have to remap current drawable pixel by pixel |
| 436 | * but it would take forever given the speed of XGet/PutPixel. |
| 437 | */ |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame^] | 438 | if (hWnd && !(COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL) ) |
| 439 | InvalidateRect16( hWnd, NULL, FALSE ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 440 | return 0x666; |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 441 | } |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame^] | 442 | |