4 * Copyright 1993 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 #include "gdi_private.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
41 #define HGDIOBJ_32(h16) ((HGDIOBJ)(ULONG_PTR)(h16))
43 #define GDI_HEAP_SIZE 0xffe0
45 /***********************************************************************
49 static const LOGBRUSH WhiteBrush = { BS_SOLID, RGB(255,255,255), 0 };
50 static const LOGBRUSH BlackBrush = { BS_SOLID, RGB(0,0,0), 0 };
51 static const LOGBRUSH NullBrush = { BS_NULL, 0, 0 };
53 static const LOGBRUSH LtGrayBrush = { BS_SOLID, RGB(192,192,192), 0 };
54 static const LOGBRUSH GrayBrush = { BS_SOLID, RGB(128,128,128), 0 };
55 static const LOGBRUSH DkGrayBrush = { BS_SOLID, RGB(64,64,64), 0 };
57 static const LOGPEN WhitePen = { PS_SOLID, { 0, 0 }, RGB(255,255,255) };
58 static const LOGPEN BlackPen = { PS_SOLID, { 0, 0 }, RGB(0,0,0) };
59 static const LOGPEN NullPen = { PS_NULL, { 0, 0 }, 0 };
61 static const LOGBRUSH DCBrush = { BS_SOLID, RGB(255,255,255), 0 };
62 static const LOGPEN DCPen = { PS_SOLID, { 0, 0 }, RGB(0,0,0) };
64 /* reserve one extra entry for the stock default bitmap */
65 /* this is what Windows does too */
66 #define NB_STOCK_OBJECTS (STOCK_LAST+2)
68 static HGDIOBJ stock_objects[NB_STOCK_OBJECTS];
70 static SYSLEVEL GDI_level;
71 static CRITICAL_SECTION_DEBUG critsect_debug =
73 0, 0, &GDI_level.crst,
74 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
75 0, 0, { (DWORD_PTR)(__FILE__ ": GDI_level") }
77 static SYSLEVEL GDI_level = { { &critsect_debug, -1, 0, 0, 0, 0 }, 3 };
79 inline static BOOL get_bool(char *buffer)
81 return (buffer[0] == 'y' || buffer[0] == 'Y' ||
82 buffer[0] == 't' || buffer[0] == 'T' ||
87 /****************************************************************************
89 * language-independent stock fonts
93 static const LOGFONTW OEMFixedFont =
94 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, OEM_CHARSET,
95 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} };
97 static const LOGFONTW AnsiFixedFont =
98 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
99 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} };
101 static const LOGFONTW AnsiVarFont =
102 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
103 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
104 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'} };
106 /******************************************************************************
108 * language-dependent stock fonts
110 * 'ANSI' charset and 'DEFAULT' charset is not same.
111 * The chars in CP_ACP should be drawn with 'DEFAULT' charset.
112 * 'ANSI' charset seems to be identical with ISO-8859-1.
113 * 'DEFAULT' charset is a language-dependent charset.
115 * 'System' font seems to be an alias for language-dependent font.
119 * language-dependent stock fonts for all known charsets
120 * please see TranslateCharsetInfo (dlls/gdi/font.c) and
121 * CharsetBindingInfo (dlls/x11drv/xfont.c),
122 * and modify entries for your language if needed.
124 struct DefaultFontInfo
128 LOGFONTW DeviceDefaultFont;
129 LOGFONTW SystemFixedFont;
130 LOGFONTW DefaultGuiFont; /* Note for this font the lfHeight member should be the point size */
133 static const struct DefaultFontInfo default_fonts[] =
137 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
138 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
139 {'S','y','s','t','e','m','\0'}
141 { /* Device Default */
142 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
143 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
147 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
148 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
151 { /* DefaultGuiFont */
152 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
153 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
154 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
157 { EASTEUROPE_CHARSET,
159 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
160 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
161 {'S','y','s','t','e','m','\0'}
163 { /* Device Default */
164 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
165 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
169 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
170 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
173 { /* DefaultGuiFont */
174 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
175 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
176 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
181 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
182 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
183 {'S','y','s','t','e','m','\0'}
185 { /* Device Default */
186 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
187 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
191 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
192 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
195 { /* DefaultGuiFont */
196 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
197 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
198 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
203 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
204 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
205 {'S','y','s','t','e','m','\0'}
207 { /* Device Default */
208 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
209 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
213 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
214 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
217 { /* DefaultGuiFont */
218 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
219 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
220 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
225 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
226 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
227 {'S','y','s','t','e','m','\0'}
229 { /* Device Default */
230 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
231 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
235 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
236 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
239 { /* DefaultGuiFont */
240 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
241 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
242 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
247 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
248 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
249 {'S','y','s','t','e','m','\0'}
251 { /* Device Default */
252 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
253 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
257 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
258 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
261 { /* DefaultGuiFont */
262 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
263 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
264 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
269 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
270 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
271 {'S','y','s','t','e','m','\0'}
273 { /* Device Default */
274 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
275 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
279 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
280 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
283 { /* DefaultGuiFont */
284 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
285 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
286 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
291 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
292 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
293 {'S','y','s','t','e','m','\0'}
295 { /* Device Default */
296 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
297 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
301 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
302 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
305 { /* DefaultGuiFont */
306 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
307 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
308 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
313 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
314 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
315 {'S','y','s','t','e','m','\0'}
317 { /* Device Default */
318 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
319 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
323 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
324 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
327 { /* DefaultGuiFont */
328 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
329 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
330 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
335 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
336 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
337 {'S','y','s','t','e','m','\0'}
339 { /* Device Default */
340 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
341 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
345 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
346 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
349 { /* DefaultGuiFont */
350 9, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
351 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
352 {'M','S',' ','U','I',' ','G','o','t','h','i','c','\0'}
357 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
358 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
359 {'S','y','s','t','e','m','\0'}
361 { /* Device Default */
362 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
363 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
367 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
368 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
371 { /* DefaultGuiFont */
372 9, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
373 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
374 {'M','S',' ','S','o','n','g','\0'} /* FIXME: Is this correct? */
379 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
380 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
381 {'S','y','s','t','e','m','\0'}
383 { /* Device Default */
384 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
385 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
389 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
390 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
393 { /* DefaultGuiFont */
394 9, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
395 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
396 {'G','u','l','i','m','\0'},
399 { CHINESEBIG5_CHARSET,
401 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
402 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
403 {'S','y','s','t','e','m','\0'}
405 { /* Device Default */
406 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
407 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
411 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
412 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
415 { /* DefaultGuiFont */
416 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
417 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
418 {'\0'} /* FIXME - what is the native font??? */
423 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
424 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
425 {'S','y','s','t','e','m','\0'}
427 { /* Device Default */
428 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
429 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
433 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
434 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
437 { /* DefaultGuiFont */
438 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
439 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
440 {'M','S',' ','M','i','n','g','l','i','u','\0'} /* FIXME: Is this correct? */
446 /*************************************************************************
447 * __wine_make_gdi_object_system (GDI32.@)
449 * USER has to tell GDI that its system brushes and pens are non-deletable.
450 * For a description of the GDI object magics and their flags,
451 * see "Undocumented Windows" (wrong about the OBJECT_NOSYSTEM flag, though).
453 void __wine_make_gdi_object_system( HGDIOBJ handle, BOOL set)
455 GDIOBJHDR *ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
457 /* touch the "system" bit of the wMagic field of a GDIOBJHDR */
459 ptr->wMagic &= ~OBJECT_NOSYSTEM;
461 ptr->wMagic |= OBJECT_NOSYSTEM;
463 GDI_ReleaseObj( handle );
466 /******************************************************************************
469 static const struct DefaultFontInfo* get_default_fonts(UINT charset)
473 for(n=0;n<(sizeof(default_fonts)/sizeof(default_fonts[0]));n++)
475 if ( default_fonts[n].charset == charset )
476 return &default_fonts[n];
479 FIXME( "unhandled charset 0x%08x - use ANSI_CHARSET for default stock objects\n", charset );
480 return &default_fonts[0];
484 /******************************************************************************
485 * get_default_charset (internal)
487 * get the language-dependent charset that can handle CP_ACP correctly.
489 static UINT get_default_charset( void )
495 csi.ciCharset = ANSI_CHARSET;
496 if ( ! TranslateCharsetInfo( (LPDWORD)uACP, &csi, TCI_SRCCODEPAGE ) )
498 FIXME( "unhandled codepage %u - use ANSI_CHARSET for default stock objects\n", uACP );
502 return csi.ciCharset;
505 static const WCHAR dpi_key_name[] = {'S','o','f','t','w','a','r','e','\\','F','o','n','t','s','\0'};
506 static const WCHAR dpi_value_name[] = {'L','o','g','P','i','x','e','l','s','\0'};
508 /******************************************************************************
511 * get the dpi from the registry
513 static DWORD get_dpi( void )
518 if (RegOpenKeyW(HKEY_CURRENT_CONFIG, dpi_key_name, &hkey) == ERROR_SUCCESS)
520 DWORD type, size, new_dpi;
522 size = sizeof(new_dpi);
523 if(RegQueryValueExW(hkey, dpi_value_name, NULL, &type, (void *)&new_dpi, &size) == ERROR_SUCCESS)
525 if(type == REG_DWORD && new_dpi != 0)
534 /***********************************************************************
537 * Increment the reference count of a GDI object.
539 inline static void inc_ref_count( HGDIOBJ handle )
543 if ((header = GDI_GetObjPtr( handle, MAGIC_DONTCARE )))
546 GDI_ReleaseObj( handle );
551 /***********************************************************************
554 * Decrement the reference count of a GDI object.
556 inline static void dec_ref_count( HGDIOBJ handle )
560 if ((header = GDI_GetObjPtr( handle, MAGIC_DONTCARE )))
562 if (header->dwCount) header->dwCount--;
563 if (header->dwCount != 0x80000000) GDI_ReleaseObj( handle );
566 /* handle delayed DeleteObject*/
568 GDI_ReleaseObj( handle );
569 TRACE( "executing delayed DeleteObject for %p\n", handle );
570 DeleteObject( handle );
576 /***********************************************************************
579 * GDI initialization.
583 LOGFONTW default_gui_font;
584 const struct DefaultFontInfo* deffonts;
587 /* create stock objects */
588 stock_objects[WHITE_BRUSH] = CreateBrushIndirect( &WhiteBrush );
589 stock_objects[LTGRAY_BRUSH] = CreateBrushIndirect( &LtGrayBrush );
590 stock_objects[GRAY_BRUSH] = CreateBrushIndirect( &GrayBrush );
591 stock_objects[DKGRAY_BRUSH] = CreateBrushIndirect( &DkGrayBrush );
592 stock_objects[BLACK_BRUSH] = CreateBrushIndirect( &BlackBrush );
593 stock_objects[NULL_BRUSH] = CreateBrushIndirect( &NullBrush );
595 stock_objects[WHITE_PEN] = CreatePenIndirect( &WhitePen );
596 stock_objects[BLACK_PEN] = CreatePenIndirect( &BlackPen );
597 stock_objects[NULL_PEN] = CreatePenIndirect( &NullPen );
599 stock_objects[DEFAULT_PALETTE] = PALETTE_Init();
600 stock_objects[DEFAULT_BITMAP] = CreateBitmap( 1, 1, 1, 1, NULL );
602 /* language-independent stock fonts */
603 stock_objects[OEM_FIXED_FONT] = CreateFontIndirectW( &OEMFixedFont );
604 stock_objects[ANSI_FIXED_FONT] = CreateFontIndirectW( &AnsiFixedFont );
605 stock_objects[ANSI_VAR_FONT] = CreateFontIndirectW( &AnsiVarFont );
607 /* language-dependent stock fonts */
608 deffonts = get_default_fonts(get_default_charset());
609 stock_objects[SYSTEM_FONT] = CreateFontIndirectW( &deffonts->SystemFont );
610 stock_objects[DEVICE_DEFAULT_FONT] = CreateFontIndirectW( &deffonts->DeviceDefaultFont );
611 stock_objects[SYSTEM_FIXED_FONT] = CreateFontIndirectW( &deffonts->SystemFixedFont );
613 /* For the default gui font, we use the lfHeight member in deffonts as a place-holder
614 for the point size so we must convert this into a true height */
615 memcpy(&default_gui_font, &deffonts->DefaultGuiFont, sizeof(default_gui_font));
616 default_gui_font.lfHeight = -MulDiv(default_gui_font.lfHeight, get_dpi(), 72);
617 stock_objects[DEFAULT_GUI_FONT] = CreateFontIndirectW( &default_gui_font );
619 stock_objects[DC_BRUSH] = CreateBrushIndirect( &DCBrush );
620 stock_objects[DC_PEN] = CreatePenIndirect( &DCPen );
622 /* clear the NOSYSTEM bit on all stock objects*/
623 for (i = 0; i < NB_STOCK_OBJECTS; i++)
625 if (!stock_objects[i])
627 if (i == 9) continue; /* there's no stock object 9 */
628 ERR( "could not create stock object %d\n", i );
631 __wine_make_gdi_object_system( stock_objects[i], TRUE );
639 #define FIRST_LARGE_HANDLE 16
640 #define MAX_LARGE_HANDLES ((GDI_HEAP_SIZE >> 2) - FIRST_LARGE_HANDLE)
641 static GDIOBJHDR *large_handles[MAX_LARGE_HANDLES];
642 static int next_large_handle;
644 /***********************************************************************
647 * Allocate a GDI handle from the large heap. Helper for GDI_AllocObject
649 inline static GDIOBJHDR *alloc_large_heap( WORD size, HGDIOBJ *handle )
654 for (i = next_large_handle + 1; i < MAX_LARGE_HANDLES; i++)
655 if (!large_handles[i]) goto found;
656 for (i = 0; i <= next_large_handle; i++)
657 if (!large_handles[i]) goto found;
662 if ((obj = HeapAlloc( GetProcessHeap(), 0, size )))
664 large_handles[i] = obj;
665 *handle = (HGDIOBJ)(ULONG_PTR)((i + FIRST_LARGE_HANDLE) << 2);
666 next_large_handle = i;
672 /***********************************************************************
675 void *GDI_AllocObject( WORD size, WORD magic, HGDIOBJ *handle, const struct gdi_obj_funcs *funcs )
677 GDIOBJHDR *obj = NULL;
679 _EnterSysLevel( &GDI_level );
680 if (!(obj = alloc_large_heap( size, handle ))) goto error;
682 obj->wMagic = magic|OBJECT_NOSYSTEM;
687 TRACE("(%p): enter %ld\n", *handle, GDI_level.crst.RecursionCount);
691 _LeaveSysLevel( &GDI_level );
697 /***********************************************************************
700 * The object ptr must have been obtained with GDI_GetObjPtr.
701 * The new pointer must be released with GDI_ReleaseObj.
703 void *GDI_ReallocObject( WORD size, HGDIOBJ handle, void *object )
705 void *new_ptr = NULL;
708 i = ((ULONG_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
709 if (i >= 0 && i < MAX_LARGE_HANDLES && large_handles[i])
711 new_ptr = HeapReAlloc( GetProcessHeap(), 0, large_handles[i], size );
712 if (new_ptr) large_handles[i] = new_ptr;
714 else ERR( "Invalid handle %p\n", handle );
717 TRACE("(%p): leave %ld\n", handle, GDI_level.crst.RecursionCount);
718 _LeaveSysLevel( &GDI_level );
724 /***********************************************************************
727 BOOL GDI_FreeObject( HGDIOBJ handle, void *ptr )
729 GDIOBJHDR *object = ptr;
732 object->wMagic = 0; /* Mark it as invalid */
733 object->funcs = NULL;
734 i = ((ULONG_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
735 if (i >= 0 && i < MAX_LARGE_HANDLES && large_handles[i])
737 HeapFree( GetProcessHeap(), 0, large_handles[i] );
738 large_handles[i] = NULL;
740 else ERR( "Invalid handle %p\n", handle );
741 TRACE("(%p): leave %ld\n", handle, GDI_level.crst.RecursionCount);
742 _LeaveSysLevel( &GDI_level );
747 /***********************************************************************
750 * Return a pointer to the GDI object associated to the handle.
751 * Return NULL if the object has the wrong magic number.
752 * The object must be released with GDI_ReleaseObj.
754 void *GDI_GetObjPtr( HGDIOBJ handle, WORD magic )
756 GDIOBJHDR *ptr = NULL;
759 _EnterSysLevel( &GDI_level );
761 i = ((UINT_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
762 if (i >= 0 && i < MAX_LARGE_HANDLES)
764 ptr = large_handles[i];
765 if (ptr && (magic != MAGIC_DONTCARE) && (GDIMAGIC(ptr->wMagic) != magic)) ptr = NULL;
770 _LeaveSysLevel( &GDI_level );
771 WARN( "Invalid handle %p\n", handle );
773 else TRACE("(%p): enter %ld\n", handle, GDI_level.crst.RecursionCount);
779 /***********************************************************************
783 void GDI_ReleaseObj( HGDIOBJ handle )
785 TRACE("(%p): leave %ld\n", handle, GDI_level.crst.RecursionCount);
786 _LeaveSysLevel( &GDI_level );
790 /***********************************************************************
793 void GDI_CheckNotLock(void)
795 _CheckNotSysLevel( &GDI_level );
799 /***********************************************************************
800 * DeleteObject (GDI32.@)
802 * Delete a Gdi object.
805 * obj [I] Gdi object to delete
808 * Success: TRUE. If obj was not returned from GetStockObject(), any resources
809 * it consumed are released.
810 * Failure: FALSE, if obj is not a valid Gdi object, or is currently selected
813 BOOL WINAPI DeleteObject( HGDIOBJ obj )
815 /* Check if object is valid */
818 if (HIWORD(obj)) return FALSE;
820 if (!(header = GDI_GetObjPtr( obj, MAGIC_DONTCARE ))) return FALSE;
822 if (!(header->wMagic & OBJECT_NOSYSTEM)
823 && (header->wMagic >= FIRST_MAGIC) && (header->wMagic <= LAST_MAGIC))
825 TRACE("Preserving system object %p\n", obj);
826 GDI_ReleaseObj( obj );
832 DC *dc = DC_GetDCPtr(header->hdcs->hdc);
833 struct hdc_list *tmp;
835 TRACE("hdc %p has interest in %p\n", header->hdcs->hdc, obj);
838 if(dc->funcs->pDeleteObject)
839 dc->funcs->pDeleteObject( dc->physDev, obj );
840 GDI_ReleaseObj( header->hdcs->hdc );
843 header->hdcs = header->hdcs->next;
844 HeapFree(GetProcessHeap(), 0, tmp);
849 TRACE("delayed for %p because object in use, count %ld\n", obj, header->dwCount );
850 header->dwCount |= 0x80000000; /* mark for delete */
851 GDI_ReleaseObj( obj );
859 if (header->funcs && header->funcs->pDeleteObject)
860 return header->funcs->pDeleteObject( obj, header );
862 GDI_ReleaseObj( obj );
866 /***********************************************************************
867 * GDI_hdc_using_object
869 * Call this if the dc requires DeleteObject notification
871 BOOL GDI_hdc_using_object(HGDIOBJ obj, HDC hdc)
874 struct hdc_list **pphdc;
876 TRACE("obj %p hdc %p\n", obj, hdc);
878 if (!(header = GDI_GetObjPtr( obj, MAGIC_DONTCARE ))) return FALSE;
880 if (!(header->wMagic & OBJECT_NOSYSTEM) &&
881 (header->wMagic >= FIRST_MAGIC) && (header->wMagic <= LAST_MAGIC))
887 for(pphdc = &header->hdcs; *pphdc; pphdc = &(*pphdc)->next)
888 if((*pphdc)->hdc == hdc)
892 *pphdc = HeapAlloc(GetProcessHeap(), 0, sizeof(**pphdc));
894 (*pphdc)->next = NULL;
901 /***********************************************************************
902 * GDI_hdc_not_using_object
905 BOOL GDI_hdc_not_using_object(HGDIOBJ obj, HDC hdc)
908 struct hdc_list *phdc, **prev;
910 TRACE("obj %p hdc %p\n", obj, hdc);
912 if (!(header = GDI_GetObjPtr( obj, MAGIC_DONTCARE ))) return FALSE;
914 if (!(header->wMagic & OBJECT_NOSYSTEM) &&
915 (header->wMagic >= FIRST_MAGIC) && (header->wMagic <= LAST_MAGIC))
922 prev = &header->hdcs;
925 if(phdc->hdc == hdc) {
927 HeapFree(GetProcessHeap(), 0, phdc);
939 /***********************************************************************
940 * GetStockObject (GDI32.@)
942 HGDIOBJ WINAPI GetStockObject( INT obj )
945 if ((obj < 0) || (obj >= NB_STOCK_OBJECTS)) return 0;
946 ret = stock_objects[obj];
947 TRACE("returning %p\n", ret );
952 /***********************************************************************
955 INT16 WINAPI GetObject16( HGDIOBJ16 handle16, INT16 count, LPVOID buffer )
958 HGDIOBJ handle = HGDIOBJ_32( handle16 );
961 TRACE("%p %d %p\n", handle, count, buffer );
962 if (!count) return 0;
964 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
966 if (ptr->funcs && ptr->funcs->pGetObject16)
967 result = ptr->funcs->pGetObject16( handle, ptr, count, buffer );
969 SetLastError( ERROR_INVALID_HANDLE );
971 GDI_ReleaseObj( handle );
976 /***********************************************************************
977 * GetObjectA (GDI32.@)
979 INT WINAPI GetObjectA( HGDIOBJ handle, INT count, LPVOID buffer )
983 TRACE("%p %d %p\n", handle, count, buffer );
985 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
987 if (ptr->funcs && ptr->funcs->pGetObjectA)
988 result = ptr->funcs->pGetObjectA( handle, ptr, count, buffer );
990 SetLastError( ERROR_INVALID_HANDLE );
992 GDI_ReleaseObj( handle );
996 /***********************************************************************
997 * GetObjectW (GDI32.@)
999 INT WINAPI GetObjectW( HGDIOBJ handle, INT count, LPVOID buffer )
1003 TRACE("%p %d %p\n", handle, count, buffer );
1005 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
1007 if (ptr->funcs && ptr->funcs->pGetObjectW)
1008 result = ptr->funcs->pGetObjectW( handle, ptr, count, buffer );
1010 SetLastError( ERROR_INVALID_HANDLE );
1012 GDI_ReleaseObj( handle );
1016 /***********************************************************************
1017 * GetObjectType (GDI32.@)
1019 DWORD WINAPI GetObjectType( HGDIOBJ handle )
1023 TRACE("%p\n", handle );
1025 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE )))
1027 SetLastError( ERROR_INVALID_HANDLE );
1031 switch(GDIMAGIC(ptr->wMagic))
1040 result = OBJ_BITMAP;
1049 result = OBJ_REGION;
1055 result = OBJ_METADC;
1057 case METAFILE_MAGIC:
1058 result = OBJ_METAFILE;
1060 case METAFILE_DC_MAGIC:
1061 result = OBJ_METADC;
1063 case ENHMETAFILE_MAGIC:
1064 result = OBJ_ENHMETAFILE;
1066 case ENHMETAFILE_DC_MAGIC:
1067 result = OBJ_ENHMETADC;
1069 case MEMORY_DC_MAGIC:
1073 FIXME("Magic %04x not implemented\n", GDIMAGIC(ptr->wMagic) );
1076 GDI_ReleaseObj( handle );
1080 /***********************************************************************
1081 * GetCurrentObject (GDI32.@)
1083 * Get the currently selected object of a given type in a device context.
1086 * hdc [I] Device context to get the current object from
1087 * type [I] Type of current object to get (OBJ_* defines from "wingdi.h")
1090 * Success: The current object of the given type selected in hdc.
1091 * Failure: A NULL handle.
1094 * - only the following object types are supported:
1101 HGDIOBJ WINAPI GetCurrentObject(HDC hdc,UINT type)
1104 DC * dc = DC_GetDCPtr( hdc );
1109 case OBJ_EXTPEN: /* fall through */
1110 case OBJ_PEN: ret = dc->hPen; break;
1111 case OBJ_BRUSH: ret = dc->hBrush; break;
1112 case OBJ_PAL: ret = dc->hPalette; break;
1113 case OBJ_FONT: ret = dc->hFont; break;
1114 case OBJ_BITMAP: ret = dc->hBitmap; break;
1116 /* tests show that OBJ_REGION is explicitly ignored */
1117 case OBJ_REGION: break;
1119 /* the SDK only mentions those above */
1120 FIXME("(%p,%d): unknown type.\n",hdc,type);
1123 GDI_ReleaseObj( hdc );
1129 /***********************************************************************
1130 * SelectObject (GDI32.@)
1132 * Select a Gdi object into a device context.
1135 * hdc [I] Device context to associate the object with
1136 * hObj [I] Gdi object to associate with hdc
1139 * Success: A non-NULL handle representing the previously selected object of
1140 * the same type as hObj.
1141 * Failure: A NULL object. If hdc is invalid, GetLastError() returns ERROR_INVALID_HANDLE.
1142 * if hObj is not a valid object handle, no last error is set. In either
1143 * case, hdc is unaffected by the call.
1145 HGDIOBJ WINAPI SelectObject( HDC hdc, HGDIOBJ hObj )
1151 TRACE( "(%p,%p)\n", hdc, hObj );
1153 if (!(dc = DC_GetDCPtr( hdc )))
1154 SetLastError( ERROR_INVALID_HANDLE );
1157 GDI_ReleaseObj( hdc );
1159 header = GDI_GetObjPtr( hObj, MAGIC_DONTCARE );
1162 if (header->funcs && header->funcs->pSelectObject)
1164 ret = header->funcs->pSelectObject( hObj, header, hdc );
1165 if (ret && ret != hObj && (INT)ret > COMPLEXREGION)
1167 inc_ref_count( hObj );
1168 dec_ref_count( ret );
1171 GDI_ReleaseObj( hObj );
1178 /***********************************************************************
1179 * UnrealizeObject (GDI32.@)
1181 BOOL WINAPI UnrealizeObject( HGDIOBJ obj )
1184 /* Check if object is valid */
1186 GDIOBJHDR * header = GDI_GetObjPtr( obj, MAGIC_DONTCARE );
1187 if (!header) return FALSE;
1189 TRACE("%p\n", obj );
1191 /* Unrealize object */
1193 if (header->funcs && header->funcs->pUnrealizeObject)
1194 result = header->funcs->pUnrealizeObject( obj, header );
1196 GDI_ReleaseObj( obj );
1201 /* Solid colors to enumerate */
1202 static const COLORREF solid_colors[] =
1203 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
1204 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
1205 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
1206 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
1207 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
1208 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
1209 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
1210 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
1214 /***********************************************************************
1215 * EnumObjects (GDI32.@)
1217 INT WINAPI EnumObjects( HDC hdc, INT nObjType,
1218 GOBJENUMPROC lpEnumFunc, LPARAM lParam )
1225 TRACE("%p %d %p %08lx\n", hdc, nObjType, lpEnumFunc, lParam );
1229 /* Enumerate solid pens */
1230 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1232 pen.lopnStyle = PS_SOLID;
1233 pen.lopnWidth.x = 1;
1234 pen.lopnWidth.y = 0;
1235 pen.lopnColor = solid_colors[i];
1236 retval = lpEnumFunc( &pen, lParam );
1237 TRACE("solid pen %08lx, ret=%d\n",
1238 solid_colors[i], retval);
1244 /* Enumerate solid brushes */
1245 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1247 brush.lbStyle = BS_SOLID;
1248 brush.lbColor = solid_colors[i];
1250 retval = lpEnumFunc( &brush, lParam );
1251 TRACE("solid brush %08lx, ret=%d\n",
1252 solid_colors[i], retval);
1256 /* Now enumerate hatched brushes */
1257 if (retval) for (i = HS_HORIZONTAL; i <= HS_DIAGCROSS; i++)
1259 brush.lbStyle = BS_HATCHED;
1260 brush.lbColor = RGB(0,0,0);
1262 retval = lpEnumFunc( &brush, lParam );
1263 TRACE("hatched brush %d, ret=%d\n",
1270 /* FIXME: implement Win32 types */
1271 WARN("(%d): Invalid type\n", nObjType );
1278 /***********************************************************************
1279 * IsGDIObject (GDI.462)
1281 * returns type of object if valid (W95 system programming secrets p. 264-5)
1283 BOOL16 WINAPI IsGDIObject16( HGDIOBJ16 handle16 )
1286 HGDIOBJ handle = HGDIOBJ_32( handle16 );
1288 GDIOBJHDR *object = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1291 magic = GDIMAGIC(object->wMagic) - PEN_MAGIC + 1;
1292 GDI_ReleaseObj( handle );
1298 /***********************************************************************
1299 * SetObjectOwner (GDI32.@)
1301 void WINAPI SetObjectOwner( HGDIOBJ handle, HANDLE owner )
1307 /***********************************************************************
1308 * MakeObjectPrivate (GDI.463)
1310 * What does that mean ?
1311 * Some little docu can be found in "Undocumented Windows",
1312 * but this is basically useless.
1313 * At least we know that this flags the GDI object's wMagic
1314 * with 0x2000 (OBJECT_PRIVATE), so we just do it.
1315 * But Wine doesn't react on that yet.
1317 void WINAPI MakeObjectPrivate16( HGDIOBJ16 handle16, BOOL16 private )
1319 HGDIOBJ handle = HGDIOBJ_32( handle16 );
1320 GDIOBJHDR *ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1323 ERR("invalid GDI object %p !\n", handle);
1326 ptr->wMagic |= OBJECT_PRIVATE;
1327 GDI_ReleaseObj( handle );
1331 /***********************************************************************
1332 * GdiFlush (GDI32.@)
1334 BOOL WINAPI GdiFlush(void)
1336 return TRUE; /* FIXME */
1340 /***********************************************************************
1341 * GdiGetBatchLimit (GDI32.@)
1343 DWORD WINAPI GdiGetBatchLimit(void)
1345 return 1; /* FIXME */
1349 /***********************************************************************
1350 * GdiSetBatchLimit (GDI32.@)
1352 DWORD WINAPI GdiSetBatchLimit( DWORD limit )
1354 return 1; /* FIXME */
1358 /***********************************************************************
1359 * GdiSeeGdiDo (GDI.452)
1361 DWORD WINAPI GdiSeeGdiDo16( WORD wReqType, WORD wParam1, WORD wParam2,
1368 case 0x0001: /* LocalAlloc */
1369 WARN("LocalAlloc16(%x, %x): ignoring\n", wParam1, wParam3);
1372 case 0x0002: /* LocalFree */
1373 WARN("LocalFree16(%x): ignoring\n", wParam1);
1376 case 0x0003: /* LocalCompact */
1377 WARN("LocalCompact16(%x): ignoring\n", wParam3);
1378 ret = 65000; /* lie about the amount of free space */
1380 case 0x0103: /* LocalHeap */
1381 WARN("LocalHeap16(): ignoring\n");
1384 WARN("(wReqType=%04x): Unknown\n", wReqType);
1390 /***********************************************************************
1391 * GdiSignalProc32 (GDI.610)
1393 WORD WINAPI GdiSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
1394 DWORD dwFlags, HMODULE16 hModule )
1399 /***********************************************************************
1400 * GdiInit2 (GDI.403)
1402 * See "Undocumented Windows"
1406 * h2 [I] global data
1408 HANDLE16 WINAPI GdiInit216( HANDLE16 h1, HANDLE16 h2 )
1410 FIXME("(%04x, %04x), stub.\n", h1, h2);
1412 return 0xffff; /* undefined return value */
1413 return h1; /* FIXME: should be the memory handle of h1 */
1416 /***********************************************************************
1417 * FinalGdiInit (GDI.405)
1419 void WINAPI FinalGdiInit16( HBRUSH16 hPattern /* [in] fill pattern of desktop */ )
1423 /***********************************************************************
1424 * GdiFreeResources (GDI.609)
1426 WORD WINAPI GdiFreeResources16( DWORD reserve )
1428 return 90; /* lie about it, it shouldn't matter */
1432 /*******************************************************************
1433 * GetColorAdjustment [GDI32.@]
1437 BOOL WINAPI GetColorAdjustment(HDC hdc, LPCOLORADJUSTMENT lpca)
1439 FIXME("GetColorAdjustment, stub\n");
1443 /*******************************************************************
1444 * GdiComment [GDI32.@]
1448 BOOL WINAPI GdiComment(HDC hdc, UINT cbSize, const BYTE *lpData)
1450 DC *dc = DC_GetDCPtr(hdc);
1454 if (dc->funcs->pGdiComment)
1455 ret = dc->funcs->pGdiComment( dc->physDev, cbSize, lpData );
1457 GDI_ReleaseObj( hdc );
1461 /*******************************************************************
1462 * SetColorAdjustment [GDI32.@]
1466 BOOL WINAPI SetColorAdjustment(HDC hdc, const COLORADJUSTMENT* lpca)
1468 FIXME("SetColorAdjustment, stub\n");