Fix a TRACE.
[wine/multimedia.git] / objects / gdiobj.c
blob88b8d9fc28e42de78fb5644ebbe712d1b9e6f75a
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 "winerror.h"
34 #include "bitmap.h"
35 #include "local.h"
36 #include "palette.h"
37 #include "gdi.h"
38 #include "gdi_private.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
43 #define HGDIOBJ_32(h16) ((HGDIOBJ)(ULONG_PTR)(h16))
45 #define GDI_HEAP_SIZE 0xffe0
47 /***********************************************************************
48 * GDI stock objects
51 static const LOGBRUSH WhiteBrush = { BS_SOLID, RGB(255,255,255), 0 };
52 static const LOGBRUSH BlackBrush = { BS_SOLID, RGB(0,0,0), 0 };
53 static const LOGBRUSH NullBrush = { BS_NULL, 0, 0 };
55 /* FIXME: these should perhaps be BS_HATCHED, at least for 1 bitperpixel */
56 static const LOGBRUSH LtGrayBrush = { BS_SOLID, RGB(192,192,192), 0 };
57 static const LOGBRUSH GrayBrush = { BS_SOLID, RGB(128,128,128), 0 };
59 /* This is BS_HATCHED, for 1 bitperpixel. This makes the spray work in pbrush */
60 /* See HatchBrushes in x11drv for the HS_DIAGCROSS+1 hack */
61 static const LOGBRUSH DkGrayBrush = { BS_HATCHED, RGB(0,0,0), (HS_DIAGCROSS+1) };
63 static const LOGPEN WhitePen = { PS_SOLID, { 0, 0 }, RGB(255,255,255) };
64 static const LOGPEN BlackPen = { PS_SOLID, { 0, 0 }, RGB(0,0,0) };
65 static const LOGPEN NullPen = { PS_NULL, { 0, 0 }, 0 };
67 static const LOGBRUSH DCBrush = { BS_SOLID, RGB(255,255,255), 0 };
68 static const LOGPEN DCPen = { PS_SOLID, { 0, 0 }, RGB(0,0,0) };
70 /* reserve one extra entry for the stock default bitmap */
71 /* this is what Windows does too */
72 #define NB_STOCK_OBJECTS (STOCK_LAST+2)
74 static HGDIOBJ stock_objects[NB_STOCK_OBJECTS];
76 static SYSLEVEL GDI_level;
77 static CRITICAL_SECTION_DEBUG critsect_debug =
79 0, 0, &GDI_level.crst,
80 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
81 0, 0, { 0, (DWORD)(__FILE__ ": GDI_level") }
83 static SYSLEVEL GDI_level = { { &critsect_debug, -1, 0, 0, 0, 0 }, 3 };
85 static WORD GDI_HeapSel;
87 inline static BOOL get_bool(char *buffer)
89 return (buffer[0] == 'y' || buffer[0] == 'Y' ||
90 buffer[0] == 't' || buffer[0] == 'T' ||
91 buffer[0] == '1');
95 /****************************************************************************
97 * language-independent stock fonts
101 static const LOGFONTW OEMFixedFont =
102 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, OEM_CHARSET,
103 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} };
105 static const LOGFONTW AnsiFixedFont =
106 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
107 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} };
109 static const LOGFONTW AnsiVarFont =
110 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
111 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
112 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'} };
114 /******************************************************************************
116 * language-dependent stock fonts
118 * 'ANSI' charset and 'DEFAULT' charset is not same.
119 * The chars in CP_ACP should be drawn with 'DEFAULT' charset.
120 * 'ANSI' charset seems to be identical with ISO-8859-1.
121 * 'DEFAULT' charset is a language-dependent charset.
123 * 'System' font seems to be an alias for language-dependent font.
127 * language-dependenet stock fonts for all known charsets
128 * please see TranslateCharsetInfo (objects/font.c) and
129 * CharsetBindingInfo (graphics/x11drv/xfont.c),
130 * and modify entries for your language if needed.
132 struct DefaultFontInfo
134 UINT charset;
135 LOGFONTW SystemFont;
136 LOGFONTW DeviceDefaultFont;
137 LOGFONTW SystemFixedFont;
138 LOGFONTW DefaultGuiFont;
141 static const struct DefaultFontInfo default_fonts[] =
143 { ANSI_CHARSET,
144 { /* System */
145 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
146 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
147 {'S','y','s','t','e','m','\0'}
149 { /* Device Default */
150 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
151 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
152 {'\0'}
154 { /* System Fixed */
155 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
156 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
157 {'\0'}
159 { /* DefaultGuiFont */
160 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
161 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
162 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
165 { EASTEUROPE_CHARSET,
166 { /* System */
167 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
168 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
169 {'S','y','s','t','e','m','\0'}
171 { /* Device Default */
172 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
173 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
174 {'\0'}
176 { /* System Fixed */
177 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
178 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
179 {'\0'}
181 { /* DefaultGuiFont */
182 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
183 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
184 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
187 { RUSSIAN_CHARSET,
188 { /* System */
189 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
190 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
191 {'S','y','s','t','e','m','\0'}
193 { /* Device Default */
194 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
195 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
196 {'\0'}
198 { /* System Fixed */
199 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
200 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
201 {'\0'}
203 { /* DefaultGuiFont */
204 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
205 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
206 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
209 { GREEK_CHARSET,
210 { /* System */
211 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
212 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
213 {'S','y','s','t','e','m','\0'}
215 { /* Device Default */
216 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
217 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
218 {'\0'}
220 { /* System Fixed */
221 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
222 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
223 {'\0'}
225 { /* DefaultGuiFont */
226 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
227 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
228 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
231 { TURKISH_CHARSET,
232 { /* System */
233 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
234 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
235 {'S','y','s','t','e','m','\0'}
237 { /* Device Default */
238 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
239 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
240 {'\0'}
242 { /* System Fixed */
243 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
244 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
245 {'\0'}
247 { /* DefaultGuiFont */
248 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
249 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
250 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
253 { HEBREW_CHARSET,
254 { /* System */
255 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
256 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
257 {'S','y','s','t','e','m','\0'}
259 { /* Device Default */
260 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
261 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
262 {'\0'}
264 { /* System Fixed */
265 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
266 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
267 {'\0'}
269 { /* DefaultGuiFont */
270 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
271 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
272 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
275 { ARABIC_CHARSET,
276 { /* System */
277 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
278 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
279 {'S','y','s','t','e','m','\0'}
281 { /* Device Default */
282 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
283 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
284 {'\0'}
286 { /* System Fixed */
287 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
288 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
289 {'\0'}
291 { /* DefaultGuiFont */
292 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
293 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
294 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
297 { BALTIC_CHARSET,
298 { /* System */
299 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
300 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
301 {'S','y','s','t','e','m','\0'}
303 { /* Device Default */
304 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
305 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
306 {'\0'}
308 { /* System Fixed */
309 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
310 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
311 {'\0'}
313 { /* DefaultGuiFont */
314 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
315 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
316 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
319 { THAI_CHARSET,
320 { /* System */
321 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
322 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
323 {'S','y','s','t','e','m','\0'}
325 { /* Device Default */
326 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
327 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
328 {'\0'}
330 { /* System Fixed */
331 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
332 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
333 {'\0'}
335 { /* DefaultGuiFont */
336 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
337 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
338 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
341 { SHIFTJIS_CHARSET,
342 { /* System */
343 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
344 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
345 {'S','y','s','t','e','m','\0'}
347 { /* Device Default */
348 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
349 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
350 {'\0'}
352 { /* System Fixed */
353 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
354 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
355 {'\0'}
357 { /* DefaultGuiFont */
358 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
359 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
360 {'M','S',' ','U','I',' ','G','o','t','h','i','c','\0'}
363 { GB2312_CHARSET,
364 { /* System */
365 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
366 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
367 {'S','y','s','t','e','m','\0'}
369 { /* Device Default */
370 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
371 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
372 {'\0'}
374 { /* System Fixed */
375 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
376 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
377 {'\0'}
379 { /* DefaultGuiFont */
380 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
381 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
382 {'M','S',' ','S','o','n','g','\0'} /* FIXME: Is this correct? */
385 { HANGEUL_CHARSET,
386 { /* System */
387 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
388 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
389 {'S','y','s','t','e','m','\0'}
391 { /* Device Default */
392 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
393 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
394 {'\0'}
396 { /* System Fixed */
397 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
398 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
399 {'\0'}
401 { /* DefaultGuiFont */
402 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
403 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
404 {'G','u','l','i','m'},
407 { CHINESEBIG5_CHARSET,
408 { /* System */
409 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
410 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
411 {'S','y','s','t','e','m','\0'}
413 { /* Device Default */
414 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
415 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
416 {'\0'}
418 { /* System Fixed */
419 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
420 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
421 {'\0'}
423 { /* DefaultGuiFont */
424 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
425 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
426 {'\0'} /* FIXME - what is the native font??? */
429 { JOHAB_CHARSET,
430 { /* System */
431 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
432 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
433 {'S','y','s','t','e','m','\0'}
435 { /* Device Default */
436 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
437 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
438 {'\0'}
440 { /* System Fixed */
441 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
442 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
443 {'\0'}
445 { /* DefaultGuiFont */
446 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
447 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
448 {'M','S',' ','M','i','n','g','l','i','u','\0'} /* FIXME: Is this correct? */
454 /******************************************************************************
455 * get_default_fonts
457 static const struct DefaultFontInfo* get_default_fonts(UINT charset)
459 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( (LPDWORD)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;
494 /******************************************************************************
495 * create_stock_font
497 static HFONT create_stock_font( char const *fontName, const LOGFONTW *font, HKEY hkey )
499 LOGFONTW lf;
500 char key[256];
501 char buffer[MAX_PATH];
502 DWORD type, count;
504 if (!hkey) return CreateFontIndirectW( font );
506 lf = *font;
507 sprintf(key, "%s.Height", fontName);
508 count = sizeof(buffer);
509 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
510 lf.lfHeight = atoi(buffer);
512 sprintf(key, "%s.Bold", fontName);
513 count = sizeof(buffer);
514 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
515 lf.lfWeight = get_bool(buffer) ? FW_BOLD : FW_NORMAL;
517 sprintf(key, "%s.Italic", fontName);
518 count = sizeof(buffer);
519 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
520 lf.lfItalic = get_bool(buffer);
522 sprintf(key, "%s.Underline", fontName);
523 count = sizeof(buffer);
524 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
525 lf.lfUnderline = get_bool(buffer);
527 sprintf(key, "%s.StrikeOut", fontName);
528 count = sizeof(buffer);
529 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
530 lf.lfStrikeOut = get_bool(buffer);
531 return CreateFontIndirectW( &lf );
535 #define TRACE_SEC(handle,text) \
536 TRACE("(%p): " text " %ld\n", (handle), GDI_level.crst.RecursionCount)
539 /***********************************************************************
540 * inc_ref_count
542 * Increment the reference count of a GDI object.
544 inline static void inc_ref_count( HGDIOBJ handle )
546 GDIOBJHDR *header;
548 if ((header = GDI_GetObjPtr( handle, MAGIC_DONTCARE )))
550 header->dwCount++;
551 GDI_ReleaseObj( handle );
556 /***********************************************************************
557 * dec_ref_count
559 * Decrement the reference count of a GDI object.
561 inline static void dec_ref_count( HGDIOBJ handle )
563 GDIOBJHDR *header;
565 if ((header = GDI_GetObjPtr( handle, MAGIC_DONTCARE )))
567 if (header->dwCount) header->dwCount--;
568 if (header->dwCount != 0x80000000) GDI_ReleaseObj( handle );
569 else
571 /* handle delayed DeleteObject*/
572 header->dwCount = 0;
573 GDI_ReleaseObj( handle );
574 TRACE( "executing delayed DeleteObject for %p\n", handle );
575 DeleteObject( handle );
581 /***********************************************************************
582 * GDI_Init
584 * GDI initialization.
586 BOOL GDI_Init(void)
588 HINSTANCE16 instance;
589 HKEY hkey;
590 GDIOBJHDR *ptr;
591 const struct DefaultFontInfo* deffonts;
592 int i;
594 if (RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Tweak.Fonts", &hkey))
595 hkey = 0;
597 /* create GDI heap */
598 if ((instance = LoadLibrary16( "GDI.EXE" )) >= 32) GDI_HeapSel = instance | 7;
600 /* create stock objects */
601 stock_objects[WHITE_BRUSH] = CreateBrushIndirect( &WhiteBrush );
602 stock_objects[LTGRAY_BRUSH] = CreateBrushIndirect( &LtGrayBrush );
603 stock_objects[GRAY_BRUSH] = CreateBrushIndirect( &GrayBrush );
604 stock_objects[DKGRAY_BRUSH] = CreateBrushIndirect( &DkGrayBrush );
605 stock_objects[BLACK_BRUSH] = CreateBrushIndirect( &BlackBrush );
606 stock_objects[NULL_BRUSH] = CreateBrushIndirect( &NullBrush );
608 stock_objects[WHITE_PEN] = CreatePenIndirect( &WhitePen );
609 stock_objects[BLACK_PEN] = CreatePenIndirect( &BlackPen );
610 stock_objects[NULL_PEN] = CreatePenIndirect( &NullPen );
612 stock_objects[DEFAULT_PALETTE] = PALETTE_Init();
613 stock_objects[DEFAULT_BITMAP] = CreateBitmap( 1, 1, 1, 1, NULL );
615 /* language-independent stock fonts */
616 stock_objects[OEM_FIXED_FONT] = create_stock_font( "OEMFixed", &OEMFixedFont, hkey );
617 stock_objects[ANSI_FIXED_FONT] = create_stock_font( "AnsiFixed", &AnsiFixedFont, hkey );
618 stock_objects[ANSI_VAR_FONT] = create_stock_font( "AnsiVar", &AnsiVarFont, hkey );
620 /* language-dependent stock fonts */
621 deffonts = get_default_fonts(get_default_charset());
622 stock_objects[SYSTEM_FONT] = create_stock_font( "System", &deffonts->SystemFont, hkey );
623 stock_objects[DEVICE_DEFAULT_FONT] = create_stock_font( "DeviceDefault", &deffonts->DeviceDefaultFont, hkey );
624 stock_objects[SYSTEM_FIXED_FONT] = create_stock_font( "SystemFixed", &deffonts->SystemFixedFont, hkey );
625 stock_objects[DEFAULT_GUI_FONT] = create_stock_font( "DefaultGui", &deffonts->DefaultGuiFont, hkey );
627 stock_objects[DC_BRUSH] = CreateBrushIndirect( &DCBrush );
628 stock_objects[DC_PEN] = CreatePenIndirect( &DCPen );
630 /* clear the NOSYSTEM bit on all stock objects*/
631 for (i = 0; i < NB_STOCK_OBJECTS; i++)
633 if (!stock_objects[i])
635 if (i == 9) continue; /* there's no stock object 9 */
636 ERR( "could not create stock object %d\n", i );
637 return FALSE;
639 ptr = GDI_GetObjPtr( stock_objects[i], MAGIC_DONTCARE );
640 ptr->wMagic &= ~OBJECT_NOSYSTEM;
641 GDI_ReleaseObj( stock_objects[i] );
644 if (hkey) RegCloseKey( hkey );
646 WineEngInit();
648 return TRUE;
651 #define FIRST_LARGE_HANDLE 16
652 #define MAX_LARGE_HANDLES ((GDI_HEAP_SIZE >> 2) - FIRST_LARGE_HANDLE)
653 static GDIOBJHDR *large_handles[MAX_LARGE_HANDLES];
654 static int next_large_handle;
656 /***********************************************************************
657 * alloc_large_heap
659 * Allocate a GDI handle from the large heap. Helper for GDI_AllocObject
661 inline static GDIOBJHDR *alloc_large_heap( WORD size, HGDIOBJ *handle )
663 int i;
664 GDIOBJHDR *obj;
666 for (i = next_large_handle + 1; i < MAX_LARGE_HANDLES; i++)
667 if (!large_handles[i]) goto found;
668 for (i = 0; i <= next_large_handle; i++)
669 if (!large_handles[i]) goto found;
670 *handle = 0;
671 return NULL;
673 found:
674 if ((obj = HeapAlloc( GetProcessHeap(), 0, size )))
676 large_handles[i] = obj;
677 *handle = (HGDIOBJ)(ULONG_PTR)((i + FIRST_LARGE_HANDLE) << 2);
678 next_large_handle = i;
680 return obj;
684 /***********************************************************************
685 * GDI_AllocObject
687 void *GDI_AllocObject( WORD size, WORD magic, HGDIOBJ *handle, const struct gdi_obj_funcs *funcs )
689 GDIOBJHDR *obj;
690 HLOCAL16 hlocal;
692 _EnterSysLevel( &GDI_level );
693 switch(magic)
695 default:
696 if (GDI_HeapSel)
698 if (!(hlocal = LOCAL_Alloc( GDI_HeapSel, LMEM_MOVEABLE, size ))) goto error;
699 assert( hlocal & 2 );
700 obj = (GDIOBJHDR *)LOCAL_Lock( GDI_HeapSel, hlocal );
701 *handle = (HGDIOBJ)(ULONG_PTR)hlocal;
702 break;
704 /* fall through */
705 case DC_MAGIC:
706 case DISABLED_DC_MAGIC:
707 case META_DC_MAGIC:
708 case METAFILE_MAGIC:
709 case METAFILE_DC_MAGIC:
710 case ENHMETAFILE_MAGIC:
711 case ENHMETAFILE_DC_MAGIC:
712 case MEMORY_DC_MAGIC:
713 case BITMAP_MAGIC:
714 case PALETTE_MAGIC:
715 if (!(obj = alloc_large_heap( size, handle ))) goto error;
716 break;
719 obj->hNext = 0;
720 obj->wMagic = magic|OBJECT_NOSYSTEM;
721 obj->dwCount = 0;
722 obj->funcs = funcs;
723 obj->hdcs = NULL;
725 TRACE_SEC( *handle, "enter" );
726 return obj;
728 error:
729 _LeaveSysLevel( &GDI_level );
730 *handle = 0;
731 return NULL;
735 /***********************************************************************
736 * GDI_ReallocObject
738 * The object ptr must have been obtained with GDI_GetObjPtr.
739 * The new pointer must be released with GDI_ReleaseObj.
741 void *GDI_ReallocObject( WORD size, HGDIOBJ handle, void *object )
743 HGDIOBJ new_handle;
745 if ((UINT_PTR)handle & 2) /* GDI heap handle */
747 HLOCAL16 h = LOWORD(handle);
748 LOCAL_Unlock( GDI_HeapSel, h );
749 if ((new_handle = (HGDIOBJ)(ULONG_PTR)LOCAL_ReAlloc( GDI_HeapSel, h, size, LMEM_MOVEABLE )))
751 assert( new_handle == handle ); /* moveable handle cannot change */
752 return LOCAL_Lock( GDI_HeapSel, h );
755 else
757 int i = ((ULONG_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
758 if (i >= 0 && i < MAX_LARGE_HANDLES && large_handles[i])
760 void *new_ptr = HeapReAlloc( GetProcessHeap(), 0, large_handles[i], size );
761 if (new_ptr)
763 large_handles[i] = new_ptr;
764 return new_ptr;
767 else ERR( "Invalid handle %p\n", handle );
769 TRACE_SEC( handle, "leave" );
770 _LeaveSysLevel( &GDI_level );
771 return NULL;
775 /***********************************************************************
776 * GDI_FreeObject
778 BOOL GDI_FreeObject( HGDIOBJ handle, void *ptr )
780 GDIOBJHDR *object = ptr;
782 object->wMagic = 0; /* Mark it as invalid */
783 object->funcs = NULL;
784 if ((UINT_PTR)handle & 2) /* GDI heap handle */
786 HLOCAL16 h = LOWORD(handle);
787 LOCAL_Unlock( GDI_HeapSel, h );
788 LOCAL_Free( GDI_HeapSel, h );
790 else /* large heap handle */
792 int i = ((ULONG_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
793 if (i >= 0 && i < MAX_LARGE_HANDLES && large_handles[i])
795 HeapFree( GetProcessHeap(), 0, large_handles[i] );
796 large_handles[i] = NULL;
798 else ERR( "Invalid handle %p\n", handle );
800 TRACE_SEC( handle, "leave" );
801 _LeaveSysLevel( &GDI_level );
802 return TRUE;
806 /***********************************************************************
807 * GDI_GetObjPtr
809 * Return a pointer to the GDI object associated to the handle.
810 * Return NULL if the object has the wrong magic number.
811 * The object must be released with GDI_ReleaseObj.
813 void *GDI_GetObjPtr( HGDIOBJ handle, WORD magic )
815 GDIOBJHDR *ptr = NULL;
817 _EnterSysLevel( &GDI_level );
819 if ((UINT_PTR)handle & 2) /* GDI heap handle */
821 HLOCAL16 h = LOWORD(handle);
822 ptr = (GDIOBJHDR *)LOCAL_Lock( GDI_HeapSel, h );
823 if (ptr)
825 if (((magic != MAGIC_DONTCARE) && (GDIMAGIC(ptr->wMagic) != magic)) ||
826 (GDIMAGIC(ptr->wMagic) < FIRST_MAGIC) ||
827 (GDIMAGIC(ptr->wMagic) > LAST_MAGIC))
829 LOCAL_Unlock( GDI_HeapSel, h );
830 ptr = NULL;
834 else /* large heap handle */
836 int i = ((UINT_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
837 if (i >= 0 && i < MAX_LARGE_HANDLES)
839 ptr = large_handles[i];
840 if (ptr && (magic != MAGIC_DONTCARE) && (GDIMAGIC(ptr->wMagic) != magic)) ptr = NULL;
844 if (!ptr)
846 _LeaveSysLevel( &GDI_level );
847 SetLastError( ERROR_INVALID_HANDLE );
848 WARN( "Invalid handle %p\n", handle );
850 else TRACE_SEC( handle, "enter" );
852 return ptr;
856 /***********************************************************************
857 * GDI_ReleaseObj
860 void GDI_ReleaseObj( HGDIOBJ handle )
862 if ((UINT_PTR)handle & 2) LOCAL_Unlock( GDI_HeapSel, LOWORD(handle) );
863 TRACE_SEC( handle, "leave" );
864 _LeaveSysLevel( &GDI_level );
868 /***********************************************************************
869 * GDI_CheckNotLock
871 void GDI_CheckNotLock(void)
873 _CheckNotSysLevel( &GDI_level );
877 /***********************************************************************
878 * DeleteObject (GDI32.@)
880 BOOL WINAPI DeleteObject( HGDIOBJ obj )
882 /* Check if object is valid */
884 GDIOBJHDR * header;
885 if (HIWORD(obj)) return FALSE;
887 if (!(header = GDI_GetObjPtr( obj, MAGIC_DONTCARE ))) return FALSE;
889 if (!(header->wMagic & OBJECT_NOSYSTEM)
890 && (header->wMagic >= FIRST_MAGIC) && (header->wMagic <= LAST_MAGIC))
892 TRACE("Preserving system object %p\n", obj);
893 GDI_ReleaseObj( obj );
894 return TRUE;
897 while (header->hdcs)
899 DC *dc = DC_GetDCPtr(header->hdcs->hdc);
900 struct hdc_list *tmp;
902 TRACE("hdc %p has interest in %p\n", header->hdcs->hdc, obj);
903 if(dc)
905 if(dc->funcs->pDeleteObject)
906 dc->funcs->pDeleteObject( dc->physDev, obj );
907 GDI_ReleaseObj( header->hdcs->hdc );
909 tmp = header->hdcs;
910 header->hdcs = header->hdcs->next;
911 HeapFree(GetProcessHeap(), 0, tmp);
914 if (header->dwCount)
916 TRACE("delayed for %p because object in use, count %ld\n", obj, header->dwCount );
917 header->dwCount |= 0x80000000; /* mark for delete */
918 GDI_ReleaseObj( obj );
919 return TRUE;
922 TRACE("%p\n", obj );
924 /* Delete object */
926 if (header->funcs && header->funcs->pDeleteObject)
927 return header->funcs->pDeleteObject( obj, header );
929 GDI_ReleaseObj( obj );
930 return FALSE;
933 /***********************************************************************
934 * GDI_hdc_using_object
936 * Call this if the dc requires DeleteObject notification
938 BOOL GDI_hdc_using_object(HGDIOBJ obj, HDC hdc)
940 GDIOBJHDR * header;
941 struct hdc_list **pphdc;
943 TRACE("obj %p hdc %p\n", obj, hdc);
945 if (!(header = GDI_GetObjPtr( obj, MAGIC_DONTCARE ))) return FALSE;
947 if (!(header->wMagic & OBJECT_NOSYSTEM) &&
948 (header->wMagic >= FIRST_MAGIC) && (header->wMagic <= LAST_MAGIC))
950 GDI_ReleaseObj(obj);
951 return FALSE;
954 for(pphdc = &header->hdcs; *pphdc; pphdc = &(*pphdc)->next)
955 if((*pphdc)->hdc == hdc)
956 break;
958 if(!*pphdc) {
959 *pphdc = HeapAlloc(GetProcessHeap(), 0, sizeof(**pphdc));
960 (*pphdc)->hdc = hdc;
961 (*pphdc)->next = NULL;
964 GDI_ReleaseObj(obj);
965 return TRUE;
968 /***********************************************************************
969 * GDI_hdc_not_using_object
972 BOOL GDI_hdc_not_using_object(HGDIOBJ obj, HDC hdc)
974 GDIOBJHDR * header;
975 struct hdc_list *phdc, **prev;
977 TRACE("obj %p hdc %p\n", obj, hdc);
979 if (!(header = GDI_GetObjPtr( obj, MAGIC_DONTCARE ))) return FALSE;
981 if (!(header->wMagic & OBJECT_NOSYSTEM) &&
982 (header->wMagic >= FIRST_MAGIC) && (header->wMagic <= LAST_MAGIC))
984 GDI_ReleaseObj(obj);
985 return FALSE;
988 phdc = header->hdcs;
989 prev = &header->hdcs;
991 while(phdc) {
992 if(phdc->hdc == hdc) {
993 *prev = phdc->next;
994 HeapFree(GetProcessHeap(), 0, phdc);
995 phdc = *prev;
996 } else {
997 prev = &phdc->next;
998 phdc = phdc->next;
1002 GDI_ReleaseObj(obj);
1003 return TRUE;
1006 /***********************************************************************
1007 * GetStockObject (GDI32.@)
1009 HGDIOBJ WINAPI GetStockObject( INT obj )
1011 HGDIOBJ ret;
1012 if ((obj < 0) || (obj >= NB_STOCK_OBJECTS)) return 0;
1013 ret = stock_objects[obj];
1014 TRACE("returning %p\n", ret );
1015 return ret;
1019 /***********************************************************************
1020 * GetObject (GDI.82)
1022 INT16 WINAPI GetObject16( HANDLE16 handle16, INT16 count, LPVOID buffer )
1024 GDIOBJHDR * ptr;
1025 HGDIOBJ handle = HGDIOBJ_32( handle16 );
1026 INT16 result = 0;
1028 TRACE("%p %d %p\n", handle, count, buffer );
1029 if (!count) return 0;
1031 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
1033 if (ptr->funcs && ptr->funcs->pGetObject16)
1034 result = ptr->funcs->pGetObject16( handle, ptr, count, buffer );
1035 else
1036 SetLastError( ERROR_INVALID_HANDLE );
1038 GDI_ReleaseObj( handle );
1039 return result;
1043 /***********************************************************************
1044 * GetObjectA (GDI32.@)
1046 INT WINAPI GetObjectA( HANDLE handle, INT count, LPVOID buffer )
1048 GDIOBJHDR * ptr;
1049 INT result = 0;
1050 TRACE("%p %d %p\n", handle, count, buffer );
1052 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
1054 if (ptr->funcs && ptr->funcs->pGetObjectA)
1055 result = ptr->funcs->pGetObjectA( handle, ptr, count, buffer );
1056 else
1057 SetLastError( ERROR_INVALID_HANDLE );
1059 GDI_ReleaseObj( handle );
1060 return result;
1063 /***********************************************************************
1064 * GetObjectW (GDI32.@)
1066 INT WINAPI GetObjectW( HANDLE handle, INT count, LPVOID buffer )
1068 GDIOBJHDR * ptr;
1069 INT result = 0;
1070 TRACE("%p %d %p\n", handle, count, buffer );
1072 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
1074 if (ptr->funcs && ptr->funcs->pGetObjectW)
1075 result = ptr->funcs->pGetObjectW( handle, ptr, count, buffer );
1076 else
1077 SetLastError( ERROR_INVALID_HANDLE );
1079 GDI_ReleaseObj( handle );
1080 return result;
1083 /***********************************************************************
1084 * GetObjectType (GDI32.@)
1086 DWORD WINAPI GetObjectType( HANDLE handle )
1088 GDIOBJHDR * ptr;
1089 INT result = 0;
1090 TRACE("%p\n", handle );
1092 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
1094 switch(GDIMAGIC(ptr->wMagic))
1096 case PEN_MAGIC:
1097 result = OBJ_PEN;
1098 break;
1099 case BRUSH_MAGIC:
1100 result = OBJ_BRUSH;
1101 break;
1102 case BITMAP_MAGIC:
1103 result = OBJ_BITMAP;
1104 break;
1105 case FONT_MAGIC:
1106 result = OBJ_FONT;
1107 break;
1108 case PALETTE_MAGIC:
1109 result = OBJ_PAL;
1110 break;
1111 case REGION_MAGIC:
1112 result = OBJ_REGION;
1113 break;
1114 case DC_MAGIC:
1115 result = OBJ_DC;
1116 break;
1117 case META_DC_MAGIC:
1118 result = OBJ_METADC;
1119 break;
1120 case METAFILE_MAGIC:
1121 result = OBJ_METAFILE;
1122 break;
1123 case METAFILE_DC_MAGIC:
1124 result = OBJ_METADC;
1125 break;
1126 case ENHMETAFILE_MAGIC:
1127 result = OBJ_ENHMETAFILE;
1128 break;
1129 case ENHMETAFILE_DC_MAGIC:
1130 result = OBJ_ENHMETADC;
1131 break;
1132 case MEMORY_DC_MAGIC:
1133 result = OBJ_MEMDC;
1134 break;
1135 default:
1136 FIXME("Magic %04x not implemented\n", GDIMAGIC(ptr->wMagic) );
1137 break;
1139 GDI_ReleaseObj( handle );
1140 return result;
1143 /***********************************************************************
1144 * GetCurrentObject (GDI32.@)
1146 HANDLE WINAPI GetCurrentObject(HDC hdc,UINT type)
1148 HANDLE ret = 0;
1149 DC * dc = DC_GetDCPtr( hdc );
1151 if (dc)
1153 switch (type) {
1154 case OBJ_PEN: ret = dc->hPen; break;
1155 case OBJ_BRUSH: ret = dc->hBrush; break;
1156 case OBJ_PAL: ret = dc->hPalette; break;
1157 case OBJ_FONT: ret = dc->hFont; break;
1158 case OBJ_BITMAP: ret = dc->hBitmap; break;
1159 default:
1160 /* the SDK only mentions those above */
1161 FIXME("(%p,%d): unknown type.\n",hdc,type);
1162 break;
1164 GDI_ReleaseObj( hdc );
1166 return ret;
1170 /***********************************************************************
1171 * SelectObject (GDI32.@)
1173 HGDIOBJ WINAPI SelectObject( HDC hdc, HGDIOBJ handle )
1175 HGDIOBJ ret = 0;
1176 GDIOBJHDR *header = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1177 if (!header) return 0;
1179 TRACE("hdc=%p %p\n", hdc, handle );
1181 if (header->funcs && header->funcs->pSelectObject)
1183 ret = header->funcs->pSelectObject( handle, header, hdc );
1184 if (ret && ret != handle && (INT)ret > COMPLEXREGION)
1186 inc_ref_count( handle );
1187 dec_ref_count( ret );
1190 GDI_ReleaseObj( handle );
1191 return ret;
1195 /***********************************************************************
1196 * UnrealizeObject (GDI32.@)
1198 BOOL WINAPI UnrealizeObject( HGDIOBJ obj )
1200 BOOL result = TRUE;
1201 /* Check if object is valid */
1203 GDIOBJHDR * header = GDI_GetObjPtr( obj, MAGIC_DONTCARE );
1204 if (!header) return FALSE;
1206 TRACE("%p\n", obj );
1208 /* Unrealize object */
1210 if (header->funcs && header->funcs->pUnrealizeObject)
1211 result = header->funcs->pUnrealizeObject( obj, header );
1213 GDI_ReleaseObj( obj );
1214 return result;
1218 /* Solid colors to enumerate */
1219 static const COLORREF solid_colors[] =
1220 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
1221 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
1222 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
1223 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
1224 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
1225 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
1226 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
1227 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
1231 /***********************************************************************
1232 * EnumObjects (GDI32.@)
1234 INT WINAPI EnumObjects( HDC hdc, INT nObjType,
1235 GOBJENUMPROC lpEnumFunc, LPARAM lParam )
1237 INT i, retval = 0;
1238 LOGPEN pen;
1239 LOGBRUSH brush;
1241 TRACE("%p %d %p %08lx\n", hdc, nObjType, lpEnumFunc, lParam );
1242 switch(nObjType)
1244 case OBJ_PEN:
1245 /* Enumerate solid pens */
1246 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1248 pen.lopnStyle = PS_SOLID;
1249 pen.lopnWidth.x = 1;
1250 pen.lopnWidth.y = 0;
1251 pen.lopnColor = solid_colors[i];
1252 retval = lpEnumFunc( &pen, lParam );
1253 TRACE("solid pen %08lx, ret=%d\n",
1254 solid_colors[i], retval);
1255 if (!retval) break;
1257 break;
1259 case OBJ_BRUSH:
1260 /* Enumerate solid brushes */
1261 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1263 brush.lbStyle = BS_SOLID;
1264 brush.lbColor = solid_colors[i];
1265 brush.lbHatch = 0;
1266 retval = lpEnumFunc( &brush, lParam );
1267 TRACE("solid brush %08lx, ret=%d\n",
1268 solid_colors[i], retval);
1269 if (!retval) break;
1272 /* Now enumerate hatched brushes */
1273 if (retval) for (i = HS_HORIZONTAL; i <= HS_DIAGCROSS; i++)
1275 brush.lbStyle = BS_HATCHED;
1276 brush.lbColor = RGB(0,0,0);
1277 brush.lbHatch = i;
1278 retval = lpEnumFunc( &brush, lParam );
1279 TRACE("hatched brush %d, ret=%d\n",
1280 i, retval);
1281 if (!retval) break;
1283 break;
1285 default:
1286 /* FIXME: implement Win32 types */
1287 WARN("(%d): Invalid type\n", nObjType );
1288 break;
1290 return retval;
1294 /***********************************************************************
1295 * IsGDIObject (GDI.462)
1297 * returns type of object if valid (W95 system programming secrets p. 264-5)
1299 BOOL16 WINAPI IsGDIObject16( HGDIOBJ16 handle16 )
1301 UINT16 magic = 0;
1302 HGDIOBJ handle = HGDIOBJ_32( handle16 );
1304 GDIOBJHDR *object = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1305 if (object)
1307 magic = GDIMAGIC(object->wMagic) - PEN_MAGIC + 1;
1308 GDI_ReleaseObj( handle );
1310 return magic;
1314 /***********************************************************************
1315 * SetObjectOwner (GDI32.@)
1317 void WINAPI SetObjectOwner( HGDIOBJ handle, HANDLE owner )
1319 /* Nothing to do */
1323 /***********************************************************************
1324 * MakeObjectPrivate (GDI.463)
1326 * What does that mean ?
1327 * Some little docu can be found in "Undocumented Windows",
1328 * but this is basically useless.
1329 * At least we know that this flags the GDI object's wMagic
1330 * with 0x2000 (OBJECT_PRIVATE), so we just do it.
1331 * But Wine doesn't react on that yet.
1333 void WINAPI MakeObjectPrivate16( HGDIOBJ16 handle16, BOOL16 private )
1335 HGDIOBJ handle = HGDIOBJ_32( handle16 );
1336 GDIOBJHDR *ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1337 if (!ptr)
1339 ERR("invalid GDI object %p !\n", handle);
1340 return;
1342 ptr->wMagic |= OBJECT_PRIVATE;
1343 GDI_ReleaseObj( handle );
1347 /***********************************************************************
1348 * GdiFlush (GDI32.@)
1350 BOOL WINAPI GdiFlush(void)
1352 return TRUE; /* FIXME */
1356 /***********************************************************************
1357 * GdiGetBatchLimit (GDI32.@)
1359 DWORD WINAPI GdiGetBatchLimit(void)
1361 return 1; /* FIXME */
1365 /***********************************************************************
1366 * GdiSetBatchLimit (GDI32.@)
1368 DWORD WINAPI GdiSetBatchLimit( DWORD limit )
1370 return 1; /* FIXME */
1374 /***********************************************************************
1375 * GdiSeeGdiDo (GDI.452)
1377 DWORD WINAPI GdiSeeGdiDo16( WORD wReqType, WORD wParam1, WORD wParam2,
1378 WORD wParam3 )
1380 switch (wReqType)
1382 case 0x0001: /* LocalAlloc */
1383 return LOCAL_Alloc( GDI_HeapSel, wParam1, wParam3 );
1384 case 0x0002: /* LocalFree */
1385 return LOCAL_Free( GDI_HeapSel, wParam1 );
1386 case 0x0003: /* LocalCompact */
1387 return LOCAL_Compact( GDI_HeapSel, wParam3, 0 );
1388 case 0x0103: /* LocalHeap */
1389 return GDI_HeapSel;
1390 default:
1391 WARN("(wReqType=%04x): Unknown\n", wReqType);
1392 return ~0UL;
1396 /***********************************************************************
1397 * GdiSignalProc32 (GDI.610)
1399 WORD WINAPI GdiSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
1400 DWORD dwFlags, HMODULE16 hModule )
1402 return 0;
1405 /***********************************************************************
1406 * GdiInit2 (GDI.403)
1408 * See "Undocumented Windows"
1410 HANDLE16 WINAPI GdiInit216(
1411 HANDLE16 h1, /* [in] GDI object */
1412 HANDLE16 h2 /* [in] global data */
1415 FIXME("(%04x, %04x), stub.\n", h1, h2);
1416 if (h2 == 0xffff)
1417 return 0xffff; /* undefined return value */
1418 return h1; /* FIXME: should be the memory handle of h1 */
1421 /***********************************************************************
1422 * FinalGdiInit (GDI.405)
1424 void WINAPI FinalGdiInit16( HBRUSH16 hPattern /* [in] fill pattern of desktop */ )
1428 /***********************************************************************
1429 * GdiFreeResources (GDI.609)
1431 WORD WINAPI GdiFreeResources16( DWORD reserve )
1433 return (WORD)( (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
1434 (int)LOCAL_HeapSize( GDI_HeapSel ) );
1438 /*******************************************************************
1439 * GetColorAdjustment [GDI32.@]
1443 BOOL WINAPI GetColorAdjustment(HDC hdc, LPCOLORADJUSTMENT lpca)
1445 FIXME("GetColorAdjustment, stub\n");
1446 return 0;
1449 /*******************************************************************
1450 * GetMiterLimit [GDI32.@]
1454 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
1456 FIXME("GetMiterLimit, stub\n");
1457 return 0;
1460 /*******************************************************************
1461 * SetMiterLimit [GDI32.@]
1465 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
1467 FIXME("SetMiterLimit, stub\n");
1468 return 0;
1471 /*******************************************************************
1472 * GdiComment [GDI32.@]
1476 BOOL WINAPI GdiComment(HDC hdc, UINT cbSize, const BYTE *lpData)
1478 DC *dc = DC_GetDCPtr(hdc);
1479 BOOL ret = FALSE;
1480 if(dc)
1482 if (dc->funcs->pGdiComment)
1483 ret = dc->funcs->pGdiComment( dc->physDev, cbSize, lpData );
1485 GDI_ReleaseObj( hdc );
1486 return ret;
1489 /*******************************************************************
1490 * SetColorAdjustment [GDI32.@]
1494 BOOL WINAPI SetColorAdjustment(HDC hdc, const COLORADJUSTMENT* lpca)
1496 FIXME("SetColorAdjustment, stub\n");
1497 return 0;