- Implementation of HCR_GetExecuteCommandExW for internal use.
[wine.git] / objects / gdiobj.c
blob70b6929e4750637700582d6f445aca85c66043aa
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 "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
42 #define HGDIOBJ_32(h16) ((HGDIOBJ)(ULONG_PTR)(h16))
44 /***********************************************************************
45 * GDI stock objects
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 /* FIXME: these should perhaps be BS_HATCHED, at least for 1 bitperpixel */
53 static const LOGBRUSH LtGrayBrush = { BS_SOLID, RGB(192,192,192), 0 };
54 static const LOGBRUSH GrayBrush = { BS_SOLID, RGB(128,128,128), 0 };
56 /* This is BS_HATCHED, for 1 bitperpixel. This makes the spray work in pbrush */
57 /* See HatchBrushes in x11drv for the HS_DIAGCROSS+1 hack */
58 static const LOGBRUSH DkGrayBrush = { BS_HATCHED, RGB(0,0,0), (HS_DIAGCROSS+1) };
60 static const LOGPEN WhitePen = { PS_SOLID, { 0, 0 }, RGB(255,255,255) };
61 static const LOGPEN BlackPen = { PS_SOLID, { 0, 0 }, RGB(0,0,0) };
62 static const LOGPEN NullPen = { PS_NULL, { 0, 0 }, 0 };
64 static const LOGBRUSH DCBrush = { BS_SOLID, RGB(255,255,255), 0 };
65 static const LOGPEN DCPen = { PS_SOLID, { 0, 0 }, RGB(0,0,0) };
67 /* reserve one extra entry for the stock default bitmap */
68 /* this is what Windows does too */
69 #define NB_STOCK_OBJECTS (STOCK_LAST+2)
71 static HGDIOBJ stock_objects[NB_STOCK_OBJECTS];
73 static SYSLEVEL GDI_level;
74 static CRITICAL_SECTION_DEBUG critsect_debug =
76 0, 0, &GDI_level.crst,
77 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
78 0, 0, { 0, (DWORD)(__FILE__ ": GDI_level") }
80 static SYSLEVEL GDI_level = { { &critsect_debug, -1, 0, 0, 0, 0 }, 3 };
82 static WORD GDI_HeapSel;
84 inline static BOOL get_bool(char *buffer)
86 return (buffer[0] == 'y' || buffer[0] == 'Y' ||
87 buffer[0] == 't' || buffer[0] == 'T' ||
88 buffer[0] == '1');
92 /****************************************************************************
94 * language-independent stock fonts
98 static const LOGFONTW OEMFixedFont =
99 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, OEM_CHARSET,
100 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} };
102 static const LOGFONTW AnsiFixedFont =
103 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
104 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} };
106 static const LOGFONTW AnsiVarFont =
107 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
108 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
109 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'} };
111 /******************************************************************************
113 * language-dependent stock fonts
115 * 'ANSI' charset and 'DEFAULT' charset is not same.
116 * The chars in CP_ACP should be drawn with 'DEFAULT' charset.
117 * 'ANSI' charset seems to be identical with ISO-8859-1.
118 * 'DEFAULT' charset is a language-dependent charset.
120 * 'System' font seems to be an alias for language-dependent font.
124 * language-dependenet stock fonts for all known charsets
125 * please see TranslateCharsetInfo (objects/font.c) and
126 * CharsetBindingInfo (graphics/x11drv/xfont.c),
127 * and modify entries for your language if needed.
129 struct DefaultFontInfo
131 UINT charset;
132 LOGFONTW SystemFont;
133 LOGFONTW DeviceDefaultFont;
134 LOGFONTW SystemFixedFont;
135 LOGFONTW DefaultGuiFont;
138 static const struct DefaultFontInfo default_fonts[] =
140 { ANSI_CHARSET,
141 { /* System */
142 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
143 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
144 {'S','y','s','t','e','m','\0'}
146 { /* Device Default */
147 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
148 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
149 {'\0'}
151 { /* System Fixed */
152 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
153 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
154 {'\0'}
156 { /* DefaultGuiFont */
157 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
158 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
159 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
162 { EASTEUROPE_CHARSET,
163 { /* System */
164 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
165 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
166 {'S','y','s','t','e','m','\0'}
168 { /* Device Default */
169 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
170 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
171 {'\0'}
173 { /* System Fixed */
174 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
175 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
176 {'\0'}
178 { /* DefaultGuiFont */
179 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
180 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
181 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
184 { RUSSIAN_CHARSET,
185 { /* System */
186 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
187 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
188 {'S','y','s','t','e','m','\0'}
190 { /* Device Default */
191 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
192 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
193 {'\0'}
195 { /* System Fixed */
196 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
197 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
198 {'\0'}
200 { /* DefaultGuiFont */
201 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
202 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
203 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
206 { GREEK_CHARSET,
207 { /* System */
208 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
209 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
210 {'S','y','s','t','e','m','\0'}
212 { /* Device Default */
213 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
214 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
215 {'\0'}
217 { /* System Fixed */
218 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
219 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
220 {'\0'}
222 { /* DefaultGuiFont */
223 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
224 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
225 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
228 { TURKISH_CHARSET,
229 { /* System */
230 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
231 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
232 {'S','y','s','t','e','m','\0'}
234 { /* Device Default */
235 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
236 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
237 {'\0'}
239 { /* System Fixed */
240 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
241 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
242 {'\0'}
244 { /* DefaultGuiFont */
245 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
246 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
247 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
250 { HEBREW_CHARSET,
251 { /* System */
252 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
253 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
254 {'S','y','s','t','e','m','\0'}
256 { /* Device Default */
257 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
258 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
259 {'\0'}
261 { /* System Fixed */
262 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
263 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
264 {'\0'}
266 { /* DefaultGuiFont */
267 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
268 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
269 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
272 { ARABIC_CHARSET,
273 { /* System */
274 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
275 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
276 {'S','y','s','t','e','m','\0'}
278 { /* Device Default */
279 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
280 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
281 {'\0'}
283 { /* System Fixed */
284 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
285 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
286 {'\0'}
288 { /* DefaultGuiFont */
289 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
290 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
291 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
294 { BALTIC_CHARSET,
295 { /* System */
296 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
297 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
298 {'S','y','s','t','e','m','\0'}
300 { /* Device Default */
301 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
302 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
303 {'\0'}
305 { /* System Fixed */
306 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
307 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
308 {'\0'}
310 { /* DefaultGuiFont */
311 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
312 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
313 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
316 { THAI_CHARSET,
317 { /* System */
318 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
319 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
320 {'S','y','s','t','e','m','\0'}
322 { /* Device Default */
323 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
324 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
325 {'\0'}
327 { /* System Fixed */
328 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
329 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
330 {'\0'}
332 { /* DefaultGuiFont */
333 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
334 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
335 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
338 { SHIFTJIS_CHARSET,
339 { /* System */
340 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
341 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
342 {'S','y','s','t','e','m','\0'}
344 { /* Device Default */
345 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
346 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
347 {'\0'}
349 { /* System Fixed */
350 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
351 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
352 {'\0'}
354 { /* DefaultGuiFont */
355 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
356 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
357 {'M','S',' ','P','G','o','t','h','i','c','\0'}
360 { GB2312_CHARSET,
361 { /* System */
362 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
363 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
364 {'S','y','s','t','e','m','\0'}
366 { /* Device Default */
367 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
368 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
369 {'\0'}
371 { /* System Fixed */
372 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
373 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
374 {'\0'}
376 { /* DefaultGuiFont */
377 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
378 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
379 {'M','S',' ','S','o','n','g','\0'} /* FIXME: Is this correct? */
382 { HANGEUL_CHARSET,
383 { /* System */
384 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
385 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
386 {'S','y','s','t','e','m','\0'}
388 { /* Device Default */
389 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
390 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
391 {'\0'}
393 { /* System Fixed */
394 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
395 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
396 {'\0'}
398 { /* DefaultGuiFont */
399 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
400 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
401 {'G','u','l','i','m'},
404 { CHINESEBIG5_CHARSET,
405 { /* System */
406 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
407 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
408 {'S','y','s','t','e','m','\0'}
410 { /* Device Default */
411 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
412 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
413 {'\0'}
415 { /* System Fixed */
416 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
417 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
418 {'\0'}
420 { /* DefaultGuiFont */
421 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
422 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
423 {'\0'} /* FIXME - what is the native font??? */
426 { JOHAB_CHARSET,
427 { /* System */
428 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
429 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
430 {'S','y','s','t','e','m','\0'}
432 { /* Device Default */
433 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
434 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
435 {'\0'}
437 { /* System Fixed */
438 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
439 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
440 {'\0'}
442 { /* DefaultGuiFont */
443 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
444 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
445 {'M','S',' ','M','i','n','g','l','i','u','\0'} /* FIXME: Is this correct? */
451 /******************************************************************************
452 * get_default_fonts
454 static const struct DefaultFontInfo* get_default_fonts(UINT charset)
456 int n;
458 for(n=0;n<(sizeof(default_fonts)/sizeof(default_fonts[0]));n++)
460 if ( default_fonts[n].charset == charset )
461 return &default_fonts[n];
464 FIXME( "unhandled charset 0x%08x - use ANSI_CHARSET for default stock objects\n", charset );
465 return &default_fonts[0];
469 /******************************************************************************
470 * get_default_charset (internal)
472 * get the language-dependent charset that can handle CP_ACP correctly.
474 static UINT get_default_charset( void )
476 CHARSETINFO csi;
477 UINT uACP;
479 uACP = GetACP();
480 csi.ciCharset = ANSI_CHARSET;
481 if ( ! TranslateCharsetInfo( (LPDWORD)uACP, &csi, TCI_SRCCODEPAGE ) )
483 FIXME( "unhandled codepage %u - use ANSI_CHARSET for default stock objects\n", uACP );
484 return ANSI_CHARSET;
487 return csi.ciCharset;
491 /******************************************************************************
492 * create_stock_font
494 static HFONT create_stock_font( char const *fontName, const LOGFONTW *font, HKEY hkey )
496 LOGFONTW lf;
497 char key[256];
498 char buffer[MAX_PATH];
499 DWORD type, count;
501 if (!hkey) return CreateFontIndirectW( font );
503 lf = *font;
504 sprintf(key, "%s.Height", fontName);
505 count = sizeof(buffer);
506 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
507 lf.lfHeight = atoi(buffer);
509 sprintf(key, "%s.Bold", fontName);
510 count = sizeof(buffer);
511 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
512 lf.lfWeight = get_bool(buffer) ? FW_BOLD : FW_NORMAL;
514 sprintf(key, "%s.Italic", fontName);
515 count = sizeof(buffer);
516 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
517 lf.lfItalic = get_bool(buffer);
519 sprintf(key, "%s.Underline", fontName);
520 count = sizeof(buffer);
521 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
522 lf.lfUnderline = get_bool(buffer);
524 sprintf(key, "%s.StrikeOut", fontName);
525 count = sizeof(buffer);
526 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
527 lf.lfStrikeOut = get_bool(buffer);
528 return CreateFontIndirectW( &lf );
532 #define TRACE_SEC(handle,text) \
533 TRACE("(%p): " text " %ld\n", (handle), GDI_level.crst.RecursionCount)
536 /***********************************************************************
537 * inc_ref_count
539 * Increment the reference count of a GDI object.
541 inline static void inc_ref_count( HGDIOBJ handle )
543 GDIOBJHDR *header;
545 if ((header = GDI_GetObjPtr( handle, MAGIC_DONTCARE )))
547 header->dwCount++;
548 GDI_ReleaseObj( handle );
553 /***********************************************************************
554 * dec_ref_count
556 * Decrement the reference count of a GDI object.
558 inline static void dec_ref_count( HGDIOBJ handle )
560 GDIOBJHDR *header;
562 if ((header = GDI_GetObjPtr( handle, MAGIC_DONTCARE )))
564 if (header->dwCount) header->dwCount--;
565 if (header->dwCount != 0x80000000) GDI_ReleaseObj( handle );
566 else
568 /* handle delayed DeleteObject*/
569 header->dwCount = 0;
570 GDI_ReleaseObj( handle );
571 TRACE( "executing delayed DeleteObject for %p\n", handle );
572 DeleteObject( handle );
578 /***********************************************************************
579 * GDI_Init
581 * GDI initialization.
583 BOOL GDI_Init(void)
585 HINSTANCE16 instance;
586 HKEY hkey;
587 GDIOBJHDR *ptr;
588 const struct DefaultFontInfo* deffonts;
589 int i;
591 if (RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Tweak.Fonts", &hkey))
592 hkey = 0;
594 /* create GDI heap */
595 if ((instance = LoadLibrary16( "GDI.EXE" )) >= 32) GDI_HeapSel = instance | 7;
597 /* create stock objects */
598 stock_objects[WHITE_BRUSH] = CreateBrushIndirect( &WhiteBrush );
599 stock_objects[LTGRAY_BRUSH] = CreateBrushIndirect( &LtGrayBrush );
600 stock_objects[GRAY_BRUSH] = CreateBrushIndirect( &GrayBrush );
601 stock_objects[DKGRAY_BRUSH] = CreateBrushIndirect( &DkGrayBrush );
602 stock_objects[BLACK_BRUSH] = CreateBrushIndirect( &BlackBrush );
603 stock_objects[NULL_BRUSH] = CreateBrushIndirect( &NullBrush );
605 stock_objects[WHITE_PEN] = CreatePenIndirect( &WhitePen );
606 stock_objects[BLACK_PEN] = CreatePenIndirect( &BlackPen );
607 stock_objects[NULL_PEN] = CreatePenIndirect( &NullPen );
609 stock_objects[DEFAULT_PALETTE] = PALETTE_Init();
610 stock_objects[DEFAULT_BITMAP] = CreateBitmap( 1, 1, 1, 1, NULL );
612 /* language-independent stock fonts */
613 stock_objects[OEM_FIXED_FONT] = create_stock_font( "OEMFixed", &OEMFixedFont, hkey );
614 stock_objects[ANSI_FIXED_FONT] = create_stock_font( "AnsiFixed", &AnsiFixedFont, hkey );
615 stock_objects[ANSI_VAR_FONT] = create_stock_font( "AnsiVar", &AnsiVarFont, hkey );
617 /* language-dependent stock fonts */
618 deffonts = get_default_fonts(get_default_charset());
619 stock_objects[SYSTEM_FONT] = create_stock_font( "System", &deffonts->SystemFont, hkey );
620 stock_objects[DEVICE_DEFAULT_FONT] = create_stock_font( "DeviceDefault", &deffonts->DeviceDefaultFont, hkey );
621 stock_objects[SYSTEM_FIXED_FONT] = create_stock_font( "SystemFixed", &deffonts->SystemFixedFont, hkey );
622 stock_objects[DEFAULT_GUI_FONT] = create_stock_font( "DefaultGui", &deffonts->DefaultGuiFont, hkey );
624 stock_objects[DC_BRUSH] = CreateBrushIndirect( &DCBrush );
625 stock_objects[DC_PEN] = CreatePenIndirect( &DCPen );
627 /* clear the NOSYSTEM bit on all stock objects*/
628 for (i = 0; i < NB_STOCK_OBJECTS; i++)
630 if (!stock_objects[i])
632 if (i == 9) continue; /* there's no stock object 9 */
633 ERR( "could not create stock object %d\n", i );
634 return FALSE;
636 ptr = GDI_GetObjPtr( stock_objects[i], MAGIC_DONTCARE );
637 ptr->wMagic &= ~OBJECT_NOSYSTEM;
638 GDI_ReleaseObj( stock_objects[i] );
641 if (hkey) RegCloseKey( hkey );
643 WineEngInit();
645 return TRUE;
648 #define FIRST_LARGE_HANDLE 16
649 #define MAX_LARGE_HANDLES ((GDI_HEAP_SIZE >> 2) - FIRST_LARGE_HANDLE)
650 static GDIOBJHDR *large_handles[MAX_LARGE_HANDLES];
651 static int next_large_handle;
653 /***********************************************************************
654 * alloc_large_heap
656 * Allocate a GDI handle from the large heap. Helper for GDI_AllocObject
658 inline static GDIOBJHDR *alloc_large_heap( WORD size, HGDIOBJ *handle )
660 int i;
661 GDIOBJHDR *obj;
663 for (i = next_large_handle + 1; i < MAX_LARGE_HANDLES; i++)
664 if (!large_handles[i]) goto found;
665 for (i = 0; i <= next_large_handle; i++)
666 if (!large_handles[i]) goto found;
667 *handle = 0;
668 return NULL;
670 found:
671 if ((obj = HeapAlloc( GetProcessHeap(), 0, size )))
673 large_handles[i] = obj;
674 *handle = (HGDIOBJ)(ULONG_PTR)((i + FIRST_LARGE_HANDLE) << 2);
675 next_large_handle = i;
677 return obj;
681 /***********************************************************************
682 * GDI_AllocObject
684 void *GDI_AllocObject( WORD size, WORD magic, HGDIOBJ *handle, const struct gdi_obj_funcs *funcs )
686 GDIOBJHDR *obj;
687 HLOCAL16 hlocal;
689 _EnterSysLevel( &GDI_level );
690 switch(magic)
692 default:
693 if (GDI_HeapSel)
695 if (!(hlocal = LOCAL_Alloc( GDI_HeapSel, LMEM_MOVEABLE, size ))) goto error;
696 assert( hlocal & 2 );
697 obj = (GDIOBJHDR *)LOCAL_Lock( GDI_HeapSel, hlocal );
698 *handle = (HGDIOBJ)(ULONG_PTR)hlocal;
699 break;
701 /* fall through */
702 case DC_MAGIC:
703 case DISABLED_DC_MAGIC:
704 case META_DC_MAGIC:
705 case METAFILE_MAGIC:
706 case METAFILE_DC_MAGIC:
707 case ENHMETAFILE_MAGIC:
708 case ENHMETAFILE_DC_MAGIC:
709 case MEMORY_DC_MAGIC:
710 case BITMAP_MAGIC:
711 case PALETTE_MAGIC:
712 if (!(obj = alloc_large_heap( size, handle ))) goto error;
713 break;
716 obj->hNext = 0;
717 obj->wMagic = magic|OBJECT_NOSYSTEM;
718 obj->dwCount = 0;
719 obj->funcs = funcs;
720 obj->hdcs = NULL;
722 TRACE_SEC( *handle, "enter" );
723 return obj;
725 error:
726 _LeaveSysLevel( &GDI_level );
727 *handle = 0;
728 return NULL;
732 /***********************************************************************
733 * GDI_ReallocObject
735 * The object ptr must have been obtained with GDI_GetObjPtr.
736 * The new pointer must be released with GDI_ReleaseObj.
738 void *GDI_ReallocObject( WORD size, HGDIOBJ handle, void *object )
740 HGDIOBJ new_handle;
742 if ((UINT_PTR)handle & 2) /* GDI heap handle */
744 HLOCAL16 h = LOWORD(handle);
745 LOCAL_Unlock( GDI_HeapSel, h );
746 if ((new_handle = (HGDIOBJ)(ULONG_PTR)LOCAL_ReAlloc( GDI_HeapSel, h, size, LMEM_MOVEABLE )))
748 assert( new_handle == handle ); /* moveable handle cannot change */
749 return LOCAL_Lock( GDI_HeapSel, h );
752 else
754 int i = ((ULONG_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
755 if (i >= 0 && i < MAX_LARGE_HANDLES && large_handles[i])
757 void *new_ptr = HeapReAlloc( GetProcessHeap(), 0, large_handles[i], size );
758 if (new_ptr)
760 large_handles[i] = new_ptr;
761 return new_ptr;
764 else ERR( "Invalid handle %p\n", handle );
766 TRACE_SEC( handle, "leave" );
767 _LeaveSysLevel( &GDI_level );
768 return NULL;
772 /***********************************************************************
773 * GDI_FreeObject
775 BOOL GDI_FreeObject( HGDIOBJ handle, void *ptr )
777 GDIOBJHDR *object = ptr;
779 object->wMagic = 0; /* Mark it as invalid */
780 object->funcs = NULL;
781 if ((UINT_PTR)handle & 2) /* GDI heap handle */
783 HLOCAL16 h = LOWORD(handle);
784 LOCAL_Unlock( GDI_HeapSel, h );
785 LOCAL_Free( GDI_HeapSel, h );
787 else /* large heap handle */
789 int i = ((ULONG_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
790 if (i >= 0 && i < MAX_LARGE_HANDLES && large_handles[i])
792 HeapFree( GetProcessHeap(), 0, large_handles[i] );
793 large_handles[i] = NULL;
795 else ERR( "Invalid handle %p\n", handle );
797 TRACE_SEC( handle, "leave" );
798 _LeaveSysLevel( &GDI_level );
799 return TRUE;
803 /***********************************************************************
804 * GDI_GetObjPtr
806 * Return a pointer to the GDI object associated to the handle.
807 * Return NULL if the object has the wrong magic number.
808 * The object must be released with GDI_ReleaseObj.
810 void *GDI_GetObjPtr( HGDIOBJ handle, WORD magic )
812 GDIOBJHDR *ptr = NULL;
814 _EnterSysLevel( &GDI_level );
816 if ((UINT_PTR)handle & 2) /* GDI heap handle */
818 HLOCAL16 h = LOWORD(handle);
819 ptr = (GDIOBJHDR *)LOCAL_Lock( GDI_HeapSel, h );
820 if (ptr)
822 if (((magic != MAGIC_DONTCARE) && (GDIMAGIC(ptr->wMagic) != magic)) ||
823 (GDIMAGIC(ptr->wMagic) < FIRST_MAGIC) ||
824 (GDIMAGIC(ptr->wMagic) > LAST_MAGIC))
826 LOCAL_Unlock( GDI_HeapSel, h );
827 ptr = NULL;
831 else /* large heap handle */
833 int i = ((UINT_PTR)handle >> 2) - FIRST_LARGE_HANDLE;
834 if (i >= 0 && i < MAX_LARGE_HANDLES)
836 ptr = large_handles[i];
837 if (ptr && (magic != MAGIC_DONTCARE) && (GDIMAGIC(ptr->wMagic) != magic)) ptr = NULL;
841 if (!ptr)
843 _LeaveSysLevel( &GDI_level );
844 SetLastError( ERROR_INVALID_HANDLE );
845 WARN( "Invalid handle %p\n", handle );
847 else TRACE_SEC( handle, "enter" );
849 return ptr;
853 /***********************************************************************
854 * GDI_ReleaseObj
857 void GDI_ReleaseObj( HGDIOBJ handle )
859 if ((UINT_PTR)handle & 2) LOCAL_Unlock( GDI_HeapSel, LOWORD(handle) );
860 TRACE_SEC( handle, "leave" );
861 _LeaveSysLevel( &GDI_level );
865 /***********************************************************************
866 * GDI_CheckNotLock
868 void GDI_CheckNotLock(void)
870 _CheckNotSysLevel( &GDI_level );
874 /***********************************************************************
875 * DeleteObject (GDI32.@)
877 BOOL WINAPI DeleteObject( HGDIOBJ obj )
879 /* Check if object is valid */
881 GDIOBJHDR * header;
882 if (HIWORD(obj)) return FALSE;
884 if (!(header = GDI_GetObjPtr( obj, MAGIC_DONTCARE ))) return FALSE;
886 if (!(header->wMagic & OBJECT_NOSYSTEM)
887 && (header->wMagic >= FIRST_MAGIC) && (header->wMagic <= LAST_MAGIC))
889 TRACE("Preserving system object %p\n", obj);
890 GDI_ReleaseObj( obj );
891 return TRUE;
894 while (header->hdcs)
896 DC *dc = DC_GetDCPtr(header->hdcs->hdc);
897 struct hdc_list *tmp;
899 TRACE("hdc %p has interest in %p\n", header->hdcs->hdc, obj);
900 if(dc)
902 if(dc->funcs->pDeleteObject)
903 dc->funcs->pDeleteObject( dc->physDev, obj );
904 GDI_ReleaseObj( header->hdcs->hdc );
906 tmp = header->hdcs;
907 header->hdcs = header->hdcs->next;
908 HeapFree(GetProcessHeap(), 0, tmp);
911 if (header->dwCount)
913 TRACE("delayed for %p because object in use, count %ld\n", obj, header->dwCount );
914 header->dwCount |= 0x80000000; /* mark for delete */
915 GDI_ReleaseObj( obj );
916 return TRUE;
919 TRACE("%p\n", obj );
921 /* Delete object */
923 if (header->funcs && header->funcs->pDeleteObject)
924 return header->funcs->pDeleteObject( obj, header );
926 GDI_ReleaseObj( obj );
927 return FALSE;
930 /***********************************************************************
931 * GDI_hdc_using_object
933 * Call this if the dc requires DeleteObject notification
935 BOOL GDI_hdc_using_object(HGDIOBJ obj, HDC hdc)
937 GDIOBJHDR * header;
938 struct hdc_list **pphdc;
940 TRACE("obj %p hdc %p\n", obj, hdc);
942 if (!(header = GDI_GetObjPtr( obj, MAGIC_DONTCARE ))) return FALSE;
944 if (!(header->wMagic & OBJECT_NOSYSTEM) &&
945 (header->wMagic >= FIRST_MAGIC) && (header->wMagic <= LAST_MAGIC))
947 GDI_ReleaseObj(obj);
948 return FALSE;
951 for(pphdc = &header->hdcs; *pphdc; pphdc = &(*pphdc)->next)
952 if((*pphdc)->hdc == hdc)
953 break;
955 if(!*pphdc) {
956 *pphdc = HeapAlloc(GetProcessHeap(), 0, sizeof(**pphdc));
957 (*pphdc)->hdc = hdc;
958 (*pphdc)->next = NULL;
961 GDI_ReleaseObj(obj);
962 return TRUE;
965 /***********************************************************************
966 * GDI_hdc_not_using_object
969 BOOL GDI_hdc_not_using_object(HGDIOBJ obj, HDC hdc)
971 GDIOBJHDR * header;
972 struct hdc_list *phdc, **prev;
974 TRACE("obj %p hdc %p\n", obj, hdc);
976 if (!(header = GDI_GetObjPtr( obj, MAGIC_DONTCARE ))) return FALSE;
978 if (!(header->wMagic & OBJECT_NOSYSTEM) &&
979 (header->wMagic >= FIRST_MAGIC) && (header->wMagic <= LAST_MAGIC))
981 GDI_ReleaseObj(obj);
982 return FALSE;
985 phdc = header->hdcs;
986 prev = &header->hdcs;
988 while(phdc) {
989 if(phdc->hdc == hdc) {
990 *prev = phdc->next;
991 HeapFree(GetProcessHeap(), 0, phdc);
992 phdc = *prev;
993 } else {
994 prev = &phdc->next;
995 phdc = phdc->next;
999 GDI_ReleaseObj(obj);
1000 return TRUE;
1003 /***********************************************************************
1004 * GetStockObject (GDI32.@)
1006 HGDIOBJ WINAPI GetStockObject( INT obj )
1008 HGDIOBJ ret;
1009 if ((obj < 0) || (obj >= NB_STOCK_OBJECTS)) return 0;
1010 ret = stock_objects[obj];
1011 TRACE("returning %p\n", ret );
1012 return ret;
1016 /***********************************************************************
1017 * GetObject (GDI.82)
1019 INT16 WINAPI GetObject16( HANDLE16 handle16, INT16 count, LPVOID buffer )
1021 GDIOBJHDR * ptr;
1022 HGDIOBJ handle = HGDIOBJ_32( handle16 );
1023 INT16 result = 0;
1025 TRACE("%p %d %p\n", handle, count, buffer );
1026 if (!count) return 0;
1028 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
1030 if (ptr->funcs && ptr->funcs->pGetObject16)
1031 result = ptr->funcs->pGetObject16( handle, ptr, count, buffer );
1032 else
1033 SetLastError( ERROR_INVALID_HANDLE );
1035 GDI_ReleaseObj( handle );
1036 return result;
1040 /***********************************************************************
1041 * GetObjectA (GDI32.@)
1043 INT WINAPI GetObjectA( HANDLE handle, INT count, LPVOID buffer )
1045 GDIOBJHDR * ptr;
1046 INT result = 0;
1047 TRACE("%p %d %p\n", handle, count, buffer );
1049 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
1051 if (ptr->funcs && ptr->funcs->pGetObjectA)
1052 result = ptr->funcs->pGetObjectA( handle, ptr, count, buffer );
1053 else
1054 SetLastError( ERROR_INVALID_HANDLE );
1056 GDI_ReleaseObj( handle );
1057 return result;
1060 /***********************************************************************
1061 * GetObjectW (GDI32.@)
1063 INT WINAPI GetObjectW( HANDLE handle, INT count, LPVOID buffer )
1065 GDIOBJHDR * ptr;
1066 INT result = 0;
1067 TRACE("%p %d %p\n", handle, count, buffer );
1069 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
1071 if (ptr->funcs && ptr->funcs->pGetObjectW)
1072 result = ptr->funcs->pGetObjectW( handle, ptr, count, buffer );
1073 else
1074 SetLastError( ERROR_INVALID_HANDLE );
1076 GDI_ReleaseObj( handle );
1077 return result;
1080 /***********************************************************************
1081 * GetObjectType (GDI32.@)
1083 DWORD WINAPI GetObjectType( HANDLE handle )
1085 GDIOBJHDR * ptr;
1086 INT result = 0;
1087 TRACE("%p\n", handle );
1089 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
1091 switch(GDIMAGIC(ptr->wMagic))
1093 case PEN_MAGIC:
1094 result = OBJ_PEN;
1095 break;
1096 case BRUSH_MAGIC:
1097 result = OBJ_BRUSH;
1098 break;
1099 case BITMAP_MAGIC:
1100 result = OBJ_BITMAP;
1101 break;
1102 case FONT_MAGIC:
1103 result = OBJ_FONT;
1104 break;
1105 case PALETTE_MAGIC:
1106 result = OBJ_PAL;
1107 break;
1108 case REGION_MAGIC:
1109 result = OBJ_REGION;
1110 break;
1111 case DC_MAGIC:
1112 result = OBJ_DC;
1113 break;
1114 case META_DC_MAGIC:
1115 result = OBJ_METADC;
1116 break;
1117 case METAFILE_MAGIC:
1118 result = OBJ_METAFILE;
1119 break;
1120 case METAFILE_DC_MAGIC:
1121 result = OBJ_METADC;
1122 break;
1123 case ENHMETAFILE_MAGIC:
1124 result = OBJ_ENHMETAFILE;
1125 break;
1126 case ENHMETAFILE_DC_MAGIC:
1127 result = OBJ_ENHMETADC;
1128 break;
1129 case MEMORY_DC_MAGIC:
1130 result = OBJ_MEMDC;
1131 break;
1132 default:
1133 FIXME("Magic %04x not implemented\n", GDIMAGIC(ptr->wMagic) );
1134 break;
1136 GDI_ReleaseObj( handle );
1137 return result;
1140 /***********************************************************************
1141 * GetCurrentObject (GDI32.@)
1143 HANDLE WINAPI GetCurrentObject(HDC hdc,UINT type)
1145 HANDLE ret = 0;
1146 DC * dc = DC_GetDCPtr( hdc );
1148 if (dc)
1150 switch (type) {
1151 case OBJ_PEN: ret = dc->hPen; break;
1152 case OBJ_BRUSH: ret = dc->hBrush; break;
1153 case OBJ_PAL: ret = dc->hPalette; break;
1154 case OBJ_FONT: ret = dc->hFont; break;
1155 case OBJ_BITMAP: ret = dc->hBitmap; break;
1156 default:
1157 /* the SDK only mentions those above */
1158 FIXME("(%p,%d): unknown type.\n",hdc,type);
1159 break;
1161 GDI_ReleaseObj( hdc );
1163 return ret;
1167 /***********************************************************************
1168 * SelectObject (GDI32.@)
1170 HGDIOBJ WINAPI SelectObject( HDC hdc, HGDIOBJ handle )
1172 HGDIOBJ ret = 0;
1173 GDIOBJHDR *header = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1174 if (!header) return 0;
1176 TRACE("hdc=%p %p\n", hdc, handle );
1178 if (header->funcs && header->funcs->pSelectObject)
1180 ret = header->funcs->pSelectObject( handle, header, hdc );
1181 if (ret && ret != handle && (INT)ret > COMPLEXREGION)
1183 inc_ref_count( handle );
1184 dec_ref_count( ret );
1187 GDI_ReleaseObj( handle );
1188 return ret;
1192 /***********************************************************************
1193 * UnrealizeObject (GDI32.@)
1195 BOOL WINAPI UnrealizeObject( HGDIOBJ obj )
1197 BOOL result = TRUE;
1198 /* Check if object is valid */
1200 GDIOBJHDR * header = GDI_GetObjPtr( obj, MAGIC_DONTCARE );
1201 if (!header) return FALSE;
1203 TRACE("%p\n", obj );
1205 /* Unrealize object */
1207 if (header->funcs && header->funcs->pUnrealizeObject)
1208 result = header->funcs->pUnrealizeObject( obj, header );
1210 GDI_ReleaseObj( obj );
1211 return result;
1215 /* Solid colors to enumerate */
1216 static const COLORREF solid_colors[] =
1217 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
1218 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
1219 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
1220 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
1221 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
1222 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
1223 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
1224 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
1228 /***********************************************************************
1229 * EnumObjects (GDI32.@)
1231 INT WINAPI EnumObjects( HDC hdc, INT nObjType,
1232 GOBJENUMPROC lpEnumFunc, LPARAM lParam )
1234 INT i, retval = 0;
1235 LOGPEN pen;
1236 LOGBRUSH brush;
1238 TRACE("%p %d %p %08lx\n", hdc, nObjType, lpEnumFunc, lParam );
1239 switch(nObjType)
1241 case OBJ_PEN:
1242 /* Enumerate solid pens */
1243 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1245 pen.lopnStyle = PS_SOLID;
1246 pen.lopnWidth.x = 1;
1247 pen.lopnWidth.y = 0;
1248 pen.lopnColor = solid_colors[i];
1249 retval = lpEnumFunc( &pen, lParam );
1250 TRACE("solid pen %08lx, ret=%d\n",
1251 solid_colors[i], retval);
1252 if (!retval) break;
1254 break;
1256 case OBJ_BRUSH:
1257 /* Enumerate solid brushes */
1258 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1260 brush.lbStyle = BS_SOLID;
1261 brush.lbColor = solid_colors[i];
1262 brush.lbHatch = 0;
1263 retval = lpEnumFunc( &brush, lParam );
1264 TRACE("solid brush %08lx, ret=%d\n",
1265 solid_colors[i], retval);
1266 if (!retval) break;
1269 /* Now enumerate hatched brushes */
1270 if (retval) for (i = HS_HORIZONTAL; i <= HS_DIAGCROSS; i++)
1272 brush.lbStyle = BS_HATCHED;
1273 brush.lbColor = RGB(0,0,0);
1274 brush.lbHatch = i;
1275 retval = lpEnumFunc( &brush, lParam );
1276 TRACE("hatched brush %d, ret=%d\n",
1277 i, retval);
1278 if (!retval) break;
1280 break;
1282 default:
1283 /* FIXME: implement Win32 types */
1284 WARN("(%d): Invalid type\n", nObjType );
1285 break;
1287 return retval;
1291 /***********************************************************************
1292 * IsGDIObject (GDI.462)
1294 * returns type of object if valid (W95 system programming secrets p. 264-5)
1296 BOOL16 WINAPI IsGDIObject16( HGDIOBJ16 handle16 )
1298 UINT16 magic = 0;
1299 HGDIOBJ handle = HGDIOBJ_32( handle16 );
1301 GDIOBJHDR *object = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1302 if (object)
1304 magic = GDIMAGIC(object->wMagic) - PEN_MAGIC + 1;
1305 GDI_ReleaseObj( handle );
1307 return magic;
1311 /***********************************************************************
1312 * SetObjectOwner (GDI32.@)
1314 void WINAPI SetObjectOwner( HGDIOBJ handle, HANDLE owner )
1316 /* Nothing to do */
1320 /***********************************************************************
1321 * MakeObjectPrivate (GDI.463)
1323 * What does that mean ?
1324 * Some little docu can be found in "Undocumented Windows",
1325 * but this is basically useless.
1326 * At least we know that this flags the GDI object's wMagic
1327 * with 0x2000 (OBJECT_PRIVATE), so we just do it.
1328 * But Wine doesn't react on that yet.
1330 void WINAPI MakeObjectPrivate16( HGDIOBJ16 handle16, BOOL16 private )
1332 HGDIOBJ handle = HGDIOBJ_32( handle16 );
1333 GDIOBJHDR *ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1334 if (!ptr)
1336 ERR("invalid GDI object %p !\n", handle);
1337 return;
1339 ptr->wMagic |= OBJECT_PRIVATE;
1340 GDI_ReleaseObj( handle );
1344 /***********************************************************************
1345 * GdiFlush (GDI32.@)
1347 BOOL WINAPI GdiFlush(void)
1349 return TRUE; /* FIXME */
1353 /***********************************************************************
1354 * GdiGetBatchLimit (GDI32.@)
1356 DWORD WINAPI GdiGetBatchLimit(void)
1358 return 1; /* FIXME */
1362 /***********************************************************************
1363 * GdiSetBatchLimit (GDI32.@)
1365 DWORD WINAPI GdiSetBatchLimit( DWORD limit )
1367 return 1; /* FIXME */
1371 /***********************************************************************
1372 * GdiSeeGdiDo (GDI.452)
1374 DWORD WINAPI GdiSeeGdiDo16( WORD wReqType, WORD wParam1, WORD wParam2,
1375 WORD wParam3 )
1377 switch (wReqType)
1379 case 0x0001: /* LocalAlloc */
1380 return LOCAL_Alloc( GDI_HeapSel, wParam1, wParam3 );
1381 case 0x0002: /* LocalFree */
1382 return LOCAL_Free( GDI_HeapSel, wParam1 );
1383 case 0x0003: /* LocalCompact */
1384 return LOCAL_Compact( GDI_HeapSel, wParam3, 0 );
1385 case 0x0103: /* LocalHeap */
1386 return GDI_HeapSel;
1387 default:
1388 WARN("(wReqType=%04x): Unknown\n", wReqType);
1389 return (DWORD)-1;
1393 /***********************************************************************
1394 * GdiSignalProc32 (GDI.610)
1396 WORD WINAPI GdiSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
1397 DWORD dwFlags, HMODULE16 hModule )
1399 return 0;
1402 /***********************************************************************
1403 * GdiInit2 (GDI.403)
1405 * See "Undocumented Windows"
1407 HANDLE16 WINAPI GdiInit216(
1408 HANDLE16 h1, /* [in] GDI object */
1409 HANDLE16 h2 /* [in] global data */
1412 FIXME("(%04x, %04x), stub.\n", h1, h2);
1413 if (h2 == 0xffff)
1414 return 0xffff; /* undefined return value */
1415 return h1; /* FIXME: should be the memory handle of h1 */
1418 /***********************************************************************
1419 * FinalGdiInit (GDI.405)
1421 void WINAPI FinalGdiInit16( HBRUSH16 hPattern /* [in] fill pattern of desktop */ )
1425 /***********************************************************************
1426 * GdiFreeResources (GDI.609)
1428 WORD WINAPI GdiFreeResources16( DWORD reserve )
1430 return (WORD)( (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
1431 (int)LOCAL_HeapSize( GDI_HeapSel ) );
1435 /*******************************************************************
1436 * GetColorAdjustment [GDI32.@]
1440 BOOL WINAPI GetColorAdjustment(HDC hdc, LPCOLORADJUSTMENT lpca)
1442 FIXME("GetColorAdjustment, stub\n");
1443 return 0;
1446 /*******************************************************************
1447 * GetMiterLimit [GDI32.@]
1451 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
1453 FIXME("GetMiterLimit, stub\n");
1454 return 0;
1457 /*******************************************************************
1458 * SetMiterLimit [GDI32.@]
1462 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
1464 FIXME("SetMiterLimit, stub\n");
1465 return 0;
1468 /*******************************************************************
1469 * GdiComment [GDI32.@]
1473 BOOL WINAPI GdiComment(HDC hdc, UINT cbSize, const BYTE *lpData)
1475 DC *dc = DC_GetDCPtr(hdc);
1476 BOOL ret = FALSE;
1477 if(dc)
1479 if (dc->funcs->pGdiComment)
1480 ret = dc->funcs->pGdiComment( dc->physDev, cbSize, lpData );
1482 GDI_ReleaseObj( hdc );
1483 return ret;
1486 /*******************************************************************
1487 * SetColorAdjustment [GDI32.@]
1491 BOOL WINAPI SetColorAdjustment(HDC hdc, const COLORADJUSTMENT* lpca)
1493 FIXME("SetColorAdjustment, stub\n");
1494 return 0;