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
, {'\0'} };
94 static const LOGFONTW AnsiVarFont
=
95 { 12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
96 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
97 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'} };
99 /******************************************************************************
101 * language-dependent stock fonts
103 * 'ANSI' charset and 'DEFAULT' charset is not same.
104 * The chars in CP_ACP should be drawn with 'DEFAULT' charset.
105 * 'ANSI' charset seems to be identical with ISO-8859-1.
106 * 'DEFAULT' charset is a language-dependent charset.
108 * 'System' font seems to be an alias for language-dependent font.
112 * language-dependent stock fonts for all known charsets
113 * please see TranslateCharsetInfo (dlls/gdi/font.c) and
114 * CharsetBindingInfo (dlls/x11drv/xfont.c),
115 * and modify entries for your language if needed.
117 struct DefaultFontInfo
121 LOGFONTW DeviceDefaultFont
;
122 LOGFONTW SystemFixedFont
;
123 LOGFONTW DefaultGuiFont
; /* Note for this font the lfHeight member should be the point size */
126 static const struct DefaultFontInfo default_fonts
[] =
130 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
131 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
132 {'S','y','s','t','e','m','\0'}
134 { /* Device Default */
135 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
136 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
140 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
141 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
144 { /* DefaultGuiFont */
145 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
146 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
147 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
150 { EASTEUROPE_CHARSET
,
152 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, EASTEUROPE_CHARSET
,
153 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
154 {'S','y','s','t','e','m','\0'}
156 { /* Device Default */
157 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, EASTEUROPE_CHARSET
,
158 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
162 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, EASTEUROPE_CHARSET
,
163 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
166 { /* DefaultGuiFont */
167 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, EASTEUROPE_CHARSET
,
168 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
169 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
174 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, RUSSIAN_CHARSET
,
175 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
176 {'S','y','s','t','e','m','\0'}
178 { /* Device Default */
179 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, RUSSIAN_CHARSET
,
180 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
184 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, RUSSIAN_CHARSET
,
185 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
188 { /* DefaultGuiFont */
189 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, RUSSIAN_CHARSET
,
190 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
191 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
196 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GREEK_CHARSET
,
197 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
198 {'S','y','s','t','e','m','\0'}
200 { /* Device Default */
201 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GREEK_CHARSET
,
202 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
206 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GREEK_CHARSET
,
207 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
210 { /* DefaultGuiFont */
211 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GREEK_CHARSET
,
212 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
213 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
218 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, TURKISH_CHARSET
,
219 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
220 {'S','y','s','t','e','m','\0'}
222 { /* Device Default */
223 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, TURKISH_CHARSET
,
224 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
228 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, TURKISH_CHARSET
,
229 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
232 { /* DefaultGuiFont */
233 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, TURKISH_CHARSET
,
234 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
235 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
240 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HEBREW_CHARSET
,
241 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
242 {'S','y','s','t','e','m','\0'}
244 { /* Device Default */
245 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HEBREW_CHARSET
,
246 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
250 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HEBREW_CHARSET
,
251 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
254 { /* DefaultGuiFont */
255 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HEBREW_CHARSET
,
256 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
257 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
262 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ARABIC_CHARSET
,
263 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
264 {'S','y','s','t','e','m','\0'}
266 { /* Device Default */
267 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ARABIC_CHARSET
,
268 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
272 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ARABIC_CHARSET
,
273 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
276 { /* DefaultGuiFont */
277 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ARABIC_CHARSET
,
278 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
279 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
284 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, BALTIC_CHARSET
,
285 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
286 {'S','y','s','t','e','m','\0'}
288 { /* Device Default */
289 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, BALTIC_CHARSET
,
290 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
294 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, BALTIC_CHARSET
,
295 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
298 { /* DefaultGuiFont */
299 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, BALTIC_CHARSET
,
300 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
301 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
306 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, THAI_CHARSET
,
307 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
308 {'S','y','s','t','e','m','\0'}
310 { /* Device Default */
311 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, THAI_CHARSET
,
312 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
316 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, THAI_CHARSET
,
317 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
320 { /* DefaultGuiFont */
321 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, THAI_CHARSET
,
322 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
323 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
328 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, SHIFTJIS_CHARSET
,
329 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
330 {'S','y','s','t','e','m','\0'}
332 { /* Device Default */
333 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, SHIFTJIS_CHARSET
,
334 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
338 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, SHIFTJIS_CHARSET
,
339 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
342 { /* DefaultGuiFont */
343 9, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, SHIFTJIS_CHARSET
,
344 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
345 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
350 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GB2312_CHARSET
,
351 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
352 {'S','y','s','t','e','m','\0'}
354 { /* Device Default */
355 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GB2312_CHARSET
,
356 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
360 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GB2312_CHARSET
,
361 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
364 { /* DefaultGuiFont */
365 9, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GB2312_CHARSET
,
366 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
367 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
372 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HANGEUL_CHARSET
,
373 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
374 {'S','y','s','t','e','m','\0'}
376 { /* Device Default */
377 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HANGEUL_CHARSET
,
378 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
382 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HANGEUL_CHARSET
,
383 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
386 { /* DefaultGuiFont */
387 9, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HANGEUL_CHARSET
,
388 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
389 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
392 { CHINESEBIG5_CHARSET
,
394 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, CHINESEBIG5_CHARSET
,
395 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
396 {'S','y','s','t','e','m','\0'}
398 { /* Device Default */
399 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, CHINESEBIG5_CHARSET
,
400 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
404 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, CHINESEBIG5_CHARSET
,
405 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
408 { /* DefaultGuiFont */
409 9, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, CHINESEBIG5_CHARSET
,
410 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
411 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
416 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, JOHAB_CHARSET
,
417 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
418 {'S','y','s','t','e','m','\0'}
420 { /* Device Default */
421 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, JOHAB_CHARSET
,
422 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
426 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, JOHAB_CHARSET
,
427 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
430 { /* DefaultGuiFont */
431 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, JOHAB_CHARSET
,
432 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
433 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
439 /*************************************************************************
440 * __wine_make_gdi_object_system (GDI32.@)
442 * USER has to tell GDI that its system brushes and pens are non-deletable.
443 * For a description of the GDI object magics and their flags,
444 * see "Undocumented Windows" (wrong about the OBJECT_NOSYSTEM flag, though).
446 void CDECL
__wine_make_gdi_object_system( HGDIOBJ handle
, BOOL set
)
448 GDIOBJHDR
*ptr
= GDI_GetObjPtr( handle
, 0 );
450 GDI_ReleaseObj( handle
);
453 /******************************************************************************
456 static const struct DefaultFontInfo
* get_default_fonts(UINT charset
)
460 for(n
=0;n
<(sizeof(default_fonts
)/sizeof(default_fonts
[0]));n
++)
462 if ( default_fonts
[n
].charset
== charset
)
463 return &default_fonts
[n
];
466 FIXME( "unhandled charset 0x%08x - use ANSI_CHARSET for default stock objects\n", charset
);
467 return &default_fonts
[0];
471 /******************************************************************************
472 * get_default_charset (internal)
474 * get the language-dependent charset that can handle CP_ACP correctly.
476 static UINT
get_default_charset( void )
482 csi
.ciCharset
= ANSI_CHARSET
;
483 if ( !TranslateCharsetInfo( ULongToPtr(uACP
), &csi
, TCI_SRCCODEPAGE
) )
485 FIXME( "unhandled codepage %u - use ANSI_CHARSET for default stock objects\n", uACP
);
489 return csi
.ciCharset
;
492 static const WCHAR dpi_key_name
[] = {'S','o','f','t','w','a','r','e','\\','F','o','n','t','s','\0'};
493 static const WCHAR dpi_value_name
[] = {'L','o','g','P','i','x','e','l','s','\0'};
495 /******************************************************************************
498 * get the dpi from the registry
500 static DWORD
get_dpi( void )
505 if (RegOpenKeyW(HKEY_CURRENT_CONFIG
, dpi_key_name
, &hkey
) == ERROR_SUCCESS
)
507 DWORD type
, size
, new_dpi
;
509 size
= sizeof(new_dpi
);
510 if(RegQueryValueExW(hkey
, dpi_value_name
, NULL
, &type
, (void *)&new_dpi
, &size
) == ERROR_SUCCESS
)
512 if(type
== REG_DWORD
&& new_dpi
!= 0)
521 /***********************************************************************
524 * Increment the reference count of a GDI object.
526 HGDIOBJ
GDI_inc_ref_count( HGDIOBJ handle
)
530 if ((header
= GDI_GetObjPtr( handle
, 0 )))
533 GDI_ReleaseObj( handle
);
541 /***********************************************************************
544 * Decrement the reference count of a GDI object.
546 BOOL
GDI_dec_ref_count( HGDIOBJ handle
)
550 if ((header
= GDI_GetObjPtr( handle
, 0 )))
552 assert( header
->selcount
);
553 if (!--header
->selcount
&& header
->deleted
)
555 /* handle delayed DeleteObject*/
557 GDI_ReleaseObj( handle
);
558 TRACE( "executing delayed DeleteObject for %p\n", handle
);
559 DeleteObject( handle
);
561 else GDI_ReleaseObj( handle
);
563 return header
!= NULL
;
567 /***********************************************************************
570 * GDI initialization.
572 BOOL WINAPI
DllMain( HINSTANCE inst
, DWORD reason
, LPVOID reserved
)
574 LOGFONTW default_gui_font
;
575 const struct DefaultFontInfo
* deffonts
;
578 if (reason
!= DLL_PROCESS_ATTACH
) return TRUE
;
580 DisableThreadLibraryCalls( inst
);
581 LoadLibraryA( "gdi.exe16" );
585 /* create stock objects */
586 stock_objects
[WHITE_BRUSH
] = CreateBrushIndirect( &WhiteBrush
);
587 stock_objects
[LTGRAY_BRUSH
] = CreateBrushIndirect( &LtGrayBrush
);
588 stock_objects
[GRAY_BRUSH
] = CreateBrushIndirect( &GrayBrush
);
589 stock_objects
[DKGRAY_BRUSH
] = CreateBrushIndirect( &DkGrayBrush
);
590 stock_objects
[BLACK_BRUSH
] = CreateBrushIndirect( &BlackBrush
);
591 stock_objects
[NULL_BRUSH
] = CreateBrushIndirect( &NullBrush
);
593 stock_objects
[WHITE_PEN
] = CreatePenIndirect( &WhitePen
);
594 stock_objects
[BLACK_PEN
] = CreatePenIndirect( &BlackPen
);
595 stock_objects
[NULL_PEN
] = CreatePenIndirect( &NullPen
);
597 stock_objects
[DEFAULT_PALETTE
] = PALETTE_Init();
598 stock_objects
[DEFAULT_BITMAP
] = CreateBitmap( 1, 1, 1, 1, NULL
);
600 /* language-independent stock fonts */
601 stock_objects
[OEM_FIXED_FONT
] = CreateFontIndirectW( &OEMFixedFont
);
602 stock_objects
[ANSI_FIXED_FONT
] = CreateFontIndirectW( &AnsiFixedFont
);
603 stock_objects
[ANSI_VAR_FONT
] = CreateFontIndirectW( &AnsiVarFont
);
605 /* language-dependent stock fonts */
606 deffonts
= get_default_fonts(get_default_charset());
607 stock_objects
[SYSTEM_FONT
] = CreateFontIndirectW( &deffonts
->SystemFont
);
608 stock_objects
[DEVICE_DEFAULT_FONT
] = CreateFontIndirectW( &deffonts
->DeviceDefaultFont
);
609 stock_objects
[SYSTEM_FIXED_FONT
] = CreateFontIndirectW( &deffonts
->SystemFixedFont
);
611 /* For the default gui font, we use the lfHeight member in deffonts as a place-holder
612 for the point size so we must convert this into a true height */
613 default_gui_font
= deffonts
->DefaultGuiFont
;
614 default_gui_font
.lfHeight
= -MulDiv(default_gui_font
.lfHeight
, get_dpi(), 72);
615 stock_objects
[DEFAULT_GUI_FONT
] = CreateFontIndirectW( &default_gui_font
);
617 stock_objects
[DC_BRUSH
] = CreateBrushIndirect( &DCBrush
);
618 stock_objects
[DC_PEN
] = CreatePenIndirect( &DCPen
);
620 /* clear the NOSYSTEM bit on all stock objects*/
621 for (i
= 0; i
< NB_STOCK_OBJECTS
; i
++)
623 if (!stock_objects
[i
])
625 if (i
== 9) continue; /* there's no stock object 9 */
626 ERR( "could not create stock object %d\n", i
);
629 __wine_make_gdi_object_system( stock_objects
[i
], TRUE
);
635 #define FIRST_LARGE_HANDLE 16
636 #define MAX_LARGE_HANDLES ((GDI_HEAP_SIZE >> 2) - FIRST_LARGE_HANDLE)
637 static GDIOBJHDR
*large_handles
[MAX_LARGE_HANDLES
];
638 static int next_large_handle
;
640 /***********************************************************************
643 * Allocate a GDI handle for an object, which must have been allocated on the process heap.
645 HGDIOBJ
alloc_gdi_handle( GDIOBJHDR
*obj
, WORD type
, const struct gdi_obj_funcs
*funcs
)
649 /* initialize the object header */
657 EnterCriticalSection( &gdi_section
);
658 for (i
= next_large_handle
+ 1; i
< MAX_LARGE_HANDLES
; i
++)
659 if (!large_handles
[i
]) goto found
;
660 for (i
= 0; i
<= next_large_handle
; i
++)
661 if (!large_handles
[i
]) goto found
;
662 LeaveCriticalSection( &gdi_section
);
666 large_handles
[i
] = obj
;
667 next_large_handle
= i
;
668 LeaveCriticalSection( &gdi_section
);
669 return (HGDIOBJ
)(ULONG_PTR
)((i
+ FIRST_LARGE_HANDLE
) << 2);
673 /***********************************************************************
676 * Free a GDI handle and return a pointer to the object.
678 void *free_gdi_handle( HGDIOBJ handle
)
680 GDIOBJHDR
*object
= NULL
;
683 i
= ((ULONG_PTR
)handle
>> 2) - FIRST_LARGE_HANDLE
;
684 if (i
>= 0 && i
< MAX_LARGE_HANDLES
)
686 EnterCriticalSection( &gdi_section
);
687 object
= large_handles
[i
];
688 large_handles
[i
] = NULL
;
689 LeaveCriticalSection( &gdi_section
);
693 object
->type
= 0; /* mark it as invalid */
694 object
->funcs
= NULL
;
700 /***********************************************************************
703 * Return a pointer to the GDI object associated to the handle.
704 * Return NULL if the object has the wrong magic number.
705 * The object must be released with GDI_ReleaseObj.
707 void *GDI_GetObjPtr( HGDIOBJ handle
, WORD type
)
709 GDIOBJHDR
*ptr
= NULL
;
712 EnterCriticalSection( &gdi_section
);
714 i
= ((UINT_PTR
)handle
>> 2) - FIRST_LARGE_HANDLE
;
715 if (i
>= 0 && i
< MAX_LARGE_HANDLES
)
717 ptr
= large_handles
[i
];
718 if (ptr
&& type
&& ptr
->type
!= type
) ptr
= NULL
;
723 LeaveCriticalSection( &gdi_section
);
724 WARN( "Invalid handle %p\n", handle
);
726 else TRACE("(%p): enter %d\n", handle
, gdi_section
.RecursionCount
);
732 /***********************************************************************
736 void GDI_ReleaseObj( HGDIOBJ handle
)
738 TRACE("(%p): leave %d\n", handle
, gdi_section
.RecursionCount
);
739 LeaveCriticalSection( &gdi_section
);
743 /***********************************************************************
746 void GDI_CheckNotLock(void)
748 if (gdi_section
.OwningThread
== ULongToHandle(GetCurrentThreadId()) && gdi_section
.RecursionCount
)
750 ERR( "BUG: holding GDI lock\n" );
756 /***********************************************************************
757 * DeleteObject (GDI32.@)
759 * Delete a Gdi object.
762 * obj [I] Gdi object to delete
765 * Success: TRUE. If obj was not returned from GetStockObject(), any resources
766 * it consumed are released.
767 * Failure: FALSE, if obj is not a valid Gdi object, or is currently selected
770 BOOL WINAPI
DeleteObject( HGDIOBJ obj
)
772 /* Check if object is valid */
774 struct hdc_list
*hdcs_head
;
775 const struct gdi_obj_funcs
*funcs
;
778 if (HIWORD(obj
)) return FALSE
;
780 if (!(header
= GDI_GetObjPtr( obj
, 0 ))) return FALSE
;
784 TRACE("Preserving system object %p\n", obj
);
785 GDI_ReleaseObj( obj
);
789 while ((hdcs_head
= header
->hdcs
) != NULL
)
791 DC
*dc
= get_dc_ptr(hdcs_head
->hdc
);
793 header
->hdcs
= hdcs_head
->next
;
794 TRACE("hdc %p has interest in %p\n", hdcs_head
->hdc
, obj
);
798 if(dc
->funcs
->pDeleteObject
)
800 GDI_ReleaseObj( obj
); /* release the GDI lock */
801 dc
->funcs
->pDeleteObject( dc
->physDev
, obj
);
802 header
= GDI_GetObjPtr( obj
, 0 ); /* and grab it again */
804 release_dc_ptr( dc
);
806 HeapFree(GetProcessHeap(), 0, hdcs_head
);
807 if (!header
) return FALSE
;
810 if (header
->selcount
)
812 TRACE("delayed for %p because object in use, count %u\n", obj
, header
->selcount
);
813 header
->deleted
= 1; /* mark for delete */
814 GDI_ReleaseObj( obj
);
822 funcs
= header
->funcs
;
823 GDI_ReleaseObj( obj
);
824 if (funcs
&& funcs
->pDeleteObject
)
825 return funcs
->pDeleteObject( obj
);
830 /***********************************************************************
831 * GDI_hdc_using_object
833 * Call this if the dc requires DeleteObject notification
835 BOOL
GDI_hdc_using_object(HGDIOBJ obj
, HDC hdc
)
838 struct hdc_list
**pphdc
;
840 TRACE("obj %p hdc %p\n", obj
, hdc
);
842 if (!(header
= GDI_GetObjPtr( obj
, 0 ))) return FALSE
;
850 for(pphdc
= &header
->hdcs
; *pphdc
; pphdc
= &(*pphdc
)->next
)
851 if((*pphdc
)->hdc
== hdc
)
855 *pphdc
= HeapAlloc(GetProcessHeap(), 0, sizeof(**pphdc
));
857 (*pphdc
)->next
= NULL
;
864 /***********************************************************************
865 * GDI_hdc_not_using_object
868 BOOL
GDI_hdc_not_using_object(HGDIOBJ obj
, HDC hdc
)
871 struct hdc_list
*phdc
, **prev
;
873 TRACE("obj %p hdc %p\n", obj
, hdc
);
875 if (!(header
= GDI_GetObjPtr( obj
, 0 ))) return FALSE
;
884 prev
= &header
->hdcs
;
887 if(phdc
->hdc
== hdc
) {
889 HeapFree(GetProcessHeap(), 0, phdc
);
901 /***********************************************************************
902 * GetStockObject (GDI32.@)
904 HGDIOBJ WINAPI
GetStockObject( INT obj
)
907 if ((obj
< 0) || (obj
>= NB_STOCK_OBJECTS
)) return 0;
908 ret
= stock_objects
[obj
];
909 TRACE("returning %p\n", ret
);
914 /***********************************************************************
915 * GetObjectA (GDI32.@)
917 INT WINAPI
GetObjectA( HGDIOBJ handle
, INT count
, LPVOID buffer
)
919 const struct gdi_obj_funcs
*funcs
;
923 TRACE("%p %d %p\n", handle
, count
, buffer
);
925 if (!(ptr
= GDI_GetObjPtr( handle
, 0 ))) return 0;
927 GDI_ReleaseObj( handle
);
929 if (funcs
&& funcs
->pGetObjectA
)
930 result
= funcs
->pGetObjectA( handle
, count
, buffer
);
932 SetLastError( ERROR_INVALID_HANDLE
);
937 /***********************************************************************
938 * GetObjectW (GDI32.@)
940 INT WINAPI
GetObjectW( HGDIOBJ handle
, INT count
, LPVOID buffer
)
942 const struct gdi_obj_funcs
*funcs
;
945 TRACE("%p %d %p\n", handle
, count
, buffer
);
947 if (!(ptr
= GDI_GetObjPtr( handle
, 0 ))) return 0;
949 GDI_ReleaseObj( handle
);
951 if (funcs
&& funcs
->pGetObjectW
)
952 result
= funcs
->pGetObjectW( handle
, count
, buffer
);
954 SetLastError( ERROR_INVALID_HANDLE
);
959 /***********************************************************************
960 * GetObjectType (GDI32.@)
962 DWORD WINAPI
GetObjectType( HGDIOBJ handle
)
967 if (!(ptr
= GDI_GetObjPtr( handle
, 0 )))
969 SetLastError( ERROR_INVALID_HANDLE
);
973 GDI_ReleaseObj( handle
);
974 TRACE("%p -> %u\n", handle
, result
);
978 /***********************************************************************
979 * GetCurrentObject (GDI32.@)
981 * Get the currently selected object of a given type in a device context.
984 * hdc [I] Device context to get the current object from
985 * type [I] Type of current object to get (OBJ_* defines from "wingdi.h")
988 * Success: The current object of the given type selected in hdc.
989 * Failure: A NULL handle.
992 * - only the following object types are supported:
999 HGDIOBJ WINAPI
GetCurrentObject(HDC hdc
,UINT type
)
1002 DC
* dc
= get_dc_ptr( hdc
);
1007 case OBJ_EXTPEN
: /* fall through */
1008 case OBJ_PEN
: ret
= dc
->hPen
; break;
1009 case OBJ_BRUSH
: ret
= dc
->hBrush
; break;
1010 case OBJ_PAL
: ret
= dc
->hPalette
; break;
1011 case OBJ_FONT
: ret
= dc
->hFont
; break;
1012 case OBJ_BITMAP
: ret
= dc
->hBitmap
; break;
1014 /* tests show that OBJ_REGION is explicitly ignored */
1015 case OBJ_REGION
: break;
1017 /* the SDK only mentions those above */
1018 FIXME("(%p,%d): unknown type.\n",hdc
,type
);
1021 release_dc_ptr( dc
);
1026 /***********************************************************************
1027 * SelectObject (GDI32.@)
1029 * Select a Gdi object into a device context.
1032 * hdc [I] Device context to associate the object with
1033 * hObj [I] Gdi object to associate with hdc
1036 * Success: A non-NULL handle representing the previously selected object of
1037 * the same type as hObj.
1038 * Failure: A NULL object. If hdc is invalid, GetLastError() returns ERROR_INVALID_HANDLE.
1039 * if hObj is not a valid object handle, no last error is set. In either
1040 * case, hdc is unaffected by the call.
1042 HGDIOBJ WINAPI
SelectObject( HDC hdc
, HGDIOBJ hObj
)
1047 TRACE( "(%p,%p)\n", hdc
, hObj
);
1049 header
= GDI_GetObjPtr( hObj
, 0 );
1052 const struct gdi_obj_funcs
*funcs
= header
->funcs
;
1053 GDI_ReleaseObj( hObj
);
1054 if (funcs
&& funcs
->pSelectObject
) ret
= funcs
->pSelectObject( hObj
, hdc
);
1060 /***********************************************************************
1061 * UnrealizeObject (GDI32.@)
1063 BOOL WINAPI
UnrealizeObject( HGDIOBJ obj
)
1065 BOOL result
= FALSE
;
1066 GDIOBJHDR
* header
= GDI_GetObjPtr( obj
, 0 );
1070 const struct gdi_obj_funcs
*funcs
= header
->funcs
;
1072 GDI_ReleaseObj( obj
);
1073 if (funcs
&& funcs
->pUnrealizeObject
)
1074 result
= header
->funcs
->pUnrealizeObject( obj
);
1082 /* Solid colors to enumerate */
1083 static const COLORREF solid_colors
[] =
1084 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
1085 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
1086 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
1087 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
1088 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
1089 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
1090 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
1091 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
1095 /***********************************************************************
1096 * EnumObjects (GDI32.@)
1098 INT WINAPI
EnumObjects( HDC hdc
, INT nObjType
,
1099 GOBJENUMPROC lpEnumFunc
, LPARAM lParam
)
1106 TRACE("%p %d %p %08lx\n", hdc
, nObjType
, lpEnumFunc
, lParam
);
1110 /* Enumerate solid pens */
1111 for (i
= 0; i
< sizeof(solid_colors
)/sizeof(solid_colors
[0]); i
++)
1113 pen
.lopnStyle
= PS_SOLID
;
1114 pen
.lopnWidth
.x
= 1;
1115 pen
.lopnWidth
.y
= 0;
1116 pen
.lopnColor
= solid_colors
[i
];
1117 retval
= lpEnumFunc( &pen
, lParam
);
1118 TRACE("solid pen %08x, ret=%d\n",
1119 solid_colors
[i
], retval
);
1125 /* Enumerate solid brushes */
1126 for (i
= 0; i
< sizeof(solid_colors
)/sizeof(solid_colors
[0]); i
++)
1128 brush
.lbStyle
= BS_SOLID
;
1129 brush
.lbColor
= solid_colors
[i
];
1131 retval
= lpEnumFunc( &brush
, lParam
);
1132 TRACE("solid brush %08x, ret=%d\n",
1133 solid_colors
[i
], retval
);
1137 /* Now enumerate hatched brushes */
1138 if (retval
) for (i
= HS_HORIZONTAL
; i
<= HS_DIAGCROSS
; i
++)
1140 brush
.lbStyle
= BS_HATCHED
;
1141 brush
.lbColor
= RGB(0,0,0);
1143 retval
= lpEnumFunc( &brush
, lParam
);
1144 TRACE("hatched brush %d, ret=%d\n",
1151 /* FIXME: implement Win32 types */
1152 WARN("(%d): Invalid type\n", nObjType
);
1159 /***********************************************************************
1160 * SetObjectOwner (GDI32.@)
1162 void WINAPI
SetObjectOwner( HGDIOBJ handle
, HANDLE owner
)
1168 /***********************************************************************
1169 * GdiFlush (GDI32.@)
1171 BOOL WINAPI
GdiFlush(void)
1173 return TRUE
; /* FIXME */
1177 /***********************************************************************
1178 * GdiGetBatchLimit (GDI32.@)
1180 DWORD WINAPI
GdiGetBatchLimit(void)
1182 return 1; /* FIXME */
1186 /***********************************************************************
1187 * GdiSetBatchLimit (GDI32.@)
1189 DWORD WINAPI
GdiSetBatchLimit( DWORD limit
)
1191 return 1; /* FIXME */
1195 /*******************************************************************
1196 * GetColorAdjustment [GDI32.@]
1200 BOOL WINAPI
GetColorAdjustment(HDC hdc
, LPCOLORADJUSTMENT lpca
)
1202 FIXME("GetColorAdjustment, stub\n");
1206 /*******************************************************************
1207 * GdiComment [GDI32.@]
1211 BOOL WINAPI
GdiComment(HDC hdc
, UINT cbSize
, const BYTE
*lpData
)
1213 DC
*dc
= get_dc_ptr(hdc
);
1217 if (dc
->funcs
->pGdiComment
)
1218 ret
= dc
->funcs
->pGdiComment( dc
->physDev
, cbSize
, lpData
);
1219 release_dc_ptr( dc
);
1224 /*******************************************************************
1225 * SetColorAdjustment [GDI32.@]
1229 BOOL WINAPI
SetColorAdjustment(HDC hdc
, const COLORADJUSTMENT
* lpca
)
1231 FIXME("SetColorAdjustment, stub\n");