Improved display and layout code.
[wine.git] / graphics / painting.c
blobc6df9a3c66fd1bc96e3759f6df0398830cbcdcad
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"
29 /***********************************************************************
30 * LineTo16 (GDI.19)
32 BOOL16 WINAPI LineTo16( HDC16 hdc, INT16 x, INT16 y )
34 return LineTo32( hdc, x, y );
38 /***********************************************************************
39 * LineTo32 (GDI32.249)
41 BOOL32 WINAPI LineTo32( HDC32 hdc, INT32 x, INT32 y )
43 DC * dc = DC_GetDCPtr( hdc );
45 if(dc && PATH_IsPathOpen(dc->w.path))
46 if(!PATH_LineTo(hdc, x, y))
47 return FALSE;
49 return dc && dc->funcs->pLineTo &&
50 dc->funcs->pLineTo(dc,x,y);
54 /***********************************************************************
55 * MoveTo (GDI.20)
57 DWORD WINAPI MoveTo( HDC16 hdc, INT16 x, INT16 y )
59 POINT16 pt;
61 if (!MoveToEx16(hdc,x,y,&pt))
62 return 0;
63 return MAKELONG(pt.x,pt.y);
67 /***********************************************************************
68 * MoveToEx16 (GDI.483)
70 BOOL16 WINAPI MoveToEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
72 POINT32 pt32;
74 if (!MoveToEx32( (HDC32)hdc, (INT32)x, (INT32)y, &pt32 )) return FALSE;
75 if (pt) CONV_POINT32TO16( &pt32, pt );
76 return TRUE;
81 /***********************************************************************
82 * MoveToEx32 (GDI32.254)
84 BOOL32 WINAPI MoveToEx32( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 pt )
86 DC * dc = DC_GetDCPtr( hdc );
88 if(dc && PATH_IsPathOpen(dc->w.path))
89 if(!PATH_MoveTo(hdc))
90 return FALSE;
92 return dc && dc->funcs->pMoveToEx &&
93 dc->funcs->pMoveToEx(dc,x,y,pt);
97 /***********************************************************************
98 * Arc16 (GDI.23)
100 BOOL16 WINAPI Arc16( HDC16 hdc, INT16 left, INT16 top, INT16 right,
101 INT16 bottom, INT16 xstart, INT16 ystart,
102 INT16 xend, INT16 yend )
104 return Arc32( (HDC32)hdc, (INT32)left, (INT32)top, (INT32)right,
105 (INT32)bottom, (INT32)xstart, (INT32)ystart, (INT32)xend,
106 (INT32)yend );
110 /***********************************************************************
111 * Arc32 (GDI32.7)
113 BOOL32 WINAPI Arc32( HDC32 hdc, INT32 left, INT32 top, INT32 right,
114 INT32 bottom, INT32 xstart, INT32 ystart,
115 INT32 xend, INT32 yend )
117 DC * dc = DC_GetDCPtr( hdc );
119 if(dc && PATH_IsPathOpen(dc->w.path))
120 if(!PATH_Arc(hdc, left, top, right, bottom, xstart, ystart, xend,
121 yend))
122 return FALSE;
124 return dc && dc->funcs->pArc &&
125 dc->funcs->pArc(dc,left,top,right,bottom,xstart,ystart,xend,yend);
129 /***********************************************************************
130 * Pie16 (GDI.26)
132 BOOL16 WINAPI Pie16( HDC16 hdc, INT16 left, INT16 top,
133 INT16 right, INT16 bottom, INT16 xstart, INT16 ystart,
134 INT16 xend, INT16 yend )
136 return Pie32( (HDC32)hdc, (INT32)left, (INT32)top, (INT32)right,
137 (INT32)bottom, (INT32)xstart, (INT32)ystart, (INT32)xend,
138 (INT32)yend );
142 /***********************************************************************
143 * Pie32 (GDI32.262)
145 BOOL32 WINAPI Pie32( HDC32 hdc, INT32 left, INT32 top,
146 INT32 right, INT32 bottom, INT32 xstart, INT32 ystart,
147 INT32 xend, INT32 yend )
149 DC * dc = DC_GetDCPtr( hdc );
151 return dc && dc->funcs->pPie &&
152 dc->funcs->pPie(dc,left,top,right,bottom,xstart,ystart,xend,yend);
156 /***********************************************************************
157 * Chord16 (GDI.348)
159 BOOL16 WINAPI Chord16( HDC16 hdc, INT16 left, INT16 top,
160 INT16 right, INT16 bottom, INT16 xstart, INT16 ystart,
161 INT16 xend, INT16 yend )
163 return Chord32( hdc, left, top, right, bottom, xstart, ystart, xend, yend );
167 /***********************************************************************
168 * Chord32 (GDI32.14)
170 BOOL32 WINAPI Chord32( HDC32 hdc, INT32 left, INT32 top,
171 INT32 right, INT32 bottom, INT32 xstart, INT32 ystart,
172 INT32 xend, INT32 yend )
174 DC * dc = DC_GetDCPtr( hdc );
176 return dc && dc->funcs->pChord &&
177 dc->funcs->pChord(dc,left,top,right,bottom,xstart,ystart,xend,yend);
181 /***********************************************************************
182 * Ellipse16 (GDI.24)
184 BOOL16 WINAPI Ellipse16( HDC16 hdc, INT16 left, INT16 top,
185 INT16 right, INT16 bottom )
187 return Ellipse32( hdc, left, top, right, bottom );
191 /***********************************************************************
192 * Ellipse32 (GDI32.75)
194 BOOL32 WINAPI Ellipse32( HDC32 hdc, INT32 left, INT32 top,
195 INT32 right, INT32 bottom )
197 DC * dc = DC_GetDCPtr( hdc );
199 return dc && dc->funcs->pEllipse &&
200 dc->funcs->pEllipse(dc,left,top,right,bottom);
204 /***********************************************************************
205 * Rectangle16 (GDI.27)
207 BOOL16 WINAPI Rectangle16( HDC16 hdc, INT16 left, INT16 top,
208 INT16 right, INT16 bottom )
210 return Rectangle32( hdc, left, top, right, bottom );
214 /***********************************************************************
215 * Rectangle32 (GDI32.283)
217 BOOL32 WINAPI Rectangle32( HDC32 hdc, INT32 left, INT32 top,
218 INT32 right, INT32 bottom )
220 DC * dc = DC_GetDCPtr( hdc );
222 if(dc && PATH_IsPathOpen(dc->w.path))
223 if(!PATH_Rectangle(hdc, left, top, right, bottom))
224 return FALSE;
226 return dc && dc->funcs->pRectangle &&
227 dc->funcs->pRectangle(dc,left,top,right,bottom);
231 /***********************************************************************
232 * RoundRect16 (GDI.28)
234 BOOL16 WINAPI RoundRect16( HDC16 hdc, INT16 left, INT16 top, INT16 right,
235 INT16 bottom, INT16 ell_width, INT16 ell_height )
237 return RoundRect32( hdc, left, top, right, bottom, ell_width, ell_height );
241 /***********************************************************************
242 * RoundRect32 (GDI32.291)
244 BOOL32 WINAPI RoundRect32( HDC32 hdc, INT32 left, INT32 top, INT32 right,
245 INT32 bottom, INT32 ell_width, INT32 ell_height )
248 if(ell_width == 0 || ell_height == 0) /* Just an optimization */
249 return Rectangle32(hdc, left, top, right, bottom);
251 else {
252 DC * dc = DC_GetDCPtr( hdc );
254 return dc && dc->funcs->pRoundRect &&
255 dc->funcs->pRoundRect(dc,left,top,right,bottom,ell_width,ell_height);
260 /***********************************************************************
261 * FillRect16 (USER.81)
263 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
265 HBRUSH16 prevBrush;
267 /* coordinates are logical so we cannot fast-check 'rect',
268 * it will be done later in the PatBlt().
271 if (!(prevBrush = SelectObject16( hdc, hbrush ))) return 0;
272 PatBlt32( hdc, rect->left, rect->top,
273 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
274 SelectObject16( hdc, prevBrush );
275 return 1;
279 /***********************************************************************
280 * FillRect32 (USER32.197)
282 INT32 WINAPI FillRect32( HDC32 hdc, const RECT32 *rect, HBRUSH32 hbrush )
284 HBRUSH32 prevBrush;
286 if (!(prevBrush = SelectObject32( hdc, hbrush ))) return 0;
287 PatBlt32( hdc, rect->left, rect->top,
288 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
289 SelectObject32( hdc, prevBrush );
290 return 1;
294 /***********************************************************************
295 * InvertRect16 (USER.82)
297 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
299 PatBlt32( hdc, rect->left, rect->top,
300 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
304 /***********************************************************************
305 * InvertRect32 (USER32.330)
307 void WINAPI InvertRect32( HDC32 hdc, const RECT32 *rect )
309 PatBlt32( hdc, rect->left, rect->top,
310 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
314 /***********************************************************************
315 * FrameRect16 (USER.83)
317 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
319 HBRUSH16 prevBrush;
320 int left, top, right, bottom;
322 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
323 if (!dc) return FALSE;
325 left = XLPTODP( dc, rect->left );
326 top = YLPTODP( dc, rect->top );
327 right = XLPTODP( dc, rect->right );
328 bottom = YLPTODP( dc, rect->bottom );
330 if ( (right <= left) || (bottom <= top) ) return 0;
331 if (!(prevBrush = SelectObject16( hdc, hbrush ))) return 0;
333 if (DC_SetupGCForBrush( dc ))
335 PatBlt32( hdc, rect->left, rect->top, 1,
336 rect->bottom - rect->top, PATCOPY );
337 PatBlt32( hdc, rect->right - 1, rect->top, 1,
338 rect->bottom - rect->top, PATCOPY );
339 PatBlt32( hdc, rect->left, rect->top,
340 rect->right - rect->left, 1, PATCOPY );
341 PatBlt32( hdc, rect->left, rect->bottom - 1,
342 rect->right - rect->left, 1, PATCOPY );
344 SelectObject16( hdc, prevBrush );
345 return 1;
349 /***********************************************************************
350 * FrameRect32 (USER32.203)
352 INT32 WINAPI FrameRect32( HDC32 hdc, const RECT32 *rect, HBRUSH32 hbrush )
354 RECT16 rect16;
355 CONV_RECT32TO16( rect, &rect16 );
356 return FrameRect16( (HDC16)hdc, &rect16, (HBRUSH16)hbrush );
360 /***********************************************************************
361 * SetPixel16 (GDI.31)
363 COLORREF WINAPI SetPixel16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
365 return SetPixel32( hdc, x, y, color );
369 /***********************************************************************
370 * SetPixel32 (GDI32.327)
372 COLORREF WINAPI SetPixel32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
374 DC * dc = DC_GetDCPtr( hdc );
376 if (!dc || !dc->funcs->pSetPixel) return 0;
377 return dc->funcs->pSetPixel(dc,x,y,color);
380 /***********************************************************************
381 * SetPixelV32 (GDI32.329)
383 BOOL32 WINAPI SetPixelV32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
385 DC * dc = DC_GetDCPtr( hdc );
387 if (!dc || !dc->funcs->pSetPixel) return FALSE;
388 dc->funcs->pSetPixel(dc,x,y,color);
389 return TRUE;
392 /***********************************************************************
393 * GetPixel16 (GDI.83)
395 COLORREF WINAPI GetPixel16( HDC16 hdc, INT16 x, INT16 y )
397 return GetPixel32( hdc, x, y );
401 /***********************************************************************
402 * GetPixel32 (GDI32.211)
404 COLORREF WINAPI GetPixel32( HDC32 hdc, INT32 x, INT32 y )
406 DC * dc = DC_GetDCPtr( hdc );
408 if (!dc) return 0;
409 #ifdef SOLITAIRE_SPEED_HACK
410 return 0;
411 #endif
413 /* FIXME: should this be in the graphics driver? */
414 if (!PtVisible32( hdc, x, y )) return 0;
415 if (!dc || !dc->funcs->pGetPixel) return 0;
416 return dc->funcs->pGetPixel(dc,x,y);
420 /******************************************************************************
421 * ChoosePixelFormat [GDI32.13]
422 * Matches a pixel format to given format
424 * PARAMS
425 * hdc [I] Device context to search for best pixel match
426 * ppfd [I] Pixel format for which a match is sought
428 * RETURNS
429 * Success: Pixel format index closest to given format
430 * Failure: 0
432 INT32 WINAPI ChoosePixelFormat( HDC32 hdc, const PIXELFORMATDESCRIPTOR* ppfd )
434 FIXME(gdi, "(%d,%p): stub\n",hdc,ppfd);
435 return 1;
439 /******************************************************************************
440 * SetPixelFormat [GDI32.328]
441 * Sets pixel format of device context
443 * PARAMS
444 * hdc [I] Device context to search for best pixel match
445 * iPixelFormat [I] Pixel format index
446 * ppfd [I] Pixel format for which a match is sought
448 * RETURNS STD
450 BOOL32 WINAPI SetPixelFormat( HDC32 hdc, int iPixelFormat,
451 const PIXELFORMATDESCRIPTOR* ppfd)
453 FIXME(gdi, "(%d,%d,%p): stub\n",hdc,iPixelFormat,ppfd);
454 return TRUE;
458 /******************************************************************************
459 * GetPixelFormat [GDI32.212]
460 * Gets index of pixel format of DC
462 * PARAMETERS
463 * hdc [I] Device context whose pixel format index is sought
465 * RETURNS
466 * Success: Currently selected pixel format
467 * Failure: 0
469 int WINAPI GetPixelFormat( HDC32 hdc )
471 FIXME(gdi, "(%d): stub\n",hdc);
472 return 1;
476 /******************************************************************************
477 * DescribePixelFormat [GDI32.71]
478 * Gets info about pixel format from DC
480 * PARAMS
481 * hdc [I] Device context
482 * iPixelFormat [I] Pixel format selector
483 * nBytes [I] Size of buffer
484 * ppfd [O] Pointer to structure to receive pixel format data
486 * RETURNS
487 * Success: Maximum pixel format index of the device context
488 * Failure: 0
490 int WINAPI DescribePixelFormat( HDC32 hdc, int iPixelFormat, UINT32 nBytes,
491 LPPIXELFORMATDESCRIPTOR ppfd )
493 FIXME(gdi, "(%d,%d,%d,%p): stub\n",hdc,iPixelFormat,nBytes,ppfd);
494 ppfd->nSize = nBytes;
495 ppfd->nVersion = 1;
496 return 3;
500 /******************************************************************************
501 * SwapBuffers [GDI32.354]
502 * Exchanges front and back buffers of window
504 * PARAMS
505 * hdc [I] Device context whose buffers get swapped
507 * RETURNS STD
509 BOOL32 WINAPI SwapBuffers( HDC32 hdc )
511 FIXME(gdi, "(%d): stub\n",hdc);
512 return TRUE;
516 /***********************************************************************
517 * PaintRgn16 (GDI.43)
519 BOOL16 WINAPI PaintRgn16( HDC16 hdc, HRGN16 hrgn )
521 return PaintRgn32( hdc, hrgn );
525 /***********************************************************************
526 * PaintRgn32 (GDI32.259)
528 BOOL32 WINAPI PaintRgn32( HDC32 hdc, HRGN32 hrgn )
530 DC * dc = DC_GetDCPtr( hdc );
532 return dc && dc->funcs->pPaintRgn &&
533 dc->funcs->pPaintRgn(dc,hrgn);
537 /***********************************************************************
538 * FillRgn16 (GDI.40)
540 BOOL16 WINAPI FillRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush )
542 return FillRgn32( hdc, hrgn, hbrush );
546 /***********************************************************************
547 * FillRgn32 (GDI32.101)
549 BOOL32 WINAPI FillRgn32( HDC32 hdc, HRGN32 hrgn, HBRUSH32 hbrush )
551 BOOL32 retval;
552 HBRUSH32 prevBrush = SelectObject32( hdc, hbrush );
553 if (!prevBrush) return FALSE;
554 retval = PaintRgn32( hdc, hrgn );
555 SelectObject32( hdc, prevBrush );
556 return retval;
560 /***********************************************************************
561 * FrameRgn16 (GDI.41)
563 BOOL16 WINAPI FrameRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush,
564 INT16 nWidth, INT16 nHeight )
566 return FrameRgn32( hdc, hrgn, hbrush, nWidth, nHeight );
570 /***********************************************************************
571 * FrameRgn32 (GDI32.105)
573 BOOL32 WINAPI FrameRgn32( HDC32 hdc, HRGN32 hrgn, HBRUSH32 hbrush,
574 INT32 nWidth, INT32 nHeight )
576 HRGN32 tmp = CreateRectRgn32( 0, 0, 0, 0 );
577 if(!REGION_FrameRgn( tmp, hrgn, nWidth, nHeight )) return FALSE;
578 FillRgn32( hdc, tmp, hbrush );
579 DeleteObject32( tmp );
580 return TRUE;
584 /***********************************************************************
585 * InvertRgn16 (GDI.42)
587 BOOL16 WINAPI InvertRgn16( HDC16 hdc, HRGN16 hrgn )
589 return InvertRgn32( hdc, hrgn );
593 /***********************************************************************
594 * InvertRgn32 (GDI32.246)
596 BOOL32 WINAPI InvertRgn32( HDC32 hdc, HRGN32 hrgn )
598 HBRUSH32 prevBrush = SelectObject32( hdc, GetStockObject32(BLACK_BRUSH) );
599 INT32 prevROP = SetROP232( hdc, R2_NOT );
600 BOOL32 retval = PaintRgn32( hdc, hrgn );
601 SelectObject32( hdc, prevBrush );
602 SetROP232( hdc, prevROP );
603 return retval;
607 /***********************************************************************
608 * DrawFocusRect16 (USER.466)
610 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
612 RECT32 rect32;
613 CONV_RECT16TO32( rc, &rect32 );
614 DrawFocusRect32( hdc, &rect32 );
618 /***********************************************************************
619 * DrawFocusRect32 (USER32.156)
621 * FIXME: PatBlt(PATINVERT) with background brush.
623 void WINAPI DrawFocusRect32( HDC32 hdc, const RECT32* rc )
625 HPEN32 hOldPen, hnewPen;
626 INT32 oldDrawMode, oldBkMode;
627 INT32 left, top, right, bottom;
629 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
630 if (!dc) return;
632 left = XLPTODP( dc, rc->left );
633 top = YLPTODP( dc, rc->top );
634 right = XLPTODP( dc, rc->right );
635 bottom = YLPTODP( dc, rc->bottom );
637 if(left == right || top == bottom)
638 return;
640 hnewPen = CreatePen32(PS_DOT, 1, GetSysColor32(COLOR_WINDOWTEXT) );
641 hOldPen = SelectObject32( hdc, hnewPen );
642 oldDrawMode = SetROP232(hdc, R2_XORPEN);
643 oldBkMode = SetBkMode32(hdc, TRANSPARENT);
645 /* Hack: make sure the XORPEN operation has an effect */
646 dc->u.x.pen.pixel = (1 << screenDepth) - 1;
648 if (DC_SetupGCForPen( dc ))
649 TSXDrawRectangle( display, dc->u.x.drawable, dc->u.x.gc,
650 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
651 right-left-1, bottom-top-1 );
653 SetBkMode32(hdc, oldBkMode);
654 SetROP232(hdc, oldDrawMode);
655 SelectObject32(hdc, hOldPen);
656 DeleteObject32(hnewPen);
660 /**********************************************************************
661 * Polyline16 (GDI.37)
663 BOOL16 WINAPI Polyline16( HDC16 hdc, const POINT16* pt, INT16 count )
665 register int i;
666 BOOL16 ret;
667 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
668 count*sizeof(POINT32) );
670 if (!pt32) return FALSE;
671 for (i=count;i--;) CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
672 ret = Polyline32(hdc,pt32,count);
673 HeapFree( GetProcessHeap(), 0, pt32 );
674 return ret;
678 /**********************************************************************
679 * Polyline32 (GDI32.276)
681 BOOL32 WINAPI Polyline32( HDC32 hdc, const POINT32* pt, INT32 count )
683 DC * dc = DC_GetDCPtr( hdc );
685 return dc && dc->funcs->pPolyline &&
686 dc->funcs->pPolyline(dc,pt,count);
690 /**********************************************************************
691 * Polygon16 (GDI.36)
693 BOOL16 WINAPI Polygon16( HDC16 hdc, const POINT16* pt, INT16 count )
695 register int i;
696 BOOL32 ret;
697 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
698 count*sizeof(POINT32) );
700 if (!pt32) return FALSE;
701 for (i=count;i--;) CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
702 ret = Polygon32(hdc,pt32,count);
703 HeapFree( GetProcessHeap(), 0, pt32 );
704 return ret;
708 /**********************************************************************
709 * Polygon32 (GDI32.275)
711 BOOL32 WINAPI Polygon32( HDC32 hdc, const POINT32* pt, INT32 count )
713 DC * dc = DC_GetDCPtr( hdc );
715 return dc && dc->funcs->pPolygon &&
716 dc->funcs->pPolygon(dc,pt,count);
720 /**********************************************************************
721 * PolyPolygon16 (GDI.450)
723 BOOL16 WINAPI PolyPolygon16( HDC16 hdc, const POINT16* pt, const INT16* counts,
724 UINT16 polygons )
726 int i,nrpts;
727 LPPOINT32 pt32;
728 LPINT32 counts32;
729 BOOL16 ret;
731 nrpts=0;
732 for (i=polygons;i--;)
733 nrpts+=counts[i];
734 pt32 = (LPPOINT32)HEAP_xalloc( GetProcessHeap(), 0, sizeof(POINT32)*nrpts);
735 for (i=nrpts;i--;)
736 CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
737 counts32 = (LPINT32)HEAP_xalloc( GetProcessHeap(), 0,
738 polygons*sizeof(INT32) );
739 for (i=polygons;i--;) counts32[i]=counts[i];
741 ret = PolyPolygon32(hdc,pt32,counts32,polygons);
742 HeapFree( GetProcessHeap(), 0, counts32 );
743 HeapFree( GetProcessHeap(), 0, pt32 );
744 return ret;
747 /**********************************************************************
748 * PolyPolygon32 (GDI.450)
750 BOOL32 WINAPI PolyPolygon32( HDC32 hdc, const POINT32* pt, const INT32* counts,
751 UINT32 polygons )
753 DC * dc = DC_GetDCPtr( hdc );
755 return dc && dc->funcs->pPolyPolygon &&
756 dc->funcs->pPolyPolygon(dc,pt,counts,polygons);
759 /**********************************************************************
760 * PolyPolyline32 (GDI32.272)
762 BOOL32 WINAPI PolyPolyline32( HDC32 hdc, const POINT32* pt, const DWORD* counts,
763 DWORD polylines )
765 DC * dc = DC_GetDCPtr( hdc );
767 return dc && dc->funcs->pPolyPolyline &&
768 dc->funcs->pPolyPolyline(dc,pt,counts,polylines);
771 /**********************************************************************
772 * ExtFloodFill16 (GDI.372)
774 BOOL16 WINAPI ExtFloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color,
775 UINT16 fillType )
777 return ExtFloodFill32( hdc, x, y, color, fillType );
781 /**********************************************************************
782 * ExtFloodFill32 (GDI32.96)
784 BOOL32 WINAPI ExtFloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color,
785 UINT32 fillType )
787 DC *dc = DC_GetDCPtr( hdc );
789 return dc && dc->funcs->pExtFloodFill &&
790 dc->funcs->pExtFloodFill(dc,x,y,color,fillType);
794 /**********************************************************************
795 * FloodFill16 (GDI.25)
797 BOOL16 WINAPI FloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
799 return ExtFloodFill32( hdc, x, y, color, FLOODFILLBORDER );
803 /**********************************************************************
804 * FloodFill32 (GDI32.104)
806 BOOL32 WINAPI FloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
808 return ExtFloodFill32( hdc, x, y, color, FLOODFILLBORDER );
812 /**********************************************************************
813 * DrawAnimatedRects32 (USER32.153)
815 BOOL32 WINAPI DrawAnimatedRects32( HWND32 hwnd, int idAni,
816 const RECT32* lprcFrom,
817 const RECT32* lprcTo )
819 FIXME(gdi,"(0x%x,%d,%p,%p): stub\n",hwnd,idAni,lprcFrom,lprcTo);
820 return TRUE;
824 /**********************************************************************
825 * PAINTING_DrawStateJam
827 * Jams in the requested type in the dc
829 static BOOL32 PAINTING_DrawStateJam(HDC32 hdc, UINT32 opcode,
830 DRAWSTATEPROC32 func, LPARAM lp, WPARAM32 wp,
831 LPRECT32 rc, UINT32 dtflags,
832 BOOL32 unicode, BOOL32 _32bit)
834 HDC32 memdc;
835 HBITMAP32 hbmsave;
836 BOOL32 retval;
837 INT32 cx = rc->right - rc->left;
838 INT32 cy = rc->bottom - rc->top;
840 switch(opcode)
842 case DST_TEXT:
843 case DST_PREFIXTEXT:
844 if(unicode)
845 return DrawText32W(hdc, (LPWSTR)lp, (INT32)wp, rc, dtflags);
846 else if(_32bit)
847 return DrawText32A(hdc, (LPSTR)lp, (INT32)wp, rc, dtflags);
848 else
849 return DrawText32A(hdc, (LPSTR)PTR_SEG_TO_LIN(lp), (INT32)wp, rc, dtflags);
851 case DST_ICON:
852 return DrawIcon32(hdc, rc->left, rc->top, (HICON32)lp);
854 case DST_BITMAP:
855 memdc = CreateCompatibleDC32(hdc);
856 if(!memdc) return FALSE;
857 hbmsave = (HBITMAP32)SelectObject32(memdc, (HBITMAP32)lp);
858 if(!hbmsave)
860 DeleteDC32(memdc);
861 return FALSE;
863 retval = BitBlt32(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
864 SelectObject32(memdc, hbmsave);
865 DeleteDC32(memdc);
866 return retval;
868 case DST_COMPLEX:
869 if(func)
870 if(_32bit)
871 return func(hdc, lp, wp, cx, cy);
872 else
873 return (BOOL32)((DRAWSTATEPROC16)func)((HDC16)hdc, (LPARAM)lp, (WPARAM16)wp, (INT16)cx, (INT16)cy);
874 else
875 return FALSE;
877 return FALSE;
880 /**********************************************************************
881 * PAINTING_DrawState32()
883 static BOOL32 PAINTING_DrawState32(HDC32 hdc, HBRUSH32 hbr,
884 DRAWSTATEPROC32 func, LPARAM lp, WPARAM32 wp,
885 INT32 x, INT32 y, INT32 cx, INT32 cy,
886 UINT32 flags, BOOL32 unicode, BOOL32 _32bit)
888 HBITMAP32 hbm, hbmsave;
889 HFONT32 hfsave;
890 HBRUSH32 hbsave;
891 HDC32 memdc;
892 RECT32 rc;
893 UINT32 dtflags = DT_NOCLIP;
894 COLORREF fg, bg;
895 UINT32 opcode = flags & 0xf;
896 INT32 len = wp;
897 BOOL32 retval, tmp;
899 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
901 if(unicode)
902 len = lstrlen32W((LPWSTR)lp);
903 else if(_32bit)
904 len = lstrlen32A((LPSTR)lp);
905 else
906 len = lstrlen32A((LPSTR)PTR_SEG_TO_LIN(lp));
909 /* Find out what size the image has if not given by caller */
910 if(!cx || !cy)
912 SIZE32 s;
913 CURSORICONINFO *ici;
914 BITMAPOBJ *bmp;
916 switch(opcode)
918 case DST_TEXT:
919 case DST_PREFIXTEXT:
920 if(unicode)
921 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
922 else if(_32bit)
923 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
924 else
925 retval = GetTextExtentPoint32A(hdc, PTR_SEG_TO_LIN(lp), len, &s);
926 if(!retval) return FALSE;
927 break;
929 case DST_ICON:
930 ici = (CURSORICONINFO *)GlobalLock16((HGLOBAL16)lp);
931 if(!ici) return FALSE;
932 s.cx = ici->nWidth;
933 s.cy = ici->nHeight;
934 GlobalUnlock16((HGLOBAL16)lp);
935 break;
937 case DST_BITMAP:
938 bmp = (BITMAPOBJ *)GDI_GetObjPtr((HBITMAP16)lp, BITMAP_MAGIC);
939 if(!bmp) return FALSE;
940 s.cx = bmp->bitmap.bmWidth;
941 s.cy = bmp->bitmap.bmHeight;
942 break;
944 case DST_COMPLEX: /* cx and cy must be set in this mode */
945 return FALSE;
948 if(!cx) cx = s.cx;
949 if(!cy) cy = s.cy;
952 rc.left = x;
953 rc.top = y;
954 rc.right = x + cx;
955 rc.bottom = y + cy;
957 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
958 dtflags |= DT_RIGHT;
959 if(opcode == DST_TEXT)
960 dtflags |= DT_NOPREFIX;
962 /* For DSS_NORMAL we just jam in the image and return */
963 if((flags & 0x7ff0) == DSS_NORMAL)
965 return PAINTING_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
968 /* For all other states we need to convert the image to B/W in a local bitmap */
969 /* before it is displayed */
970 fg = SetTextColor32(hdc, RGB(0, 0, 0));
971 bg = SetBkColor32(hdc, RGB(255, 255, 255));
972 hbm = (HBITMAP32)NULL; hbmsave = (HBITMAP32)NULL;
973 memdc = (HDC32)NULL; hbsave = (HBRUSH32)NULL;
974 retval = FALSE; /* assume failure */
976 /* From here on we must use "goto cleanup" when something goes wrong */
977 hbm = CreateBitmap32(cx, cy, 1, 1, NULL);
978 if(!hbm) goto cleanup;
979 memdc = CreateCompatibleDC32(hdc);
980 if(!memdc) goto cleanup;
981 hbmsave = (HBITMAP32)SelectObject32(memdc, hbm);
982 if(!hbmsave) goto cleanup;
983 rc.left = rc.top = 0;
984 rc.right = cx;
985 rc.bottom = cy;
986 if(!FillRect32(memdc, &rc, (HBRUSH32)GetStockObject32(WHITE_BRUSH))) goto cleanup;
987 SetBkColor32(memdc, RGB(255, 255, 255));
988 SetTextColor32(memdc, RGB(0, 0, 0));
989 hfsave = (HFONT32)SelectObject32(memdc, GetCurrentObject(hdc, OBJ_FONT));
990 if(!hfsave && (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)) goto cleanup;
991 tmp = PAINTING_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
992 if(hfsave) SelectObject32(memdc, hfsave);
993 if(!tmp) goto cleanup;
995 /* These states cause the image to be dithered */
996 if(flags & (DSS_UNION|DSS_DISABLED))
998 hbsave = (HBRUSH32)SelectObject32(memdc, CACHE_GetPattern55AABrush());
999 if(!hbsave) goto cleanup;
1000 tmp = PatBlt32(memdc, 0, 0, cx, cy, 0x00FA0089);
1001 if(hbsave) SelectObject32(memdc, hbsave);
1002 if(!tmp) goto cleanup;
1005 hbsave = (HBRUSH32)SelectObject32(hdc, hbr ? hbr : GetStockObject32(WHITE_BRUSH));
1006 if(!hbsave) goto cleanup;
1008 if(!BitBlt32(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1010 /* DSS_DEFAULT makes the image boldface */
1011 if(flags & DSS_DEFAULT)
1013 if(!BitBlt32(hdc, x+1, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1016 retval = TRUE; /* We succeeded */
1018 cleanup:
1019 SetTextColor32(hdc, fg);
1020 SetBkColor32(hdc, bg);
1022 if(hbsave) SelectObject32(hdc, hbsave);
1023 if(hbmsave) SelectObject32(memdc, hbmsave);
1024 if(hbm) DeleteObject32(hbm);
1025 if(memdc) DeleteDC32(memdc);
1027 return retval;
1030 /**********************************************************************
1031 * DrawState32A() (USER32.162)
1033 BOOL32 WINAPI DrawState32A(HDC32 hdc, HBRUSH32 hbr,
1034 DRAWSTATEPROC32 func, LPARAM ldata, WPARAM32 wdata,
1035 INT32 x, INT32 y, INT32 cx, INT32 cy, UINT32 flags)
1037 return PAINTING_DrawState32(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE, TRUE);
1040 /**********************************************************************
1041 * DrawState32W() (USER32.163)
1043 BOOL32 WINAPI DrawState32W(HDC32 hdc, HBRUSH32 hbr,
1044 DRAWSTATEPROC32 func, LPARAM ldata, WPARAM32 wdata,
1045 INT32 x, INT32 y, INT32 cx, INT32 cy, UINT32 flags)
1047 return PAINTING_DrawState32(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE, TRUE);
1050 /**********************************************************************
1051 * DrawState16() (USER.449)
1053 BOOL16 WINAPI DrawState16(HDC16 hdc, HBRUSH16 hbr,
1054 DRAWSTATEPROC16 func, LPARAM ldata, WPARAM16 wdata,
1055 INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags)
1057 return PAINTING_DrawState32(hdc, hbr, (DRAWSTATEPROC32)func, ldata, wdata, x, y, cx, cy, flags, FALSE, FALSE);
1061 /******************************************************************************
1062 * PolyBezier16 [GDI.502]
1064 BOOL16 WINAPI PolyBezier16( HDC16 hDc, const POINT16* lppt, INT16 cPoints )
1066 int i;
1067 BOOL16 ret;
1068 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
1069 cPoints*sizeof(POINT32) );
1070 if(!pt32) return FALSE;
1071 for (i=cPoints;i--;) CONV_POINT16TO32(&(lppt[i]),&(pt32[i]));
1072 ret= PolyBezier32(hDc, pt32, cPoints);
1073 HeapFree( GetProcessHeap(), 0, pt32 );
1074 return ret;
1077 /******************************************************************************
1078 * PolyBezierTo16 [GDI.503]
1080 BOOL16 WINAPI PolyBezierTo16( HDC16 hDc, const POINT16* lppt, INT16 cPoints )
1082 int i;
1083 BOOL16 ret;
1084 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
1085 cPoints*sizeof(POINT32) );
1086 if(!pt32) return FALSE;
1087 for (i=cPoints;i--;) CONV_POINT16TO32(&(lppt[i]),&(pt32[i]));
1088 ret= PolyBezierTo32(hDc, pt32, cPoints);
1089 HeapFree( GetProcessHeap(), 0, pt32 );
1090 return ret;
1093 /******************************************************************************
1094 * PolyBezier32 [GDI32.268]
1095 * Draws one or more Bezier curves
1097 * PARAMS
1098 * hDc [I] Handle to device context
1099 * lppt [I] Pointer to endpoints and control points
1100 * cPoints [I] Count of endpoints and control points
1102 * RETURNS STD
1104 BOOL32 WINAPI PolyBezier32( HDC32 hdc, const POINT32* lppt, DWORD cPoints )
1106 DC * dc = DC_GetDCPtr( hdc );
1107 if(!dc) return FALSE;
1108 if(dc && PATH_IsPathOpen(dc->w.path))
1109 FIXME(gdi, "PATH_PolyBezier is not implemented!\n");
1110 /* if(!PATH_PolyBezier(hdc, x, y))
1111 return FALSE; */
1112 return dc->funcs->pPolyBezier&&
1113 dc->funcs->pPolyBezier(dc, lppt[0], lppt+1, cPoints-1);
1116 /******************************************************************************
1117 * PolyBezierTo32 [GDI32.269]
1118 * Draws one or more Bezier curves
1120 * PARAMS
1121 * hDc [I] Handle to device context
1122 * lppt [I] Pointer to endpoints and control points
1123 * cPoints [I] Count of endpoints and control points
1125 * RETURNS STD
1127 BOOL32 WINAPI PolyBezierTo32( HDC32 hdc, const POINT32* lppt, DWORD cPoints )
1129 DC * dc = DC_GetDCPtr( hdc );
1130 POINT32 pt;
1131 BOOL32 ret;
1132 if(!dc) return FALSE;
1133 pt.x=dc->w.CursPosX;
1134 pt.y=dc->w.CursPosY;
1135 if(dc && PATH_IsPathOpen(dc->w.path))
1136 FIXME(gdi, "PATH_PolyBezierTo is not implemented!\n");
1137 /* if(!PATH_PolyBezier(hdc, x, y))
1138 return FALSE; */
1139 ret= dc->funcs->pPolyBezier &&
1140 dc->funcs->pPolyBezier(dc, pt, lppt, cPoints);
1141 if( dc->funcs->pMoveToEx)
1142 dc->funcs->pMoveToEx(dc,lppt[cPoints].x,lppt[cPoints].y,&pt);
1143 return ret;