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 };
78 inline static BOOL get_bool(char *buffer)
80 return (buffer[0] == 'y' || buffer[0] == 'Y' ||
81 buffer[0] == 't' || buffer[0] == 'T' ||
86 /****************************************************************************
88 * language-independent stock fonts
92 static const LOGFONTW OEMFixedFont =
93 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, OEM_CHARSET,
94 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} };
96 static const LOGFONTW AnsiFixedFont =
97 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
98 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} };
100 static const LOGFONTW AnsiVarFont =
101 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
102 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
103 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'} };
105 /******************************************************************************
107 * language-dependent stock fonts
109 * 'ANSI' charset and 'DEFAULT' charset is not same.
110 * The chars in CP_ACP should be drawn with 'DEFAULT' charset.
111 * 'ANSI' charset seems to be identical with ISO-8859-1.
112 * 'DEFAULT' charset is a language-dependent charset.
114 * 'System' font seems to be an alias for language-dependent font.
118 * language-dependent stock fonts for all known charsets
119 * please see TranslateCharsetInfo (dlls/gdi/font.c) and
120 * CharsetBindingInfo (dlls/x11drv/xfont.c),
121 * and modify entries for your language if needed.
123 struct DefaultFontInfo
127 LOGFONTW DeviceDefaultFont;
128 LOGFONTW SystemFixedFont;
129 LOGFONTW DefaultGuiFont; /* Note for this font the lfHeight member should be the point size */
132 static const struct DefaultFontInfo default_fonts[] =
136 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
137 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
138 {'S','y','s','t','e','m','\0'}
140 { /* Device Default */
141 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
142 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
146 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
147 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
150 { /* DefaultGuiFont */
151 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
152 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
153 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
156 { EASTEUROPE_CHARSET,
158 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
159 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
160 {'S','y','s','t','e','m','\0'}
162 { /* Device Default */
163 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
164 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
168 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
169 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
172 { /* DefaultGuiFont */
173 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
174 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
175 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
180 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
181 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
182 {'S','y','s','t','e','m','\0'}
184 { /* Device Default */
185 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
186 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
190 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
191 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
194 { /* DefaultGuiFont */
195 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
196 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
197 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
202 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
203 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
204 {'S','y','s','t','e','m','\0'}
206 { /* Device Default */
207 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
208 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
212 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
213 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
216 { /* DefaultGuiFont */
217 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
218 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
219 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
224 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
225 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
226 {'S','y','s','t','e','m','\0'}
228 { /* Device Default */
229 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
230 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
234 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
235 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
238 { /* DefaultGuiFont */
239 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
240 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
241 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
246 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
247 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
248 {'S','y','s','t','e','m','\0'}
250 { /* Device Default */
251 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
252 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
256 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
257 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
260 { /* DefaultGuiFont */
261 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
262 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
263 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
268 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
269 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
270 {'S','y','s','t','e','m','\0'}
272 { /* Device Default */
273 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
274 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
278 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
279 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
282 { /* DefaultGuiFont */
283 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
284 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
285 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
290 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
291 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
292 {'S','y','s','t','e','m','\0'}
294 { /* Device Default */
295 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
296 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
300 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
301 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
304 { /* DefaultGuiFont */
305 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
306 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
307 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
312 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
313 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
314 {'S','y','s','t','e','m','\0'}
316 { /* Device Default */
317 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
318 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
322 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
323 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
326 { /* DefaultGuiFont */
327 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
328 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
329 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
334 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
335 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
336 {'S','y','s','t','e','m','\0'}
338 { /* Device Default */
339 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
340 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
344 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
345 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
348 { /* DefaultGuiFont */
349 9, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
350 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
351 {'M','S',' ','U','I',' ','G','o','t','h','i','c','\0'}
356 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
357 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
358 {'S','y','s','t','e','m','\0'}
360 { /* Device Default */
361 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
362 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
366 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
367 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
370 { /* DefaultGuiFont */
371 9, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
372 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
373 {'M','S',' ','S','o','n','g','\0'} /* FIXME: Is this correct? */
378 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
379 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
380 {'S','y','s','t','e','m','\0'}
382 { /* Device Default */
383 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
384 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
388 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
389 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
392 { /* DefaultGuiFont */
393 9, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
394 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
395 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
398 { CHINESEBIG5_CHARSET,
400 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
401 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
402 {'S','y','s','t','e','m','\0'}
404 { /* Device Default */
405 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
406 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
410 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
411 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
414 { /* DefaultGuiFont */
415 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
416 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
417 {'\0'} /* FIXME - what is the native font??? */
422 16, 7, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
423 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
424 {'S','y','s','t','e','m','\0'}
426 { /* Device Default */
427 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
428 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
432 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
433 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
436 { /* DefaultGuiFont */
437 8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
438 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
439 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
445 /*************************************************************************
446 * __wine_make_gdi_object_system (GDI32.@)
448 * USER has to tell GDI that its system brushes and pens are non-deletable.
449 * For a description of the GDI object magics and their flags,
450 * see "Undocumented Windows" (wrong about the OBJECT_NOSYSTEM flag, though).
452 void __wine_make_gdi_object_system( HGDIOBJ handle, BOOL set)
454 GDIOBJHDR *ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
456 /* touch the "system" bit of the wMagic field of a GDIOBJHDR */
458 ptr->wMagic &= ~OBJECT_NOSYSTEM;
460 ptr->wMagic |= OBJECT_NOSYSTEM;
462 GDI_ReleaseObj( handle );
465 /******************************************************************************
468 static const struct DefaultFontInfo* get_default_fonts(UINT charset)
472 for(n=0;n<(sizeof(default_fonts)/sizeof(default_fonts[0]));n++)
474 if ( default_fonts[n].charset == charset )
475 return &default_fonts[n];
478 FIXME( "unhandled charset 0x%08x - use ANSI_CHARSET for default stock objects\n", charset );
479 return &default_fonts[0];
483 /******************************************************************************
484 * get_default_charset (internal)
486 * get the language-dependent charset that can handle CP_ACP correctly.
488 static UINT get_default_charset( void )
494 csi.ciCharset = ANSI_CHARSET;
495 if ( ! TranslateCharsetInfo( (LPDWORD)uACP, &csi, TCI_SRCCODEPAGE ) )
497 FIXME( "unhandled codepage %u - use ANSI_CHARSET for default stock objects\n", uACP );
501 return csi.ciCharset;
504 static const WCHAR dpi_key_name[] = {'S','o','f','t','w','a','r','e','\\','F','o','n','t','s','\0'};
505 static const WCHAR dpi_value_name[] = {'L','o','g','P','i','x','e','l','s','\0'};
507 /******************************************************************************
510 * get the dpi from the registry
512 static DWORD get_dpi( void )
517 if (RegOpenKeyW(HKEY_CURRENT_CONFIG, dpi_key_name, &hkey) == ERROR_SUCCESS)
519 DWORD type, size, new_dpi;
521 size = sizeof(new_dpi);
522 if(RegQueryValueExW(hkey, dpi_value_name, NULL, &type, (void *)&new_dpi, &size) == ERROR_SUCCESS)
524 if(type == REG_DWORD && new_dpi != 0)
533 /***********************************************************************
536 * Increment the reference count of a GDI object.
538 inline static void inc_ref_count( HGDIOBJ handle )
542 if ((header = GDI_GetObjPtr( handle, MAGIC_DONTCARE )))
545 GDI_ReleaseObj( handle );
550 /***********************************************************************
553 * Decrement the reference count of a GDI object.
555 inline static void dec_ref_count( HGDIOBJ handle )
559 if ((header = GDI_GetObjPtr( handle, MAGIC_DONTCARE )))
561 if (header->dwCount) header->dwCount--;
562 if (header->dwCount != 0x80000000) GDI_ReleaseObj( handle );
565 /* handle delayed DeleteObject*/
567 GDI_ReleaseObj( handle );
568 TRACE( "executing delayed DeleteObject for %p\n", handle );
569 DeleteObject( handle );
575 /***********************************************************************
578 * GDI initialization.
582 LOGFONTW default_gui_font;
583 const struct DefaultFontInfo* deffonts;
588 /* create stock objects */
589 stock_objects[WHITE_BRUSH] = CreateBrushIndirect( &WhiteBrush );
590 stock_objects[LTGRAY_BRUSH] = CreateBrushIndirect( &LtGrayBrush );
591 stock_objects[GRAY_BRUSH] = CreateBrushIndirect( &GrayBrush );
592 stock_objects[DKGRAY_BRUSH] = CreateBrushIndirect( &DkGrayBrush );
593 stock_objects[BLACK_BRUSH] = CreateBrushIndirect( &BlackBrush );
594 stock_objects[NULL_BRUSH] = CreateBrushIndirect( &NullBrush );
596 stock_objects[WHITE_PEN] = CreatePenIndirect( &WhitePen );
597 stock_objects[BLACK_PEN] = CreatePenIndirect( &BlackPen );
598 stock_objects[NULL_PEN] = CreatePenIndirect( &NullPen );
600 stock_objects[DEFAULT_PALETTE] = PALETTE_Init();
601 stock_objects[DEFAULT_BITMAP] = CreateBitmap( 1, 1, 1, 1, NULL );
603 /* language-independent stock fonts */
604 stock_objects[OEM_FIXED_FONT] = CreateFontIndirectW( &OEMFixedFont );
605 stock_objects[ANSI_FIXED_FONT] = CreateFontIndirectW( &AnsiFixedFont );
606 stock_objects[ANSI_VAR_FONT] = CreateFontIndirectW( &AnsiVarFont );
608 /* language-dependent stock fonts */
609 deffonts = get_default_fonts(get_default_charset());
610 stock_objects[SYSTEM_FONT] = CreateFontIndirectW( &deffonts->SystemFont );
611 stock_objects[DEVICE_DEFAULT_FONT] = CreateFontIndirectW( &deffonts->DeviceDefaultFont );
612 stock_objects[SYSTEM_FIXED_FONT] = CreateFontIndirectW( &deffonts->SystemFixedFont );
614 /* For the default gui font, we use the lfHeight member in deffonts as a place-holder
615 for the point size so we must convert this into a true height */
616 memcpy(&default_gui_font, &deffonts->DefaultGuiFont, sizeof(default_gui_font));
617 default_gui_font.lfHeight = -MulDiv(default_gui_font.lfHeight, get_dpi(), 72);
618 stock_objects[DEFAULT_GUI_FONT] = CreateFontIndirectW( &default_gui_font );
620 stock_objects[DC_BRUSH] = CreateBrushIndirect( &DCBrush );
621 stock_objects[DC_PEN] = CreatePenIndirect( &DCPen );
623 /* clear the NOSYSTEM bit on all stock objects*/
624 for (i = 0; i < NB_STOCK_OBJECTS; i++)
626 if (!stock_objects[i])
628 if (i == 9) continue; /* there's no stock object 9 */
629 ERR( "could not create stock object %d\n", i );
632 __wine_make_gdi_object_system( stock_objects[i], TRUE );
638 #define FIRST_LARGE_HANDLE 16
639 #define MAX_LARGE_HANDLES ((GDI_HEAP_SIZE >> 2) - FIRST_LARGE_HANDLE)
640 static GDIOBJHDR *large_handles[MAX_LARGE_HANDLES];
641 static int next_large_handle;
643 /***********************************************************************
646 * Allocate a GDI handle from the large heap. Helper for GDI_AllocObject
648 inline static GDIOBJHDR *alloc_large_heap( WORD size, HGDIOBJ *handle )
653 for (i = next_large_handle + 1; i < MAX_LARGE_HANDLES; i++)
654 if (!large_handles[i]) goto found;
655 for (i = 0; i <= next_large_handle; i++)
656 if (!large_handles[i]) goto found;
661 if ((obj = HeapAlloc( GetProcessHeap(), 0, size )))
663 large_handles[i] = obj;
664 *handle = (HGDIOBJ)(ULONG_PTR)((i + FIRST_LARGE_HANDLE) << 2);
665 next_large_handle = i;
671 /***********************************************************************
674 void *GDI_AllocObject( WORD size, WORD magic, HGDIOBJ *handle, const struct gdi_obj_funcs *funcs )
676 GDIOBJHDR *obj = NULL;
678 _EnterSysLevel( &GDI_level );
679 if (!(obj = alloc_large_heap( size, handle ))) goto error;
681 obj->wMagic = magic|OBJECT_NOSYSTEM;
686 TRACE("(%p): enter %d\n", *handle, GDI_level.crst.RecursionCount);
690 _LeaveSysLevel( &GDI_level );
696 /***********************************************************************
699 * The object ptr must have been obtained with GDI_GetObjPtr.
700 * The new pointer must be released with GDI_ReleaseObj.
702 void *GDI_ReallocObject( WORD size, HGDIOBJ handle, void *object )
704 void *new_ptr = NULL;
707 i = ((ULONG_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
708 if (i >= 0 && i < MAX_LARGE_HANDLES && large_handles[i])
710 new_ptr = HeapReAlloc( GetProcessHeap(), 0, large_handles[i], size );
711 if (new_ptr) large_handles[i] = new_ptr;
713 else ERR( "Invalid handle %p\n", handle );
716 TRACE("(%p): leave %d\n", handle, GDI_level.crst.RecursionCount);
717 _LeaveSysLevel( &GDI_level );
723 /***********************************************************************
726 BOOL GDI_FreeObject( HGDIOBJ handle, void *ptr )
728 GDIOBJHDR *object = ptr;
731 object->wMagic = 0; /* Mark it as invalid */
732 object->funcs = NULL;
733 i = ((ULONG_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
734 if (i >= 0 && i < MAX_LARGE_HANDLES)
736 HeapFree( GetProcessHeap(), 0, large_handles[i] );
737 large_handles[i] = NULL;
739 else ERR( "Invalid handle %p\n", handle );
740 TRACE("(%p): leave %d\n", handle, GDI_level.crst.RecursionCount);
741 _LeaveSysLevel( &GDI_level );
746 /***********************************************************************
749 * Return a pointer to the GDI object associated to the handle.
750 * Return NULL if the object has the wrong magic number.
751 * The object must be released with GDI_ReleaseObj.
753 void *GDI_GetObjPtr( HGDIOBJ handle, WORD magic )
755 GDIOBJHDR *ptr = NULL;
758 _EnterSysLevel( &GDI_level );
760 i = ((UINT_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
761 if (i >= 0 && i < MAX_LARGE_HANDLES)
763 ptr = large_handles[i];
764 if (ptr && (magic != MAGIC_DONTCARE) && (GDIMAGIC(ptr->wMagic) != magic)) ptr = NULL;
769 _LeaveSysLevel( &GDI_level );
770 WARN( "Invalid handle %p\n", handle );
772 else TRACE("(%p): enter %d\n", handle, GDI_level.crst.RecursionCount);
778 /***********************************************************************
782 void GDI_ReleaseObj( HGDIOBJ handle )
784 TRACE("(%p): leave %d\n", handle, GDI_level.crst.RecursionCount);
785 _LeaveSysLevel( &GDI_level );
789 /***********************************************************************
792 void GDI_CheckNotLock(void)
794 _CheckNotSysLevel( &GDI_level );
798 /***********************************************************************
799 * DeleteObject (GDI32.@)
801 * Delete a Gdi object.
804 * obj [I] Gdi object to delete
807 * Success: TRUE. If obj was not returned from GetStockObject(), any resources
808 * it consumed are released.
809 * Failure: FALSE, if obj is not a valid Gdi object, or is currently selected
812 BOOL WINAPI DeleteObject( HGDIOBJ obj )
814 /* Check if object is valid */
817 if (HIWORD(obj)) return FALSE;
819 if (!(header = GDI_GetObjPtr( obj, MAGIC_DONTCARE ))) return FALSE;
821 if (!(header->wMagic & OBJECT_NOSYSTEM)
822 && (header->wMagic >= FIRST_MAGIC) && (header->wMagic <= LAST_MAGIC))
824 TRACE("Preserving system object %p\n", obj);
825 GDI_ReleaseObj( obj );
831 DC *dc = DC_GetDCPtr(header->hdcs->hdc);
832 struct hdc_list *tmp;
834 TRACE("hdc %p has interest in %p\n", header->hdcs->hdc, obj);
837 if(dc->funcs->pDeleteObject)
838 dc->funcs->pDeleteObject( dc->physDev, obj );
839 GDI_ReleaseObj( header->hdcs->hdc );
842 header->hdcs = header->hdcs->next;
843 HeapFree(GetProcessHeap(), 0, tmp);
848 TRACE("delayed for %p because object in use, count %d\n", obj, header->dwCount );
849 header->dwCount |= 0x80000000; /* mark for delete */
850 GDI_ReleaseObj( obj );
858 if (header->funcs && header->funcs->pDeleteObject)
859 return header->funcs->pDeleteObject( obj, header );
861 GDI_ReleaseObj( obj );
865 /***********************************************************************
866 * GDI_hdc_using_object
868 * Call this if the dc requires DeleteObject notification
870 BOOL GDI_hdc_using_object(HGDIOBJ obj, HDC hdc)
873 struct hdc_list **pphdc;
875 TRACE("obj %p hdc %p\n", obj, hdc);
877 if (!(header = GDI_GetObjPtr( obj, MAGIC_DONTCARE ))) return FALSE;
879 if (!(header->wMagic & OBJECT_NOSYSTEM) &&
880 (header->wMagic >= FIRST_MAGIC) && (header->wMagic <= LAST_MAGIC))
886 for(pphdc = &header->hdcs; *pphdc; pphdc = &(*pphdc)->next)
887 if((*pphdc)->hdc == hdc)
891 *pphdc = HeapAlloc(GetProcessHeap(), 0, sizeof(**pphdc));
893 (*pphdc)->next = NULL;
900 /***********************************************************************
901 * GDI_hdc_not_using_object
904 BOOL GDI_hdc_not_using_object(HGDIOBJ obj, HDC hdc)
907 struct hdc_list *phdc, **prev;
909 TRACE("obj %p hdc %p\n", obj, hdc);
911 if (!(header = GDI_GetObjPtr( obj, MAGIC_DONTCARE ))) return FALSE;
913 if (!(header->wMagic & OBJECT_NOSYSTEM) &&
914 (header->wMagic >= FIRST_MAGIC) && (header->wMagic <= LAST_MAGIC))
921 prev = &header->hdcs;
924 if(phdc->hdc == hdc) {
926 HeapFree(GetProcessHeap(), 0, phdc);
938 /***********************************************************************
939 * GetStockObject (GDI32.@)
941 HGDIOBJ WINAPI GetStockObject( INT obj )
944 if ((obj < 0) || (obj >= NB_STOCK_OBJECTS)) return 0;
945 ret = stock_objects[obj];
946 TRACE("returning %p\n", ret );
951 /***********************************************************************
954 INT16 WINAPI GetObject16( HGDIOBJ16 handle16, INT16 count, LPVOID buffer )
957 HGDIOBJ handle = HGDIOBJ_32( handle16 );
960 TRACE("%p %d %p\n", handle, count, buffer );
961 if (!count) return 0;
963 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
965 if (ptr->funcs && ptr->funcs->pGetObject16)
966 result = ptr->funcs->pGetObject16( handle, ptr, count, buffer );
968 SetLastError( ERROR_INVALID_HANDLE );
970 GDI_ReleaseObj( handle );
975 /***********************************************************************
976 * GetObjectA (GDI32.@)
978 INT WINAPI GetObjectA( HGDIOBJ handle, INT count, LPVOID buffer )
982 TRACE("%p %d %p\n", handle, count, buffer );
984 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
986 if (ptr->funcs && ptr->funcs->pGetObjectA)
987 result = ptr->funcs->pGetObjectA( handle, ptr, count, buffer );
989 SetLastError( ERROR_INVALID_HANDLE );
991 GDI_ReleaseObj( handle );
995 /***********************************************************************
996 * GetObjectW (GDI32.@)
998 INT WINAPI GetObjectW( HGDIOBJ handle, INT count, LPVOID buffer )
1002 TRACE("%p %d %p\n", handle, count, buffer );
1004 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
1006 if (ptr->funcs && ptr->funcs->pGetObjectW)
1007 result = ptr->funcs->pGetObjectW( handle, ptr, count, buffer );
1009 SetLastError( ERROR_INVALID_HANDLE );
1011 GDI_ReleaseObj( handle );
1015 /***********************************************************************
1016 * GetObjectType (GDI32.@)
1018 DWORD WINAPI GetObjectType( HGDIOBJ handle )
1022 TRACE("%p\n", handle );
1024 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE )))
1026 SetLastError( ERROR_INVALID_HANDLE );
1030 switch(GDIMAGIC(ptr->wMagic))
1036 result = OBJ_EXTPEN;
1042 result = OBJ_BITMAP;
1051 result = OBJ_REGION;
1057 result = OBJ_METADC;
1059 case METAFILE_MAGIC:
1060 result = OBJ_METAFILE;
1062 case METAFILE_DC_MAGIC:
1063 result = OBJ_METADC;
1065 case ENHMETAFILE_MAGIC:
1066 result = OBJ_ENHMETAFILE;
1068 case ENHMETAFILE_DC_MAGIC:
1069 result = OBJ_ENHMETADC;
1071 case MEMORY_DC_MAGIC:
1075 FIXME("Magic %04x not implemented\n", GDIMAGIC(ptr->wMagic) );
1078 GDI_ReleaseObj( handle );
1082 /***********************************************************************
1083 * GetCurrentObject (GDI32.@)
1085 * Get the currently selected object of a given type in a device context.
1088 * hdc [I] Device context to get the current object from
1089 * type [I] Type of current object to get (OBJ_* defines from "wingdi.h")
1092 * Success: The current object of the given type selected in hdc.
1093 * Failure: A NULL handle.
1096 * - only the following object types are supported:
1103 HGDIOBJ WINAPI GetCurrentObject(HDC hdc,UINT type)
1106 DC * dc = DC_GetDCPtr( hdc );
1111 case OBJ_EXTPEN: /* fall through */
1112 case OBJ_PEN: ret = dc->hPen; break;
1113 case OBJ_BRUSH: ret = dc->hBrush; break;
1114 case OBJ_PAL: ret = dc->hPalette; break;
1115 case OBJ_FONT: ret = dc->hFont; break;
1116 case OBJ_BITMAP: ret = dc->hBitmap; break;
1118 /* tests show that OBJ_REGION is explicitly ignored */
1119 case OBJ_REGION: break;
1121 /* the SDK only mentions those above */
1122 FIXME("(%p,%d): unknown type.\n",hdc,type);
1125 GDI_ReleaseObj( hdc );
1131 /***********************************************************************
1132 * SelectObject (GDI32.@)
1134 * Select a Gdi object into a device context.
1137 * hdc [I] Device context to associate the object with
1138 * hObj [I] Gdi object to associate with hdc
1141 * Success: A non-NULL handle representing the previously selected object of
1142 * the same type as hObj.
1143 * Failure: A NULL object. If hdc is invalid, GetLastError() returns ERROR_INVALID_HANDLE.
1144 * if hObj is not a valid object handle, no last error is set. In either
1145 * case, hdc is unaffected by the call.
1147 HGDIOBJ WINAPI SelectObject( HDC hdc, HGDIOBJ hObj )
1153 TRACE( "(%p,%p)\n", hdc, hObj );
1155 if (!(dc = DC_GetDCPtr( hdc )))
1156 SetLastError( ERROR_INVALID_HANDLE );
1159 GDI_ReleaseObj( hdc );
1161 header = GDI_GetObjPtr( hObj, MAGIC_DONTCARE );
1164 if (header->funcs && header->funcs->pSelectObject)
1166 ret = header->funcs->pSelectObject( hObj, header, hdc );
1167 if (ret && ret != hObj && (INT)ret > COMPLEXREGION)
1169 inc_ref_count( hObj );
1170 dec_ref_count( ret );
1173 GDI_ReleaseObj( hObj );
1180 /***********************************************************************
1181 * UnrealizeObject (GDI32.@)
1183 BOOL WINAPI UnrealizeObject( HGDIOBJ obj )
1186 /* Check if object is valid */
1188 GDIOBJHDR * header = GDI_GetObjPtr( obj, MAGIC_DONTCARE );
1189 if (!header) return FALSE;
1191 TRACE("%p\n", obj );
1193 /* Unrealize object */
1195 if (header->funcs && header->funcs->pUnrealizeObject)
1196 result = header->funcs->pUnrealizeObject( obj, header );
1198 GDI_ReleaseObj( obj );
1203 /* Solid colors to enumerate */
1204 static const COLORREF solid_colors[] =
1205 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
1206 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
1207 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
1208 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
1209 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
1210 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
1211 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
1212 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
1216 /***********************************************************************
1217 * EnumObjects (GDI32.@)
1219 INT WINAPI EnumObjects( HDC hdc, INT nObjType,
1220 GOBJENUMPROC lpEnumFunc, LPARAM lParam )
1227 TRACE("%p %d %p %08lx\n", hdc, nObjType, lpEnumFunc, lParam );
1231 /* Enumerate solid pens */
1232 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1234 pen.lopnStyle = PS_SOLID;
1235 pen.lopnWidth.x = 1;
1236 pen.lopnWidth.y = 0;
1237 pen.lopnColor = solid_colors[i];
1238 retval = lpEnumFunc( &pen, lParam );
1239 TRACE("solid pen %08x, ret=%d\n",
1240 solid_colors[i], retval);
1246 /* Enumerate solid brushes */
1247 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1249 brush.lbStyle = BS_SOLID;
1250 brush.lbColor = solid_colors[i];
1252 retval = lpEnumFunc( &brush, lParam );
1253 TRACE("solid brush %08x, ret=%d\n",
1254 solid_colors[i], retval);
1258 /* Now enumerate hatched brushes */
1259 if (retval) for (i = HS_HORIZONTAL; i <= HS_DIAGCROSS; i++)
1261 brush.lbStyle = BS_HATCHED;
1262 brush.lbColor = RGB(0,0,0);
1264 retval = lpEnumFunc( &brush, lParam );
1265 TRACE("hatched brush %d, ret=%d\n",
1272 /* FIXME: implement Win32 types */
1273 WARN("(%d): Invalid type\n", nObjType );
1280 /***********************************************************************
1281 * IsGDIObject (GDI.462)
1283 * returns type of object if valid (W95 system programming secrets p. 264-5)
1285 BOOL16 WINAPI IsGDIObject16( HGDIOBJ16 handle16 )
1288 HGDIOBJ handle = HGDIOBJ_32( handle16 );
1290 GDIOBJHDR *object = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1293 magic = GDIMAGIC(object->wMagic) - FIRST_MAGIC + 1;
1294 GDI_ReleaseObj( handle );
1300 /***********************************************************************
1301 * SetObjectOwner (GDI32.@)
1303 void WINAPI SetObjectOwner( HGDIOBJ handle, HANDLE owner )
1309 /***********************************************************************
1310 * MakeObjectPrivate (GDI.463)
1312 * What does that mean ?
1313 * Some little docu can be found in "Undocumented Windows",
1314 * but this is basically useless.
1315 * At least we know that this flags the GDI object's wMagic
1316 * with 0x2000 (OBJECT_PRIVATE), so we just do it.
1317 * But Wine doesn't react on that yet.
1319 void WINAPI MakeObjectPrivate16( HGDIOBJ16 handle16, BOOL16 private )
1321 HGDIOBJ handle = HGDIOBJ_32( handle16 );
1322 GDIOBJHDR *ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1325 ERR("invalid GDI object %p !\n", handle);
1328 ptr->wMagic |= OBJECT_PRIVATE;
1329 GDI_ReleaseObj( handle );
1333 /***********************************************************************
1334 * GdiFlush (GDI32.@)
1336 BOOL WINAPI GdiFlush(void)
1338 return TRUE; /* FIXME */
1342 /***********************************************************************
1343 * GdiGetBatchLimit (GDI32.@)
1345 DWORD WINAPI GdiGetBatchLimit(void)
1347 return 1; /* FIXME */
1351 /***********************************************************************
1352 * GdiSetBatchLimit (GDI32.@)
1354 DWORD WINAPI GdiSetBatchLimit( DWORD limit )
1356 return 1; /* FIXME */
1360 /***********************************************************************
1361 * GdiSeeGdiDo (GDI.452)
1363 DWORD WINAPI GdiSeeGdiDo16( WORD wReqType, WORD wParam1, WORD wParam2,
1370 case 0x0001: /* LocalAlloc */
1371 WARN("LocalAlloc16(%x, %x): ignoring\n", wParam1, wParam3);
1374 case 0x0002: /* LocalFree */
1375 WARN("LocalFree16(%x): ignoring\n", wParam1);
1378 case 0x0003: /* LocalCompact */
1379 WARN("LocalCompact16(%x): ignoring\n", wParam3);
1380 ret = 65000; /* lie about the amount of free space */
1382 case 0x0103: /* LocalHeap */
1383 WARN("LocalHeap16(): ignoring\n");
1386 WARN("(wReqType=%04x): Unknown\n", wReqType);
1392 /***********************************************************************
1393 * GdiSignalProc32 (GDI.610)
1395 WORD WINAPI GdiSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
1396 DWORD dwFlags, HMODULE16 hModule )
1401 /***********************************************************************
1402 * GdiInit2 (GDI.403)
1404 * See "Undocumented Windows"
1408 * h2 [I] global data
1410 HANDLE16 WINAPI GdiInit216( HANDLE16 h1, HANDLE16 h2 )
1412 FIXME("(%04x, %04x), stub.\n", h1, h2);
1414 return 0xffff; /* undefined return value */
1415 return h1; /* FIXME: should be the memory handle of h1 */
1418 /***********************************************************************
1419 * FinalGdiInit (GDI.405)
1421 void WINAPI FinalGdiInit16( HBRUSH16 hPattern /* [in] fill pattern of desktop */ )
1425 /***********************************************************************
1426 * GdiFreeResources (GDI.609)
1428 WORD WINAPI GdiFreeResources16( DWORD reserve )
1430 return 90; /* lie about it, it shouldn't matter */
1434 /*******************************************************************
1435 * GetColorAdjustment [GDI32.@]
1439 BOOL WINAPI GetColorAdjustment(HDC hdc, LPCOLORADJUSTMENT lpca)
1441 FIXME("GetColorAdjustment, stub\n");
1445 /*******************************************************************
1446 * GdiComment [GDI32.@]
1450 BOOL WINAPI GdiComment(HDC hdc, UINT cbSize, const BYTE *lpData)
1452 DC *dc = DC_GetDCPtr(hdc);
1456 if (dc->funcs->pGdiComment)
1457 ret = dc->funcs->pGdiComment( dc->physDev, cbSize, lpData );
1459 GDI_ReleaseObj( hdc );
1463 /*******************************************************************
1464 * SetColorAdjustment [GDI32.@]
1468 BOOL WINAPI SetColorAdjustment(HDC hdc, const COLORADJUSTMENT* lpca)
1470 FIXME("SetColorAdjustment, stub\n");