4 * Copyright 1993 Alexandre Julliard
17 #include "wine/winbase16.h"
27 #include "debugtools.h"
30 DEFAULT_DEBUG_CHANNEL(gdi);
33 /***********************************************************************
37 static BRUSHOBJ WhiteBrush =
39 { 0, BRUSH_MAGIC, 1 }, /* header */
40 { BS_SOLID, RGB(255,255,255), 0 } /* logbrush */
43 static BRUSHOBJ LtGrayBrush =
45 { 0, BRUSH_MAGIC, 1 }, /* header */
46 /* FIXME : this should perhaps be BS_HATCHED, at least for 1 bitperpixel */
47 { BS_SOLID, RGB(192,192,192), 0 } /* logbrush */
50 static BRUSHOBJ GrayBrush =
52 { 0, BRUSH_MAGIC, 1 }, /* header */
53 /* FIXME : this should perhaps be BS_HATCHED, at least for 1 bitperpixel */
54 { BS_SOLID, RGB(128,128,128), 0 } /* logbrush */
57 static BRUSHOBJ DkGrayBrush =
59 { 0, BRUSH_MAGIC, 1 }, /* header */
60 /* This is BS_HATCHED, for 1 bitperpixel. This makes the spray work in pbrush */
61 /* NB_HATCH_STYLES is an index into HatchBrushes */
62 { BS_HATCHED, RGB(0,0,0), NB_HATCH_STYLES } /* logbrush */
65 static BRUSHOBJ BlackBrush =
67 { 0, BRUSH_MAGIC, 1 }, /* header */
68 { BS_SOLID, RGB(0,0,0), 0 } /* logbrush */
71 static BRUSHOBJ NullBrush =
73 { 0, BRUSH_MAGIC, 1 }, /* header */
74 { BS_NULL, 0, 0 } /* logbrush */
77 static PENOBJ WhitePen =
79 { 0, PEN_MAGIC, 1 }, /* header */
80 { PS_SOLID, { 0, 0 }, RGB(255,255,255) } /* logpen */
83 static PENOBJ BlackPen =
85 { 0, PEN_MAGIC, 1 }, /* header */
86 { PS_SOLID, { 0, 0 }, RGB(0,0,0) } /* logpen */
89 static PENOBJ NullPen =
91 { 0, PEN_MAGIC, 1 }, /* header */
92 { PS_NULL, { 0, 0 }, 0 } /* logpen */
95 static FONTOBJ OEMFixedFont =
97 { 0, FONT_MAGIC, 1 }, /* header */
98 { 0, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, OEM_CHARSET,
99 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} }
102 static FONTOBJ AnsiFixedFont =
104 { 0, FONT_MAGIC, 1 }, /* header */
105 { 0, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
106 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} }
109 static FONTOBJ AnsiVarFont =
111 { 0, FONT_MAGIC, 1 }, /* header */
112 { 0, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
113 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
114 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'} }
117 static FONTOBJ SystemFont =
119 { 0, FONT_MAGIC, 1 },
120 { 0, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
121 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
122 {'S','y','s','t','e','m','\0'} }
125 static FONTOBJ DeviceDefaultFont =
127 { 0, FONT_MAGIC, 1 }, /* header */
128 { 0, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
129 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS, {'\0'} }
132 static FONTOBJ SystemFixedFont =
134 { 0, FONT_MAGIC, 1 }, /* header */
135 { 0, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
136 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, {'\0'} }
139 /* FIXME: Is this correct? */
140 static FONTOBJ DefaultGuiFont =
142 { 0, FONT_MAGIC, 1 }, /* header */
143 { 0, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
144 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
145 {'M','S',' ','S','a','n','s',' ','S','e','r','i','f','\0'} }
149 static GDIOBJHDR * StockObjects[NB_STOCK_OBJECTS] =
151 (GDIOBJHDR *) &WhiteBrush,
152 (GDIOBJHDR *) &LtGrayBrush,
153 (GDIOBJHDR *) &GrayBrush,
154 (GDIOBJHDR *) &DkGrayBrush,
155 (GDIOBJHDR *) &BlackBrush,
156 (GDIOBJHDR *) &NullBrush,
157 (GDIOBJHDR *) &WhitePen,
158 (GDIOBJHDR *) &BlackPen,
159 (GDIOBJHDR *) &NullPen,
161 (GDIOBJHDR *) &OEMFixedFont,
162 (GDIOBJHDR *) &AnsiFixedFont,
163 (GDIOBJHDR *) &AnsiVarFont,
164 (GDIOBJHDR *) &SystemFont,
165 (GDIOBJHDR *) &DeviceDefaultFont,
166 NULL, /* DEFAULT_PALETTE created by PALETTE_Init */
167 (GDIOBJHDR *) &SystemFixedFont,
168 (GDIOBJHDR *) &DefaultGuiFont
171 HBITMAP hPseudoStockBitmap; /* 1x1 bitmap for memory DCs */
173 static SYSLEVEL GDI_level = { CRITICAL_SECTION_INIT, 3 };
174 static WORD GDI_HeapSel;
176 static BOOL get_bool(char *buffer, BOOL def_value)
199 /******************************************************************************
201 * void ReadFontInformation(
202 * char const *fontName,
210 * ReadFontInformation() checks the Wine configuration file's Tweak.Fonts
211 * section for entries containing fontName.Height, fontName.Bold, etc.,
212 * where fontName is the name specified in the call (e.g., "System"). It
213 * attempts to be user friendly by accepting 'n', 'N', 'f', 'F', or '0' as
214 * the first character in the boolean attributes (bold, italic, and
216 *****************************************************************************/
218 static void ReadFontInformation(
219 char const *fontName,
228 char buffer[MAX_PATH];
232 /* In order for the stock fonts to be independent of
233 * mapping mode, the height (& width) must be 0
236 /* assign defaults */
237 font->logfont.lfHeight = defHeight;
238 font->logfont.lfWeight = defBold;
239 font->logfont.lfItalic = defItalic;
240 font->logfont.lfUnderline = defUnderline;
241 font->logfont.lfStrikeOut = defStrikeOut;
243 if(RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Tweak.Fonts", &hkey))
246 sprintf(key, "%s.Height", fontName);
247 count = sizeof(buffer);
248 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
249 font->logfont.lfHeight = atoi(buffer);
251 sprintf(key, "%s.Bold", fontName);
252 count = sizeof(buffer);
253 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
254 font->logfont.lfWeight = get_bool(buffer, defBold) ? FW_BOLD : FW_NORMAL;
256 sprintf(key, "%s.Italic", fontName);
257 count = sizeof(buffer);
258 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
259 font->logfont.lfItalic = get_bool(buffer, defItalic);
261 sprintf(key, "%s.Underline", fontName);
262 count = sizeof(buffer);
263 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
264 font->logfont.lfUnderline = get_bool(buffer, defUnderline);
266 sprintf(key, "%s.StrikeOut", fontName);
267 count = sizeof(buffer);
268 if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
269 font->logfont.lfStrikeOut = get_bool(buffer, defStrikeOut);
274 /***********************************************************************
275 * Because the stock fonts have their structure initialized with
276 * a height of 0 to keep them independent of mapping mode, simply
277 * returning the LOGFONT as is will not work correctly.
278 * These "FixStockFontSizeXXX()" methods will get the correct
279 * size for the fonts.
281 static void GetFontMetrics(HFONT handle, LPTEXTMETRICA lptm)
286 hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
288 hOldFont = (HFONT)SelectObject(hdc, handle);
290 GetTextMetricsA(hdc, lptm);
292 SelectObject(hdc, hOldFont);
297 static inline void FixStockFontSize16(
303 LOGFONT16* pLogFont = (LOGFONT16*)buffer;
306 * Was the lfHeight field copied (it's the first field)?
307 * If it was and it was null, replace the height.
309 if ( (count >= 2*sizeof(INT16)) &&
310 (pLogFont->lfHeight == 0) )
312 GetFontMetrics(handle, &tm);
314 pLogFont->lfHeight = tm.tmHeight;
315 pLogFont->lfWidth = tm.tmAveCharWidth;
319 static inline void FixStockFontSizeA(
325 LOGFONTA* pLogFont = (LOGFONTA*)buffer;
328 * Was the lfHeight field copied (it's the first field)?
329 * If it was and it was null, replace the height.
331 if ( (count >= 2*sizeof(INT)) &&
332 (pLogFont->lfHeight == 0) )
334 GetFontMetrics(handle, &tm);
336 pLogFont->lfHeight = tm.tmHeight;
337 pLogFont->lfWidth = tm.tmAveCharWidth;
342 * Since the LOGFONTA and LOGFONTW structures are identical up to the
343 * lfHeight member (the one of interest in this case) we simply define
344 * the W version as the A version.
346 #define FixStockFontSizeW FixStockFontSizeA
348 #define TRACE_SEC(handle,text) \
349 TRACE("(%04x): " text " %ld\n", (handle), GDI_level.crst.RecursionCount)
351 /***********************************************************************
354 * GDI initialization.
359 HINSTANCE16 instance;
361 /* create GDI heap */
362 if ((instance = LoadLibrary16( "GDI.EXE" )) < 32) return FALSE;
363 GDI_HeapSel = instance | 7;
365 /* TWEAK: Initialize font hints */
366 ReadFontInformation("OEMFixed", &OEMFixedFont, 0, 0, 0, 0, 0);
367 ReadFontInformation("AnsiFixed", &AnsiFixedFont, 0, 0, 0, 0, 0);
368 ReadFontInformation("AnsiVar", &AnsiVarFont, 0, 0, 0, 0, 0);
369 ReadFontInformation("System", &SystemFont, 0, 0, 0, 0, 0);
370 ReadFontInformation("DeviceDefault", &DeviceDefaultFont, 0, 0, 0, 0, 0);
371 ReadFontInformation("SystemFixed", &SystemFixedFont, 0, 0, 0, 0, 0);
372 ReadFontInformation("DefaultGui", &DefaultGuiFont, 0, 0, 0, 0, 0);
374 /* Create default palette */
376 /* DR well *this* palette can't be moveable (?) */
377 hpalette = PALETTE_Init();
378 if( !hpalette ) return FALSE;
379 StockObjects[DEFAULT_PALETTE] = (GDIOBJHDR *)LOCAL_Lock( GDI_HeapSel, hpalette );
381 hPseudoStockBitmap = CreateBitmap( 1, 1, 1, 1, NULL );
385 #define FIRST_LARGE_HANDLE 16
386 #define MAX_LARGE_HANDLES ((GDI_HEAP_SIZE >> 2) - FIRST_LARGE_HANDLE)
387 static GDIOBJHDR *large_handles[MAX_LARGE_HANDLES];
388 static int next_large_handle;
390 /***********************************************************************
393 * Allocate a GDI handle from the large heap. Helper for GDI_AllocObject
395 inline static GDIOBJHDR *alloc_large_heap( WORD size, HGDIOBJ *handle )
400 for (i = next_large_handle + 1; i < MAX_LARGE_HANDLES; i++)
401 if (!large_handles[i]) goto found;
402 for (i = 0; i <= next_large_handle; i++)
403 if (!large_handles[i]) goto found;
408 if ((obj = HeapAlloc( GetProcessHeap(), 0, size )))
410 large_handles[i] = obj;
411 *handle = (i + FIRST_LARGE_HANDLE) << 2;
412 next_large_handle = i;
418 /***********************************************************************
421 void *GDI_AllocObject( WORD size, WORD magic, HGDIOBJ *handle )
423 static DWORD count = 0;
426 _EnterSysLevel( &GDI_level );
429 /* allocate DCs on the larger heap */
431 case DISABLED_DC_MAGIC:
434 case METAFILE_DC_MAGIC:
435 case ENHMETAFILE_MAGIC:
436 case ENHMETAFILE_DC_MAGIC:
438 if (!(obj = alloc_large_heap( size, handle ))) goto error;
441 if (!(*handle = LOCAL_Alloc( GDI_HeapSel, LMEM_MOVEABLE, size ))) goto error;
442 assert( *handle & 2 );
443 obj = (GDIOBJHDR *)LOCAL_Lock( GDI_HeapSel, *handle );
448 obj->wMagic = magic|OBJECT_NOSYSTEM;
449 obj->dwCount = ++count;
451 TRACE_SEC( *handle, "enter" );
455 _LeaveSysLevel( &GDI_level );
461 /***********************************************************************
464 * The object ptr must have been obtained with GDI_GetObjPtr.
465 * The new pointer must be released with GDI_ReleaseObj.
467 void *GDI_ReallocObject( WORD size, HGDIOBJ handle, void *object )
471 assert( handle & 2 ); /* no realloc for large handles */
472 LOCAL_Unlock( GDI_HeapSel, handle );
473 if (!(new_handle = LOCAL_ReAlloc( GDI_HeapSel, handle, size, LMEM_MOVEABLE )))
475 TRACE_SEC( handle, "leave" );
476 _LeaveSysLevel( &GDI_level );
479 assert( new_handle == handle ); /* moveable handle cannot change */
480 return LOCAL_Lock( GDI_HeapSel, handle );
484 /***********************************************************************
487 BOOL GDI_FreeObject( HGDIOBJ handle, void *ptr )
489 GDIOBJHDR *object = ptr;
491 /* can't free stock objects */
492 if (handle < FIRST_STOCK_HANDLE)
494 object->wMagic = 0; /* Mark it as invalid */
495 if (handle & 2) /* GDI heap handle */
497 LOCAL_Unlock( GDI_HeapSel, handle );
498 LOCAL_Free( GDI_HeapSel, handle );
500 else /* large heap handle */
502 int i = (handle >> 2) - FIRST_LARGE_HANDLE;
503 if (i >= 0 && large_handles[i])
505 HeapFree( GetProcessHeap(), 0, large_handles[i] );
506 large_handles[i] = NULL;
510 TRACE_SEC( handle, "leave" );
511 _LeaveSysLevel( &GDI_level );
516 /***********************************************************************
519 * Return a pointer to the GDI object associated to the handle.
520 * Return NULL if the object has the wrong magic number.
521 * The object must be released with GDI_ReleaseObj.
523 void *GDI_GetObjPtr( HGDIOBJ handle, WORD magic )
525 GDIOBJHDR *ptr = NULL;
527 _EnterSysLevel( &GDI_level );
529 if (handle >= FIRST_STOCK_HANDLE)
531 if (handle <= LAST_STOCK_HANDLE) ptr = StockObjects[handle - FIRST_STOCK_HANDLE];
532 if (ptr && (magic != MAGIC_DONTCARE)
533 && (GDIMAGIC(ptr->wMagic) != magic)) ptr = NULL;
535 else if (handle & 2) /* GDI heap handle */
537 ptr = (GDIOBJHDR *)LOCAL_Lock( GDI_HeapSel, handle );
539 (magic != MAGIC_DONTCARE) && (GDIMAGIC(ptr->wMagic) != magic))
541 LOCAL_Unlock( GDI_HeapSel, handle );
545 else /* large heap handle */
547 int i = (handle >> 2) - FIRST_LARGE_HANDLE;
550 ptr = large_handles[i];
551 if (ptr && (magic != MAGIC_DONTCARE) && (GDIMAGIC(ptr->wMagic) != magic)) ptr = NULL;
557 _LeaveSysLevel( &GDI_level );
558 SetLastError( ERROR_INVALID_HANDLE );
560 else TRACE_SEC( handle, "enter" );
566 /***********************************************************************
570 void GDI_ReleaseObj( HGDIOBJ handle )
572 if (handle < FIRST_STOCK_HANDLE && (handle & 2)) LOCAL_Unlock( GDI_HeapSel, handle );
573 TRACE_SEC( handle, "leave" );
574 _LeaveSysLevel( &GDI_level );
578 /***********************************************************************
579 * DeleteObject (GDI.69)
580 * SysDeleteObject (GDI.605)
582 BOOL16 WINAPI DeleteObject16( HGDIOBJ16 obj )
584 return DeleteObject( obj );
588 /***********************************************************************
589 * DeleteObject (GDI32.@)
591 BOOL WINAPI DeleteObject( HGDIOBJ obj )
593 /* Check if object is valid */
596 if (HIWORD(obj)) return FALSE;
597 if ((obj >= FIRST_STOCK_HANDLE) && (obj <= LAST_STOCK_HANDLE)) {
598 TRACE("Preserving Stock object %04x\n", obj );
599 /* NOTE: No GDI_Release is necessary */
602 if (obj == hPseudoStockBitmap) return TRUE;
603 if (!(header = GDI_GetObjPtr( obj, MAGIC_DONTCARE ))) return FALSE;
605 if (!(header->wMagic & OBJECT_NOSYSTEM)
606 && (header->wMagic >= FIRST_MAGIC) && (header->wMagic <= LAST_MAGIC))
608 TRACE("Preserving system object %04x\n", obj);
609 GDI_ReleaseObj( obj );
613 TRACE("%04x\n", obj );
617 switch(GDIMAGIC(header->wMagic))
619 case PEN_MAGIC: return GDI_FreeObject( obj, header );
620 case BRUSH_MAGIC: return BRUSH_DeleteObject( obj, (BRUSHOBJ*)header );
621 case FONT_MAGIC: return GDI_FreeObject( obj, header );
622 case PALETTE_MAGIC: return PALETTE_DeleteObject(obj,(PALETTEOBJ*)header);
623 case BITMAP_MAGIC: return BITMAP_DeleteObject( obj, (BITMAPOBJ*)header);
624 case REGION_MAGIC: return REGION_DeleteObject( obj, (RGNOBJ*)header );
626 GDI_ReleaseObj( obj );
627 return DeleteDC(obj);
629 WARN("Already deleted\n");
632 WARN("Unknown magic number (%d)\n",GDIMAGIC(header->wMagic));
634 GDI_ReleaseObj( obj );
638 /***********************************************************************
639 * GetStockObject (GDI.87)
641 HGDIOBJ16 WINAPI GetStockObject16( INT16 obj )
643 return (HGDIOBJ16)GetStockObject( obj );
647 /***********************************************************************
648 * GetStockObject (GDI32.@)
650 HGDIOBJ WINAPI GetStockObject( INT obj )
653 if ((obj < 0) || (obj >= NB_STOCK_OBJECTS)) return 0;
654 if (!StockObjects[obj]) return 0;
655 ret = (HGDIOBJ16)(FIRST_STOCK_HANDLE + obj);
656 TRACE("returning %4x\n", ret );
661 /***********************************************************************
664 INT16 WINAPI GetObject16( HANDLE16 handle, INT16 count, LPVOID buffer )
668 TRACE("%04x %d %p\n", handle, count, buffer );
669 if (!count) return 0;
671 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
673 switch(GDIMAGIC(ptr->wMagic))
676 result = PEN_GetObject16( (PENOBJ *)ptr, count, buffer );
679 result = BRUSH_GetObject16( (BRUSHOBJ *)ptr, count, buffer );
682 result = BITMAP_GetObject16( (BITMAPOBJ *)ptr, count, buffer );
685 result = FONT_GetObject16( (FONTOBJ *)ptr, count, buffer );
688 * Fix the LOGFONT structure for the stock fonts
690 if ( (handle >= FIRST_STOCK_HANDLE) &&
691 (handle <= LAST_STOCK_HANDLE) )
692 FixStockFontSize16(handle, count, buffer);
695 result = PALETTE_GetObject( (PALETTEOBJ *)ptr, count, buffer );
698 GDI_ReleaseObj( handle );
703 /***********************************************************************
704 * GetObjectA (GDI32.@)
706 INT WINAPI GetObjectA( HANDLE handle, INT count, LPVOID buffer )
710 TRACE("%08x %d %p\n", handle, count, buffer );
711 if (!count) return 0;
713 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
715 switch(GDIMAGIC(ptr->wMagic))
718 result = PEN_GetObject( (PENOBJ *)ptr, count, buffer );
721 result = BRUSH_GetObject( (BRUSHOBJ *)ptr, count, buffer );
724 result = BITMAP_GetObject( (BITMAPOBJ *)ptr, count, buffer );
727 result = FONT_GetObjectA( (FONTOBJ *)ptr, count, buffer );
730 * Fix the LOGFONT structure for the stock fonts
732 if ( (handle >= FIRST_STOCK_HANDLE) &&
733 (handle <= LAST_STOCK_HANDLE) )
734 FixStockFontSizeA(handle, count, buffer);
737 result = PALETTE_GetObject( (PALETTEOBJ *)ptr, count, buffer );
742 case DISABLED_DC_MAGIC:
745 case METAFILE_DC_MAGIC:
746 case ENHMETAFILE_MAGIC:
747 case ENHMETAFILE_DC_MAGIC:
748 FIXME("Magic %04x not implemented\n", GDIMAGIC(ptr->wMagic) );
752 ERR("Invalid GDI Magic %04x\n", GDIMAGIC(ptr->wMagic));
755 GDI_ReleaseObj( handle );
759 /***********************************************************************
760 * GetObjectW (GDI32.@)
762 INT WINAPI GetObjectW( HANDLE handle, INT count, LPVOID buffer )
766 TRACE("%08x %d %p\n", handle, count, buffer );
767 if (!count) return 0;
769 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
771 switch(GDIMAGIC(ptr->wMagic))
774 result = PEN_GetObject( (PENOBJ *)ptr, count, buffer );
777 result = BRUSH_GetObject( (BRUSHOBJ *)ptr, count, buffer );
780 result = BITMAP_GetObject( (BITMAPOBJ *)ptr, count, buffer );
783 result = FONT_GetObjectW( (FONTOBJ *)ptr, count, buffer );
786 * Fix the LOGFONT structure for the stock fonts
788 if ( (handle >= FIRST_STOCK_HANDLE) &&
789 (handle <= LAST_STOCK_HANDLE) )
790 FixStockFontSizeW(handle, count, buffer);
793 result = PALETTE_GetObject( (PALETTEOBJ *)ptr, count, buffer );
796 FIXME("Magic %04x not implemented\n", GDIMAGIC(ptr->wMagic) );
799 GDI_ReleaseObj( handle );
803 /***********************************************************************
804 * GetObjectType (GDI32.@)
806 DWORD WINAPI GetObjectType( HANDLE handle )
810 TRACE("%08x\n", handle );
812 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
814 switch(GDIMAGIC(ptr->wMagic))
841 result = OBJ_METAFILE;
843 case METAFILE_DC_MAGIC:
846 case ENHMETAFILE_MAGIC:
847 result = OBJ_ENHMETAFILE;
849 case ENHMETAFILE_DC_MAGIC:
850 result = OBJ_ENHMETADC;
853 FIXME("Magic %04x not implemented\n", GDIMAGIC(ptr->wMagic) );
856 GDI_ReleaseObj( handle );
860 /***********************************************************************
861 * GetCurrentObject (GDI32.@)
863 HANDLE WINAPI GetCurrentObject(HDC hdc,UINT type)
866 DC * dc = DC_GetDCPtr( hdc );
871 case OBJ_PEN: ret = dc->hPen; break;
872 case OBJ_BRUSH: ret = dc->hBrush; break;
873 case OBJ_PAL: ret = dc->hPalette; break;
874 case OBJ_FONT: ret = dc->hFont; break;
875 case OBJ_BITMAP: ret = dc->hBitmap; break;
877 /* the SDK only mentions those above */
878 FIXME("(%08x,%d): unknown type.\n",hdc,type);
881 GDI_ReleaseObj( hdc );
887 /***********************************************************************
888 * SelectObject (GDI.45)
890 HGDIOBJ16 WINAPI SelectObject16( HDC16 hdc, HGDIOBJ16 handle )
892 return (HGDIOBJ16)SelectObject( hdc, handle );
896 /***********************************************************************
897 * SelectObject (GDI32.@)
899 HGDIOBJ WINAPI SelectObject( HDC hdc, HGDIOBJ handle )
902 DC * dc = DC_GetDCUpdate( hdc );
904 TRACE("hdc=%04x %04x\n", hdc, handle );
905 if (dc->funcs->pSelectObject)
906 ret = dc->funcs->pSelectObject( dc, handle );
907 GDI_ReleaseObj( hdc );
912 /***********************************************************************
913 * UnrealizeObject (GDI.150)
915 BOOL16 WINAPI UnrealizeObject16( HGDIOBJ16 obj )
917 return UnrealizeObject( obj );
921 /***********************************************************************
922 * UnrealizeObject (GDI32.@)
924 BOOL WINAPI UnrealizeObject( HGDIOBJ obj )
927 /* Check if object is valid */
929 GDIOBJHDR * header = GDI_GetObjPtr( obj, MAGIC_DONTCARE );
930 if (!header) return FALSE;
932 TRACE("%04x\n", obj );
934 /* Unrealize object */
936 switch(GDIMAGIC(header->wMagic))
939 result = PALETTE_UnrealizeObject( obj, (PALETTEOBJ *)header );
943 /* Windows resets the brush origin. We don't need to. */
946 GDI_ReleaseObj( obj );
951 /***********************************************************************
952 * EnumObjects16 (GDI.71)
954 INT16 WINAPI EnumObjects16( HDC16 hdc, INT16 nObjType,
955 GOBJENUMPROC16 lpEnumFunc, LPARAM lParam )
957 /* Solid colors to enumerate */
958 static const COLORREF solid_colors[] =
959 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
960 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
961 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
962 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
963 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
964 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
965 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
966 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
971 LOGBRUSH16 *brush = NULL;
973 TRACE("%04x %d %08lx %08lx\n",
974 hdc, nObjType, (DWORD)lpEnumFunc, lParam );
978 /* Enumerate solid pens */
979 if (!(pen = SEGPTR_NEW(LOGPEN16))) break;
980 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
982 pen->lopnStyle = PS_SOLID;
983 pen->lopnWidth.x = 1;
984 pen->lopnWidth.y = 0;
985 pen->lopnColor = solid_colors[i];
986 retval = lpEnumFunc( SEGPTR_GET(pen), lParam );
987 TRACE("solid pen %08lx, ret=%d\n",
988 solid_colors[i], retval);
995 /* Enumerate solid brushes */
996 if (!(brush = SEGPTR_NEW(LOGBRUSH16))) break;
997 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
999 brush->lbStyle = BS_SOLID;
1000 brush->lbColor = solid_colors[i];
1002 retval = lpEnumFunc( SEGPTR_GET(brush), lParam );
1003 TRACE("solid brush %08lx, ret=%d\n",
1004 solid_colors[i], retval);
1008 /* Now enumerate hatched brushes */
1009 if (retval) for (i = HS_HORIZONTAL; i <= HS_DIAGCROSS; i++)
1011 brush->lbStyle = BS_HATCHED;
1012 brush->lbColor = RGB(0,0,0);
1014 retval = lpEnumFunc( SEGPTR_GET(brush), lParam );
1015 TRACE("hatched brush %d, ret=%d\n",
1023 WARN("(%d): Invalid type\n", nObjType );
1030 /***********************************************************************
1031 * EnumObjects (GDI32.@)
1033 INT WINAPI EnumObjects( HDC hdc, INT nObjType,
1034 GOBJENUMPROC lpEnumFunc, LPARAM lParam )
1036 /* Solid colors to enumerate */
1037 static const COLORREF solid_colors[] =
1038 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
1039 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
1040 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
1041 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
1042 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
1043 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
1044 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
1045 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
1052 TRACE("%04x %d %08lx %08lx\n",
1053 hdc, nObjType, (DWORD)lpEnumFunc, lParam );
1057 /* Enumerate solid pens */
1058 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1060 pen.lopnStyle = PS_SOLID;
1061 pen.lopnWidth.x = 1;
1062 pen.lopnWidth.y = 0;
1063 pen.lopnColor = solid_colors[i];
1064 retval = lpEnumFunc( &pen, lParam );
1065 TRACE("solid pen %08lx, ret=%d\n",
1066 solid_colors[i], retval);
1072 /* Enumerate solid brushes */
1073 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
1075 brush.lbStyle = BS_SOLID;
1076 brush.lbColor = solid_colors[i];
1078 retval = lpEnumFunc( &brush, lParam );
1079 TRACE("solid brush %08lx, ret=%d\n",
1080 solid_colors[i], retval);
1084 /* Now enumerate hatched brushes */
1085 if (retval) for (i = HS_HORIZONTAL; i <= HS_DIAGCROSS; i++)
1087 brush.lbStyle = BS_HATCHED;
1088 brush.lbColor = RGB(0,0,0);
1090 retval = lpEnumFunc( &brush, lParam );
1091 TRACE("hatched brush %d, ret=%d\n",
1098 /* FIXME: implement Win32 types */
1099 WARN("(%d): Invalid type\n", nObjType );
1106 /***********************************************************************
1107 * IsGDIObject (GDI.462)
1109 * returns type of object if valid (W95 system programming secrets p. 264-5)
1111 BOOL16 WINAPI IsGDIObject16( HGDIOBJ16 handle )
1115 GDIOBJHDR *object = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1118 magic = GDIMAGIC(object->wMagic) - PEN_MAGIC + 1;
1119 GDI_ReleaseObj( handle );
1125 /***********************************************************************
1126 * SetObjectOwner (GDI.461)
1128 void WINAPI SetObjectOwner16( HGDIOBJ16 handle, HANDLE16 owner )
1134 /***********************************************************************
1135 * SetObjectOwner (GDI32.@)
1137 void WINAPI SetObjectOwner( HGDIOBJ handle, HANDLE owner )
1143 /***********************************************************************
1144 * MakeObjectPrivate (GDI.463)
1146 * What does that mean ?
1147 * Some little docu can be found in "Undocumented Windows",
1148 * but this is basically useless.
1149 * At least we know that this flags the GDI object's wMagic
1150 * with 0x2000 (OBJECT_PRIVATE), so we just do it.
1151 * But Wine doesn't react on that yet.
1153 void WINAPI MakeObjectPrivate16( HGDIOBJ16 handle, BOOL16 private )
1155 GDIOBJHDR *ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1158 ERR("invalid GDI object %04x !\n", handle);
1161 ptr->wMagic |= OBJECT_PRIVATE;
1162 GDI_ReleaseObj( handle );
1166 /***********************************************************************
1167 * GdiFlush (GDI32.@)
1169 BOOL WINAPI GdiFlush(void)
1171 return TRUE; /* FIXME */
1175 /***********************************************************************
1176 * GdiGetBatchLimit (GDI32.@)
1178 DWORD WINAPI GdiGetBatchLimit(void)
1180 return 1; /* FIXME */
1184 /***********************************************************************
1185 * GdiSetBatchLimit (GDI32.@)
1187 DWORD WINAPI GdiSetBatchLimit( DWORD limit )
1189 return 1; /* FIXME */
1193 /***********************************************************************
1194 * GdiSeeGdiDo (GDI.452)
1196 DWORD WINAPI GdiSeeGdiDo16( WORD wReqType, WORD wParam1, WORD wParam2,
1201 case 0x0001: /* LocalAlloc */
1202 return LOCAL_Alloc( GDI_HeapSel, wParam1, wParam3 );
1203 case 0x0002: /* LocalFree */
1204 return LOCAL_Free( GDI_HeapSel, wParam1 );
1205 case 0x0003: /* LocalCompact */
1206 return LOCAL_Compact( GDI_HeapSel, wParam3, 0 );
1207 case 0x0103: /* LocalHeap */
1210 WARN("(wReqType=%04x): Unknown\n", wReqType);
1215 /***********************************************************************
1216 * GdiSignalProc32 (GDI.610)
1218 WORD WINAPI GdiSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
1219 DWORD dwFlags, HMODULE16 hModule )
1224 /***********************************************************************
1225 * FinalGdiInit (GDI.405)
1227 void WINAPI FinalGdiInit16( HANDLE16 unknown )
1231 /***********************************************************************
1232 * GdiFreeResources (GDI.609)
1234 WORD WINAPI GdiFreeResources16( DWORD reserve )
1236 return (WORD)( (int)LOCAL_CountFree( GDI_HeapSel ) * 100 /
1237 (int)LOCAL_HeapSize( GDI_HeapSel ) );
1240 /***********************************************************************
1243 INT16 WINAPI MulDiv16(
1244 INT16 nMultiplicand,
1249 if (!nDivisor) return -32768;
1250 /* We want to deal with a positive divisor to simplify the logic. */
1253 nMultiplicand = - nMultiplicand;
1254 nDivisor = -nDivisor;
1256 /* If the result is positive, we "add" to round. else,
1257 * we subtract to round. */
1258 if ( ( (nMultiplicand < 0) && (nMultiplier < 0) ) ||
1259 ( (nMultiplicand >= 0) && (nMultiplier >= 0) ) )
1260 ret = (((int)nMultiplicand * nMultiplier) + (nDivisor/2)) / nDivisor;
1262 ret = (((int)nMultiplicand * nMultiplier) - (nDivisor/2)) / nDivisor;
1263 if ((ret > 32767) || (ret < -32767)) return -32768;
1268 /*******************************************************************
1269 * GetColorAdjustment [GDI32.@]
1273 BOOL WINAPI GetColorAdjustment(HDC hdc, LPCOLORADJUSTMENT lpca)
1275 FIXME("GetColorAdjustment, stub\n");
1279 /*******************************************************************
1280 * GetMiterLimit [GDI32.@]
1284 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
1286 FIXME("GetMiterLimit, stub\n");
1290 /*******************************************************************
1291 * SetMiterLimit [GDI32.@]
1295 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
1297 FIXME("SetMiterLimit, stub\n");
1301 /*******************************************************************
1302 * GdiComment [GDI32.@]
1306 BOOL WINAPI GdiComment(HDC hdc, UINT cbSize, const BYTE *lpData)
1308 FIXME("GdiComment, stub\n");
1311 /*******************************************************************
1312 * SetColorAdjustment [GDI32.@]
1316 BOOL WINAPI SetColorAdjustment(HDC hdc, const COLORADJUSTMENT* lpca)
1318 FIXME("SetColorAdjustment, stub\n");