4 * Copyright 1993 Alexandre Julliard
16 #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
;
177 /******************************************************************************
179 * void ReadFontInformation(
180 * char const *fontName,
188 * ReadFontInformation() checks the Wine configuration file's Tweak.Fonts
189 * section for entries containing fontName.Height, fontName.Bold, etc.,
190 * where fontName is the name specified in the call (e.g., "System"). It
191 * attempts to be user friendly by accepting 'n', 'N', 'f', 'F', or '0' as
192 * the first character in the boolean attributes (bold, italic, and
194 *****************************************************************************/
196 static void ReadFontInformation(
197 char const *fontName
,
207 /* In order for the stock fonts to be independent of
208 * mapping mode, the height (& width) must be 0
210 sprintf(key
, "%s.Height", fontName
);
211 font
->logfont
.lfHeight
=
212 PROFILE_GetWineIniInt("Tweak.Fonts", key
, defHeight
);
214 sprintf(key
, "%s.Bold", fontName
);
215 font
->logfont
.lfWeight
=
216 (PROFILE_GetWineIniBool("Tweak.Fonts", key
, defBold
)) ?
219 sprintf(key
, "%s.Italic", fontName
);
220 font
->logfont
.lfItalic
=
221 PROFILE_GetWineIniBool("Tweak.Fonts", key
, defItalic
);
223 sprintf(key
, "%s.Underline", fontName
);
224 font
->logfont
.lfUnderline
=
225 PROFILE_GetWineIniBool("Tweak.Fonts", key
, defUnderline
);
227 sprintf(key
, "%s.StrikeOut", fontName
);
228 font
->logfont
.lfStrikeOut
=
229 PROFILE_GetWineIniBool("Tweak.Fonts", key
, defStrikeOut
);
234 /***********************************************************************
235 * Because the stock fonts have their structure initialized with
236 * a height of 0 to keep them independent of mapping mode, simply
237 * returning the LOGFONT as is will not work correctly.
238 * These "FixStockFontSizeXXX()" methods will get the correct
239 * size for the fonts.
241 static void GetFontMetrics(HFONT handle
, LPTEXTMETRICA lptm
)
246 hdc
= CreateDCA("DISPLAY", NULL
, NULL
, NULL
);
248 hOldFont
= (HFONT
)SelectObject(hdc
, handle
);
250 GetTextMetricsA(hdc
, lptm
);
252 SelectObject(hdc
, hOldFont
);
257 static inline void FixStockFontSize16(
263 LOGFONT16
* pLogFont
= (LOGFONT16
*)buffer
;
266 * Was the lfHeight field copied (it's the first field)?
267 * If it was and it was null, replace the height.
269 if ( (count
>= 2*sizeof(INT16
)) &&
270 (pLogFont
->lfHeight
== 0) )
272 GetFontMetrics(handle
, &tm
);
274 pLogFont
->lfHeight
= tm
.tmHeight
;
275 pLogFont
->lfWidth
= tm
.tmAveCharWidth
;
279 static inline void FixStockFontSizeA(
285 LOGFONTA
* pLogFont
= (LOGFONTA
*)buffer
;
288 * Was the lfHeight field copied (it's the first field)?
289 * If it was and it was null, replace the height.
291 if ( (count
>= 2*sizeof(INT
)) &&
292 (pLogFont
->lfHeight
== 0) )
294 GetFontMetrics(handle
, &tm
);
296 pLogFont
->lfHeight
= tm
.tmHeight
;
297 pLogFont
->lfWidth
= tm
.tmAveCharWidth
;
302 * Since the LOGFONTA and LOGFONTW structures are identical up to the
303 * lfHeight member (the one of interest in this case) we simply define
304 * the W version as the A version.
306 #define FixStockFontSizeW FixStockFontSizeA
308 #define TRACE_SEC(handle,text) \
309 TRACE("(%04x): " text " %ld\n", (handle), GDI_level.crst.RecursionCount)
311 /***********************************************************************
314 * GDI initialization.
319 HINSTANCE16 instance
;
321 /* create GDI heap */
322 if ((instance
= LoadLibrary16( "GDI.EXE" )) < 32) return FALSE
;
323 GDI_HeapSel
= GlobalHandleToSel16( instance
);
325 /* TWEAK: Initialize font hints */
326 ReadFontInformation("OEMFixed", &OEMFixedFont
, 0, 0, 0, 0, 0);
327 ReadFontInformation("AnsiFixed", &AnsiFixedFont
, 0, 0, 0, 0, 0);
328 ReadFontInformation("AnsiVar", &AnsiVarFont
, 0, 0, 0, 0, 0);
329 ReadFontInformation("System", &SystemFont
, 0, 0, 0, 0, 0);
330 ReadFontInformation("DeviceDefault", &DeviceDefaultFont
, 0, 0, 0, 0, 0);
331 ReadFontInformation("SystemFixed", &SystemFixedFont
, 0, 0, 0, 0, 0);
332 ReadFontInformation("DefaultGui", &DefaultGuiFont
, 0, 0, 0, 0, 0);
334 /* Create default palette */
336 /* DR well *this* palette can't be moveable (?) */
337 hpalette
= PALETTE_Init();
338 if( !hpalette
) return FALSE
;
339 StockObjects
[DEFAULT_PALETTE
] = (GDIOBJHDR
*)LOCAL_Lock( GDI_HeapSel
, hpalette
);
341 hPseudoStockBitmap
= CreateBitmap( 1, 1, 1, 1, NULL
);
345 #define FIRST_LARGE_HANDLE 16
346 #define MAX_LARGE_HANDLES ((GDI_HEAP_SIZE >> 2) - FIRST_LARGE_HANDLE)
347 static GDIOBJHDR
*large_handles
[MAX_LARGE_HANDLES
];
348 static int next_large_handle
;
350 /***********************************************************************
353 * Allocate a GDI handle from the large heap. Helper for GDI_AllocObject
355 inline static GDIOBJHDR
*alloc_large_heap( WORD size
, HGDIOBJ
*handle
)
360 for (i
= next_large_handle
+ 1; i
< MAX_LARGE_HANDLES
; i
++)
361 if (!large_handles
[i
]) goto found
;
362 for (i
= 0; i
<= next_large_handle
; i
++)
363 if (!large_handles
[i
]) goto found
;
368 if ((obj
= HeapAlloc( GetProcessHeap(), 0, size
)))
370 large_handles
[i
] = obj
;
371 *handle
= (i
+ FIRST_LARGE_HANDLE
) << 2;
372 next_large_handle
= i
;
378 /***********************************************************************
381 void *GDI_AllocObject( WORD size
, WORD magic
, HGDIOBJ
*handle
)
383 static DWORD count
= 0;
386 _EnterSysLevel( &GDI_level
);
389 /* allocate DCs on the larger heap */
391 case DISABLED_DC_MAGIC
:
394 case METAFILE_DC_MAGIC
:
395 case ENHMETAFILE_MAGIC
:
396 case ENHMETAFILE_DC_MAGIC
:
397 if (!(obj
= alloc_large_heap( size
, handle
))) goto error
;
400 if (!(*handle
= LOCAL_Alloc( GDI_HeapSel
, LMEM_MOVEABLE
, size
))) goto error
;
401 assert( *handle
& 2 );
402 obj
= (GDIOBJHDR
*)LOCAL_Lock( GDI_HeapSel
, *handle
);
407 obj
->wMagic
= magic
|OBJECT_NOSYSTEM
;
408 obj
->dwCount
= ++count
;
410 TRACE_SEC( *handle
, "enter" );
414 _LeaveSysLevel( &GDI_level
);
420 /***********************************************************************
423 * The object ptr must have been obtained with GDI_GetObjPtr.
424 * The new pointer must be released with GDI_ReleaseObj.
426 void *GDI_ReallocObject( WORD size
, HGDIOBJ handle
, void *object
)
430 assert( handle
& 2 ); /* no realloc for large handles */
431 LOCAL_Unlock( GDI_HeapSel
, handle
);
432 if (!(new_handle
= LOCAL_ReAlloc( GDI_HeapSel
, handle
, size
, LMEM_MOVEABLE
)))
434 TRACE_SEC( handle
, "leave" );
435 _LeaveSysLevel( &GDI_level
);
438 assert( new_handle
== handle
); /* moveable handle cannot change */
439 return LOCAL_Lock( GDI_HeapSel
, handle
);
443 /***********************************************************************
446 BOOL
GDI_FreeObject( HGDIOBJ handle
, void *ptr
)
448 GDIOBJHDR
*object
= ptr
;
450 /* can't free stock objects */
451 if (handle
< FIRST_STOCK_HANDLE
)
453 object
->wMagic
= 0; /* Mark it as invalid */
454 if (handle
& 2) /* GDI heap handle */
456 LOCAL_Unlock( GDI_HeapSel
, handle
);
457 LOCAL_Free( GDI_HeapSel
, handle
);
459 else /* large heap handle */
461 int i
= (handle
>> 2) - FIRST_LARGE_HANDLE
;
462 if (i
>= 0 && large_handles
[i
])
464 HeapFree( GetProcessHeap(), 0, large_handles
[i
] );
465 large_handles
[i
] = NULL
;
469 TRACE_SEC( handle
, "leave" );
470 _LeaveSysLevel( &GDI_level
);
475 /***********************************************************************
478 * Return a pointer to the GDI object associated to the handle.
479 * Return NULL if the object has the wrong magic number.
480 * The object must be released with GDI_ReleaseObj.
482 void *GDI_GetObjPtr( HGDIOBJ handle
, WORD magic
)
484 GDIOBJHDR
*ptr
= NULL
;
486 _EnterSysLevel( &GDI_level
);
488 if (handle
>= FIRST_STOCK_HANDLE
)
490 if (handle
<= LAST_STOCK_HANDLE
) ptr
= StockObjects
[handle
- FIRST_STOCK_HANDLE
];
491 if (ptr
&& (magic
!= MAGIC_DONTCARE
)
492 && (GDIMAGIC(ptr
->wMagic
) != magic
)) ptr
= NULL
;
494 else if (handle
& 2) /* GDI heap handle */
496 ptr
= (GDIOBJHDR
*)LOCAL_Lock( GDI_HeapSel
, handle
);
498 (magic
!= MAGIC_DONTCARE
) && (GDIMAGIC(ptr
->wMagic
) != magic
))
500 LOCAL_Unlock( GDI_HeapSel
, handle
);
504 else /* large heap handle */
506 int i
= (handle
>> 2) - FIRST_LARGE_HANDLE
;
509 ptr
= large_handles
[i
];
510 if (ptr
&& (magic
!= MAGIC_DONTCARE
) && (GDIMAGIC(ptr
->wMagic
) != magic
)) ptr
= NULL
;
516 _LeaveSysLevel( &GDI_level
);
517 SetLastError( ERROR_INVALID_HANDLE
);
519 else TRACE_SEC( handle
, "enter" );
525 /***********************************************************************
529 void GDI_ReleaseObj( HGDIOBJ handle
)
531 if (handle
< FIRST_STOCK_HANDLE
&& (handle
& 2)) LOCAL_Unlock( GDI_HeapSel
, handle
);
532 TRACE_SEC( handle
, "leave" );
533 _LeaveSysLevel( &GDI_level
);
537 /***********************************************************************
538 * DeleteObject16 (GDI.605)
540 BOOL16 WINAPI
DeleteObject16( HGDIOBJ16 obj
)
542 return DeleteObject( obj
);
546 /***********************************************************************
547 * DeleteObject (GDI32.@)
549 BOOL WINAPI
DeleteObject( HGDIOBJ obj
)
551 /* Check if object is valid */
554 if (HIWORD(obj
)) return FALSE
;
555 if ((obj
>= FIRST_STOCK_HANDLE
) && (obj
<= LAST_STOCK_HANDLE
)) {
556 TRACE("Preserving Stock object %04x\n", obj
);
557 /* NOTE: No GDI_Release is necessary */
560 if (obj
== hPseudoStockBitmap
) return TRUE
;
561 if (!(header
= GDI_GetObjPtr( obj
, MAGIC_DONTCARE
))) return FALSE
;
563 if (!(header
->wMagic
& OBJECT_NOSYSTEM
)
564 && (header
->wMagic
>= FIRST_MAGIC
) && (header
->wMagic
<= LAST_MAGIC
))
566 TRACE("Preserving system object %04x\n", obj
);
567 GDI_ReleaseObj( obj
);
571 TRACE("%04x\n", obj
);
575 switch(GDIMAGIC(header
->wMagic
))
577 case PEN_MAGIC
: return GDI_FreeObject( obj
, header
);
578 case BRUSH_MAGIC
: return BRUSH_DeleteObject( obj
, (BRUSHOBJ
*)header
);
579 case FONT_MAGIC
: return GDI_FreeObject( obj
, header
);
580 case PALETTE_MAGIC
: return PALETTE_DeleteObject(obj
,(PALETTEOBJ
*)header
);
581 case BITMAP_MAGIC
: return BITMAP_DeleteObject( obj
, (BITMAPOBJ
*)header
);
582 case REGION_MAGIC
: return REGION_DeleteObject( obj
, (RGNOBJ
*)header
);
584 GDI_ReleaseObj( obj
);
585 return DeleteDC(obj
);
587 WARN("Already deleted\n");
590 WARN("Unknown magic number (%d)\n",GDIMAGIC(header
->wMagic
));
592 GDI_ReleaseObj( obj
);
596 /***********************************************************************
597 * GetStockObject16 (GDI.87)
599 HGDIOBJ16 WINAPI
GetStockObject16( INT16 obj
)
601 return (HGDIOBJ16
)GetStockObject( obj
);
605 /***********************************************************************
606 * GetStockObject (GDI32.@)
608 HGDIOBJ WINAPI
GetStockObject( INT obj
)
611 if ((obj
< 0) || (obj
>= NB_STOCK_OBJECTS
)) return 0;
612 if (!StockObjects
[obj
]) return 0;
613 ret
= (HGDIOBJ16
)(FIRST_STOCK_HANDLE
+ obj
);
614 TRACE("returning %4x\n", ret
);
619 /***********************************************************************
620 * GetObject16 (GDI.82)
622 INT16 WINAPI
GetObject16( HANDLE16 handle
, INT16 count
, LPVOID buffer
)
626 TRACE("%04x %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_GetObject16( (PENOBJ
*)ptr
, count
, buffer
);
637 result
= BRUSH_GetObject16( (BRUSHOBJ
*)ptr
, count
, buffer
);
640 result
= BITMAP_GetObject16( (BITMAPOBJ
*)ptr
, count
, buffer
);
643 result
= FONT_GetObject16( (FONTOBJ
*)ptr
, count
, buffer
);
646 * Fix the LOGFONT structure for the stock fonts
648 if ( (handle
>= FIRST_STOCK_HANDLE
) &&
649 (handle
<= LAST_STOCK_HANDLE
) )
650 FixStockFontSize16(handle
, count
, buffer
);
653 result
= PALETTE_GetObject( (PALETTEOBJ
*)ptr
, count
, buffer
);
656 GDI_ReleaseObj( handle
);
661 /***********************************************************************
662 * GetObjectA (GDI32.@)
664 INT WINAPI
GetObjectA( HANDLE handle
, INT count
, LPVOID buffer
)
668 TRACE("%08x %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_GetObject( (PENOBJ
*)ptr
, count
, buffer
);
679 result
= BRUSH_GetObject( (BRUSHOBJ
*)ptr
, count
, buffer
);
682 result
= BITMAP_GetObject( (BITMAPOBJ
*)ptr
, count
, buffer
);
685 result
= FONT_GetObjectA( (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 FixStockFontSizeA(handle
, count
, buffer
);
695 result
= PALETTE_GetObject( (PALETTEOBJ
*)ptr
, count
, buffer
);
700 case DISABLED_DC_MAGIC
:
703 case METAFILE_DC_MAGIC
:
704 case ENHMETAFILE_MAGIC
:
705 case ENHMETAFILE_DC_MAGIC
:
706 FIXME("Magic %04x not implemented\n", GDIMAGIC(ptr
->wMagic
) );
710 ERR("Invalid GDI Magic %04x\n", GDIMAGIC(ptr
->wMagic
));
713 GDI_ReleaseObj( handle
);
717 /***********************************************************************
718 * GetObjectW (GDI32.@)
720 INT WINAPI
GetObjectW( HANDLE handle
, INT count
, LPVOID buffer
)
724 TRACE("%08x %d %p\n", handle
, count
, buffer
);
725 if (!count
) return 0;
727 if (!(ptr
= GDI_GetObjPtr( handle
, MAGIC_DONTCARE
))) return 0;
729 switch(GDIMAGIC(ptr
->wMagic
))
732 result
= PEN_GetObject( (PENOBJ
*)ptr
, count
, buffer
);
735 result
= BRUSH_GetObject( (BRUSHOBJ
*)ptr
, count
, buffer
);
738 result
= BITMAP_GetObject( (BITMAPOBJ
*)ptr
, count
, buffer
);
741 result
= FONT_GetObjectW( (FONTOBJ
*)ptr
, count
, buffer
);
744 * Fix the LOGFONT structure for the stock fonts
746 if ( (handle
>= FIRST_STOCK_HANDLE
) &&
747 (handle
<= LAST_STOCK_HANDLE
) )
748 FixStockFontSizeW(handle
, count
, buffer
);
751 result
= PALETTE_GetObject( (PALETTEOBJ
*)ptr
, count
, buffer
);
754 FIXME("Magic %04x not implemented\n", GDIMAGIC(ptr
->wMagic
) );
757 GDI_ReleaseObj( handle
);
761 /***********************************************************************
762 * GetObjectType (GDI32.@)
764 DWORD WINAPI
GetObjectType( HANDLE handle
)
768 TRACE("%08x\n", handle
);
770 if (!(ptr
= GDI_GetObjPtr( handle
, MAGIC_DONTCARE
))) return 0;
772 switch(GDIMAGIC(ptr
->wMagic
))
799 result
= OBJ_METAFILE
;
801 case METAFILE_DC_MAGIC
:
804 case ENHMETAFILE_MAGIC
:
805 result
= OBJ_ENHMETAFILE
;
807 case ENHMETAFILE_DC_MAGIC
:
808 result
= OBJ_ENHMETADC
;
811 FIXME("Magic %04x not implemented\n", GDIMAGIC(ptr
->wMagic
) );
814 GDI_ReleaseObj( handle
);
818 /***********************************************************************
819 * GetCurrentObject (GDI32.@)
821 HANDLE WINAPI
GetCurrentObject(HDC hdc
,UINT type
)
824 DC
* dc
= DC_GetDCPtr( hdc
);
829 case OBJ_PEN
: ret
= dc
->hPen
; break;
830 case OBJ_BRUSH
: ret
= dc
->hBrush
; break;
831 case OBJ_PAL
: ret
= dc
->hPalette
; break;
832 case OBJ_FONT
: ret
= dc
->hFont
; break;
833 case OBJ_BITMAP
: ret
= dc
->hBitmap
; break;
835 /* the SDK only mentions those above */
836 FIXME("(%08x,%d): unknown type.\n",hdc
,type
);
839 GDI_ReleaseObj( hdc
);
845 /***********************************************************************
846 * SelectObject16 (GDI.45)
848 HGDIOBJ16 WINAPI
SelectObject16( HDC16 hdc
, HGDIOBJ16 handle
)
850 return (HGDIOBJ16
)SelectObject( hdc
, handle
);
854 /***********************************************************************
855 * SelectObject (GDI32.@)
857 HGDIOBJ WINAPI
SelectObject( HDC hdc
, HGDIOBJ handle
)
860 DC
* dc
= DC_GetDCUpdate( hdc
);
862 TRACE("hdc=%04x %04x\n", hdc
, handle
);
863 if (dc
->funcs
->pSelectObject
)
864 ret
= dc
->funcs
->pSelectObject( dc
, handle
);
865 GDI_ReleaseObj( hdc
);
870 /***********************************************************************
871 * UnrealizeObject16 (GDI.150)
873 BOOL16 WINAPI
UnrealizeObject16( HGDIOBJ16 obj
)
875 return UnrealizeObject( obj
);
879 /***********************************************************************
880 * UnrealizeObject (GDI32.@)
882 BOOL WINAPI
UnrealizeObject( HGDIOBJ obj
)
885 /* Check if object is valid */
887 GDIOBJHDR
* header
= GDI_GetObjPtr( obj
, MAGIC_DONTCARE
);
888 if (!header
) return FALSE
;
890 TRACE("%04x\n", obj
);
892 /* Unrealize object */
894 switch(GDIMAGIC(header
->wMagic
))
897 result
= PALETTE_UnrealizeObject( obj
, (PALETTEOBJ
*)header
);
901 /* Windows resets the brush origin. We don't need to. */
904 GDI_ReleaseObj( obj
);
909 /***********************************************************************
910 * EnumObjects16 (GDI.71)
912 INT16 WINAPI
EnumObjects16( HDC16 hdc
, INT16 nObjType
,
913 GOBJENUMPROC16 lpEnumFunc
, LPARAM lParam
)
915 /* Solid colors to enumerate */
916 static const COLORREF solid_colors
[] =
917 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
918 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
919 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
920 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
921 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
922 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
923 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
924 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
929 LOGBRUSH16
*brush
= NULL
;
931 TRACE("%04x %d %08lx %08lx\n",
932 hdc
, nObjType
, (DWORD
)lpEnumFunc
, lParam
);
936 /* Enumerate solid pens */
937 if (!(pen
= SEGPTR_NEW(LOGPEN16
))) break;
938 for (i
= 0; i
< sizeof(solid_colors
)/sizeof(solid_colors
[0]); i
++)
940 pen
->lopnStyle
= PS_SOLID
;
941 pen
->lopnWidth
.x
= 1;
942 pen
->lopnWidth
.y
= 0;
943 pen
->lopnColor
= solid_colors
[i
];
944 retval
= lpEnumFunc( SEGPTR_GET(pen
), lParam
);
945 TRACE("solid pen %08lx, ret=%d\n",
946 solid_colors
[i
], retval
);
953 /* Enumerate solid brushes */
954 if (!(brush
= SEGPTR_NEW(LOGBRUSH16
))) break;
955 for (i
= 0; i
< sizeof(solid_colors
)/sizeof(solid_colors
[0]); i
++)
957 brush
->lbStyle
= BS_SOLID
;
958 brush
->lbColor
= solid_colors
[i
];
960 retval
= lpEnumFunc( SEGPTR_GET(brush
), lParam
);
961 TRACE("solid brush %08lx, ret=%d\n",
962 solid_colors
[i
], retval
);
966 /* Now enumerate hatched brushes */
967 if (retval
) for (i
= HS_HORIZONTAL
; i
<= HS_DIAGCROSS
; i
++)
969 brush
->lbStyle
= BS_HATCHED
;
970 brush
->lbColor
= RGB(0,0,0);
972 retval
= lpEnumFunc( SEGPTR_GET(brush
), lParam
);
973 TRACE("hatched brush %d, ret=%d\n",
981 WARN("(%d): Invalid type\n", nObjType
);
988 /***********************************************************************
989 * EnumObjects (GDI32.@)
991 INT WINAPI
EnumObjects( HDC hdc
, INT nObjType
,
992 GOBJENUMPROC lpEnumFunc
, LPARAM lParam
)
994 /* Solid colors to enumerate */
995 static const COLORREF solid_colors
[] =
996 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
997 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
998 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
999 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
1000 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
1001 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
1002 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
1003 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
1010 TRACE("%04x %d %08lx %08lx\n",
1011 hdc
, nObjType
, (DWORD
)lpEnumFunc
, lParam
);
1015 /* Enumerate solid pens */
1016 for (i
= 0; i
< sizeof(solid_colors
)/sizeof(solid_colors
[0]); i
++)
1018 pen
.lopnStyle
= PS_SOLID
;
1019 pen
.lopnWidth
.x
= 1;
1020 pen
.lopnWidth
.y
= 0;
1021 pen
.lopnColor
= solid_colors
[i
];
1022 retval
= lpEnumFunc( &pen
, lParam
);
1023 TRACE("solid pen %08lx, ret=%d\n",
1024 solid_colors
[i
], retval
);
1030 /* Enumerate solid brushes */
1031 for (i
= 0; i
< sizeof(solid_colors
)/sizeof(solid_colors
[0]); i
++)
1033 brush
.lbStyle
= BS_SOLID
;
1034 brush
.lbColor
= solid_colors
[i
];
1036 retval
= lpEnumFunc( &brush
, lParam
);
1037 TRACE("solid brush %08lx, ret=%d\n",
1038 solid_colors
[i
], retval
);
1042 /* Now enumerate hatched brushes */
1043 if (retval
) for (i
= HS_HORIZONTAL
; i
<= HS_DIAGCROSS
; i
++)
1045 brush
.lbStyle
= BS_HATCHED
;
1046 brush
.lbColor
= RGB(0,0,0);
1048 retval
= lpEnumFunc( &brush
, lParam
);
1049 TRACE("hatched brush %d, ret=%d\n",
1056 /* FIXME: implement Win32 types */
1057 WARN("(%d): Invalid type\n", nObjType
);
1064 /***********************************************************************
1065 * IsGDIObject (GDI.462)
1067 * returns type of object if valid (W95 system programming secrets p. 264-5)
1069 BOOL16 WINAPI
IsGDIObject16( HGDIOBJ16 handle
)
1073 GDIOBJHDR
*object
= GDI_GetObjPtr( handle
, MAGIC_DONTCARE
);
1076 magic
= GDIMAGIC(object
->wMagic
) - PEN_MAGIC
+ 1;
1077 GDI_ReleaseObj( handle
);
1083 /***********************************************************************
1084 * SetObjectOwner16 (GDI.461)
1086 void WINAPI
SetObjectOwner16( HGDIOBJ16 handle
, HANDLE16 owner
)
1092 /***********************************************************************
1093 * SetObjectOwner (GDI32.@)
1095 void WINAPI
SetObjectOwner( HGDIOBJ handle
, HANDLE owner
)
1101 /***********************************************************************
1102 * MakeObjectPrivate (GDI.463)
1104 * What does that mean ?
1105 * Some little docu can be found in "Undocumented Windows",
1106 * but this is basically useless.
1107 * At least we know that this flags the GDI object's wMagic
1108 * with 0x2000 (OBJECT_PRIVATE), so we just do it.
1109 * But Wine doesn't react on that yet.
1111 void WINAPI
MakeObjectPrivate16( HGDIOBJ16 handle
, BOOL16
private )
1113 GDIOBJHDR
*ptr
= GDI_GetObjPtr( handle
, MAGIC_DONTCARE
);
1116 ERR("invalid GDI object %04x !\n", handle
);
1119 ptr
->wMagic
|= OBJECT_PRIVATE
;
1120 GDI_ReleaseObj( handle
);
1124 /***********************************************************************
1125 * GdiFlush (GDI32.@)
1127 BOOL WINAPI
GdiFlush(void)
1129 return TRUE
; /* FIXME */
1133 /***********************************************************************
1134 * GdiGetBatchLimit (GDI32.@)
1136 DWORD WINAPI
GdiGetBatchLimit(void)
1138 return 1; /* FIXME */
1142 /***********************************************************************
1143 * GdiSetBatchLimit (GDI32.@)
1145 DWORD WINAPI
GdiSetBatchLimit( DWORD limit
)
1147 return 1; /* FIXME */
1151 /***********************************************************************
1152 * GdiSeeGdiDo (GDI.452)
1154 DWORD WINAPI
GdiSeeGdiDo16( WORD wReqType
, WORD wParam1
, WORD wParam2
,
1159 case 0x0001: /* LocalAlloc */
1160 return LOCAL_Alloc( GDI_HeapSel
, wParam1
, wParam3
);
1161 case 0x0002: /* LocalFree */
1162 return LOCAL_Free( GDI_HeapSel
, wParam1
);
1163 case 0x0003: /* LocalCompact */
1164 return LOCAL_Compact( GDI_HeapSel
, wParam3
, 0 );
1165 case 0x0103: /* LocalHeap */
1168 WARN("(wReqType=%04x): Unknown\n", wReqType
);
1173 /***********************************************************************
1174 * GdiSignalProc (GDI.610)
1176 WORD WINAPI
GdiSignalProc( UINT uCode
, DWORD dwThreadOrProcessID
,
1177 DWORD dwFlags
, HMODULE16 hModule
)
1182 /***********************************************************************
1183 * FinalGdiInit16 (GDI.405)
1185 void WINAPI
FinalGdiInit16( HANDLE16 unknown
)
1189 /***********************************************************************
1190 * GdiFreeResources (GDI.609)
1192 WORD WINAPI
GdiFreeResources16( DWORD reserve
)
1194 return (WORD
)( (int)LOCAL_CountFree( GDI_HeapSel
) * 100 /
1195 (int)LOCAL_HeapSize( GDI_HeapSel
) );
1198 /***********************************************************************
1199 * MulDiv16 (GDI.128)
1201 INT16 WINAPI
MulDiv16(
1202 INT16 nMultiplicand
,
1207 if (!nDivisor
) return -32768;
1208 /* We want to deal with a positive divisor to simplify the logic. */
1211 nMultiplicand
= - nMultiplicand
;
1212 nDivisor
= -nDivisor
;
1214 /* If the result is positive, we "add" to round. else,
1215 * we subtract to round. */
1216 if ( ( (nMultiplicand
< 0) && (nMultiplier
< 0) ) ||
1217 ( (nMultiplicand
>= 0) && (nMultiplier
>= 0) ) )
1218 ret
= (((int)nMultiplicand
* nMultiplier
) + (nDivisor
/2)) / nDivisor
;
1220 ret
= (((int)nMultiplicand
* nMultiplier
) - (nDivisor
/2)) / nDivisor
;
1221 if ((ret
> 32767) || (ret
< -32767)) return -32768;
1226 /*******************************************************************
1227 * GetColorAdjustment [GDI32.@]
1231 BOOL WINAPI
GetColorAdjustment(HDC hdc
, LPCOLORADJUSTMENT lpca
)
1233 FIXME("GetColorAdjustment, stub\n");
1237 /*******************************************************************
1238 * GetMiterLimit [GDI32.@]
1242 BOOL WINAPI
GetMiterLimit(HDC hdc
, PFLOAT peLimit
)
1244 FIXME("GetMiterLimit, stub\n");
1248 /*******************************************************************
1249 * SetMiterLimit [GDI32.@]
1253 BOOL WINAPI
SetMiterLimit(HDC hdc
, FLOAT eNewLimit
, PFLOAT peOldLimit
)
1255 FIXME("SetMiterLimit, stub\n");
1259 /*******************************************************************
1260 * GdiComment [GDI32.@]
1264 BOOL WINAPI
GdiComment(HDC hdc
, UINT cbSize
, const BYTE
*lpData
)
1266 FIXME("GdiComment, stub\n");
1269 /*******************************************************************
1270 * SetColorAdjustment [GDI32.@]
1274 BOOL WINAPI
SetColorAdjustment(HDC hdc
, const COLORADJUSTMENT
* lpca
)
1276 FIXME("SetColorAdjustment, stub\n");