Small fixes.
[wine/multimedia.git] / graphics / painting.c
blob03c529c8bbee65347e83aeb787c1c0df5addf312
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 "color.h"
25 #include "region.h"
26 #include "path.h"
27 #include "debug.h"
28 #include "winerror.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);
130 /***********************************************************************
131 * Pie16 (GDI.26)
133 BOOL16 WINAPI Pie16( HDC16 hdc, INT16 left, INT16 top,
134 INT16 right, INT16 bottom, INT16 xstart, INT16 ystart,
135 INT16 xend, INT16 yend )
137 return Pie32( (HDC32)hdc, (INT32)left, (INT32)top, (INT32)right,
138 (INT32)bottom, (INT32)xstart, (INT32)ystart, (INT32)xend,
139 (INT32)yend );
143 /***********************************************************************
144 * Pie32 (GDI32.262)
146 BOOL32 WINAPI Pie32( HDC32 hdc, INT32 left, INT32 top,
147 INT32 right, INT32 bottom, INT32 xstart, INT32 ystart,
148 INT32 xend, INT32 yend )
150 DC * dc = DC_GetDCPtr( hdc );
152 return dc && dc->funcs->pPie &&
153 dc->funcs->pPie(dc,left,top,right,bottom,xstart,ystart,xend,yend);
157 /***********************************************************************
158 * Chord16 (GDI.348)
160 BOOL16 WINAPI Chord16( HDC16 hdc, INT16 left, INT16 top,
161 INT16 right, INT16 bottom, INT16 xstart, INT16 ystart,
162 INT16 xend, INT16 yend )
164 return Chord32( hdc, left, top, right, bottom, xstart, ystart, xend, yend );
168 /***********************************************************************
169 * Chord32 (GDI32.14)
171 BOOL32 WINAPI Chord32( HDC32 hdc, INT32 left, INT32 top,
172 INT32 right, INT32 bottom, INT32 xstart, INT32 ystart,
173 INT32 xend, INT32 yend )
175 DC * dc = DC_GetDCPtr( hdc );
177 return dc && dc->funcs->pChord &&
178 dc->funcs->pChord(dc,left,top,right,bottom,xstart,ystart,xend,yend);
182 /***********************************************************************
183 * Ellipse16 (GDI.24)
185 BOOL16 WINAPI Ellipse16( HDC16 hdc, INT16 left, INT16 top,
186 INT16 right, INT16 bottom )
188 return Ellipse32( hdc, left, top, right, bottom );
192 /***********************************************************************
193 * Ellipse32 (GDI32.75)
195 BOOL32 WINAPI Ellipse32( HDC32 hdc, INT32 left, INT32 top,
196 INT32 right, INT32 bottom )
198 DC * dc = DC_GetDCPtr( hdc );
200 return dc && dc->funcs->pEllipse &&
201 dc->funcs->pEllipse(dc,left,top,right,bottom);
205 /***********************************************************************
206 * Rectangle16 (GDI.27)
208 BOOL16 WINAPI Rectangle16( HDC16 hdc, INT16 left, INT16 top,
209 INT16 right, INT16 bottom )
211 return Rectangle32( hdc, left, top, right, bottom );
215 /***********************************************************************
216 * Rectangle32 (GDI32.283)
218 BOOL32 WINAPI Rectangle32( HDC32 hdc, INT32 left, INT32 top,
219 INT32 right, INT32 bottom )
221 DC * dc = DC_GetDCPtr( hdc );
223 if(dc && PATH_IsPathOpen(dc->w.path))
224 if(!PATH_Rectangle(hdc, left, top, right, bottom))
225 return FALSE;
227 return dc && dc->funcs->pRectangle &&
228 dc->funcs->pRectangle(dc,left,top,right,bottom);
232 /***********************************************************************
233 * RoundRect16 (GDI.28)
235 BOOL16 WINAPI RoundRect16( HDC16 hdc, INT16 left, INT16 top, INT16 right,
236 INT16 bottom, INT16 ell_width, INT16 ell_height )
238 return RoundRect32( hdc, left, top, right, bottom, ell_width, ell_height );
242 /***********************************************************************
243 * RoundRect32 (GDI32.291)
245 BOOL32 WINAPI RoundRect32( HDC32 hdc, INT32 left, INT32 top, INT32 right,
246 INT32 bottom, INT32 ell_width, INT32 ell_height )
249 if(ell_width == 0 || ell_height == 0) /* Just an optimization */
250 return Rectangle32(hdc, left, top, right, bottom);
252 else {
253 DC * dc = DC_GetDCPtr( hdc );
255 return dc && dc->funcs->pRoundRect &&
256 dc->funcs->pRoundRect(dc,left,top,right,bottom,ell_width,ell_height);
261 /***********************************************************************
262 * FillRect16 (USER.81)
264 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
266 HBRUSH16 prevBrush;
268 /* coordinates are logical so we cannot fast-check 'rect',
269 * it will be done later in the PatBlt().
272 if (!(prevBrush = SelectObject16( hdc, hbrush ))) return 0;
273 PatBlt32( hdc, rect->left, rect->top,
274 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
275 SelectObject16( hdc, prevBrush );
276 return 1;
280 /***********************************************************************
281 * FillRect32 (USER32.197)
283 INT32 WINAPI FillRect32( HDC32 hdc, const RECT32 *rect, HBRUSH32 hbrush )
285 HBRUSH32 prevBrush;
287 if (!(prevBrush = SelectObject32( hdc, hbrush ))) return 0;
288 PatBlt32( hdc, rect->left, rect->top,
289 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
290 SelectObject32( hdc, prevBrush );
291 return 1;
295 /***********************************************************************
296 * InvertRect16 (USER.82)
298 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
300 PatBlt32( hdc, rect->left, rect->top,
301 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
305 /***********************************************************************
306 * InvertRect32 (USER32.330)
308 void WINAPI InvertRect32( HDC32 hdc, const RECT32 *rect )
310 PatBlt32( hdc, rect->left, rect->top,
311 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
315 /***********************************************************************
316 * FrameRect16 (USER.83)
318 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
320 HBRUSH16 prevBrush;
321 int left, top, right, bottom;
323 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
324 if (!dc) return FALSE;
326 left = XLPTODP( dc, rect->left );
327 top = YLPTODP( dc, rect->top );
328 right = XLPTODP( dc, rect->right );
329 bottom = YLPTODP( dc, rect->bottom );
331 if ( (right <= left) || (bottom <= top) ) return 0;
332 if (!(prevBrush = SelectObject16( hdc, hbrush ))) return 0;
334 if (DC_SetupGCForBrush( dc ))
336 PatBlt32( hdc, rect->left, rect->top, 1,
337 rect->bottom - rect->top, PATCOPY );
338 PatBlt32( hdc, rect->right - 1, rect->top, 1,
339 rect->bottom - rect->top, PATCOPY );
340 PatBlt32( hdc, rect->left, rect->top,
341 rect->right - rect->left, 1, PATCOPY );
342 PatBlt32( hdc, rect->left, rect->bottom - 1,
343 rect->right - rect->left, 1, PATCOPY );
345 SelectObject16( hdc, prevBrush );
346 return 1;
350 /***********************************************************************
351 * FrameRect32 (USER32.203)
353 INT32 WINAPI FrameRect32( HDC32 hdc, const RECT32 *rect, HBRUSH32 hbrush )
355 RECT16 rect16;
356 CONV_RECT32TO16( rect, &rect16 );
357 return FrameRect16( (HDC16)hdc, &rect16, (HBRUSH16)hbrush );
361 /***********************************************************************
362 * SetPixel16 (GDI.31)
364 COLORREF WINAPI SetPixel16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
366 return SetPixel32( hdc, x, y, color );
370 /***********************************************************************
371 * SetPixel32 (GDI32.327)
373 COLORREF WINAPI SetPixel32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
375 DC * dc = DC_GetDCPtr( hdc );
377 if (!dc || !dc->funcs->pSetPixel) return 0;
378 return dc->funcs->pSetPixel(dc,x,y,color);
381 /***********************************************************************
382 * SetPixelV32 (GDI32.329)
384 BOOL32 WINAPI SetPixelV32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
386 DC * dc = DC_GetDCPtr( hdc );
388 if (!dc || !dc->funcs->pSetPixel) return FALSE;
389 dc->funcs->pSetPixel(dc,x,y,color);
390 return TRUE;
393 /***********************************************************************
394 * GetPixel16 (GDI.83)
396 COLORREF WINAPI GetPixel16( HDC16 hdc, INT16 x, INT16 y )
398 return GetPixel32( hdc, x, y );
402 /***********************************************************************
403 * GetPixel32 (GDI32.211)
405 COLORREF WINAPI GetPixel32( HDC32 hdc, INT32 x, INT32 y )
407 DC * dc = DC_GetDCPtr( hdc );
409 if (!dc) return 0;
410 #ifdef SOLITAIRE_SPEED_HACK
411 return 0;
412 #endif
414 /* FIXME: should this be in the graphics driver? */
415 if (!PtVisible32( hdc, x, y )) return 0;
416 if (!dc || !dc->funcs->pGetPixel) return 0;
417 return dc->funcs->pGetPixel(dc,x,y);
421 /******************************************************************************
422 * ChoosePixelFormat [GDI32.13]
423 * Matches a pixel format to given format
425 * PARAMS
426 * hdc [I] Device context to search for best pixel match
427 * ppfd [I] Pixel format for which a match is sought
429 * RETURNS
430 * Success: Pixel format index closest to given format
431 * Failure: 0
433 INT32 WINAPI ChoosePixelFormat( HDC32 hdc, const PIXELFORMATDESCRIPTOR* ppfd )
435 FIXME(gdi, "(%d,%p): stub\n",hdc,ppfd);
436 return 1;
440 /******************************************************************************
441 * SetPixelFormat [GDI32.328]
442 * Sets pixel format of device context
444 * PARAMS
445 * hdc [I] Device context to search for best pixel match
446 * iPixelFormat [I] Pixel format index
447 * ppfd [I] Pixel format for which a match is sought
449 * RETURNS STD
451 BOOL32 WINAPI SetPixelFormat( HDC32 hdc, int iPixelFormat,
452 const PIXELFORMATDESCRIPTOR* ppfd)
454 FIXME(gdi, "(%d,%d,%p): stub\n",hdc,iPixelFormat,ppfd);
455 return TRUE;
459 /******************************************************************************
460 * GetPixelFormat [GDI32.212]
461 * Gets index of pixel format of DC
463 * PARAMETERS
464 * hdc [I] Device context whose pixel format index is sought
466 * RETURNS
467 * Success: Currently selected pixel format
468 * Failure: 0
470 int WINAPI GetPixelFormat( HDC32 hdc )
472 FIXME(gdi, "(%d): stub\n",hdc);
473 return 1;
477 /******************************************************************************
478 * DescribePixelFormat [GDI32.71]
479 * Gets info about pixel format from DC
481 * PARAMS
482 * hdc [I] Device context
483 * iPixelFormat [I] Pixel format selector
484 * nBytes [I] Size of buffer
485 * ppfd [O] Pointer to structure to receive pixel format data
487 * RETURNS
488 * Success: Maximum pixel format index of the device context
489 * Failure: 0
491 int WINAPI DescribePixelFormat( HDC32 hdc, int iPixelFormat, UINT32 nBytes,
492 LPPIXELFORMATDESCRIPTOR ppfd )
494 FIXME(gdi, "(%d,%d,%d,%p): stub\n",hdc,iPixelFormat,nBytes,ppfd);
495 ppfd->nSize = nBytes;
496 ppfd->nVersion = 1;
497 return 3;
501 /******************************************************************************
502 * SwapBuffers [GDI32.354]
503 * Exchanges front and back buffers of window
505 * PARAMS
506 * hdc [I] Device context whose buffers get swapped
508 * RETURNS STD
510 BOOL32 WINAPI SwapBuffers( HDC32 hdc )
512 FIXME(gdi, "(%d): stub\n",hdc);
513 return TRUE;
517 /***********************************************************************
518 * PaintRgn16 (GDI.43)
520 BOOL16 WINAPI PaintRgn16( HDC16 hdc, HRGN16 hrgn )
522 return PaintRgn32( hdc, hrgn );
526 /***********************************************************************
527 * PaintRgn32 (GDI32.259)
529 BOOL32 WINAPI PaintRgn32( HDC32 hdc, HRGN32 hrgn )
531 DC * dc = DC_GetDCPtr( hdc );
533 return dc && dc->funcs->pPaintRgn &&
534 dc->funcs->pPaintRgn(dc,hrgn);
538 /***********************************************************************
539 * FillRgn16 (GDI.40)
541 BOOL16 WINAPI FillRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush )
543 return FillRgn32( hdc, hrgn, hbrush );
547 /***********************************************************************
548 * FillRgn32 (GDI32.101)
550 BOOL32 WINAPI FillRgn32( HDC32 hdc, HRGN32 hrgn, HBRUSH32 hbrush )
552 BOOL32 retval;
553 HBRUSH32 prevBrush = SelectObject32( hdc, hbrush );
554 if (!prevBrush) return FALSE;
555 retval = PaintRgn32( hdc, hrgn );
556 SelectObject32( hdc, prevBrush );
557 return retval;
561 /***********************************************************************
562 * FrameRgn16 (GDI.41)
564 BOOL16 WINAPI FrameRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush,
565 INT16 nWidth, INT16 nHeight )
567 return FrameRgn32( hdc, hrgn, hbrush, nWidth, nHeight );
571 /***********************************************************************
572 * FrameRgn32 (GDI32.105)
574 BOOL32 WINAPI FrameRgn32( HDC32 hdc, HRGN32 hrgn, HBRUSH32 hbrush,
575 INT32 nWidth, INT32 nHeight )
577 HRGN32 tmp = CreateRectRgn32( 0, 0, 0, 0 );
578 if(!REGION_FrameRgn( tmp, hrgn, nWidth, nHeight )) return FALSE;
579 FillRgn32( hdc, tmp, hbrush );
580 DeleteObject32( tmp );
581 return TRUE;
585 /***********************************************************************
586 * InvertRgn16 (GDI.42)
588 BOOL16 WINAPI InvertRgn16( HDC16 hdc, HRGN16 hrgn )
590 return InvertRgn32( hdc, hrgn );
594 /***********************************************************************
595 * InvertRgn32 (GDI32.246)
597 BOOL32 WINAPI InvertRgn32( HDC32 hdc, HRGN32 hrgn )
599 HBRUSH32 prevBrush = SelectObject32( hdc, GetStockObject32(BLACK_BRUSH) );
600 INT32 prevROP = SetROP232( hdc, R2_NOT );
601 BOOL32 retval = PaintRgn32( hdc, hrgn );
602 SelectObject32( hdc, prevBrush );
603 SetROP232( hdc, prevROP );
604 return retval;
608 /***********************************************************************
609 * DrawFocusRect16 (USER.466)
611 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
613 RECT32 rect32;
614 CONV_RECT16TO32( rc, &rect32 );
615 DrawFocusRect32( hdc, &rect32 );
619 /***********************************************************************
620 * DrawFocusRect32 (USER32.156)
622 * FIXME: PatBlt(PATINVERT) with background brush.
624 void WINAPI DrawFocusRect32( HDC32 hdc, const RECT32* rc )
626 HPEN32 hOldPen, hnewPen;
627 INT32 oldDrawMode, oldBkMode;
628 INT32 left, top, right, bottom;
630 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
631 if (!dc) return;
633 left = XLPTODP( dc, rc->left );
634 top = YLPTODP( dc, rc->top );
635 right = XLPTODP( dc, rc->right );
636 bottom = YLPTODP( dc, rc->bottom );
638 if(left == right || top == bottom)
639 return;
641 hnewPen = CreatePen32(PS_DOT, 1, GetSysColor32(COLOR_WINDOWTEXT) );
642 hOldPen = SelectObject32( hdc, hnewPen );
643 oldDrawMode = SetROP232(hdc, R2_XORPEN);
644 oldBkMode = SetBkMode32(hdc, TRANSPARENT);
646 /* Hack: make sure the XORPEN operation has an effect */
647 dc->u.x.pen.pixel = (1 << screenDepth) - 1;
649 if (DC_SetupGCForPen( dc ))
650 TSXDrawRectangle( display, dc->u.x.drawable, dc->u.x.gc,
651 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
652 right-left-1, bottom-top-1 );
654 SetBkMode32(hdc, oldBkMode);
655 SetROP232(hdc, oldDrawMode);
656 SelectObject32(hdc, hOldPen);
657 DeleteObject32(hnewPen);
661 /**********************************************************************
662 * Polyline16 (GDI.37)
664 BOOL16 WINAPI Polyline16( HDC16 hdc, const POINT16* pt, INT16 count )
666 register int i;
667 BOOL16 ret;
668 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
669 count*sizeof(POINT32) );
671 if (!pt32) return FALSE;
672 for (i=count;i--;) CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
673 ret = Polyline32(hdc,pt32,count);
674 HeapFree( GetProcessHeap(), 0, pt32 );
675 return ret;
679 /**********************************************************************
680 * Polyline32 (GDI32.276)
682 BOOL32 WINAPI Polyline32( HDC32 hdc, const POINT32* pt, INT32 count )
684 DC * dc = DC_GetDCPtr( hdc );
686 return dc && dc->funcs->pPolyline &&
687 dc->funcs->pPolyline(dc,pt,count);
691 /**********************************************************************
692 * Polygon16 (GDI.36)
694 BOOL16 WINAPI Polygon16( HDC16 hdc, const POINT16* pt, INT16 count )
696 register int i;
697 BOOL32 ret;
698 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
699 count*sizeof(POINT32) );
701 if (!pt32) return FALSE;
702 for (i=count;i--;) CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
703 ret = Polygon32(hdc,pt32,count);
704 HeapFree( GetProcessHeap(), 0, pt32 );
705 return ret;
709 /**********************************************************************
710 * Polygon32 (GDI32.275)
712 BOOL32 WINAPI Polygon32( HDC32 hdc, const POINT32* pt, INT32 count )
714 DC * dc = DC_GetDCPtr( hdc );
716 return dc && dc->funcs->pPolygon &&
717 dc->funcs->pPolygon(dc,pt,count);
721 /**********************************************************************
722 * PolyPolygon16 (GDI.450)
724 BOOL16 WINAPI PolyPolygon16( HDC16 hdc, const POINT16* pt, const INT16* counts,
725 UINT16 polygons )
727 int i,nrpts;
728 LPPOINT32 pt32;
729 LPINT32 counts32;
730 BOOL16 ret;
732 nrpts=0;
733 for (i=polygons;i--;)
734 nrpts+=counts[i];
735 pt32 = (LPPOINT32)HEAP_xalloc( GetProcessHeap(), 0, sizeof(POINT32)*nrpts);
736 for (i=nrpts;i--;)
737 CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
738 counts32 = (LPINT32)HEAP_xalloc( GetProcessHeap(), 0,
739 polygons*sizeof(INT32) );
740 for (i=polygons;i--;) counts32[i]=counts[i];
742 ret = PolyPolygon32(hdc,pt32,counts32,polygons);
743 HeapFree( GetProcessHeap(), 0, counts32 );
744 HeapFree( GetProcessHeap(), 0, pt32 );
745 return ret;
748 /**********************************************************************
749 * PolyPolygon32 (GDI.450)
751 BOOL32 WINAPI PolyPolygon32( HDC32 hdc, const POINT32* pt, const INT32* counts,
752 UINT32 polygons )
754 DC * dc = DC_GetDCPtr( hdc );
756 return dc && dc->funcs->pPolyPolygon &&
757 dc->funcs->pPolyPolygon(dc,pt,counts,polygons);
760 /**********************************************************************
761 * PolyPolyline32 (GDI32.272)
763 BOOL32 WINAPI PolyPolyline32( HDC32 hdc, const POINT32* pt, const DWORD* counts,
764 DWORD polylines )
766 DC * dc = DC_GetDCPtr( hdc );
768 return dc && dc->funcs->pPolyPolyline &&
769 dc->funcs->pPolyPolyline(dc,pt,counts,polylines);
772 /**********************************************************************
773 * ExtFloodFill16 (GDI.372)
775 BOOL16 WINAPI ExtFloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color,
776 UINT16 fillType )
778 return ExtFloodFill32( hdc, x, y, color, fillType );
782 /**********************************************************************
783 * ExtFloodFill32 (GDI32.96)
785 BOOL32 WINAPI ExtFloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color,
786 UINT32 fillType )
788 DC *dc = DC_GetDCPtr( hdc );
790 return dc && dc->funcs->pExtFloodFill &&
791 dc->funcs->pExtFloodFill(dc,x,y,color,fillType);
795 /**********************************************************************
796 * FloodFill16 (GDI.25)
798 BOOL16 WINAPI FloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
800 return ExtFloodFill32( hdc, x, y, color, FLOODFILLBORDER );
804 /**********************************************************************
805 * FloodFill32 (GDI32.104)
807 BOOL32 WINAPI FloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
809 return ExtFloodFill32( hdc, x, y, color, FLOODFILLBORDER );
813 /**********************************************************************
814 * DrawAnimatedRects32 (USER32.153)
816 BOOL32 WINAPI DrawAnimatedRects32( HWND32 hwnd, int idAni,
817 const RECT32* lprcFrom,
818 const RECT32* lprcTo )
820 FIXME(gdi,"(0x%x,%d,%p,%p): stub\n",hwnd,idAni,lprcFrom,lprcTo);
821 return TRUE;
825 /**********************************************************************
826 * PAINTING_DrawStateJam
828 * Jams in the requested type in the dc
830 static BOOL32 PAINTING_DrawStateJam(HDC32 hdc, UINT32 opcode,
831 DRAWSTATEPROC32 func, LPARAM lp, WPARAM32 wp,
832 LPRECT32 rc, UINT32 dtflags,
833 BOOL32 unicode, BOOL32 _32bit)
835 HDC32 memdc;
836 HBITMAP32 hbmsave;
837 BOOL32 retval;
838 INT32 cx = rc->right - rc->left;
839 INT32 cy = rc->bottom - rc->top;
841 switch(opcode)
843 case DST_TEXT:
844 case DST_PREFIXTEXT:
845 if(unicode)
846 return DrawText32W(hdc, (LPWSTR)lp, (INT32)wp, rc, dtflags);
847 else if(_32bit)
848 return DrawText32A(hdc, (LPSTR)lp, (INT32)wp, rc, dtflags);
849 else
850 return DrawText32A(hdc, (LPSTR)PTR_SEG_TO_LIN(lp), (INT32)wp, rc, dtflags);
852 case DST_ICON:
853 return DrawIcon32(hdc, rc->left, rc->top, (HICON32)lp);
855 case DST_BITMAP:
856 memdc = CreateCompatibleDC32(hdc);
857 if(!memdc) return FALSE;
858 hbmsave = (HBITMAP32)SelectObject32(memdc, (HBITMAP32)lp);
859 if(!hbmsave)
861 DeleteDC32(memdc);
862 return FALSE;
864 retval = BitBlt32(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
865 SelectObject32(memdc, hbmsave);
866 DeleteDC32(memdc);
867 return retval;
869 case DST_COMPLEX:
870 if(func)
871 if(_32bit)
872 return func(hdc, lp, wp, cx, cy);
873 else
874 return (BOOL32)((DRAWSTATEPROC16)func)((HDC16)hdc, (LPARAM)lp, (WPARAM16)wp, (INT16)cx, (INT16)cy);
875 else
876 return FALSE;
878 return FALSE;
881 /**********************************************************************
882 * PAINTING_DrawState32()
884 static BOOL32 PAINTING_DrawState32(HDC32 hdc, HBRUSH32 hbr,
885 DRAWSTATEPROC32 func, LPARAM lp, WPARAM32 wp,
886 INT32 x, INT32 y, INT32 cx, INT32 cy,
887 UINT32 flags, BOOL32 unicode, BOOL32 _32bit)
889 HBITMAP32 hbm, hbmsave;
890 HFONT32 hfsave;
891 HBRUSH32 hbsave;
892 HDC32 memdc;
893 RECT32 rc;
894 UINT32 dtflags = DT_NOCLIP;
895 COLORREF fg, bg;
896 UINT32 opcode = flags & 0xf;
897 INT32 len = wp;
898 BOOL32 retval, tmp;
900 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
902 if(unicode)
903 len = lstrlen32W((LPWSTR)lp);
904 else if(_32bit)
905 len = lstrlen32A((LPSTR)lp);
906 else
907 len = lstrlen32A((LPSTR)PTR_SEG_TO_LIN(lp));
910 /* Find out what size the image has if not given by caller */
911 if(!cx || !cy)
913 SIZE32 s;
914 CURSORICONINFO *ici;
915 BITMAPOBJ *bmp;
917 switch(opcode)
919 case DST_TEXT:
920 case DST_PREFIXTEXT:
921 if(unicode)
922 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
923 else if(_32bit)
924 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
925 else
926 retval = GetTextExtentPoint32A(hdc, PTR_SEG_TO_LIN(lp), len, &s);
927 if(!retval) return FALSE;
928 break;
930 case DST_ICON:
931 ici = (CURSORICONINFO *)GlobalLock16((HGLOBAL16)lp);
932 if(!ici) return FALSE;
933 s.cx = ici->nWidth;
934 s.cy = ici->nHeight;
935 GlobalUnlock16((HGLOBAL16)lp);
936 break;
938 case DST_BITMAP:
939 bmp = (BITMAPOBJ *)GDI_GetObjPtr((HBITMAP16)lp, BITMAP_MAGIC);
940 if(!bmp) return FALSE;
941 s.cx = bmp->bitmap.bmWidth;
942 s.cy = bmp->bitmap.bmHeight;
943 break;
945 case DST_COMPLEX: /* cx and cy must be set in this mode */
946 return FALSE;
949 if(!cx) cx = s.cx;
950 if(!cy) cy = s.cy;
953 rc.left = x;
954 rc.top = y;
955 rc.right = x + cx;
956 rc.bottom = y + cy;
958 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
959 dtflags |= DT_RIGHT;
960 if(opcode == DST_TEXT)
961 dtflags |= DT_NOPREFIX;
963 /* For DSS_NORMAL we just jam in the image and return */
964 if((flags & 0x7ff0) == DSS_NORMAL)
966 return PAINTING_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
969 /* For all other states we need to convert the image to B/W in a local bitmap */
970 /* before it is displayed */
971 fg = SetTextColor32(hdc, RGB(0, 0, 0));
972 bg = SetBkColor32(hdc, RGB(255, 255, 255));
973 hbm = (HBITMAP32)NULL; hbmsave = (HBITMAP32)NULL;
974 memdc = (HDC32)NULL; hbsave = (HBRUSH32)NULL;
975 retval = FALSE; /* assume failure */
977 /* From here on we must use "goto cleanup" when something goes wrong */
978 hbm = CreateBitmap32(cx, cy, 1, 1, NULL);
979 if(!hbm) goto cleanup;
980 memdc = CreateCompatibleDC32(hdc);
981 if(!memdc) goto cleanup;
982 hbmsave = (HBITMAP32)SelectObject32(memdc, hbm);
983 if(!hbmsave) goto cleanup;
984 rc.left = rc.top = 0;
985 rc.right = cx;
986 rc.bottom = cy;
987 if(!FillRect32(memdc, &rc, (HBRUSH32)GetStockObject32(WHITE_BRUSH))) goto cleanup;
988 SetBkColor32(memdc, RGB(255, 255, 255));
989 SetTextColor32(memdc, RGB(0, 0, 0));
990 hfsave = (HFONT32)SelectObject32(memdc, GetCurrentObject(hdc, OBJ_FONT));
991 if(!hfsave && (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)) goto cleanup;
992 tmp = PAINTING_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
993 if(hfsave) SelectObject32(memdc, hfsave);
994 if(!tmp) goto cleanup;
996 /* These states cause the image to be dithered */
997 if(flags & (DSS_UNION|DSS_DISABLED))
999 hbsave = (HBRUSH32)SelectObject32(memdc, CACHE_GetPattern55AABrush());
1000 if(!hbsave) goto cleanup;
1001 tmp = PatBlt32(memdc, 0, 0, cx, cy, 0x00FA0089);
1002 if(hbsave) SelectObject32(memdc, hbsave);
1003 if(!tmp) goto cleanup;
1006 hbsave = (HBRUSH32)SelectObject32(hdc, hbr ? hbr : GetStockObject32(WHITE_BRUSH));
1007 if(!hbsave) goto cleanup;
1009 if(!BitBlt32(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1011 /* DSS_DEFAULT makes the image boldface */
1012 if(flags & DSS_DEFAULT)
1014 if(!BitBlt32(hdc, x+1, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1017 retval = TRUE; /* We succeeded */
1019 cleanup:
1020 SetTextColor32(hdc, fg);
1021 SetBkColor32(hdc, bg);
1023 if(hbsave) SelectObject32(hdc, hbsave);
1024 if(hbmsave) SelectObject32(memdc, hbmsave);
1025 if(hbm) DeleteObject32(hbm);
1026 if(memdc) DeleteDC32(memdc);
1028 return retval;
1031 /**********************************************************************
1032 * DrawState32A() (USER32.162)
1034 BOOL32 WINAPI DrawState32A(HDC32 hdc, HBRUSH32 hbr,
1035 DRAWSTATEPROC32 func, LPARAM ldata, WPARAM32 wdata,
1036 INT32 x, INT32 y, INT32 cx, INT32 cy, UINT32 flags)
1038 return PAINTING_DrawState32(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE, TRUE);
1041 /**********************************************************************
1042 * DrawState32W() (USER32.163)
1044 BOOL32 WINAPI DrawState32W(HDC32 hdc, HBRUSH32 hbr,
1045 DRAWSTATEPROC32 func, LPARAM ldata, WPARAM32 wdata,
1046 INT32 x, INT32 y, INT32 cx, INT32 cy, UINT32 flags)
1048 return PAINTING_DrawState32(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE, TRUE);
1051 /**********************************************************************
1052 * DrawState16() (USER.449)
1054 BOOL16 WINAPI DrawState16(HDC16 hdc, HBRUSH16 hbr,
1055 DRAWSTATEPROC16 func, LPARAM ldata, WPARAM16 wdata,
1056 INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags)
1058 return PAINTING_DrawState32(hdc, hbr, (DRAWSTATEPROC32)func, ldata, wdata, x, y, cx, cy, flags, FALSE, FALSE);
1062 /******************************************************************************
1063 * PolyBezier16 [GDI.502]
1065 BOOL16 WINAPI PolyBezier16( HDC16 hDc, const POINT16* lppt, INT16 cPoints )
1067 int i;
1068 BOOL16 ret;
1069 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
1070 cPoints*sizeof(POINT32) );
1071 if(!pt32) return FALSE;
1072 for (i=cPoints;i--;) CONV_POINT16TO32(&(lppt[i]),&(pt32[i]));
1073 ret= PolyBezier32(hDc, pt32, cPoints);
1074 HeapFree( GetProcessHeap(), 0, pt32 );
1075 return ret;
1078 /******************************************************************************
1079 * PolyBezierTo16 [GDI.503]
1081 BOOL16 WINAPI PolyBezierTo16( HDC16 hDc, const POINT16* lppt, INT16 cPoints )
1083 int i;
1084 BOOL16 ret;
1085 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
1086 cPoints*sizeof(POINT32) );
1087 if(!pt32) return FALSE;
1088 for (i=cPoints;i--;) CONV_POINT16TO32(&(lppt[i]),&(pt32[i]));
1089 ret= PolyBezierTo32(hDc, pt32, cPoints);
1090 HeapFree( GetProcessHeap(), 0, pt32 );
1091 return ret;
1094 /******************************************************************************
1095 * PolyBezier32 [GDI32.268]
1096 * Draws one or more Bezier curves
1098 * PARAMS
1099 * hDc [I] Handle to device context
1100 * lppt [I] Pointer to endpoints and control points
1101 * cPoints [I] Count of endpoints and control points
1103 * RETURNS STD
1105 BOOL32 WINAPI PolyBezier32( HDC32 hdc, const POINT32* lppt, DWORD cPoints )
1107 DC * dc = DC_GetDCPtr( hdc );
1108 if(!dc) return FALSE;
1109 if(dc && PATH_IsPathOpen(dc->w.path))
1110 FIXME(gdi, "PATH_PolyBezier is not implemented!\n");
1111 /* if(!PATH_PolyBezier(hdc, x, y))
1112 return FALSE; */
1113 return dc->funcs->pPolyBezier&&
1114 dc->funcs->pPolyBezier(dc, lppt[0], lppt+1, cPoints-1);
1117 /******************************************************************************
1118 * PolyBezierTo32 [GDI32.269]
1119 * Draws one or more Bezier curves
1121 * PARAMS
1122 * hDc [I] Handle to device context
1123 * lppt [I] Pointer to endpoints and control points
1124 * cPoints [I] Count of endpoints and control points
1126 * RETURNS STD
1128 BOOL32 WINAPI PolyBezierTo32( HDC32 hdc, const POINT32* lppt, DWORD cPoints )
1130 DC * dc = DC_GetDCPtr( hdc );
1131 POINT32 pt;
1132 BOOL32 ret;
1133 if(!dc) return FALSE;
1134 pt.x=dc->w.CursPosX;
1135 pt.y=dc->w.CursPosY;
1136 if(dc && PATH_IsPathOpen(dc->w.path))
1137 FIXME(gdi, "PATH_PolyBezierTo is not implemented!\n");
1138 /* if(!PATH_PolyBezier(hdc, x, y))
1139 return FALSE; */
1140 ret= dc->funcs->pPolyBezier &&
1141 dc->funcs->pPolyBezier(dc, pt, lppt, cPoints);
1142 if( dc->funcs->pMoveToEx)
1143 dc->funcs->pMoveToEx(dc,lppt[cPoints].x,lppt[cPoints].y,&pt);
1144 return ret;
1147 INT32 WINAPI EndDoc32(HDC32 a)
1149 FIXME(gdi,"stub\n");
1150 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1151 return 0; /* failure*/
1154 INT32 WINAPI StartDoc32A(HDC32 hdc ,const DOCINFO32A* doc)
1156 FIXME(gdi,"stub\n");
1157 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1158 return 0; /* failure*/