Updated so it's in line with README.
[wine.git] / objects / gdiobj.c
blob7e8b30f378efbc385a8f50d912c455751747556e
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 <stdio.h>
27 #include "windef.h"
28 #include "wingdi.h"
29 #include "winreg.h"
30 #include "winerror.h"
31 #include "wine/winbase16.h"
33 #include "bitmap.h"
34 #include "font.h"
35 #include "local.h"
36 #include "palette.h"
37 #include "wine/debug.h"
38 #include "gdi.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
42 /* ### start build ### */
43 extern WORD CALLBACK GDI_CallTo16_word_ll(GOBJENUMPROC16,LONG,LONG);
44 /* ### stop build ### */
46 /***********************************************************************
47 * GDI stock objects
50 static const LOGBRUSH WhiteBrush = { BS_SOLID, RGB(255,255,255), 0 };
51 static const LOGBRUSH BlackBrush = { BS_SOLID, RGB(0,0,0), 0 };
52 static const LOGBRUSH NullBrush = { BS_NULL, 0, 0 };
54 /* FIXME: these should perhaps be BS_HATCHED, at least for 1 bitperpixel */
55 static const LOGBRUSH LtGrayBrush = { BS_SOLID, RGB(192,192,192), 0 };
56 static const LOGBRUSH GrayBrush = { BS_SOLID, RGB(128,128,128), 0 };
58 /* This is BS_HATCHED, for 1 bitperpixel. This makes the spray work in pbrush */
59 /* See HatchBrushes in x11drv for the HS_DIAGCROSS+1 hack */
60 static const LOGBRUSH DkGrayBrush = { BS_HATCHED, RGB(0,0,0), (HS_DIAGCROSS+1) };
62 static const LOGPEN WhitePen = { PS_SOLID, { 0, 0 }, RGB(255,255,255) };
63 static const LOGPEN BlackPen = { PS_SOLID, { 0, 0 }, RGB(0,0,0) };
64 static const LOGPEN NullPen = { PS_NULL, { 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 = { CRITICAL_SECTION_INIT("GDI_level"), 3 };
74 static WORD GDI_HeapSel;
76 inline static BOOL get_bool(char *buffer)
78 return (buffer[0] == 'y' || buffer[0] == 'Y' ||
79 buffer[0] == 't' || buffer[0] == 'T' ||
80 buffer[0] == '1');
84 /****************************************************************************
86 * language-independent stock fonts
90 static const LOGFONTW OEMFixedFont =
91 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, OEM_CHARSET,
92 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} };
94 static const LOGFONTW AnsiFixedFont =
95 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
96 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} };
98 static const LOGFONTW AnsiVarFont =
99 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
100 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
101 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'} };
103 /******************************************************************************
105 * language-dependent stock fonts
107 * 'ANSI' charset and 'DEFAULT' charset is not same.
108 * The chars in CP_ACP should be drawn with 'DEFAULT' charset.
109 * 'ANSI' charset seems to be identical with ISO-8859-1.
110 * 'DEFAULT' charset is a language-dependent charset.
112 * 'System' font seems to be an alias for language-dependent font.
116 * language-dependenet stock fonts for all known charsets
117 * please see TranslateCharsetInfo (objects/font.c) and
118 * CharsetBindingInfo (graphics/x11drv/xfont.c),
119 * and modify entries for your language if needed.
121 struct DefaultFontInfo
123 UINT charset;
124 LOGFONTW SystemFont;
125 LOGFONTW DeviceDefaultFont;
126 LOGFONTW SystemFixedFont;
127 LOGFONTW DefaultGuiFont;
130 static const struct DefaultFontInfo default_fonts[] =
132 { ANSI_CHARSET,
133 { /* System */
134 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
135 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
136 {'S','y','s','t','e','m','\0'}
138 { /* Device Default */
139 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
140 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
141 {'\0'}
143 { /* System Fixed */
144 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
145 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
146 {'\0'}
148 { /* DefaultGuiFont */
149 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
150 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
151 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'}
154 { EASTEUROPE_CHARSET,
155 { /* System */
156 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
157 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
158 {'S','y','s','t','e','m','\0'}
160 { /* Device Default */
161 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
162 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
163 {'\0'}
165 { /* System Fixed */
166 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
167 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
168 {'\0'}
170 { /* DefaultGuiFont */
171 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET,
172 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
173 {'\0'} /* FIXME - what is the native font??? */
176 { RUSSIAN_CHARSET,
177 { /* System */
178 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
179 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
180 {'S','y','s','t','e','m','\0'}
182 { /* Device Default */
183 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
184 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
185 {'\0'}
187 { /* System Fixed */
188 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
189 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
190 {'\0'}
192 { /* DefaultGuiFont */
193 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, RUSSIAN_CHARSET,
194 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
195 {'\0'} /* FIXME - what is the native font??? */
198 { GREEK_CHARSET,
199 { /* System */
200 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
201 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
202 {'S','y','s','t','e','m','\0'}
204 { /* Device Default */
205 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
206 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
207 {'\0'}
209 { /* System Fixed */
210 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
211 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
212 {'\0'}
214 { /* DefaultGuiFont */
215 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GREEK_CHARSET,
216 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
217 {'\0'} /* FIXME - what is the native font??? */
220 { TURKISH_CHARSET,
221 { /* System */
222 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
223 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
224 {'S','y','s','t','e','m','\0'}
226 { /* Device Default */
227 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
228 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
229 {'\0'}
231 { /* System Fixed */
232 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
233 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
234 {'\0'}
236 { /* DefaultGuiFont */
237 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, TURKISH_CHARSET,
238 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
239 {'\0'} /* FIXME - what is the native font??? */
242 { HEBREW_CHARSET,
243 { /* System */
244 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
245 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
246 {'S','y','s','t','e','m','\0'}
248 { /* Device Default */
249 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
250 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
251 {'\0'}
253 { /* System Fixed */
254 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
255 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
256 {'\0'}
258 { /* DefaultGuiFont */
259 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HEBREW_CHARSET,
260 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
261 {'\0'} /* FIXME - what is the native font??? */
264 { ARABIC_CHARSET,
265 { /* System */
266 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
267 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
268 {'S','y','s','t','e','m','\0'}
270 { /* Device Default */
271 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
272 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
273 {'\0'}
275 { /* System Fixed */
276 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
277 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
278 {'\0'}
280 { /* DefaultGuiFont */
281 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ARABIC_CHARSET,
282 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
283 {'\0'} /* FIXME - what is the native font??? */
286 { BALTIC_CHARSET,
287 { /* System */
288 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
289 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
290 {'S','y','s','t','e','m','\0'}
292 { /* Device Default */
293 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
294 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
295 {'\0'}
297 { /* System Fixed */
298 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
299 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
300 {'\0'}
302 { /* DefaultGuiFont */
303 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, BALTIC_CHARSET,
304 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
305 {'\0'} /* FIXME - what is the native font??? */
309 { THAI_CHARSET,
310 { /* System */
311 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
312 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
313 {'S','y','s','t','e','m','\0'}
315 { /* Device Default */
316 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
317 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
318 {'\0'}
320 { /* System Fixed */
321 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
322 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
323 {'\0'}
325 { /* DefaultGuiFont */
326 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, THAI_CHARSET,
327 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
328 {'\0'} /* FIXME - what is the native font??? */
331 { SHIFTJIS_CHARSET,
332 { /* System */
333 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
334 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
335 {'S','y','s','t','e','m','\0'}
337 { /* Device Default */
338 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
339 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
340 {'\0'}
342 { /* System Fixed */
343 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
344 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
345 {'\0'}
347 { /* DefaultGuiFont */
348 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
349 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
350 {'\0'} /* FIXME - mbtowc of native ("MS P gothic") */
353 { GB2312_CHARSET,
354 { /* System */
355 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
356 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
357 {'S','y','s','t','e','m','\0'}
359 { /* Device Default */
360 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
361 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
362 {'\0'}
364 { /* System Fixed */
365 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
366 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
367 {'\0'}
369 { /* DefaultGuiFont */
370 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, GB2312_CHARSET,
371 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
372 {'M','S',' ','S','o','n','g','\0'} /* FIXME: Is this correct? */
375 { HANGEUL_CHARSET,
376 { /* System */
377 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
378 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
379 {'S','y','s','t','e','m','\0'}
381 { /* Device Default */
382 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
383 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
384 {'\0'}
386 { /* System Fixed */
387 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
388 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
389 {'\0'}
391 { /* DefaultGuiFont */
392 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, HANGEUL_CHARSET,
393 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
394 {'G','u','l','i','m','C','h','e'}, /* FIXME: Is this correct? */
397 { CHINESEBIG5_CHARSET,
398 { /* System */
399 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
400 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
401 {'S','y','s','t','e','m','\0'}
403 { /* Device Default */
404 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
405 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
406 {'\0'}
408 { /* System Fixed */
409 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
410 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
411 {'\0'}
413 { /* DefaultGuiFont */
414 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, CHINESEBIG5_CHARSET,
415 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
416 {'\0'} /* FIXME - what is the native font??? */
419 { JOHAB_CHARSET,
420 { /* System */
421 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
422 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
423 {'S','y','s','t','e','m','\0'}
425 { /* Device Default */
426 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
427 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
428 {'\0'}
430 { /* System Fixed */
431 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
432 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
433 {'\0'}
435 { /* DefaultGuiFont */
436 -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, JOHAB_CHARSET,
437 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
438 {'\0'} /* FIXME - what is the native font??? mbtowc of native ("MS Mingliu")??? */
444 /******************************************************************************
445 * get_default_fonts
447 static const struct DefaultFontInfo* get_default_fonts(UINT charset)
449 int n;
451 for(n=0;n<(sizeof(default_fonts)/sizeof(default_fonts[0]));n++)
453 if ( default_fonts[n].charset == charset )
454 return &default_fonts[n];
457 FIXME( "unhandled charset 0x%08x - use ANSI_CHARSET for default stock objects\n", charset );
458 return &default_fonts[0];
462 /******************************************************************************
463 * get_default_charset (internal)
465 * get the language-dependent charset that can handle CP_ACP correctly.
467 static UINT get_default_charset( void )
469 CHARSETINFO csi;
470 UINT uACP;
472 uACP = GetACP();
473 csi.ciCharset = ANSI_CHARSET;
474 if ( ! TranslateCharsetInfo( (LPDWORD)uACP, &csi, TCI_SRCCODEPAGE ) )
476 FIXME( "unhandled codepage %u - use ANSI_CHARSET for default stock objects\n", uACP );
477 return ANSI_CHARSET;
480 return csi.ciCharset;
484 /******************************************************************************
485 * create_stock_font
487 static HFONT create_stock_font( char const *fontName, const LOGFONTW *font, HKEY hkey )
489 LOGFONTW lf;
490 char key[256];
491 char buffer[MAX_PATH];
492 DWORD type, count;
494 if (!hkey) return CreateFontIndirectW( font );
496 lf = *font;
497 sprintf(key, "%s.Height", fontName);
498 count = sizeof(buffer);
499 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
500 lf.lfHeight = atoi(buffer);
502 sprintf(key, "%s.Bold", fontName);
503 count = sizeof(buffer);
504 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
505 lf.lfWeight = get_bool(buffer) ? FW_BOLD : FW_NORMAL;
507 sprintf(key, "%s.Italic", fontName);
508 count = sizeof(buffer);
509 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
510 lf.lfItalic = get_bool(buffer);
512 sprintf(key, "%s.Underline", fontName);
513 count = sizeof(buffer);
514 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
515 lf.lfUnderline = get_bool(buffer);
517 sprintf(key, "%s.StrikeOut", fontName);
518 count = sizeof(buffer);
519 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
520 lf.lfStrikeOut = get_bool(buffer);
521 return CreateFontIndirectW( &lf );
525 #define TRACE_SEC(handle,text) \
526 TRACE("(%04x): " text " %ld\n", (handle), GDI_level.crst.RecursionCount)
529 /***********************************************************************
530 * inc_ref_count
532 * Increment the reference count of a GDI object.
534 inline static void inc_ref_count( HGDIOBJ handle )
536 GDIOBJHDR *header;
538 if ((header = GDI_GetObjPtr( handle, MAGIC_DONTCARE )))
540 header->dwCount++;
541 GDI_ReleaseObj( handle );
546 /***********************************************************************
547 * dec_ref_count
549 * Decrement the reference count of a GDI object.
551 inline static void dec_ref_count( HGDIOBJ handle )
553 GDIOBJHDR *header;
555 if ((header = GDI_GetObjPtr( handle, MAGIC_DONTCARE )))
557 if (header->dwCount) header->dwCount--;
558 if (header->dwCount != 0x80000000) GDI_ReleaseObj( handle );
559 else
561 /* handle delayed DeleteObject*/
562 header->dwCount = 0;
563 GDI_ReleaseObj( handle );
564 TRACE( "executing delayed DeleteObject for %04x\n", handle );
565 DeleteObject( handle );
571 /***********************************************************************
572 * GDI_Init
574 * GDI initialization.
576 BOOL GDI_Init(void)
578 HINSTANCE16 instance;
579 HKEY hkey;
580 GDIOBJHDR *ptr;
581 const struct DefaultFontInfo* deffonts;
582 int i;
584 if (RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Tweak.Fonts", &hkey))
585 hkey = 0;
587 /* create GDI heap */
588 if ((instance = LoadLibrary16( "GDI.EXE" )) < 32) return FALSE;
589 GDI_HeapSel = instance | 7;
591 /* create stock objects */
592 stock_objects[WHITE_BRUSH] = CreateBrushIndirect( &WhiteBrush );
593 stock_objects[LTGRAY_BRUSH] = CreateBrushIndirect( &LtGrayBrush );
594 stock_objects[GRAY_BRUSH] = CreateBrushIndirect( &GrayBrush );
595 stock_objects[DKGRAY_BRUSH] = CreateBrushIndirect( &DkGrayBrush );
596 stock_objects[BLACK_BRUSH] = CreateBrushIndirect( &BlackBrush );
597 stock_objects[NULL_BRUSH] = CreateBrushIndirect( &NullBrush );
599 stock_objects[WHITE_PEN] = CreatePenIndirect( &WhitePen );
600 stock_objects[BLACK_PEN] = CreatePenIndirect( &BlackPen );
601 stock_objects[NULL_PEN] = CreatePenIndirect( &NullPen );
603 stock_objects[DEFAULT_PALETTE] = PALETTE_Init();
604 stock_objects[DEFAULT_BITMAP] = CreateBitmap( 1, 1, 1, 1, NULL );
606 /* language-independent stock fonts */
607 stock_objects[OEM_FIXED_FONT] = create_stock_font( "OEMFixed", &OEMFixedFont, hkey );
608 stock_objects[ANSI_FIXED_FONT] = create_stock_font( "AnsiFixed", &AnsiFixedFont, hkey );
609 stock_objects[ANSI_VAR_FONT] = create_stock_font( "AnsiVar", &AnsiVarFont, hkey );
611 /* language-dependent stock fonts */
612 deffonts = get_default_fonts(get_default_charset());
613 stock_objects[SYSTEM_FONT] = create_stock_font( "System", &deffonts->SystemFont, hkey );
614 stock_objects[DEVICE_DEFAULT_FONT] = create_stock_font( "DeviceDefault", &deffonts->DeviceDefaultFont, hkey );
615 stock_objects[SYSTEM_FIXED_FONT] = create_stock_font( "SystemFixed", &deffonts->SystemFixedFont, hkey );
616 stock_objects[DEFAULT_GUI_FONT] = create_stock_font( "DefaultGui", &deffonts->DefaultGuiFont, hkey );
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 ptr = GDI_GetObjPtr( stock_objects[i], MAGIC_DONTCARE );
629 ptr->wMagic &= ~OBJECT_NOSYSTEM;
630 GDI_ReleaseObj( stock_objects[i] );
633 if (hkey) RegCloseKey( hkey );
635 WineEngInit();
637 return TRUE;
640 #define FIRST_LARGE_HANDLE 16
641 #define MAX_LARGE_HANDLES ((GDI_HEAP_SIZE >> 2) - FIRST_LARGE_HANDLE)
642 static GDIOBJHDR *large_handles[MAX_LARGE_HANDLES];
643 static int next_large_handle;
645 /***********************************************************************
646 * alloc_large_heap
648 * Allocate a GDI handle from the large heap. Helper for GDI_AllocObject
650 inline static GDIOBJHDR *alloc_large_heap( WORD size, HGDIOBJ *handle )
652 int i;
653 GDIOBJHDR *obj;
655 for (i = next_large_handle + 1; i < MAX_LARGE_HANDLES; i++)
656 if (!large_handles[i]) goto found;
657 for (i = 0; i <= next_large_handle; i++)
658 if (!large_handles[i]) goto found;
659 *handle = 0;
660 return NULL;
662 found:
663 if ((obj = HeapAlloc( GetProcessHeap(), 0, size )))
665 large_handles[i] = obj;
666 *handle = (i + FIRST_LARGE_HANDLE) << 2;
667 next_large_handle = i;
669 return obj;
673 /***********************************************************************
674 * GDI_AllocObject
676 void *GDI_AllocObject( WORD size, WORD magic, HGDIOBJ *handle, const struct gdi_obj_funcs *funcs )
678 GDIOBJHDR *obj;
680 _EnterSysLevel( &GDI_level );
681 switch(magic)
683 /* allocate DCs on the larger heap */
684 case DC_MAGIC:
685 case DISABLED_DC_MAGIC:
686 case META_DC_MAGIC:
687 case METAFILE_MAGIC:
688 case METAFILE_DC_MAGIC:
689 case ENHMETAFILE_MAGIC:
690 case ENHMETAFILE_DC_MAGIC:
691 case BITMAP_MAGIC:
692 if (!(obj = alloc_large_heap( size, handle ))) goto error;
693 break;
694 default:
695 if (!(*handle = LOCAL_Alloc( GDI_HeapSel, LMEM_MOVEABLE, size ))) goto error;
696 assert( *handle & 2 );
697 obj = (GDIOBJHDR *)LOCAL_Lock( GDI_HeapSel, *handle );
698 break;
701 obj->hNext = 0;
702 obj->wMagic = magic|OBJECT_NOSYSTEM;
703 obj->dwCount = 0;
704 obj->funcs = funcs;
706 TRACE_SEC( *handle, "enter" );
707 return obj;
709 error:
710 _LeaveSysLevel( &GDI_level );
711 *handle = 0;
712 return NULL;
716 /***********************************************************************
717 * GDI_ReallocObject
719 * The object ptr must have been obtained with GDI_GetObjPtr.
720 * The new pointer must be released with GDI_ReleaseObj.
722 void *GDI_ReallocObject( WORD size, HGDIOBJ handle, void *object )
724 HGDIOBJ new_handle;
726 assert( handle & 2 ); /* no realloc for large handles */
727 LOCAL_Unlock( GDI_HeapSel, handle );
728 if (!(new_handle = LOCAL_ReAlloc( GDI_HeapSel, handle, size, LMEM_MOVEABLE )))
730 TRACE_SEC( handle, "leave" );
731 _LeaveSysLevel( &GDI_level );
732 return NULL;
734 assert( new_handle == handle ); /* moveable handle cannot change */
735 return LOCAL_Lock( GDI_HeapSel, handle );
739 /***********************************************************************
740 * GDI_FreeObject
742 BOOL GDI_FreeObject( HGDIOBJ handle, void *ptr )
744 GDIOBJHDR *object = ptr;
746 object->wMagic = 0; /* Mark it as invalid */
747 object->funcs = NULL;
748 if (handle & 2) /* GDI heap handle */
750 LOCAL_Unlock( GDI_HeapSel, handle );
751 LOCAL_Free( GDI_HeapSel, handle );
753 else /* large heap handle */
755 int i = (handle >> 2) - FIRST_LARGE_HANDLE;
756 if (i >= 0 && i < MAX_LARGE_HANDLES && large_handles[i])
758 HeapFree( GetProcessHeap(), 0, large_handles[i] );
759 large_handles[i] = NULL;
761 else ERR( "Invalid handle %x\n", handle );
763 TRACE_SEC( handle, "leave" );
764 _LeaveSysLevel( &GDI_level );
765 return TRUE;
769 /***********************************************************************
770 * GDI_GetObjPtr
772 * Return a pointer to the GDI object associated to the handle.
773 * Return NULL if the object has the wrong magic number.
774 * The object must be released with GDI_ReleaseObj.
776 void *GDI_GetObjPtr( HGDIOBJ handle, WORD magic )
778 GDIOBJHDR *ptr = NULL;
780 _EnterSysLevel( &GDI_level );
782 if (handle & 2) /* GDI heap handle */
784 ptr = (GDIOBJHDR *)LOCAL_Lock( GDI_HeapSel, handle );
785 if (ptr)
787 if (((magic != MAGIC_DONTCARE) && (GDIMAGIC(ptr->wMagic) != magic)) ||
788 (GDIMAGIC(ptr->wMagic) < FIRST_MAGIC) ||
789 (GDIMAGIC(ptr->wMagic) > LAST_MAGIC))
791 LOCAL_Unlock( GDI_HeapSel, handle );
792 ptr = NULL;
796 else /* large heap handle */
798 int i = (handle >> 2) - FIRST_LARGE_HANDLE;
799 if (i >= 0 && i < MAX_LARGE_HANDLES)
801 ptr = large_handles[i];
802 if (ptr && (magic != MAGIC_DONTCARE) && (GDIMAGIC(ptr->wMagic) != magic)) ptr = NULL;
806 if (!ptr)
808 _LeaveSysLevel( &GDI_level );
809 SetLastError( ERROR_INVALID_HANDLE );
810 WARN( "Invalid handle %x\n", handle );
812 else TRACE_SEC( handle, "enter" );
814 return ptr;
818 /***********************************************************************
819 * GDI_ReleaseObj
822 void GDI_ReleaseObj( HGDIOBJ handle )
824 if (handle & 2) LOCAL_Unlock( GDI_HeapSel, handle );
825 TRACE_SEC( handle, "leave" );
826 _LeaveSysLevel( &GDI_level );
830 /***********************************************************************
831 * GDI_CheckNotLock
833 void GDI_CheckNotLock(void)
835 _CheckNotSysLevel( &GDI_level );
839 /***********************************************************************
840 * DeleteObject (GDI.69)
841 * SysDeleteObject (GDI.605)
843 BOOL16 WINAPI DeleteObject16( HGDIOBJ16 obj )
845 return DeleteObject( obj );
849 /***********************************************************************
850 * DeleteObject (GDI32.@)
852 BOOL WINAPI DeleteObject( HGDIOBJ obj )
854 /* Check if object is valid */
856 GDIOBJHDR * header;
857 if (HIWORD(obj)) return FALSE;
859 if (!(header = GDI_GetObjPtr( obj, MAGIC_DONTCARE ))) return FALSE;
861 if (!(header->wMagic & OBJECT_NOSYSTEM)
862 && (header->wMagic >= FIRST_MAGIC) && (header->wMagic <= LAST_MAGIC))
864 TRACE("Preserving system object %04x\n", obj);
865 GDI_ReleaseObj( obj );
866 return TRUE;
869 if (header->dwCount)
871 TRACE("delayed for %04x because object in use, count %ld\n", obj, header->dwCount );
872 header->dwCount |= 0x80000000; /* mark for delete */
873 GDI_ReleaseObj( obj );
874 return TRUE;
877 TRACE("%04x\n", obj );
879 /* Delete object */
881 if (header->funcs &&
882 header->funcs->pDeleteObject &&
883 header->funcs->pDeleteObject( obj, header ))
884 return TRUE;
886 GDI_ReleaseObj( obj );
887 return FALSE;
890 /***********************************************************************
891 * GetStockObject (GDI.87)
893 HGDIOBJ16 WINAPI GetStockObject16( INT16 obj )
895 return (HGDIOBJ16)GetStockObject( obj );
899 /***********************************************************************
900 * GetStockObject (GDI32.@)
902 HGDIOBJ WINAPI GetStockObject( INT obj )
904 HGDIOBJ ret;
905 if ((obj < 0) || (obj >= NB_STOCK_OBJECTS)) return 0;
906 ret = stock_objects[obj];
907 TRACE("returning %4x\n", ret );
908 return ret;
912 /***********************************************************************
913 * GetObject (GDI.82)
915 INT16 WINAPI GetObject16( HANDLE16 handle, INT16 count, LPVOID buffer )
917 GDIOBJHDR * ptr;
918 INT16 result = 0;
919 TRACE("%04x %d %p\n", handle, count, buffer );
920 if (!count) return 0;
922 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
924 if (ptr->funcs && ptr->funcs->pGetObject16)
925 result = ptr->funcs->pGetObject16( handle, ptr, count, buffer );
926 else
927 SetLastError( ERROR_INVALID_HANDLE );
929 GDI_ReleaseObj( handle );
930 return result;
934 /***********************************************************************
935 * GetObjectA (GDI32.@)
937 INT WINAPI GetObjectA( HANDLE handle, INT count, LPVOID buffer )
939 GDIOBJHDR * ptr;
940 INT result = 0;
941 TRACE("%08x %d %p\n", handle, count, buffer );
942 if (!count) return 0;
944 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
946 if (ptr->funcs && ptr->funcs->pGetObjectA)
947 result = ptr->funcs->pGetObjectA( handle, ptr, count, buffer );
948 else
949 SetLastError( ERROR_INVALID_HANDLE );
951 GDI_ReleaseObj( handle );
952 return result;
955 /***********************************************************************
956 * GetObjectW (GDI32.@)
958 INT WINAPI GetObjectW( HANDLE handle, INT count, LPVOID buffer )
960 GDIOBJHDR * ptr;
961 INT result = 0;
962 TRACE("%08x %d %p\n", handle, count, buffer );
963 if (!count) return 0;
965 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
967 if (ptr->funcs && ptr->funcs->pGetObjectW)
968 result = ptr->funcs->pGetObjectW( handle, ptr, count, buffer );
969 else
970 SetLastError( ERROR_INVALID_HANDLE );
972 GDI_ReleaseObj( handle );
973 return result;
976 /***********************************************************************
977 * GetObjectType (GDI32.@)
979 DWORD WINAPI GetObjectType( HANDLE handle )
981 GDIOBJHDR * ptr;
982 INT result = 0;
983 TRACE("%08x\n", handle );
985 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
987 switch(GDIMAGIC(ptr->wMagic))
989 case PEN_MAGIC:
990 result = OBJ_PEN;
991 break;
992 case BRUSH_MAGIC:
993 result = OBJ_BRUSH;
994 break;
995 case BITMAP_MAGIC:
996 result = OBJ_BITMAP;
997 break;
998 case FONT_MAGIC:
999 result = OBJ_FONT;
1000 break;
1001 case PALETTE_MAGIC:
1002 result = OBJ_PAL;
1003 break;
1004 case REGION_MAGIC:
1005 result = OBJ_REGION;
1006 break;
1007 case DC_MAGIC:
1008 result = OBJ_DC;
1009 break;
1010 case META_DC_MAGIC:
1011 result = OBJ_METADC;
1012 break;
1013 case METAFILE_MAGIC:
1014 result = OBJ_METAFILE;
1015 break;
1016 case METAFILE_DC_MAGIC:
1017 result = OBJ_METADC;
1018 break;
1019 case ENHMETAFILE_MAGIC:
1020 result = OBJ_ENHMETAFILE;
1021 break;
1022 case ENHMETAFILE_DC_MAGIC:
1023 result = OBJ_ENHMETADC;
1024 break;
1025 default:
1026 FIXME("Magic %04x not implemented\n", GDIMAGIC(ptr->wMagic) );
1027 break;
1029 GDI_ReleaseObj( handle );
1030 return result;
1033 /***********************************************************************
1034 * GetCurrentObject (GDI32.@)
1036 HANDLE WINAPI GetCurrentObject(HDC hdc,UINT type)
1038 HANDLE ret = 0;
1039 DC * dc = DC_GetDCPtr( hdc );
1041 if (dc)
1043 switch (type) {
1044 case OBJ_PEN: ret = dc->hPen; break;
1045 case OBJ_BRUSH: ret = dc->hBrush; break;
1046 case OBJ_PAL: ret = dc->hPalette; break;
1047 case OBJ_FONT: ret = dc->hFont; break;
1048 case OBJ_BITMAP: ret = dc->hBitmap; break;
1049 default:
1050 /* the SDK only mentions those above */
1051 FIXME("(%08x,%d): unknown type.\n",hdc,type);
1052 break;
1054 GDI_ReleaseObj( hdc );
1056 return ret;
1060 /***********************************************************************
1061 * SelectObject (GDI.45)
1063 HGDIOBJ16 WINAPI SelectObject16( HDC16 hdc, HGDIOBJ16 handle )
1065 return (HGDIOBJ16)SelectObject( hdc, handle );
1069 /***********************************************************************
1070 * SelectObject (GDI32.@)
1072 HGDIOBJ WINAPI SelectObject( HDC hdc, HGDIOBJ handle )
1074 HGDIOBJ ret = 0;
1075 GDIOBJHDR *header = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1076 if (!header) return 0;
1078 TRACE("hdc=%04x %04x\n", hdc, handle );
1080 if (header->funcs && header->funcs->pSelectObject)
1082 ret = header->funcs->pSelectObject( handle, header, hdc );
1083 if (ret && ret != handle && (INT)ret > COMPLEXREGION)
1085 inc_ref_count( handle );
1086 dec_ref_count( ret );
1089 GDI_ReleaseObj( handle );
1090 return ret;
1094 /***********************************************************************
1095 * UnrealizeObject (GDI.150)
1097 BOOL16 WINAPI UnrealizeObject16( HGDIOBJ16 obj )
1099 return UnrealizeObject( obj );
1103 /***********************************************************************
1104 * UnrealizeObject (GDI32.@)
1106 BOOL WINAPI UnrealizeObject( HGDIOBJ obj )
1108 BOOL result = TRUE;
1109 /* Check if object is valid */
1111 GDIOBJHDR * header = GDI_GetObjPtr( obj, MAGIC_DONTCARE );
1112 if (!header) return FALSE;
1114 TRACE("%04x\n", obj );
1116 /* Unrealize object */
1118 if (header->funcs && header->funcs->pUnrealizeObject)
1119 result = header->funcs->pUnrealizeObject( obj, header );
1121 GDI_ReleaseObj( obj );
1122 return result;
1126 /* Solid colors to enumerate */
1127 static const COLORREF solid_colors[] =
1128 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
1129 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
1130 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
1131 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
1132 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
1133 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
1134 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
1135 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
1138 /***********************************************************************
1139 * EnumObjects (GDI.71)
1141 INT16 WINAPI EnumObjects16( HDC16 hdc, INT16 nObjType,
1142 GOBJENUMPROC16 lpEnumFunc, LPARAM lParam )
1144 INT16 i, retval = 0;
1145 LOGPEN16 pen;
1146 LOGBRUSH16 brush;
1147 SEGPTR segptr;
1149 TRACE("%04x %d %08lx %08lx\n",
1150 hdc, nObjType, (DWORD)lpEnumFunc, lParam );
1151 switch(nObjType)
1153 case OBJ_PEN:
1154 /* Enumerate solid pens */
1155 segptr = MapLS( &pen );
1156 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1158 pen.lopnStyle = PS_SOLID;
1159 pen.lopnWidth.x = 1;
1160 pen.lopnWidth.y = 0;
1161 pen.lopnColor = solid_colors[i];
1162 retval = GDI_CallTo16_word_ll( lpEnumFunc, segptr, lParam );
1163 TRACE("solid pen %08lx, ret=%d\n", solid_colors[i], retval);
1164 if (!retval) break;
1166 UnMapLS( segptr );
1167 break;
1169 case OBJ_BRUSH:
1170 /* Enumerate solid brushes */
1171 segptr = MapLS( &brush );
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 = GDI_CallTo16_word_ll( lpEnumFunc, segptr, lParam );
1178 TRACE("solid brush %08lx, ret=%d\n", solid_colors[i], retval);
1179 if (!retval) break;
1182 /* Now enumerate hatched brushes */
1183 if (retval) for (i = HS_HORIZONTAL; i <= HS_DIAGCROSS; i++)
1185 brush.lbStyle = BS_HATCHED;
1186 brush.lbColor = RGB(0,0,0);
1187 brush.lbHatch = i;
1188 retval = GDI_CallTo16_word_ll( lpEnumFunc, segptr, lParam );
1189 TRACE("hatched brush %d, ret=%d\n", i, retval);
1190 if (!retval) break;
1192 UnMapLS( segptr );
1193 break;
1195 default:
1196 WARN("(%d): Invalid type\n", nObjType );
1197 break;
1199 return retval;
1203 /***********************************************************************
1204 * EnumObjects (GDI32.@)
1206 INT WINAPI EnumObjects( HDC hdc, INT nObjType,
1207 GOBJENUMPROC lpEnumFunc, LPARAM lParam )
1209 INT i, retval = 0;
1210 LOGPEN pen;
1211 LOGBRUSH brush;
1213 TRACE("%04x %d %08lx %08lx\n",
1214 hdc, nObjType, (DWORD)lpEnumFunc, lParam );
1215 switch(nObjType)
1217 case OBJ_PEN:
1218 /* Enumerate solid pens */
1219 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1221 pen.lopnStyle = PS_SOLID;
1222 pen.lopnWidth.x = 1;
1223 pen.lopnWidth.y = 0;
1224 pen.lopnColor = solid_colors[i];
1225 retval = lpEnumFunc( &pen, lParam );
1226 TRACE("solid pen %08lx, ret=%d\n",
1227 solid_colors[i], retval);
1228 if (!retval) break;
1230 break;
1232 case OBJ_BRUSH:
1233 /* Enumerate solid brushes */
1234 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1236 brush.lbStyle = BS_SOLID;
1237 brush.lbColor = solid_colors[i];
1238 brush.lbHatch = 0;
1239 retval = lpEnumFunc( &brush, lParam );
1240 TRACE("solid brush %08lx, ret=%d\n",
1241 solid_colors[i], retval);
1242 if (!retval) break;
1245 /* Now enumerate hatched brushes */
1246 if (retval) for (i = HS_HORIZONTAL; i <= HS_DIAGCROSS; i++)
1248 brush.lbStyle = BS_HATCHED;
1249 brush.lbColor = RGB(0,0,0);
1250 brush.lbHatch = i;
1251 retval = lpEnumFunc( &brush, lParam );
1252 TRACE("hatched brush %d, ret=%d\n",
1253 i, retval);
1254 if (!retval) break;
1256 break;
1258 default:
1259 /* FIXME: implement Win32 types */
1260 WARN("(%d): Invalid type\n", nObjType );
1261 break;
1263 return retval;
1267 /***********************************************************************
1268 * IsGDIObject (GDI.462)
1270 * returns type of object if valid (W95 system programming secrets p. 264-5)
1272 BOOL16 WINAPI IsGDIObject16( HGDIOBJ16 handle )
1274 UINT16 magic = 0;
1276 GDIOBJHDR *object = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1277 if (object)
1279 magic = GDIMAGIC(object->wMagic) - PEN_MAGIC + 1;
1280 GDI_ReleaseObj( handle );
1282 return magic;
1286 /***********************************************************************
1287 * SetObjectOwner (GDI.461)
1289 void WINAPI SetObjectOwner16( HGDIOBJ16 handle, HANDLE16 owner )
1291 /* Nothing to do */
1295 /***********************************************************************
1296 * SetObjectOwner (GDI32.@)
1298 void WINAPI SetObjectOwner( HGDIOBJ handle, HANDLE owner )
1300 /* Nothing to do */
1304 /***********************************************************************
1305 * MakeObjectPrivate (GDI.463)
1307 * What does that mean ?
1308 * Some little docu can be found in "Undocumented Windows",
1309 * but this is basically useless.
1310 * At least we know that this flags the GDI object's wMagic
1311 * with 0x2000 (OBJECT_PRIVATE), so we just do it.
1312 * But Wine doesn't react on that yet.
1314 void WINAPI MakeObjectPrivate16( HGDIOBJ16 handle, BOOL16 private )
1316 GDIOBJHDR *ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1317 if (!ptr)
1319 ERR("invalid GDI object %04x !\n", handle);
1320 return;
1322 ptr->wMagic |= OBJECT_PRIVATE;
1323 GDI_ReleaseObj( handle );
1327 /***********************************************************************
1328 * GdiFlush (GDI32.@)
1330 BOOL WINAPI GdiFlush(void)
1332 return TRUE; /* FIXME */
1336 /***********************************************************************
1337 * GdiGetBatchLimit (GDI32.@)
1339 DWORD WINAPI GdiGetBatchLimit(void)
1341 return 1; /* FIXME */
1345 /***********************************************************************
1346 * GdiSetBatchLimit (GDI32.@)
1348 DWORD WINAPI GdiSetBatchLimit( DWORD limit )
1350 return 1; /* FIXME */
1354 /***********************************************************************
1355 * GdiSeeGdiDo (GDI.452)
1357 DWORD WINAPI GdiSeeGdiDo16( WORD wReqType, WORD wParam1, WORD wParam2,
1358 WORD wParam3 )
1360 switch (wReqType)
1362 case 0x0001: /* LocalAlloc */
1363 return LOCAL_Alloc( GDI_HeapSel, wParam1, wParam3 );
1364 case 0x0002: /* LocalFree */
1365 return LOCAL_Free( GDI_HeapSel, wParam1 );
1366 case 0x0003: /* LocalCompact */
1367 return LOCAL_Compact( GDI_HeapSel, wParam3, 0 );
1368 case 0x0103: /* LocalHeap */
1369 return GDI_HeapSel;
1370 default:
1371 WARN("(wReqType=%04x): Unknown\n", wReqType);
1372 return (DWORD)-1;
1376 /***********************************************************************
1377 * GdiSignalProc32 (GDI.610)
1379 WORD WINAPI GdiSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
1380 DWORD dwFlags, HMODULE16 hModule )
1382 return 0;
1385 /***********************************************************************
1386 * GdiInit2 (GDI.403)
1388 * See "Undocumented Windows"
1390 HANDLE16 WINAPI GdiInit216(
1391 HANDLE16 h1, /* [in] GDI object */
1392 HANDLE16 h2 /* [in] global data */
1395 FIXME("(%04x, %04x), stub.\n", h1, h2);
1396 if (h2 == 0xffff)
1397 return 0xffff; /* undefined return value */
1398 return h1; /* FIXME: should be the memory handle of h1 */
1401 /***********************************************************************
1402 * FinalGdiInit (GDI.405)
1404 void WINAPI FinalGdiInit16( HBRUSH16 hPattern /* [in] fill pattern of desktop */ )
1408 /***********************************************************************
1409 * GdiFreeResources (GDI.609)
1411 WORD WINAPI GdiFreeResources16( DWORD reserve )
1413 return (WORD)( (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
1414 (int)LOCAL_HeapSize( GDI_HeapSel ) );
1417 /***********************************************************************
1418 * MulDiv (GDI.128)
1420 INT16 WINAPI MulDiv16(
1421 INT16 nMultiplicand,
1422 INT16 nMultiplier,
1423 INT16 nDivisor)
1425 INT ret;
1426 if (!nDivisor) return -32768;
1427 /* We want to deal with a positive divisor to simplify the logic. */
1428 if (nDivisor < 0)
1430 nMultiplicand = - nMultiplicand;
1431 nDivisor = -nDivisor;
1433 /* If the result is positive, we "add" to round. else,
1434 * we subtract to round. */
1435 if ( ( (nMultiplicand < 0) && (nMultiplier < 0) ) ||
1436 ( (nMultiplicand >= 0) && (nMultiplier >= 0) ) )
1437 ret = (((int)nMultiplicand * nMultiplier) + (nDivisor/2)) / nDivisor;
1438 else
1439 ret = (((int)nMultiplicand * nMultiplier) - (nDivisor/2)) / nDivisor;
1440 if ((ret > 32767) || (ret < -32767)) return -32768;
1441 return (INT16) ret;
1445 /*******************************************************************
1446 * GetColorAdjustment [GDI32.@]
1450 BOOL WINAPI GetColorAdjustment(HDC hdc, LPCOLORADJUSTMENT lpca)
1452 FIXME("GetColorAdjustment, stub\n");
1453 return 0;
1456 /*******************************************************************
1457 * GetMiterLimit [GDI32.@]
1461 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
1463 FIXME("GetMiterLimit, stub\n");
1464 return 0;
1467 /*******************************************************************
1468 * SetMiterLimit [GDI32.@]
1472 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
1474 FIXME("SetMiterLimit, stub\n");
1475 return 0;
1478 /*******************************************************************
1479 * GdiComment [GDI32.@]
1483 BOOL WINAPI GdiComment(HDC hdc, UINT cbSize, const BYTE *lpData)
1485 FIXME("GdiComment, stub\n");
1486 return 0;
1488 /*******************************************************************
1489 * SetColorAdjustment [GDI32.@]
1493 BOOL WINAPI SetColorAdjustment(HDC hdc, const COLORADJUSTMENT* lpca)
1495 FIXME("SetColorAdjustment, stub\n");
1496 return 0;