IExtractIcon had an extra c in a struct definition.
[wine/multimedia.git] / graphics / painting.c
blob0c7d3a90e4c8438ab65fed490ac8bd072a4a101b
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 )
247 DC * dc = DC_GetDCPtr( hdc );
249 return dc && dc->funcs->pRoundRect &&
250 dc->funcs->pRoundRect(dc,left,top,right,bottom,ell_width,ell_height);
254 /***********************************************************************
255 * FillRect16 (USER.81)
257 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
259 HBRUSH16 prevBrush;
261 /* coordinates are logical so we cannot fast-check 'rect',
262 * it will be done later in the PatBlt().
265 if (!(prevBrush = SelectObject16( hdc, hbrush ))) return 0;
266 PatBlt32( hdc, rect->left, rect->top,
267 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
268 SelectObject16( hdc, prevBrush );
269 return 1;
273 /***********************************************************************
274 * FillRect32 (USER32.197)
276 INT32 WINAPI FillRect32( HDC32 hdc, const RECT32 *rect, HBRUSH32 hbrush )
278 HBRUSH32 prevBrush;
280 if (!(prevBrush = SelectObject32( hdc, hbrush ))) return 0;
281 PatBlt32( hdc, rect->left, rect->top,
282 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
283 SelectObject32( hdc, prevBrush );
284 return 1;
288 /***********************************************************************
289 * InvertRect16 (USER.82)
291 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
293 PatBlt32( hdc, rect->left, rect->top,
294 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
298 /***********************************************************************
299 * InvertRect32 (USER32.330)
301 void WINAPI InvertRect32( HDC32 hdc, const RECT32 *rect )
303 PatBlt32( hdc, rect->left, rect->top,
304 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
308 /***********************************************************************
309 * FrameRect16 (USER.83)
311 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
313 HBRUSH16 prevBrush;
314 int left, top, right, bottom;
316 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
317 if (!dc) return FALSE;
319 left = XLPTODP( dc, rect->left );
320 top = YLPTODP( dc, rect->top );
321 right = XLPTODP( dc, rect->right );
322 bottom = YLPTODP( dc, rect->bottom );
324 if ( (right <= left) || (bottom <= top) ) return 0;
325 if (!(prevBrush = SelectObject16( hdc, hbrush ))) return 0;
327 if (DC_SetupGCForBrush( dc ))
329 PatBlt32( hdc, rect->left, rect->top, 1,
330 rect->bottom - rect->top, PATCOPY );
331 PatBlt32( hdc, rect->right - 1, rect->top, 1,
332 rect->bottom - rect->top, PATCOPY );
333 PatBlt32( hdc, rect->left, rect->top,
334 rect->right - rect->left, 1, PATCOPY );
335 PatBlt32( hdc, rect->left, rect->bottom - 1,
336 rect->right - rect->left, 1, PATCOPY );
338 SelectObject16( hdc, prevBrush );
339 return 1;
343 /***********************************************************************
344 * FrameRect32 (USER32.203)
346 INT32 WINAPI FrameRect32( HDC32 hdc, const RECT32 *rect, HBRUSH32 hbrush )
348 RECT16 rect16;
349 CONV_RECT32TO16( rect, &rect16 );
350 return FrameRect16( (HDC16)hdc, &rect16, (HBRUSH16)hbrush );
354 /***********************************************************************
355 * SetPixel16 (GDI.31)
357 COLORREF WINAPI SetPixel16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
359 return SetPixel32( hdc, x, y, color );
363 /***********************************************************************
364 * SetPixel32 (GDI32.327)
366 COLORREF WINAPI SetPixel32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
368 DC * dc = DC_GetDCPtr( hdc );
370 if (!dc || !dc->funcs->pSetPixel) return 0;
371 return dc->funcs->pSetPixel(dc,x,y,color);
374 /***********************************************************************
375 * SetPixelV32 (GDI32.329)
377 BOOL32 WINAPI SetPixelV32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
379 DC * dc = DC_GetDCPtr( hdc );
381 if (!dc || !dc->funcs->pSetPixel) return FALSE;
382 dc->funcs->pSetPixel(dc,x,y,color);
383 return TRUE;
386 /***********************************************************************
387 * GetPixel16 (GDI.83)
389 COLORREF WINAPI GetPixel16( HDC16 hdc, INT16 x, INT16 y )
391 return GetPixel32( hdc, x, y );
395 /***********************************************************************
396 * GetPixel32 (GDI32.211)
398 COLORREF WINAPI GetPixel32( HDC32 hdc, INT32 x, INT32 y )
400 DC * dc = DC_GetDCPtr( hdc );
402 if (!dc) return 0;
403 #ifdef SOLITAIRE_SPEED_HACK
404 return 0;
405 #endif
407 /* FIXME: should this be in the graphics driver? */
408 if (!PtVisible32( hdc, x, y )) return 0;
409 if (!dc || !dc->funcs->pGetPixel) return 0;
410 return dc->funcs->pGetPixel(dc,x,y);
414 /******************************************************************************
415 * ChoosePixelFormat [GDI32.13]
416 * Matches a pixel format to given format
418 * PARAMS
419 * hdc [I] Device context to search for best pixel match
420 * ppfd [I] Pixel format for which a match is sought
422 * RETURNS
423 * Success: Pixel format index closest to given format
424 * Failure: 0
426 INT32 WINAPI ChoosePixelFormat( HDC32 hdc, PIXELFORMATDESCRIPTOR *ppfd )
428 FIXME(gdi, "(%d,%p): stub\n",hdc,ppfd);
429 ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
430 ppfd->nVersion = 1;
431 return 1;
435 /******************************************************************************
436 * SetPixelFormat [GDI32.328]
437 * Sets pixel format of device context
439 * PARAMS
440 * hdc [I] Device context to search for best pixel match
441 * iPixelFormat [I] Pixel format index
442 * ppfd [I] Pixel format for which a match is sought
444 * RETURNS STD
446 BOOL32 WINAPI SetPixelFormat( HDC32 hdc, int iPixelFormat,
447 PIXELFORMATDESCRIPTOR * ppfd)
449 FIXME(gdi, "(%d,%d,%p): stub\n",hdc,iPixelFormat,ppfd);
450 return TRUE;
454 /******************************************************************************
455 * GetPixelFormat [GDI32.212]
456 * Gets index of pixel format of DC
458 * PARAMETERS
459 * hdc [I] Device context whose pixel format index is sought
461 * RETURNS
462 * Success: Currently selected pixel format
463 * Failure: 0
465 int WINAPI GetPixelFormat( HDC32 hdc )
467 FIXME(gdi, "(%d): stub\n",hdc);
468 return 1;
472 /******************************************************************************
473 * DescribePixelFormat [GDI32.71]
474 * Gets info about pixel format from DC
476 * PARAMS
477 * hdc [I] Device context
478 * iPixelFormat [I] Pixel format selector
479 * nBytes [I] Size of buffer
480 * ppfd [O] Pointer to structure to receive pixel format data
482 * RETURNS
483 * Success: Maximum pixel format index of the device context
484 * Failure: 0
486 int WINAPI DescribePixelFormat( HDC32 hdc, int iPixelFormat, UINT32 nBytes,
487 LPPIXELFORMATDESCRIPTOR ppfd )
489 FIXME(gdi, "(%d,%d,%d,%p): stub\n",hdc,iPixelFormat,nBytes,ppfd);
490 ppfd->nSize = nBytes;
491 ppfd->nVersion = 1;
492 return 3;
496 /******************************************************************************
497 * SwapBuffers [GDI32.354]
498 * Exchanges front and back buffers of window
500 * PARAMS
501 * hdc [I] Device context whose buffers get swapped
503 * RETURNS STD
505 BOOL32 WINAPI SwapBuffers( HDC32 hdc )
507 FIXME(gdi, "(%d): stub\n",hdc);
508 return TRUE;
512 /***********************************************************************
513 * PaintRgn16 (GDI.43)
515 BOOL16 WINAPI PaintRgn16( HDC16 hdc, HRGN16 hrgn )
517 return PaintRgn32( hdc, hrgn );
521 /***********************************************************************
522 * PaintRgn32 (GDI32.259)
524 BOOL32 WINAPI PaintRgn32( HDC32 hdc, HRGN32 hrgn )
526 DC * dc = DC_GetDCPtr( hdc );
528 return dc && dc->funcs->pPaintRgn &&
529 dc->funcs->pPaintRgn(dc,hrgn);
533 /***********************************************************************
534 * FillRgn16 (GDI.40)
536 BOOL16 WINAPI FillRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush )
538 return FillRgn32( hdc, hrgn, hbrush );
542 /***********************************************************************
543 * FillRgn32 (GDI32.101)
545 BOOL32 WINAPI FillRgn32( HDC32 hdc, HRGN32 hrgn, HBRUSH32 hbrush )
547 BOOL32 retval;
548 HBRUSH32 prevBrush = SelectObject32( hdc, hbrush );
549 if (!prevBrush) return FALSE;
550 retval = PaintRgn32( hdc, hrgn );
551 SelectObject32( hdc, prevBrush );
552 return retval;
556 /***********************************************************************
557 * FrameRgn16 (GDI.41)
559 BOOL16 WINAPI FrameRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush,
560 INT16 nWidth, INT16 nHeight )
562 return FrameRgn32( hdc, hrgn, hbrush, nWidth, nHeight );
566 /***********************************************************************
567 * FrameRgn32 (GDI32.105)
569 BOOL32 WINAPI FrameRgn32( HDC32 hdc, HRGN32 hrgn, HBRUSH32 hbrush,
570 INT32 nWidth, INT32 nHeight )
572 HRGN32 tmp = CreateRectRgn32( 0, 0, 0, 0 );
573 if(!REGION_FrameRgn( tmp, hrgn, nWidth, nHeight )) return FALSE;
574 FillRgn32( hdc, tmp, hbrush );
575 DeleteObject32( tmp );
576 return TRUE;
580 /***********************************************************************
581 * InvertRgn16 (GDI.42)
583 BOOL16 WINAPI InvertRgn16( HDC16 hdc, HRGN16 hrgn )
585 return InvertRgn32( hdc, hrgn );
589 /***********************************************************************
590 * InvertRgn32 (GDI32.246)
592 BOOL32 WINAPI InvertRgn32( HDC32 hdc, HRGN32 hrgn )
594 HBRUSH32 prevBrush = SelectObject32( hdc, GetStockObject32(BLACK_BRUSH) );
595 INT32 prevROP = SetROP232( hdc, R2_NOT );
596 BOOL32 retval = PaintRgn32( hdc, hrgn );
597 SelectObject32( hdc, prevBrush );
598 SetROP232( hdc, prevROP );
599 return retval;
603 /***********************************************************************
604 * DrawFocusRect16 (USER.466)
606 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
608 RECT32 rect32;
609 CONV_RECT16TO32( rc, &rect32 );
610 DrawFocusRect32( hdc, &rect32 );
614 /***********************************************************************
615 * DrawFocusRect32 (USER32.156)
617 * FIXME: PatBlt(PATINVERT) with background brush.
619 void WINAPI DrawFocusRect32( HDC32 hdc, const RECT32* rc )
621 HPEN32 hOldPen, hnewPen;
622 INT32 oldDrawMode, oldBkMode;
623 INT32 left, top, right, bottom;
625 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
626 if (!dc) return;
628 left = XLPTODP( dc, rc->left );
629 top = YLPTODP( dc, rc->top );
630 right = XLPTODP( dc, rc->right );
631 bottom = YLPTODP( dc, rc->bottom );
633 if(left == right || top == bottom)
634 return;
636 hnewPen = CreatePen32(PS_DOT, 1, GetSysColor32(COLOR_WINDOWTEXT) );
637 hOldPen = SelectObject32( hdc, hnewPen );
638 oldDrawMode = SetROP232(hdc, R2_XORPEN);
639 oldBkMode = SetBkMode32(hdc, TRANSPARENT);
641 /* Hack: make sure the XORPEN operation has an effect */
642 dc->u.x.pen.pixel = (1 << screenDepth) - 1;
644 if (DC_SetupGCForPen( dc ))
645 TSXDrawRectangle( display, dc->u.x.drawable, dc->u.x.gc,
646 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
647 right-left-1, bottom-top-1 );
649 SetBkMode32(hdc, oldBkMode);
650 SetROP232(hdc, oldDrawMode);
651 SelectObject32(hdc, hOldPen);
652 DeleteObject32(hnewPen);
656 /**********************************************************************
657 * Polyline16 (GDI.37)
659 BOOL16 WINAPI Polyline16( HDC16 hdc, LPPOINT16 pt, INT16 count )
661 register int i;
662 BOOL16 ret;
663 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
664 count*sizeof(POINT32) );
666 if (!pt32) return FALSE;
667 for (i=count;i--;) CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
668 ret = Polyline32(hdc,pt32,count);
669 HeapFree( GetProcessHeap(), 0, pt32 );
670 return ret;
674 /**********************************************************************
675 * Polyline32 (GDI32.276)
677 BOOL32 WINAPI Polyline32( HDC32 hdc, const LPPOINT32 pt, INT32 count )
679 DC * dc = DC_GetDCPtr( hdc );
681 return dc && dc->funcs->pPolyline &&
682 dc->funcs->pPolyline(dc,pt,count);
686 /**********************************************************************
687 * Polygon16 (GDI.36)
689 BOOL16 WINAPI Polygon16( HDC16 hdc, LPPOINT16 pt, INT16 count )
691 register int i;
692 BOOL32 ret;
693 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
694 count*sizeof(POINT32) );
696 if (!pt32) return FALSE;
697 for (i=count;i--;) CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
698 ret = Polygon32(hdc,pt32,count);
699 HeapFree( GetProcessHeap(), 0, pt32 );
700 return ret;
704 /**********************************************************************
705 * Polygon32 (GDI32.275)
707 BOOL32 WINAPI Polygon32( HDC32 hdc, LPPOINT32 pt, INT32 count )
709 DC * dc = DC_GetDCPtr( hdc );
711 return dc && dc->funcs->pPolygon &&
712 dc->funcs->pPolygon(dc,pt,count);
716 /**********************************************************************
717 * PolyPolygon16 (GDI.450)
719 BOOL16 WINAPI PolyPolygon16( HDC16 hdc, LPPOINT16 pt, LPINT16 counts,
720 UINT16 polygons )
722 int i,nrpts;
723 LPPOINT32 pt32;
724 LPINT32 counts32;
725 BOOL16 ret;
727 nrpts=0;
728 for (i=polygons;i--;)
729 nrpts+=counts[i];
730 pt32 = (LPPOINT32)HEAP_xalloc( GetProcessHeap(), 0, sizeof(POINT32)*nrpts);
731 for (i=nrpts;i--;)
732 CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
733 counts32 = (LPINT32)HEAP_xalloc( GetProcessHeap(), 0,
734 polygons*sizeof(INT32) );
735 for (i=polygons;i--;) counts32[i]=counts[i];
737 ret = PolyPolygon32(hdc,pt32,counts32,polygons);
738 HeapFree( GetProcessHeap(), 0, counts32 );
739 HeapFree( GetProcessHeap(), 0, pt32 );
740 return ret;
743 /**********************************************************************
744 * PolyPolygon32 (GDI.450)
746 BOOL32 WINAPI PolyPolygon32( HDC32 hdc, LPPOINT32 pt, LPINT32 counts,
747 UINT32 polygons )
749 DC * dc = DC_GetDCPtr( hdc );
751 return dc && dc->funcs->pPolyPolygon &&
752 dc->funcs->pPolyPolygon(dc,pt,counts,polygons);
755 /**********************************************************************
756 * PolyPolyline32 (GDI32.272)
758 BOOL32 WINAPI PolyPolyline32( HDC32 hdc, LPPOINT32 pt, LPDWORD counts,
759 DWORD polylines )
761 DC * dc = DC_GetDCPtr( hdc );
763 return dc && dc->funcs->pPolyPolyline &&
764 dc->funcs->pPolyPolyline(dc,pt,counts,polylines);
767 /**********************************************************************
768 * ExtFloodFill16 (GDI.372)
770 BOOL16 WINAPI ExtFloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color,
771 UINT16 fillType )
773 return ExtFloodFill32( hdc, x, y, color, fillType );
777 /**********************************************************************
778 * ExtFloodFill32 (GDI32.96)
780 BOOL32 WINAPI ExtFloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color,
781 UINT32 fillType )
783 DC *dc = DC_GetDCPtr( hdc );
785 return dc && dc->funcs->pExtFloodFill &&
786 dc->funcs->pExtFloodFill(dc,x,y,color,fillType);
790 /**********************************************************************
791 * FloodFill16 (GDI.25)
793 BOOL16 WINAPI FloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
795 return ExtFloodFill32( hdc, x, y, color, FLOODFILLBORDER );
799 /**********************************************************************
800 * FloodFill32 (GDI32.104)
802 BOOL32 WINAPI FloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
804 return ExtFloodFill32( hdc, x, y, color, FLOODFILLBORDER );
808 /**********************************************************************
809 * DrawAnimatedRects32 (USER32.153)
811 BOOL32 WINAPI DrawAnimatedRects32( HWND32 hwnd, int idAni,
812 const LPRECT32 lprcFrom,
813 const LPRECT32 lprcTo )
815 FIXME(gdi,"(0x%x,%d,%p,%p): stub\n",hwnd,idAni,lprcFrom,lprcTo);
816 return TRUE;
820 /**********************************************************************
821 * PAINTING_DrawStateJam
823 * Jams in the requested type in the dc
825 static BOOL32 PAINTING_DrawStateJam(HDC32 hdc, UINT32 opcode,
826 DRAWSTATEPROC32 func, LPARAM lp, WPARAM32 wp,
827 LPRECT32 rc, UINT32 dtflags,
828 BOOL32 unicode, BOOL32 _32bit)
830 HDC32 memdc;
831 HBITMAP32 hbmsave;
832 BOOL32 retval;
833 INT32 cx = rc->right - rc->left;
834 INT32 cy = rc->bottom - rc->top;
836 switch(opcode)
838 case DST_TEXT:
839 case DST_PREFIXTEXT:
840 if(unicode)
841 return DrawText32W(hdc, (LPWSTR)lp, (INT32)wp, rc, dtflags);
842 else if(_32bit)
843 return DrawText32A(hdc, (LPSTR)lp, (INT32)wp, rc, dtflags);
844 else
845 return DrawText32A(hdc, (LPSTR)PTR_SEG_TO_LIN(lp), (INT32)wp, rc, dtflags);
847 case DST_ICON:
848 return DrawIcon32(hdc, rc->left, rc->top, (HICON32)lp);
850 case DST_BITMAP:
851 memdc = CreateCompatibleDC32(hdc);
852 if(!memdc) return FALSE;
853 hbmsave = (HBITMAP32)SelectObject32(memdc, (HBITMAP32)lp);
854 if(!hbmsave)
856 DeleteDC32(memdc);
857 return FALSE;
859 retval = BitBlt32(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
860 SelectObject32(memdc, hbmsave);
861 DeleteDC32(memdc);
862 return retval;
864 case DST_COMPLEX:
865 if(func)
866 if(_32bit)
867 return func(hdc, lp, wp, cx, cy);
868 else
869 return (BOOL32)((DRAWSTATEPROC16)func)((HDC16)hdc, (LPARAM)lp, (WPARAM16)wp, (INT16)cx, (INT16)cy);
870 else
871 return FALSE;
873 return FALSE;
876 /**********************************************************************
877 * PAINTING_DrawState32()
879 static BOOL32 PAINTING_DrawState32(HDC32 hdc, HBRUSH32 hbr,
880 DRAWSTATEPROC32 func, LPARAM lp, WPARAM32 wp,
881 INT32 x, INT32 y, INT32 cx, INT32 cy,
882 UINT32 flags, BOOL32 unicode, BOOL32 _32bit)
884 HBITMAP32 hbm, hbmsave;
885 HFONT32 hfsave;
886 HBRUSH32 hbsave;
887 HDC32 memdc;
888 RECT32 rc;
889 UINT32 dtflags = DT_NOCLIP;
890 COLORREF fg, bg;
891 UINT32 opcode = flags & 0xf;
892 INT32 len = wp;
893 BOOL32 retval, tmp;
895 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
897 if(unicode)
898 len = lstrlen32W((LPWSTR)lp);
899 else if(_32bit)
900 len = lstrlen32A((LPSTR)lp);
901 else
902 len = lstrlen32A((LPSTR)PTR_SEG_TO_LIN(lp));
905 /* Find out what size the image has if not given by caller */
906 if(!cx || !cy)
908 SIZE32 s;
909 CURSORICONINFO *ici;
910 BITMAPOBJ *bmp;
912 switch(opcode)
914 case DST_TEXT:
915 case DST_PREFIXTEXT:
916 if(unicode)
917 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
918 else if(_32bit)
919 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
920 else
921 retval = GetTextExtentPoint32A(hdc, PTR_SEG_TO_LIN(lp), len, &s);
922 if(!retval) return FALSE;
923 break;
925 case DST_ICON:
926 ici = (CURSORICONINFO *)GlobalLock16((HGLOBAL16)lp);
927 if(!ici) return FALSE;
928 s.cx = ici->nWidth;
929 s.cy = ici->nHeight;
930 GlobalUnlock16((HGLOBAL16)lp);
931 break;
933 case DST_BITMAP:
934 bmp = (BITMAPOBJ *)GDI_GetObjPtr((HBITMAP16)lp, BITMAP_MAGIC);
935 if(!bmp) return FALSE;
936 s.cx = bmp->bitmap.bmWidth;
937 s.cy = bmp->bitmap.bmHeight;
938 break;
940 case DST_COMPLEX: /* cx and cy must be set in this mode */
941 return FALSE;
944 if(!cx) cx = s.cx;
945 if(!cy) cy = s.cy;
948 rc.left = x;
949 rc.top = y;
950 rc.right = x + cx;
951 rc.bottom = y + cy;
953 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
954 dtflags |= DT_RIGHT;
955 if(opcode == DST_TEXT)
956 dtflags |= DT_NOPREFIX;
958 /* For DSS_NORMAL we just jam in the image and return */
959 if((flags & 0x7ff0) == DSS_NORMAL)
961 return PAINTING_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
964 /* For all other states we need to convert the image to B/W in a local bitmap */
965 /* before it is displayed */
966 fg = SetTextColor32(hdc, RGB(0, 0, 0));
967 bg = SetBkColor32(hdc, RGB(255, 255, 255));
968 hbm = (HBITMAP32)NULL; hbmsave = (HBITMAP32)NULL;
969 memdc = (HDC32)NULL; hbsave = (HBRUSH32)NULL;
970 retval = FALSE; /* assume failure */
972 /* From here on we must use "goto cleanup" when something goes wrong */
973 hbm = CreateBitmap32(cx, cy, 1, 1, NULL);
974 if(!hbm) goto cleanup;
975 memdc = CreateCompatibleDC32(hdc);
976 if(!memdc) goto cleanup;
977 hbmsave = (HBITMAP32)SelectObject32(memdc, hbm);
978 if(!hbmsave) goto cleanup;
979 rc.left = rc.top = 0;
980 rc.right = cx;
981 rc.bottom = cy;
982 if(!FillRect32(memdc, &rc, (HBRUSH32)GetStockObject32(WHITE_BRUSH))) goto cleanup;
983 SetBkColor32(memdc, RGB(255, 255, 255));
984 SetTextColor32(memdc, RGB(0, 0, 0));
985 hfsave = (HFONT32)SelectObject32(memdc, GetCurrentObject(hdc, OBJ_FONT));
986 if(!hfsave && (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)) goto cleanup;
987 tmp = PAINTING_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
988 if(hfsave) SelectObject32(memdc, hfsave);
989 if(!tmp) goto cleanup;
991 /* These states cause the image to be dithered */
992 if(flags & (DSS_UNION|DSS_DISABLED))
994 hbsave = (HBRUSH32)SelectObject32(memdc, CACHE_GetPattern55AABrush());
995 if(!hbsave) goto cleanup;
996 tmp = PatBlt32(memdc, 0, 0, cx, cy, 0x00FA0089);
997 if(hbsave) SelectObject32(memdc, hbsave);
998 if(!tmp) goto cleanup;
1001 hbsave = (HBRUSH32)SelectObject32(hdc, hbr ? hbr : GetStockObject32(WHITE_BRUSH));
1002 if(!hbsave) goto cleanup;
1004 if(!BitBlt32(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1006 /* DSS_DEFAULT makes the image boldface */
1007 if(flags & DSS_DEFAULT)
1009 if(!BitBlt32(hdc, x+1, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1012 retval = TRUE; /* We succeeded */
1014 cleanup:
1015 SetTextColor32(hdc, fg);
1016 SetBkColor32(hdc, bg);
1018 if(hbsave) SelectObject32(hdc, hbsave);
1019 if(hbmsave) SelectObject32(memdc, hbmsave);
1020 if(hbm) DeleteObject32(hbm);
1021 if(memdc) DeleteDC32(memdc);
1023 return retval;
1026 /**********************************************************************
1027 * DrawState32A() (USER32.162)
1029 BOOL32 WINAPI DrawState32A(HDC32 hdc, HBRUSH32 hbr,
1030 DRAWSTATEPROC32 func, LPARAM ldata, WPARAM32 wdata,
1031 INT32 x, INT32 y, INT32 cx, INT32 cy, UINT32 flags)
1033 return PAINTING_DrawState32(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE, TRUE);
1036 /**********************************************************************
1037 * DrawState32W() (USER32.163)
1039 BOOL32 WINAPI DrawState32W(HDC32 hdc, HBRUSH32 hbr,
1040 DRAWSTATEPROC32 func, LPARAM ldata, WPARAM32 wdata,
1041 INT32 x, INT32 y, INT32 cx, INT32 cy, UINT32 flags)
1043 return PAINTING_DrawState32(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE, TRUE);
1046 /**********************************************************************
1047 * DrawState16() (USER.449)
1049 BOOL16 WINAPI DrawState16(HDC16 hdc, HBRUSH16 hbr,
1050 DRAWSTATEPROC16 func, LPARAM ldata, WPARAM16 wdata,
1051 INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags)
1053 return PAINTING_DrawState32(hdc, hbr, (DRAWSTATEPROC32)func, ldata, wdata, x, y, cx, cy, flags, FALSE, FALSE);
1057 /******************************************************************************
1058 * PolyBezier16 [GDI.502]
1060 BOOL16 WINAPI PolyBezier16( HDC16 hDc, LPPOINT16 lppt, INT16 cPoints )
1062 int i;
1063 BOOL16 ret;
1064 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
1065 cPoints*sizeof(POINT32) );
1066 if(!pt32) return FALSE;
1067 for (i=cPoints;i--;) CONV_POINT16TO32(&(lppt[i]),&(pt32[i]));
1068 ret= PolyBezier32(hDc, pt32, cPoints);
1069 HeapFree( GetProcessHeap(), 0, pt32 );
1070 return ret;
1073 /******************************************************************************
1074 * PolyBezierTo16 [GDI.503]
1076 BOOL16 WINAPI PolyBezierTo16( HDC16 hDc, LPPOINT16 lppt, INT16 cPoints )
1078 int i;
1079 BOOL16 ret;
1080 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
1081 cPoints*sizeof(POINT32) );
1082 if(!pt32) return FALSE;
1083 for (i=cPoints;i--;) CONV_POINT16TO32(&(lppt[i]),&(pt32[i]));
1084 ret= PolyBezierTo32(hDc, pt32, cPoints);
1085 HeapFree( GetProcessHeap(), 0, pt32 );
1086 return ret;
1089 /******************************************************************************
1090 * PolyBezier32 [GDI32.268]
1091 * Draws one or more Bezier curves
1093 * PARAMS
1094 * hDc [I] Handle to device context
1095 * lppt [I] Pointer to endpoints and control points
1096 * cPoints [I] Count of endpoints and control points
1098 * RETURNS STD
1100 BOOL32 WINAPI PolyBezier32( HDC32 hdc, LPPOINT32 lppt, DWORD cPoints )
1102 DC * dc = DC_GetDCPtr( hdc );
1103 if(!dc) return FALSE;
1104 if(dc && PATH_IsPathOpen(dc->w.path))
1105 FIXME(gdi, "PATH_PolyBezier is not implemented!\n");
1106 /* if(!PATH_PolyBezier(hdc, x, y))
1107 return FALSE; */
1108 return dc->funcs->pPolyBezier&&
1109 dc->funcs->pPolyBezier(dc, lppt[0], lppt+1, cPoints-1);
1112 /******************************************************************************
1113 * PolyBezierTo32 [GDI32.269]
1114 * Draws one or more Bezier curves
1116 * PARAMS
1117 * hDc [I] Handle to device context
1118 * lppt [I] Pointer to endpoints and control points
1119 * cPoints [I] Count of endpoints and control points
1121 * RETURNS STD
1123 BOOL32 WINAPI PolyBezierTo32( HDC32 hdc, LPPOINT32 lppt, DWORD cPoints )
1125 DC * dc = DC_GetDCPtr( hdc );
1126 POINT32 pt;
1127 BOOL32 ret;
1128 if(!dc) return FALSE;
1129 pt.x=dc->w.CursPosX;
1130 pt.y=dc->w.CursPosY;
1131 if(dc && PATH_IsPathOpen(dc->w.path))
1132 FIXME(gdi, "PATH_PolyBezierTo is not implemented!\n");
1133 /* if(!PATH_PolyBezier(hdc, x, y))
1134 return FALSE; */
1135 ret= dc->funcs->pPolyBezier &&
1136 dc->funcs->pPolyBezier(dc, pt, lppt, cPoints);
1137 if( dc->funcs->pMoveToEx)
1138 dc->funcs->pMoveToEx(dc,lppt[cPoints].x,lppt[cPoints].y,&pt);
1139 return ret;