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
31 #include "wine/winbase16.h"
37 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
42 /* ### start build ### */
43 extern WORD CALLBACK GDI_CallTo16_word_ll(GOBJENUMPROC16,LONG,LONG);
44 /* ### stop build ### */
46 /***********************************************************************
50 static const LOGBRUSH WhiteBrush = { BS_SOLID, RGB(255,255,255), 0 };
51 static const LOGBRUSH BlackBrush = { BS_SOLID, RGB(0,0,0), 0 };
52 static const LOGBRUSH NullBrush = { BS_NULL, 0, 0 };
54 /* FIXME: these should perhaps be BS_HATCHED, at least for 1 bitperpixel */
55 static const LOGBRUSH LtGrayBrush = { BS_SOLID, RGB(192,192,192), 0 };
56 static const LOGBRUSH GrayBrush = { BS_SOLID, RGB(128,128,128), 0 };
58 /* This is BS_HATCHED, for 1 bitperpixel. This makes the spray work in pbrush */
59 /* See HatchBrushes in x11drv for the HS_DIAGCROSS+1 hack */
60 static const LOGBRUSH DkGrayBrush = { BS_HATCHED, RGB(0,0,0), (HS_DIAGCROSS+1) };
62 static const LOGPEN WhitePen = { PS_SOLID, { 0, 0 }, RGB(255,255,255) };
63 static const LOGPEN BlackPen = { PS_SOLID, { 0, 0 }, RGB(0,0,0) };
64 static const LOGPEN NullPen = { PS_NULL, { 0, 0 }, 0 };
67 /* reserve one extra entry for the stock default bitmap */
68 /* this is what Windows does too */
69 #define NB_STOCK_OBJECTS (STOCK_LAST+2)
71 static HGDIOBJ stock_objects[NB_STOCK_OBJECTS];
73 static SYSLEVEL GDI_level = { CRITICAL_SECTION_INIT("GDI_level"), 3 };
74 static WORD GDI_HeapSel;
76 inline static BOOL get_bool(char *buffer)
78 return (buffer[0] == 'y' || buffer[0] == 'Y' ||
79 buffer[0] == 't' || buffer[0] == 'T' ||
84 /****************************************************************************
86 * language-independent stock fonts
90 static const LOGFONTW OEMFixedFont =
91 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, OEM_CHARSET,
92 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} };
94 static const LOGFONTW AnsiFixedFont =
95 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
96 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} };
98 static const LOGFONTW AnsiVarFont =
99 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
100 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
101 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'} };
103 /******************************************************************************
105 * language-dependent stock fonts
107 * 'ANSI' charset and 'DEFAULT' charset is not same.
108 * The chars in CP_ACP should be drawn with 'DEFAULT' charset.
109 * 'ANSI' charset seems to be identical with ISO-8859-1.
110 * 'DEFAULT' charset is a language-dependent charset.
112 * 'System' font seems to be an alias for language-dependent font.
116 * language-dependenet stock fonts for all known charsets
117 * please see TranslateCharsetInfo (objects/font.c) and
118 * CharsetBindingInfo (graphics/x11drv/xfont.c),
119 * and modify entries for your language if needed.
121 struct DefaultFontInfo
125 LOGFONTW DeviceDefaultFont;
126 LOGFONTW SystemFixedFont;
127 LOGFONTW DefaultGuiFont;
130 static const struct DefaultFontInfo default_fonts[] =
134 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
135 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
136 {'S','y','s','t','e','m','\0'}
138 { /* Device Default */
139 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
140 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
144 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
145 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
148 { /* DefaultGuiFont */
149 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
150 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
151 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
154 { EASTEUROPE_CHARSET,
156 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
157 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
158 {'S','y','s','t','e','m','\0'}
160 { /* Device Default */
161 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
162 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
166 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
167 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
170 { /* DefaultGuiFont */
171 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
172 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
173 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
178 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
179 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
180 {'S','y','s','t','e','m','\0'}
182 { /* Device Default */
183 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
184 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
188 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
189 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
192 { /* DefaultGuiFont */
193 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
194 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
195 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
200 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
201 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
202 {'S','y','s','t','e','m','\0'}
204 { /* Device Default */
205 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
206 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
210 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
211 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
214 { /* DefaultGuiFont */
215 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
216 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
217 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
222 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
223 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
224 {'S','y','s','t','e','m','\0'}
226 { /* Device Default */
227 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
228 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
232 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
233 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
236 { /* DefaultGuiFont */
237 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
238 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
239 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
244 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
245 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
246 {'S','y','s','t','e','m','\0'}
248 { /* Device Default */
249 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
250 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
254 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
255 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
258 { /* DefaultGuiFont */
259 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
260 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
261 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
266 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
267 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
268 {'S','y','s','t','e','m','\0'}
270 { /* Device Default */
271 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
272 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
276 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
277 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
280 { /* DefaultGuiFont */
281 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
282 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
283 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
288 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
289 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
290 {'S','y','s','t','e','m','\0'}
292 { /* Device Default */
293 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
294 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
298 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
299 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
302 { /* DefaultGuiFont */
303 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
304 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
305 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
310 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
311 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
312 {'S','y','s','t','e','m','\0'}
314 { /* Device Default */
315 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
316 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
320 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
321 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
324 { /* DefaultGuiFont */
325 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
326 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
327 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
332 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
333 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
334 {'S','y','s','t','e','m','\0'}
336 { /* Device Default */
337 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
338 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
342 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
343 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
346 { /* DefaultGuiFont */
347 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
348 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
349 {'M','S',' ','P',' ','g','o','t','h','i','c','\0'} /* FIXME: Is this correct? */
354 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
355 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
356 {'S','y','s','t','e','m','\0'}
358 { /* Device Default */
359 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
360 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
364 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
365 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
368 { /* DefaultGuiFont */
369 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
370 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
371 {'M','S',' ','S','o','n','g','\0'} /* FIXME: Is this correct? */
376 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
377 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
378 {'S','y','s','t','e','m','\0'}
380 { /* Device Default */
381 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
382 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
386 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
387 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
390 { /* DefaultGuiFont */
391 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
392 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
393 {'G','u','l','i','m'},
396 { CHINESEBIG5_CHARSET,
398 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
399 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
400 {'S','y','s','t','e','m','\0'}
402 { /* Device Default */
403 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
404 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
408 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
409 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
412 { /* DefaultGuiFont */
413 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
414 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
415 {'\0'} /* FIXME - what is the native font??? */
420 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
421 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
422 {'S','y','s','t','e','m','\0'}
424 { /* Device Default */
425 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
426 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
430 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
431 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
434 { /* DefaultGuiFont */
435 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
436 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
437 {'M','S',' ','M','i','n','g','l','i','u','\0'} /* FIXME: Is this correct? */
443 /******************************************************************************
446 static const struct DefaultFontInfo* get_default_fonts(UINT charset)
450 for(n=0;n<(sizeof(default_fonts)/sizeof(default_fonts[0]));n++)
452 if ( default_fonts[n].charset == charset )
453 return &default_fonts[n];
456 FIXME( "unhandled charset 0x%08x - use ANSI_CHARSET for default stock objects\n", charset );
457 return &default_fonts[0];
461 /******************************************************************************
462 * get_default_charset (internal)
464 * get the language-dependent charset that can handle CP_ACP correctly.
466 static UINT get_default_charset( void )
472 csi.ciCharset = ANSI_CHARSET;
473 if ( ! TranslateCharsetInfo( (LPDWORD)uACP, &csi, TCI_SRCCODEPAGE ) )
475 FIXME( "unhandled codepage %u - use ANSI_CHARSET for default stock objects\n", uACP );
479 return csi.ciCharset;
483 /******************************************************************************
486 static HFONT create_stock_font( char const *fontName, const LOGFONTW *font, HKEY hkey )
490 char buffer[MAX_PATH];
493 if (!hkey) return CreateFontIndirectW( font );
496 sprintf(key, "%s.Height", fontName);
497 count = sizeof(buffer);
498 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
499 lf.lfHeight = atoi(buffer);
501 sprintf(key, "%s.Bold", fontName);
502 count = sizeof(buffer);
503 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
504 lf.lfWeight = get_bool(buffer) ? FW_BOLD : FW_NORMAL;
506 sprintf(key, "%s.Italic", fontName);
507 count = sizeof(buffer);
508 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
509 lf.lfItalic = get_bool(buffer);
511 sprintf(key, "%s.Underline", fontName);
512 count = sizeof(buffer);
513 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
514 lf.lfUnderline = get_bool(buffer);
516 sprintf(key, "%s.StrikeOut", fontName);
517 count = sizeof(buffer);
518 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
519 lf.lfStrikeOut = get_bool(buffer);
520 return CreateFontIndirectW( &lf );
524 #define TRACE_SEC(handle,text) \
525 TRACE("(%04x): " text " %ld\n", (handle), GDI_level.crst.RecursionCount)
528 /***********************************************************************
531 * Increment the reference count of a GDI object.
533 inline static void inc_ref_count( HGDIOBJ handle )
537 if ((header = GDI_GetObjPtr( handle, MAGIC_DONTCARE )))
540 GDI_ReleaseObj( handle );
545 /***********************************************************************
548 * Decrement the reference count of a GDI object.
550 inline static void dec_ref_count( HGDIOBJ handle )
554 if ((header = GDI_GetObjPtr( handle, MAGIC_DONTCARE )))
556 if (header->dwCount) header->dwCount--;
557 if (header->dwCount != 0x80000000) GDI_ReleaseObj( handle );
560 /* handle delayed DeleteObject*/
562 GDI_ReleaseObj( handle );
563 TRACE( "executing delayed DeleteObject for %04x\n", handle );
564 DeleteObject( handle );
570 /***********************************************************************
573 * GDI initialization.
577 HINSTANCE16 instance;
580 const struct DefaultFontInfo* deffonts;
583 if (RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Tweak.Fonts", &hkey))
586 /* create GDI heap */
587 if ((instance = LoadLibrary16( "GDI.EXE" )) >= 32) GDI_HeapSel = instance | 7;
589 /* create stock objects */
590 stock_objects[WHITE_BRUSH] = CreateBrushIndirect( &WhiteBrush );
591 stock_objects[LTGRAY_BRUSH] = CreateBrushIndirect( &LtGrayBrush );
592 stock_objects[GRAY_BRUSH] = CreateBrushIndirect( &GrayBrush );
593 stock_objects[DKGRAY_BRUSH] = CreateBrushIndirect( &DkGrayBrush );
594 stock_objects[BLACK_BRUSH] = CreateBrushIndirect( &BlackBrush );
595 stock_objects[NULL_BRUSH] = CreateBrushIndirect( &NullBrush );
597 stock_objects[WHITE_PEN] = CreatePenIndirect( &WhitePen );
598 stock_objects[BLACK_PEN] = CreatePenIndirect( &BlackPen );
599 stock_objects[NULL_PEN] = CreatePenIndirect( &NullPen );
601 stock_objects[DEFAULT_PALETTE] = PALETTE_Init();
602 stock_objects[DEFAULT_BITMAP] = CreateBitmap( 1, 1, 1, 1, NULL );
604 /* language-independent stock fonts */
605 stock_objects[OEM_FIXED_FONT] = create_stock_font( "OEMFixed", &OEMFixedFont, hkey );
606 stock_objects[ANSI_FIXED_FONT] = create_stock_font( "AnsiFixed", &AnsiFixedFont, hkey );
607 stock_objects[ANSI_VAR_FONT] = create_stock_font( "AnsiVar", &AnsiVarFont, hkey );
609 /* language-dependent stock fonts */
610 deffonts = get_default_fonts(get_default_charset());
611 stock_objects[SYSTEM_FONT] = create_stock_font( "System", &deffonts->SystemFont, hkey );
612 stock_objects[DEVICE_DEFAULT_FONT] = create_stock_font( "DeviceDefault", &deffonts->DeviceDefaultFont, hkey );
613 stock_objects[SYSTEM_FIXED_FONT] = create_stock_font( "SystemFixed", &deffonts->SystemFixedFont, hkey );
614 stock_objects[DEFAULT_GUI_FONT] = create_stock_font( "DefaultGui", &deffonts->DefaultGuiFont, hkey );
617 /* clear the NOSYSTEM bit on all stock objects*/
618 for (i = 0; i < NB_STOCK_OBJECTS; i++)
620 if (!stock_objects[i])
622 if (i == 9) continue; /* there's no stock object 9 */
623 ERR( "could not create stock object %d\n", i );
626 ptr = GDI_GetObjPtr( stock_objects[i], MAGIC_DONTCARE );
627 ptr->wMagic &= ~OBJECT_NOSYSTEM;
628 GDI_ReleaseObj( stock_objects[i] );
631 if (hkey) RegCloseKey( hkey );
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 )
679 _EnterSysLevel( &GDI_level );
685 if (!(hlocal = LOCAL_Alloc( GDI_HeapSel, LMEM_MOVEABLE, size ))) goto error;
686 assert( hlocal & 2 );
687 obj = (GDIOBJHDR *)LOCAL_Lock( GDI_HeapSel, hlocal );
688 *handle = (HGDIOBJ)(ULONG_PTR)hlocal;
693 case DISABLED_DC_MAGIC:
696 case METAFILE_DC_MAGIC:
697 case ENHMETAFILE_MAGIC:
698 case ENHMETAFILE_DC_MAGIC:
700 if (!(obj = alloc_large_heap( size, handle ))) goto error;
705 obj->wMagic = magic|OBJECT_NOSYSTEM;
709 TRACE_SEC( *handle, "enter" );
713 _LeaveSysLevel( &GDI_level );
719 /***********************************************************************
722 * The object ptr must have been obtained with GDI_GetObjPtr.
723 * The new pointer must be released with GDI_ReleaseObj.
725 void *GDI_ReallocObject( WORD size, HGDIOBJ handle, void *object )
729 if (handle & 2) /* GDI heap handle */
731 LOCAL_Unlock( GDI_HeapSel, handle );
732 if ((new_handle = LOCAL_ReAlloc( GDI_HeapSel, handle, size, LMEM_MOVEABLE )))
734 assert( new_handle == handle ); /* moveable handle cannot change */
735 return LOCAL_Lock( GDI_HeapSel, handle );
740 int i = ((ULONG_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
741 if (i >= 0 && i < MAX_LARGE_HANDLES && large_handles[i])
743 void *new_ptr = HeapReAlloc( GetProcessHeap(), 0, large_handles[i], size );
746 large_handles[i] = new_ptr;
750 else ERR( "Invalid handle %x\n", handle );
752 TRACE_SEC( handle, "leave" );
753 _LeaveSysLevel( &GDI_level );
758 /***********************************************************************
761 BOOL GDI_FreeObject( HGDIOBJ handle, void *ptr )
763 GDIOBJHDR *object = ptr;
765 object->wMagic = 0; /* Mark it as invalid */
766 object->funcs = NULL;
767 if (handle & 2) /* GDI heap handle */
769 LOCAL_Unlock( GDI_HeapSel, handle );
770 LOCAL_Free( GDI_HeapSel, handle );
772 else /* large heap handle */
774 int i = ((ULONG_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
775 if (i >= 0 && i < MAX_LARGE_HANDLES && large_handles[i])
777 HeapFree( GetProcessHeap(), 0, large_handles[i] );
778 large_handles[i] = NULL;
780 else ERR( "Invalid handle %x\n", handle );
782 TRACE_SEC( handle, "leave" );
783 _LeaveSysLevel( &GDI_level );
788 /***********************************************************************
791 * Return a pointer to the GDI object associated to the handle.
792 * Return NULL if the object has the wrong magic number.
793 * The object must be released with GDI_ReleaseObj.
795 void *GDI_GetObjPtr( HGDIOBJ handle, WORD magic )
797 GDIOBJHDR *ptr = NULL;
799 _EnterSysLevel( &GDI_level );
801 if (handle & 2) /* GDI heap handle */
803 ptr = (GDIOBJHDR *)LOCAL_Lock( GDI_HeapSel, handle );
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, handle );
815 else /* large heap handle */
817 int i = (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 %x\n", handle );
831 else TRACE_SEC( handle, "enter" );
837 /***********************************************************************
841 void GDI_ReleaseObj( HGDIOBJ handle )
843 if (handle & 2) LOCAL_Unlock( GDI_HeapSel, 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 %04x\n", obj);
874 GDI_ReleaseObj( obj );
880 TRACE("delayed for %04x because object in use, count %ld\n", obj, header->dwCount );
881 header->dwCount |= 0x80000000; /* mark for delete */
882 GDI_ReleaseObj( obj );
886 TRACE("%04x\n", 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 %4x\n", ret );
911 /***********************************************************************
914 INT16 WINAPI GetObject16( HANDLE16 handle, INT16 count, LPVOID buffer )
918 TRACE("%04x %d %p\n", handle, count, buffer );
919 if (!count) return 0;
921 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
923 if (ptr->funcs && ptr->funcs->pGetObject16)
924 result = ptr->funcs->pGetObject16( handle, ptr, count, buffer );
926 SetLastError( ERROR_INVALID_HANDLE );
928 GDI_ReleaseObj( handle );
933 /***********************************************************************
934 * GetObjectA (GDI32.@)
936 INT WINAPI GetObjectA( HANDLE handle, INT count, LPVOID buffer )
940 TRACE("%08x %d %p\n", handle, count, buffer );
941 if (!count) return 0;
943 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
945 if (ptr->funcs && ptr->funcs->pGetObjectA)
946 result = ptr->funcs->pGetObjectA( handle, ptr, count, buffer );
948 SetLastError( ERROR_INVALID_HANDLE );
950 GDI_ReleaseObj( handle );
954 /***********************************************************************
955 * GetObjectW (GDI32.@)
957 INT WINAPI GetObjectW( HANDLE handle, INT count, LPVOID buffer )
961 TRACE("%08x %d %p\n", handle, count, buffer );
962 if (!count) return 0;
964 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
966 if (ptr->funcs && ptr->funcs->pGetObjectW)
967 result = ptr->funcs->pGetObjectW( handle, ptr, count, buffer );
969 SetLastError( ERROR_INVALID_HANDLE );
971 GDI_ReleaseObj( handle );
975 /***********************************************************************
976 * GetObjectType (GDI32.@)
978 DWORD WINAPI GetObjectType( HANDLE handle )
982 TRACE("%08x\n", handle );
984 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
986 switch(GDIMAGIC(ptr->wMagic))
1004 result = OBJ_REGION;
1010 result = OBJ_METADC;
1012 case METAFILE_MAGIC:
1013 result = OBJ_METAFILE;
1015 case METAFILE_DC_MAGIC:
1016 result = OBJ_METADC;
1018 case ENHMETAFILE_MAGIC:
1019 result = OBJ_ENHMETAFILE;
1021 case ENHMETAFILE_DC_MAGIC:
1022 result = OBJ_ENHMETADC;
1025 FIXME("Magic %04x not implemented\n", GDIMAGIC(ptr->wMagic) );
1028 GDI_ReleaseObj( handle );
1032 /***********************************************************************
1033 * GetCurrentObject (GDI32.@)
1035 HANDLE WINAPI GetCurrentObject(HDC hdc,UINT type)
1038 DC * dc = DC_GetDCPtr( hdc );
1043 case OBJ_PEN: ret = dc->hPen; break;
1044 case OBJ_BRUSH: ret = dc->hBrush; break;
1045 case OBJ_PAL: ret = dc->hPalette; break;
1046 case OBJ_FONT: ret = dc->hFont; break;
1047 case OBJ_BITMAP: ret = dc->hBitmap; break;
1049 /* the SDK only mentions those above */
1050 FIXME("(%08x,%d): unknown type.\n",hdc,type);
1053 GDI_ReleaseObj( hdc );
1059 /***********************************************************************
1060 * SelectObject (GDI32.@)
1062 HGDIOBJ WINAPI SelectObject( HDC hdc, HGDIOBJ handle )
1065 GDIOBJHDR *header = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1066 if (!header) return 0;
1068 TRACE("hdc=%04x %04x\n", hdc, handle );
1070 if (header->funcs && header->funcs->pSelectObject)
1072 ret = header->funcs->pSelectObject( handle, header, hdc );
1073 if (ret && ret != handle && (INT)ret > COMPLEXREGION)
1075 inc_ref_count( handle );
1076 dec_ref_count( ret );
1079 GDI_ReleaseObj( handle );
1084 /***********************************************************************
1085 * UnrealizeObject (GDI32.@)
1087 BOOL WINAPI UnrealizeObject( HGDIOBJ obj )
1090 /* Check if object is valid */
1092 GDIOBJHDR * header = GDI_GetObjPtr( obj, MAGIC_DONTCARE );
1093 if (!header) return FALSE;
1095 TRACE("%04x\n", obj );
1097 /* Unrealize object */
1099 if (header->funcs && header->funcs->pUnrealizeObject)
1100 result = header->funcs->pUnrealizeObject( obj, header );
1102 GDI_ReleaseObj( obj );
1107 /* Solid colors to enumerate */
1108 static const COLORREF solid_colors[] =
1109 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
1110 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
1111 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
1112 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
1113 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
1114 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
1115 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
1116 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
1119 /***********************************************************************
1120 * EnumObjects (GDI.71)
1122 INT16 WINAPI EnumObjects16( HDC16 hdc, INT16 nObjType,
1123 GOBJENUMPROC16 lpEnumFunc, LPARAM lParam )
1125 INT16 i, retval = 0;
1130 TRACE("%04x %d %08lx %08lx\n",
1131 hdc, nObjType, (DWORD)lpEnumFunc, lParam );
1135 /* Enumerate solid pens */
1136 segptr = MapLS( &pen );
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 = GDI_CallTo16_word_ll( lpEnumFunc, segptr, lParam );
1144 TRACE("solid pen %08lx, ret=%d\n", solid_colors[i], retval);
1151 /* Enumerate solid brushes */
1152 segptr = MapLS( &brush );
1153 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1155 brush.lbStyle = BS_SOLID;
1156 brush.lbColor = solid_colors[i];
1158 retval = GDI_CallTo16_word_ll( lpEnumFunc, segptr, lParam );
1159 TRACE("solid brush %08lx, ret=%d\n", 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 = GDI_CallTo16_word_ll( lpEnumFunc, segptr, lParam );
1170 TRACE("hatched brush %d, ret=%d\n", i, retval);
1177 WARN("(%d): Invalid type\n", nObjType );
1184 /***********************************************************************
1185 * EnumObjects (GDI32.@)
1187 INT WINAPI EnumObjects( HDC hdc, INT nObjType,
1188 GOBJENUMPROC lpEnumFunc, LPARAM lParam )
1194 TRACE("%04x %d %08lx %08lx\n",
1195 hdc, nObjType, (DWORD)lpEnumFunc, lParam );
1199 /* Enumerate solid pens */
1200 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1202 pen.lopnStyle = PS_SOLID;
1203 pen.lopnWidth.x = 1;
1204 pen.lopnWidth.y = 0;
1205 pen.lopnColor = solid_colors[i];
1206 retval = lpEnumFunc( &pen, lParam );
1207 TRACE("solid pen %08lx, ret=%d\n",
1208 solid_colors[i], retval);
1214 /* Enumerate solid brushes */
1215 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1217 brush.lbStyle = BS_SOLID;
1218 brush.lbColor = solid_colors[i];
1220 retval = lpEnumFunc( &brush, lParam );
1221 TRACE("solid brush %08lx, ret=%d\n",
1222 solid_colors[i], retval);
1226 /* Now enumerate hatched brushes */
1227 if (retval) for (i = HS_HORIZONTAL; i <= HS_DIAGCROSS; i++)
1229 brush.lbStyle = BS_HATCHED;
1230 brush.lbColor = RGB(0,0,0);
1232 retval = lpEnumFunc( &brush, lParam );
1233 TRACE("hatched brush %d, ret=%d\n",
1240 /* FIXME: implement Win32 types */
1241 WARN("(%d): Invalid type\n", nObjType );
1248 /***********************************************************************
1249 * IsGDIObject (GDI.462)
1251 * returns type of object if valid (W95 system programming secrets p. 264-5)
1253 BOOL16 WINAPI IsGDIObject16( HGDIOBJ16 handle )
1257 GDIOBJHDR *object = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1260 magic = GDIMAGIC(object->wMagic) - PEN_MAGIC + 1;
1261 GDI_ReleaseObj( handle );
1267 /***********************************************************************
1268 * SetObjectOwner (GDI32.@)
1270 void WINAPI SetObjectOwner( HGDIOBJ handle, HANDLE owner )
1276 /***********************************************************************
1277 * MakeObjectPrivate (GDI.463)
1279 * What does that mean ?
1280 * Some little docu can be found in "Undocumented Windows",
1281 * but this is basically useless.
1282 * At least we know that this flags the GDI object's wMagic
1283 * with 0x2000 (OBJECT_PRIVATE), so we just do it.
1284 * But Wine doesn't react on that yet.
1286 void WINAPI MakeObjectPrivate16( HGDIOBJ16 handle, BOOL16 private )
1288 GDIOBJHDR *ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1291 ERR("invalid GDI object %04x !\n", handle);
1294 ptr->wMagic |= OBJECT_PRIVATE;
1295 GDI_ReleaseObj( handle );
1299 /***********************************************************************
1300 * GdiFlush (GDI32.@)
1302 BOOL WINAPI GdiFlush(void)
1304 return TRUE; /* FIXME */
1308 /***********************************************************************
1309 * GdiGetBatchLimit (GDI32.@)
1311 DWORD WINAPI GdiGetBatchLimit(void)
1313 return 1; /* FIXME */
1317 /***********************************************************************
1318 * GdiSetBatchLimit (GDI32.@)
1320 DWORD WINAPI GdiSetBatchLimit( DWORD limit )
1322 return 1; /* FIXME */
1326 /***********************************************************************
1327 * GdiSeeGdiDo (GDI.452)
1329 DWORD WINAPI GdiSeeGdiDo16( WORD wReqType, WORD wParam1, WORD wParam2,
1334 case 0x0001: /* LocalAlloc */
1335 return LOCAL_Alloc( GDI_HeapSel, wParam1, wParam3 );
1336 case 0x0002: /* LocalFree */
1337 return LOCAL_Free( GDI_HeapSel, wParam1 );
1338 case 0x0003: /* LocalCompact */
1339 return LOCAL_Compact( GDI_HeapSel, wParam3, 0 );
1340 case 0x0103: /* LocalHeap */
1343 WARN("(wReqType=%04x): Unknown\n", wReqType);
1348 /***********************************************************************
1349 * GdiSignalProc32 (GDI.610)
1351 WORD WINAPI GdiSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
1352 DWORD dwFlags, HMODULE16 hModule )
1357 /***********************************************************************
1358 * GdiInit2 (GDI.403)
1360 * See "Undocumented Windows"
1362 HANDLE16 WINAPI GdiInit216(
1363 HANDLE16 h1, /* [in] GDI object */
1364 HANDLE16 h2 /* [in] global data */
1367 FIXME("(%04x, %04x), stub.\n", h1, h2);
1369 return 0xffff; /* undefined return value */
1370 return h1; /* FIXME: should be the memory handle of h1 */
1373 /***********************************************************************
1374 * FinalGdiInit (GDI.405)
1376 void WINAPI FinalGdiInit16( HBRUSH16 hPattern /* [in] fill pattern of desktop */ )
1380 /***********************************************************************
1381 * GdiFreeResources (GDI.609)
1383 WORD WINAPI GdiFreeResources16( DWORD reserve )
1385 return (WORD)( (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
1386 (int)LOCAL_HeapSize( GDI_HeapSel ) );
1390 /*******************************************************************
1391 * GetColorAdjustment [GDI32.@]
1395 BOOL WINAPI GetColorAdjustment(HDC hdc, LPCOLORADJUSTMENT lpca)
1397 FIXME("GetColorAdjustment, stub\n");
1401 /*******************************************************************
1402 * GetMiterLimit [GDI32.@]
1406 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
1408 FIXME("GetMiterLimit, stub\n");
1412 /*******************************************************************
1413 * SetMiterLimit [GDI32.@]
1417 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
1419 FIXME("SetMiterLimit, stub\n");
1423 /*******************************************************************
1424 * GdiComment [GDI32.@]
1428 BOOL WINAPI GdiComment(HDC hdc, UINT cbSize, const BYTE *lpData)
1430 FIXME("GdiComment, stub\n");
1433 /*******************************************************************
1434 * SetColorAdjustment [GDI32.@]
1438 BOOL WINAPI SetColorAdjustment(HDC hdc, const COLORADJUSTMENT* lpca)
1440 FIXME("SetColorAdjustment, stub\n");