Changed DOS extended error handling to be based on SetLastError;
[wine/multimedia.git] / graphics / painting.c
blobb424d6382369d508d8f4f4473c97b78160105683
1 /*
2 * Misc. graphics operations
4 * Copyright 1993, 1994 Alexandre Julliard
5 * Copyright 1997 Bertho A. Stultiens
6 */
8 #include <math.h>
9 #include <stdlib.h>
10 #include "ts_xlib.h"
11 #include "ts_xutil.h"
12 #include <X11/Intrinsic.h>
13 #ifndef PI
14 #define PI M_PI
15 #endif
16 #include "gdi.h"
17 #include "dc.h"
18 #include "bitmap.h"
19 #include "callback.h"
20 #include "heap.h"
21 #include "metafile.h"
22 #include "palette.h"
23 #include "cache.h"
24 #include "region.h"
25 #include "path.h"
26 #include "debug.h"
27 #include "winerror.h"
28 #include "x11drv.h"
30 /***********************************************************************
31 * LineTo16 (GDI.19)
33 BOOL16 WINAPI LineTo16( HDC16 hdc, INT16 x, INT16 y )
35 return LineTo32( hdc, x, y );
39 /***********************************************************************
40 * LineTo32 (GDI32.249)
42 BOOL32 WINAPI LineTo32( HDC32 hdc, INT32 x, INT32 y )
44 DC * dc = DC_GetDCPtr( hdc );
46 if(dc && PATH_IsPathOpen(dc->w.path))
47 if(!PATH_LineTo(hdc, x, y))
48 return FALSE;
50 return dc && dc->funcs->pLineTo &&
51 dc->funcs->pLineTo(dc,x,y);
55 /***********************************************************************
56 * MoveTo (GDI.20)
58 DWORD WINAPI MoveTo( HDC16 hdc, INT16 x, INT16 y )
60 POINT16 pt;
62 if (!MoveToEx16(hdc,x,y,&pt))
63 return 0;
64 return MAKELONG(pt.x,pt.y);
68 /***********************************************************************
69 * MoveToEx16 (GDI.483)
71 BOOL16 WINAPI MoveToEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
73 POINT32 pt32;
75 if (!MoveToEx32( (HDC32)hdc, (INT32)x, (INT32)y, &pt32 )) return FALSE;
76 if (pt) CONV_POINT32TO16( &pt32, pt );
77 return TRUE;
82 /***********************************************************************
83 * MoveToEx32 (GDI32.254)
85 BOOL32 WINAPI MoveToEx32( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 pt )
87 DC * dc = DC_GetDCPtr( hdc );
89 if(dc && PATH_IsPathOpen(dc->w.path))
90 if(!PATH_MoveTo(hdc))
91 return FALSE;
93 return dc && dc->funcs->pMoveToEx &&
94 dc->funcs->pMoveToEx(dc,x,y,pt);
98 /***********************************************************************
99 * Arc16 (GDI.23)
101 BOOL16 WINAPI Arc16( HDC16 hdc, INT16 left, INT16 top, INT16 right,
102 INT16 bottom, INT16 xstart, INT16 ystart,
103 INT16 xend, INT16 yend )
105 return Arc32( (HDC32)hdc, (INT32)left, (INT32)top, (INT32)right,
106 (INT32)bottom, (INT32)xstart, (INT32)ystart, (INT32)xend,
107 (INT32)yend );
111 /***********************************************************************
112 * Arc32 (GDI32.7)
114 BOOL32 WINAPI Arc32( HDC32 hdc, INT32 left, INT32 top, INT32 right,
115 INT32 bottom, INT32 xstart, INT32 ystart,
116 INT32 xend, INT32 yend )
118 DC * dc = DC_GetDCPtr( hdc );
120 if(dc && PATH_IsPathOpen(dc->w.path))
121 if(!PATH_Arc(hdc, left, top, right, bottom, xstart, ystart, xend,
122 yend))
123 return FALSE;
125 return dc && dc->funcs->pArc &&
126 dc->funcs->pArc(dc,left,top,right,bottom,xstart,ystart,xend,yend);
129 /***********************************************************************
130 * ArcTo (GDI32.8)
132 BOOL32 WINAPI ArcTo( HDC32 hdc,
133 INT32 left, INT32 top,
134 INT32 right, INT32 bottom,
135 INT32 xstart, INT32 ystart,
136 INT32 xend, INT32 yend )
138 BOOL32 result;
141 * According to the documentation, a line is drawn from the current
142 * position to the starting point of the arc.
144 LineTo32(hdc, xstart, ystart);
147 * Then the arc is drawn.
149 result = Arc32(hdc,
150 left, top,
151 right, bottom,
152 xstart, ystart,
153 xend, yend);
156 * If no error occured, the current position is moved to the ending
157 * point of the arc.
159 if (result)
161 MoveToEx32(hdc, xend, yend, NULL);
164 return result;
167 /***********************************************************************
168 * Pie16 (GDI.26)
170 BOOL16 WINAPI Pie16( HDC16 hdc, INT16 left, INT16 top,
171 INT16 right, INT16 bottom, INT16 xstart, INT16 ystart,
172 INT16 xend, INT16 yend )
174 return Pie32( (HDC32)hdc, (INT32)left, (INT32)top, (INT32)right,
175 (INT32)bottom, (INT32)xstart, (INT32)ystart, (INT32)xend,
176 (INT32)yend );
180 /***********************************************************************
181 * Pie32 (GDI32.262)
183 BOOL32 WINAPI Pie32( HDC32 hdc, INT32 left, INT32 top,
184 INT32 right, INT32 bottom, INT32 xstart, INT32 ystart,
185 INT32 xend, INT32 yend )
187 DC * dc = DC_GetDCPtr( hdc );
189 return dc && dc->funcs->pPie &&
190 dc->funcs->pPie(dc,left,top,right,bottom,xstart,ystart,xend,yend);
194 /***********************************************************************
195 * Chord16 (GDI.348)
197 BOOL16 WINAPI Chord16( HDC16 hdc, INT16 left, INT16 top,
198 INT16 right, INT16 bottom, INT16 xstart, INT16 ystart,
199 INT16 xend, INT16 yend )
201 return Chord32( hdc, left, top, right, bottom, xstart, ystart, xend, yend );
205 /***********************************************************************
206 * Chord32 (GDI32.14)
208 BOOL32 WINAPI Chord32( HDC32 hdc, INT32 left, INT32 top,
209 INT32 right, INT32 bottom, INT32 xstart, INT32 ystart,
210 INT32 xend, INT32 yend )
212 DC * dc = DC_GetDCPtr( hdc );
214 return dc && dc->funcs->pChord &&
215 dc->funcs->pChord(dc,left,top,right,bottom,xstart,ystart,xend,yend);
219 /***********************************************************************
220 * Ellipse16 (GDI.24)
222 BOOL16 WINAPI Ellipse16( HDC16 hdc, INT16 left, INT16 top,
223 INT16 right, INT16 bottom )
225 return Ellipse32( hdc, left, top, right, bottom );
229 /***********************************************************************
230 * Ellipse32 (GDI32.75)
232 BOOL32 WINAPI Ellipse32( HDC32 hdc, INT32 left, INT32 top,
233 INT32 right, INT32 bottom )
235 DC * dc = DC_GetDCPtr( hdc );
237 return dc && dc->funcs->pEllipse &&
238 dc->funcs->pEllipse(dc,left,top,right,bottom);
242 /***********************************************************************
243 * Rectangle16 (GDI.27)
245 BOOL16 WINAPI Rectangle16( HDC16 hdc, INT16 left, INT16 top,
246 INT16 right, INT16 bottom )
248 return Rectangle32( hdc, left, top, right, bottom );
252 /***********************************************************************
253 * Rectangle32 (GDI32.283)
255 BOOL32 WINAPI Rectangle32( HDC32 hdc, INT32 left, INT32 top,
256 INT32 right, INT32 bottom )
258 DC * dc = DC_GetDCPtr( hdc );
260 if(dc && PATH_IsPathOpen(dc->w.path))
261 if(!PATH_Rectangle(hdc, left, top, right, bottom))
262 return FALSE;
264 return dc && dc->funcs->pRectangle &&
265 dc->funcs->pRectangle(dc,left,top,right,bottom);
269 /***********************************************************************
270 * RoundRect16 (GDI.28)
272 BOOL16 WINAPI RoundRect16( HDC16 hdc, INT16 left, INT16 top, INT16 right,
273 INT16 bottom, INT16 ell_width, INT16 ell_height )
275 return RoundRect32( hdc, left, top, right, bottom, ell_width, ell_height );
279 /***********************************************************************
280 * RoundRect32 (GDI32.291)
282 BOOL32 WINAPI RoundRect32( HDC32 hdc, INT32 left, INT32 top, INT32 right,
283 INT32 bottom, INT32 ell_width, INT32 ell_height )
286 if(ell_width == 0 || ell_height == 0) /* Just an optimization */
287 return Rectangle32(hdc, left, top, right, bottom);
289 else {
290 DC * dc = DC_GetDCPtr( hdc );
292 return dc && dc->funcs->pRoundRect &&
293 dc->funcs->pRoundRect(dc,left,top,right,bottom,ell_width,ell_height);
298 /***********************************************************************
299 * FillRect16 (USER.81)
301 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
303 HBRUSH16 prevBrush;
305 /* coordinates are logical so we cannot fast-check 'rect',
306 * it will be done later in the PatBlt().
309 if (!(prevBrush = SelectObject16( hdc, hbrush ))) return 0;
310 PatBlt32( hdc, rect->left, rect->top,
311 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
312 SelectObject16( hdc, prevBrush );
313 return 1;
317 /***********************************************************************
318 * FillRect32 (USER32.197)
320 INT32 WINAPI FillRect32( HDC32 hdc, const RECT32 *rect, HBRUSH32 hbrush )
322 HBRUSH32 prevBrush;
324 if (!(prevBrush = SelectObject32( hdc, hbrush ))) return 0;
325 PatBlt32( hdc, rect->left, rect->top,
326 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
327 SelectObject32( hdc, prevBrush );
328 return 1;
332 /***********************************************************************
333 * InvertRect16 (USER.82)
335 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
337 PatBlt32( hdc, rect->left, rect->top,
338 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
342 /***********************************************************************
343 * InvertRect32 (USER32.330)
345 void WINAPI InvertRect32( HDC32 hdc, const RECT32 *rect )
347 PatBlt32( hdc, rect->left, rect->top,
348 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
352 /***********************************************************************
353 * FrameRect16 (USER.83)
355 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
357 HBRUSH16 prevBrush;
358 int left, top, right, bottom;
360 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
361 if (!dc) return FALSE;
363 left = XLPTODP( dc, rect->left );
364 top = YLPTODP( dc, rect->top );
365 right = XLPTODP( dc, rect->right );
366 bottom = YLPTODP( dc, rect->bottom );
368 if ( (right <= left) || (bottom <= top) ) return 0;
369 if (!(prevBrush = SelectObject16( hdc, hbrush ))) return 0;
371 PatBlt32( hdc, rect->left, rect->top, 1,
372 rect->bottom - rect->top, PATCOPY );
373 PatBlt32( hdc, rect->right - 1, rect->top, 1,
374 rect->bottom - rect->top, PATCOPY );
375 PatBlt32( hdc, rect->left, rect->top,
376 rect->right - rect->left, 1, PATCOPY );
377 PatBlt32( hdc, rect->left, rect->bottom - 1,
378 rect->right - rect->left, 1, PATCOPY );
380 SelectObject16( hdc, prevBrush );
381 return 1;
385 /***********************************************************************
386 * FrameRect32 (USER32.203)
388 INT32 WINAPI FrameRect32( HDC32 hdc, const RECT32 *rect, HBRUSH32 hbrush )
390 RECT16 rect16;
391 CONV_RECT32TO16( rect, &rect16 );
392 return FrameRect16( (HDC16)hdc, &rect16, (HBRUSH16)hbrush );
396 /***********************************************************************
397 * SetPixel16 (GDI.31)
399 COLORREF WINAPI SetPixel16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
401 return SetPixel32( hdc, x, y, color );
405 /***********************************************************************
406 * SetPixel32 (GDI32.327)
408 COLORREF WINAPI SetPixel32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
410 DC * dc = DC_GetDCPtr( hdc );
412 if (!dc || !dc->funcs->pSetPixel) return 0;
413 return dc->funcs->pSetPixel(dc,x,y,color);
416 /***********************************************************************
417 * SetPixelV32 (GDI32.329)
419 BOOL32 WINAPI SetPixelV32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
421 DC * dc = DC_GetDCPtr( hdc );
423 if (!dc || !dc->funcs->pSetPixel) return FALSE;
424 dc->funcs->pSetPixel(dc,x,y,color);
425 return TRUE;
428 /***********************************************************************
429 * GetPixel16 (GDI.83)
431 COLORREF WINAPI GetPixel16( HDC16 hdc, INT16 x, INT16 y )
433 return GetPixel32( hdc, x, y );
437 /***********************************************************************
438 * GetPixel32 (GDI32.211)
440 COLORREF WINAPI GetPixel32( HDC32 hdc, INT32 x, INT32 y )
442 DC * dc = DC_GetDCPtr( hdc );
444 if (!dc) return 0;
445 #ifdef SOLITAIRE_SPEED_HACK
446 return 0;
447 #endif
449 /* FIXME: should this be in the graphics driver? */
450 if (!PtVisible32( hdc, x, y )) return 0;
451 if (!dc || !dc->funcs->pGetPixel) return 0;
452 return dc->funcs->pGetPixel(dc,x,y);
456 /******************************************************************************
457 * ChoosePixelFormat [GDI32.13]
458 * Matches a pixel format to given format
460 * PARAMS
461 * hdc [I] Device context to search for best pixel match
462 * ppfd [I] Pixel format for which a match is sought
464 * RETURNS
465 * Success: Pixel format index closest to given format
466 * Failure: 0
468 INT32 WINAPI ChoosePixelFormat( HDC32 hdc, const PIXELFORMATDESCRIPTOR* ppfd )
470 FIXME(gdi, "(%d,%p): stub\n",hdc,ppfd);
471 return 1;
475 /******************************************************************************
476 * SetPixelFormat [GDI32.328]
477 * Sets pixel format of device context
479 * PARAMS
480 * hdc [I] Device context to search for best pixel match
481 * iPixelFormat [I] Pixel format index
482 * ppfd [I] Pixel format for which a match is sought
484 * RETURNS STD
486 BOOL32 WINAPI SetPixelFormat( HDC32 hdc, int iPixelFormat,
487 const PIXELFORMATDESCRIPTOR* ppfd)
489 FIXME(gdi, "(%d,%d,%p): stub\n",hdc,iPixelFormat,ppfd);
490 return TRUE;
494 /******************************************************************************
495 * GetPixelFormat [GDI32.212]
496 * Gets index of pixel format of DC
498 * PARAMETERS
499 * hdc [I] Device context whose pixel format index is sought
501 * RETURNS
502 * Success: Currently selected pixel format
503 * Failure: 0
505 int WINAPI GetPixelFormat( HDC32 hdc )
507 FIXME(gdi, "(%d): stub\n",hdc);
508 return 1;
512 /******************************************************************************
513 * DescribePixelFormat [GDI32.71]
514 * Gets info about pixel format from DC
516 * PARAMS
517 * hdc [I] Device context
518 * iPixelFormat [I] Pixel format selector
519 * nBytes [I] Size of buffer
520 * ppfd [O] Pointer to structure to receive pixel format data
522 * RETURNS
523 * Success: Maximum pixel format index of the device context
524 * Failure: 0
526 int WINAPI DescribePixelFormat( HDC32 hdc, int iPixelFormat, UINT32 nBytes,
527 LPPIXELFORMATDESCRIPTOR ppfd )
529 FIXME(gdi, "(%d,%d,%d,%p): stub\n",hdc,iPixelFormat,nBytes,ppfd);
530 ppfd->nSize = nBytes;
531 ppfd->nVersion = 1;
532 return 3;
536 /******************************************************************************
537 * SwapBuffers [GDI32.354]
538 * Exchanges front and back buffers of window
540 * PARAMS
541 * hdc [I] Device context whose buffers get swapped
543 * RETURNS STD
545 BOOL32 WINAPI SwapBuffers( HDC32 hdc )
547 FIXME(gdi, "(%d): stub\n",hdc);
548 return TRUE;
552 /***********************************************************************
553 * PaintRgn16 (GDI.43)
555 BOOL16 WINAPI PaintRgn16( HDC16 hdc, HRGN16 hrgn )
557 return PaintRgn32( hdc, hrgn );
561 /***********************************************************************
562 * PaintRgn32 (GDI32.259)
564 BOOL32 WINAPI PaintRgn32( HDC32 hdc, HRGN32 hrgn )
566 DC * dc = DC_GetDCPtr( hdc );
568 return dc && dc->funcs->pPaintRgn &&
569 dc->funcs->pPaintRgn(dc,hrgn);
573 /***********************************************************************
574 * FillRgn16 (GDI.40)
576 BOOL16 WINAPI FillRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush )
578 return FillRgn32( hdc, hrgn, hbrush );
582 /***********************************************************************
583 * FillRgn32 (GDI32.101)
585 BOOL32 WINAPI FillRgn32( HDC32 hdc, HRGN32 hrgn, HBRUSH32 hbrush )
587 BOOL32 retval;
588 HBRUSH32 prevBrush = SelectObject32( hdc, hbrush );
589 if (!prevBrush) return FALSE;
590 retval = PaintRgn32( hdc, hrgn );
591 SelectObject32( hdc, prevBrush );
592 return retval;
596 /***********************************************************************
597 * FrameRgn16 (GDI.41)
599 BOOL16 WINAPI FrameRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush,
600 INT16 nWidth, INT16 nHeight )
602 return FrameRgn32( hdc, hrgn, hbrush, nWidth, nHeight );
606 /***********************************************************************
607 * FrameRgn32 (GDI32.105)
609 BOOL32 WINAPI FrameRgn32( HDC32 hdc, HRGN32 hrgn, HBRUSH32 hbrush,
610 INT32 nWidth, INT32 nHeight )
612 HRGN32 tmp = CreateRectRgn32( 0, 0, 0, 0 );
613 if(!REGION_FrameRgn( tmp, hrgn, nWidth, nHeight )) return FALSE;
614 FillRgn32( hdc, tmp, hbrush );
615 DeleteObject32( tmp );
616 return TRUE;
620 /***********************************************************************
621 * InvertRgn16 (GDI.42)
623 BOOL16 WINAPI InvertRgn16( HDC16 hdc, HRGN16 hrgn )
625 return InvertRgn32( hdc, hrgn );
629 /***********************************************************************
630 * InvertRgn32 (GDI32.246)
632 BOOL32 WINAPI InvertRgn32( HDC32 hdc, HRGN32 hrgn )
634 HBRUSH32 prevBrush = SelectObject32( hdc, GetStockObject32(BLACK_BRUSH) );
635 INT32 prevROP = SetROP232( hdc, R2_NOT );
636 BOOL32 retval = PaintRgn32( hdc, hrgn );
637 SelectObject32( hdc, prevBrush );
638 SetROP232( hdc, prevROP );
639 return retval;
643 /***********************************************************************
644 * DrawFocusRect16 (USER.466)
646 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
648 RECT32 rect32;
649 CONV_RECT16TO32( rc, &rect32 );
650 DrawFocusRect32( hdc, &rect32 );
654 /***********************************************************************
655 * DrawFocusRect32 (USER32.156)
657 * FIXME: PatBlt(PATINVERT) with background brush.
659 void WINAPI DrawFocusRect32( HDC32 hdc, const RECT32* rc )
661 HPEN32 hOldPen, hnewPen;
662 INT32 oldDrawMode, oldBkMode;
663 INT32 left, top, right, bottom;
664 X11DRV_PDEVICE *physDev;
666 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
667 if (!dc) return;
668 physDev = (X11DRV_PDEVICE *)dc->physDev;
670 left = XLPTODP( dc, rc->left );
671 top = YLPTODP( dc, rc->top );
672 right = XLPTODP( dc, rc->right );
673 bottom = YLPTODP( dc, rc->bottom );
675 if(left == right || top == bottom)
676 return;
678 hnewPen = CreatePen32(PS_DOT, 1, GetSysColor32(COLOR_WINDOWTEXT) );
679 hOldPen = SelectObject32( hdc, hnewPen );
680 oldDrawMode = SetROP232(hdc, R2_XORPEN);
681 oldBkMode = SetBkMode32(hdc, TRANSPARENT);
683 /* Hack: make sure the XORPEN operation has an effect */
684 physDev->pen.pixel = (1 << screenDepth) - 1;
686 if (X11DRV_SetupGCForPen( dc ))
687 TSXDrawRectangle( display, physDev->drawable, physDev->gc,
688 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
689 right-left-1, bottom-top-1 );
691 SetBkMode32(hdc, oldBkMode);
692 SetROP232(hdc, oldDrawMode);
693 SelectObject32(hdc, hOldPen);
694 DeleteObject32(hnewPen);
698 /**********************************************************************
699 * Polyline16 (GDI.37)
701 BOOL16 WINAPI Polyline16( HDC16 hdc, const POINT16* pt, INT16 count )
703 register int i;
704 BOOL16 ret;
705 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
706 count*sizeof(POINT32) );
708 if (!pt32) return FALSE;
709 for (i=count;i--;) CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
710 ret = Polyline32(hdc,pt32,count);
711 HeapFree( GetProcessHeap(), 0, pt32 );
712 return ret;
716 /**********************************************************************
717 * Polyline32 (GDI32.276)
719 BOOL32 WINAPI Polyline32( HDC32 hdc, const POINT32* pt, INT32 count )
721 DC * dc = DC_GetDCPtr( hdc );
723 return dc && dc->funcs->pPolyline &&
724 dc->funcs->pPolyline(dc,pt,count);
727 /**********************************************************************
728 * PolylineTo32 (GDI32.277)
730 BOOL32 WINAPI PolylineTo32( HDC32 hdc, const POINT32* pt, DWORD cCount )
732 POINT32 *pts = HeapAlloc( GetProcessHeap(), 0,
733 sizeof(POINT32) * (cCount + 1) );
734 if(!pts) return FALSE;
736 /* Get the current point */
737 MoveToEx32( hdc, 0, 0, pts);
739 /* Add in the other points */
740 memcpy( pts + 1, pt, sizeof(POINT32) * cCount );
742 /* Draw the lines */
743 Polyline32( hdc, pts, cCount + 1 );
745 /* Move to last point */
746 MoveToEx32( hdc, (pts + cCount)->x, (pts + cCount)->y, NULL );
748 HeapFree( GetProcessHeap(), 0, pts );
749 return TRUE;
752 /**********************************************************************
753 * Polygon16 (GDI.36)
755 BOOL16 WINAPI Polygon16( HDC16 hdc, const POINT16* pt, INT16 count )
757 register int i;
758 BOOL32 ret;
759 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
760 count*sizeof(POINT32) );
762 if (!pt32) return FALSE;
763 for (i=count;i--;) CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
764 ret = Polygon32(hdc,pt32,count);
765 HeapFree( GetProcessHeap(), 0, pt32 );
766 return ret;
770 /**********************************************************************
771 * Polygon32 (GDI32.275)
773 BOOL32 WINAPI Polygon32( HDC32 hdc, const POINT32* pt, INT32 count )
775 DC * dc = DC_GetDCPtr( hdc );
777 return dc && dc->funcs->pPolygon &&
778 dc->funcs->pPolygon(dc,pt,count);
782 /**********************************************************************
783 * PolyPolygon16 (GDI.450)
785 BOOL16 WINAPI PolyPolygon16( HDC16 hdc, const POINT16* pt, const INT16* counts,
786 UINT16 polygons )
788 int i,nrpts;
789 LPPOINT32 pt32;
790 LPINT32 counts32;
791 BOOL16 ret;
793 nrpts=0;
794 for (i=polygons;i--;)
795 nrpts+=counts[i];
796 pt32 = (LPPOINT32)HEAP_xalloc( GetProcessHeap(), 0, sizeof(POINT32)*nrpts);
797 for (i=nrpts;i--;)
798 CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
799 counts32 = (LPINT32)HEAP_xalloc( GetProcessHeap(), 0,
800 polygons*sizeof(INT32) );
801 for (i=polygons;i--;) counts32[i]=counts[i];
803 ret = PolyPolygon32(hdc,pt32,counts32,polygons);
804 HeapFree( GetProcessHeap(), 0, counts32 );
805 HeapFree( GetProcessHeap(), 0, pt32 );
806 return ret;
809 /**********************************************************************
810 * PolyPolygon32 (GDI.450)
812 BOOL32 WINAPI PolyPolygon32( HDC32 hdc, const POINT32* pt, const INT32* counts,
813 UINT32 polygons )
815 DC * dc = DC_GetDCPtr( hdc );
817 return dc && dc->funcs->pPolyPolygon &&
818 dc->funcs->pPolyPolygon(dc,pt,counts,polygons);
821 /**********************************************************************
822 * PolyPolyline (GDI32.272)
824 BOOL32 WINAPI PolyPolyline( HDC32 hdc, const POINT32* pt, const DWORD* counts,
825 DWORD polylines )
827 DC * dc = DC_GetDCPtr( hdc );
829 return dc && dc->funcs->pPolyPolyline &&
830 dc->funcs->pPolyPolyline(dc,pt,counts,polylines);
833 /**********************************************************************
834 * ExtFloodFill16 (GDI.372)
836 BOOL16 WINAPI ExtFloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color,
837 UINT16 fillType )
839 return ExtFloodFill32( hdc, x, y, color, fillType );
843 /**********************************************************************
844 * ExtFloodFill32 (GDI32.96)
846 BOOL32 WINAPI ExtFloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color,
847 UINT32 fillType )
849 DC *dc = DC_GetDCPtr( hdc );
851 return dc && dc->funcs->pExtFloodFill &&
852 dc->funcs->pExtFloodFill(dc,x,y,color,fillType);
856 /**********************************************************************
857 * FloodFill16 (GDI.25)
859 BOOL16 WINAPI FloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
861 return ExtFloodFill32( hdc, x, y, color, FLOODFILLBORDER );
865 /**********************************************************************
866 * FloodFill32 (GDI32.104)
868 BOOL32 WINAPI FloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
870 return ExtFloodFill32( hdc, x, y, color, FLOODFILLBORDER );
874 /**********************************************************************
875 * DrawAnimatedRects16 (USER.448)
877 BOOL16 WINAPI DrawAnimatedRects16( HWND16 hwnd, INT16 idAni,
878 const RECT16* lprcFrom,
879 const RECT16* lprcTo )
881 RECT32 rcFrom32, rcTo32;
883 rcFrom32.left = (INT32)lprcFrom->left;
884 rcFrom32.top = (INT32)lprcFrom->top;
885 rcFrom32.right = (INT32)lprcFrom->right;
886 rcFrom32.bottom = (INT32)lprcFrom->bottom;
888 rcTo32.left = (INT32)lprcTo->left;
889 rcTo32.top = (INT32)lprcTo->top;
890 rcTo32.right = (INT32)lprcTo->right;
891 rcTo32.bottom = (INT32)lprcTo->bottom;
893 return DrawAnimatedRects32((HWND32)hwnd, (INT32)idAni, &rcFrom32, &rcTo32);
897 /**********************************************************************
898 * DrawAnimatedRects32 (USER32.153)
900 BOOL32 WINAPI DrawAnimatedRects32( HWND32 hwnd, int idAni,
901 const RECT32* lprcFrom,
902 const RECT32* lprcTo )
904 FIXME(gdi,"(0x%x,%d,%p,%p): stub\n",hwnd,idAni,lprcFrom,lprcTo);
905 return TRUE;
909 /**********************************************************************
910 * PAINTING_DrawStateJam
912 * Jams in the requested type in the dc
914 static BOOL32 PAINTING_DrawStateJam(HDC32 hdc, UINT32 opcode,
915 DRAWSTATEPROC32 func, LPARAM lp, WPARAM32 wp,
916 LPRECT32 rc, UINT32 dtflags,
917 BOOL32 unicode, BOOL32 _32bit)
919 HDC32 memdc;
920 HBITMAP32 hbmsave;
921 BOOL32 retval;
922 INT32 cx = rc->right - rc->left;
923 INT32 cy = rc->bottom - rc->top;
925 switch(opcode)
927 case DST_TEXT:
928 case DST_PREFIXTEXT:
929 if(unicode)
930 return DrawText32W(hdc, (LPWSTR)lp, (INT32)wp, rc, dtflags);
931 else if(_32bit)
932 return DrawText32A(hdc, (LPSTR)lp, (INT32)wp, rc, dtflags);
933 else
934 return DrawText32A(hdc, (LPSTR)PTR_SEG_TO_LIN(lp), (INT32)wp, rc, dtflags);
936 case DST_ICON:
937 return DrawIcon32(hdc, rc->left, rc->top, (HICON32)lp);
939 case DST_BITMAP:
940 memdc = CreateCompatibleDC32(hdc);
941 if(!memdc) return FALSE;
942 hbmsave = (HBITMAP32)SelectObject32(memdc, (HBITMAP32)lp);
943 if(!hbmsave)
945 DeleteDC32(memdc);
946 return FALSE;
948 retval = BitBlt32(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
949 SelectObject32(memdc, hbmsave);
950 DeleteDC32(memdc);
951 return retval;
953 case DST_COMPLEX:
954 if(func)
955 if(_32bit)
956 return func(hdc, lp, wp, cx, cy);
957 else
958 return (BOOL32)((DRAWSTATEPROC16)func)((HDC16)hdc, (LPARAM)lp, (WPARAM16)wp, (INT16)cx, (INT16)cy);
959 else
960 return FALSE;
962 return FALSE;
965 /**********************************************************************
966 * PAINTING_DrawState32()
968 static BOOL32 PAINTING_DrawState32(HDC32 hdc, HBRUSH32 hbr,
969 DRAWSTATEPROC32 func, LPARAM lp, WPARAM32 wp,
970 INT32 x, INT32 y, INT32 cx, INT32 cy,
971 UINT32 flags, BOOL32 unicode, BOOL32 _32bit)
973 HBITMAP32 hbm, hbmsave;
974 HFONT32 hfsave;
975 HBRUSH32 hbsave;
976 HDC32 memdc;
977 RECT32 rc;
978 UINT32 dtflags = DT_NOCLIP;
979 COLORREF fg, bg;
980 UINT32 opcode = flags & 0xf;
981 INT32 len = wp;
982 BOOL32 retval, tmp;
984 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
986 if(unicode)
987 len = lstrlen32W((LPWSTR)lp);
988 else if(_32bit)
989 len = lstrlen32A((LPSTR)lp);
990 else
991 len = lstrlen32A((LPSTR)PTR_SEG_TO_LIN(lp));
994 /* Find out what size the image has if not given by caller */
995 if(!cx || !cy)
997 SIZE32 s;
998 CURSORICONINFO *ici;
999 BITMAPOBJ *bmp;
1001 switch(opcode)
1003 case DST_TEXT:
1004 case DST_PREFIXTEXT:
1005 if(unicode)
1006 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
1007 else if(_32bit)
1008 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
1009 else
1010 retval = GetTextExtentPoint32A(hdc, PTR_SEG_TO_LIN(lp), len, &s);
1011 if(!retval) return FALSE;
1012 break;
1014 case DST_ICON:
1015 ici = (CURSORICONINFO *)GlobalLock16((HGLOBAL16)lp);
1016 if(!ici) return FALSE;
1017 s.cx = ici->nWidth;
1018 s.cy = ici->nHeight;
1019 GlobalUnlock16((HGLOBAL16)lp);
1020 break;
1022 case DST_BITMAP:
1023 bmp = (BITMAPOBJ *)GDI_GetObjPtr((HBITMAP16)lp, BITMAP_MAGIC);
1024 if(!bmp) return FALSE;
1025 s.cx = bmp->bitmap.bmWidth;
1026 s.cy = bmp->bitmap.bmHeight;
1027 break;
1029 case DST_COMPLEX: /* cx and cy must be set in this mode */
1030 return FALSE;
1033 if(!cx) cx = s.cx;
1034 if(!cy) cy = s.cy;
1037 rc.left = x;
1038 rc.top = y;
1039 rc.right = x + cx;
1040 rc.bottom = y + cy;
1042 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
1043 dtflags |= DT_RIGHT;
1044 if(opcode == DST_TEXT)
1045 dtflags |= DT_NOPREFIX;
1047 /* For DSS_NORMAL we just jam in the image and return */
1048 if((flags & 0x7ff0) == DSS_NORMAL)
1050 return PAINTING_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
1053 /* For all other states we need to convert the image to B/W in a local bitmap */
1054 /* before it is displayed */
1055 fg = SetTextColor32(hdc, RGB(0, 0, 0));
1056 bg = SetBkColor32(hdc, RGB(255, 255, 255));
1057 hbm = (HBITMAP32)NULL; hbmsave = (HBITMAP32)NULL;
1058 memdc = (HDC32)NULL; hbsave = (HBRUSH32)NULL;
1059 retval = FALSE; /* assume failure */
1061 /* From here on we must use "goto cleanup" when something goes wrong */
1062 hbm = CreateBitmap32(cx, cy, 1, 1, NULL);
1063 if(!hbm) goto cleanup;
1064 memdc = CreateCompatibleDC32(hdc);
1065 if(!memdc) goto cleanup;
1066 hbmsave = (HBITMAP32)SelectObject32(memdc, hbm);
1067 if(!hbmsave) goto cleanup;
1068 rc.left = rc.top = 0;
1069 rc.right = cx;
1070 rc.bottom = cy;
1071 if(!FillRect32(memdc, &rc, (HBRUSH32)GetStockObject32(WHITE_BRUSH))) goto cleanup;
1072 SetBkColor32(memdc, RGB(255, 255, 255));
1073 SetTextColor32(memdc, RGB(0, 0, 0));
1074 hfsave = (HFONT32)SelectObject32(memdc, GetCurrentObject(hdc, OBJ_FONT));
1075 if(!hfsave && (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)) goto cleanup;
1076 tmp = PAINTING_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
1077 if(hfsave) SelectObject32(memdc, hfsave);
1078 if(!tmp) goto cleanup;
1080 /* These states cause the image to be dithered */
1081 if(flags & (DSS_UNION|DSS_DISABLED))
1083 hbsave = (HBRUSH32)SelectObject32(memdc, CACHE_GetPattern55AABrush());
1084 if(!hbsave) goto cleanup;
1085 tmp = PatBlt32(memdc, 0, 0, cx, cy, 0x00FA0089);
1086 if(hbsave) SelectObject32(memdc, hbsave);
1087 if(!tmp) goto cleanup;
1090 hbsave = (HBRUSH32)SelectObject32(hdc, hbr ? hbr : GetStockObject32(WHITE_BRUSH));
1091 if(!hbsave) goto cleanup;
1093 if(!BitBlt32(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1095 /* DSS_DEFAULT makes the image boldface */
1096 if(flags & DSS_DEFAULT)
1098 if(!BitBlt32(hdc, x+1, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1101 retval = TRUE; /* We succeeded */
1103 cleanup:
1104 SetTextColor32(hdc, fg);
1105 SetBkColor32(hdc, bg);
1107 if(hbsave) SelectObject32(hdc, hbsave);
1108 if(hbmsave) SelectObject32(memdc, hbmsave);
1109 if(hbm) DeleteObject32(hbm);
1110 if(memdc) DeleteDC32(memdc);
1112 return retval;
1115 /**********************************************************************
1116 * DrawState32A() (USER32.162)
1118 BOOL32 WINAPI DrawState32A(HDC32 hdc, HBRUSH32 hbr,
1119 DRAWSTATEPROC32 func, LPARAM ldata, WPARAM32 wdata,
1120 INT32 x, INT32 y, INT32 cx, INT32 cy, UINT32 flags)
1122 return PAINTING_DrawState32(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE, TRUE);
1125 /**********************************************************************
1126 * DrawState32W() (USER32.163)
1128 BOOL32 WINAPI DrawState32W(HDC32 hdc, HBRUSH32 hbr,
1129 DRAWSTATEPROC32 func, LPARAM ldata, WPARAM32 wdata,
1130 INT32 x, INT32 y, INT32 cx, INT32 cy, UINT32 flags)
1132 return PAINTING_DrawState32(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE, TRUE);
1135 /**********************************************************************
1136 * DrawState16() (USER.449)
1138 BOOL16 WINAPI DrawState16(HDC16 hdc, HBRUSH16 hbr,
1139 DRAWSTATEPROC16 func, LPARAM ldata, WPARAM16 wdata,
1140 INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags)
1142 return PAINTING_DrawState32(hdc, hbr, (DRAWSTATEPROC32)func, ldata, wdata, x, y, cx, cy, flags, FALSE, FALSE);
1146 /******************************************************************************
1147 * PolyBezier16 [GDI.502]
1149 BOOL16 WINAPI PolyBezier16( HDC16 hDc, const POINT16* lppt, INT16 cPoints )
1151 int i;
1152 BOOL16 ret;
1153 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
1154 cPoints*sizeof(POINT32) );
1155 if(!pt32) return FALSE;
1156 for (i=cPoints;i--;) CONV_POINT16TO32(&(lppt[i]),&(pt32[i]));
1157 ret= PolyBezier32(hDc, pt32, cPoints);
1158 HeapFree( GetProcessHeap(), 0, pt32 );
1159 return ret;
1162 /******************************************************************************
1163 * PolyBezierTo16 [GDI.503]
1165 BOOL16 WINAPI PolyBezierTo16( HDC16 hDc, const POINT16* lppt, INT16 cPoints )
1167 int i;
1168 BOOL16 ret;
1169 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
1170 cPoints*sizeof(POINT32) );
1171 if(!pt32) return FALSE;
1172 for (i=cPoints;i--;) CONV_POINT16TO32(&(lppt[i]),&(pt32[i]));
1173 ret= PolyBezierTo32(hDc, pt32, cPoints);
1174 HeapFree( GetProcessHeap(), 0, pt32 );
1175 return ret;
1178 /******************************************************************************
1179 * PolyBezier32 [GDI32.268]
1180 * Draws one or more Bezier curves
1182 * PARAMS
1183 * hDc [I] Handle to device context
1184 * lppt [I] Pointer to endpoints and control points
1185 * cPoints [I] Count of endpoints and control points
1187 * RETURNS STD
1189 BOOL32 WINAPI PolyBezier32( HDC32 hdc, const POINT32* lppt, DWORD cPoints )
1191 DC * dc = DC_GetDCPtr( hdc );
1192 if(!dc) return FALSE;
1193 if(dc && PATH_IsPathOpen(dc->w.path))
1194 FIXME(gdi, "PATH_PolyBezier is not implemented!\n");
1195 /* if(!PATH_PolyBezier(hdc, x, y))
1196 return FALSE; */
1197 return dc->funcs->pPolyBezier&&
1198 dc->funcs->pPolyBezier(dc, lppt[0], lppt+1, cPoints-1);
1201 /******************************************************************************
1202 * PolyBezierTo32 [GDI32.269]
1203 * Draws one or more Bezier curves
1205 * PARAMS
1206 * hDc [I] Handle to device context
1207 * lppt [I] Pointer to endpoints and control points
1208 * cPoints [I] Count of endpoints and control points
1210 * RETURNS STD
1212 BOOL32 WINAPI PolyBezierTo32( HDC32 hdc, const POINT32* lppt, DWORD cPoints )
1214 DC * dc = DC_GetDCPtr( hdc );
1215 POINT32 pt;
1216 BOOL32 ret;
1217 if(!dc) return FALSE;
1218 pt.x=dc->w.CursPosX;
1219 pt.y=dc->w.CursPosY;
1220 if(dc && PATH_IsPathOpen(dc->w.path))
1221 FIXME(gdi, "PATH_PolyBezierTo is not implemented!\n");
1222 /* if(!PATH_PolyBezier(hdc, x, y))
1223 return FALSE; */
1224 ret= dc->funcs->pPolyBezier &&
1225 dc->funcs->pPolyBezier(dc, pt, lppt, cPoints);
1226 if( dc->funcs->pMoveToEx)
1227 dc->funcs->pMoveToEx(dc,lppt[cPoints].x,lppt[cPoints].y,&pt);
1228 return ret;
1231 /***************************************************************
1232 * AngleArc (GDI32.5)
1235 BOOL32 WINAPI AngleArc(HDC32 hdc, INT32 x, INT32 y, DWORD dwRadius,
1236 FLOAT eStartAngle, FLOAT eSweepAngle)
1238 FIXME(gdi,"AngleArc, stub\n");
1239 return 0;
1242 /***************************************************************
1243 * PolyDraw (GDI32.270)
1246 BOOL32 WINAPI PolyDraw(HDC32 hdc, const POINT32 *lppt, const BYTE *lpbTypes,
1247 DWORD cCount)
1249 FIXME(gdi,"PolyDraw, stub\n");
1250 return 0;