Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * GDI functions |
| 3 | * |
| 4 | * Copyright 1993 Alexandre Julliard |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 5 | */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 6 | |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 7 | #include <stdlib.h> |
| 8 | #include <stdio.h> |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 9 | #include "color.h" |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 10 | #include "bitmap.h" |
Alexandre Julliard | 7cbe657 | 1995-01-09 18:21:16 +0000 | [diff] [blame] | 11 | #include "brush.h" |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 12 | #include "dc.h" |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 13 | #include "font.h" |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 14 | #include "heap.h" |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 15 | #include "options.h" |
Alexandre Julliard | 7cbe657 | 1995-01-09 18:21:16 +0000 | [diff] [blame] | 16 | #include "palette.h" |
| 17 | #include "pen.h" |
| 18 | #include "region.h" |
| 19 | #include "stddebug.h" |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 20 | #include "debug.h" |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 21 | #include "gdi.h" |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 22 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 23 | WORD GDI_HeapSel = 0; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 24 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 25 | /*********************************************************************** |
| 26 | * GDI stock objects |
| 27 | */ |
| 28 | |
| 29 | static BRUSHOBJ WhiteBrush = |
| 30 | { |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 31 | { 0, BRUSH_MAGIC, 1 }, /* header */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 32 | { BS_SOLID, RGB(255,255,255), 0 } /* logbrush */ |
| 33 | }; |
| 34 | |
| 35 | static BRUSHOBJ LtGrayBrush = |
| 36 | { |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 37 | { 0, BRUSH_MAGIC, 1 }, /* header */ |
Alexandre Julliard | 33072e1 | 1997-06-29 18:08:02 +0000 | [diff] [blame] | 38 | /* FIXME : this should perhaps be BS_HATCHED, at least for 1 bitperpixel */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 39 | { BS_SOLID, RGB(192,192,192), 0 } /* logbrush */ |
| 40 | }; |
| 41 | |
| 42 | static BRUSHOBJ GrayBrush = |
| 43 | { |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 44 | { 0, BRUSH_MAGIC, 1 }, /* header */ |
Alexandre Julliard | 33072e1 | 1997-06-29 18:08:02 +0000 | [diff] [blame] | 45 | /* FIXME : this should perhaps be BS_HATCHED, at least for 1 bitperpixel */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 46 | { BS_SOLID, RGB(128,128,128), 0 } /* logbrush */ |
| 47 | }; |
| 48 | |
| 49 | static BRUSHOBJ DkGrayBrush = |
| 50 | { |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 51 | { 0, BRUSH_MAGIC, 1 }, /* header */ |
Alexandre Julliard | 33072e1 | 1997-06-29 18:08:02 +0000 | [diff] [blame] | 52 | /* This is BS_HATCHED, for 1 bitperpixel. This makes the spray work in pbrush */ |
| 53 | /* NB_HATCH_STYLES is an index into HatchBrushes */ |
| 54 | { BS_HATCHED, RGB(0,0,0), NB_HATCH_STYLES } /* logbrush */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | static BRUSHOBJ BlackBrush = |
| 58 | { |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 59 | { 0, BRUSH_MAGIC, 1 }, /* header */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 60 | { BS_SOLID, RGB(0,0,0), 0 } /* logbrush */ |
| 61 | }; |
| 62 | |
| 63 | static BRUSHOBJ NullBrush = |
| 64 | { |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 65 | { 0, BRUSH_MAGIC, 1 }, /* header */ |
| 66 | { BS_NULL, 0, 0 } /* logbrush */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | static PENOBJ WhitePen = |
| 70 | { |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 71 | { 0, PEN_MAGIC, 1 }, /* header */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 72 | { PS_SOLID, { 1, 0 }, RGB(255,255,255) } /* logpen */ |
| 73 | }; |
| 74 | |
| 75 | static PENOBJ BlackPen = |
| 76 | { |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 77 | { 0, PEN_MAGIC, 1 }, /* header */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 78 | { PS_SOLID, { 1, 0 }, RGB(0,0,0) } /* logpen */ |
| 79 | }; |
| 80 | |
| 81 | static PENOBJ NullPen = |
| 82 | { |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 83 | { 0, PEN_MAGIC, 1 }, /* header */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 84 | { PS_NULL, { 1, 0 }, 0 } /* logpen */ |
| 85 | }; |
| 86 | |
| 87 | static FONTOBJ OEMFixedFont = |
| 88 | { |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 89 | { 0, FONT_MAGIC, 1 }, /* header */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 90 | { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, OEM_CHARSET, |
| 91 | 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, "" } |
| 92 | }; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame^] | 93 | /* Filler to make the location counter dword aligned again. This is necessary |
| 94 | since (a) FONTOBJ is packed, (b) gcc places initialised variables in the code |
| 95 | segment, and (c) Solaris assembler is stupid. */ |
| 96 | static UINT16 align_OEMFixedFont = 1; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 97 | |
| 98 | static FONTOBJ AnsiFixedFont = |
| 99 | { |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 100 | { 0, FONT_MAGIC, 1 }, /* header */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 101 | { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, |
| 102 | 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, "" } |
| 103 | }; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame^] | 104 | static UINT16 align_AnsiFixedFont = 1; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 105 | |
| 106 | static FONTOBJ AnsiVarFont = |
| 107 | { |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 108 | { 0, FONT_MAGIC, 1 }, /* header */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 109 | { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 110 | 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS, "MS Sans Serif" } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 111 | }; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame^] | 112 | static UINT16 align_AnsiVarFont = 1; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 113 | |
| 114 | static FONTOBJ SystemFont = |
| 115 | { |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 116 | { 0, FONT_MAGIC, 1 }, |
Alexandre Julliard | 33072e1 | 1997-06-29 18:08:02 +0000 | [diff] [blame] | 117 | { 16, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 118 | 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS, "System" } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 119 | }; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame^] | 120 | static UINT16 align_SystemFont = 1; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 121 | |
| 122 | static FONTOBJ DeviceDefaultFont = |
| 123 | { |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 124 | { 0, FONT_MAGIC, 1 }, /* header */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 125 | { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, |
| 126 | 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS, "" } |
| 127 | }; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame^] | 128 | static UINT16 align_DeviceDefaultFont = 1; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 129 | |
| 130 | static FONTOBJ SystemFixedFont = |
| 131 | { |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 132 | { 0, FONT_MAGIC, 1 }, /* header */ |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 133 | { 12, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 134 | 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, "" } |
| 135 | }; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame^] | 136 | static UINT16 align_SystemFixedFont = 1; |
| 137 | |
| 138 | /* FIXME: Is this correct? */ |
| 139 | static FONTOBJ DefaultGuiFont = |
| 140 | { |
| 141 | { 9, FONT_MAGIC, 1 }, /* header */ |
| 142 | { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, |
| 143 | 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS, "MS Sans Serif" } |
| 144 | }; |
| 145 | static UINT16 align_DefaultGuiFont = 1; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 146 | |
| 147 | |
| 148 | static GDIOBJHDR * StockObjects[NB_STOCK_OBJECTS] = |
| 149 | { |
| 150 | (GDIOBJHDR *) &WhiteBrush, |
| 151 | (GDIOBJHDR *) &LtGrayBrush, |
| 152 | (GDIOBJHDR *) &GrayBrush, |
| 153 | (GDIOBJHDR *) &DkGrayBrush, |
| 154 | (GDIOBJHDR *) &BlackBrush, |
| 155 | (GDIOBJHDR *) &NullBrush, |
| 156 | (GDIOBJHDR *) &WhitePen, |
| 157 | (GDIOBJHDR *) &BlackPen, |
| 158 | (GDIOBJHDR *) &NullPen, |
| 159 | NULL, |
| 160 | (GDIOBJHDR *) &OEMFixedFont, |
| 161 | (GDIOBJHDR *) &AnsiFixedFont, |
| 162 | (GDIOBJHDR *) &AnsiVarFont, |
| 163 | (GDIOBJHDR *) &SystemFont, |
| 164 | (GDIOBJHDR *) &DeviceDefaultFont, |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 165 | NULL, /* DEFAULT_PALETTE created by PALETTE_Init */ |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame^] | 166 | (GDIOBJHDR *) &SystemFixedFont, |
| 167 | (GDIOBJHDR *) &DefaultGuiFont |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 168 | }; |
| 169 | |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 170 | /****************************************************************************** |
| 171 | * |
| 172 | * void ReadFontInformation( |
| 173 | * char const *fontName, |
| 174 | * FONTOBJ *font, |
| 175 | * int defHeight, |
| 176 | * int defBold, |
| 177 | * int defItalic, |
| 178 | * int defUnderline, |
| 179 | * int defStrikeOut ) |
| 180 | * |
| 181 | * ReadFontInformation() checks the Wine configuration file's Tweak.Fonts |
| 182 | * section for entries containing fontName.Height, fontName.Bold, etc., |
| 183 | * where fontName is the name specified in the call (e.g., "System"). It |
| 184 | * attempts to be user friendly by accepting 'n', 'N', 'f', 'F', or '0' as |
| 185 | * the first character in the boolean attributes (bold, italic, and |
| 186 | * underline). |
| 187 | *****************************************************************************/ |
| 188 | |
| 189 | static void ReadFontInformation( |
| 190 | char const *fontName, |
| 191 | FONTOBJ *font, |
| 192 | int defHeight, |
| 193 | int defBold, |
| 194 | int defItalic, |
| 195 | int defUnderline, |
| 196 | int defStrikeOut ) |
| 197 | { |
| 198 | char key[256]; |
| 199 | |
| 200 | sprintf(key, "%s.Height", fontName); |
| 201 | font->logfont.lfHeight = |
| 202 | PROFILE_GetWineIniInt("Tweak.Fonts", key, defHeight); |
| 203 | |
| 204 | sprintf(key, "%s.Bold", fontName); |
| 205 | font->logfont.lfWeight = |
| 206 | (PROFILE_GetWineIniBool("Tweak.Fonts", key, defBold)) ? |
| 207 | FW_BOLD : FW_NORMAL; |
| 208 | |
| 209 | sprintf(key, "%s.Italic", fontName); |
| 210 | font->logfont.lfItalic = |
| 211 | PROFILE_GetWineIniBool("Tweak.Fonts", key, defItalic); |
| 212 | |
| 213 | sprintf(key, "%s.Underline", fontName); |
| 214 | font->logfont.lfUnderline = |
| 215 | PROFILE_GetWineIniBool("Tweak.Fonts", key, defUnderline); |
| 216 | |
| 217 | sprintf(key, "%s.StrikeOut", fontName); |
| 218 | font->logfont.lfStrikeOut = |
| 219 | PROFILE_GetWineIniBool("Tweak.Fonts", key, defStrikeOut); |
| 220 | |
| 221 | return; |
| 222 | } |
| 223 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 224 | |
| 225 | /*********************************************************************** |
| 226 | * GDI_Init |
| 227 | * |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 228 | * GDI initialization. |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 229 | */ |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 230 | BOOL32 GDI_Init(void) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 231 | { |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 232 | extern BOOL32 X11DRV_Init(void); |
Alexandre Julliard | 7ff1c41 | 1997-05-25 13:58:18 +0000 | [diff] [blame] | 233 | extern BOOL32 DIB_Init(void); |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 234 | |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame^] | 235 | /* Kill some warnings. */ |
| 236 | (void)align_OEMFixedFont; |
| 237 | (void)align_AnsiFixedFont; |
| 238 | (void)align_AnsiVarFont; |
| 239 | (void)align_SystemFont; |
| 240 | (void)align_DeviceDefaultFont; |
| 241 | (void)align_SystemFixedFont; |
| 242 | (void)align_DefaultGuiFont; |
| 243 | |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 244 | /* TWEAK: Initialize font hints */ |
| 245 | ReadFontInformation("OEMFixed", &OEMFixedFont, 12, 0, 0, 0, 0); |
| 246 | ReadFontInformation("AnsiFixed", &AnsiFixedFont, 12, 0, 0, 0, 0); |
| 247 | ReadFontInformation("AnsiVar", &AnsiVarFont, 12, 0, 0, 0, 0); |
| 248 | ReadFontInformation("System", &SystemFont, 16, 1, 0, 0, 0); |
| 249 | ReadFontInformation("SystemFixed", &SystemFixedFont, 12, 1, 0, 0, 0); |
| 250 | |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 251 | /* Initialize drivers */ |
| 252 | |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 253 | DIB_Init(); /* always before X11DRV_Init() */ |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 254 | |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 255 | if( X11DRV_Init() ) |
| 256 | { |
| 257 | /* Create default palette */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 258 | |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 259 | /* DR well *this* palette can't be moveable (?) */ |
| 260 | |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 261 | HPALETTE16 hpalette = PALETTE_Init(); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 262 | |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 263 | if( hpalette ) |
| 264 | { |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 265 | StockObjects[DEFAULT_PALETTE] = (GDIOBJHDR *)GDI_HEAP_LOCK( hpalette ); |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 266 | return TRUE; |
| 267 | } |
| 268 | } |
| 269 | return FALSE; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | |
| 273 | /*********************************************************************** |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 274 | * GDI_AllocObject |
| 275 | */ |
Alexandre Julliard | bf9130a | 1996-10-13 17:45:47 +0000 | [diff] [blame] | 276 | HGDIOBJ16 GDI_AllocObject( WORD size, WORD magic ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 277 | { |
| 278 | static DWORD count = 0; |
| 279 | GDIOBJHDR * obj; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 280 | HGDIOBJ16 handle; |
| 281 | if ( magic == DC_MAGIC || magic == METAFILE_DC_MAGIC ) |
| 282 | handle = GDI_HEAP_ALLOC( size ); |
| 283 | else |
| 284 | handle = GDI_HEAP_ALLOC_MOVEABLE( size ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 285 | if (!handle) return 0; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 286 | obj = (GDIOBJHDR *) GDI_HEAP_LOCK( handle ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 287 | obj->hNext = 0; |
| 288 | obj->wMagic = magic; |
| 289 | obj->dwCount = ++count; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 290 | GDI_HEAP_UNLOCK( handle ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 291 | return handle; |
| 292 | } |
| 293 | |
| 294 | |
| 295 | /*********************************************************************** |
| 296 | * GDI_FreeObject |
| 297 | */ |
Alexandre Julliard | bf9130a | 1996-10-13 17:45:47 +0000 | [diff] [blame] | 298 | BOOL32 GDI_FreeObject( HGDIOBJ16 handle ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 299 | { |
| 300 | GDIOBJHDR * object; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 301 | |
| 302 | /* Can't free stock objects */ |
Alexandre Julliard | 59730ae | 1996-03-24 16:20:51 +0000 | [diff] [blame] | 303 | if ((handle >= FIRST_STOCK_HANDLE) && (handle <= LAST_STOCK_HANDLE)) |
| 304 | return TRUE; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 305 | |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 306 | object = (GDIOBJHDR *) GDI_HEAP_LOCK( handle ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 307 | if (!object) return FALSE; |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 308 | object->wMagic = 0; /* Mark it as invalid */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 309 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 310 | /* Free object */ |
| 311 | |
| 312 | GDI_HEAP_FREE( handle ); |
| 313 | return TRUE; |
| 314 | } |
| 315 | |
| 316 | /*********************************************************************** |
| 317 | * GDI_GetObjPtr |
| 318 | * |
| 319 | * Return a pointer to the GDI object associated to the handle. |
| 320 | * Return NULL if the object has the wrong magic number. |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 321 | * Movable GDI objects are locked in memory: it is up to the caller to unlock |
| 322 | * it after the caller is done with the pointer. |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 323 | */ |
Alexandre Julliard | bf9130a | 1996-10-13 17:45:47 +0000 | [diff] [blame] | 324 | GDIOBJHDR * GDI_GetObjPtr( HGDIOBJ16 handle, WORD magic ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 325 | { |
| 326 | GDIOBJHDR * ptr = NULL; |
| 327 | |
Alexandre Julliard | 59730ae | 1996-03-24 16:20:51 +0000 | [diff] [blame] | 328 | if ((handle >= FIRST_STOCK_HANDLE) && (handle <= LAST_STOCK_HANDLE)) |
| 329 | ptr = StockObjects[handle - FIRST_STOCK_HANDLE]; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 330 | else |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 331 | ptr = (GDIOBJHDR *) GDI_HEAP_LOCK( handle ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 332 | if (!ptr) return NULL; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 333 | if ((magic != MAGIC_DONTCARE) && (ptr->wMagic != magic)) |
| 334 | { |
| 335 | GDI_HEAP_UNLOCK( handle ); |
| 336 | return NULL; |
| 337 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 338 | return ptr; |
| 339 | } |
| 340 | |
| 341 | |
| 342 | /*********************************************************************** |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 343 | * DeleteObject16 (GDI.69) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 344 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 345 | BOOL16 WINAPI DeleteObject16( HGDIOBJ16 obj ) |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 346 | { |
| 347 | return DeleteObject32( obj ); |
| 348 | } |
| 349 | |
| 350 | |
| 351 | /*********************************************************************** |
| 352 | * DeleteObject32 (GDI32.70) |
| 353 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 354 | BOOL32 WINAPI DeleteObject32( HGDIOBJ32 obj ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 355 | { |
| 356 | /* Check if object is valid */ |
| 357 | |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 358 | GDIOBJHDR * header; |
| 359 | if (HIWORD(obj)) return FALSE; |
| 360 | if ((obj >= FIRST_STOCK_HANDLE) && (obj <= LAST_STOCK_HANDLE)) |
| 361 | return TRUE; |
| 362 | if (!(header = (GDIOBJHDR *) GDI_HEAP_LOCK( obj ))) return FALSE; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 363 | |
Alexandre Julliard | 59730ae | 1996-03-24 16:20:51 +0000 | [diff] [blame] | 364 | dprintf_gdi(stddeb, "DeleteObject: %04x\n", obj ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 365 | |
| 366 | /* Delete object */ |
| 367 | |
| 368 | switch(header->wMagic) |
| 369 | { |
| 370 | case PEN_MAGIC: return GDI_FreeObject( obj ); |
Alexandre Julliard | 7cbe657 | 1995-01-09 18:21:16 +0000 | [diff] [blame] | 371 | case BRUSH_MAGIC: return BRUSH_DeleteObject( obj, (BRUSHOBJ*)header ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 372 | case FONT_MAGIC: return GDI_FreeObject( obj ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 373 | case PALETTE_MAGIC: return PALETTE_DeleteObject(obj,(PALETTEOBJ*)header); |
Alexandre Julliard | 7cbe657 | 1995-01-09 18:21:16 +0000 | [diff] [blame] | 374 | case BITMAP_MAGIC: return BITMAP_DeleteObject( obj, (BITMAPOBJ*)header); |
| 375 | case REGION_MAGIC: return REGION_DeleteObject( obj, (RGNOBJ*)header ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 376 | } |
| 377 | return FALSE; |
| 378 | } |
| 379 | |
| 380 | |
| 381 | /*********************************************************************** |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 382 | * GetStockObject16 (GDI.87) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 383 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 384 | HGDIOBJ16 WINAPI GetStockObject16( INT16 obj ) |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 385 | { |
| 386 | return (HGDIOBJ16)GetStockObject32( obj ); |
| 387 | } |
| 388 | |
| 389 | |
| 390 | /*********************************************************************** |
| 391 | * GetStockObject32 (GDI32.220) |
| 392 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 393 | HGDIOBJ32 WINAPI GetStockObject32( INT32 obj ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 394 | { |
| 395 | if ((obj < 0) || (obj >= NB_STOCK_OBJECTS)) return 0; |
| 396 | if (!StockObjects[obj]) return 0; |
Alexandre Julliard | 59730ae | 1996-03-24 16:20:51 +0000 | [diff] [blame] | 397 | dprintf_gdi(stddeb, "GetStockObject: returning %d\n", |
| 398 | FIRST_STOCK_HANDLE + obj ); |
Alexandre Julliard | bf9130a | 1996-10-13 17:45:47 +0000 | [diff] [blame] | 399 | return (HGDIOBJ16)(FIRST_STOCK_HANDLE + obj); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | |
| 403 | /*********************************************************************** |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 404 | * GetObject16 (GDI.82) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 405 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 406 | INT16 WINAPI GetObject16( HANDLE16 handle, INT16 count, LPVOID buffer ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 407 | { |
| 408 | GDIOBJHDR * ptr = NULL; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 409 | INT16 result = 0; |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 410 | dprintf_gdi(stddeb, "GetObject16: %04x %d %p\n", handle, count, buffer ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 411 | if (!count) return 0; |
| 412 | |
Alexandre Julliard | 59730ae | 1996-03-24 16:20:51 +0000 | [diff] [blame] | 413 | if ((handle >= FIRST_STOCK_HANDLE) && (handle <= LAST_STOCK_HANDLE)) |
| 414 | ptr = StockObjects[handle - FIRST_STOCK_HANDLE]; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 415 | else |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 416 | ptr = (GDIOBJHDR *) GDI_HEAP_LOCK( handle ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 417 | if (!ptr) return 0; |
| 418 | |
| 419 | switch(ptr->wMagic) |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 420 | { |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 421 | case PEN_MAGIC: |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 422 | result = PEN_GetObject16( (PENOBJ *)ptr, count, buffer ); |
| 423 | break; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 424 | case BRUSH_MAGIC: |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 425 | result = BRUSH_GetObject16( (BRUSHOBJ *)ptr, count, buffer ); |
| 426 | break; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 427 | case BITMAP_MAGIC: |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 428 | result = BITMAP_GetObject16( (BITMAPOBJ *)ptr, count, buffer ); |
| 429 | break; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 430 | case FONT_MAGIC: |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 431 | result = FONT_GetObject16( (FONTOBJ *)ptr, count, buffer ); |
| 432 | break; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 433 | case PALETTE_MAGIC: |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 434 | result = PALETTE_GetObject( (PALETTEOBJ *)ptr, count, buffer ); |
| 435 | break; |
| 436 | } |
| 437 | GDI_HEAP_UNLOCK( handle ); |
| 438 | return result; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | |
| 442 | /*********************************************************************** |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 443 | * GetObject32A (GDI32.204) |
| 444 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 445 | INT32 WINAPI GetObject32A( HANDLE32 handle, INT32 count, LPVOID buffer ) |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 446 | { |
| 447 | GDIOBJHDR * ptr = NULL; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 448 | INT32 result = 0; |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 449 | dprintf_gdi(stddeb, "GetObject32A: %08x %d %p\n", handle, count, buffer ); |
| 450 | if (!count) return 0; |
| 451 | |
| 452 | if ((handle >= FIRST_STOCK_HANDLE) && (handle <= LAST_STOCK_HANDLE)) |
| 453 | ptr = StockObjects[handle - FIRST_STOCK_HANDLE]; |
| 454 | else |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 455 | ptr = (GDIOBJHDR *) GDI_HEAP_LOCK( handle ); |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 456 | if (!ptr) return 0; |
| 457 | |
| 458 | switch(ptr->wMagic) |
| 459 | { |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 460 | case PEN_MAGIC: |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 461 | result = PEN_GetObject32( (PENOBJ *)ptr, count, buffer ); |
| 462 | break; |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 463 | case BRUSH_MAGIC: |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 464 | result = BRUSH_GetObject32( (BRUSHOBJ *)ptr, count, buffer ); |
| 465 | break; |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 466 | case BITMAP_MAGIC: |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 467 | result = BITMAP_GetObject32( (BITMAPOBJ *)ptr, count, buffer ); |
| 468 | break; |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 469 | case FONT_MAGIC: |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 470 | result = FONT_GetObject32A( (FONTOBJ *)ptr, count, buffer ); |
| 471 | break; |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 472 | case PALETTE_MAGIC: |
| 473 | fprintf( stderr, "GetObject32: magic %04x not implemented\n", |
| 474 | ptr->wMagic ); |
| 475 | break; |
| 476 | } |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 477 | GDI_HEAP_UNLOCK( handle ); |
| 478 | return result; |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 479 | } |
| 480 | |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 481 | /*********************************************************************** |
| 482 | * GetObjectType (GDI32.205) |
| 483 | */ |
| 484 | DWORD WINAPI GetObjectType( HANDLE32 handle ) |
| 485 | { |
| 486 | GDIOBJHDR * ptr = NULL; |
| 487 | INT32 result = 0; |
| 488 | dprintf_gdi(stddeb, "GetObjectType: %08x\n", handle ); |
| 489 | |
| 490 | if ((handle >= FIRST_STOCK_HANDLE) && (handle <= LAST_STOCK_HANDLE)) |
| 491 | ptr = StockObjects[handle - FIRST_STOCK_HANDLE]; |
| 492 | else |
| 493 | ptr = (GDIOBJHDR *) GDI_HEAP_LOCK( handle ); |
| 494 | if (!ptr) return 0; |
| 495 | |
| 496 | switch(ptr->wMagic) |
| 497 | { |
| 498 | case PEN_MAGIC: |
| 499 | result = OBJ_PEN; |
| 500 | break; |
| 501 | case BRUSH_MAGIC: |
| 502 | result = OBJ_BRUSH; |
| 503 | break; |
| 504 | case BITMAP_MAGIC: |
| 505 | result = OBJ_BITMAP; |
| 506 | break; |
| 507 | case FONT_MAGIC: |
| 508 | result = OBJ_FONT; |
| 509 | break; |
| 510 | case PALETTE_MAGIC: |
| 511 | result = OBJ_PAL; |
| 512 | break; |
| 513 | case REGION_MAGIC: |
| 514 | result = OBJ_REGION; |
| 515 | break; |
| 516 | case DC_MAGIC: |
| 517 | result = OBJ_DC; |
| 518 | break; |
| 519 | case META_DC_MAGIC: |
| 520 | result = OBJ_METADC; |
| 521 | break; |
| 522 | case METAFILE_MAGIC: |
| 523 | result = OBJ_METAFILE; |
| 524 | break; |
| 525 | case METAFILE_DC_MAGIC: |
| 526 | result = OBJ_METADC; |
| 527 | break; |
| 528 | |
| 529 | default: |
| 530 | fprintf( stderr, "GetObjectType: magic %04x not implemented\n", |
| 531 | ptr->wMagic ); |
| 532 | break; |
| 533 | } |
| 534 | GDI_HEAP_UNLOCK( handle ); |
| 535 | return result; |
| 536 | } |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 537 | |
| 538 | /*********************************************************************** |
| 539 | * GetObject32W (GDI32.206) |
| 540 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 541 | INT32 WINAPI GetObject32W( HANDLE32 handle, INT32 count, LPVOID buffer ) |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 542 | { |
| 543 | return GetObject32A( handle, count, buffer ); |
| 544 | } |
| 545 | |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame^] | 546 | /*********************************************************************** |
| 547 | * GetCurrentObject (GDI32.166) |
| 548 | */ |
| 549 | HANDLE32 WINAPI GetCurrentObject(HDC32 hdc,UINT32 type) |
| 550 | { |
| 551 | DC * dc = DC_GetDCPtr( hdc ); |
| 552 | |
| 553 | if (!dc) |
| 554 | return 0; |
| 555 | switch (type) { |
| 556 | case OBJ_PEN: return dc->w.hPen; |
| 557 | case OBJ_BRUSH: return dc->w.hBrush; |
| 558 | case OBJ_PAL: return dc->w.hPalette; |
| 559 | case OBJ_FONT: return dc->w.hFont; |
| 560 | case OBJ_BITMAP: return dc->w.hBitmap; |
| 561 | default: |
| 562 | /* the SDK only mentions those above */ |
| 563 | fprintf(stderr,"GetCurrentObject(%08x,%d), unknown type.\n",hdc,type); |
| 564 | return 0; |
| 565 | } |
| 566 | } |
| 567 | |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 568 | |
| 569 | /*********************************************************************** |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 570 | * SelectObject16 (GDI.45) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 571 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 572 | HGDIOBJ16 WINAPI SelectObject16( HDC16 hdc, HGDIOBJ16 handle ) |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 573 | { |
| 574 | return (HGDIOBJ16)SelectObject32( hdc, handle ); |
| 575 | } |
| 576 | |
| 577 | |
| 578 | /*********************************************************************** |
| 579 | * SelectObject32 (GDI32.299) |
| 580 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 581 | HGDIOBJ32 WINAPI SelectObject32( HDC32 hdc, HGDIOBJ32 handle ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 582 | { |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 583 | DC * dc = DC_GetDCPtr( hdc ); |
| 584 | if (!dc || !dc->funcs->pSelectObject) return 0; |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 585 | dprintf_gdi(stddeb, "SelectObject: hdc=%04x %04x\n", hdc, handle ); |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 586 | return dc->funcs->pSelectObject( dc, handle ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | |
| 590 | /*********************************************************************** |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 591 | * UnrealizeObject16 (GDI.150) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 592 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 593 | BOOL16 WINAPI UnrealizeObject16( HGDIOBJ16 obj ) |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 594 | { |
| 595 | return UnrealizeObject32( obj ); |
| 596 | } |
| 597 | |
| 598 | |
| 599 | /*********************************************************************** |
| 600 | * UnrealizeObject (GDI32.358) |
| 601 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 602 | BOOL32 WINAPI UnrealizeObject32( HGDIOBJ32 obj ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 603 | { |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 604 | BOOL32 result = TRUE; |
| 605 | /* Check if object is valid */ |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 606 | |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 607 | GDIOBJHDR * header = (GDIOBJHDR *) GDI_HEAP_LOCK( obj ); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 608 | if (!header) return FALSE; |
| 609 | |
| 610 | dprintf_gdi( stddeb, "UnrealizeObject: %04x\n", obj ); |
| 611 | |
| 612 | /* Unrealize object */ |
| 613 | |
| 614 | switch(header->wMagic) |
| 615 | { |
| 616 | case PALETTE_MAGIC: |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 617 | result = PALETTE_UnrealizeObject( obj, (PALETTEOBJ *)header ); |
| 618 | break; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 619 | |
| 620 | case BRUSH_MAGIC: |
| 621 | /* Windows resets the brush origin. We don't need to. */ |
| 622 | break; |
| 623 | } |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 624 | GDI_HEAP_UNLOCK( obj ); |
| 625 | return result; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 626 | } |
Alexandre Julliard | 1f57929 | 1994-05-25 16:25:21 +0000 | [diff] [blame] | 627 | |
| 628 | |
| 629 | /*********************************************************************** |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 630 | * EnumObjects16 (GDI.71) |
Alexandre Julliard | 1f57929 | 1994-05-25 16:25:21 +0000 | [diff] [blame] | 631 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 632 | INT16 WINAPI EnumObjects16( HDC16 hdc, INT16 nObjType, |
| 633 | GOBJENUMPROC16 lpEnumFunc, LPARAM lParam ) |
Alexandre Julliard | 1f57929 | 1994-05-25 16:25:21 +0000 | [diff] [blame] | 634 | { |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 635 | /* Solid colors to enumerate */ |
| 636 | static const COLORREF solid_colors[] = |
| 637 | { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff), |
| 638 | RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00), |
| 639 | RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00), |
| 640 | RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff), |
| 641 | RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00), |
| 642 | RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80), |
| 643 | RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80), |
| 644 | RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0) |
| 645 | }; |
| 646 | |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 647 | INT16 i, retval = 0; |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 648 | LOGPEN16 *pen; |
| 649 | LOGBRUSH16 *brush = NULL; |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 650 | |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 651 | dprintf_gdi( stddeb, "EnumObjects16: %04x %d %08lx %08lx\n", |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 652 | hdc, nObjType, (DWORD)lpEnumFunc, lParam ); |
| 653 | switch(nObjType) |
| 654 | { |
| 655 | case OBJ_PEN: |
| 656 | /* Enumerate solid pens */ |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 657 | if (!(pen = SEGPTR_NEW(LOGPEN16))) break; |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 658 | for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++) |
| 659 | { |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 660 | pen->lopnStyle = PS_SOLID; |
| 661 | pen->lopnWidth.x = 1; |
| 662 | pen->lopnWidth.y = 0; |
| 663 | pen->lopnColor = solid_colors[i]; |
Alexandre Julliard | f1aa303 | 1996-08-05 17:42:43 +0000 | [diff] [blame] | 664 | retval = lpEnumFunc( SEGPTR_GET(pen), lParam ); |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 665 | dprintf_gdi( stddeb, "EnumObjects16: solid pen %08lx, ret=%d\n", |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 666 | solid_colors[i], retval); |
| 667 | if (!retval) break; |
| 668 | } |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 669 | SEGPTR_FREE(pen); |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 670 | break; |
| 671 | |
| 672 | case OBJ_BRUSH: |
| 673 | /* Enumerate solid brushes */ |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 674 | if (!(brush = SEGPTR_NEW(LOGBRUSH16))) break; |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 675 | for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++) |
| 676 | { |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 677 | brush->lbStyle = BS_SOLID; |
| 678 | brush->lbColor = solid_colors[i]; |
| 679 | brush->lbHatch = 0; |
Alexandre Julliard | f1aa303 | 1996-08-05 17:42:43 +0000 | [diff] [blame] | 680 | retval = lpEnumFunc( SEGPTR_GET(brush), lParam ); |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 681 | dprintf_gdi( stddeb, "EnumObjects16: solid brush %08lx, ret=%d\n", |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 682 | solid_colors[i], retval); |
| 683 | if (!retval) break; |
| 684 | } |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 685 | |
| 686 | /* Now enumerate hatched brushes */ |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 687 | if (retval) for (i = HS_HORIZONTAL; i <= HS_DIAGCROSS; i++) |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 688 | { |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 689 | brush->lbStyle = BS_HATCHED; |
| 690 | brush->lbColor = RGB(0,0,0); |
| 691 | brush->lbHatch = i; |
Alexandre Julliard | f1aa303 | 1996-08-05 17:42:43 +0000 | [diff] [blame] | 692 | retval = lpEnumFunc( SEGPTR_GET(brush), lParam ); |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 693 | dprintf_gdi( stddeb, "EnumObjects16: hatched brush %d, ret=%d\n", |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 694 | i, retval); |
| 695 | if (!retval) break; |
| 696 | } |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 697 | SEGPTR_FREE(brush); |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 698 | break; |
| 699 | |
| 700 | default: |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 701 | fprintf( stderr, "EnumObjects16: invalid type %d\n", nObjType ); |
| 702 | break; |
| 703 | } |
| 704 | return retval; |
| 705 | } |
| 706 | |
| 707 | |
| 708 | /*********************************************************************** |
| 709 | * EnumObjects32 (GDI32.89) |
| 710 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 711 | INT32 WINAPI EnumObjects32( HDC32 hdc, INT32 nObjType, |
| 712 | GOBJENUMPROC32 lpEnumFunc, LPARAM lParam ) |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 713 | { |
| 714 | /* Solid colors to enumerate */ |
| 715 | static const COLORREF solid_colors[] = |
| 716 | { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff), |
| 717 | RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00), |
| 718 | RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00), |
| 719 | RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff), |
| 720 | RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00), |
| 721 | RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80), |
| 722 | RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80), |
| 723 | RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0) |
| 724 | }; |
| 725 | |
| 726 | INT32 i, retval = 0; |
| 727 | LOGPEN32 pen; |
| 728 | LOGBRUSH32 brush; |
| 729 | |
| 730 | dprintf_gdi( stddeb, "EnumObjects32: %04x %d %08lx %08lx\n", |
| 731 | hdc, nObjType, (DWORD)lpEnumFunc, lParam ); |
| 732 | switch(nObjType) |
| 733 | { |
| 734 | case OBJ_PEN: |
| 735 | /* Enumerate solid pens */ |
| 736 | for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++) |
| 737 | { |
| 738 | pen.lopnStyle = PS_SOLID; |
| 739 | pen.lopnWidth.x = 1; |
| 740 | pen.lopnWidth.y = 0; |
| 741 | pen.lopnColor = solid_colors[i]; |
| 742 | retval = lpEnumFunc( &pen, lParam ); |
| 743 | dprintf_gdi( stddeb, "EnumObjects32: solid pen %08lx, ret=%d\n", |
| 744 | solid_colors[i], retval); |
| 745 | if (!retval) break; |
| 746 | } |
| 747 | break; |
| 748 | |
| 749 | case OBJ_BRUSH: |
| 750 | /* Enumerate solid brushes */ |
| 751 | for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++) |
| 752 | { |
| 753 | brush.lbStyle = BS_SOLID; |
| 754 | brush.lbColor = solid_colors[i]; |
| 755 | brush.lbHatch = 0; |
| 756 | retval = lpEnumFunc( &brush, lParam ); |
| 757 | dprintf_gdi( stddeb, "EnumObjects32: solid brush %08lx, ret=%d\n", |
| 758 | solid_colors[i], retval); |
| 759 | if (!retval) break; |
| 760 | } |
| 761 | |
| 762 | /* Now enumerate hatched brushes */ |
| 763 | if (retval) for (i = HS_HORIZONTAL; i <= HS_DIAGCROSS; i++) |
| 764 | { |
| 765 | brush.lbStyle = BS_HATCHED; |
| 766 | brush.lbColor = RGB(0,0,0); |
| 767 | brush.lbHatch = i; |
| 768 | retval = lpEnumFunc( &brush, lParam ); |
| 769 | dprintf_gdi( stddeb, "EnumObjects32: hatched brush %d, ret=%d\n", |
| 770 | i, retval); |
| 771 | if (!retval) break; |
| 772 | } |
| 773 | break; |
| 774 | |
| 775 | default: |
| 776 | /* FIXME: implement Win32 types */ |
| 777 | fprintf( stderr, "EnumObjects32: invalid type %d\n", nObjType ); |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 778 | break; |
| 779 | } |
| 780 | return retval; |
Alexandre Julliard | 1f57929 | 1994-05-25 16:25:21 +0000 | [diff] [blame] | 781 | } |
Alexandre Julliard | 7cc9c0c | 1994-06-15 15:45:11 +0000 | [diff] [blame] | 782 | |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 783 | |
Alexandre Julliard | 7cc9c0c | 1994-06-15 15:45:11 +0000 | [diff] [blame] | 784 | /*********************************************************************** |
Alexandre Julliard | 59730ae | 1996-03-24 16:20:51 +0000 | [diff] [blame] | 785 | * IsGDIObject (GDI.462) |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 786 | * |
| 787 | * returns type of object if valid (W95 system programming secrets p. 264-5) |
Alexandre Julliard | 7cc9c0c | 1994-06-15 15:45:11 +0000 | [diff] [blame] | 788 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 789 | BOOL16 WINAPI IsGDIObject( HGDIOBJ16 handle ) |
Alexandre Julliard | 7cc9c0c | 1994-06-15 15:45:11 +0000 | [diff] [blame] | 790 | { |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 791 | if (handle >= FIRST_STOCK_HANDLE ) |
| 792 | return TRUE; |
| 793 | else |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 794 | { |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 795 | GDIOBJHDR *object = (GDIOBJHDR *) GDI_HEAP_LOCK( handle ); |
| 796 | if (object) |
| 797 | { |
| 798 | UINT16 magic = object->wMagic; |
| 799 | GDI_HEAP_UNLOCK( handle ); |
| 800 | if (magic >= PEN_MAGIC && magic <= METAFILE_DC_MAGIC) |
| 801 | return magic - PEN_MAGIC + 1; |
| 802 | } |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 803 | } |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 804 | return FALSE; |
Alexandre Julliard | 7cc9c0c | 1994-06-15 15:45:11 +0000 | [diff] [blame] | 805 | } |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 806 | |
| 807 | |
| 808 | /*********************************************************************** |
Alexandre Julliard | 17216f5 | 1997-10-12 16:30:17 +0000 | [diff] [blame] | 809 | * SetObjectOwner16 (GDI.461) |
| 810 | */ |
| 811 | void WINAPI SetObjectOwner16( HGDIOBJ16 handle, HANDLE16 owner ) |
| 812 | { |
| 813 | /* Nothing to do */ |
| 814 | } |
| 815 | |
| 816 | |
| 817 | /*********************************************************************** |
| 818 | * SetObjectOwner32 (GDI32.386) |
| 819 | */ |
| 820 | void WINAPI SetObjectOwner32( HGDIOBJ32 handle, HANDLE32 owner ) |
| 821 | { |
| 822 | /* Nothing to do */ |
| 823 | } |
| 824 | |
Alexandre Julliard | 491502b | 1997-11-01 19:08:16 +0000 | [diff] [blame] | 825 | /*********************************************************************** |
| 826 | * GdiFlush (GDI32.128) |
| 827 | */ |
| 828 | BOOL32 WINAPI GdiFlush(void) |
| 829 | { |
| 830 | return TRUE; /* FIXME */ |
| 831 | } |
| 832 | |
Alexandre Julliard | 17216f5 | 1997-10-12 16:30:17 +0000 | [diff] [blame] | 833 | |
| 834 | /*********************************************************************** |
| 835 | * GdiGetBatchLimit (GDI32.129) |
| 836 | */ |
| 837 | DWORD WINAPI GdiGetBatchLimit(void) |
| 838 | { |
| 839 | return 1; /* FIXME */ |
| 840 | } |
| 841 | |
| 842 | |
| 843 | /*********************************************************************** |
| 844 | * GdiSetBatchLimit (GDI32.139) |
| 845 | */ |
| 846 | DWORD WINAPI GdiSetBatchLimit( DWORD limit ) |
| 847 | { |
| 848 | return 1; /* FIXME */ |
| 849 | } |
| 850 | |
| 851 | |
| 852 | /*********************************************************************** |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 853 | * MulDiv16 (GDI.128) |
| 854 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 855 | INT16 WINAPI MulDiv16( INT16 foo, INT16 bar, INT16 baz ) |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 856 | { |
| 857 | INT32 ret; |
| 858 | if (!baz) return -32768; |
| 859 | ret = (foo * bar) / baz; |
| 860 | if ((ret > 32767) || (ret < -32767)) return -32768; |
| 861 | return ret; |
| 862 | } |
| 863 | |
| 864 | |
| 865 | /*********************************************************************** |
| 866 | * MulDiv32 (KERNEL32.391) |
| 867 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 868 | INT32 WINAPI MulDiv32( INT32 foo, INT32 bar, INT32 baz ) |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 869 | { |
| 870 | #ifdef __GNUC__ |
| 871 | long long ret; |
| 872 | if (!baz) return -1; |
| 873 | ret = ((long long)foo * bar) / baz; |
| 874 | if ((ret > 2147483647) || (ret < -2147483647)) return -1; |
| 875 | return ret; |
| 876 | #else |
| 877 | if (!baz) return -1; |
| 878 | return (foo * bar) / baz; |
| 879 | #endif |
| 880 | } |