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
35 #include "gdi_private.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(gdi
);
40 #define HGDIOBJ_32(h16) ((HGDIOBJ)(ULONG_PTR)(h16))
42 #define GDI_HEAP_SIZE 0xffe0
44 /***********************************************************************
48 static const LOGBRUSH WhiteBrush
= { BS_SOLID
, RGB(255,255,255), 0 };
49 static const LOGBRUSH BlackBrush
= { BS_SOLID
, RGB(0,0,0), 0 };
50 static const LOGBRUSH NullBrush
= { BS_NULL
, 0, 0 };
52 static const LOGBRUSH LtGrayBrush
= { BS_SOLID
, RGB(192,192,192), 0 };
53 static const LOGBRUSH GrayBrush
= { BS_SOLID
, RGB(128,128,128), 0 };
54 static const LOGBRUSH DkGrayBrush
= { BS_SOLID
, RGB(64,64,64), 0 };
56 static const LOGPEN WhitePen
= { PS_SOLID
, { 0, 0 }, RGB(255,255,255) };
57 static const LOGPEN BlackPen
= { PS_SOLID
, { 0, 0 }, RGB(0,0,0) };
58 static const LOGPEN NullPen
= { PS_NULL
, { 0, 0 }, 0 };
60 static const LOGBRUSH DCBrush
= { BS_SOLID
, RGB(255,255,255), 0 };
61 static const LOGPEN DCPen
= { PS_SOLID
, { 0, 0 }, RGB(0,0,0) };
63 /* reserve one extra entry for the stock default bitmap */
64 /* this is what Windows does too */
65 #define NB_STOCK_OBJECTS (STOCK_LAST+2)
67 static HGDIOBJ stock_objects
[NB_STOCK_OBJECTS
];
69 static SYSLEVEL GDI_level
;
70 static CRITICAL_SECTION_DEBUG critsect_debug
=
72 0, 0, &GDI_level
.crst
,
73 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
74 0, 0, { (DWORD_PTR
)(__FILE__
": GDI_level") }
76 static SYSLEVEL GDI_level
= { { &critsect_debug
, -1, 0, 0, 0, 0 }, 3 };
79 /****************************************************************************
81 * language-independent stock fonts
85 static const LOGFONTW OEMFixedFont
=
86 { 12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, OEM_CHARSET
,
87 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, {'\0'} };
89 static const LOGFONTW AnsiFixedFont
=
90 { 12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
91 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, {'\0'} };
93 static const LOGFONTW AnsiVarFont
=
94 { 12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
95 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
96 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'} };
98 /******************************************************************************
100 * language-dependent stock fonts
102 * 'ANSI' charset and 'DEFAULT' charset is not same.
103 * The chars in CP_ACP should be drawn with 'DEFAULT' charset.
104 * 'ANSI' charset seems to be identical with ISO-8859-1.
105 * 'DEFAULT' charset is a language-dependent charset.
107 * 'System' font seems to be an alias for language-dependent font.
111 * language-dependent stock fonts for all known charsets
112 * please see TranslateCharsetInfo (dlls/gdi/font.c) and
113 * CharsetBindingInfo (dlls/x11drv/xfont.c),
114 * and modify entries for your language if needed.
116 struct DefaultFontInfo
120 LOGFONTW DeviceDefaultFont
;
121 LOGFONTW SystemFixedFont
;
122 LOGFONTW DefaultGuiFont
; /* Note for this font the lfHeight member should be the point size */
125 static const struct DefaultFontInfo default_fonts
[] =
129 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
130 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
131 {'S','y','s','t','e','m','\0'}
133 { /* Device Default */
134 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
135 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
139 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
140 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
143 { /* DefaultGuiFont */
144 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
145 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
146 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
149 { EASTEUROPE_CHARSET
,
151 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, EASTEUROPE_CHARSET
,
152 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
153 {'S','y','s','t','e','m','\0'}
155 { /* Device Default */
156 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, EASTEUROPE_CHARSET
,
157 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
161 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, EASTEUROPE_CHARSET
,
162 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
165 { /* DefaultGuiFont */
166 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, EASTEUROPE_CHARSET
,
167 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
168 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
173 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, RUSSIAN_CHARSET
,
174 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
175 {'S','y','s','t','e','m','\0'}
177 { /* Device Default */
178 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, RUSSIAN_CHARSET
,
179 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
183 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, RUSSIAN_CHARSET
,
184 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
187 { /* DefaultGuiFont */
188 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, RUSSIAN_CHARSET
,
189 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
190 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
195 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GREEK_CHARSET
,
196 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
197 {'S','y','s','t','e','m','\0'}
199 { /* Device Default */
200 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GREEK_CHARSET
,
201 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
205 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GREEK_CHARSET
,
206 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
209 { /* DefaultGuiFont */
210 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GREEK_CHARSET
,
211 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
212 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
217 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, TURKISH_CHARSET
,
218 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
219 {'S','y','s','t','e','m','\0'}
221 { /* Device Default */
222 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, TURKISH_CHARSET
,
223 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
227 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, TURKISH_CHARSET
,
228 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
231 { /* DefaultGuiFont */
232 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, TURKISH_CHARSET
,
233 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
234 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
239 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HEBREW_CHARSET
,
240 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
241 {'S','y','s','t','e','m','\0'}
243 { /* Device Default */
244 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HEBREW_CHARSET
,
245 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
249 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HEBREW_CHARSET
,
250 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
253 { /* DefaultGuiFont */
254 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HEBREW_CHARSET
,
255 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
256 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
261 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ARABIC_CHARSET
,
262 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
263 {'S','y','s','t','e','m','\0'}
265 { /* Device Default */
266 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ARABIC_CHARSET
,
267 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
271 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ARABIC_CHARSET
,
272 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
275 { /* DefaultGuiFont */
276 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ARABIC_CHARSET
,
277 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
278 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
283 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, BALTIC_CHARSET
,
284 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
285 {'S','y','s','t','e','m','\0'}
287 { /* Device Default */
288 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, BALTIC_CHARSET
,
289 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
293 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, BALTIC_CHARSET
,
294 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
297 { /* DefaultGuiFont */
298 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, BALTIC_CHARSET
,
299 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
300 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
305 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, THAI_CHARSET
,
306 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
307 {'S','y','s','t','e','m','\0'}
309 { /* Device Default */
310 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, THAI_CHARSET
,
311 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
315 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, THAI_CHARSET
,
316 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
319 { /* DefaultGuiFont */
320 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, THAI_CHARSET
,
321 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
322 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
327 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, SHIFTJIS_CHARSET
,
328 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
329 {'S','y','s','t','e','m','\0'}
331 { /* Device Default */
332 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, SHIFTJIS_CHARSET
,
333 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
337 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, SHIFTJIS_CHARSET
,
338 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
341 { /* DefaultGuiFont */
342 9, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, SHIFTJIS_CHARSET
,
343 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
344 {'M','S',' ','U','I',' ','G','o','t','h','i','c','\0'}
349 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GB2312_CHARSET
,
350 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
351 {'S','y','s','t','e','m','\0'}
353 { /* Device Default */
354 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GB2312_CHARSET
,
355 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
359 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GB2312_CHARSET
,
360 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
363 { /* DefaultGuiFont */
364 9, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GB2312_CHARSET
,
365 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
366 {'S','i','m','S','u','n','\0'}
371 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HANGEUL_CHARSET
,
372 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
373 {'S','y','s','t','e','m','\0'}
375 { /* Device Default */
376 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HANGEUL_CHARSET
,
377 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
381 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HANGEUL_CHARSET
,
382 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
385 { /* DefaultGuiFont */
386 9, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HANGEUL_CHARSET
,
387 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
388 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
391 { CHINESEBIG5_CHARSET
,
393 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, CHINESEBIG5_CHARSET
,
394 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
395 {'S','y','s','t','e','m','\0'}
397 { /* Device Default */
398 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, CHINESEBIG5_CHARSET
,
399 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
403 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, CHINESEBIG5_CHARSET
,
404 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
407 { /* DefaultGuiFont */
408 9, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, CHINESEBIG5_CHARSET
,
409 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
410 {'P','M','i','n','g','L','i','U','\0'}
415 16, 7, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, JOHAB_CHARSET
,
416 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
417 {'S','y','s','t','e','m','\0'}
419 { /* Device Default */
420 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, JOHAB_CHARSET
,
421 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
425 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, JOHAB_CHARSET
,
426 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
,
429 { /* DefaultGuiFont */
430 8, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, JOHAB_CHARSET
,
431 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
,
432 {'M','S',' ','S','h','e','l','l',' ','D','l','g','\0'}
438 /*************************************************************************
439 * __wine_make_gdi_object_system (GDI32.@)
441 * USER has to tell GDI that its system brushes and pens are non-deletable.
442 * For a description of the GDI object magics and their flags,
443 * see "Undocumented Windows" (wrong about the OBJECT_NOSYSTEM flag, though).
445 void __wine_make_gdi_object_system( HGDIOBJ handle
, BOOL set
)
447 GDIOBJHDR
*ptr
= GDI_GetObjPtr( handle
, MAGIC_DONTCARE
);
449 /* touch the "system" bit of the wMagic field of a GDIOBJHDR */
451 ptr
->wMagic
&= ~OBJECT_NOSYSTEM
;
453 ptr
->wMagic
|= OBJECT_NOSYSTEM
;
455 GDI_ReleaseObj( handle
);
458 /******************************************************************************
461 static const struct DefaultFontInfo
* get_default_fonts(UINT charset
)
465 for(n
=0;n
<(sizeof(default_fonts
)/sizeof(default_fonts
[0]));n
++)
467 if ( default_fonts
[n
].charset
== charset
)
468 return &default_fonts
[n
];
471 FIXME( "unhandled charset 0x%08x - use ANSI_CHARSET for default stock objects\n", charset
);
472 return &default_fonts
[0];
476 /******************************************************************************
477 * get_default_charset (internal)
479 * get the language-dependent charset that can handle CP_ACP correctly.
481 static UINT
get_default_charset( void )
487 csi
.ciCharset
= ANSI_CHARSET
;
488 if ( !TranslateCharsetInfo( ULongToPtr(uACP
), &csi
, TCI_SRCCODEPAGE
) )
490 FIXME( "unhandled codepage %u - use ANSI_CHARSET for default stock objects\n", uACP
);
494 return csi
.ciCharset
;
497 static const WCHAR dpi_key_name
[] = {'S','o','f','t','w','a','r','e','\\','F','o','n','t','s','\0'};
498 static const WCHAR dpi_value_name
[] = {'L','o','g','P','i','x','e','l','s','\0'};
500 /******************************************************************************
503 * get the dpi from the registry
505 static DWORD
get_dpi( void )
510 if (RegOpenKeyW(HKEY_CURRENT_CONFIG
, dpi_key_name
, &hkey
) == ERROR_SUCCESS
)
512 DWORD type
, size
, new_dpi
;
514 size
= sizeof(new_dpi
);
515 if(RegQueryValueExW(hkey
, dpi_value_name
, NULL
, &type
, (void *)&new_dpi
, &size
) == ERROR_SUCCESS
)
517 if(type
== REG_DWORD
&& new_dpi
!= 0)
526 /***********************************************************************
529 * Increment the reference count of a GDI object.
531 BOOL
GDI_inc_ref_count( HGDIOBJ handle
)
535 if ((header
= GDI_GetObjPtr( handle
, MAGIC_DONTCARE
)))
538 GDI_ReleaseObj( handle
);
540 return header
!= NULL
;
544 /***********************************************************************
547 * Decrement the reference count of a GDI object.
549 BOOL
GDI_dec_ref_count( HGDIOBJ handle
)
553 if ((header
= GDI_GetObjPtr( handle
, MAGIC_DONTCARE
)))
555 if (header
->dwCount
) header
->dwCount
--;
556 if (header
->dwCount
!= 0x80000000) GDI_ReleaseObj( handle
);
559 /* handle delayed DeleteObject*/
561 GDI_ReleaseObj( handle
);
562 TRACE( "executing delayed DeleteObject for %p\n", handle
);
563 DeleteObject( handle
);
566 return header
!= NULL
;
570 /***********************************************************************
573 * GDI initialization.
577 LOGFONTW default_gui_font
;
578 const struct DefaultFontInfo
* deffonts
;
583 /* create stock objects */
584 stock_objects
[WHITE_BRUSH
] = CreateBrushIndirect( &WhiteBrush
);
585 stock_objects
[LTGRAY_BRUSH
] = CreateBrushIndirect( &LtGrayBrush
);
586 stock_objects
[GRAY_BRUSH
] = CreateBrushIndirect( &GrayBrush
);
587 stock_objects
[DKGRAY_BRUSH
] = CreateBrushIndirect( &DkGrayBrush
);
588 stock_objects
[BLACK_BRUSH
] = CreateBrushIndirect( &BlackBrush
);
589 stock_objects
[NULL_BRUSH
] = CreateBrushIndirect( &NullBrush
);
591 stock_objects
[WHITE_PEN
] = CreatePenIndirect( &WhitePen
);
592 stock_objects
[BLACK_PEN
] = CreatePenIndirect( &BlackPen
);
593 stock_objects
[NULL_PEN
] = CreatePenIndirect( &NullPen
);
595 stock_objects
[DEFAULT_PALETTE
] = PALETTE_Init();
596 stock_objects
[DEFAULT_BITMAP
] = CreateBitmap( 1, 1, 1, 1, NULL
);
598 /* language-independent stock fonts */
599 stock_objects
[OEM_FIXED_FONT
] = CreateFontIndirectW( &OEMFixedFont
);
600 stock_objects
[ANSI_FIXED_FONT
] = CreateFontIndirectW( &AnsiFixedFont
);
601 stock_objects
[ANSI_VAR_FONT
] = CreateFontIndirectW( &AnsiVarFont
);
603 /* language-dependent stock fonts */
604 deffonts
= get_default_fonts(get_default_charset());
605 stock_objects
[SYSTEM_FONT
] = CreateFontIndirectW( &deffonts
->SystemFont
);
606 stock_objects
[DEVICE_DEFAULT_FONT
] = CreateFontIndirectW( &deffonts
->DeviceDefaultFont
);
607 stock_objects
[SYSTEM_FIXED_FONT
] = CreateFontIndirectW( &deffonts
->SystemFixedFont
);
609 /* For the default gui font, we use the lfHeight member in deffonts as a place-holder
610 for the point size so we must convert this into a true height */
611 default_gui_font
= deffonts
->DefaultGuiFont
;
612 default_gui_font
.lfHeight
= -MulDiv(default_gui_font
.lfHeight
, get_dpi(), 72);
613 stock_objects
[DEFAULT_GUI_FONT
] = CreateFontIndirectW( &default_gui_font
);
615 stock_objects
[DC_BRUSH
] = CreateBrushIndirect( &DCBrush
);
616 stock_objects
[DC_PEN
] = CreatePenIndirect( &DCPen
);
618 /* clear the NOSYSTEM bit on all stock objects*/
619 for (i
= 0; i
< NB_STOCK_OBJECTS
; i
++)
621 if (!stock_objects
[i
])
623 if (i
== 9) continue; /* there's no stock object 9 */
624 ERR( "could not create stock object %d\n", i
);
627 __wine_make_gdi_object_system( stock_objects
[i
], TRUE
);
633 #define FIRST_LARGE_HANDLE 16
634 #define MAX_LARGE_HANDLES ((GDI_HEAP_SIZE >> 2) - FIRST_LARGE_HANDLE)
635 static GDIOBJHDR
*large_handles
[MAX_LARGE_HANDLES
];
636 static int next_large_handle
;
638 /***********************************************************************
641 * Allocate a GDI handle from the large heap. Helper for GDI_AllocObject
643 static inline GDIOBJHDR
*alloc_large_heap( WORD size
, HGDIOBJ
*handle
)
648 for (i
= next_large_handle
+ 1; i
< MAX_LARGE_HANDLES
; i
++)
649 if (!large_handles
[i
]) goto found
;
650 for (i
= 0; i
<= next_large_handle
; i
++)
651 if (!large_handles
[i
]) goto found
;
656 if ((obj
= HeapAlloc( GetProcessHeap(), 0, size
)))
658 large_handles
[i
] = obj
;
659 *handle
= (HGDIOBJ
)(ULONG_PTR
)((i
+ FIRST_LARGE_HANDLE
) << 2);
660 next_large_handle
= i
;
666 /***********************************************************************
669 void *GDI_AllocObject( WORD size
, WORD magic
, HGDIOBJ
*handle
, const struct gdi_obj_funcs
*funcs
)
671 GDIOBJHDR
*obj
= NULL
;
673 _EnterSysLevel( &GDI_level
);
674 if (!(obj
= alloc_large_heap( size
, handle
))) goto error
;
676 obj
->wMagic
= magic
|OBJECT_NOSYSTEM
;
681 TRACE("(%p): enter %d\n", *handle
, GDI_level
.crst
.RecursionCount
);
685 _LeaveSysLevel( &GDI_level
);
691 /***********************************************************************
694 * The object ptr must have been obtained with GDI_GetObjPtr.
695 * The new pointer must be released with GDI_ReleaseObj.
697 void *GDI_ReallocObject( WORD size
, HGDIOBJ handle
, void *object
)
699 void *new_ptr
= NULL
;
702 i
= ((ULONG_PTR
)handle
>> 2) - FIRST_LARGE_HANDLE
;
703 if (i
>= 0 && i
< MAX_LARGE_HANDLES
&& large_handles
[i
])
705 new_ptr
= HeapReAlloc( GetProcessHeap(), 0, large_handles
[i
], size
);
706 if (new_ptr
) large_handles
[i
] = new_ptr
;
708 else ERR( "Invalid handle %p\n", handle
);
711 TRACE("(%p): leave %d\n", handle
, GDI_level
.crst
.RecursionCount
);
712 _LeaveSysLevel( &GDI_level
);
718 /***********************************************************************
721 BOOL
GDI_FreeObject( HGDIOBJ handle
, void *ptr
)
723 GDIOBJHDR
*object
= ptr
;
726 object
->wMagic
= 0; /* Mark it as invalid */
727 object
->funcs
= NULL
;
728 i
= ((ULONG_PTR
)handle
>> 2) - FIRST_LARGE_HANDLE
;
729 if (i
>= 0 && i
< MAX_LARGE_HANDLES
)
731 HeapFree( GetProcessHeap(), 0, large_handles
[i
] );
732 large_handles
[i
] = NULL
;
734 else ERR( "Invalid handle %p\n", handle
);
735 TRACE("(%p): leave %d\n", handle
, GDI_level
.crst
.RecursionCount
);
736 _LeaveSysLevel( &GDI_level
);
741 /***********************************************************************
744 * Return a pointer to the GDI object associated to the handle.
745 * Return NULL if the object has the wrong magic number.
746 * The object must be released with GDI_ReleaseObj.
748 void *GDI_GetObjPtr( HGDIOBJ handle
, WORD magic
)
750 GDIOBJHDR
*ptr
= NULL
;
753 _EnterSysLevel( &GDI_level
);
755 i
= ((UINT_PTR
)handle
>> 2) - FIRST_LARGE_HANDLE
;
756 if (i
>= 0 && i
< MAX_LARGE_HANDLES
)
758 ptr
= large_handles
[i
];
759 if (ptr
&& (magic
!= MAGIC_DONTCARE
) && (GDIMAGIC(ptr
->wMagic
) != magic
)) ptr
= NULL
;
764 _LeaveSysLevel( &GDI_level
);
765 WARN( "Invalid handle %p\n", handle
);
767 else TRACE("(%p): enter %d\n", handle
, GDI_level
.crst
.RecursionCount
);
773 /***********************************************************************
777 void GDI_ReleaseObj( HGDIOBJ handle
)
779 TRACE("(%p): leave %d\n", handle
, GDI_level
.crst
.RecursionCount
);
780 _LeaveSysLevel( &GDI_level
);
784 /***********************************************************************
787 void GDI_CheckNotLock(void)
789 _CheckNotSysLevel( &GDI_level
);
793 /***********************************************************************
794 * DeleteObject (GDI32.@)
796 * Delete a Gdi object.
799 * obj [I] Gdi object to delete
802 * Success: TRUE. If obj was not returned from GetStockObject(), any resources
803 * it consumed are released.
804 * Failure: FALSE, if obj is not a valid Gdi object, or is currently selected
807 BOOL WINAPI
DeleteObject( HGDIOBJ obj
)
809 /* Check if object is valid */
812 if (HIWORD(obj
)) return FALSE
;
814 if (!(header
= GDI_GetObjPtr( obj
, MAGIC_DONTCARE
))) return FALSE
;
816 if (!(header
->wMagic
& OBJECT_NOSYSTEM
)
817 && (header
->wMagic
>= FIRST_MAGIC
) && (header
->wMagic
<= LAST_MAGIC
))
819 TRACE("Preserving system object %p\n", obj
);
820 GDI_ReleaseObj( obj
);
826 DC
*dc
= get_dc_ptr(header
->hdcs
->hdc
);
827 struct hdc_list
*tmp
;
829 TRACE("hdc %p has interest in %p\n", header
->hdcs
->hdc
, obj
);
832 if(dc
->funcs
->pDeleteObject
)
833 dc
->funcs
->pDeleteObject( dc
->physDev
, obj
);
834 release_dc_ptr( dc
);
837 header
->hdcs
= header
->hdcs
->next
;
838 HeapFree(GetProcessHeap(), 0, tmp
);
843 TRACE("delayed for %p because object in use, count %d\n", obj
, header
->dwCount
);
844 header
->dwCount
|= 0x80000000; /* mark for delete */
845 GDI_ReleaseObj( obj
);
853 if (header
->funcs
&& header
->funcs
->pDeleteObject
)
854 return header
->funcs
->pDeleteObject( obj
, header
);
856 GDI_ReleaseObj( obj
);
860 /***********************************************************************
861 * GDI_hdc_using_object
863 * Call this if the dc requires DeleteObject notification
865 BOOL
GDI_hdc_using_object(HGDIOBJ obj
, HDC hdc
)
868 struct hdc_list
**pphdc
;
870 TRACE("obj %p hdc %p\n", obj
, hdc
);
872 if (!(header
= GDI_GetObjPtr( obj
, MAGIC_DONTCARE
))) return FALSE
;
874 if (!(header
->wMagic
& OBJECT_NOSYSTEM
) &&
875 (header
->wMagic
>= FIRST_MAGIC
) && (header
->wMagic
<= LAST_MAGIC
))
881 for(pphdc
= &header
->hdcs
; *pphdc
; pphdc
= &(*pphdc
)->next
)
882 if((*pphdc
)->hdc
== hdc
)
886 *pphdc
= HeapAlloc(GetProcessHeap(), 0, sizeof(**pphdc
));
888 (*pphdc
)->next
= NULL
;
895 /***********************************************************************
896 * GDI_hdc_not_using_object
899 BOOL
GDI_hdc_not_using_object(HGDIOBJ obj
, HDC hdc
)
902 struct hdc_list
*phdc
, **prev
;
904 TRACE("obj %p hdc %p\n", obj
, hdc
);
906 if (!(header
= GDI_GetObjPtr( obj
, MAGIC_DONTCARE
))) return FALSE
;
908 if (!(header
->wMagic
& OBJECT_NOSYSTEM
) &&
909 (header
->wMagic
>= FIRST_MAGIC
) && (header
->wMagic
<= LAST_MAGIC
))
916 prev
= &header
->hdcs
;
919 if(phdc
->hdc
== hdc
) {
921 HeapFree(GetProcessHeap(), 0, phdc
);
933 /***********************************************************************
934 * GetStockObject (GDI32.@)
936 HGDIOBJ WINAPI
GetStockObject( INT obj
)
939 if ((obj
< 0) || (obj
>= NB_STOCK_OBJECTS
)) return 0;
940 ret
= stock_objects
[obj
];
941 TRACE("returning %p\n", ret
);
946 /***********************************************************************
947 * GetObjectA (GDI32.@)
949 INT WINAPI
GetObjectA( HGDIOBJ handle
, INT count
, LPVOID buffer
)
953 TRACE("%p %d %p\n", handle
, count
, buffer
);
955 if (!(ptr
= GDI_GetObjPtr( handle
, MAGIC_DONTCARE
))) return 0;
957 if (ptr
->funcs
&& ptr
->funcs
->pGetObjectA
)
958 result
= ptr
->funcs
->pGetObjectA( handle
, ptr
, count
, buffer
);
960 SetLastError( ERROR_INVALID_HANDLE
);
962 GDI_ReleaseObj( handle
);
966 /***********************************************************************
967 * GetObjectW (GDI32.@)
969 INT WINAPI
GetObjectW( HGDIOBJ handle
, INT count
, LPVOID buffer
)
973 TRACE("%p %d %p\n", handle
, count
, buffer
);
975 if (!(ptr
= GDI_GetObjPtr( handle
, MAGIC_DONTCARE
))) return 0;
977 if (ptr
->funcs
&& ptr
->funcs
->pGetObjectW
)
978 result
= ptr
->funcs
->pGetObjectW( handle
, ptr
, count
, buffer
);
980 SetLastError( ERROR_INVALID_HANDLE
);
982 GDI_ReleaseObj( handle
);
986 /***********************************************************************
987 * GetObjectType (GDI32.@)
989 DWORD WINAPI
GetObjectType( HGDIOBJ handle
)
993 TRACE("%p\n", handle
);
995 if (!(ptr
= GDI_GetObjPtr( handle
, MAGIC_DONTCARE
)))
997 SetLastError( ERROR_INVALID_HANDLE
);
1001 switch(GDIMAGIC(ptr
->wMagic
))
1007 result
= OBJ_EXTPEN
;
1013 result
= OBJ_BITMAP
;
1022 result
= OBJ_REGION
;
1028 result
= OBJ_METADC
;
1030 case METAFILE_MAGIC
:
1031 result
= OBJ_METAFILE
;
1033 case METAFILE_DC_MAGIC
:
1034 result
= OBJ_METADC
;
1036 case ENHMETAFILE_MAGIC
:
1037 result
= OBJ_ENHMETAFILE
;
1039 case ENHMETAFILE_DC_MAGIC
:
1040 result
= OBJ_ENHMETADC
;
1042 case MEMORY_DC_MAGIC
:
1046 FIXME("Magic %04x not implemented\n", GDIMAGIC(ptr
->wMagic
) );
1049 GDI_ReleaseObj( handle
);
1053 /***********************************************************************
1054 * GetCurrentObject (GDI32.@)
1056 * Get the currently selected object of a given type in a device context.
1059 * hdc [I] Device context to get the current object from
1060 * type [I] Type of current object to get (OBJ_* defines from "wingdi.h")
1063 * Success: The current object of the given type selected in hdc.
1064 * Failure: A NULL handle.
1067 * - only the following object types are supported:
1074 HGDIOBJ WINAPI
GetCurrentObject(HDC hdc
,UINT type
)
1077 DC
* dc
= get_dc_ptr( hdc
);
1082 case OBJ_EXTPEN
: /* fall through */
1083 case OBJ_PEN
: ret
= dc
->hPen
; break;
1084 case OBJ_BRUSH
: ret
= dc
->hBrush
; break;
1085 case OBJ_PAL
: ret
= dc
->hPalette
; break;
1086 case OBJ_FONT
: ret
= dc
->hFont
; break;
1087 case OBJ_BITMAP
: ret
= dc
->hBitmap
; break;
1089 /* tests show that OBJ_REGION is explicitly ignored */
1090 case OBJ_REGION
: break;
1092 /* the SDK only mentions those above */
1093 FIXME("(%p,%d): unknown type.\n",hdc
,type
);
1096 release_dc_ptr( dc
);
1101 /***********************************************************************
1102 * SelectObject (GDI32.@)
1104 * Select a Gdi object into a device context.
1107 * hdc [I] Device context to associate the object with
1108 * hObj [I] Gdi object to associate with hdc
1111 * Success: A non-NULL handle representing the previously selected object of
1112 * the same type as hObj.
1113 * Failure: A NULL object. If hdc is invalid, GetLastError() returns ERROR_INVALID_HANDLE.
1114 * if hObj is not a valid object handle, no last error is set. In either
1115 * case, hdc is unaffected by the call.
1117 HGDIOBJ WINAPI
SelectObject( HDC hdc
, HGDIOBJ hObj
)
1122 TRACE( "(%p,%p)\n", hdc
, hObj
);
1124 header
= GDI_GetObjPtr( hObj
, MAGIC_DONTCARE
);
1127 const struct gdi_obj_funcs
*funcs
= header
->funcs
;
1128 GDI_ReleaseObj( hObj
);
1129 if (funcs
&& funcs
->pSelectObject
) ret
= funcs
->pSelectObject( hObj
, hdc
);
1135 /***********************************************************************
1136 * UnrealizeObject (GDI32.@)
1138 BOOL WINAPI
UnrealizeObject( HGDIOBJ obj
)
1141 /* Check if object is valid */
1143 GDIOBJHDR
* header
= GDI_GetObjPtr( obj
, MAGIC_DONTCARE
);
1144 if (!header
) return FALSE
;
1146 TRACE("%p\n", obj
);
1148 /* Unrealize object */
1150 if (header
->funcs
&& header
->funcs
->pUnrealizeObject
)
1151 result
= header
->funcs
->pUnrealizeObject( obj
, header
);
1153 GDI_ReleaseObj( obj
);
1158 /* Solid colors to enumerate */
1159 static const COLORREF solid_colors
[] =
1160 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
1161 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
1162 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
1163 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
1164 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
1165 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
1166 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
1167 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
1171 /***********************************************************************
1172 * EnumObjects (GDI32.@)
1174 INT WINAPI
EnumObjects( HDC hdc
, INT nObjType
,
1175 GOBJENUMPROC lpEnumFunc
, LPARAM lParam
)
1182 TRACE("%p %d %p %08lx\n", hdc
, nObjType
, lpEnumFunc
, lParam
);
1186 /* Enumerate solid pens */
1187 for (i
= 0; i
< sizeof(solid_colors
)/sizeof(solid_colors
[0]); i
++)
1189 pen
.lopnStyle
= PS_SOLID
;
1190 pen
.lopnWidth
.x
= 1;
1191 pen
.lopnWidth
.y
= 0;
1192 pen
.lopnColor
= solid_colors
[i
];
1193 retval
= lpEnumFunc( &pen
, lParam
);
1194 TRACE("solid pen %08x, ret=%d\n",
1195 solid_colors
[i
], retval
);
1201 /* Enumerate solid brushes */
1202 for (i
= 0; i
< sizeof(solid_colors
)/sizeof(solid_colors
[0]); i
++)
1204 brush
.lbStyle
= BS_SOLID
;
1205 brush
.lbColor
= solid_colors
[i
];
1207 retval
= lpEnumFunc( &brush
, lParam
);
1208 TRACE("solid brush %08x, ret=%d\n",
1209 solid_colors
[i
], retval
);
1213 /* Now enumerate hatched brushes */
1214 if (retval
) for (i
= HS_HORIZONTAL
; i
<= HS_DIAGCROSS
; i
++)
1216 brush
.lbStyle
= BS_HATCHED
;
1217 brush
.lbColor
= RGB(0,0,0);
1219 retval
= lpEnumFunc( &brush
, lParam
);
1220 TRACE("hatched brush %d, ret=%d\n",
1227 /* FIXME: implement Win32 types */
1228 WARN("(%d): Invalid type\n", nObjType
);
1235 /***********************************************************************
1236 * SetObjectOwner (GDI32.@)
1238 void WINAPI
SetObjectOwner( HGDIOBJ handle
, HANDLE owner
)
1244 /***********************************************************************
1245 * MakeObjectPrivate (GDI.463)
1247 * What does that mean ?
1248 * Some little docu can be found in "Undocumented Windows",
1249 * but this is basically useless.
1250 * At least we know that this flags the GDI object's wMagic
1251 * with 0x2000 (OBJECT_PRIVATE), so we just do it.
1252 * But Wine doesn't react on that yet.
1254 void WINAPI
MakeObjectPrivate16( HGDIOBJ16 handle16
, BOOL16
private )
1256 HGDIOBJ handle
= HGDIOBJ_32( handle16
);
1257 GDIOBJHDR
*ptr
= GDI_GetObjPtr( handle
, MAGIC_DONTCARE
);
1260 ERR("invalid GDI object %p !\n", handle
);
1263 ptr
->wMagic
|= OBJECT_PRIVATE
;
1264 GDI_ReleaseObj( handle
);
1268 /***********************************************************************
1269 * GdiFlush (GDI32.@)
1271 BOOL WINAPI
GdiFlush(void)
1273 return TRUE
; /* FIXME */
1277 /***********************************************************************
1278 * GdiGetBatchLimit (GDI32.@)
1280 DWORD WINAPI
GdiGetBatchLimit(void)
1282 return 1; /* FIXME */
1286 /***********************************************************************
1287 * GdiSetBatchLimit (GDI32.@)
1289 DWORD WINAPI
GdiSetBatchLimit( DWORD limit
)
1291 return 1; /* FIXME */
1295 /*******************************************************************
1296 * GetColorAdjustment [GDI32.@]
1300 BOOL WINAPI
GetColorAdjustment(HDC hdc
, LPCOLORADJUSTMENT lpca
)
1302 FIXME("GetColorAdjustment, stub\n");
1306 /*******************************************************************
1307 * GdiComment [GDI32.@]
1311 BOOL WINAPI
GdiComment(HDC hdc
, UINT cbSize
, const BYTE
*lpData
)
1313 DC
*dc
= get_dc_ptr(hdc
);
1317 if (dc
->funcs
->pGdiComment
)
1318 ret
= dc
->funcs
->pGdiComment( dc
->physDev
, cbSize
, lpData
);
1319 release_dc_ptr( dc
);
1324 /*******************************************************************
1325 * SetColorAdjustment [GDI32.@]
1329 BOOL WINAPI
SetColorAdjustment(HDC hdc
, const COLORADJUSTMENT
* lpca
)
1331 FIXME("SetColorAdjustment, stub\n");