4 * Copyright 1993 Alexandre Julliard
25 /***********************************************************************
29 static BRUSHOBJ WhiteBrush =
31 { 0, BRUSH_MAGIC, 1 }, /* header */
32 { BS_SOLID, RGB(255,255,255), 0 } /* logbrush */
35 static BRUSHOBJ LtGrayBrush =
37 { 0, BRUSH_MAGIC, 1 }, /* header */
38 /* FIXME : this should perhaps be BS_HATCHED, at least for 1 bitperpixel */
39 { BS_SOLID, RGB(192,192,192), 0 } /* logbrush */
42 static BRUSHOBJ GrayBrush =
44 { 0, BRUSH_MAGIC, 1 }, /* header */
45 /* FIXME : this should perhaps be BS_HATCHED, at least for 1 bitperpixel */
46 { BS_SOLID, RGB(128,128,128), 0 } /* logbrush */
49 static BRUSHOBJ DkGrayBrush =
51 { 0, BRUSH_MAGIC, 1 }, /* header */
52 /* This is BS_HATCHED, for 1 bitperpixel. This makes the spray work in pbrush */
53 /* NB_HATCH_STYLES is an index into HatchBrushes */
54 { BS_HATCHED, RGB(0,0,0), NB_HATCH_STYLES } /* logbrush */
57 static BRUSHOBJ BlackBrush =
59 { 0, BRUSH_MAGIC, 1 }, /* header */
60 { BS_SOLID, RGB(0,0,0), 0 } /* logbrush */
63 static BRUSHOBJ NullBrush =
65 { 0, BRUSH_MAGIC, 1 }, /* header */
66 { BS_NULL, 0, 0 } /* logbrush */
69 static PENOBJ WhitePen =
71 { 0, PEN_MAGIC, 1 }, /* header */
72 { PS_SOLID, { 1, 0 }, RGB(255,255,255) } /* logpen */
75 static PENOBJ BlackPen =
77 { 0, PEN_MAGIC, 1 }, /* header */
78 { PS_SOLID, { 1, 0 }, RGB(0,0,0) } /* logpen */
81 static PENOBJ NullPen =
83 { 0, PEN_MAGIC, 1 }, /* header */
84 { PS_NULL, { 1, 0 }, 0 } /* logpen */
87 static FONTOBJ OEMFixedFont =
89 { 0, FONT_MAGIC, 1 }, /* header */
90 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, OEM_CHARSET,
91 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, "" }
94 static FONTOBJ AnsiFixedFont =
96 { 0, FONT_MAGIC, 1 }, /* header */
97 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
98 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, "" }
101 static FONTOBJ AnsiVarFont =
103 { 0, FONT_MAGIC, 1 }, /* header */
104 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
105 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS, "MS Sans Serif" }
108 static FONTOBJ SystemFont =
110 { 0, FONT_MAGIC, 1 },
111 { 16, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET,
112 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS, "System" }
115 static FONTOBJ DeviceDefaultFont =
117 { 0, FONT_MAGIC, 1 }, /* header */
118 { 12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
119 0, 0, DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS, "" }
122 static FONTOBJ SystemFixedFont =
124 { 0, FONT_MAGIC, 1 }, /* header */
125 { 12, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET,
126 0, 0, DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN, "" }
130 static GDIOBJHDR * StockObjects[NB_STOCK_OBJECTS] =
132 (GDIOBJHDR *) &WhiteBrush,
133 (GDIOBJHDR *) &LtGrayBrush,
134 (GDIOBJHDR *) &GrayBrush,
135 (GDIOBJHDR *) &DkGrayBrush,
136 (GDIOBJHDR *) &BlackBrush,
137 (GDIOBJHDR *) &NullBrush,
138 (GDIOBJHDR *) &WhitePen,
139 (GDIOBJHDR *) &BlackPen,
140 (GDIOBJHDR *) &NullPen,
142 (GDIOBJHDR *) &OEMFixedFont,
143 (GDIOBJHDR *) &AnsiFixedFont,
144 (GDIOBJHDR *) &AnsiVarFont,
145 (GDIOBJHDR *) &SystemFont,
146 (GDIOBJHDR *) &DeviceDefaultFont,
147 NULL, /* DEFAULT_PALETTE created by PALETTE_Init */
148 (GDIOBJHDR *) &SystemFixedFont
151 /******************************************************************************
153 * void ReadFontInformation(
154 * char const *fontName,
162 * ReadFontInformation() checks the Wine configuration file's Tweak.Fonts
163 * section for entries containing fontName.Height, fontName.Bold, etc.,
164 * where fontName is the name specified in the call (e.g., "System"). It
165 * attempts to be user friendly by accepting 'n', 'N', 'f', 'F', or '0' as
166 * the first character in the boolean attributes (bold, italic, and
168 *****************************************************************************/
170 static void ReadFontInformation(
171 char const *fontName,
181 sprintf(key, "%s.Height", fontName);
182 font->logfont.lfHeight =
183 PROFILE_GetWineIniInt("Tweak.Fonts", key, defHeight);
185 sprintf(key, "%s.Bold", fontName);
186 font->logfont.lfWeight =
187 (PROFILE_GetWineIniBool("Tweak.Fonts", key, defBold)) ?
190 sprintf(key, "%s.Italic", fontName);
191 font->logfont.lfItalic =
192 PROFILE_GetWineIniBool("Tweak.Fonts", key, defItalic);
194 sprintf(key, "%s.Underline", fontName);
195 font->logfont.lfUnderline =
196 PROFILE_GetWineIniBool("Tweak.Fonts", key, defUnderline);
198 sprintf(key, "%s.StrikeOut", fontName);
199 font->logfont.lfStrikeOut =
200 PROFILE_GetWineIniBool("Tweak.Fonts", key, defStrikeOut);
206 /***********************************************************************
209 * GDI initialization.
211 BOOL32 GDI_Init(void)
213 extern BOOL32 X11DRV_Init(void);
214 extern BOOL32 DIB_Init(void);
216 /* TWEAK: Initialize font hints */
217 ReadFontInformation("OEMFixed", &OEMFixedFont, 12, 0, 0, 0, 0);
218 ReadFontInformation("AnsiFixed", &AnsiFixedFont, 12, 0, 0, 0, 0);
219 ReadFontInformation("AnsiVar", &AnsiVarFont, 12, 0, 0, 0, 0);
220 ReadFontInformation("System", &SystemFont, 16, 1, 0, 0, 0);
221 ReadFontInformation("SystemFixed", &SystemFixedFont, 12, 1, 0, 0, 0);
223 /* Initialize drivers */
225 DIB_Init(); /* always before X11DRV_Init() */
229 /* Create default palette */
231 /* DR well *this* palette can't be moveable (?) */
233 HPALETTE16 hpalette = PALETTE_Init();
237 StockObjects[DEFAULT_PALETTE] = (GDIOBJHDR *)GDI_HEAP_LOCK( hpalette );
245 /***********************************************************************
248 HGDIOBJ16 GDI_AllocObject( WORD size, WORD magic )
250 static DWORD count = 0;
253 if ( magic == DC_MAGIC || magic == METAFILE_DC_MAGIC )
254 handle = GDI_HEAP_ALLOC( size );
256 handle = GDI_HEAP_ALLOC_MOVEABLE( size );
257 if (!handle) return 0;
258 obj = (GDIOBJHDR *) GDI_HEAP_LOCK( handle );
261 obj->dwCount = ++count;
262 GDI_HEAP_UNLOCK( handle );
267 /***********************************************************************
270 BOOL32 GDI_FreeObject( HGDIOBJ16 handle )
274 /* Can't free stock objects */
275 if ((handle >= FIRST_STOCK_HANDLE) && (handle <= LAST_STOCK_HANDLE))
278 object = (GDIOBJHDR *) GDI_HEAP_LOCK( handle );
279 if (!object) return FALSE;
280 object->wMagic = 0; /* Mark it as invalid */
284 GDI_HEAP_FREE( handle );
288 /***********************************************************************
291 * Return a pointer to the GDI object associated to the handle.
292 * Return NULL if the object has the wrong magic number.
293 * Movable GDI objects are locked in memory: it is up to the caller to unlock
294 * it after the caller is done with the pointer.
296 GDIOBJHDR * GDI_GetObjPtr( HGDIOBJ16 handle, WORD magic )
298 GDIOBJHDR * ptr = NULL;
300 if ((handle >= FIRST_STOCK_HANDLE) && (handle <= LAST_STOCK_HANDLE))
301 ptr = StockObjects[handle - FIRST_STOCK_HANDLE];
303 ptr = (GDIOBJHDR *) GDI_HEAP_LOCK( handle );
304 if (!ptr) return NULL;
305 if ((magic != MAGIC_DONTCARE) && (ptr->wMagic != magic))
307 GDI_HEAP_UNLOCK( handle );
314 /***********************************************************************
315 * DeleteObject16 (GDI.69)
317 BOOL16 WINAPI DeleteObject16( HGDIOBJ16 obj )
319 return DeleteObject32( obj );
323 /***********************************************************************
324 * DeleteObject32 (GDI32.70)
326 BOOL32 WINAPI DeleteObject32( HGDIOBJ32 obj )
328 /* Check if object is valid */
331 if (HIWORD(obj)) return FALSE;
332 if ((obj >= FIRST_STOCK_HANDLE) && (obj <= LAST_STOCK_HANDLE))
334 if (!(header = (GDIOBJHDR *) GDI_HEAP_LOCK( obj ))) return FALSE;
336 dprintf_gdi(stddeb, "DeleteObject: %04x\n", obj );
340 switch(header->wMagic)
342 case PEN_MAGIC: return GDI_FreeObject( obj );
343 case BRUSH_MAGIC: return BRUSH_DeleteObject( obj, (BRUSHOBJ*)header );
344 case FONT_MAGIC: return GDI_FreeObject( obj );
345 case PALETTE_MAGIC: return PALETTE_DeleteObject(obj,(PALETTEOBJ*)header);
346 case BITMAP_MAGIC: return BITMAP_DeleteObject( obj, (BITMAPOBJ*)header);
347 case REGION_MAGIC: return REGION_DeleteObject( obj, (RGNOBJ*)header );
353 /***********************************************************************
354 * GetStockObject16 (GDI.87)
356 HGDIOBJ16 WINAPI GetStockObject16( INT16 obj )
358 return (HGDIOBJ16)GetStockObject32( obj );
362 /***********************************************************************
363 * GetStockObject32 (GDI32.220)
365 HGDIOBJ32 WINAPI GetStockObject32( INT32 obj )
367 if ((obj < 0) || (obj >= NB_STOCK_OBJECTS)) return 0;
368 if (!StockObjects[obj]) return 0;
369 dprintf_gdi(stddeb, "GetStockObject: returning %d\n",
370 FIRST_STOCK_HANDLE + obj );
371 return (HGDIOBJ16)(FIRST_STOCK_HANDLE + obj);
375 /***********************************************************************
376 * GetObject16 (GDI.82)
378 INT16 WINAPI GetObject16( HANDLE16 handle, INT16 count, LPVOID buffer )
380 GDIOBJHDR * ptr = NULL;
382 dprintf_gdi(stddeb, "GetObject16: %04x %d %p\n", handle, count, buffer );
383 if (!count) return 0;
385 if ((handle >= FIRST_STOCK_HANDLE) && (handle <= LAST_STOCK_HANDLE))
386 ptr = StockObjects[handle - FIRST_STOCK_HANDLE];
388 ptr = (GDIOBJHDR *) GDI_HEAP_LOCK( handle );
394 result = PEN_GetObject16( (PENOBJ *)ptr, count, buffer );
397 result = BRUSH_GetObject16( (BRUSHOBJ *)ptr, count, buffer );
400 result = BITMAP_GetObject16( (BITMAPOBJ *)ptr, count, buffer );
403 result = FONT_GetObject16( (FONTOBJ *)ptr, count, buffer );
406 result = PALETTE_GetObject( (PALETTEOBJ *)ptr, count, buffer );
409 GDI_HEAP_UNLOCK( handle );
414 /***********************************************************************
415 * GetObject32A (GDI32.204)
417 INT32 WINAPI GetObject32A( HANDLE32 handle, INT32 count, LPVOID buffer )
419 GDIOBJHDR * ptr = NULL;
421 dprintf_gdi(stddeb, "GetObject32A: %08x %d %p\n", handle, count, buffer );
422 if (!count) return 0;
424 if ((handle >= FIRST_STOCK_HANDLE) && (handle <= LAST_STOCK_HANDLE))
425 ptr = StockObjects[handle - FIRST_STOCK_HANDLE];
427 ptr = (GDIOBJHDR *) GDI_HEAP_LOCK( handle );
433 result = PEN_GetObject32( (PENOBJ *)ptr, count, buffer );
436 result = BRUSH_GetObject32( (BRUSHOBJ *)ptr, count, buffer );
439 result = BITMAP_GetObject32( (BITMAPOBJ *)ptr, count, buffer );
442 result = FONT_GetObject32A( (FONTOBJ *)ptr, count, buffer );
445 fprintf( stderr, "GetObject32: magic %04x not implemented\n",
449 GDI_HEAP_UNLOCK( handle );
453 /***********************************************************************
454 * GetObjectType (GDI32.205)
456 DWORD WINAPI GetObjectType( HANDLE32 handle )
458 GDIOBJHDR * ptr = NULL;
460 dprintf_gdi(stddeb, "GetObjectType: %08x\n", handle );
462 if ((handle >= FIRST_STOCK_HANDLE) && (handle <= LAST_STOCK_HANDLE))
463 ptr = StockObjects[handle - FIRST_STOCK_HANDLE];
465 ptr = (GDIOBJHDR *) GDI_HEAP_LOCK( handle );
495 result = OBJ_METAFILE;
497 case METAFILE_DC_MAGIC:
502 fprintf( stderr, "GetObjectType: magic %04x not implemented\n",
506 GDI_HEAP_UNLOCK( handle );
510 /***********************************************************************
511 * GetObject32W (GDI32.206)
513 INT32 WINAPI GetObject32W( HANDLE32 handle, INT32 count, LPVOID buffer )
515 return GetObject32A( handle, count, buffer );
519 /***********************************************************************
520 * SelectObject16 (GDI.45)
522 HGDIOBJ16 WINAPI SelectObject16( HDC16 hdc, HGDIOBJ16 handle )
524 return (HGDIOBJ16)SelectObject32( hdc, handle );
528 /***********************************************************************
529 * SelectObject32 (GDI32.299)
531 HGDIOBJ32 WINAPI SelectObject32( HDC32 hdc, HGDIOBJ32 handle )
533 DC * dc = DC_GetDCPtr( hdc );
534 if (!dc || !dc->funcs->pSelectObject) return 0;
535 dprintf_gdi(stddeb, "SelectObject: hdc=%04x %04x\n", hdc, handle );
536 return dc->funcs->pSelectObject( dc, handle );
540 /***********************************************************************
541 * UnrealizeObject16 (GDI.150)
543 BOOL16 WINAPI UnrealizeObject16( HGDIOBJ16 obj )
545 return UnrealizeObject32( obj );
549 /***********************************************************************
550 * UnrealizeObject (GDI32.358)
552 BOOL32 WINAPI UnrealizeObject32( HGDIOBJ32 obj )
554 BOOL32 result = TRUE;
555 /* Check if object is valid */
557 GDIOBJHDR * header = (GDIOBJHDR *) GDI_HEAP_LOCK( obj );
558 if (!header) return FALSE;
560 dprintf_gdi( stddeb, "UnrealizeObject: %04x\n", obj );
562 /* Unrealize object */
564 switch(header->wMagic)
567 result = PALETTE_UnrealizeObject( obj, (PALETTEOBJ *)header );
571 /* Windows resets the brush origin. We don't need to. */
574 GDI_HEAP_UNLOCK( obj );
579 /***********************************************************************
580 * EnumObjects16 (GDI.71)
582 INT16 WINAPI EnumObjects16( HDC16 hdc, INT16 nObjType,
583 GOBJENUMPROC16 lpEnumFunc, LPARAM lParam )
585 /* Solid colors to enumerate */
586 static const COLORREF solid_colors[] =
587 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
588 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
589 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
590 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
591 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
592 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
593 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
594 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
599 LOGBRUSH16 *brush = NULL;
601 dprintf_gdi( stddeb, "EnumObjects16: %04x %d %08lx %08lx\n",
602 hdc, nObjType, (DWORD)lpEnumFunc, lParam );
606 /* Enumerate solid pens */
607 if (!(pen = SEGPTR_NEW(LOGPEN16))) break;
608 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
610 pen->lopnStyle = PS_SOLID;
611 pen->lopnWidth.x = 1;
612 pen->lopnWidth.y = 0;
613 pen->lopnColor = solid_colors[i];
614 retval = lpEnumFunc( SEGPTR_GET(pen), lParam );
615 dprintf_gdi( stddeb, "EnumObjects16: solid pen %08lx, ret=%d\n",
616 solid_colors[i], retval);
623 /* Enumerate solid brushes */
624 if (!(brush = SEGPTR_NEW(LOGBRUSH16))) break;
625 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
627 brush->lbStyle = BS_SOLID;
628 brush->lbColor = solid_colors[i];
630 retval = lpEnumFunc( SEGPTR_GET(brush), lParam );
631 dprintf_gdi( stddeb, "EnumObjects16: solid brush %08lx, ret=%d\n",
632 solid_colors[i], retval);
636 /* Now enumerate hatched brushes */
637 if (retval) for (i = HS_HORIZONTAL; i <= HS_DIAGCROSS; i++)
639 brush->lbStyle = BS_HATCHED;
640 brush->lbColor = RGB(0,0,0);
642 retval = lpEnumFunc( SEGPTR_GET(brush), lParam );
643 dprintf_gdi( stddeb, "EnumObjects16: hatched brush %d, ret=%d\n",
651 fprintf( stderr, "EnumObjects16: invalid type %d\n", nObjType );
658 /***********************************************************************
659 * EnumObjects32 (GDI32.89)
661 INT32 WINAPI EnumObjects32( HDC32 hdc, INT32 nObjType,
662 GOBJENUMPROC32 lpEnumFunc, LPARAM lParam )
664 /* Solid colors to enumerate */
665 static const COLORREF solid_colors[] =
666 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
667 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
668 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
669 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
670 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
671 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
672 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
673 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
680 dprintf_gdi( stddeb, "EnumObjects32: %04x %d %08lx %08lx\n",
681 hdc, nObjType, (DWORD)lpEnumFunc, lParam );
685 /* Enumerate solid pens */
686 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
688 pen.lopnStyle = PS_SOLID;
691 pen.lopnColor = solid_colors[i];
692 retval = lpEnumFunc( &pen, lParam );
693 dprintf_gdi( stddeb, "EnumObjects32: solid pen %08lx, ret=%d\n",
694 solid_colors[i], retval);
700 /* Enumerate solid brushes */
701 for (i = 0; i < sizeof(solid_colors)/sizeof(solid_colors[0]); i++)
703 brush.lbStyle = BS_SOLID;
704 brush.lbColor = solid_colors[i];
706 retval = lpEnumFunc( &brush, lParam );
707 dprintf_gdi( stddeb, "EnumObjects32: solid brush %08lx, ret=%d\n",
708 solid_colors[i], retval);
712 /* Now enumerate hatched brushes */
713 if (retval) for (i = HS_HORIZONTAL; i <= HS_DIAGCROSS; i++)
715 brush.lbStyle = BS_HATCHED;
716 brush.lbColor = RGB(0,0,0);
718 retval = lpEnumFunc( &brush, lParam );
719 dprintf_gdi( stddeb, "EnumObjects32: hatched brush %d, ret=%d\n",
726 /* FIXME: implement Win32 types */
727 fprintf( stderr, "EnumObjects32: invalid type %d\n", nObjType );
734 /***********************************************************************
735 * IsGDIObject (GDI.462)
737 * returns type of object if valid (W95 system programming secrets p. 264-5)
739 BOOL16 WINAPI IsGDIObject( HGDIOBJ16 handle )
741 GDIOBJHDR *object = (GDIOBJHDR *) GDI_HEAP_LOCK( handle );
744 UINT16 magic = object->wMagic;
745 GDI_HEAP_UNLOCK( handle );
746 if (magic >= PEN_MAGIC && magic <= METAFILE_DC_MAGIC)
747 return magic - PEN_MAGIC + 1;
753 /***********************************************************************
754 * SetObjectOwner16 (GDI.461)
756 void WINAPI SetObjectOwner16( HGDIOBJ16 handle, HANDLE16 owner )
762 /***********************************************************************
763 * SetObjectOwner32 (GDI32.386)
765 void WINAPI SetObjectOwner32( HGDIOBJ32 handle, HANDLE32 owner )
770 /***********************************************************************
771 * GdiFlush (GDI32.128)
773 BOOL32 WINAPI GdiFlush(void)
775 return TRUE; /* FIXME */
779 /***********************************************************************
780 * GdiGetBatchLimit (GDI32.129)
782 DWORD WINAPI GdiGetBatchLimit(void)
784 return 1; /* FIXME */
788 /***********************************************************************
789 * GdiSetBatchLimit (GDI32.139)
791 DWORD WINAPI GdiSetBatchLimit( DWORD limit )
793 return 1; /* FIXME */
797 /***********************************************************************
800 INT16 WINAPI MulDiv16( INT16 foo, INT16 bar, INT16 baz )
803 if (!baz) return -32768;
804 ret = (foo * bar) / baz;
805 if ((ret > 32767) || (ret < -32767)) return -32768;
810 /***********************************************************************
811 * MulDiv32 (KERNEL32.391)
813 INT32 WINAPI MulDiv32( INT32 foo, INT32 bar, INT32 baz )
818 ret = ((long long)foo * bar) / baz;
819 if ((ret > 2147483647) || (ret < -2147483647)) return -1;
823 return (foo * bar) / baz;