Release 980503
[wine/multimedia.git] / graphics / painting.c
bloba142c91f6ecc1472ed3a021f61eae8aebae7cebe
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 return dc && dc->funcs->pRectangle &&
223 dc->funcs->pRectangle(dc,left,top,right,bottom);
227 /***********************************************************************
228 * RoundRect16 (GDI.28)
230 BOOL16 WINAPI RoundRect16( HDC16 hdc, INT16 left, INT16 top, INT16 right,
231 INT16 bottom, INT16 ell_width, INT16 ell_height )
233 return RoundRect32( hdc, left, top, right, bottom, ell_width, ell_height );
237 /***********************************************************************
238 * RoundRect32 (GDI32.291)
240 BOOL32 WINAPI RoundRect32( HDC32 hdc, INT32 left, INT32 top, INT32 right,
241 INT32 bottom, INT32 ell_width, INT32 ell_height )
243 DC * dc = DC_GetDCPtr( hdc );
245 return dc && dc->funcs->pRoundRect &&
246 dc->funcs->pRoundRect(dc,left,top,right,bottom,ell_width,ell_height);
250 /***********************************************************************
251 * FillRect16 (USER.81)
253 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
255 HBRUSH16 prevBrush;
257 /* coordinates are logical so we cannot fast-check 'rect',
258 * it will be done later in the PatBlt().
261 if (!(prevBrush = SelectObject16( hdc, hbrush ))) return 0;
262 PatBlt32( hdc, rect->left, rect->top,
263 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
264 SelectObject16( hdc, prevBrush );
265 return 1;
269 /***********************************************************************
270 * FillRect32 (USER32.197)
272 INT32 WINAPI FillRect32( HDC32 hdc, const RECT32 *rect, HBRUSH32 hbrush )
274 HBRUSH32 prevBrush;
276 if (!(prevBrush = SelectObject32( hdc, hbrush ))) return 0;
277 PatBlt32( hdc, rect->left, rect->top,
278 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
279 SelectObject32( hdc, prevBrush );
280 return 1;
284 /***********************************************************************
285 * InvertRect16 (USER.82)
287 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
289 PatBlt32( hdc, rect->left, rect->top,
290 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
294 /***********************************************************************
295 * InvertRect32 (USER32.330)
297 void WINAPI InvertRect32( HDC32 hdc, const RECT32 *rect )
299 PatBlt32( hdc, rect->left, rect->top,
300 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
304 /***********************************************************************
305 * FrameRect16 (USER.83)
307 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
309 HBRUSH16 prevBrush;
310 int left, top, right, bottom;
312 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
313 if (!dc) return FALSE;
315 left = XLPTODP( dc, rect->left );
316 top = YLPTODP( dc, rect->top );
317 right = XLPTODP( dc, rect->right );
318 bottom = YLPTODP( dc, rect->bottom );
320 if ( (right <= left) || (bottom <= top) ) return 0;
321 if (!(prevBrush = SelectObject16( hdc, hbrush ))) return 0;
323 if (DC_SetupGCForBrush( dc ))
325 PatBlt32( hdc, rect->left, rect->top, 1,
326 rect->bottom - rect->top, PATCOPY );
327 PatBlt32( hdc, rect->right - 1, rect->top, 1,
328 rect->bottom - rect->top, PATCOPY );
329 PatBlt32( hdc, rect->left, rect->top,
330 rect->right - rect->left, 1, PATCOPY );
331 PatBlt32( hdc, rect->left, rect->bottom - 1,
332 rect->right - rect->left, 1, PATCOPY );
334 SelectObject16( hdc, prevBrush );
335 return 1;
339 /***********************************************************************
340 * FrameRect32 (USER32.203)
342 INT32 WINAPI FrameRect32( HDC32 hdc, const RECT32 *rect, HBRUSH32 hbrush )
344 RECT16 rect16;
345 CONV_RECT32TO16( rect, &rect16 );
346 return FrameRect16( (HDC16)hdc, &rect16, (HBRUSH16)hbrush );
350 /***********************************************************************
351 * SetPixel16 (GDI.31)
353 COLORREF WINAPI SetPixel16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
355 return SetPixel32( hdc, x, y, color );
359 /***********************************************************************
360 * SetPixel32 (GDI32.327)
362 COLORREF WINAPI SetPixel32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
364 DC * dc = DC_GetDCPtr( hdc );
366 if (!dc || !dc->funcs->pSetPixel) return 0;
367 return dc->funcs->pSetPixel(dc,x,y,color);
370 /***********************************************************************
371 * SetPixelV32 (GDI32.329)
373 BOOL32 WINAPI SetPixelV32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
375 DC * dc = DC_GetDCPtr( hdc );
377 if (!dc || !dc->funcs->pSetPixel) return FALSE;
378 dc->funcs->pSetPixel(dc,x,y,color);
379 return TRUE;
382 /***********************************************************************
383 * GetPixel16 (GDI.83)
385 COLORREF WINAPI GetPixel16( HDC16 hdc, INT16 x, INT16 y )
387 return GetPixel32( hdc, x, y );
391 /***********************************************************************
392 * GetPixel32 (GDI32.211)
394 COLORREF WINAPI GetPixel32( HDC32 hdc, INT32 x, INT32 y )
396 DC * dc = DC_GetDCPtr( hdc );
398 if (!dc) return 0;
399 #ifdef SOLITAIRE_SPEED_HACK
400 return 0;
401 #endif
403 /* FIXME: should this be in the graphics driver? */
404 if (!PtVisible32( hdc, x, y )) return 0;
405 if (!dc || !dc->funcs->pGetPixel) return 0;
406 return dc->funcs->pGetPixel(dc,x,y);
410 /******************************************************************************
411 * ChoosePixelFormat [GDI32.13]
412 * Matches a pixel format to given format
414 * PARAMS
415 * hdc [I] Device context to search for best pixel match
416 * ppfd [I] Pixel format for which a match is sought
418 * RETURNS
419 * Success: Pixel format index closest to given format
420 * Failure: 0
422 INT32 WINAPI ChoosePixelFormat( HDC32 hdc, PIXELFORMATDESCRIPTOR *ppfd )
424 FIXME(gdi, "(%d,%p): stub\n",hdc,ppfd);
425 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
426 ppfd->nVersion = 1;
427 return 1;
431 /******************************************************************************
432 * SetPixelFormat [GDI32.328]
433 * Sets pixel format of device context
435 * PARAMS
436 * hdc [I] Device context to search for best pixel match
437 * iPixelFormat [I] Pixel format index
438 * ppfd [I] Pixel format for which a match is sought
440 * RETURNS STD
442 BOOL32 WINAPI SetPixelFormat( HDC32 hdc, int iPixelFormat,
443 PIXELFORMATDESCRIPTOR * ppfd)
445 FIXME(gdi, "(%d,%d,%p): stub\n",hdc,iPixelFormat,ppfd);
446 return TRUE;
450 /******************************************************************************
451 * GetPixelFormat [GDI32.212]
452 * Gets index of pixel format of DC
454 * PARAMETERS
455 * hdc [I] Device context whose pixel format index is sought
457 * RETURNS
458 * Success: Currently selected pixel format
459 * Failure: 0
461 int WINAPI GetPixelFormat( HDC32 hdc )
463 FIXME(gdi, "(%d): stub\n",hdc);
464 return 1;
468 /******************************************************************************
469 * DescribePixelFormat [GDI32.71]
470 * Gets info about pixel format from DC
472 * PARAMS
473 * hdc [I] Device context
474 * iPixelFormat [I] Pixel format selector
475 * nBytes [I] Size of buffer
476 * ppfd [O] Pointer to structure to receive pixel format data
478 * RETURNS
479 * Success: Maximum pixel format index of the device context
480 * Failure: 0
482 int WINAPI DescribePixelFormat( HDC32 hdc, int iPixelFormat, UINT32 nBytes,
483 LPPIXELFORMATDESCRIPTOR ppfd )
485 FIXME(gdi, "(%d,%d,%d,%p): stub\n",hdc,iPixelFormat,nBytes,ppfd);
486 ppfd->nSize = nBytes;
487 ppfd->nVersion = 1;
488 return 3;
492 /******************************************************************************
493 * SwapBuffers [GDI32.354]
494 * Exchanges front and back buffers of window
496 * PARAMS
497 * hdc [I] Device context whose buffers get swapped
499 * RETURNS STD
501 BOOL32 WINAPI SwapBuffers( HDC32 hdc )
503 FIXME(gdi, "(%d): stub\n",hdc);
504 return TRUE;
508 /***********************************************************************
509 * PaintRgn16 (GDI.43)
511 BOOL16 WINAPI PaintRgn16( HDC16 hdc, HRGN16 hrgn )
513 return PaintRgn32( hdc, hrgn );
517 /***********************************************************************
518 * PaintRgn32 (GDI32.259)
520 BOOL32 WINAPI PaintRgn32( HDC32 hdc, HRGN32 hrgn )
522 DC * dc = DC_GetDCPtr( hdc );
524 return dc && dc->funcs->pPaintRgn &&
525 dc->funcs->pPaintRgn(dc,hrgn);
529 /***********************************************************************
530 * FillRgn16 (GDI.40)
532 BOOL16 WINAPI FillRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush )
534 return FillRgn32( hdc, hrgn, hbrush );
538 /***********************************************************************
539 * FillRgn32 (GDI32.101)
541 BOOL32 WINAPI FillRgn32( HDC32 hdc, HRGN32 hrgn, HBRUSH32 hbrush )
543 BOOL32 retval;
544 HBRUSH32 prevBrush = SelectObject32( hdc, hbrush );
545 if (!prevBrush) return FALSE;
546 retval = PaintRgn32( hdc, hrgn );
547 SelectObject32( hdc, prevBrush );
548 return retval;
552 /***********************************************************************
553 * FrameRgn16 (GDI.41)
555 BOOL16 WINAPI FrameRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush,
556 INT16 nWidth, INT16 nHeight )
558 return FrameRgn32( hdc, hrgn, hbrush, nWidth, nHeight );
562 /***********************************************************************
563 * FrameRgn32 (GDI32.105)
565 BOOL32 WINAPI FrameRgn32( HDC32 hdc, HRGN32 hrgn, HBRUSH32 hbrush,
566 INT32 nWidth, INT32 nHeight )
568 HRGN32 tmp = CreateRectRgn32( 0, 0, 0, 0 );
569 if(!REGION_FrameRgn( tmp, hrgn, nWidth, nHeight )) return FALSE;
570 FillRgn32( hdc, tmp, hbrush );
571 DeleteObject32( tmp );
572 return TRUE;
576 /***********************************************************************
577 * InvertRgn16 (GDI.42)
579 BOOL16 WINAPI InvertRgn16( HDC16 hdc, HRGN16 hrgn )
581 return InvertRgn32( hdc, hrgn );
585 /***********************************************************************
586 * InvertRgn32 (GDI32.246)
588 BOOL32 WINAPI InvertRgn32( HDC32 hdc, HRGN32 hrgn )
590 HBRUSH32 prevBrush = SelectObject32( hdc, GetStockObject32(BLACK_BRUSH) );
591 INT32 prevROP = SetROP232( hdc, R2_NOT );
592 BOOL32 retval = PaintRgn32( hdc, hrgn );
593 SelectObject32( hdc, prevBrush );
594 SetROP232( hdc, prevROP );
595 return retval;
599 /***********************************************************************
600 * DrawFocusRect16 (USER.466)
602 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
604 RECT32 rect32;
605 CONV_RECT16TO32( rc, &rect32 );
606 DrawFocusRect32( hdc, &rect32 );
610 /***********************************************************************
611 * DrawFocusRect32 (USER32.156)
613 * FIXME: PatBlt(PATINVERT) with background brush.
615 void WINAPI DrawFocusRect32( HDC32 hdc, const RECT32* rc )
617 HPEN32 hOldPen, hnewPen;
618 INT32 oldDrawMode, oldBkMode;
619 INT32 left, top, right, bottom;
621 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
622 if (!dc) return;
624 left = XLPTODP( dc, rc->left );
625 top = YLPTODP( dc, rc->top );
626 right = XLPTODP( dc, rc->right );
627 bottom = YLPTODP( dc, rc->bottom );
629 hnewPen = CreatePen32(PS_DOT, 1, GetSysColor32(COLOR_WINDOWTEXT) );
630 hOldPen = SelectObject32( hdc, hnewPen );
631 oldDrawMode = SetROP232(hdc, R2_XORPEN);
632 oldBkMode = SetBkMode32(hdc, TRANSPARENT);
634 /* Hack: make sure the XORPEN operation has an effect */
635 dc->u.x.pen.pixel = (1 << screenDepth) - 1;
637 if (DC_SetupGCForPen( dc ))
638 TSXDrawRectangle( display, dc->u.x.drawable, dc->u.x.gc,
639 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
640 right-left-1, bottom-top-1 );
642 SetBkMode32(hdc, oldBkMode);
643 SetROP232(hdc, oldDrawMode);
644 SelectObject32(hdc, hOldPen);
645 DeleteObject32(hnewPen);
649 /**********************************************************************
650 * Polyline16 (GDI.37)
652 BOOL16 WINAPI Polyline16( HDC16 hdc, LPPOINT16 pt, INT16 count )
654 register int i;
655 BOOL16 ret;
656 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
657 count*sizeof(POINT32) );
659 if (!pt32) return FALSE;
660 for (i=count;i--;) CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
661 ret = Polyline32(hdc,pt32,count);
662 HeapFree( GetProcessHeap(), 0, pt32 );
663 return ret;
667 /**********************************************************************
668 * Polyline32 (GDI32.276)
670 BOOL32 WINAPI Polyline32( HDC32 hdc, const LPPOINT32 pt, INT32 count )
672 DC * dc = DC_GetDCPtr( hdc );
674 return dc && dc->funcs->pPolyline &&
675 dc->funcs->pPolyline(dc,pt,count);
679 /**********************************************************************
680 * Polygon16 (GDI.36)
682 BOOL16 WINAPI Polygon16( HDC16 hdc, LPPOINT16 pt, INT16 count )
684 register int i;
685 BOOL32 ret;
686 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
687 count*sizeof(POINT32) );
689 if (!pt32) return FALSE;
690 for (i=count;i--;) CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
691 ret = Polygon32(hdc,pt32,count);
692 HeapFree( GetProcessHeap(), 0, pt32 );
693 return ret;
697 /**********************************************************************
698 * Polygon32 (GDI32.275)
700 BOOL32 WINAPI Polygon32( HDC32 hdc, LPPOINT32 pt, INT32 count )
702 DC * dc = DC_GetDCPtr( hdc );
704 return dc && dc->funcs->pPolygon &&
705 dc->funcs->pPolygon(dc,pt,count);
709 /**********************************************************************
710 * PolyPolygon16 (GDI.450)
712 BOOL16 WINAPI PolyPolygon16( HDC16 hdc, LPPOINT16 pt, LPINT16 counts,
713 UINT16 polygons )
715 int i,nrpts;
716 LPPOINT32 pt32;
717 LPINT32 counts32;
718 BOOL16 ret;
720 nrpts=0;
721 for (i=polygons;i--;)
722 nrpts+=counts[i];
723 pt32 = (LPPOINT32)HEAP_xalloc( GetProcessHeap(), 0, sizeof(POINT32)*nrpts);
724 for (i=nrpts;i--;)
725 CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
726 counts32 = (LPINT32)HEAP_xalloc( GetProcessHeap(), 0,
727 polygons*sizeof(INT32) );
728 for (i=polygons;i--;) counts32[i]=counts[i];
730 ret = PolyPolygon32(hdc,pt32,counts32,polygons);
731 HeapFree( GetProcessHeap(), 0, counts32 );
732 HeapFree( GetProcessHeap(), 0, pt32 );
733 return ret;
736 /**********************************************************************
737 * PolyPolygon32 (GDI.450)
739 BOOL32 WINAPI PolyPolygon32( HDC32 hdc, LPPOINT32 pt, LPINT32 counts,
740 UINT32 polygons )
742 DC * dc = DC_GetDCPtr( hdc );
744 return dc && dc->funcs->pPolyPolygon &&
745 dc->funcs->pPolyPolygon(dc,pt,counts,polygons);
748 /**********************************************************************
749 * PolyPolyline32 (GDI32.272)
751 BOOL32 WINAPI PolyPolyline32( HDC32 hdc, LPPOINT32 pt, LPINT32 counts,
752 UINT32 polylines )
754 DC * dc = DC_GetDCPtr( hdc );
756 return dc && dc->funcs->pPolyPolyline &&
757 dc->funcs->pPolyPolyline(dc,pt,counts,polylines);
760 /**********************************************************************
761 * ExtFloodFill16 (GDI.372)
763 BOOL16 WINAPI ExtFloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color,
764 UINT16 fillType )
766 return ExtFloodFill32( hdc, x, y, color, fillType );
770 /**********************************************************************
771 * ExtFloodFill32 (GDI32.96)
773 BOOL32 WINAPI ExtFloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color,
774 UINT32 fillType )
776 DC *dc = DC_GetDCPtr( hdc );
778 return dc && dc->funcs->pExtFloodFill &&
779 dc->funcs->pExtFloodFill(dc,x,y,color,fillType);
783 /**********************************************************************
784 * FloodFill16 (GDI.25)
786 BOOL16 WINAPI FloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
788 return ExtFloodFill32( hdc, x, y, color, FLOODFILLBORDER );
792 /**********************************************************************
793 * FloodFill32 (GDI32.104)
795 BOOL32 WINAPI FloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
797 return ExtFloodFill32( hdc, x, y, color, FLOODFILLBORDER );
801 /**********************************************************************
802 * DrawAnimatedRects32 (USER32.153)
804 BOOL32 WINAPI DrawAnimatedRects32( HWND32 hwnd, int idAni,
805 const LPRECT32 lprcFrom,
806 const LPRECT32 lprcTo )
808 FIXME(gdi,"(%x,%d,%p,%p): empty stub!\n",
809 hwnd, idAni, lprcFrom, lprcTo );
810 return TRUE;
814 /**********************************************************************
815 * PAINTING_DrawStateJam
817 * Jams in the requested type in the dc
819 static BOOL32 PAINTING_DrawStateJam(HDC32 hdc, UINT32 opcode,
820 DRAWSTATEPROC32 func, LPARAM lp, WPARAM32 wp,
821 LPRECT32 rc, UINT32 dtflags,
822 BOOL32 unicode, BOOL32 _32bit)
824 HDC32 memdc;
825 HBITMAP32 hbmsave;
826 BOOL32 retval;
827 INT32 cx = rc->right - rc->left;
828 INT32 cy = rc->bottom - rc->top;
830 switch(opcode)
832 case DST_TEXT:
833 case DST_PREFIXTEXT:
834 if(unicode)
835 return DrawText32W(hdc, (LPWSTR)lp, (INT32)wp, rc, dtflags);
836 else if(_32bit)
837 return DrawText32A(hdc, (LPSTR)lp, (INT32)wp, rc, dtflags);
838 else
839 return DrawText32A(hdc, (LPSTR)PTR_SEG_TO_LIN(lp), (INT32)wp, rc, dtflags);
841 case DST_ICON:
842 return DrawIcon32(hdc, rc->left, rc->top, (HICON32)lp);
844 case DST_BITMAP:
845 memdc = CreateCompatibleDC32(hdc);
846 if(!memdc) return FALSE;
847 hbmsave = (HBITMAP32)SelectObject32(memdc, (HBITMAP32)lp);
848 if(!hbmsave)
850 DeleteDC32(memdc);
851 return FALSE;
853 retval = BitBlt32(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
854 SelectObject32(memdc, hbmsave);
855 DeleteDC32(memdc);
856 return retval;
858 case DST_COMPLEX:
859 if(func)
860 if(_32bit)
861 return func(hdc, lp, wp, cx, cy);
862 else
863 return (BOOL32)((DRAWSTATEPROC16)func)((HDC16)hdc, (LPARAM)lp, (WPARAM16)wp, (INT16)cx, (INT16)cy);
864 else
865 return FALSE;
867 return FALSE;
870 /**********************************************************************
871 * PAINTING_DrawState32()
873 static BOOL32 PAINTING_DrawState32(HDC32 hdc, HBRUSH32 hbr,
874 DRAWSTATEPROC32 func, LPARAM lp, WPARAM32 wp,
875 INT32 x, INT32 y, INT32 cx, INT32 cy,
876 UINT32 flags, BOOL32 unicode, BOOL32 _32bit)
878 HBITMAP32 hbm, hbmsave;
879 HFONT32 hfsave;
880 HBRUSH32 hbsave;
881 HDC32 memdc;
882 RECT32 rc;
883 UINT32 dtflags = DT_NOCLIP;
884 COLORREF fg, bg;
885 UINT32 opcode = flags & 0xf;
886 INT32 len = wp;
887 BOOL32 retval, tmp;
889 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
891 if(unicode)
892 len = lstrlen32W((LPWSTR)lp);
893 else if(_32bit)
894 len = lstrlen32A((LPSTR)lp);
895 else
896 len = lstrlen32A((LPSTR)PTR_SEG_TO_LIN(lp));
899 /* Find out what size the image has if not given by caller */
900 if(!cx || !cy)
902 SIZE32 s;
903 CURSORICONINFO *ici;
904 BITMAPOBJ *bmp;
906 switch(opcode)
908 case DST_TEXT:
909 case DST_PREFIXTEXT:
910 if(unicode)
911 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
912 else if(_32bit)
913 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
914 else
915 retval = GetTextExtentPoint32A(hdc, PTR_SEG_TO_LIN(lp), len, &s);
916 if(!retval) return FALSE;
917 break;
919 case DST_ICON:
920 ici = (CURSORICONINFO *)GlobalLock16((HGLOBAL16)lp);
921 if(!ici) return FALSE;
922 s.cx = ici->nWidth;
923 s.cy = ici->nHeight;
924 GlobalUnlock16((HGLOBAL16)lp);
925 break;
927 case DST_BITMAP:
928 bmp = (BITMAPOBJ *)GDI_GetObjPtr((HBITMAP16)lp, BITMAP_MAGIC);
929 if(!bmp) return FALSE;
930 s.cx = bmp->bitmap.bmWidth;
931 s.cy = bmp->bitmap.bmHeight;
932 break;
934 case DST_COMPLEX: /* cx and cy must be set in this mode */
935 return FALSE;
938 if(!cx) cx = s.cx;
939 if(!cy) cy = s.cy;
942 rc.left = x;
943 rc.top = y;
944 rc.right = x + cx;
945 rc.bottom = y + cy;
947 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
948 dtflags |= DT_RIGHT;
949 if(opcode == DST_TEXT)
950 dtflags |= DT_NOPREFIX;
952 /* For DSS_NORMAL we just jam in the image and return */
953 if((flags & 0x7ff0) == DSS_NORMAL)
955 return PAINTING_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
958 /* For all other states we need to convert the image to B/W in a local bitmap */
959 /* before it is displayed */
960 fg = SetTextColor32(hdc, RGB(0, 0, 0));
961 bg = SetBkColor32(hdc, RGB(255, 255, 255));
962 hbm = NULL; hbmsave = NULL; memdc = NULL; memdc = NULL; hbsave = NULL;
963 retval = FALSE; /* assume failure */
965 /* From here on we must use "goto cleanup" when something goes wrong */
966 hbm = CreateBitmap32(cx, cy, 1, 1, NULL);
967 if(!hbm) goto cleanup;
968 memdc = CreateCompatibleDC32(hdc);
969 if(!memdc) goto cleanup;
970 hbmsave = (HBITMAP32)SelectObject32(memdc, hbm);
971 if(!hbmsave) goto cleanup;
972 rc.left = rc.top = 0;
973 rc.right = cx;
974 rc.bottom = cy;
975 if(!FillRect32(memdc, &rc, (HBRUSH32)GetStockObject32(WHITE_BRUSH))) goto cleanup;
976 SetBkColor32(memdc, RGB(255, 255, 255));
977 SetTextColor32(memdc, RGB(0, 0, 0));
978 hfsave = (HFONT32)SelectObject32(memdc, GetCurrentObject(hdc, OBJ_FONT));
979 if(!hfsave && (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)) goto cleanup;
980 tmp = PAINTING_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
981 if(hfsave) SelectObject32(memdc, hfsave);
982 if(!tmp) goto cleanup;
984 /* These states cause the image to be dithered */
985 if(flags & (DSS_UNION|DSS_DISABLED))
987 hbsave = (HBRUSH32)SelectObject32(memdc, CACHE_GetPattern55AABrush());
988 if(!hbsave) goto cleanup;
989 tmp = PatBlt32(memdc, 0, 0, cx, cy, 0x00FA0089);
990 if(hbsave) SelectObject32(memdc, hbsave);
991 if(!tmp) goto cleanup;
994 hbsave = (HBRUSH32)SelectObject32(hdc, hbr ? hbr : GetStockObject32(WHITE_BRUSH));
995 if(!hbsave) goto cleanup;
997 if(!BitBlt32(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
999 /* DSS_DEFAULT makes the image boldface */
1000 if(flags & DSS_DEFAULT)
1002 if(!BitBlt32(hdc, x+1, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1005 retval = TRUE; /* We succeeded */
1007 cleanup:
1008 SetTextColor32(hdc, fg);
1009 SetBkColor32(hdc, bg);
1011 if(hbsave) SelectObject32(hdc, hbsave);
1012 if(hbmsave) SelectObject32(memdc, hbmsave);
1013 if(hbm) DeleteObject32(hbm);
1014 if(memdc) DeleteDC32(memdc);
1016 return retval;
1019 /**********************************************************************
1020 * DrawState32A() (USER32.162)
1022 BOOL32 WINAPI DrawState32A(HDC32 hdc, HBRUSH32 hbr,
1023 DRAWSTATEPROC32 func, LPARAM ldata, WPARAM32 wdata,
1024 INT32 x, INT32 y, INT32 cx, INT32 cy, UINT32 flags)
1026 return PAINTING_DrawState32(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE, TRUE);
1029 /**********************************************************************
1030 * DrawState32W() (USER32.163)
1032 BOOL32 WINAPI DrawState32W(HDC32 hdc, HBRUSH32 hbr,
1033 DRAWSTATEPROC32 func, LPARAM ldata, WPARAM32 wdata,
1034 INT32 x, INT32 y, INT32 cx, INT32 cy, UINT32 flags)
1036 return PAINTING_DrawState32(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE, TRUE);
1039 /**********************************************************************
1040 * DrawState16() (USER.449)
1042 BOOL16 WINAPI DrawState16(HDC16 hdc, HBRUSH16 hbr,
1043 DRAWSTATEPROC16 func, LPARAM ldata, WPARAM16 wdata,
1044 INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags)
1046 return PAINTING_DrawState32(hdc, hbr, (DRAWSTATEPROC32)func, ldata, wdata, x, y, cx, cy, flags, FALSE, FALSE);
1050 /******************************************************************************
1051 * PolyBezier16 [GDI.502]
1053 BOOL16 WINAPI PolyBezier16( HDC16 hDc, LPPOINT16 lppt, INT16 cPoints )
1055 FIXME(gdi, "(%x,%p,%d): stub\n",hDc,lppt,cPoints);
1056 return TRUE;
1059 /******************************************************************************
1060 * PolyBezier32 [GDI32.268]
1061 * Draws one or more Bezier curves
1063 * PARAMS
1064 * hDc [I] Handle to device context
1065 * lppt [I] Pointer to endpoints and control points
1066 * cPoints [I] Count of endpoints and control points
1068 * RETURNS STD
1070 BOOL32 WINAPI PolyBezier32( HDC32 hDc, LPPOINT32 lppt, DWORD cPoints )
1072 FIXME(gdi, "(%x,%p,%ld): stub\n",hDc,lppt,cPoints);
1073 return TRUE;