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
;
638 static LONG debug_count
;
640 static const char *gdi_obj_type( unsigned type
)
644 case OBJ_PEN
: return "OBJ_PEN";
645 case OBJ_BRUSH
: return "OBJ_BRUSH";
646 case OBJ_DC
: return "OBJ_DC";
647 case OBJ_METADC
: return "OBJ_METADC";
648 case OBJ_PAL
: return "OBJ_PAL";
649 case OBJ_FONT
: return "OBJ_FONT";
650 case OBJ_BITMAP
: return "OBJ_BITMAP";
651 case OBJ_REGION
: return "OBJ_REGION";
652 case OBJ_METAFILE
: return "OBJ_METAFILE";
653 case OBJ_MEMDC
: return "OBJ_MEMDC";
654 case OBJ_EXTPEN
: return "OBJ_EXTPEN";
655 case OBJ_ENHMETADC
: return "OBJ_ENHMETADC";
656 case OBJ_ENHMETAFILE
: return "OBJ_ENHMETAFILE";
657 case OBJ_COLORSPACE
: return "OBJ_COLORSPACE";
658 default: return "UNKNOWN";
662 static void dump_gdi_objects( void )
666 TRACE( "%u objects:\n", MAX_LARGE_HANDLES
);
668 EnterCriticalSection( &gdi_section
);
669 for (i
= 0; i
< MAX_LARGE_HANDLES
; i
++)
671 if (!large_handles
[i
])
673 TRACE( "index %d handle %p FREE\n", i
, (HGDIOBJ
)(ULONG_PTR
)((i
+ FIRST_LARGE_HANDLE
) << 2) );
676 TRACE( "handle %p obj %p type %s selcount %u deleted %u\n",
677 (HGDIOBJ
)(ULONG_PTR
)((i
+ FIRST_LARGE_HANDLE
) << 2),
678 large_handles
[i
], gdi_obj_type( large_handles
[i
]->type
),
679 large_handles
[i
]->selcount
, large_handles
[i
]->deleted
);
681 LeaveCriticalSection( &gdi_section
);
684 /***********************************************************************
687 * Allocate a GDI handle for an object, which must have been allocated on the process heap.
689 HGDIOBJ
alloc_gdi_handle( GDIOBJHDR
*obj
, WORD type
, const struct gdi_obj_funcs
*funcs
)
693 /* initialize the object header */
701 EnterCriticalSection( &gdi_section
);
702 for (i
= next_large_handle
+ 1; i
< MAX_LARGE_HANDLES
; i
++)
703 if (!large_handles
[i
]) goto found
;
704 for (i
= 0; i
<= next_large_handle
; i
++)
705 if (!large_handles
[i
]) goto found
;
706 LeaveCriticalSection( &gdi_section
);
708 ERR( "out of GDI object handles, expect a crash\n" );
709 if (TRACE_ON(gdi
)) dump_gdi_objects();
713 large_handles
[i
] = obj
;
714 next_large_handle
= i
;
715 LeaveCriticalSection( &gdi_section
);
716 TRACE( "allocated %s %p %u/%u\n",
717 gdi_obj_type(type
), (HGDIOBJ
)(ULONG_PTR
)((i
+ FIRST_LARGE_HANDLE
) << 2),
718 InterlockedIncrement( &debug_count
), MAX_LARGE_HANDLES
);
719 return (HGDIOBJ
)(ULONG_PTR
)((i
+ FIRST_LARGE_HANDLE
) << 2);
723 /***********************************************************************
726 * Free a GDI handle and return a pointer to the object.
728 void *free_gdi_handle( HGDIOBJ handle
)
730 GDIOBJHDR
*object
= NULL
;
733 i
= ((ULONG_PTR
)handle
>> 2) - FIRST_LARGE_HANDLE
;
734 if (i
>= 0 && i
< MAX_LARGE_HANDLES
)
736 EnterCriticalSection( &gdi_section
);
737 object
= large_handles
[i
];
738 large_handles
[i
] = NULL
;
739 LeaveCriticalSection( &gdi_section
);
743 TRACE( "freed %s %p %u/%u\n", gdi_obj_type( object
->type
), handle
,
744 InterlockedDecrement( &debug_count
) + 1, MAX_LARGE_HANDLES
);
745 object
->type
= 0; /* mark it as invalid */
746 object
->funcs
= NULL
;
752 /***********************************************************************
755 * Return a pointer to the GDI object associated to the handle.
756 * Return NULL if the object has the wrong magic number.
757 * The object must be released with GDI_ReleaseObj.
759 void *GDI_GetObjPtr( HGDIOBJ handle
, WORD type
)
761 GDIOBJHDR
*ptr
= NULL
;
764 EnterCriticalSection( &gdi_section
);
766 i
= ((UINT_PTR
)handle
>> 2) - FIRST_LARGE_HANDLE
;
767 if (i
>= 0 && i
< MAX_LARGE_HANDLES
)
769 ptr
= large_handles
[i
];
770 if (ptr
&& type
&& ptr
->type
!= type
) ptr
= NULL
;
775 LeaveCriticalSection( &gdi_section
);
776 WARN( "Invalid handle %p\n", handle
);
783 /***********************************************************************
787 void GDI_ReleaseObj( HGDIOBJ handle
)
789 LeaveCriticalSection( &gdi_section
);
793 /***********************************************************************
796 void GDI_CheckNotLock(void)
798 if (gdi_section
.OwningThread
== ULongToHandle(GetCurrentThreadId()) && gdi_section
.RecursionCount
)
800 ERR( "BUG: holding GDI lock\n" );
806 /***********************************************************************
807 * DeleteObject (GDI32.@)
809 * Delete a Gdi object.
812 * obj [I] Gdi object to delete
815 * Success: TRUE. If obj was not returned from GetStockObject(), any resources
816 * it consumed are released.
817 * Failure: FALSE, if obj is not a valid Gdi object, or is currently selected
820 BOOL WINAPI
DeleteObject( HGDIOBJ obj
)
822 /* Check if object is valid */
824 struct hdc_list
*hdcs_head
;
825 const struct gdi_obj_funcs
*funcs
;
828 if (HIWORD(obj
)) return FALSE
;
830 if (!(header
= GDI_GetObjPtr( obj
, 0 ))) return FALSE
;
834 TRACE("Preserving system object %p\n", obj
);
835 GDI_ReleaseObj( obj
);
839 while ((hdcs_head
= header
->hdcs
) != NULL
)
841 DC
*dc
= get_dc_ptr(hdcs_head
->hdc
);
843 header
->hdcs
= hdcs_head
->next
;
844 TRACE("hdc %p has interest in %p\n", hdcs_head
->hdc
, obj
);
848 if(dc
->funcs
->pDeleteObject
)
850 GDI_ReleaseObj( obj
); /* release the GDI lock */
851 dc
->funcs
->pDeleteObject( dc
->physDev
, obj
);
852 header
= GDI_GetObjPtr( obj
, 0 ); /* and grab it again */
854 release_dc_ptr( dc
);
856 HeapFree(GetProcessHeap(), 0, hdcs_head
);
857 if (!header
) return FALSE
;
860 if (header
->selcount
)
862 TRACE("delayed for %p because object in use, count %u\n", obj
, header
->selcount
);
863 header
->deleted
= 1; /* mark for delete */
864 GDI_ReleaseObj( obj
);
872 funcs
= header
->funcs
;
873 GDI_ReleaseObj( obj
);
874 if (funcs
&& funcs
->pDeleteObject
)
875 return funcs
->pDeleteObject( obj
);
880 /***********************************************************************
881 * GDI_hdc_using_object
883 * Call this if the dc requires DeleteObject notification
885 BOOL
GDI_hdc_using_object(HGDIOBJ obj
, HDC hdc
)
888 struct hdc_list
**pphdc
;
890 TRACE("obj %p hdc %p\n", obj
, hdc
);
892 if (!(header
= GDI_GetObjPtr( obj
, 0 ))) return FALSE
;
900 for(pphdc
= &header
->hdcs
; *pphdc
; pphdc
= &(*pphdc
)->next
)
901 if((*pphdc
)->hdc
== hdc
)
905 *pphdc
= HeapAlloc(GetProcessHeap(), 0, sizeof(**pphdc
));
907 (*pphdc
)->next
= NULL
;
914 /***********************************************************************
915 * GDI_hdc_not_using_object
918 BOOL
GDI_hdc_not_using_object(HGDIOBJ obj
, HDC hdc
)
921 struct hdc_list
*phdc
, **prev
;
923 TRACE("obj %p hdc %p\n", obj
, hdc
);
925 if (!(header
= GDI_GetObjPtr( obj
, 0 ))) return FALSE
;
934 prev
= &header
->hdcs
;
937 if(phdc
->hdc
== hdc
) {
939 HeapFree(GetProcessHeap(), 0, phdc
);
951 /***********************************************************************
952 * GetStockObject (GDI32.@)
954 HGDIOBJ WINAPI
GetStockObject( INT obj
)
957 if ((obj
< 0) || (obj
>= NB_STOCK_OBJECTS
)) return 0;
958 ret
= stock_objects
[obj
];
959 TRACE("returning %p\n", ret
);
964 /***********************************************************************
965 * GetObjectA (GDI32.@)
967 INT WINAPI
GetObjectA( HGDIOBJ handle
, INT count
, LPVOID buffer
)
969 const struct gdi_obj_funcs
*funcs
;
973 TRACE("%p %d %p\n", handle
, count
, buffer
);
975 if (!(ptr
= GDI_GetObjPtr( handle
, 0 ))) return 0;
977 GDI_ReleaseObj( handle
);
979 if (funcs
&& funcs
->pGetObjectA
)
981 if (buffer
&& ((ULONG_PTR
)buffer
>> 16) == 0) /* catch apps getting argument order wrong */
982 SetLastError( ERROR_NOACCESS
);
984 result
= funcs
->pGetObjectA( handle
, count
, buffer
);
987 SetLastError( ERROR_INVALID_HANDLE
);
992 /***********************************************************************
993 * GetObjectW (GDI32.@)
995 INT WINAPI
GetObjectW( HGDIOBJ handle
, INT count
, LPVOID buffer
)
997 const struct gdi_obj_funcs
*funcs
;
1000 TRACE("%p %d %p\n", handle
, count
, buffer
);
1002 if (!(ptr
= GDI_GetObjPtr( handle
, 0 ))) return 0;
1004 GDI_ReleaseObj( handle
);
1006 if (funcs
&& funcs
->pGetObjectW
)
1008 if (buffer
&& ((ULONG_PTR
)buffer
>> 16) == 0) /* catch apps getting argument order wrong */
1009 SetLastError( ERROR_NOACCESS
);
1011 result
= funcs
->pGetObjectW( handle
, count
, buffer
);
1014 SetLastError( ERROR_INVALID_HANDLE
);
1019 /***********************************************************************
1020 * GetObjectType (GDI32.@)
1022 DWORD WINAPI
GetObjectType( HGDIOBJ handle
)
1027 if (!(ptr
= GDI_GetObjPtr( handle
, 0 )))
1029 SetLastError( ERROR_INVALID_HANDLE
);
1033 GDI_ReleaseObj( handle
);
1034 TRACE("%p -> %u\n", handle
, result
);
1038 /***********************************************************************
1039 * GetCurrentObject (GDI32.@)
1041 * Get the currently selected object of a given type in a device context.
1044 * hdc [I] Device context to get the current object from
1045 * type [I] Type of current object to get (OBJ_* defines from "wingdi.h")
1048 * Success: The current object of the given type selected in hdc.
1049 * Failure: A NULL handle.
1052 * - only the following object types are supported:
1059 HGDIOBJ WINAPI
GetCurrentObject(HDC hdc
,UINT type
)
1062 DC
* dc
= get_dc_ptr( hdc
);
1067 case OBJ_EXTPEN
: /* fall through */
1068 case OBJ_PEN
: ret
= dc
->hPen
; break;
1069 case OBJ_BRUSH
: ret
= dc
->hBrush
; break;
1070 case OBJ_PAL
: ret
= dc
->hPalette
; break;
1071 case OBJ_FONT
: ret
= dc
->hFont
; break;
1072 case OBJ_BITMAP
: ret
= dc
->hBitmap
; break;
1074 /* tests show that OBJ_REGION is explicitly ignored */
1075 case OBJ_REGION
: break;
1077 /* the SDK only mentions those above */
1078 FIXME("(%p,%d): unknown type.\n",hdc
,type
);
1081 release_dc_ptr( dc
);
1086 /***********************************************************************
1087 * SelectObject (GDI32.@)
1089 * Select a Gdi object into a device context.
1092 * hdc [I] Device context to associate the object with
1093 * hObj [I] Gdi object to associate with hdc
1096 * Success: A non-NULL handle representing the previously selected object of
1097 * the same type as hObj.
1098 * Failure: A NULL object. If hdc is invalid, GetLastError() returns ERROR_INVALID_HANDLE.
1099 * if hObj is not a valid object handle, no last error is set. In either
1100 * case, hdc is unaffected by the call.
1102 HGDIOBJ WINAPI
SelectObject( HDC hdc
, HGDIOBJ hObj
)
1107 TRACE( "(%p,%p)\n", hdc
, hObj
);
1109 header
= GDI_GetObjPtr( hObj
, 0 );
1112 const struct gdi_obj_funcs
*funcs
= header
->funcs
;
1113 GDI_ReleaseObj( hObj
);
1114 if (funcs
&& funcs
->pSelectObject
) ret
= funcs
->pSelectObject( hObj
, hdc
);
1120 /***********************************************************************
1121 * UnrealizeObject (GDI32.@)
1123 BOOL WINAPI
UnrealizeObject( HGDIOBJ obj
)
1125 BOOL result
= FALSE
;
1126 GDIOBJHDR
* header
= GDI_GetObjPtr( obj
, 0 );
1130 const struct gdi_obj_funcs
*funcs
= header
->funcs
;
1132 GDI_ReleaseObj( obj
);
1133 if (funcs
&& funcs
->pUnrealizeObject
)
1134 result
= header
->funcs
->pUnrealizeObject( obj
);
1142 /* Solid colors to enumerate */
1143 static const COLORREF solid_colors
[] =
1144 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
1145 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
1146 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
1147 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
1148 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
1149 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
1150 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
1151 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
1155 /***********************************************************************
1156 * EnumObjects (GDI32.@)
1158 INT WINAPI
EnumObjects( HDC hdc
, INT nObjType
,
1159 GOBJENUMPROC lpEnumFunc
, LPARAM lParam
)
1166 TRACE("%p %d %p %08lx\n", hdc
, nObjType
, lpEnumFunc
, lParam
);
1170 /* Enumerate solid pens */
1171 for (i
= 0; i
< sizeof(solid_colors
)/sizeof(solid_colors
[0]); i
++)
1173 pen
.lopnStyle
= PS_SOLID
;
1174 pen
.lopnWidth
.x
= 1;
1175 pen
.lopnWidth
.y
= 0;
1176 pen
.lopnColor
= solid_colors
[i
];
1177 retval
= lpEnumFunc( &pen
, lParam
);
1178 TRACE("solid pen %08x, ret=%d\n",
1179 solid_colors
[i
], retval
);
1185 /* Enumerate solid brushes */
1186 for (i
= 0; i
< sizeof(solid_colors
)/sizeof(solid_colors
[0]); i
++)
1188 brush
.lbStyle
= BS_SOLID
;
1189 brush
.lbColor
= solid_colors
[i
];
1191 retval
= lpEnumFunc( &brush
, lParam
);
1192 TRACE("solid brush %08x, ret=%d\n",
1193 solid_colors
[i
], retval
);
1197 /* Now enumerate hatched brushes */
1198 if (retval
) for (i
= HS_HORIZONTAL
; i
<= HS_DIAGCROSS
; i
++)
1200 brush
.lbStyle
= BS_HATCHED
;
1201 brush
.lbColor
= RGB(0,0,0);
1203 retval
= lpEnumFunc( &brush
, lParam
);
1204 TRACE("hatched brush %d, ret=%d\n",
1211 /* FIXME: implement Win32 types */
1212 WARN("(%d): Invalid type\n", nObjType
);
1219 /***********************************************************************
1220 * SetObjectOwner (GDI32.@)
1222 void WINAPI
SetObjectOwner( HGDIOBJ handle
, HANDLE owner
)
1227 /***********************************************************************
1228 * GdiInitializeLanguagePack (GDI32.@)
1230 DWORD WINAPI
GdiInitializeLanguagePack( DWORD arg
)
1236 /***********************************************************************
1237 * GdiFlush (GDI32.@)
1239 BOOL WINAPI
GdiFlush(void)
1241 return TRUE
; /* FIXME */
1245 /***********************************************************************
1246 * GdiGetBatchLimit (GDI32.@)
1248 DWORD WINAPI
GdiGetBatchLimit(void)
1250 return 1; /* FIXME */
1254 /***********************************************************************
1255 * GdiSetBatchLimit (GDI32.@)
1257 DWORD WINAPI
GdiSetBatchLimit( DWORD limit
)
1259 return 1; /* FIXME */
1263 /*******************************************************************
1264 * GetColorAdjustment [GDI32.@]
1268 BOOL WINAPI
GetColorAdjustment(HDC hdc
, LPCOLORADJUSTMENT lpca
)
1274 /*******************************************************************
1275 * GdiComment [GDI32.@]
1279 BOOL WINAPI
GdiComment(HDC hdc
, UINT cbSize
, const BYTE
*lpData
)
1281 DC
*dc
= get_dc_ptr(hdc
);
1285 if (dc
->funcs
->pGdiComment
)
1286 ret
= dc
->funcs
->pGdiComment( dc
->physDev
, cbSize
, lpData
);
1287 release_dc_ptr( dc
);
1292 /*******************************************************************
1293 * SetColorAdjustment [GDI32.@]
1297 BOOL WINAPI
SetColorAdjustment(HDC hdc
, const COLORADJUSTMENT
* lpca
)