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
36 #include "gdi_private.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(gdi
);
41 #define HGDIOBJ_32(h16) ((HGDIOBJ)(ULONG_PTR)(h16))
43 #define GDI_HEAP_SIZE 0xffe0
45 /***********************************************************************
49 static const LOGBRUSH WhiteBrush
= { BS_SOLID
, RGB(255,255,255), 0 };
50 static const LOGBRUSH BlackBrush
= { BS_SOLID
, RGB(0,0,0), 0 };
51 static const LOGBRUSH NullBrush
= { BS_NULL
, 0, 0 };
53 static const LOGBRUSH LtGrayBrush
= { BS_SOLID
, RGB(192,192,192), 0 };
54 static const LOGBRUSH GrayBrush
= { BS_SOLID
, RGB(128,128,128), 0 };
55 static const LOGBRUSH DkGrayBrush
= { BS_SOLID
, RGB(64,64,64), 0 };
57 static const LOGPEN WhitePen
= { PS_SOLID
, { 0, 0 }, RGB(255,255,255) };
58 static const LOGPEN BlackPen
= { PS_SOLID
, { 0, 0 }, RGB(0,0,0) };
59 static const LOGPEN NullPen
= { PS_NULL
, { 0, 0 }, 0 };
61 static const LOGBRUSH DCBrush
= { BS_SOLID
, RGB(255,255,255), 0 };
62 static const LOGPEN DCPen
= { PS_SOLID
, { 0, 0 }, RGB(0,0,0) };
64 /* reserve one extra entry for the stock default bitmap */
65 /* this is what Windows does too */
66 #define NB_STOCK_OBJECTS (STOCK_LAST+2)
68 static HGDIOBJ stock_objects
[NB_STOCK_OBJECTS
];
70 static CRITICAL_SECTION gdi_section
;
71 static CRITICAL_SECTION_DEBUG critsect_debug
=
74 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
75 0, 0, { (DWORD_PTR
)(__FILE__
": gdi_section") }
77 static CRITICAL_SECTION gdi_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
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
,
93 {'C','o','u','r','i','e','r','\0'} };
95 static const LOGFONTW AnsiVarFont
=
96 { 12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
97 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
98 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'} };
100 /******************************************************************************
102 * language-dependent stock fonts
104 * 'ANSI' charset and 'DEFAULT' charset is not same.
105 * The chars in CP_ACP should be drawn with 'DEFAULT' charset.
106 * 'ANSI' charset seems to be identical with ISO-8859-1.
107 * 'DEFAULT' charset is a language-dependent charset.
109 * 'System' font seems to be an alias for language-dependent font.
113 * language-dependent stock fonts for all known charsets
114 * please see TranslateCharsetInfo (dlls/gdi/font.c) and
115 * CharsetBindingInfo (dlls/x11drv/xfont.c),
116 * and modify entries for your language if needed.
118 struct DefaultFontInfo
122 LOGFONTW DeviceDefaultFont
;
123 LOGFONTW SystemFixedFont
;
124 LOGFONTW DefaultGuiFont
; /* Note for this font the lfHeight member should be the point size */
127 static const struct DefaultFontInfo default_fonts
[] =
131 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
132 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
133 {'S','y','s','t','e','m','\0'}
135 { /* Device Default */
136 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
137 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
141 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
142 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
145 { /* DefaultGuiFont */
146 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
147 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
148 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
151 { EASTEUROPE_CHARSET
,
153 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, EASTEUROPE_CHARSET
,
154 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
155 {'S','y','s','t','e','m','\0'}
157 { /* Device Default */
158 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, EASTEUROPE_CHARSET
,
159 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
163 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, EASTEUROPE_CHARSET
,
164 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
167 { /* DefaultGuiFont */
168 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, EASTEUROPE_CHARSET
,
169 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
170 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
175 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, RUSSIAN_CHARSET
,
176 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
177 {'S','y','s','t','e','m','\0'}
179 { /* Device Default */
180 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, RUSSIAN_CHARSET
,
181 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
185 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, RUSSIAN_CHARSET
,
186 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
189 { /* DefaultGuiFont */
190 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, RUSSIAN_CHARSET
,
191 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
192 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
197 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GREEK_CHARSET
,
198 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
199 {'S','y','s','t','e','m','\0'}
201 { /* Device Default */
202 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GREEK_CHARSET
,
203 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
207 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GREEK_CHARSET
,
208 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
211 { /* DefaultGuiFont */
212 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GREEK_CHARSET
,
213 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
214 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
219 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, TURKISH_CHARSET
,
220 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
221 {'S','y','s','t','e','m','\0'}
223 { /* Device Default */
224 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, TURKISH_CHARSET
,
225 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
229 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, TURKISH_CHARSET
,
230 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
233 { /* DefaultGuiFont */
234 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, TURKISH_CHARSET
,
235 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
236 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
241 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HEBREW_CHARSET
,
242 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
243 {'S','y','s','t','e','m','\0'}
245 { /* Device Default */
246 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HEBREW_CHARSET
,
247 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
251 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HEBREW_CHARSET
,
252 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
255 { /* DefaultGuiFont */
256 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HEBREW_CHARSET
,
257 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
258 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
263 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ARABIC_CHARSET
,
264 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
265 {'S','y','s','t','e','m','\0'}
267 { /* Device Default */
268 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ARABIC_CHARSET
,
269 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
273 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ARABIC_CHARSET
,
274 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
277 { /* DefaultGuiFont */
278 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ARABIC_CHARSET
,
279 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
280 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
285 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, BALTIC_CHARSET
,
286 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
287 {'S','y','s','t','e','m','\0'}
289 { /* Device Default */
290 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, BALTIC_CHARSET
,
291 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
295 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, BALTIC_CHARSET
,
296 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
299 { /* DefaultGuiFont */
300 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, BALTIC_CHARSET
,
301 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
302 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
307 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, THAI_CHARSET
,
308 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
309 {'S','y','s','t','e','m','\0'}
311 { /* Device Default */
312 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, THAI_CHARSET
,
313 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
317 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, THAI_CHARSET
,
318 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
321 { /* DefaultGuiFont */
322 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, THAI_CHARSET
,
323 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
324 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
329 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, SHIFTJIS_CHARSET
,
330 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
331 {'S','y','s','t','e','m','\0'}
333 { /* Device Default */
334 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, SHIFTJIS_CHARSET
,
335 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
339 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, SHIFTJIS_CHARSET
,
340 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
343 { /* DefaultGuiFont */
344 9, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, SHIFTJIS_CHARSET
,
345 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
346 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
351 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GB2312_CHARSET
,
352 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
353 {'S','y','s','t','e','m','\0'}
355 { /* Device Default */
356 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GB2312_CHARSET
,
357 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
361 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GB2312_CHARSET
,
362 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
365 { /* DefaultGuiFont */
366 9, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GB2312_CHARSET
,
367 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
368 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
373 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HANGEUL_CHARSET
,
374 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
375 {'S','y','s','t','e','m','\0'}
377 { /* Device Default */
378 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HANGEUL_CHARSET
,
379 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
383 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HANGEUL_CHARSET
,
384 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
387 { /* DefaultGuiFont */
388 9, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HANGEUL_CHARSET
,
389 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
390 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
393 { CHINESEBIG5_CHARSET
,
395 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, CHINESEBIG5_CHARSET
,
396 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
397 {'S','y','s','t','e','m','\0'}
399 { /* Device Default */
400 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, CHINESEBIG5_CHARSET
,
401 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
405 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, CHINESEBIG5_CHARSET
,
406 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
409 { /* DefaultGuiFont */
410 9, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, CHINESEBIG5_CHARSET
,
411 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
412 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
417 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, JOHAB_CHARSET
,
418 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
419 {'S','y','s','t','e','m','\0'}
421 { /* Device Default */
422 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, JOHAB_CHARSET
,
423 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
427 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, JOHAB_CHARSET
,
428 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
431 { /* DefaultGuiFont */
432 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, JOHAB_CHARSET
,
433 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
434 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
440 /*************************************************************************
441 * __wine_make_gdi_object_system (GDI32.@)
443 * USER has to tell GDI that its system brushes and pens are non-deletable.
444 * For a description of the GDI object magics and their flags,
445 * see "Undocumented Windows" (wrong about the OBJECT_NOSYSTEM flag, though).
447 void CDECL
__wine_make_gdi_object_system( HGDIOBJ handle
, BOOL set
)
449 GDIOBJHDR
*ptr
= GDI_GetObjPtr( handle
, 0 );
451 GDI_ReleaseObj( handle
);
454 /******************************************************************************
457 static const struct DefaultFontInfo
* get_default_fonts(UINT charset
)
461 for(n
=0;n
<(sizeof(default_fonts
)/sizeof(default_fonts
[0]));n
++)
463 if ( default_fonts
[n
].charset
== charset
)
464 return &default_fonts
[n
];
467 FIXME( "unhandled charset 0x%08x - use ANSI_CHARSET for default stock objects\n", charset
);
468 return &default_fonts
[0];
472 /******************************************************************************
473 * get_default_charset (internal)
475 * get the language-dependent charset that can handle CP_ACP correctly.
477 static UINT
get_default_charset( void )
483 csi
.ciCharset
= ANSI_CHARSET
;
484 if ( !TranslateCharsetInfo( ULongToPtr(uACP
), &csi
, TCI_SRCCODEPAGE
) )
486 FIXME( "unhandled codepage %u - use ANSI_CHARSET for default stock objects\n", uACP
);
490 return csi
.ciCharset
;
493 static const WCHAR dpi_key_name
[] = {'S','o','f','t','w','a','r','e','\\','F','o','n','t','s','\0'};
494 static const WCHAR dpi_value_name
[] = {'L','o','g','P','i','x','e','l','s','\0'};
496 /******************************************************************************
499 * get the dpi from the registry
501 static DWORD
get_dpi( void )
506 if (RegOpenKeyW(HKEY_CURRENT_CONFIG
, dpi_key_name
, &hkey
) == ERROR_SUCCESS
)
508 DWORD type
, size
, new_dpi
;
510 size
= sizeof(new_dpi
);
511 if(RegQueryValueExW(hkey
, dpi_value_name
, NULL
, &type
, (void *)&new_dpi
, &size
) == ERROR_SUCCESS
)
513 if(type
== REG_DWORD
&& new_dpi
!= 0)
522 /***********************************************************************
525 * Increment the reference count of a GDI object.
527 HGDIOBJ
GDI_inc_ref_count( HGDIOBJ handle
)
531 if ((header
= GDI_GetObjPtr( handle
, 0 )))
534 GDI_ReleaseObj( handle
);
542 /***********************************************************************
545 * Decrement the reference count of a GDI object.
547 BOOL
GDI_dec_ref_count( HGDIOBJ handle
)
551 if ((header
= GDI_GetObjPtr( handle
, 0 )))
553 assert( header
->selcount
);
554 if (!--header
->selcount
&& header
->deleted
)
556 /* handle delayed DeleteObject*/
558 GDI_ReleaseObj( handle
);
559 TRACE( "executing delayed DeleteObject for %p\n", handle
);
560 DeleteObject( handle
);
562 else GDI_ReleaseObj( handle
);
564 return header
!= NULL
;
568 /***********************************************************************
571 * GDI initialization.
573 BOOL WINAPI
DllMain( HINSTANCE inst
, DWORD reason
, LPVOID reserved
)
575 LOGFONTW default_gui_font
;
576 const struct DefaultFontInfo
* deffonts
;
579 if (reason
!= DLL_PROCESS_ATTACH
) return TRUE
;
581 DisableThreadLibraryCalls( inst
);
584 /* create stock objects */
585 stock_objects
[WHITE_BRUSH
] = CreateBrushIndirect( &WhiteBrush
);
586 stock_objects
[LTGRAY_BRUSH
] = CreateBrushIndirect( &LtGrayBrush
);
587 stock_objects
[GRAY_BRUSH
] = CreateBrushIndirect( &GrayBrush
);
588 stock_objects
[DKGRAY_BRUSH
] = CreateBrushIndirect( &DkGrayBrush
);
589 stock_objects
[BLACK_BRUSH
] = CreateBrushIndirect( &BlackBrush
);
590 stock_objects
[NULL_BRUSH
] = CreateBrushIndirect( &NullBrush
);
592 stock_objects
[WHITE_PEN
] = CreatePenIndirect( &WhitePen
);
593 stock_objects
[BLACK_PEN
] = CreatePenIndirect( &BlackPen
);
594 stock_objects
[NULL_PEN
] = CreatePenIndirect( &NullPen
);
596 stock_objects
[DEFAULT_PALETTE
] = PALETTE_Init();
597 stock_objects
[DEFAULT_BITMAP
] = CreateBitmap( 1, 1, 1, 1, NULL
);
599 /* language-independent stock fonts */
600 stock_objects
[OEM_FIXED_FONT
] = CreateFontIndirectW( &OEMFixedFont
);
601 stock_objects
[ANSI_FIXED_FONT
] = CreateFontIndirectW( &AnsiFixedFont
);
602 stock_objects
[ANSI_VAR_FONT
] = CreateFontIndirectW( &AnsiVarFont
);
604 /* language-dependent stock fonts */
605 deffonts
= get_default_fonts(get_default_charset());
606 stock_objects
[SYSTEM_FONT
] = CreateFontIndirectW( &deffonts
->SystemFont
);
607 stock_objects
[DEVICE_DEFAULT_FONT
] = CreateFontIndirectW( &deffonts
->DeviceDefaultFont
);
608 stock_objects
[SYSTEM_FIXED_FONT
] = CreateFontIndirectW( &deffonts
->SystemFixedFont
);
610 /* For the default gui font, we use the lfHeight member in deffonts as a place-holder
611 for the point size so we must convert this into a true height */
612 default_gui_font
= deffonts
->DefaultGuiFont
;
613 default_gui_font
.lfHeight
= -MulDiv(default_gui_font
.lfHeight
, get_dpi(), 72);
614 stock_objects
[DEFAULT_GUI_FONT
] = CreateFontIndirectW( &default_gui_font
);
616 stock_objects
[DC_BRUSH
] = CreateBrushIndirect( &DCBrush
);
617 stock_objects
[DC_PEN
] = CreatePenIndirect( &DCPen
);
619 /* clear the NOSYSTEM bit on all stock objects*/
620 for (i
= 0; i
< NB_STOCK_OBJECTS
; i
++)
622 if (!stock_objects
[i
])
624 if (i
== 9) continue; /* there's no stock object 9 */
625 ERR( "could not create stock object %d\n", i
);
628 __wine_make_gdi_object_system( stock_objects
[i
], TRUE
);
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 static const char *gdi_obj_type( unsigned type
)
643 case OBJ_PEN
: return "OBJ_PEN";
644 case OBJ_BRUSH
: return "OBJ_BRUSH";
645 case OBJ_DC
: return "OBJ_DC";
646 case OBJ_METADC
: return "OBJ_METADC";
647 case OBJ_PAL
: return "OBJ_PAL";
648 case OBJ_FONT
: return "OBJ_FONT";
649 case OBJ_BITMAP
: return "OBJ_BITMAP";
650 case OBJ_REGION
: return "OBJ_REGION";
651 case OBJ_METAFILE
: return "OBJ_METAFILE";
652 case OBJ_MEMDC
: return "OBJ_MEMDC";
653 case OBJ_EXTPEN
: return "OBJ_EXTPEN";
654 case OBJ_ENHMETADC
: return "OBJ_ENHMETADC";
655 case OBJ_ENHMETAFILE
: return "OBJ_ENHMETAFILE";
656 case OBJ_COLORSPACE
: return "OBJ_COLORSPACE";
657 default: return "UNKNOWN";
661 static void dump_gdi_objects( void )
665 TRACE( "%u objects:\n", MAX_LARGE_HANDLES
);
667 EnterCriticalSection( &gdi_section
);
668 for (i
= 0; i
< MAX_LARGE_HANDLES
; i
++)
670 if (!large_handles
[i
])
672 TRACE( "index %d handle %p FREE\n", i
, (HGDIOBJ
)(ULONG_PTR
)((i
+ FIRST_LARGE_HANDLE
) << 2) );
675 TRACE( "handle %p obj %p type %s selcount %u deleted %u\n",
676 (HGDIOBJ
)(ULONG_PTR
)((i
+ FIRST_LARGE_HANDLE
) << 2),
677 large_handles
[i
], gdi_obj_type( large_handles
[i
]->type
),
678 large_handles
[i
]->selcount
, large_handles
[i
]->deleted
);
680 LeaveCriticalSection( &gdi_section
);
683 /***********************************************************************
686 * Allocate a GDI handle for an object, which must have been allocated on the process heap.
688 HGDIOBJ
alloc_gdi_handle( GDIOBJHDR
*obj
, WORD type
, const struct gdi_obj_funcs
*funcs
)
692 /* initialize the object header */
700 EnterCriticalSection( &gdi_section
);
701 for (i
= next_large_handle
+ 1; i
< MAX_LARGE_HANDLES
; i
++)
702 if (!large_handles
[i
]) goto found
;
703 for (i
= 0; i
<= next_large_handle
; i
++)
704 if (!large_handles
[i
]) goto found
;
705 LeaveCriticalSection( &gdi_section
);
707 ERR( "out of GDI object handles, expect a crash\n" );
708 if (TRACE_ON(gdi
)) dump_gdi_objects();
712 large_handles
[i
] = obj
;
713 next_large_handle
= i
;
714 LeaveCriticalSection( &gdi_section
);
715 return (HGDIOBJ
)(ULONG_PTR
)((i
+ FIRST_LARGE_HANDLE
) << 2);
719 /***********************************************************************
722 * Free a GDI handle and return a pointer to the object.
724 void *free_gdi_handle( HGDIOBJ handle
)
726 GDIOBJHDR
*object
= NULL
;
729 i
= ((ULONG_PTR
)handle
>> 2) - FIRST_LARGE_HANDLE
;
730 if (i
>= 0 && i
< MAX_LARGE_HANDLES
)
732 EnterCriticalSection( &gdi_section
);
733 object
= large_handles
[i
];
734 large_handles
[i
] = NULL
;
735 LeaveCriticalSection( &gdi_section
);
739 object
->type
= 0; /* mark it as invalid */
740 object
->funcs
= NULL
;
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 type
)
755 GDIOBJHDR
*ptr
= NULL
;
758 EnterCriticalSection( &gdi_section
);
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
&& type
&& ptr
->type
!= type
) ptr
= NULL
;
769 LeaveCriticalSection( &gdi_section
);
770 WARN( "Invalid handle %p\n", handle
);
772 else TRACE("(%p): enter %d\n", handle
, gdi_section
.RecursionCount
);
778 /***********************************************************************
782 void GDI_ReleaseObj( HGDIOBJ handle
)
784 TRACE("(%p): leave %d\n", handle
, gdi_section
.RecursionCount
);
785 LeaveCriticalSection( &gdi_section
);
789 /***********************************************************************
792 void GDI_CheckNotLock(void)
794 if (gdi_section
.OwningThread
== ULongToHandle(GetCurrentThreadId()) && gdi_section
.RecursionCount
)
796 ERR( "BUG: holding GDI lock\n" );
802 /***********************************************************************
803 * DeleteObject (GDI32.@)
805 * Delete a Gdi object.
808 * obj [I] Gdi object to delete
811 * Success: TRUE. If obj was not returned from GetStockObject(), any resources
812 * it consumed are released.
813 * Failure: FALSE, if obj is not a valid Gdi object, or is currently selected
816 BOOL WINAPI
DeleteObject( HGDIOBJ obj
)
818 /* Check if object is valid */
820 struct hdc_list
*hdcs_head
;
821 const struct gdi_obj_funcs
*funcs
;
824 if (HIWORD(obj
)) return FALSE
;
826 if (!(header
= GDI_GetObjPtr( obj
, 0 ))) return FALSE
;
830 TRACE("Preserving system object %p\n", obj
);
831 GDI_ReleaseObj( obj
);
835 while ((hdcs_head
= header
->hdcs
) != NULL
)
837 DC
*dc
= get_dc_ptr(hdcs_head
->hdc
);
839 header
->hdcs
= hdcs_head
->next
;
840 TRACE("hdc %p has interest in %p\n", hdcs_head
->hdc
, obj
);
844 if(dc
->funcs
->pDeleteObject
)
846 GDI_ReleaseObj( obj
); /* release the GDI lock */
847 dc
->funcs
->pDeleteObject( dc
->physDev
, obj
);
848 header
= GDI_GetObjPtr( obj
, 0 ); /* and grab it again */
850 release_dc_ptr( dc
);
852 HeapFree(GetProcessHeap(), 0, hdcs_head
);
853 if (!header
) return FALSE
;
856 if (header
->selcount
)
858 TRACE("delayed for %p because object in use, count %u\n", obj
, header
->selcount
);
859 header
->deleted
= 1; /* mark for delete */
860 GDI_ReleaseObj( obj
);
868 funcs
= header
->funcs
;
869 GDI_ReleaseObj( obj
);
870 if (funcs
&& funcs
->pDeleteObject
)
871 return funcs
->pDeleteObject( obj
);
876 /***********************************************************************
877 * GDI_hdc_using_object
879 * Call this if the dc requires DeleteObject notification
881 BOOL
GDI_hdc_using_object(HGDIOBJ obj
, HDC hdc
)
884 struct hdc_list
**pphdc
;
886 TRACE("obj %p hdc %p\n", obj
, hdc
);
888 if (!(header
= GDI_GetObjPtr( obj
, 0 ))) return FALSE
;
896 for(pphdc
= &header
->hdcs
; *pphdc
; pphdc
= &(*pphdc
)->next
)
897 if((*pphdc
)->hdc
== hdc
)
901 *pphdc
= HeapAlloc(GetProcessHeap(), 0, sizeof(**pphdc
));
903 (*pphdc
)->next
= NULL
;
910 /***********************************************************************
911 * GDI_hdc_not_using_object
914 BOOL
GDI_hdc_not_using_object(HGDIOBJ obj
, HDC hdc
)
917 struct hdc_list
*phdc
, **prev
;
919 TRACE("obj %p hdc %p\n", obj
, hdc
);
921 if (!(header
= GDI_GetObjPtr( obj
, 0 ))) return FALSE
;
930 prev
= &header
->hdcs
;
933 if(phdc
->hdc
== hdc
) {
935 HeapFree(GetProcessHeap(), 0, phdc
);
947 /***********************************************************************
948 * GetStockObject (GDI32.@)
950 HGDIOBJ WINAPI
GetStockObject( INT obj
)
953 if ((obj
< 0) || (obj
>= NB_STOCK_OBJECTS
)) return 0;
954 ret
= stock_objects
[obj
];
955 TRACE("returning %p\n", ret
);
960 /***********************************************************************
961 * GetObjectA (GDI32.@)
963 INT WINAPI
GetObjectA( HGDIOBJ handle
, INT count
, LPVOID buffer
)
965 const struct gdi_obj_funcs
*funcs
;
969 TRACE("%p %d %p\n", handle
, count
, buffer
);
971 if (!(ptr
= GDI_GetObjPtr( handle
, 0 ))) return 0;
973 GDI_ReleaseObj( handle
);
975 if (funcs
&& funcs
->pGetObjectA
)
976 result
= funcs
->pGetObjectA( handle
, count
, buffer
);
978 SetLastError( ERROR_INVALID_HANDLE
);
983 /***********************************************************************
984 * GetObjectW (GDI32.@)
986 INT WINAPI
GetObjectW( HGDIOBJ handle
, INT count
, LPVOID buffer
)
988 const struct gdi_obj_funcs
*funcs
;
991 TRACE("%p %d %p\n", handle
, count
, buffer
);
993 if (!(ptr
= GDI_GetObjPtr( handle
, 0 ))) return 0;
995 GDI_ReleaseObj( handle
);
997 if (funcs
&& funcs
->pGetObjectW
)
998 result
= funcs
->pGetObjectW( handle
, count
, buffer
);
1000 SetLastError( ERROR_INVALID_HANDLE
);
1005 /***********************************************************************
1006 * GetObjectType (GDI32.@)
1008 DWORD WINAPI
GetObjectType( HGDIOBJ handle
)
1013 if (!(ptr
= GDI_GetObjPtr( handle
, 0 )))
1015 SetLastError( ERROR_INVALID_HANDLE
);
1019 GDI_ReleaseObj( handle
);
1020 TRACE("%p -> %u\n", handle
, result
);
1024 /***********************************************************************
1025 * GetCurrentObject (GDI32.@)
1027 * Get the currently selected object of a given type in a device context.
1030 * hdc [I] Device context to get the current object from
1031 * type [I] Type of current object to get (OBJ_* defines from "wingdi.h")
1034 * Success: The current object of the given type selected in hdc.
1035 * Failure: A NULL handle.
1038 * - only the following object types are supported:
1045 HGDIOBJ WINAPI
GetCurrentObject(HDC hdc
,UINT type
)
1048 DC
* dc
= get_dc_ptr( hdc
);
1053 case OBJ_EXTPEN
: /* fall through */
1054 case OBJ_PEN
: ret
= dc
->hPen
; break;
1055 case OBJ_BRUSH
: ret
= dc
->hBrush
; break;
1056 case OBJ_PAL
: ret
= dc
->hPalette
; break;
1057 case OBJ_FONT
: ret
= dc
->hFont
; break;
1058 case OBJ_BITMAP
: ret
= dc
->hBitmap
; break;
1060 /* tests show that OBJ_REGION is explicitly ignored */
1061 case OBJ_REGION
: break;
1063 /* the SDK only mentions those above */
1064 FIXME("(%p,%d): unknown type.\n",hdc
,type
);
1067 release_dc_ptr( dc
);
1072 /***********************************************************************
1073 * SelectObject (GDI32.@)
1075 * Select a Gdi object into a device context.
1078 * hdc [I] Device context to associate the object with
1079 * hObj [I] Gdi object to associate with hdc
1082 * Success: A non-NULL handle representing the previously selected object of
1083 * the same type as hObj.
1084 * Failure: A NULL object. If hdc is invalid, GetLastError() returns ERROR_INVALID_HANDLE.
1085 * if hObj is not a valid object handle, no last error is set. In either
1086 * case, hdc is unaffected by the call.
1088 HGDIOBJ WINAPI
SelectObject( HDC hdc
, HGDIOBJ hObj
)
1093 TRACE( "(%p,%p)\n", hdc
, hObj
);
1095 header
= GDI_GetObjPtr( hObj
, 0 );
1098 const struct gdi_obj_funcs
*funcs
= header
->funcs
;
1099 GDI_ReleaseObj( hObj
);
1100 if (funcs
&& funcs
->pSelectObject
) ret
= funcs
->pSelectObject( hObj
, hdc
);
1106 /***********************************************************************
1107 * UnrealizeObject (GDI32.@)
1109 BOOL WINAPI
UnrealizeObject( HGDIOBJ obj
)
1111 BOOL result
= FALSE
;
1112 GDIOBJHDR
* header
= GDI_GetObjPtr( obj
, 0 );
1116 const struct gdi_obj_funcs
*funcs
= header
->funcs
;
1118 GDI_ReleaseObj( obj
);
1119 if (funcs
&& funcs
->pUnrealizeObject
)
1120 result
= header
->funcs
->pUnrealizeObject( obj
);
1128 /* Solid colors to enumerate */
1129 static const COLORREF solid_colors
[] =
1130 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
1131 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
1132 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
1133 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
1134 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
1135 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
1136 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
1137 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
1141 /***********************************************************************
1142 * EnumObjects (GDI32.@)
1144 INT WINAPI
EnumObjects( HDC hdc
, INT nObjType
,
1145 GOBJENUMPROC lpEnumFunc
, LPARAM lParam
)
1152 TRACE("%p %d %p %08lx\n", hdc
, nObjType
, lpEnumFunc
, lParam
);
1156 /* Enumerate solid pens */
1157 for (i
= 0; i
< sizeof(solid_colors
)/sizeof(solid_colors
[0]); i
++)
1159 pen
.lopnStyle
= PS_SOLID
;
1160 pen
.lopnWidth
.x
= 1;
1161 pen
.lopnWidth
.y
= 0;
1162 pen
.lopnColor
= solid_colors
[i
];
1163 retval
= lpEnumFunc( &pen
, lParam
);
1164 TRACE("solid pen %08x, ret=%d\n",
1165 solid_colors
[i
], retval
);
1171 /* Enumerate solid brushes */
1172 for (i
= 0; i
< sizeof(solid_colors
)/sizeof(solid_colors
[0]); i
++)
1174 brush
.lbStyle
= BS_SOLID
;
1175 brush
.lbColor
= solid_colors
[i
];
1177 retval
= lpEnumFunc( &brush
, lParam
);
1178 TRACE("solid brush %08x, ret=%d\n",
1179 solid_colors
[i
], retval
);
1183 /* Now enumerate hatched brushes */
1184 if (retval
) for (i
= HS_HORIZONTAL
; i
<= HS_DIAGCROSS
; i
++)
1186 brush
.lbStyle
= BS_HATCHED
;
1187 brush
.lbColor
= RGB(0,0,0);
1189 retval
= lpEnumFunc( &brush
, lParam
);
1190 TRACE("hatched brush %d, ret=%d\n",
1197 /* FIXME: implement Win32 types */
1198 WARN("(%d): Invalid type\n", nObjType
);
1205 /***********************************************************************
1206 * SetObjectOwner (GDI32.@)
1208 void WINAPI
SetObjectOwner( HGDIOBJ handle
, HANDLE owner
)
1213 /***********************************************************************
1214 * GdiInitializeLanguagePack (GDI32.@)
1216 DWORD WINAPI
GdiInitializeLanguagePack( DWORD arg
)
1222 /***********************************************************************
1223 * GdiFlush (GDI32.@)
1225 BOOL WINAPI
GdiFlush(void)
1227 return TRUE
; /* FIXME */
1231 /***********************************************************************
1232 * GdiGetBatchLimit (GDI32.@)
1234 DWORD WINAPI
GdiGetBatchLimit(void)
1236 return 1; /* FIXME */
1240 /***********************************************************************
1241 * GdiSetBatchLimit (GDI32.@)
1243 DWORD WINAPI
GdiSetBatchLimit( DWORD limit
)
1245 return 1; /* FIXME */
1249 /*******************************************************************
1250 * GetColorAdjustment [GDI32.@]
1254 BOOL WINAPI
GetColorAdjustment(HDC hdc
, LPCOLORADJUSTMENT lpca
)
1260 /*******************************************************************
1261 * GdiComment [GDI32.@]
1265 BOOL WINAPI
GdiComment(HDC hdc
, UINT cbSize
, const BYTE
*lpData
)
1267 DC
*dc
= get_dc_ptr(hdc
);
1271 if (dc
->funcs
->pGdiComment
)
1272 ret
= dc
->funcs
->pGdiComment( dc
->physDev
, cbSize
, lpData
);
1273 release_dc_ptr( dc
);
1278 /*******************************************************************
1279 * SetColorAdjustment [GDI32.@]
1283 BOOL WINAPI
SetColorAdjustment(HDC hdc
, const COLORADJUSTMENT
* lpca
)