4 * Copyright 1993 Alexandre Julliard
17 #include "wine/winbase16.h"
27 #include "debugtools.h"
30 DEFAULT_DEBUG_CHANNEL(gdi);
33 /***********************************************************************
37 static const LOGBRUSH WhiteBrush = { BS_SOLID, RGB(255,255,255), 0 };
38 static const LOGBRUSH BlackBrush = { BS_SOLID, RGB(0,0,0), 0 };
39 static const LOGBRUSH NullBrush = { BS_NULL, 0, 0 };
41 /* FIXME: these should perhaps be BS_HATCHED, at least for 1 bitperpixel */
42 static const LOGBRUSH LtGrayBrush = { BS_SOLID, RGB(192,192,192), 0 };
43 static const LOGBRUSH GrayBrush = { BS_SOLID, RGB(128,128,128), 0 };
45 /* This is BS_HATCHED, for 1 bitperpixel. This makes the spray work in pbrush */
46 /* NB_HATCH_STYLES is an index into HatchBrushes */
47 static const LOGBRUSH DkGrayBrush = { BS_HATCHED, RGB(0,0,0), NB_HATCH_STYLES };
49 static const LOGPEN WhitePen = { PS_SOLID, { 0, 0 }, RGB(255,255,255) };
50 static const LOGPEN BlackPen = { PS_SOLID, { 0, 0 }, RGB(0,0,0) };
51 static const LOGPEN NullPen = { PS_NULL, { 0, 0 }, 0 };
53 static const LOGFONTW OEMFixedFont =
54 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, OEM_CHARSET,
55 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} };
57 static const LOGFONTW AnsiFixedFont =
58 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
59 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} };
61 static const LOGFONTW AnsiVarFont =
62 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
63 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
64 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'} };
66 static const LOGFONTW SystemFont =
67 { 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
68 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
69 {'S','y','s','t','e','m','\0'} };
71 static const LOGFONTW DeviceDefaultFont =
72 { 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
73 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS, {'\0'} };
75 static const LOGFONTW SystemFixedFont =
76 { 16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
77 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} };
79 /* FIXME: Is this correct? */
80 static const LOGFONTW DefaultGuiFont =
81 { -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
82 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
83 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'} };
85 /* reserve one extra entry for the stock default bitmap */
86 /* this is what Windows does too */
87 #define NB_STOCK_OBJECTS (STOCK_LAST+2)
89 static HGDIOBJ stock_objects[NB_STOCK_OBJECTS];
91 static SYSLEVEL GDI_level = { CRITICAL_SECTION_INIT("GDI_level"), 3 };
92 static WORD GDI_HeapSel;
94 inline static BOOL get_bool(char *buffer)
96 return (buffer[0] == 'y' || buffer[0] == 'Y' ||
97 buffer[0] == 't' || buffer[0] == 'T' ||
102 /******************************************************************************
105 static HFONT create_stock_font( char const *fontName, const LOGFONTW *font, HKEY hkey )
109 char buffer[MAX_PATH];
112 if (!hkey) return CreateFontIndirectW( font );
115 sprintf(key, "%s.Height", fontName);
116 count = sizeof(buffer);
117 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
118 lf.lfHeight = atoi(buffer);
120 sprintf(key, "%s.Bold", fontName);
121 count = sizeof(buffer);
122 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
123 lf.lfWeight = get_bool(buffer) ? FW_BOLD : FW_NORMAL;
125 sprintf(key, "%s.Italic", fontName);
126 count = sizeof(buffer);
127 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
128 lf.lfItalic = get_bool(buffer);
130 sprintf(key, "%s.Underline", fontName);
131 count = sizeof(buffer);
132 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
133 lf.lfUnderline = get_bool(buffer);
135 sprintf(key, "%s.StrikeOut", fontName);
136 count = sizeof(buffer);
137 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
138 lf.lfStrikeOut = get_bool(buffer);
139 return CreateFontIndirectW( &lf );
143 #define TRACE_SEC(handle,text) \
144 TRACE("(%04x): " text " %ld\n", (handle), GDI_level.crst.RecursionCount)
147 /***********************************************************************
150 * Increment the reference count of a GDI object.
152 inline static void inc_ref_count( HGDIOBJ handle )
156 if ((header = GDI_GetObjPtr( handle, MAGIC_DONTCARE )))
159 GDI_ReleaseObj( handle );
164 /***********************************************************************
167 * Decrement the reference count of a GDI object.
169 inline static void dec_ref_count( HGDIOBJ handle )
173 if ((header = GDI_GetObjPtr( handle, MAGIC_DONTCARE )))
175 if (header->dwCount) header->dwCount--;
176 if (header->dwCount != 0x80000000) GDI_ReleaseObj( handle );
179 /* handle delayed DeleteObject*/
181 GDI_ReleaseObj( handle );
182 TRACE( "executing delayed DeleteObject for %04x\n", handle );
183 DeleteObject( handle );
189 /***********************************************************************
192 * GDI initialization.
196 HINSTANCE16 instance;
201 if (RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Tweak.Fonts", &hkey))
204 /* create GDI heap */
205 if ((instance = LoadLibrary16( "GDI.EXE" )) < 32) return FALSE;
206 GDI_HeapSel = instance | 7;
208 /* create stock objects */
209 stock_objects[WHITE_BRUSH] = CreateBrushIndirect( &WhiteBrush );
210 stock_objects[LTGRAY_BRUSH] = CreateBrushIndirect( &LtGrayBrush );
211 stock_objects[GRAY_BRUSH] = CreateBrushIndirect( &GrayBrush );
212 stock_objects[DKGRAY_BRUSH] = CreateBrushIndirect( &DkGrayBrush );
213 stock_objects[BLACK_BRUSH] = CreateBrushIndirect( &BlackBrush );
214 stock_objects[NULL_BRUSH] = CreateBrushIndirect( &NullBrush );
216 stock_objects[WHITE_PEN] = CreatePenIndirect( &WhitePen );
217 stock_objects[BLACK_PEN] = CreatePenIndirect( &BlackPen );
218 stock_objects[NULL_PEN] = CreatePenIndirect( &NullPen );
220 stock_objects[DEFAULT_PALETTE] = PALETTE_Init();
221 stock_objects[DEFAULT_BITMAP] = CreateBitmap( 1, 1, 1, 1, NULL );
223 stock_objects[OEM_FIXED_FONT] = create_stock_font( "OEMFixed", &OEMFixedFont, hkey );
224 stock_objects[ANSI_FIXED_FONT] = create_stock_font( "AnsiFixed", &AnsiFixedFont, hkey );
225 stock_objects[ANSI_VAR_FONT] = create_stock_font( "AnsiVar", &AnsiVarFont, hkey );
226 stock_objects[SYSTEM_FONT] = create_stock_font( "System", &SystemFont, hkey );
227 stock_objects[DEVICE_DEFAULT_FONT] = create_stock_font( "DeviceDefault", &DeviceDefaultFont, hkey );
228 stock_objects[SYSTEM_FIXED_FONT] = create_stock_font( "SystemFixed", &SystemFixedFont, hkey );
229 stock_objects[DEFAULT_GUI_FONT] = create_stock_font( "DefaultGui", &DefaultGuiFont, hkey );
232 /* clear the NOSYSTEM bit on all stock objects*/
233 for (i = 0; i < NB_STOCK_OBJECTS; i++)
235 if (!stock_objects[i])
237 if (i == 9) continue; /* there's no stock object 9 */
238 ERR( "could not create stock object %d\n", i );
241 ptr = GDI_GetObjPtr( stock_objects[i], MAGIC_DONTCARE );
242 ptr->wMagic &= ~OBJECT_NOSYSTEM;
243 GDI_ReleaseObj( stock_objects[i] );
246 if (hkey) RegCloseKey( hkey );
253 #define FIRST_LARGE_HANDLE 16
254 #define MAX_LARGE_HANDLES ((GDI_HEAP_SIZE >> 2) - FIRST_LARGE_HANDLE)
255 static GDIOBJHDR *large_handles[MAX_LARGE_HANDLES];
256 static int next_large_handle;
258 /***********************************************************************
261 * Allocate a GDI handle from the large heap. Helper for GDI_AllocObject
263 inline static GDIOBJHDR *alloc_large_heap( WORD size, HGDIOBJ *handle )
268 for (i = next_large_handle + 1; i < MAX_LARGE_HANDLES; i++)
269 if (!large_handles[i]) goto found;
270 for (i = 0; i <= next_large_handle; i++)
271 if (!large_handles[i]) goto found;
276 if ((obj = HeapAlloc( GetProcessHeap(), 0, size )))
278 large_handles[i] = obj;
279 *handle = (i + FIRST_LARGE_HANDLE) << 2;
280 next_large_handle = i;
286 /***********************************************************************
289 void *GDI_AllocObject( WORD size, WORD magic, HGDIOBJ *handle )
293 _EnterSysLevel( &GDI_level );
296 /* allocate DCs on the larger heap */
298 case DISABLED_DC_MAGIC:
301 case METAFILE_DC_MAGIC:
302 case ENHMETAFILE_MAGIC:
303 case ENHMETAFILE_DC_MAGIC:
305 if (!(obj = alloc_large_heap( size, handle ))) goto error;
308 if (!(*handle = LOCAL_Alloc( GDI_HeapSel, LMEM_MOVEABLE, size ))) goto error;
309 assert( *handle & 2 );
310 obj = (GDIOBJHDR *)LOCAL_Lock( GDI_HeapSel, *handle );
315 obj->wMagic = magic|OBJECT_NOSYSTEM;
318 TRACE_SEC( *handle, "enter" );
322 _LeaveSysLevel( &GDI_level );
328 /***********************************************************************
331 * The object ptr must have been obtained with GDI_GetObjPtr.
332 * The new pointer must be released with GDI_ReleaseObj.
334 void *GDI_ReallocObject( WORD size, HGDIOBJ handle, void *object )
338 assert( handle & 2 ); /* no realloc for large handles */
339 LOCAL_Unlock( GDI_HeapSel, handle );
340 if (!(new_handle = LOCAL_ReAlloc( GDI_HeapSel, handle, size, LMEM_MOVEABLE )))
342 TRACE_SEC( handle, "leave" );
343 _LeaveSysLevel( &GDI_level );
346 assert( new_handle == handle ); /* moveable handle cannot change */
347 return LOCAL_Lock( GDI_HeapSel, handle );
351 /***********************************************************************
354 BOOL GDI_FreeObject( HGDIOBJ handle, void *ptr )
356 GDIOBJHDR *object = ptr;
358 object->wMagic = 0; /* Mark it as invalid */
359 if (handle & 2) /* GDI heap handle */
361 LOCAL_Unlock( GDI_HeapSel, handle );
362 LOCAL_Free( GDI_HeapSel, handle );
364 else /* large heap handle */
366 int i = (handle >> 2) - FIRST_LARGE_HANDLE;
367 if (i >= 0 && i < MAX_LARGE_HANDLES && large_handles[i])
369 HeapFree( GetProcessHeap(), 0, large_handles[i] );
370 large_handles[i] = NULL;
372 else ERR( "Invalid handle %x\n", handle );
374 TRACE_SEC( handle, "leave" );
375 _LeaveSysLevel( &GDI_level );
380 /***********************************************************************
383 * Return a pointer to the GDI object associated to the handle.
384 * Return NULL if the object has the wrong magic number.
385 * The object must be released with GDI_ReleaseObj.
387 void *GDI_GetObjPtr( HGDIOBJ handle, WORD magic )
389 GDIOBJHDR *ptr = NULL;
391 _EnterSysLevel( &GDI_level );
393 if (handle & 2) /* GDI heap handle */
395 ptr = (GDIOBJHDR *)LOCAL_Lock( GDI_HeapSel, handle );
398 if (((magic != MAGIC_DONTCARE) && (GDIMAGIC(ptr->wMagic) != magic)) ||
399 (GDIMAGIC(ptr->wMagic) < FIRST_MAGIC) ||
400 (GDIMAGIC(ptr->wMagic) > LAST_MAGIC))
402 LOCAL_Unlock( GDI_HeapSel, handle );
407 else /* large heap handle */
409 int i = (handle >> 2) - FIRST_LARGE_HANDLE;
410 if (i >= 0 && i < MAX_LARGE_HANDLES)
412 ptr = large_handles[i];
413 if (ptr && (magic != MAGIC_DONTCARE) && (GDIMAGIC(ptr->wMagic) != magic)) ptr = NULL;
419 _LeaveSysLevel( &GDI_level );
420 SetLastError( ERROR_INVALID_HANDLE );
421 WARN( "Invalid handle %x\n", handle );
423 else TRACE_SEC( handle, "enter" );
429 /***********************************************************************
433 void GDI_ReleaseObj( HGDIOBJ handle )
435 if (handle & 2) LOCAL_Unlock( GDI_HeapSel, handle );
436 TRACE_SEC( handle, "leave" );
437 _LeaveSysLevel( &GDI_level );
441 /***********************************************************************
444 void GDI_CheckNotLock(void)
446 _CheckNotSysLevel( &GDI_level );
450 /***********************************************************************
451 * DeleteObject (GDI.69)
452 * SysDeleteObject (GDI.605)
454 BOOL16 WINAPI DeleteObject16( HGDIOBJ16 obj )
456 return DeleteObject( obj );
460 /***********************************************************************
461 * DeleteObject (GDI32.@)
463 BOOL WINAPI DeleteObject( HGDIOBJ obj )
465 /* Check if object is valid */
468 if (HIWORD(obj)) return FALSE;
470 if (!(header = GDI_GetObjPtr( obj, MAGIC_DONTCARE ))) return FALSE;
472 if (!(header->wMagic & OBJECT_NOSYSTEM)
473 && (header->wMagic >= FIRST_MAGIC) && (header->wMagic <= LAST_MAGIC))
475 TRACE("Preserving system object %04x\n", obj);
476 GDI_ReleaseObj( obj );
482 TRACE("delayed for %04x because object in use, count %ld\n", obj, header->dwCount );
483 header->dwCount |= 0x80000000; /* mark for delete */
484 GDI_ReleaseObj( obj );
488 TRACE("%04x\n", obj );
492 switch(GDIMAGIC(header->wMagic))
494 case PEN_MAGIC: return GDI_FreeObject( obj, header );
495 case BRUSH_MAGIC: return BRUSH_DeleteObject( obj, (BRUSHOBJ*)header );
496 case FONT_MAGIC: return GDI_FreeObject( obj, header );
497 case PALETTE_MAGIC: return PALETTE_DeleteObject(obj,(PALETTEOBJ*)header);
498 case BITMAP_MAGIC: return BITMAP_DeleteObject( obj, (BITMAPOBJ*)header);
499 case REGION_MAGIC: return REGION_DeleteObject( obj, (RGNOBJ*)header );
501 GDI_ReleaseObj( obj );
502 return DeleteDC(obj);
504 WARN("Already deleted\n");
507 WARN("Unknown magic number (%04x)\n",GDIMAGIC(header->wMagic));
509 GDI_ReleaseObj( obj );
513 /***********************************************************************
514 * GetStockObject (GDI.87)
516 HGDIOBJ16 WINAPI GetStockObject16( INT16 obj )
518 return (HGDIOBJ16)GetStockObject( obj );
522 /***********************************************************************
523 * GetStockObject (GDI32.@)
525 HGDIOBJ WINAPI GetStockObject( INT obj )
528 if ((obj < 0) || (obj >= NB_STOCK_OBJECTS)) return 0;
529 ret = stock_objects[obj];
530 TRACE("returning %4x\n", ret );
535 /***********************************************************************
538 INT16 WINAPI GetObject16( HANDLE16 handle, INT16 count, LPVOID buffer )
542 TRACE("%04x %d %p\n", handle, count, buffer );
543 if (!count) return 0;
545 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
547 switch(GDIMAGIC(ptr->wMagic))
550 result = PEN_GetObject16( (PENOBJ *)ptr, count, buffer );
553 result = BRUSH_GetObject16( (BRUSHOBJ *)ptr, count, buffer );
556 result = BITMAP_GetObject16( (BITMAPOBJ *)ptr, count, buffer );
559 result = FONT_GetObject16( (FONTOBJ *)ptr, count, buffer );
562 result = PALETTE_GetObject( (PALETTEOBJ *)ptr, count, buffer );
565 GDI_ReleaseObj( handle );
570 /***********************************************************************
571 * GetObjectA (GDI32.@)
573 INT WINAPI GetObjectA( HANDLE handle, INT count, LPVOID buffer )
577 TRACE("%08x %d %p\n", handle, count, buffer );
578 if (!count) return 0;
580 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
582 switch(GDIMAGIC(ptr->wMagic))
585 result = PEN_GetObject( (PENOBJ *)ptr, count, buffer );
588 result = BRUSH_GetObject( (BRUSHOBJ *)ptr, count, buffer );
591 result = BITMAP_GetObject( (BITMAPOBJ *)ptr, count, buffer );
594 result = FONT_GetObjectA( (FONTOBJ *)ptr, count, buffer );
597 result = PALETTE_GetObject( (PALETTEOBJ *)ptr, count, buffer );
602 case DISABLED_DC_MAGIC:
605 case METAFILE_DC_MAGIC:
606 case ENHMETAFILE_MAGIC:
607 case ENHMETAFILE_DC_MAGIC:
608 FIXME("Magic %04x not implemented\n", GDIMAGIC(ptr->wMagic) );
612 ERR("Invalid GDI Magic %04x\n", GDIMAGIC(ptr->wMagic));
615 GDI_ReleaseObj( handle );
619 /***********************************************************************
620 * GetObjectW (GDI32.@)
622 INT WINAPI GetObjectW( HANDLE handle, INT count, LPVOID buffer )
626 TRACE("%08x %d %p\n", handle, count, buffer );
627 if (!count) return 0;
629 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
631 switch(GDIMAGIC(ptr->wMagic))
634 result = PEN_GetObject( (PENOBJ *)ptr, count, buffer );
637 result = BRUSH_GetObject( (BRUSHOBJ *)ptr, count, buffer );
640 result = BITMAP_GetObject( (BITMAPOBJ *)ptr, count, buffer );
643 result = FONT_GetObjectW( (FONTOBJ *)ptr, count, buffer );
646 result = PALETTE_GetObject( (PALETTEOBJ *)ptr, count, buffer );
649 FIXME("Magic %04x not implemented\n", GDIMAGIC(ptr->wMagic) );
652 GDI_ReleaseObj( handle );
656 /***********************************************************************
657 * GetObjectType (GDI32.@)
659 DWORD WINAPI GetObjectType( HANDLE handle )
663 TRACE("%08x\n", handle );
665 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
667 switch(GDIMAGIC(ptr->wMagic))
694 result = OBJ_METAFILE;
696 case METAFILE_DC_MAGIC:
699 case ENHMETAFILE_MAGIC:
700 result = OBJ_ENHMETAFILE;
702 case ENHMETAFILE_DC_MAGIC:
703 result = OBJ_ENHMETADC;
706 FIXME("Magic %04x not implemented\n", GDIMAGIC(ptr->wMagic) );
709 GDI_ReleaseObj( handle );
713 /***********************************************************************
714 * GetCurrentObject (GDI32.@)
716 HANDLE WINAPI GetCurrentObject(HDC hdc,UINT type)
719 DC * dc = DC_GetDCPtr( hdc );
724 case OBJ_PEN: ret = dc->hPen; break;
725 case OBJ_BRUSH: ret = dc->hBrush; break;
726 case OBJ_PAL: ret = dc->hPalette; break;
727 case OBJ_FONT: ret = dc->hFont; break;
728 case OBJ_BITMAP: ret = dc->hBitmap; break;
730 /* the SDK only mentions those above */
731 FIXME("(%08x,%d): unknown type.\n",hdc,type);
734 GDI_ReleaseObj( hdc );
738 /***********************************************************************
741 * If the driver supports vector fonts we create a gdi font first and
742 * then call the driver to give it a chance to supply its own device
743 * font. If the driver wants to do this it returns TRUE and we can
744 * delete the gdi font, if the driver wants to use the gdi font it
745 * should return FALSE, to signal an error return GDI_ERROR. For
746 * drivers that don't support vector fonts they must supply their own
749 static HGDIOBJ FONT_SelectObject(DC *dc, HGDIOBJ hFont)
754 WineEngDecRefFont(dc->gdiFont);
758 if(GetDeviceCaps(dc->hSelf, TEXTCAPS) & TC_VA_ABLE)
759 dc->gdiFont = WineEngCreateFontInstance(hFont);
761 if(dc->funcs->pSelectObject)
762 ret = dc->funcs->pSelectObject(dc, hFont);
764 if(ret && dc->gdiFont) {
765 WineEngDecRefFont(dc->gdiFont);
770 ret = FALSE; /* SelectObject returns FALSE on error */
779 /***********************************************************************
780 * SelectObject (GDI.45)
782 HGDIOBJ16 WINAPI SelectObject16( HDC16 hdc, HGDIOBJ16 handle )
784 return (HGDIOBJ16)SelectObject( hdc, handle );
788 /***********************************************************************
789 * SelectObject (GDI32.@)
791 HGDIOBJ WINAPI SelectObject( HDC hdc, HGDIOBJ handle )
794 DC * dc = DC_GetDCUpdate( hdc );
796 TRACE("hdc=%04x %04x\n", hdc, handle );
798 /* Fonts get a rather different treatment so we'll handle them
800 if(GetObjectType(handle) == OBJ_FONT)
801 ret = FONT_SelectObject(dc, handle);
802 else if (dc->funcs->pSelectObject)
803 ret = dc->funcs->pSelectObject( dc, handle );
804 GDI_ReleaseObj( hdc );
806 if (ret && ret != handle)
808 inc_ref_count( handle );
809 dec_ref_count( ret );
815 /***********************************************************************
816 * UnrealizeObject (GDI.150)
818 BOOL16 WINAPI UnrealizeObject16( HGDIOBJ16 obj )
820 return UnrealizeObject( obj );
824 /***********************************************************************
825 * UnrealizeObject (GDI32.@)
827 BOOL WINAPI UnrealizeObject( HGDIOBJ obj )
830 /* Check if object is valid */
832 GDIOBJHDR * header = GDI_GetObjPtr( obj, MAGIC_DONTCARE );
833 if (!header) return FALSE;
835 TRACE("%04x\n", obj );
837 /* Unrealize object */
839 switch(GDIMAGIC(header->wMagic))
842 result = PALETTE_UnrealizeObject( obj, (PALETTEOBJ *)header );
846 /* Windows resets the brush origin. We don't need to. */
849 GDI_ReleaseObj( obj );
854 /***********************************************************************
855 * EnumObjects16 (GDI.71)
857 INT16 WINAPI EnumObjects16( HDC16 hdc, INT16 nObjType,
858 GOBJENUMPROC16 lpEnumFunc, LPARAM lParam )
860 /* Solid colors to enumerate */
861 static const COLORREF solid_colors[] =
862 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
863 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
864 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
865 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
866 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
867 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
868 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
869 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
874 LOGBRUSH16 *brush = NULL;
876 TRACE("%04x %d %08lx %08lx\n",
877 hdc, nObjType, (DWORD)lpEnumFunc, lParam );
881 /* Enumerate solid pens */
882 if (!(pen = SEGPTR_NEW(LOGPEN16))) break;
883 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
885 pen->lopnStyle = PS_SOLID;
886 pen->lopnWidth.x = 1;
887 pen->lopnWidth.y = 0;
888 pen->lopnColor = solid_colors[i];
889 retval = lpEnumFunc( SEGPTR_GET(pen), lParam );
890 TRACE("solid pen %08lx, ret=%d\n",
891 solid_colors[i], retval);
898 /* Enumerate solid brushes */
899 if (!(brush = SEGPTR_NEW(LOGBRUSH16))) break;
900 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
902 brush->lbStyle = BS_SOLID;
903 brush->lbColor = solid_colors[i];
905 retval = lpEnumFunc( SEGPTR_GET(brush), lParam );
906 TRACE("solid brush %08lx, ret=%d\n",
907 solid_colors[i], retval);
911 /* Now enumerate hatched brushes */
912 if (retval) for (i = HS_HORIZONTAL; i <= HS_DIAGCROSS; i++)
914 brush->lbStyle = BS_HATCHED;
915 brush->lbColor = RGB(0,0,0);
917 retval = lpEnumFunc( SEGPTR_GET(brush), lParam );
918 TRACE("hatched brush %d, ret=%d\n",
926 WARN("(%d): Invalid type\n", nObjType );
933 /***********************************************************************
934 * EnumObjects (GDI32.@)
936 INT WINAPI EnumObjects( HDC hdc, INT nObjType,
937 GOBJENUMPROC lpEnumFunc, LPARAM lParam )
939 /* Solid colors to enumerate */
940 static const COLORREF solid_colors[] =
941 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
942 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
943 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
944 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
945 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
946 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
947 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
948 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
955 TRACE("%04x %d %08lx %08lx\n",
956 hdc, nObjType, (DWORD)lpEnumFunc, lParam );
960 /* Enumerate solid pens */
961 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
963 pen.lopnStyle = PS_SOLID;
966 pen.lopnColor = solid_colors[i];
967 retval = lpEnumFunc( &pen, lParam );
968 TRACE("solid pen %08lx, ret=%d\n",
969 solid_colors[i], retval);
975 /* Enumerate solid brushes */
976 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
978 brush.lbStyle = BS_SOLID;
979 brush.lbColor = solid_colors[i];
981 retval = lpEnumFunc( &brush, lParam );
982 TRACE("solid brush %08lx, ret=%d\n",
983 solid_colors[i], retval);
987 /* Now enumerate hatched brushes */
988 if (retval) for (i = HS_HORIZONTAL; i <= HS_DIAGCROSS; i++)
990 brush.lbStyle = BS_HATCHED;
991 brush.lbColor = RGB(0,0,0);
993 retval = lpEnumFunc( &brush, lParam );
994 TRACE("hatched brush %d, ret=%d\n",
1001 /* FIXME: implement Win32 types */
1002 WARN("(%d): Invalid type\n", nObjType );
1009 /***********************************************************************
1010 * IsGDIObject (GDI.462)
1012 * returns type of object if valid (W95 system programming secrets p. 264-5)
1014 BOOL16 WINAPI IsGDIObject16( HGDIOBJ16 handle )
1018 GDIOBJHDR *object = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1021 magic = GDIMAGIC(object->wMagic) - PEN_MAGIC + 1;
1022 GDI_ReleaseObj( handle );
1028 /***********************************************************************
1029 * SetObjectOwner (GDI.461)
1031 void WINAPI SetObjectOwner16( HGDIOBJ16 handle, HANDLE16 owner )
1037 /***********************************************************************
1038 * SetObjectOwner (GDI32.@)
1040 void WINAPI SetObjectOwner( HGDIOBJ handle, HANDLE owner )
1046 /***********************************************************************
1047 * MakeObjectPrivate (GDI.463)
1049 * What does that mean ?
1050 * Some little docu can be found in "Undocumented Windows",
1051 * but this is basically useless.
1052 * At least we know that this flags the GDI object's wMagic
1053 * with 0x2000 (OBJECT_PRIVATE), so we just do it.
1054 * But Wine doesn't react on that yet.
1056 void WINAPI MakeObjectPrivate16( HGDIOBJ16 handle, BOOL16 private )
1058 GDIOBJHDR *ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1061 ERR("invalid GDI object %04x !\n", handle);
1064 ptr->wMagic |= OBJECT_PRIVATE;
1065 GDI_ReleaseObj( handle );
1069 /***********************************************************************
1070 * GdiFlush (GDI32.@)
1072 BOOL WINAPI GdiFlush(void)
1074 return TRUE; /* FIXME */
1078 /***********************************************************************
1079 * GdiGetBatchLimit (GDI32.@)
1081 DWORD WINAPI GdiGetBatchLimit(void)
1083 return 1; /* FIXME */
1087 /***********************************************************************
1088 * GdiSetBatchLimit (GDI32.@)
1090 DWORD WINAPI GdiSetBatchLimit( DWORD limit )
1092 return 1; /* FIXME */
1096 /***********************************************************************
1097 * GdiSeeGdiDo (GDI.452)
1099 DWORD WINAPI GdiSeeGdiDo16( WORD wReqType, WORD wParam1, WORD wParam2,
1104 case 0x0001: /* LocalAlloc */
1105 return LOCAL_Alloc( GDI_HeapSel, wParam1, wParam3 );
1106 case 0x0002: /* LocalFree */
1107 return LOCAL_Free( GDI_HeapSel, wParam1 );
1108 case 0x0003: /* LocalCompact */
1109 return LOCAL_Compact( GDI_HeapSel, wParam3, 0 );
1110 case 0x0103: /* LocalHeap */
1113 WARN("(wReqType=%04x): Unknown\n", wReqType);
1118 /***********************************************************************
1119 * GdiSignalProc32 (GDI.610)
1121 WORD WINAPI GdiSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
1122 DWORD dwFlags, HMODULE16 hModule )
1127 /***********************************************************************
1128 * GdiInit2 (GDI.405)
1130 * See "Undocumented Windows"
1132 HANDLE16 WINAPI GdiInit216(
1133 HANDLE16 h1, /* GDI object */
1134 HANDLE16 h2 /* global data */
1137 FIXME("(%04x, %04x), stub.\n", h1, h2);
1139 return 0xffff; /* undefined return value */
1140 return h1; /* FIXME: should be the memory handle of h1 */
1143 /***********************************************************************
1144 * FinalGdiInit (GDI.405)
1146 void WINAPI FinalGdiInit16( HBRUSH16 hPattern /* fill pattern of desktop */ )
1150 /***********************************************************************
1151 * GdiFreeResources (GDI.609)
1153 WORD WINAPI GdiFreeResources16( DWORD reserve )
1155 return (WORD)( (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
1156 (int)LOCAL_HeapSize( GDI_HeapSel ) );
1159 /***********************************************************************
1162 INT16 WINAPI MulDiv16(
1163 INT16 nMultiplicand,
1168 if (!nDivisor) return -32768;
1169 /* We want to deal with a positive divisor to simplify the logic. */
1172 nMultiplicand = - nMultiplicand;
1173 nDivisor = -nDivisor;
1175 /* If the result is positive, we "add" to round. else,
1176 * we subtract to round. */
1177 if ( ( (nMultiplicand < 0) && (nMultiplier < 0) ) ||
1178 ( (nMultiplicand >= 0) && (nMultiplier >= 0) ) )
1179 ret = (((int)nMultiplicand * nMultiplier) + (nDivisor/2)) / nDivisor;
1181 ret = (((int)nMultiplicand * nMultiplier) - (nDivisor/2)) / nDivisor;
1182 if ((ret > 32767) || (ret < -32767)) return -32768;
1187 /*******************************************************************
1188 * GetColorAdjustment [GDI32.@]
1192 BOOL WINAPI GetColorAdjustment(HDC hdc, LPCOLORADJUSTMENT lpca)
1194 FIXME("GetColorAdjustment, stub\n");
1198 /*******************************************************************
1199 * GetMiterLimit [GDI32.@]
1203 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
1205 FIXME("GetMiterLimit, stub\n");
1209 /*******************************************************************
1210 * SetMiterLimit [GDI32.@]
1214 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
1216 FIXME("SetMiterLimit, stub\n");
1220 /*******************************************************************
1221 * GdiComment [GDI32.@]
1225 BOOL WINAPI GdiComment(HDC hdc, UINT cbSize, const BYTE *lpData)
1227 FIXME("GdiComment, stub\n");
1230 /*******************************************************************
1231 * SetColorAdjustment [GDI32.@]
1235 BOOL WINAPI SetColorAdjustment(HDC hdc, const COLORADJUSTMENT* lpca)
1237 FIXME("SetColorAdjustment, stub\n");