Added separate server pipe to wait on blocking server calls.
[wine/multimedia.git] / objects / gdiobj.c
blob73730af9488a7b6ae6fd780418e3d868c000298a
1 /*
2 * GDI functions
4 * Copyright 1993 Alexandre Julliard
5 */
7 #include "config.h"
9 #include <assert.h>
10 #include <stdlib.h>
11 #include <stdio.h>
13 #include "windef.h"
14 #include "wingdi.h"
15 #include "winerror.h"
16 #include "wine/winbase16.h"
18 #include "bitmap.h"
19 #include "brush.h"
20 #include "font.h"
21 #include "heap.h"
22 #include "local.h"
23 #include "options.h"
24 #include "palette.h"
25 #include "pen.h"
26 #include "region.h"
27 #include "debugtools.h"
28 #include "gdi.h"
30 DEFAULT_DEBUG_CHANNEL(gdi);
33 /***********************************************************************
34 * GDI stock objects
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,
160 NULL,
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,
181 * FONTOBJ *font,
182 * int defHeight,
183 * int defBold,
184 * int defItalic,
185 * int defUnderline,
186 * int defStrikeOut )
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
193 * underline).
194 *****************************************************************************/
196 static void ReadFontInformation(
197 char const *fontName,
198 FONTOBJ *font,
199 int defHeight,
200 int defBold,
201 int defItalic,
202 int defUnderline,
203 int defStrikeOut )
205 char key[256];
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)) ?
217 FW_BOLD : FW_NORMAL;
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);
231 return;
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)
243 HDC hdc;
244 HFONT hOldFont;
246 hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
248 hOldFont = (HFONT)SelectObject(hdc, handle);
250 GetTextMetricsA(hdc, lptm);
252 SelectObject(hdc, hOldFont);
254 DeleteDC(hdc);
257 static inline void FixStockFontSize16(
258 HFONT handle,
259 INT16 count,
260 LPVOID buffer)
262 TEXTMETRICA tm;
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(
280 HFONT handle,
281 INT count,
282 LPVOID buffer)
284 TEXTMETRICA tm;
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 /***********************************************************************
312 * GDI_Init
314 * GDI initialization.
316 BOOL GDI_Init(void)
318 HPALETTE16 hpalette;
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 );
342 return TRUE;
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 /***********************************************************************
351 * alloc_large_heap
353 * Allocate a GDI handle from the large heap. Helper for GDI_AllocObject
355 inline static GDIOBJHDR *alloc_large_heap( WORD size, HGDIOBJ *handle )
357 int i;
358 GDIOBJHDR *obj;
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;
364 *handle = 0;
365 return NULL;
367 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;
374 return obj;
378 /***********************************************************************
379 * GDI_AllocObject
381 void *GDI_AllocObject( WORD size, WORD magic, HGDIOBJ *handle )
383 static DWORD count = 0;
384 GDIOBJHDR *obj;
386 _EnterSysLevel( &GDI_level );
387 switch(magic)
389 /* allocate DCs on the larger heap */
390 case DC_MAGIC:
391 case DISABLED_DC_MAGIC:
392 case META_DC_MAGIC:
393 case METAFILE_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;
398 break;
399 default:
400 if (!(*handle = LOCAL_Alloc( GDI_HeapSel, LMEM_MOVEABLE, size ))) goto error;
401 assert( *handle & 2 );
402 obj = (GDIOBJHDR *)LOCAL_Lock( GDI_HeapSel, *handle );
403 break;
406 obj->hNext = 0;
407 obj->wMagic = magic|OBJECT_NOSYSTEM;
408 obj->dwCount = ++count;
410 TRACE_SEC( *handle, "enter" );
411 return obj;
413 error:
414 _LeaveSysLevel( &GDI_level );
415 *handle = 0;
416 return NULL;
420 /***********************************************************************
421 * GDI_ReallocObject
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 )
428 HGDIOBJ new_handle;
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 );
436 return NULL;
438 assert( new_handle == handle ); /* moveable handle cannot change */
439 return LOCAL_Lock( GDI_HeapSel, handle );
443 /***********************************************************************
444 * GDI_FreeObject
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 );
471 return TRUE;
475 /***********************************************************************
476 * GDI_GetObjPtr
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 );
497 if (ptr &&
498 (magic != MAGIC_DONTCARE) && (GDIMAGIC(ptr->wMagic) != magic))
500 LOCAL_Unlock( GDI_HeapSel, handle );
501 ptr = NULL;
504 else /* large heap handle */
506 int i = (handle >> 2) - FIRST_LARGE_HANDLE;
507 if (i >= 0)
509 ptr = large_handles[i];
510 if (ptr && (magic != MAGIC_DONTCARE) && (GDIMAGIC(ptr->wMagic) != magic)) ptr = NULL;
514 if (!ptr)
516 _LeaveSysLevel( &GDI_level );
517 SetLastError( ERROR_INVALID_HANDLE );
519 else TRACE_SEC( handle, "enter" );
521 return ptr;
525 /***********************************************************************
526 * GDI_ReleaseObj
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 */
553 GDIOBJHDR * header;
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 */
558 return TRUE;
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 );
568 return TRUE;
571 TRACE("%04x\n", obj );
573 /* Delete object */
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 );
583 case DC_MAGIC:
584 GDI_ReleaseObj( obj );
585 return DeleteDC(obj);
586 case 0 :
587 WARN("Already deleted\n");
588 break;
589 default:
590 WARN("Unknown magic number (%d)\n",GDIMAGIC(header->wMagic));
592 GDI_ReleaseObj( obj );
593 return FALSE;
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 )
610 HGDIOBJ ret;
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 );
615 return ret;
619 /***********************************************************************
620 * GetObject16 (GDI.82)
622 INT16 WINAPI GetObject16( HANDLE16 handle, INT16 count, LPVOID buffer )
624 GDIOBJHDR * ptr;
625 INT16 result = 0;
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))
633 case PEN_MAGIC:
634 result = PEN_GetObject16( (PENOBJ *)ptr, count, buffer );
635 break;
636 case BRUSH_MAGIC:
637 result = BRUSH_GetObject16( (BRUSHOBJ *)ptr, count, buffer );
638 break;
639 case BITMAP_MAGIC:
640 result = BITMAP_GetObject16( (BITMAPOBJ *)ptr, count, buffer );
641 break;
642 case FONT_MAGIC:
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);
651 break;
652 case PALETTE_MAGIC:
653 result = PALETTE_GetObject( (PALETTEOBJ *)ptr, count, buffer );
654 break;
656 GDI_ReleaseObj( handle );
657 return result;
661 /***********************************************************************
662 * GetObjectA (GDI32.@)
664 INT WINAPI GetObjectA( HANDLE handle, INT count, LPVOID buffer )
666 GDIOBJHDR * ptr;
667 INT result = 0;
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))
675 case PEN_MAGIC:
676 result = PEN_GetObject( (PENOBJ *)ptr, count, buffer );
677 break;
678 case BRUSH_MAGIC:
679 result = BRUSH_GetObject( (BRUSHOBJ *)ptr, count, buffer );
680 break;
681 case BITMAP_MAGIC:
682 result = BITMAP_GetObject( (BITMAPOBJ *)ptr, count, buffer );
683 break;
684 case FONT_MAGIC:
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);
693 break;
694 case PALETTE_MAGIC:
695 result = PALETTE_GetObject( (PALETTEOBJ *)ptr, count, buffer );
696 break;
698 case REGION_MAGIC:
699 case DC_MAGIC:
700 case DISABLED_DC_MAGIC:
701 case META_DC_MAGIC:
702 case METAFILE_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) );
707 break;
709 default:
710 ERR("Invalid GDI Magic %04x\n", GDIMAGIC(ptr->wMagic));
711 break;
713 GDI_ReleaseObj( handle );
714 return result;
717 /***********************************************************************
718 * GetObjectW (GDI32.@)
720 INT WINAPI GetObjectW( HANDLE handle, INT count, LPVOID buffer )
722 GDIOBJHDR * ptr;
723 INT result = 0;
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))
731 case PEN_MAGIC:
732 result = PEN_GetObject( (PENOBJ *)ptr, count, buffer );
733 break;
734 case BRUSH_MAGIC:
735 result = BRUSH_GetObject( (BRUSHOBJ *)ptr, count, buffer );
736 break;
737 case BITMAP_MAGIC:
738 result = BITMAP_GetObject( (BITMAPOBJ *)ptr, count, buffer );
739 break;
740 case FONT_MAGIC:
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);
749 break;
750 case PALETTE_MAGIC:
751 result = PALETTE_GetObject( (PALETTEOBJ *)ptr, count, buffer );
752 break;
753 default:
754 FIXME("Magic %04x not implemented\n", GDIMAGIC(ptr->wMagic) );
755 break;
757 GDI_ReleaseObj( handle );
758 return result;
761 /***********************************************************************
762 * GetObjectType (GDI32.@)
764 DWORD WINAPI GetObjectType( HANDLE handle )
766 GDIOBJHDR * ptr;
767 INT result = 0;
768 TRACE("%08x\n", handle );
770 if (!(ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) return 0;
772 switch(GDIMAGIC(ptr->wMagic))
774 case PEN_MAGIC:
775 result = OBJ_PEN;
776 break;
777 case BRUSH_MAGIC:
778 result = OBJ_BRUSH;
779 break;
780 case BITMAP_MAGIC:
781 result = OBJ_BITMAP;
782 break;
783 case FONT_MAGIC:
784 result = OBJ_FONT;
785 break;
786 case PALETTE_MAGIC:
787 result = OBJ_PAL;
788 break;
789 case REGION_MAGIC:
790 result = OBJ_REGION;
791 break;
792 case DC_MAGIC:
793 result = OBJ_DC;
794 break;
795 case META_DC_MAGIC:
796 result = OBJ_METADC;
797 break;
798 case METAFILE_MAGIC:
799 result = OBJ_METAFILE;
800 break;
801 case METAFILE_DC_MAGIC:
802 result = OBJ_METADC;
803 break;
804 case ENHMETAFILE_MAGIC:
805 result = OBJ_ENHMETAFILE;
806 break;
807 case ENHMETAFILE_DC_MAGIC:
808 result = OBJ_ENHMETADC;
809 break;
810 default:
811 FIXME("Magic %04x not implemented\n", GDIMAGIC(ptr->wMagic) );
812 break;
814 GDI_ReleaseObj( handle );
815 return result;
818 /***********************************************************************
819 * GetCurrentObject (GDI32.@)
821 HANDLE WINAPI GetCurrentObject(HDC hdc,UINT type)
823 HANDLE ret = 0;
824 DC * dc = DC_GetDCPtr( hdc );
826 if (dc)
828 switch (type) {
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;
834 default:
835 /* the SDK only mentions those above */
836 FIXME("(%08x,%d): unknown type.\n",hdc,type);
837 break;
839 GDI_ReleaseObj( hdc );
841 return ret;
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 )
859 HGDIOBJ ret = 0;
860 DC * dc = DC_GetDCUpdate( hdc );
861 if (!dc) return 0;
862 TRACE("hdc=%04x %04x\n", hdc, handle );
863 if (dc->funcs->pSelectObject)
864 ret = dc->funcs->pSelectObject( dc, handle );
865 GDI_ReleaseObj( hdc );
866 return ret;
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 )
884 BOOL result = TRUE;
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))
896 case PALETTE_MAGIC:
897 result = PALETTE_UnrealizeObject( obj, (PALETTEOBJ *)header );
898 break;
900 case BRUSH_MAGIC:
901 /* Windows resets the brush origin. We don't need to. */
902 break;
904 GDI_ReleaseObj( obj );
905 return result;
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)
927 INT16 i, retval = 0;
928 LOGPEN16 *pen;
929 LOGBRUSH16 *brush = NULL;
931 TRACE("%04x %d %08lx %08lx\n",
932 hdc, nObjType, (DWORD)lpEnumFunc, lParam );
933 switch(nObjType)
935 case OBJ_PEN:
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);
947 if (!retval) break;
949 SEGPTR_FREE(pen);
950 break;
952 case OBJ_BRUSH:
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];
959 brush->lbHatch = 0;
960 retval = lpEnumFunc( SEGPTR_GET(brush), lParam );
961 TRACE("solid brush %08lx, ret=%d\n",
962 solid_colors[i], retval);
963 if (!retval) break;
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);
971 brush->lbHatch = i;
972 retval = lpEnumFunc( SEGPTR_GET(brush), lParam );
973 TRACE("hatched brush %d, ret=%d\n",
974 i, retval);
975 if (!retval) break;
977 SEGPTR_FREE(brush);
978 break;
980 default:
981 WARN("(%d): Invalid type\n", nObjType );
982 break;
984 return retval;
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)
1006 INT i, retval = 0;
1007 LOGPEN pen;
1008 LOGBRUSH brush;
1010 TRACE("%04x %d %08lx %08lx\n",
1011 hdc, nObjType, (DWORD)lpEnumFunc, lParam );
1012 switch(nObjType)
1014 case OBJ_PEN:
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);
1025 if (!retval) break;
1027 break;
1029 case OBJ_BRUSH:
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];
1035 brush.lbHatch = 0;
1036 retval = lpEnumFunc( &brush, lParam );
1037 TRACE("solid brush %08lx, ret=%d\n",
1038 solid_colors[i], retval);
1039 if (!retval) break;
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);
1047 brush.lbHatch = i;
1048 retval = lpEnumFunc( &brush, lParam );
1049 TRACE("hatched brush %d, ret=%d\n",
1050 i, retval);
1051 if (!retval) break;
1053 break;
1055 default:
1056 /* FIXME: implement Win32 types */
1057 WARN("(%d): Invalid type\n", nObjType );
1058 break;
1060 return retval;
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 )
1071 UINT16 magic = 0;
1073 GDIOBJHDR *object = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
1074 if (object)
1076 magic = GDIMAGIC(object->wMagic) - PEN_MAGIC + 1;
1077 GDI_ReleaseObj( handle );
1079 return magic;
1083 /***********************************************************************
1084 * SetObjectOwner16 (GDI.461)
1086 void WINAPI SetObjectOwner16( HGDIOBJ16 handle, HANDLE16 owner )
1088 /* Nothing to do */
1092 /***********************************************************************
1093 * SetObjectOwner (GDI32.@)
1095 void WINAPI SetObjectOwner( HGDIOBJ handle, HANDLE owner )
1097 /* Nothing to do */
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 );
1114 if (!ptr)
1116 ERR("invalid GDI object %04x !\n", handle);
1117 return;
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,
1155 WORD wParam3 )
1157 switch (wReqType)
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 */
1166 return GDI_HeapSel;
1167 default:
1168 WARN("(wReqType=%04x): Unknown\n", wReqType);
1169 return (DWORD)-1;
1173 /***********************************************************************
1174 * GdiSignalProc (GDI.610)
1176 WORD WINAPI GdiSignalProc( UINT uCode, DWORD dwThreadOrProcessID,
1177 DWORD dwFlags, HMODULE16 hModule )
1179 return 0;
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,
1203 INT16 nMultiplier,
1204 INT16 nDivisor)
1206 INT ret;
1207 if (!nDivisor) return -32768;
1208 /* We want to deal with a positive divisor to simplify the logic. */
1209 if (nDivisor < 0)
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;
1219 else
1220 ret = (((int)nMultiplicand * nMultiplier) - (nDivisor/2)) / nDivisor;
1221 if ((ret > 32767) || (ret < -32767)) return -32768;
1222 return (INT16) ret;
1226 /*******************************************************************
1227 * GetColorAdjustment [GDI32.@]
1231 BOOL WINAPI GetColorAdjustment(HDC hdc, LPCOLORADJUSTMENT lpca)
1233 FIXME("GetColorAdjustment, stub\n");
1234 return 0;
1237 /*******************************************************************
1238 * GetMiterLimit [GDI32.@]
1242 BOOL WINAPI GetMiterLimit(HDC hdc, PFLOAT peLimit)
1244 FIXME("GetMiterLimit, stub\n");
1245 return 0;
1248 /*******************************************************************
1249 * SetMiterLimit [GDI32.@]
1253 BOOL WINAPI SetMiterLimit(HDC hdc, FLOAT eNewLimit, PFLOAT peOldLimit)
1255 FIXME("SetMiterLimit, stub\n");
1256 return 0;
1259 /*******************************************************************
1260 * GdiComment [GDI32.@]
1264 BOOL WINAPI GdiComment(HDC hdc, UINT cbSize, const BYTE *lpData)
1266 FIXME("GdiComment, stub\n");
1267 return 0;
1269 /*******************************************************************
1270 * SetColorAdjustment [GDI32.@]
1274 BOOL WINAPI SetColorAdjustment(HDC hdc, const COLORADJUSTMENT* lpca)
1276 FIXME("SetColorAdjustment, stub\n");
1277 return 0;