msi/test: Uninstall the test product when skipping patch tests.
[wine.git] / dlls / gdi32 / gdiobj.c
blob3f84f9c404abeeb8aa9822981957c09ef408c848
1 /*
2 * GDI functions
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
21 #include "config.h"
23 #include <assert.h>
24 #include <stdlib.h>
25 #include <stdarg.h>
26 #include <stdio.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winreg.h"
32 #include "winnls.h"
33 #include "winerror.h"
34 #include "winternl.h"
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 /***********************************************************************
46 * GDI stock objects
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 =
73 0, 0, &gdi_section,
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
120 UINT charset;
121 LOGFONTW SystemFont;
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[] =
129 { ANSI_CHARSET,
130 { /* System */
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,
138 {'\0'}
140 { /* System Fixed */
141 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
142 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
143 {'\0'}
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,
152 { /* System */
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,
160 {'\0'}
162 { /* System Fixed */
163 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
164 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
165 {'\0'}
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'}
173 { RUSSIAN_CHARSET,
174 { /* System */
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,
182 {'\0'}
184 { /* System Fixed */
185 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
186 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
187 {'\0'}
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'}
195 { GREEK_CHARSET,
196 { /* System */
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,
204 {'\0'}
206 { /* System Fixed */
207 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
208 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
209 {'\0'}
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'}
217 { TURKISH_CHARSET,
218 { /* System */
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,
226 {'\0'}
228 { /* System Fixed */
229 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
230 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
231 {'\0'}
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'}
239 { HEBREW_CHARSET,
240 { /* System */
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,
248 {'\0'}
250 { /* System Fixed */
251 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
252 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
253 {'\0'}
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'}
261 { ARABIC_CHARSET,
262 { /* System */
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,
270 {'\0'}
272 { /* System Fixed */
273 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
274 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
275 {'\0'}
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'}
283 { BALTIC_CHARSET,
284 { /* System */
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,
292 {'\0'}
294 { /* System Fixed */
295 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
296 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
297 {'\0'}
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'}
305 { THAI_CHARSET,
306 { /* System */
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,
314 {'\0'}
316 { /* System Fixed */
317 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
318 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
319 {'\0'}
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'}
327 { SHIFTJIS_CHARSET,
328 { /* System */
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,
336 {'\0'}
338 { /* System Fixed */
339 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
340 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
341 {'\0'}
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'}
349 { GB2312_CHARSET,
350 { /* System */
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,
358 {'\0'}
360 { /* System Fixed */
361 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
362 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
363 {'\0'}
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'}
371 { HANGEUL_CHARSET,
372 { /* System */
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,
380 {'\0'}
382 { /* System Fixed */
383 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
384 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
385 {'\0'}
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,
394 { /* System */
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,
402 {'\0'}
404 { /* System Fixed */
405 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
406 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
407 {'\0'}
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'}
415 { JOHAB_CHARSET,
416 { /* System */
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,
424 {'\0'}
426 { /* System Fixed */
427 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
428 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
429 {'\0'}
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 );
450 ptr->system = !!set;
451 GDI_ReleaseObj( handle );
454 /******************************************************************************
455 * get_default_fonts
457 static const struct DefaultFontInfo* get_default_fonts(UINT charset)
459 unsigned int n;
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 )
479 CHARSETINFO csi;
480 UINT uACP;
482 uACP = GetACP();
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 );
487 return ANSI_CHARSET;
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 /******************************************************************************
497 * get_dpi (internal)
499 * get the dpi from the registry
501 static DWORD get_dpi( void )
503 DWORD dpi = 96;
504 HKEY hkey;
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)
514 dpi = new_dpi;
516 RegCloseKey(hkey);
518 return dpi;
522 /***********************************************************************
523 * GDI_inc_ref_count
525 * Increment the reference count of a GDI object.
527 HGDIOBJ GDI_inc_ref_count( HGDIOBJ handle )
529 GDIOBJHDR *header;
531 if ((header = GDI_GetObjPtr( handle, 0 )))
533 header->selcount++;
534 GDI_ReleaseObj( handle );
536 else handle = 0;
538 return handle;
542 /***********************************************************************
543 * GDI_dec_ref_count
545 * Decrement the reference count of a GDI object.
547 BOOL GDI_dec_ref_count( HGDIOBJ handle )
549 GDIOBJHDR *header;
551 if ((header = GDI_GetObjPtr( handle, 0 )))
553 assert( header->selcount );
554 if (!--header->selcount && header->deleted)
556 /* handle delayed DeleteObject*/
557 header->deleted = 0;
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 /***********************************************************************
569 * DllMain
571 * GDI initialization.
573 BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
575 LOGFONTW default_gui_font;
576 const struct DefaultFontInfo* deffonts;
577 int i;
579 if (reason != DLL_PROCESS_ATTACH) return TRUE;
581 DisableThreadLibraryCalls( inst );
582 WineEngInit();
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 );
626 return FALSE;
628 __wine_make_gdi_object_system( stock_objects[i], TRUE );
631 return TRUE;
634 #define FIRST_LARGE_HANDLE 16
635 #define MAX_LARGE_HANDLES ((GDI_HEAP_SIZE >> 2) - FIRST_LARGE_HANDLE)
636 static GDIOBJHDR *large_handles[MAX_LARGE_HANDLES];
637 static int next_large_handle;
639 static const char *gdi_obj_type( unsigned type )
641 switch ( type )
643 case OBJ_PEN: return "OBJ_PEN";
644 case OBJ_BRUSH: return "OBJ_BRUSH";
645 case OBJ_DC: return "OBJ_DC";
646 case OBJ_METADC: return "OBJ_METADC";
647 case OBJ_PAL: return "OBJ_PAL";
648 case OBJ_FONT: return "OBJ_FONT";
649 case OBJ_BITMAP: return "OBJ_BITMAP";
650 case OBJ_REGION: return "OBJ_REGION";
651 case OBJ_METAFILE: return "OBJ_METAFILE";
652 case OBJ_MEMDC: return "OBJ_MEMDC";
653 case OBJ_EXTPEN: return "OBJ_EXTPEN";
654 case OBJ_ENHMETADC: return "OBJ_ENHMETADC";
655 case OBJ_ENHMETAFILE: return "OBJ_ENHMETAFILE";
656 case OBJ_COLORSPACE: return "OBJ_COLORSPACE";
657 default: return "UNKNOWN";
661 static void dump_gdi_objects( void )
663 int i;
665 TRACE( "%u objects:\n", MAX_LARGE_HANDLES );
667 EnterCriticalSection( &gdi_section );
668 for (i = 0; i < MAX_LARGE_HANDLES; i++)
670 if (!large_handles[i])
672 TRACE( "index %d handle %p FREE\n", i, (HGDIOBJ)(ULONG_PTR)((i + FIRST_LARGE_HANDLE) << 2) );
673 continue;
675 TRACE( "handle %p obj %p type %s selcount %u deleted %u\n",
676 (HGDIOBJ)(ULONG_PTR)((i + FIRST_LARGE_HANDLE) << 2),
677 large_handles[i], gdi_obj_type( large_handles[i]->type ),
678 large_handles[i]->selcount, large_handles[i]->deleted );
680 LeaveCriticalSection( &gdi_section );
683 /***********************************************************************
684 * alloc_gdi_handle
686 * Allocate a GDI handle for an object, which must have been allocated on the process heap.
688 HGDIOBJ alloc_gdi_handle( GDIOBJHDR *obj, WORD type, const struct gdi_obj_funcs *funcs )
690 int i;
692 /* initialize the object header */
693 obj->type = type;
694 obj->system = 0;
695 obj->deleted = 0;
696 obj->selcount = 0;
697 obj->funcs = funcs;
698 obj->hdcs = NULL;
700 EnterCriticalSection( &gdi_section );
701 for (i = next_large_handle + 1; i < MAX_LARGE_HANDLES; i++)
702 if (!large_handles[i]) goto found;
703 for (i = 0; i <= next_large_handle; i++)
704 if (!large_handles[i]) goto found;
705 LeaveCriticalSection( &gdi_section );
707 ERR( "out of GDI object handles, expect a crash\n" );
708 if (TRACE_ON(gdi)) dump_gdi_objects();
709 return 0;
711 found:
712 large_handles[i] = obj;
713 next_large_handle = i;
714 LeaveCriticalSection( &gdi_section );
715 return (HGDIOBJ)(ULONG_PTR)((i + FIRST_LARGE_HANDLE) << 2);
719 /***********************************************************************
720 * free_gdi_handle
722 * Free a GDI handle and return a pointer to the object.
724 void *free_gdi_handle( HGDIOBJ handle )
726 GDIOBJHDR *object = NULL;
727 int i;
729 i = ((ULONG_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
730 if (i >= 0 && i < MAX_LARGE_HANDLES)
732 EnterCriticalSection( &gdi_section );
733 object = large_handles[i];
734 large_handles[i] = NULL;
735 LeaveCriticalSection( &gdi_section );
737 if (object)
739 object->type = 0; /* mark it as invalid */
740 object->funcs = NULL;
742 return object;
746 /***********************************************************************
747 * GDI_GetObjPtr
749 * Return a pointer to the GDI object associated to the handle.
750 * Return NULL if the object has the wrong magic number.
751 * The object must be released with GDI_ReleaseObj.
753 void *GDI_GetObjPtr( HGDIOBJ handle, WORD type )
755 GDIOBJHDR *ptr = NULL;
756 int i;
758 EnterCriticalSection( &gdi_section );
760 i = ((UINT_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
761 if (i >= 0 && i < MAX_LARGE_HANDLES)
763 ptr = large_handles[i];
764 if (ptr && type && ptr->type != type) ptr = NULL;
767 if (!ptr)
769 LeaveCriticalSection( &gdi_section );
770 WARN( "Invalid handle %p\n", handle );
772 else TRACE("(%p): enter %d\n", handle, gdi_section.RecursionCount);
774 return ptr;
778 /***********************************************************************
779 * GDI_ReleaseObj
782 void GDI_ReleaseObj( HGDIOBJ handle )
784 TRACE("(%p): leave %d\n", handle, gdi_section.RecursionCount);
785 LeaveCriticalSection( &gdi_section );
789 /***********************************************************************
790 * GDI_CheckNotLock
792 void GDI_CheckNotLock(void)
794 if (gdi_section.OwningThread == ULongToHandle(GetCurrentThreadId()) && gdi_section.RecursionCount)
796 ERR( "BUG: holding GDI lock\n" );
797 DebugBreak();
802 /***********************************************************************
803 * DeleteObject (GDI32.@)
805 * Delete a Gdi object.
807 * PARAMS
808 * obj [I] Gdi object to delete
810 * RETURNS
811 * Success: TRUE. If obj was not returned from GetStockObject(), any resources
812 * it consumed are released.
813 * Failure: FALSE, if obj is not a valid Gdi object, or is currently selected
814 * into a DC.
816 BOOL WINAPI DeleteObject( HGDIOBJ obj )
818 /* Check if object is valid */
820 struct hdc_list *hdcs_head;
821 const struct gdi_obj_funcs *funcs;
822 GDIOBJHDR * header;
824 if (HIWORD(obj)) return FALSE;
826 if (!(header = GDI_GetObjPtr( obj, 0 ))) return FALSE;
828 if (header->system)
830 TRACE("Preserving system object %p\n", obj);
831 GDI_ReleaseObj( obj );
832 return TRUE;
835 while ((hdcs_head = header->hdcs) != NULL)
837 DC *dc = get_dc_ptr(hdcs_head->hdc);
839 header->hdcs = hdcs_head->next;
840 TRACE("hdc %p has interest in %p\n", hdcs_head->hdc, obj);
842 if(dc)
844 if(dc->funcs->pDeleteObject)
846 GDI_ReleaseObj( obj ); /* release the GDI lock */
847 dc->funcs->pDeleteObject( dc->physDev, obj );
848 header = GDI_GetObjPtr( obj, 0 ); /* and grab it again */
850 release_dc_ptr( dc );
852 HeapFree(GetProcessHeap(), 0, hdcs_head);
853 if (!header) return FALSE;
856 if (header->selcount)
858 TRACE("delayed for %p because object in use, count %u\n", obj, header->selcount );
859 header->deleted = 1; /* mark for delete */
860 GDI_ReleaseObj( obj );
861 return TRUE;
864 TRACE("%p\n", obj );
866 /* Delete object */
868 funcs = header->funcs;
869 GDI_ReleaseObj( obj );
870 if (funcs && funcs->pDeleteObject)
871 return funcs->pDeleteObject( obj );
872 else
873 return FALSE;
876 /***********************************************************************
877 * GDI_hdc_using_object
879 * Call this if the dc requires DeleteObject notification
881 BOOL GDI_hdc_using_object(HGDIOBJ obj, HDC hdc)
883 GDIOBJHDR * header;
884 struct hdc_list **pphdc;
886 TRACE("obj %p hdc %p\n", obj, hdc);
888 if (!(header = GDI_GetObjPtr( obj, 0 ))) return FALSE;
890 if (header->system)
892 GDI_ReleaseObj(obj);
893 return FALSE;
896 for(pphdc = &header->hdcs; *pphdc; pphdc = &(*pphdc)->next)
897 if((*pphdc)->hdc == hdc)
898 break;
900 if(!*pphdc) {
901 *pphdc = HeapAlloc(GetProcessHeap(), 0, sizeof(**pphdc));
902 (*pphdc)->hdc = hdc;
903 (*pphdc)->next = NULL;
906 GDI_ReleaseObj(obj);
907 return TRUE;
910 /***********************************************************************
911 * GDI_hdc_not_using_object
914 BOOL GDI_hdc_not_using_object(HGDIOBJ obj, HDC hdc)
916 GDIOBJHDR * header;
917 struct hdc_list *phdc, **prev;
919 TRACE("obj %p hdc %p\n", obj, hdc);
921 if (!(header = GDI_GetObjPtr( obj, 0 ))) return FALSE;
923 if (header->system)
925 GDI_ReleaseObj(obj);
926 return FALSE;
929 phdc = header->hdcs;
930 prev = &header->hdcs;
932 while(phdc) {
933 if(phdc->hdc == hdc) {
934 *prev = phdc->next;
935 HeapFree(GetProcessHeap(), 0, phdc);
936 phdc = *prev;
937 } else {
938 prev = &phdc->next;
939 phdc = phdc->next;
943 GDI_ReleaseObj(obj);
944 return TRUE;
947 /***********************************************************************
948 * GetStockObject (GDI32.@)
950 HGDIOBJ WINAPI GetStockObject( INT obj )
952 HGDIOBJ ret;
953 if ((obj < 0) || (obj >= NB_STOCK_OBJECTS)) return 0;
954 ret = stock_objects[obj];
955 TRACE("returning %p\n", ret );
956 return ret;
960 /***********************************************************************
961 * GetObjectA (GDI32.@)
963 INT WINAPI GetObjectA( HGDIOBJ handle, INT count, LPVOID buffer )
965 const struct gdi_obj_funcs *funcs;
966 GDIOBJHDR * ptr;
967 INT result = 0;
969 TRACE("%p %d %p\n", handle, count, buffer );
971 if (!(ptr = GDI_GetObjPtr( handle, 0 ))) return 0;
972 funcs = ptr->funcs;
973 GDI_ReleaseObj( handle );
975 if (funcs && funcs->pGetObjectA)
976 result = funcs->pGetObjectA( handle, count, buffer );
977 else
978 SetLastError( ERROR_INVALID_HANDLE );
980 return result;
983 /***********************************************************************
984 * GetObjectW (GDI32.@)
986 INT WINAPI GetObjectW( HGDIOBJ handle, INT count, LPVOID buffer )
988 const struct gdi_obj_funcs *funcs;
989 GDIOBJHDR * ptr;
990 INT result = 0;
991 TRACE("%p %d %p\n", handle, count, buffer );
993 if (!(ptr = GDI_GetObjPtr( handle, 0 ))) return 0;
994 funcs = ptr->funcs;
995 GDI_ReleaseObj( handle );
997 if (funcs && funcs->pGetObjectW)
998 result = funcs->pGetObjectW( handle, count, buffer );
999 else
1000 SetLastError( ERROR_INVALID_HANDLE );
1002 return result;
1005 /***********************************************************************
1006 * GetObjectType (GDI32.@)
1008 DWORD WINAPI GetObjectType( HGDIOBJ handle )
1010 GDIOBJHDR * ptr;
1011 DWORD result;
1013 if (!(ptr = GDI_GetObjPtr( handle, 0 )))
1015 SetLastError( ERROR_INVALID_HANDLE );
1016 return 0;
1018 result = ptr->type;
1019 GDI_ReleaseObj( handle );
1020 TRACE("%p -> %u\n", handle, result );
1021 return result;
1024 /***********************************************************************
1025 * GetCurrentObject (GDI32.@)
1027 * Get the currently selected object of a given type in a device context.
1029 * PARAMS
1030 * hdc [I] Device context to get the current object from
1031 * type [I] Type of current object to get (OBJ_* defines from "wingdi.h")
1033 * RETURNS
1034 * Success: The current object of the given type selected in hdc.
1035 * Failure: A NULL handle.
1037 * NOTES
1038 * - only the following object types are supported:
1039 *| OBJ_PEN
1040 *| OBJ_BRUSH
1041 *| OBJ_PAL
1042 *| OBJ_FONT
1043 *| OBJ_BITMAP
1045 HGDIOBJ WINAPI GetCurrentObject(HDC hdc,UINT type)
1047 HGDIOBJ ret = 0;
1048 DC * dc = get_dc_ptr( hdc );
1050 if (!dc) return 0;
1052 switch (type) {
1053 case OBJ_EXTPEN: /* fall through */
1054 case OBJ_PEN: ret = dc->hPen; break;
1055 case OBJ_BRUSH: ret = dc->hBrush; break;
1056 case OBJ_PAL: ret = dc->hPalette; break;
1057 case OBJ_FONT: ret = dc->hFont; break;
1058 case OBJ_BITMAP: ret = dc->hBitmap; break;
1060 /* tests show that OBJ_REGION is explicitly ignored */
1061 case OBJ_REGION: break;
1062 default:
1063 /* the SDK only mentions those above */
1064 FIXME("(%p,%d): unknown type.\n",hdc,type);
1065 break;
1067 release_dc_ptr( dc );
1068 return ret;
1072 /***********************************************************************
1073 * SelectObject (GDI32.@)
1075 * Select a Gdi object into a device context.
1077 * PARAMS
1078 * hdc [I] Device context to associate the object with
1079 * hObj [I] Gdi object to associate with hdc
1081 * RETURNS
1082 * Success: A non-NULL handle representing the previously selected object of
1083 * the same type as hObj.
1084 * Failure: A NULL object. If hdc is invalid, GetLastError() returns ERROR_INVALID_HANDLE.
1085 * if hObj is not a valid object handle, no last error is set. In either
1086 * case, hdc is unaffected by the call.
1088 HGDIOBJ WINAPI SelectObject( HDC hdc, HGDIOBJ hObj )
1090 HGDIOBJ ret = 0;
1091 GDIOBJHDR *header;
1093 TRACE( "(%p,%p)\n", hdc, hObj );
1095 header = GDI_GetObjPtr( hObj, 0 );
1096 if (header)
1098 const struct gdi_obj_funcs *funcs = header->funcs;
1099 GDI_ReleaseObj( hObj );
1100 if (funcs && funcs->pSelectObject) ret = funcs->pSelectObject( hObj, hdc );
1102 return ret;
1106 /***********************************************************************
1107 * UnrealizeObject (GDI32.@)
1109 BOOL WINAPI UnrealizeObject( HGDIOBJ obj )
1111 BOOL result = FALSE;
1112 GDIOBJHDR * header = GDI_GetObjPtr( obj, 0 );
1114 if (header)
1116 const struct gdi_obj_funcs *funcs = header->funcs;
1118 GDI_ReleaseObj( obj );
1119 if (funcs && funcs->pUnrealizeObject)
1120 result = header->funcs->pUnrealizeObject( obj );
1121 else
1122 result = TRUE;
1124 return result;
1128 /* Solid colors to enumerate */
1129 static const COLORREF solid_colors[] =
1130 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
1131 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
1132 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
1133 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
1134 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
1135 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
1136 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
1137 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
1141 /***********************************************************************
1142 * EnumObjects (GDI32.@)
1144 INT WINAPI EnumObjects( HDC hdc, INT nObjType,
1145 GOBJENUMPROC lpEnumFunc, LPARAM lParam )
1147 UINT i;
1148 INT retval = 0;
1149 LOGPEN pen;
1150 LOGBRUSH brush;
1152 TRACE("%p %d %p %08lx\n", hdc, nObjType, lpEnumFunc, lParam );
1153 switch(nObjType)
1155 case OBJ_PEN:
1156 /* Enumerate solid pens */
1157 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1159 pen.lopnStyle = PS_SOLID;
1160 pen.lopnWidth.x = 1;
1161 pen.lopnWidth.y = 0;
1162 pen.lopnColor = solid_colors[i];
1163 retval = lpEnumFunc( &pen, lParam );
1164 TRACE("solid pen %08x, ret=%d\n",
1165 solid_colors[i], retval);
1166 if (!retval) break;
1168 break;
1170 case OBJ_BRUSH:
1171 /* Enumerate solid brushes */
1172 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1174 brush.lbStyle = BS_SOLID;
1175 brush.lbColor = solid_colors[i];
1176 brush.lbHatch = 0;
1177 retval = lpEnumFunc( &brush, lParam );
1178 TRACE("solid brush %08x, ret=%d\n",
1179 solid_colors[i], retval);
1180 if (!retval) break;
1183 /* Now enumerate hatched brushes */
1184 if (retval) for (i = HS_HORIZONTAL; i <= HS_DIAGCROSS; i++)
1186 brush.lbStyle = BS_HATCHED;
1187 brush.lbColor = RGB(0,0,0);
1188 brush.lbHatch = i;
1189 retval = lpEnumFunc( &brush, lParam );
1190 TRACE("hatched brush %d, ret=%d\n",
1191 i, retval);
1192 if (!retval) break;
1194 break;
1196 default:
1197 /* FIXME: implement Win32 types */
1198 WARN("(%d): Invalid type\n", nObjType );
1199 break;
1201 return retval;
1205 /***********************************************************************
1206 * SetObjectOwner (GDI32.@)
1208 void WINAPI SetObjectOwner( HGDIOBJ handle, HANDLE owner )
1210 /* Nothing to do */
1213 /***********************************************************************
1214 * GdiInitializeLanguagePack (GDI32.@)
1216 DWORD WINAPI GdiInitializeLanguagePack( DWORD arg )
1218 FIXME("stub\n");
1219 return 0;
1222 /***********************************************************************
1223 * GdiFlush (GDI32.@)
1225 BOOL WINAPI GdiFlush(void)
1227 return TRUE; /* FIXME */
1231 /***********************************************************************
1232 * GdiGetBatchLimit (GDI32.@)
1234 DWORD WINAPI GdiGetBatchLimit(void)
1236 return 1; /* FIXME */
1240 /***********************************************************************
1241 * GdiSetBatchLimit (GDI32.@)
1243 DWORD WINAPI GdiSetBatchLimit( DWORD limit )
1245 return 1; /* FIXME */
1249 /*******************************************************************
1250 * GetColorAdjustment [GDI32.@]
1254 BOOL WINAPI GetColorAdjustment(HDC hdc, LPCOLORADJUSTMENT lpca)
1256 FIXME("stub\n");
1257 return 0;
1260 /*******************************************************************
1261 * GdiComment [GDI32.@]
1265 BOOL WINAPI GdiComment(HDC hdc, UINT cbSize, const BYTE *lpData)
1267 DC *dc = get_dc_ptr(hdc);
1268 BOOL ret = FALSE;
1269 if(dc)
1271 if (dc->funcs->pGdiComment)
1272 ret = dc->funcs->pGdiComment( dc->physDev, cbSize, lpData );
1273 release_dc_ptr( dc );
1275 return ret;
1278 /*******************************************************************
1279 * SetColorAdjustment [GDI32.@]
1283 BOOL WINAPI SetColorAdjustment(HDC hdc, const COLORADJUSTMENT* lpca)
1285 FIXME("stub\n");
1286 return 0;