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 "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
40 #define HGDIOBJ_32(h16) ((HGDIOBJ)(ULONG_PTR)(h16))
42 /***********************************************************************
46 static const LOGBRUSH WhiteBrush = { BS_SOLID, RGB(255,255,255), 0 };
47 static const LOGBRUSH BlackBrush = { BS_SOLID, RGB(0,0,0), 0 };
48 static const LOGBRUSH NullBrush = { BS_NULL, 0, 0 };
50 /* FIXME: these should perhaps be BS_HATCHED, at least for 1 bitperpixel */
51 static const LOGBRUSH LtGrayBrush = { BS_SOLID, RGB(192,192,192), 0 };
52 static const LOGBRUSH GrayBrush = { BS_SOLID, RGB(128,128,128), 0 };
54 /* This is BS_HATCHED, for 1 bitperpixel. This makes the spray work in pbrush */
55 /* See HatchBrushes in x11drv for the HS_DIAGCROSS+1 hack */
56 static const LOGBRUSH DkGrayBrush = { BS_HATCHED, RGB(0,0,0), (HS_DIAGCROSS+1) };
58 static const LOGPEN WhitePen = { PS_SOLID, { 0, 0 }, RGB(255,255,255) };
59 static const LOGPEN BlackPen = { PS_SOLID, { 0, 0 }, RGB(0,0,0) };
60 static const LOGPEN NullPen = { PS_NULL, { 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 = { CRITICAL_SECTION_INIT("GDI_level"), 3 };
70 static WORD GDI_HeapSel;
72 inline static BOOL get_bool(char *buffer)
74 return (buffer[0] == 'y' || buffer[0] == 'Y' ||
75 buffer[0] == 't' || buffer[0] == 'T' ||
80 /****************************************************************************
82 * language-independent stock fonts
86 static const LOGFONTW OEMFixedFont =
87 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, OEM_CHARSET,
88 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} };
90 static const LOGFONTW AnsiFixedFont =
91 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
92 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} };
94 static const LOGFONTW AnsiVarFont =
95 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
96 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
97 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'} };
99 /******************************************************************************
101 * language-dependent stock fonts
103 * 'ANSI' charset and 'DEFAULT' charset is not same.
104 * The chars in CP_ACP should be drawn with 'DEFAULT' charset.
105 * 'ANSI' charset seems to be identical with ISO-8859-1.
106 * 'DEFAULT' charset is a language-dependent charset.
108 * 'System' font seems to be an alias for language-dependent font.
112 * language-dependenet stock fonts for all known charsets
113 * please see TranslateCharsetInfo (objects/font.c) and
114 * CharsetBindingInfo (graphics/x11drv/xfont.c),
115 * and modify entries for your language if needed.
117 struct DefaultFontInfo
121 LOGFONTW DeviceDefaultFont;
122 LOGFONTW SystemFixedFont;
123 LOGFONTW DefaultGuiFont;
126 static const struct DefaultFontInfo default_fonts[] =
130 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
131 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
132 {'S','y','s','t','e','m','\0'}
134 { /* Device Default */
135 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
136 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
140 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
141 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
144 { /* DefaultGuiFont */
145 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
146 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
147 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
150 { EASTEUROPE_CHARSET,
152 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
153 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
154 {'S','y','s','t','e','m','\0'}
156 { /* Device Default */
157 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
158 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
162 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
163 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
166 { /* DefaultGuiFont */
167 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
168 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
169 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
174 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
175 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
176 {'S','y','s','t','e','m','\0'}
178 { /* Device Default */
179 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
180 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
184 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
185 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
188 { /* DefaultGuiFont */
189 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
190 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
191 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
196 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
197 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
198 {'S','y','s','t','e','m','\0'}
200 { /* Device Default */
201 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
202 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
206 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
207 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
210 { /* DefaultGuiFont */
211 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
212 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
213 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
218 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
219 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
220 {'S','y','s','t','e','m','\0'}
222 { /* Device Default */
223 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
224 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
228 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
229 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
232 { /* DefaultGuiFont */
233 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
234 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
235 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
240 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
241 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
242 {'S','y','s','t','e','m','\0'}
244 { /* Device Default */
245 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
246 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
250 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
251 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
254 { /* DefaultGuiFont */
255 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
256 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
257 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
262 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
263 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
264 {'S','y','s','t','e','m','\0'}
266 { /* Device Default */
267 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
268 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
272 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
273 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
276 { /* DefaultGuiFont */
277 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
278 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
279 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
284 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
285 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
286 {'S','y','s','t','e','m','\0'}
288 { /* Device Default */
289 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
290 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
294 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
295 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
298 { /* DefaultGuiFont */
299 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
300 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
301 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
306 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
307 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
308 {'S','y','s','t','e','m','\0'}
310 { /* Device Default */
311 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
312 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
316 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
317 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
320 { /* DefaultGuiFont */
321 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
322 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
323 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
328 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
329 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
330 {'S','y','s','t','e','m','\0'}
332 { /* Device Default */
333 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
334 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
338 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
339 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
342 { /* DefaultGuiFont */
343 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
344 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
345 {'M','S',' ','P',' ','g','o','t','h','i','c','\0'} /* FIXME: Is this correct? */
350 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
351 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
352 {'S','y','s','t','e','m','\0'}
354 { /* Device Default */
355 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
356 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
360 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
361 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
364 { /* DefaultGuiFont */
365 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
366 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
367 {'M','S',' ','S','o','n','g','\0'} /* FIXME: Is this correct? */
372 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
373 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
374 {'S','y','s','t','e','m','\0'}
376 { /* Device Default */
377 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
378 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
382 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
383 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
386 { /* DefaultGuiFont */
387 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
388 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
389 {'G','u','l','i','m'},
392 { CHINESEBIG5_CHARSET,
394 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
395 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
396 {'S','y','s','t','e','m','\0'}
398 { /* Device Default */
399 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
400 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
404 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
405 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
408 { /* DefaultGuiFont */
409 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
410 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
411 {'\0'} /* FIXME - what is the native font??? */
416 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
417 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
418 {'S','y','s','t','e','m','\0'}
420 { /* Device Default */
421 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
422 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
426 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
427 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
430 { /* DefaultGuiFont */
431 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
432 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
433 {'M','S',' ','M','i','n','g','l','i','u','\0'} /* FIXME: Is this correct? */
439 /******************************************************************************
442 static const struct DefaultFontInfo* get_default_fonts(UINT charset)
446 for(n=0;n<(sizeof(default_fonts)/sizeof(default_fonts[0]));n++)
448 if ( default_fonts[n].charset == charset )
449 return &default_fonts[n];
452 FIXME( "unhandled charset 0x%08x - use ANSI_CHARSET for default stock objects\n", charset );
453 return &default_fonts[0];
457 /******************************************************************************
458 * get_default_charset (internal)
460 * get the language-dependent charset that can handle CP_ACP correctly.
462 static UINT get_default_charset( void )
468 csi.ciCharset = ANSI_CHARSET;
469 if ( ! TranslateCharsetInfo( (LPDWORD)uACP, &csi, TCI_SRCCODEPAGE ) )
471 FIXME( "unhandled codepage %u - use ANSI_CHARSET for default stock objects\n", uACP );
475 return csi.ciCharset;
479 /******************************************************************************
482 static HFONT create_stock_font( char const *fontName, const LOGFONTW *font, HKEY hkey )
486 char buffer[MAX_PATH];
489 if (!hkey) return CreateFontIndirectW( font );
492 sprintf(key, "%s.Height", fontName);
493 count = sizeof(buffer);
494 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
495 lf.lfHeight = atoi(buffer);
497 sprintf(key, "%s.Bold", fontName);
498 count = sizeof(buffer);
499 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
500 lf.lfWeight = get_bool(buffer) ? FW_BOLD : FW_NORMAL;
502 sprintf(key, "%s.Italic", fontName);
503 count = sizeof(buffer);
504 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
505 lf.lfItalic = get_bool(buffer);
507 sprintf(key, "%s.Underline", fontName);
508 count = sizeof(buffer);
509 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
510 lf.lfUnderline = get_bool(buffer);
512 sprintf(key, "%s.StrikeOut", fontName);
513 count = sizeof(buffer);
514 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
515 lf.lfStrikeOut = get_bool(buffer);
516 return CreateFontIndirectW( &lf );
520 #define TRACE_SEC(handle,text) \
521 TRACE("(%p): " text " %ld\n", (handle), GDI_level.crst.RecursionCount)
524 /***********************************************************************
527 * Increment the reference count of a GDI object.
529 inline static void inc_ref_count( HGDIOBJ handle )
533 if ((header = GDI_GetObjPtr( handle, MAGIC_DONTCARE )))
536 GDI_ReleaseObj( handle );
541 /***********************************************************************
544 * Decrement the reference count of a GDI object.
546 inline static void dec_ref_count( HGDIOBJ handle )
550 if ((header = GDI_GetObjPtr( handle, MAGIC_DONTCARE )))
552 if (header->dwCount) header->dwCount--;
553 if (header->dwCount != 0x80000000) GDI_ReleaseObj( handle );
556 /* handle delayed DeleteObject*/
558 GDI_ReleaseObj( handle );
559 TRACE( "executing delayed DeleteObject for %p\n", handle );
560 DeleteObject( handle );
566 /***********************************************************************
569 * GDI initialization.
573 HINSTANCE16 instance;
576 const struct DefaultFontInfo* deffonts;
579 if (RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Tweak.Fonts", &hkey))
582 /* create GDI heap */
583 if ((instance = LoadLibrary16( "GDI.EXE" )) >= 32) GDI_HeapSel = instance | 7;
585 /* create stock objects */
586 stock_objects[WHITE_BRUSH] = CreateBrushIndirect( &WhiteBrush );
587 stock_objects[LTGRAY_BRUSH] = CreateBrushIndirect( &LtGrayBrush );
588 stock_objects[GRAY_BRUSH] = CreateBrushIndirect( &GrayBrush );
589 stock_objects[DKGRAY_BRUSH] = CreateBrushIndirect( &DkGrayBrush );
590 stock_objects[BLACK_BRUSH] = CreateBrushIndirect( &BlackBrush );
591 stock_objects[NULL_BRUSH] = CreateBrushIndirect( &NullBrush );
593 stock_objects[WHITE_PEN] = CreatePenIndirect( &WhitePen );
594 stock_objects[BLACK_PEN] = CreatePenIndirect( &BlackPen );
595 stock_objects[NULL_PEN] = CreatePenIndirect( &NullPen );
597 stock_objects[DEFAULT_PALETTE] = PALETTE_Init();
598 stock_objects[DEFAULT_BITMAP] = CreateBitmap( 1, 1, 1, 1, NULL );
600 /* language-independent stock fonts */
601 stock_objects[OEM_FIXED_FONT] = create_stock_font( "OEMFixed", &OEMFixedFont, hkey );
602 stock_objects[ANSI_FIXED_FONT] = create_stock_font( "AnsiFixed", &AnsiFixedFont, hkey );
603 stock_objects[ANSI_VAR_FONT] = create_stock_font( "AnsiVar", &AnsiVarFont, hkey );
605 /* language-dependent stock fonts */
606 deffonts = get_default_fonts(get_default_charset());
607 stock_objects[SYSTEM_FONT] = create_stock_font( "System", &deffonts->SystemFont, hkey );
608 stock_objects[DEVICE_DEFAULT_FONT] = create_stock_font( "DeviceDefault", &deffonts->DeviceDefaultFont, hkey );
609 stock_objects[SYSTEM_FIXED_FONT] = create_stock_font( "SystemFixed", &deffonts->SystemFixedFont, hkey );
610 stock_objects[DEFAULT_GUI_FONT] = create_stock_font( "DefaultGui", &deffonts->DefaultGuiFont, hkey );
613 /* clear the NOSYSTEM bit on all stock objects*/
614 for (i = 0; i < NB_STOCK_OBJECTS; i++)
616 if (!stock_objects[i])
618 if (i == 9) continue; /* there's no stock object 9 */
619 ERR( "could not create stock object %d\n", i );
622 ptr = GDI_GetObjPtr( stock_objects[i], MAGIC_DONTCARE );
623 ptr->wMagic &= ~OBJECT_NOSYSTEM;
624 GDI_ReleaseObj( stock_objects[i] );
627 if (hkey) RegCloseKey( hkey );
634 #define FIRST_LARGE_HANDLE 16
635 #define MAX_LARGE_HANDLES ((GDI_HEAP_SIZE >> 2) - FIRST_LARGE_HANDLE)
636 static GDIOBJHDR *large_handles[MAX_LARGE_HANDLES];
637 static int next_large_handle;
639 /***********************************************************************
642 * Allocate a GDI handle from the large heap. Helper for GDI_AllocObject
644 inline static GDIOBJHDR *alloc_large_heap( WORD size, HGDIOBJ *handle )
649 for (i = next_large_handle + 1; i < MAX_LARGE_HANDLES; i++)
650 if (!large_handles[i]) goto found;
651 for (i = 0; i <= next_large_handle; i++)
652 if (!large_handles[i]) goto found;
657 if ((obj = HeapAlloc( GetProcessHeap(), 0, size )))
659 large_handles[i] = obj;
660 *handle = (HGDIOBJ)(ULONG_PTR)((i + FIRST_LARGE_HANDLE) << 2);
661 next_large_handle = i;
667 /***********************************************************************
670 void *GDI_AllocObject( WORD size, WORD magic, HGDIOBJ *handle, const struct gdi_obj_funcs *funcs )
675 _EnterSysLevel( &GDI_level );
681 if (!(hlocal = LOCAL_Alloc( GDI_HeapSel, LMEM_MOVEABLE, size ))) goto error;
682 assert( hlocal & 2 );
683 obj = (GDIOBJHDR *)LOCAL_Lock( GDI_HeapSel, hlocal );
684 *handle = (HGDIOBJ)(ULONG_PTR)hlocal;
689 case DISABLED_DC_MAGIC:
692 case METAFILE_DC_MAGIC:
693 case ENHMETAFILE_MAGIC:
694 case ENHMETAFILE_DC_MAGIC:
697 if (!(obj = alloc_large_heap( size, handle ))) goto error;
702 obj->wMagic = magic|OBJECT_NOSYSTEM;
706 TRACE_SEC( *handle, "enter" );
710 _LeaveSysLevel( &GDI_level );
716 /***********************************************************************
719 * The object ptr must have been obtained with GDI_GetObjPtr.
720 * The new pointer must be released with GDI_ReleaseObj.
722 void *GDI_ReallocObject( WORD size, HGDIOBJ handle, void *object )
726 if ((UINT_PTR)handle & 2) /* GDI heap handle */
728 HLOCAL16 h = LOWORD(handle);
729 LOCAL_Unlock( GDI_HeapSel, h );
730 if ((new_handle = (HGDIOBJ)(ULONG_PTR)LOCAL_ReAlloc( GDI_HeapSel, h, size, LMEM_MOVEABLE )))
732 assert( new_handle == handle ); /* moveable handle cannot change */
733 return LOCAL_Lock( GDI_HeapSel, h );
738 int i = ((ULONG_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
739 if (i >= 0 && i < MAX_LARGE_HANDLES && large_handles[i])
741 void *new_ptr = HeapReAlloc( GetProcessHeap(), 0, large_handles[i], size );
744 large_handles[i] = new_ptr;
748 else ERR( "Invalid handle %p\n", handle );
750 TRACE_SEC( handle, "leave" );
751 _LeaveSysLevel( &GDI_level );
756 /***********************************************************************
759 BOOL GDI_FreeObject( HGDIOBJ handle, void *ptr )
761 GDIOBJHDR *object = ptr;
763 object->wMagic = 0; /* Mark it as invalid */
764 object->funcs = NULL;
765 if ((UINT_PTR)handle & 2) /* GDI heap handle */
767 HLOCAL16 h = LOWORD(handle);
768 LOCAL_Unlock( GDI_HeapSel, h );
769 LOCAL_Free( GDI_HeapSel, h );
771 else /* large heap handle */
773 int i = ((ULONG_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
774 if (i >= 0 && i < MAX_LARGE_HANDLES && large_handles[i])
776 HeapFree( GetProcessHeap(), 0, large_handles[i] );
777 large_handles[i] = NULL;
779 else ERR( "Invalid handle %p\n", handle );
781 TRACE_SEC( handle, "leave" );
782 _LeaveSysLevel( &GDI_level );
787 /***********************************************************************
790 * Return a pointer to the GDI object associated to the handle.
791 * Return NULL if the object has the wrong magic number.
792 * The object must be released with GDI_ReleaseObj.
794 void *GDI_GetObjPtr( HGDIOBJ handle, WORD magic )
796 GDIOBJHDR *ptr = NULL;
798 _EnterSysLevel( &GDI_level );
800 if ((UINT_PTR)handle & 2) /* GDI heap handle */
802 HLOCAL16 h = LOWORD(handle);
803 ptr = (GDIOBJHDR *)LOCAL_Lock( GDI_HeapSel, h );
806 if (((magic != MAGIC_DONTCARE) && (GDIMAGIC(ptr->wMagic) != magic)) ||
807 (GDIMAGIC(ptr->wMagic) < FIRST_MAGIC) ||
808 (GDIMAGIC(ptr->wMagic) > LAST_MAGIC))
810 LOCAL_Unlock( GDI_HeapSel, h );
815 else /* large heap handle */
817 int i = ((UINT_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
818 if (i >= 0 && i < MAX_LARGE_HANDLES)
820 ptr = large_handles[i];
821 if (ptr && (magic != MAGIC_DONTCARE) && (GDIMAGIC(ptr->wMagic) != magic)) ptr = NULL;
827 _LeaveSysLevel( &GDI_level );
828 SetLastError( ERROR_INVALID_HANDLE );
829 WARN( "Invalid handle %p\n", handle );
831 else TRACE_SEC( handle, "enter" );
837 /***********************************************************************
841 void GDI_ReleaseObj( HGDIOBJ handle )
843 if ((UINT_PTR)handle & 2) LOCAL_Unlock( GDI_HeapSel, LOWORD(handle) );
844 TRACE_SEC( handle, "leave" );
845 _LeaveSysLevel( &GDI_level );
849 /***********************************************************************
852 void GDI_CheckNotLock(void)
854 _CheckNotSysLevel( &GDI_level );
858 /***********************************************************************
859 * DeleteObject (GDI32.@)
861 BOOL WINAPI DeleteObject( HGDIOBJ obj )
863 /* Check if object is valid */
866 if (HIWORD(obj)) return FALSE;
868 if (!(header = GDI_GetObjPtr( obj, MAGIC_DONTCARE ))) return FALSE;
870 if (!(header->wMagic & OBJECT_NOSYSTEM)
871 && (header->wMagic >= FIRST_MAGIC) && (header->wMagic <= LAST_MAGIC))
873 TRACE("Preserving system object %p\n", obj);
874 GDI_ReleaseObj( obj );
880 TRACE("delayed for %p because object in use, count %ld\n", obj, header->dwCount );
881 header->dwCount |= 0x80000000; /* mark for delete */
882 GDI_ReleaseObj( obj );
890 if (header->funcs && header->funcs->pDeleteObject)
891 return header->funcs->pDeleteObject( obj, header );
893 GDI_ReleaseObj( obj );
898 /***********************************************************************
899 * GetStockObject (GDI32.@)
901 HGDIOBJ WINAPI GetStockObject( INT obj )
904 if ((obj < 0) || (obj >= NB_STOCK_OBJECTS)) return 0;
905 ret = stock_objects[obj];
906 TRACE("returning %p\n", ret );
911 /***********************************************************************
914 INT16 WINAPI GetObject16( HANDLE16 handle16, INT16 count, LPVOID buffer )
917 HGDIOBJ handle = HGDIOBJ_32( handle16 );
920 TRACE("%p %d %p\n", handle, count, buffer );
921 if (!count) return 0;
923 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
925 if (ptr->funcs && ptr->funcs->pGetObject16)
926 result = ptr->funcs->pGetObject16( handle, ptr, count, buffer );
928 SetLastError( ERROR_INVALID_HANDLE );
930 GDI_ReleaseObj( handle );
935 /***********************************************************************
936 * GetObjectA (GDI32.@)
938 INT WINAPI GetObjectA( HANDLE handle, INT count, LPVOID buffer )
942 TRACE("%p %d %p\n", handle, count, buffer );
943 if (!count) return 0;
945 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
947 if (ptr->funcs && ptr->funcs->pGetObjectA)
948 result = ptr->funcs->pGetObjectA( handle, ptr, count, buffer );
950 SetLastError( ERROR_INVALID_HANDLE );
952 GDI_ReleaseObj( handle );
956 /***********************************************************************
957 * GetObjectW (GDI32.@)
959 INT WINAPI GetObjectW( HANDLE handle, INT count, LPVOID buffer )
963 TRACE("%p %d %p\n", handle, count, buffer );
964 if (!count) return 0;
966 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
968 if (ptr->funcs && ptr->funcs->pGetObjectW)
969 result = ptr->funcs->pGetObjectW( handle, ptr, count, buffer );
971 SetLastError( ERROR_INVALID_HANDLE );
973 GDI_ReleaseObj( handle );
977 /***********************************************************************
978 * GetObjectType (GDI32.@)
980 DWORD WINAPI GetObjectType( HANDLE handle )
984 TRACE("%p\n", handle );
986 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
988 switch(GDIMAGIC(ptr->wMagic))
1006 result = OBJ_REGION;
1012 result = OBJ_METADC;
1014 case METAFILE_MAGIC:
1015 result = OBJ_METAFILE;
1017 case METAFILE_DC_MAGIC:
1018 result = OBJ_METADC;
1020 case ENHMETAFILE_MAGIC:
1021 result = OBJ_ENHMETAFILE;
1023 case ENHMETAFILE_DC_MAGIC:
1024 result = OBJ_ENHMETADC;
1027 FIXME("Magic %04x not implemented\n", GDIMAGIC(ptr->wMagic) );
1030 GDI_ReleaseObj( handle );
1034 /***********************************************************************
1035 * GetCurrentObject (GDI32.@)
1037 HANDLE WINAPI GetCurrentObject(HDC hdc,UINT type)
1040 DC * dc = DC_GetDCPtr( hdc );
1045 case OBJ_PEN: ret = dc->hPen; break;
1046 case OBJ_BRUSH: ret = dc->hBrush; break;
1047 case OBJ_PAL: ret = dc->hPalette; break;
1048 case OBJ_FONT: ret = dc->hFont; break;
1049 case OBJ_BITMAP: ret = dc->hBitmap; break;
1051 /* the SDK only mentions those above */
1052 FIXME("(%p,%d): unknown type.\n",hdc,type);
1055 GDI_ReleaseObj( hdc );
1061 /***********************************************************************
1062 * SelectObject (GDI32.@)
1064 HGDIOBJ WINAPI SelectObject( HDC hdc, HGDIOBJ handle )
1067 GDIOBJHDR *header = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1068 if (!header) return 0;
1070 TRACE("hdc=%p %p\n", hdc, handle );
1072 if (header->funcs && header->funcs->pSelectObject)
1074 ret = header->funcs->pSelectObject( handle, header, hdc );
1075 if (ret && ret != handle && (INT)ret > COMPLEXREGION)
1077 inc_ref_count( handle );
1078 dec_ref_count( ret );
1081 GDI_ReleaseObj( handle );
1086 /***********************************************************************
1087 * UnrealizeObject (GDI32.@)
1089 BOOL WINAPI UnrealizeObject( HGDIOBJ obj )
1092 /* Check if object is valid */
1094 GDIOBJHDR * header = GDI_GetObjPtr( obj, MAGIC_DONTCARE );
1095 if (!header) return FALSE;
1097 TRACE("%p\n", obj );
1099 /* Unrealize object */
1101 if (header->funcs && header->funcs->pUnrealizeObject)
1102 result = header->funcs->pUnrealizeObject( obj, header );
1104 GDI_ReleaseObj( obj );
1109 /* Solid colors to enumerate */
1110 static const COLORREF solid_colors[] =
1111 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
1112 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
1113 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
1114 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
1115 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
1116 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
1117 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
1118 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
1122 /***********************************************************************
1123 * EnumObjects (GDI32.@)
1125 INT WINAPI EnumObjects( HDC hdc, INT nObjType,
1126 GOBJENUMPROC lpEnumFunc, LPARAM lParam )
1132 TRACE("%p %d %p %08lx\n", hdc, nObjType, lpEnumFunc, lParam );
1136 /* Enumerate solid pens */
1137 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1139 pen.lopnStyle = PS_SOLID;
1140 pen.lopnWidth.x = 1;
1141 pen.lopnWidth.y = 0;
1142 pen.lopnColor = solid_colors[i];
1143 retval = lpEnumFunc( &pen, lParam );
1144 TRACE("solid pen %08lx, ret=%d\n",
1145 solid_colors[i], retval);
1151 /* Enumerate solid brushes */
1152 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1154 brush.lbStyle = BS_SOLID;
1155 brush.lbColor = solid_colors[i];
1157 retval = lpEnumFunc( &brush, lParam );
1158 TRACE("solid brush %08lx, ret=%d\n",
1159 solid_colors[i], retval);
1163 /* Now enumerate hatched brushes */
1164 if (retval) for (i = HS_HORIZONTAL; i <= HS_DIAGCROSS; i++)
1166 brush.lbStyle = BS_HATCHED;
1167 brush.lbColor = RGB(0,0,0);
1169 retval = lpEnumFunc( &brush, lParam );
1170 TRACE("hatched brush %d, ret=%d\n",
1177 /* FIXME: implement Win32 types */
1178 WARN("(%d): Invalid type\n", nObjType );
1185 /***********************************************************************
1186 * IsGDIObject (GDI.462)
1188 * returns type of object if valid (W95 system programming secrets p. 264-5)
1190 BOOL16 WINAPI IsGDIObject16( HGDIOBJ16 handle16 )
1193 HGDIOBJ handle = HGDIOBJ_32( handle16 );
1195 GDIOBJHDR *object = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1198 magic = GDIMAGIC(object->wMagic) - PEN_MAGIC + 1;
1199 GDI_ReleaseObj( handle );
1205 /***********************************************************************
1206 * SetObjectOwner (GDI32.@)
1208 void WINAPI SetObjectOwner( HGDIOBJ handle, HANDLE owner )
1214 /***********************************************************************
1215 * MakeObjectPrivate (GDI.463)
1217 * What does that mean ?
1218 * Some little docu can be found in "Undocumented Windows",
1219 * but this is basically useless.
1220 * At least we know that this flags the GDI object's wMagic
1221 * with 0x2000 (OBJECT_PRIVATE), so we just do it.
1222 * But Wine doesn't react on that yet.
1224 void WINAPI MakeObjectPrivate16( HGDIOBJ16 handle16, BOOL16 private )
1226 HGDIOBJ handle = HGDIOBJ_32( handle16 );
1227 GDIOBJHDR *ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1230 ERR("invalid GDI object %p !\n", handle);
1233 ptr->wMagic |= OBJECT_PRIVATE;
1234 GDI_ReleaseObj( handle );
1238 /***********************************************************************
1239 * GdiFlush (GDI32.@)
1241 BOOL WINAPI GdiFlush(void)
1243 return TRUE; /* FIXME */
1247 /***********************************************************************
1248 * GdiGetBatchLimit (GDI32.@)
1250 DWORD WINAPI GdiGetBatchLimit(void)
1252 return 1; /* FIXME */
1256 /***********************************************************************
1257 * GdiSetBatchLimit (GDI32.@)
1259 DWORD WINAPI GdiSetBatchLimit( DWORD limit )
1261 return 1; /* FIXME */
1265 /***********************************************************************
1266 * GdiSeeGdiDo (GDI.452)
1268 DWORD WINAPI GdiSeeGdiDo16( WORD wReqType, WORD wParam1, WORD wParam2,
1273 case 0x0001: /* LocalAlloc */
1274 return LOCAL_Alloc( GDI_HeapSel, wParam1, wParam3 );
1275 case 0x0002: /* LocalFree */
1276 return LOCAL_Free( GDI_HeapSel, wParam1 );
1277 case 0x0003: /* LocalCompact */
1278 return LOCAL_Compact( GDI_HeapSel, wParam3, 0 );
1279 case 0x0103: /* LocalHeap */
1282 WARN("(wReqType=%04x): Unknown\n", wReqType);
1287 /***********************************************************************
1288 * GdiSignalProc32 (GDI.610)
1290 WORD WINAPI GdiSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
1291 DWORD dwFlags, HMODULE16 hModule )
1296 /***********************************************************************
1297 * GdiInit2 (GDI.403)
1299 * See "Undocumented Windows"
1301 HANDLE16 WINAPI GdiInit216(
1302 HANDLE16 h1, /* [in] GDI object */
1303 HANDLE16 h2 /* [in] global data */
1306 FIXME("(%04x, %04x), stub.\n", h1, h2);
1308 return 0xffff; /* undefined return value */
1309 return h1; /* FIXME: should be the memory handle of h1 */
1312 /***********************************************************************
1313 * FinalGdiInit (GDI.405)
1315 void WINAPI FinalGdiInit16( HBRUSH16 hPattern /* [in] fill pattern of desktop */ )
1319 /***********************************************************************
1320 * GdiFreeResources (GDI.609)
1322 WORD WINAPI GdiFreeResources16( DWORD reserve )
1324 return (WORD)( (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
1325 (int)LOCAL_HeapSize( GDI_HeapSel ) );
1329 /*******************************************************************
1330 * GetColorAdjustment [GDI32.@]
1334 BOOL WINAPI GetColorAdjustment(HDC hdc, LPCOLORADJUSTMENT lpca)
1336 FIXME("GetColorAdjustment, stub\n");
1340 /*******************************************************************
1341 * GetMiterLimit [GDI32.@]
1345 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
1347 FIXME("GetMiterLimit, stub\n");
1351 /*******************************************************************
1352 * SetMiterLimit [GDI32.@]
1356 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
1358 FIXME("SetMiterLimit, stub\n");
1362 /*******************************************************************
1363 * GdiComment [GDI32.@]
1367 BOOL WINAPI GdiComment(HDC hdc, UINT cbSize, const BYTE *lpData)
1369 FIXME("GdiComment, stub\n");
1372 /*******************************************************************
1373 * SetColorAdjustment [GDI32.@]
1377 BOOL WINAPI SetColorAdjustment(HDC hdc, const COLORADJUSTMENT* lpca)
1379 FIXME("SetColorAdjustment, stub\n");