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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
35 #include "gdi_private.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
40 #define HGDIOBJ_32(h16) ((HGDIOBJ)(ULONG_PTR)(h16))
42 #define GDI_HEAP_SIZE 0xffe0
44 /***********************************************************************
48 static const LOGBRUSH WhiteBrush = { BS_SOLID, RGB(255,255,255), 0 };
49 static const LOGBRUSH BlackBrush = { BS_SOLID, RGB(0,0,0), 0 };
50 static const LOGBRUSH NullBrush = { BS_NULL, 0, 0 };
52 static const LOGBRUSH LtGrayBrush = { BS_SOLID, RGB(192,192,192), 0 };
53 static const LOGBRUSH GrayBrush = { BS_SOLID, RGB(128,128,128), 0 };
54 static const LOGBRUSH DkGrayBrush = { BS_SOLID, RGB(64,64,64), 0 };
56 static const LOGPEN WhitePen = { PS_SOLID, { 0, 0 }, RGB(255,255,255) };
57 static const LOGPEN BlackPen = { PS_SOLID, { 0, 0 }, RGB(0,0,0) };
58 static const LOGPEN NullPen = { PS_NULL, { 0, 0 }, 0 };
60 static const LOGBRUSH DCBrush = { BS_SOLID, RGB(255,255,255), 0 };
61 static const LOGPEN DCPen = { PS_SOLID, { 0, 0 }, RGB(0,0,0) };
63 /* reserve one extra entry for the stock default bitmap */
64 /* this is what Windows does too */
65 #define NB_STOCK_OBJECTS (STOCK_LAST+2)
67 static HGDIOBJ stock_objects[NB_STOCK_OBJECTS];
69 static SYSLEVEL GDI_level;
70 static CRITICAL_SECTION_DEBUG critsect_debug =
72 0, 0, &GDI_level.crst,
73 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
74 0, 0, { (DWORD_PTR)(__FILE__ ": GDI_level") }
76 static SYSLEVEL GDI_level = { { &critsect_debug, -1, 0, 0, 0, 0 }, 3 };
79 /****************************************************************************
81 * language-independent stock fonts
85 static const LOGFONTW OEMFixedFont =
86 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, OEM_CHARSET,
87 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} };
89 static const LOGFONTW AnsiFixedFont =
90 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
91 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} };
93 static const LOGFONTW AnsiVarFont =
94 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
95 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
96 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'} };
98 /******************************************************************************
100 * language-dependent stock fonts
102 * 'ANSI' charset and 'DEFAULT' charset is not same.
103 * The chars in CP_ACP should be drawn with 'DEFAULT' charset.
104 * 'ANSI' charset seems to be identical with ISO-8859-1.
105 * 'DEFAULT' charset is a language-dependent charset.
107 * 'System' font seems to be an alias for language-dependent font.
111 * language-dependent stock fonts for all known charsets
112 * please see TranslateCharsetInfo (dlls/gdi/font.c) and
113 * CharsetBindingInfo (dlls/x11drv/xfont.c),
114 * and modify entries for your language if needed.
116 struct DefaultFontInfo
120 LOGFONTW DeviceDefaultFont;
121 LOGFONTW SystemFixedFont;
122 LOGFONTW DefaultGuiFont; /* Note for this font the lfHeight member should be the point size */
125 static const struct DefaultFontInfo default_fonts[] =
129 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
130 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
131 {'S','y','s','t','e','m','\0'}
133 { /* Device Default */
134 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
135 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
139 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
140 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
143 { /* DefaultGuiFont */
144 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
145 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
146 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
149 { EASTEUROPE_CHARSET,
151 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
152 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
153 {'S','y','s','t','e','m','\0'}
155 { /* Device Default */
156 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
157 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
161 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
162 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
165 { /* DefaultGuiFont */
166 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
167 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
168 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
173 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
174 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
175 {'S','y','s','t','e','m','\0'}
177 { /* Device Default */
178 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
179 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
183 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
184 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
187 { /* DefaultGuiFont */
188 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
189 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
190 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
195 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
196 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
197 {'S','y','s','t','e','m','\0'}
199 { /* Device Default */
200 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
201 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
205 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
206 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
209 { /* DefaultGuiFont */
210 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
211 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
212 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
217 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
218 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
219 {'S','y','s','t','e','m','\0'}
221 { /* Device Default */
222 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
223 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
227 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
228 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
231 { /* DefaultGuiFont */
232 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
233 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
234 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
239 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
240 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
241 {'S','y','s','t','e','m','\0'}
243 { /* Device Default */
244 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
245 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
249 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
250 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
253 { /* DefaultGuiFont */
254 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
255 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
256 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
261 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
262 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
263 {'S','y','s','t','e','m','\0'}
265 { /* Device Default */
266 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
267 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
271 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
272 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
275 { /* DefaultGuiFont */
276 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
277 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
278 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
283 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
284 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
285 {'S','y','s','t','e','m','\0'}
287 { /* Device Default */
288 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
289 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
293 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
294 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
297 { /* DefaultGuiFont */
298 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
299 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
300 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
305 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
306 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
307 {'S','y','s','t','e','m','\0'}
309 { /* Device Default */
310 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
311 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
315 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
316 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
319 { /* DefaultGuiFont */
320 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
321 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
322 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
327 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
328 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
329 {'S','y','s','t','e','m','\0'}
331 { /* Device Default */
332 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
333 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
337 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
338 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
341 { /* DefaultGuiFont */
342 9, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
343 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
344 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
349 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
350 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
351 {'S','y','s','t','e','m','\0'}
353 { /* Device Default */
354 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
355 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
359 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
360 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
363 { /* DefaultGuiFont */
364 9, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
365 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
366 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
371 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
372 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
373 {'S','y','s','t','e','m','\0'}
375 { /* Device Default */
376 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
377 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
381 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
382 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
385 { /* DefaultGuiFont */
386 9, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
387 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
388 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
391 { CHINESEBIG5_CHARSET,
393 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
394 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
395 {'S','y','s','t','e','m','\0'}
397 { /* Device Default */
398 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
399 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
403 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
404 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
407 { /* DefaultGuiFont */
408 9, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
409 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
410 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
415 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
416 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
417 {'S','y','s','t','e','m','\0'}
419 { /* Device Default */
420 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
421 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
425 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
426 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
429 { /* DefaultGuiFont */
430 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
431 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
432 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
438 /*************************************************************************
439 * __wine_make_gdi_object_system (GDI32.@)
441 * USER has to tell GDI that its system brushes and pens are non-deletable.
442 * For a description of the GDI object magics and their flags,
443 * see "Undocumented Windows" (wrong about the OBJECT_NOSYSTEM flag, though).
445 void CDECL __wine_make_gdi_object_system( HGDIOBJ handle, BOOL set)
447 GDIOBJHDR *ptr = GDI_GetObjPtr( handle, 0 );
449 GDI_ReleaseObj( handle );
452 /******************************************************************************
455 static const struct DefaultFontInfo* get_default_fonts(UINT charset)
459 for(n=0;n<(sizeof(default_fonts)/sizeof(default_fonts[0]));n++)
461 if ( default_fonts[n].charset == charset )
462 return &default_fonts[n];
465 FIXME( "unhandled charset 0x%08x - use ANSI_CHARSET for default stock objects\n", charset );
466 return &default_fonts[0];
470 /******************************************************************************
471 * get_default_charset (internal)
473 * get the language-dependent charset that can handle CP_ACP correctly.
475 static UINT get_default_charset( void )
481 csi.ciCharset = ANSI_CHARSET;
482 if ( !TranslateCharsetInfo( ULongToPtr(uACP), &csi, TCI_SRCCODEPAGE ) )
484 FIXME( "unhandled codepage %u - use ANSI_CHARSET for default stock objects\n", uACP );
488 return csi.ciCharset;
491 static const WCHAR dpi_key_name[] = {'S','o','f','t','w','a','r','e','\\','F','o','n','t','s','\0'};
492 static const WCHAR dpi_value_name[] = {'L','o','g','P','i','x','e','l','s','\0'};
494 /******************************************************************************
497 * get the dpi from the registry
499 static DWORD get_dpi( void )
504 if (RegOpenKeyW(HKEY_CURRENT_CONFIG, dpi_key_name, &hkey) == ERROR_SUCCESS)
506 DWORD type, size, new_dpi;
508 size = sizeof(new_dpi);
509 if(RegQueryValueExW(hkey, dpi_value_name, NULL, &type, (void *)&new_dpi, &size) == ERROR_SUCCESS)
511 if(type == REG_DWORD && new_dpi != 0)
520 /***********************************************************************
523 * Increment the reference count of a GDI object.
525 HGDIOBJ GDI_inc_ref_count( HGDIOBJ handle )
529 if ((header = GDI_GetObjPtr( handle, 0 )))
532 GDI_ReleaseObj( handle );
540 /***********************************************************************
543 * Decrement the reference count of a GDI object.
545 BOOL GDI_dec_ref_count( HGDIOBJ handle )
549 if ((header = GDI_GetObjPtr( handle, 0 )))
551 assert( header->selcount );
552 if (!--header->selcount && header->deleted)
554 /* handle delayed DeleteObject*/
556 GDI_ReleaseObj( handle );
557 TRACE( "executing delayed DeleteObject for %p\n", handle );
558 DeleteObject( handle );
560 else GDI_ReleaseObj( handle );
562 return header != NULL;
566 /***********************************************************************
569 * GDI initialization.
573 LOGFONTW default_gui_font;
574 const struct DefaultFontInfo* deffonts;
579 /* create stock objects */
580 stock_objects[WHITE_BRUSH] = CreateBrushIndirect( &WhiteBrush );
581 stock_objects[LTGRAY_BRUSH] = CreateBrushIndirect( &LtGrayBrush );
582 stock_objects[GRAY_BRUSH] = CreateBrushIndirect( &GrayBrush );
583 stock_objects[DKGRAY_BRUSH] = CreateBrushIndirect( &DkGrayBrush );
584 stock_objects[BLACK_BRUSH] = CreateBrushIndirect( &BlackBrush );
585 stock_objects[NULL_BRUSH] = CreateBrushIndirect( &NullBrush );
587 stock_objects[WHITE_PEN] = CreatePenIndirect( &WhitePen );
588 stock_objects[BLACK_PEN] = CreatePenIndirect( &BlackPen );
589 stock_objects[NULL_PEN] = CreatePenIndirect( &NullPen );
591 stock_objects[DEFAULT_PALETTE] = PALETTE_Init();
592 stock_objects[DEFAULT_BITMAP] = CreateBitmap( 1, 1, 1, 1, NULL );
594 /* language-independent stock fonts */
595 stock_objects[OEM_FIXED_FONT] = CreateFontIndirectW( &OEMFixedFont );
596 stock_objects[ANSI_FIXED_FONT] = CreateFontIndirectW( &AnsiFixedFont );
597 stock_objects[ANSI_VAR_FONT] = CreateFontIndirectW( &AnsiVarFont );
599 /* language-dependent stock fonts */
600 deffonts = get_default_fonts(get_default_charset());
601 stock_objects[SYSTEM_FONT] = CreateFontIndirectW( &deffonts->SystemFont );
602 stock_objects[DEVICE_DEFAULT_FONT] = CreateFontIndirectW( &deffonts->DeviceDefaultFont );
603 stock_objects[SYSTEM_FIXED_FONT] = CreateFontIndirectW( &deffonts->SystemFixedFont );
605 /* For the default gui font, we use the lfHeight member in deffonts as a place-holder
606 for the point size so we must convert this into a true height */
607 default_gui_font = deffonts->DefaultGuiFont;
608 default_gui_font.lfHeight = -MulDiv(default_gui_font.lfHeight, get_dpi(), 72);
609 stock_objects[DEFAULT_GUI_FONT] = CreateFontIndirectW( &default_gui_font );
611 stock_objects[DC_BRUSH] = CreateBrushIndirect( &DCBrush );
612 stock_objects[DC_PEN] = CreatePenIndirect( &DCPen );
614 /* clear the NOSYSTEM bit on all stock objects*/
615 for (i = 0; i < NB_STOCK_OBJECTS; i++)
617 if (!stock_objects[i])
619 if (i == 9) continue; /* there's no stock object 9 */
620 ERR( "could not create stock object %d\n", i );
623 __wine_make_gdi_object_system( stock_objects[i], TRUE );
629 #define FIRST_LARGE_HANDLE 16
630 #define MAX_LARGE_HANDLES ((GDI_HEAP_SIZE >> 2) - FIRST_LARGE_HANDLE)
631 static GDIOBJHDR *large_handles[MAX_LARGE_HANDLES];
632 static int next_large_handle;
634 /***********************************************************************
637 * Allocate a GDI handle for an object, which must have been allocated on the process heap.
639 HGDIOBJ alloc_gdi_handle( GDIOBJHDR *obj, WORD type, const struct gdi_obj_funcs *funcs )
643 /* initialize the object header */
651 _EnterSysLevel( &GDI_level );
652 for (i = next_large_handle + 1; i < MAX_LARGE_HANDLES; i++)
653 if (!large_handles[i]) goto found;
654 for (i = 0; i <= next_large_handle; i++)
655 if (!large_handles[i]) goto found;
656 _LeaveSysLevel( &GDI_level );
660 large_handles[i] = obj;
661 next_large_handle = i;
662 _LeaveSysLevel( &GDI_level );
663 return (HGDIOBJ)(ULONG_PTR)((i + FIRST_LARGE_HANDLE) << 2);
667 /***********************************************************************
670 * Free a GDI handle and return a pointer to the object.
672 void *free_gdi_handle( HGDIOBJ handle )
674 GDIOBJHDR *object = NULL;
677 i = ((ULONG_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
678 if (i >= 0 && i < MAX_LARGE_HANDLES)
680 _EnterSysLevel( &GDI_level );
681 object = large_handles[i];
682 large_handles[i] = NULL;
683 _LeaveSysLevel( &GDI_level );
687 object->type = 0; /* mark it as invalid */
688 object->funcs = NULL;
694 /***********************************************************************
697 * Return a pointer to the GDI object associated to the handle.
698 * Return NULL if the object has the wrong magic number.
699 * The object must be released with GDI_ReleaseObj.
701 void *GDI_GetObjPtr( HGDIOBJ handle, WORD type )
703 GDIOBJHDR *ptr = NULL;
706 _EnterSysLevel( &GDI_level );
708 i = ((UINT_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
709 if (i >= 0 && i < MAX_LARGE_HANDLES)
711 ptr = large_handles[i];
712 if (ptr && type && ptr->type != type) ptr = NULL;
717 _LeaveSysLevel( &GDI_level );
718 WARN( "Invalid handle %p\n", handle );
720 else TRACE("(%p): enter %d\n", handle, GDI_level.crst.RecursionCount);
726 /***********************************************************************
730 void GDI_ReleaseObj( HGDIOBJ handle )
732 TRACE("(%p): leave %d\n", handle, GDI_level.crst.RecursionCount);
733 _LeaveSysLevel( &GDI_level );
737 /***********************************************************************
740 void GDI_CheckNotLock(void)
742 _CheckNotSysLevel( &GDI_level );
746 /***********************************************************************
747 * DeleteObject (GDI32.@)
749 * Delete a Gdi object.
752 * obj [I] Gdi object to delete
755 * Success: TRUE. If obj was not returned from GetStockObject(), any resources
756 * it consumed are released.
757 * Failure: FALSE, if obj is not a valid Gdi object, or is currently selected
760 BOOL WINAPI DeleteObject( HGDIOBJ obj )
762 /* Check if object is valid */
764 struct hdc_list *hdcs_head;
765 const struct gdi_obj_funcs *funcs;
768 if (HIWORD(obj)) return FALSE;
770 if (!(header = GDI_GetObjPtr( obj, 0 ))) return FALSE;
774 TRACE("Preserving system object %p\n", obj);
775 GDI_ReleaseObj( obj );
779 while ((hdcs_head = header->hdcs) != NULL)
781 DC *dc = get_dc_ptr(hdcs_head->hdc);
783 header->hdcs = hdcs_head->next;
784 TRACE("hdc %p has interest in %p\n", hdcs_head->hdc, obj);
788 if(dc->funcs->pDeleteObject)
790 GDI_ReleaseObj( obj ); /* release the GDI lock */
791 dc->funcs->pDeleteObject( dc->physDev, obj );
792 header = GDI_GetObjPtr( obj, 0 ); /* and grab it again */
794 release_dc_ptr( dc );
796 HeapFree(GetProcessHeap(), 0, hdcs_head);
797 if (!header) return FALSE;
800 if (header->selcount)
802 TRACE("delayed for %p because object in use, count %u\n", obj, header->selcount );
803 header->deleted = 1; /* mark for delete */
804 GDI_ReleaseObj( obj );
812 funcs = header->funcs;
813 GDI_ReleaseObj( obj );
814 if (funcs && funcs->pDeleteObject)
815 return funcs->pDeleteObject( obj );
820 /***********************************************************************
821 * GDI_hdc_using_object
823 * Call this if the dc requires DeleteObject notification
825 BOOL GDI_hdc_using_object(HGDIOBJ obj, HDC hdc)
828 struct hdc_list **pphdc;
830 TRACE("obj %p hdc %p\n", obj, hdc);
832 if (!(header = GDI_GetObjPtr( obj, 0 ))) return FALSE;
840 for(pphdc = &header->hdcs; *pphdc; pphdc = &(*pphdc)->next)
841 if((*pphdc)->hdc == hdc)
845 *pphdc = HeapAlloc(GetProcessHeap(), 0, sizeof(**pphdc));
847 (*pphdc)->next = NULL;
854 /***********************************************************************
855 * GDI_hdc_not_using_object
858 BOOL GDI_hdc_not_using_object(HGDIOBJ obj, HDC hdc)
861 struct hdc_list *phdc, **prev;
863 TRACE("obj %p hdc %p\n", obj, hdc);
865 if (!(header = GDI_GetObjPtr( obj, 0 ))) return FALSE;
874 prev = &header->hdcs;
877 if(phdc->hdc == hdc) {
879 HeapFree(GetProcessHeap(), 0, phdc);
891 /***********************************************************************
892 * GetStockObject (GDI32.@)
894 HGDIOBJ WINAPI GetStockObject( INT obj )
897 if ((obj < 0) || (obj >= NB_STOCK_OBJECTS)) return 0;
898 ret = stock_objects[obj];
899 TRACE("returning %p\n", ret );
904 /***********************************************************************
905 * GetObjectA (GDI32.@)
907 INT WINAPI GetObjectA( HGDIOBJ handle, INT count, LPVOID buffer )
909 const struct gdi_obj_funcs *funcs;
913 TRACE("%p %d %p\n", handle, count, buffer );
915 if (!(ptr = GDI_GetObjPtr( handle, 0 ))) return 0;
917 GDI_ReleaseObj( handle );
919 if (funcs && funcs->pGetObjectA)
920 result = funcs->pGetObjectA( handle, count, buffer );
922 SetLastError( ERROR_INVALID_HANDLE );
927 /***********************************************************************
928 * GetObjectW (GDI32.@)
930 INT WINAPI GetObjectW( HGDIOBJ handle, INT count, LPVOID buffer )
932 const struct gdi_obj_funcs *funcs;
935 TRACE("%p %d %p\n", handle, count, buffer );
937 if (!(ptr = GDI_GetObjPtr( handle, 0 ))) return 0;
939 GDI_ReleaseObj( handle );
941 if (funcs && funcs->pGetObjectW)
942 result = funcs->pGetObjectW( handle, count, buffer );
944 SetLastError( ERROR_INVALID_HANDLE );
949 /***********************************************************************
950 * GetObjectType (GDI32.@)
952 DWORD WINAPI GetObjectType( HGDIOBJ handle )
957 if (!(ptr = GDI_GetObjPtr( handle, 0 )))
959 SetLastError( ERROR_INVALID_HANDLE );
963 GDI_ReleaseObj( handle );
964 TRACE("%p -> %u\n", handle, result );
968 /***********************************************************************
969 * GetCurrentObject (GDI32.@)
971 * Get the currently selected object of a given type in a device context.
974 * hdc [I] Device context to get the current object from
975 * type [I] Type of current object to get (OBJ_* defines from "wingdi.h")
978 * Success: The current object of the given type selected in hdc.
979 * Failure: A NULL handle.
982 * - only the following object types are supported:
989 HGDIOBJ WINAPI GetCurrentObject(HDC hdc,UINT type)
992 DC * dc = get_dc_ptr( hdc );
997 case OBJ_EXTPEN: /* fall through */
998 case OBJ_PEN: ret = dc->hPen; break;
999 case OBJ_BRUSH: ret = dc->hBrush; break;
1000 case OBJ_PAL: ret = dc->hPalette; break;
1001 case OBJ_FONT: ret = dc->hFont; break;
1002 case OBJ_BITMAP: ret = dc->hBitmap; break;
1004 /* tests show that OBJ_REGION is explicitly ignored */
1005 case OBJ_REGION: break;
1007 /* the SDK only mentions those above */
1008 FIXME("(%p,%d): unknown type.\n",hdc,type);
1011 release_dc_ptr( dc );
1016 /***********************************************************************
1017 * SelectObject (GDI32.@)
1019 * Select a Gdi object into a device context.
1022 * hdc [I] Device context to associate the object with
1023 * hObj [I] Gdi object to associate with hdc
1026 * Success: A non-NULL handle representing the previously selected object of
1027 * the same type as hObj.
1028 * Failure: A NULL object. If hdc is invalid, GetLastError() returns ERROR_INVALID_HANDLE.
1029 * if hObj is not a valid object handle, no last error is set. In either
1030 * case, hdc is unaffected by the call.
1032 HGDIOBJ WINAPI SelectObject( HDC hdc, HGDIOBJ hObj )
1037 TRACE( "(%p,%p)\n", hdc, hObj );
1039 header = GDI_GetObjPtr( hObj, 0 );
1042 const struct gdi_obj_funcs *funcs = header->funcs;
1043 GDI_ReleaseObj( hObj );
1044 if (funcs && funcs->pSelectObject) ret = funcs->pSelectObject( hObj, hdc );
1050 /***********************************************************************
1051 * UnrealizeObject (GDI32.@)
1053 BOOL WINAPI UnrealizeObject( HGDIOBJ obj )
1055 BOOL result = FALSE;
1056 GDIOBJHDR * header = GDI_GetObjPtr( obj, 0 );
1060 const struct gdi_obj_funcs *funcs = header->funcs;
1062 GDI_ReleaseObj( obj );
1063 if (funcs && funcs->pUnrealizeObject)
1064 result = header->funcs->pUnrealizeObject( obj );
1072 /* Solid colors to enumerate */
1073 static const COLORREF solid_colors[] =
1074 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
1075 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
1076 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
1077 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
1078 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
1079 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
1080 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
1081 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
1085 /***********************************************************************
1086 * EnumObjects (GDI32.@)
1088 INT WINAPI EnumObjects( HDC hdc, INT nObjType,
1089 GOBJENUMPROC lpEnumFunc, LPARAM lParam )
1096 TRACE("%p %d %p %08lx\n", hdc, nObjType, lpEnumFunc, lParam );
1100 /* Enumerate solid pens */
1101 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1103 pen.lopnStyle = PS_SOLID;
1104 pen.lopnWidth.x = 1;
1105 pen.lopnWidth.y = 0;
1106 pen.lopnColor = solid_colors[i];
1107 retval = lpEnumFunc( &pen, lParam );
1108 TRACE("solid pen %08x, ret=%d\n",
1109 solid_colors[i], retval);
1115 /* Enumerate solid brushes */
1116 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1118 brush.lbStyle = BS_SOLID;
1119 brush.lbColor = solid_colors[i];
1121 retval = lpEnumFunc( &brush, lParam );
1122 TRACE("solid brush %08x, ret=%d\n",
1123 solid_colors[i], retval);
1127 /* Now enumerate hatched brushes */
1128 if (retval) for (i = HS_HORIZONTAL; i <= HS_DIAGCROSS; i++)
1130 brush.lbStyle = BS_HATCHED;
1131 brush.lbColor = RGB(0,0,0);
1133 retval = lpEnumFunc( &brush, lParam );
1134 TRACE("hatched brush %d, ret=%d\n",
1141 /* FIXME: implement Win32 types */
1142 WARN("(%d): Invalid type\n", nObjType );
1149 /***********************************************************************
1150 * SetObjectOwner (GDI32.@)
1152 void WINAPI SetObjectOwner( HGDIOBJ handle, HANDLE owner )
1158 /***********************************************************************
1159 * MakeObjectPrivate (GDI.463)
1161 * What does that mean ?
1162 * Some little docu can be found in "Undocumented Windows",
1163 * but this is basically useless.
1165 void WINAPI MakeObjectPrivate16( HGDIOBJ16 handle16, BOOL16 private )
1167 FIXME( "stub: %x %u\n", handle16, private );
1171 /***********************************************************************
1172 * GdiFlush (GDI32.@)
1174 BOOL WINAPI GdiFlush(void)
1176 return TRUE; /* FIXME */
1180 /***********************************************************************
1181 * GdiGetBatchLimit (GDI32.@)
1183 DWORD WINAPI GdiGetBatchLimit(void)
1185 return 1; /* FIXME */
1189 /***********************************************************************
1190 * GdiSetBatchLimit (GDI32.@)
1192 DWORD WINAPI GdiSetBatchLimit( DWORD limit )
1194 return 1; /* FIXME */
1198 /*******************************************************************
1199 * GetColorAdjustment [GDI32.@]
1203 BOOL WINAPI GetColorAdjustment(HDC hdc, LPCOLORADJUSTMENT lpca)
1205 FIXME("GetColorAdjustment, stub\n");
1209 /*******************************************************************
1210 * GdiComment [GDI32.@]
1214 BOOL WINAPI GdiComment(HDC hdc, UINT cbSize, const BYTE *lpData)
1216 DC *dc = get_dc_ptr(hdc);
1220 if (dc->funcs->pGdiComment)
1221 ret = dc->funcs->pGdiComment( dc->physDev, cbSize, lpData );
1222 release_dc_ptr( dc );
1227 /*******************************************************************
1228 * SetColorAdjustment [GDI32.@]
1232 BOOL WINAPI SetColorAdjustment(HDC hdc, const COLORADJUSTMENT* lpca)
1234 FIXME("SetColorAdjustment, stub\n");