Added WM_GETDLGCODE handling in (Un)MapMsg32Ato16.
[wine.git] / graphics / painting.c
blob48c13124e0e82eec146fb34daed18b8874458eab
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, const PIXELFORMATDESCRIPTOR* ppfd )
428 FIXME(gdi, "(%d,%p): stub\n",hdc,ppfd);
429 return 1;
433 /******************************************************************************
434 * SetPixelFormat [GDI32.328]
435 * Sets pixel format of device context
437 * PARAMS
438 * hdc [I] Device context to search for best pixel match
439 * iPixelFormat [I] Pixel format index
440 * ppfd [I] Pixel format for which a match is sought
442 * RETURNS STD
444 BOOL32 WINAPI SetPixelFormat( HDC32 hdc, int iPixelFormat,
445 const PIXELFORMATDESCRIPTOR* ppfd)
447 FIXME(gdi, "(%d,%d,%p): stub\n",hdc,iPixelFormat,ppfd);
448 return TRUE;
452 /******************************************************************************
453 * GetPixelFormat [GDI32.212]
454 * Gets index of pixel format of DC
456 * PARAMETERS
457 * hdc [I] Device context whose pixel format index is sought
459 * RETURNS
460 * Success: Currently selected pixel format
461 * Failure: 0
463 int WINAPI GetPixelFormat( HDC32 hdc )
465 FIXME(gdi, "(%d): stub\n",hdc);
466 return 1;
470 /******************************************************************************
471 * DescribePixelFormat [GDI32.71]
472 * Gets info about pixel format from DC
474 * PARAMS
475 * hdc [I] Device context
476 * iPixelFormat [I] Pixel format selector
477 * nBytes [I] Size of buffer
478 * ppfd [O] Pointer to structure to receive pixel format data
480 * RETURNS
481 * Success: Maximum pixel format index of the device context
482 * Failure: 0
484 int WINAPI DescribePixelFormat( HDC32 hdc, int iPixelFormat, UINT32 nBytes,
485 LPPIXELFORMATDESCRIPTOR ppfd )
487 FIXME(gdi, "(%d,%d,%d,%p): stub\n",hdc,iPixelFormat,nBytes,ppfd);
488 ppfd->nSize = nBytes;
489 ppfd->nVersion = 1;
490 return 3;
494 /******************************************************************************
495 * SwapBuffers [GDI32.354]
496 * Exchanges front and back buffers of window
498 * PARAMS
499 * hdc [I] Device context whose buffers get swapped
501 * RETURNS STD
503 BOOL32 WINAPI SwapBuffers( HDC32 hdc )
505 FIXME(gdi, "(%d): stub\n",hdc);
506 return TRUE;
510 /***********************************************************************
511 * PaintRgn16 (GDI.43)
513 BOOL16 WINAPI PaintRgn16( HDC16 hdc, HRGN16 hrgn )
515 return PaintRgn32( hdc, hrgn );
519 /***********************************************************************
520 * PaintRgn32 (GDI32.259)
522 BOOL32 WINAPI PaintRgn32( HDC32 hdc, HRGN32 hrgn )
524 DC * dc = DC_GetDCPtr( hdc );
526 return dc && dc->funcs->pPaintRgn &&
527 dc->funcs->pPaintRgn(dc,hrgn);
531 /***********************************************************************
532 * FillRgn16 (GDI.40)
534 BOOL16 WINAPI FillRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush )
536 return FillRgn32( hdc, hrgn, hbrush );
540 /***********************************************************************
541 * FillRgn32 (GDI32.101)
543 BOOL32 WINAPI FillRgn32( HDC32 hdc, HRGN32 hrgn, HBRUSH32 hbrush )
545 BOOL32 retval;
546 HBRUSH32 prevBrush = SelectObject32( hdc, hbrush );
547 if (!prevBrush) return FALSE;
548 retval = PaintRgn32( hdc, hrgn );
549 SelectObject32( hdc, prevBrush );
550 return retval;
554 /***********************************************************************
555 * FrameRgn16 (GDI.41)
557 BOOL16 WINAPI FrameRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush,
558 INT16 nWidth, INT16 nHeight )
560 return FrameRgn32( hdc, hrgn, hbrush, nWidth, nHeight );
564 /***********************************************************************
565 * FrameRgn32 (GDI32.105)
567 BOOL32 WINAPI FrameRgn32( HDC32 hdc, HRGN32 hrgn, HBRUSH32 hbrush,
568 INT32 nWidth, INT32 nHeight )
570 HRGN32 tmp = CreateRectRgn32( 0, 0, 0, 0 );
571 if(!REGION_FrameRgn( tmp, hrgn, nWidth, nHeight )) return FALSE;
572 FillRgn32( hdc, tmp, hbrush );
573 DeleteObject32( tmp );
574 return TRUE;
578 /***********************************************************************
579 * InvertRgn16 (GDI.42)
581 BOOL16 WINAPI InvertRgn16( HDC16 hdc, HRGN16 hrgn )
583 return InvertRgn32( hdc, hrgn );
587 /***********************************************************************
588 * InvertRgn32 (GDI32.246)
590 BOOL32 WINAPI InvertRgn32( HDC32 hdc, HRGN32 hrgn )
592 HBRUSH32 prevBrush = SelectObject32( hdc, GetStockObject32(BLACK_BRUSH) );
593 INT32 prevROP = SetROP232( hdc, R2_NOT );
594 BOOL32 retval = PaintRgn32( hdc, hrgn );
595 SelectObject32( hdc, prevBrush );
596 SetROP232( hdc, prevROP );
597 return retval;
601 /***********************************************************************
602 * DrawFocusRect16 (USER.466)
604 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
606 RECT32 rect32;
607 CONV_RECT16TO32( rc, &rect32 );
608 DrawFocusRect32( hdc, &rect32 );
612 /***********************************************************************
613 * DrawFocusRect32 (USER32.156)
615 * FIXME: PatBlt(PATINVERT) with background brush.
617 void WINAPI DrawFocusRect32( HDC32 hdc, const RECT32* rc )
619 HPEN32 hOldPen, hnewPen;
620 INT32 oldDrawMode, oldBkMode;
621 INT32 left, top, right, bottom;
623 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
624 if (!dc) return;
626 left = XLPTODP( dc, rc->left );
627 top = YLPTODP( dc, rc->top );
628 right = XLPTODP( dc, rc->right );
629 bottom = YLPTODP( dc, rc->bottom );
631 if(left == right || top == bottom)
632 return;
634 hnewPen = CreatePen32(PS_DOT, 1, GetSysColor32(COLOR_WINDOWTEXT) );
635 hOldPen = SelectObject32( hdc, hnewPen );
636 oldDrawMode = SetROP232(hdc, R2_XORPEN);
637 oldBkMode = SetBkMode32(hdc, TRANSPARENT);
639 /* Hack: make sure the XORPEN operation has an effect */
640 dc->u.x.pen.pixel = (1 << screenDepth) - 1;
642 if (DC_SetupGCForPen( dc ))
643 TSXDrawRectangle( display, dc->u.x.drawable, dc->u.x.gc,
644 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
645 right-left-1, bottom-top-1 );
647 SetBkMode32(hdc, oldBkMode);
648 SetROP232(hdc, oldDrawMode);
649 SelectObject32(hdc, hOldPen);
650 DeleteObject32(hnewPen);
654 /**********************************************************************
655 * Polyline16 (GDI.37)
657 BOOL16 WINAPI Polyline16( HDC16 hdc, const POINT16* pt, INT16 count )
659 register int i;
660 BOOL16 ret;
661 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
662 count*sizeof(POINT32) );
664 if (!pt32) return FALSE;
665 for (i=count;i--;) CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
666 ret = Polyline32(hdc,pt32,count);
667 HeapFree( GetProcessHeap(), 0, pt32 );
668 return ret;
672 /**********************************************************************
673 * Polyline32 (GDI32.276)
675 BOOL32 WINAPI Polyline32( HDC32 hdc, const POINT32* pt, INT32 count )
677 DC * dc = DC_GetDCPtr( hdc );
679 return dc && dc->funcs->pPolyline &&
680 dc->funcs->pPolyline(dc,pt,count);
684 /**********************************************************************
685 * Polygon16 (GDI.36)
687 BOOL16 WINAPI Polygon16( HDC16 hdc, const POINT16* pt, INT16 count )
689 register int i;
690 BOOL32 ret;
691 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
692 count*sizeof(POINT32) );
694 if (!pt32) return FALSE;
695 for (i=count;i--;) CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
696 ret = Polygon32(hdc,pt32,count);
697 HeapFree( GetProcessHeap(), 0, pt32 );
698 return ret;
702 /**********************************************************************
703 * Polygon32 (GDI32.275)
705 BOOL32 WINAPI Polygon32( HDC32 hdc, const POINT32* pt, INT32 count )
707 DC * dc = DC_GetDCPtr( hdc );
709 return dc && dc->funcs->pPolygon &&
710 dc->funcs->pPolygon(dc,pt,count);
714 /**********************************************************************
715 * PolyPolygon16 (GDI.450)
717 BOOL16 WINAPI PolyPolygon16( HDC16 hdc, const POINT16* pt, const INT16* counts,
718 UINT16 polygons )
720 int i,nrpts;
721 LPPOINT32 pt32;
722 LPINT32 counts32;
723 BOOL16 ret;
725 nrpts=0;
726 for (i=polygons;i--;)
727 nrpts+=counts[i];
728 pt32 = (LPPOINT32)HEAP_xalloc( GetProcessHeap(), 0, sizeof(POINT32)*nrpts);
729 for (i=nrpts;i--;)
730 CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
731 counts32 = (LPINT32)HEAP_xalloc( GetProcessHeap(), 0,
732 polygons*sizeof(INT32) );
733 for (i=polygons;i--;) counts32[i]=counts[i];
735 ret = PolyPolygon32(hdc,pt32,counts32,polygons);
736 HeapFree( GetProcessHeap(), 0, counts32 );
737 HeapFree( GetProcessHeap(), 0, pt32 );
738 return ret;
741 /**********************************************************************
742 * PolyPolygon32 (GDI.450)
744 BOOL32 WINAPI PolyPolygon32( HDC32 hdc, const POINT32* pt, const INT32* counts,
745 UINT32 polygons )
747 DC * dc = DC_GetDCPtr( hdc );
749 return dc && dc->funcs->pPolyPolygon &&
750 dc->funcs->pPolyPolygon(dc,pt,counts,polygons);
753 /**********************************************************************
754 * PolyPolyline32 (GDI32.272)
756 BOOL32 WINAPI PolyPolyline32( HDC32 hdc, const POINT32* pt, const DWORD* counts,
757 DWORD polylines )
759 DC * dc = DC_GetDCPtr( hdc );
761 return dc && dc->funcs->pPolyPolyline &&
762 dc->funcs->pPolyPolyline(dc,pt,counts,polylines);
765 /**********************************************************************
766 * ExtFloodFill16 (GDI.372)
768 BOOL16 WINAPI ExtFloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color,
769 UINT16 fillType )
771 return ExtFloodFill32( hdc, x, y, color, fillType );
775 /**********************************************************************
776 * ExtFloodFill32 (GDI32.96)
778 BOOL32 WINAPI ExtFloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color,
779 UINT32 fillType )
781 DC *dc = DC_GetDCPtr( hdc );
783 return dc && dc->funcs->pExtFloodFill &&
784 dc->funcs->pExtFloodFill(dc,x,y,color,fillType);
788 /**********************************************************************
789 * FloodFill16 (GDI.25)
791 BOOL16 WINAPI FloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
793 return ExtFloodFill32( hdc, x, y, color, FLOODFILLBORDER );
797 /**********************************************************************
798 * FloodFill32 (GDI32.104)
800 BOOL32 WINAPI FloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
802 return ExtFloodFill32( hdc, x, y, color, FLOODFILLBORDER );
806 /**********************************************************************
807 * DrawAnimatedRects32 (USER32.153)
809 BOOL32 WINAPI DrawAnimatedRects32( HWND32 hwnd, int idAni,
810 const RECT32* lprcFrom,
811 const RECT32* lprcTo )
813 FIXME(gdi,"(0x%x,%d,%p,%p): stub\n",hwnd,idAni,lprcFrom,lprcTo);
814 return TRUE;
818 /**********************************************************************
819 * PAINTING_DrawStateJam
821 * Jams in the requested type in the dc
823 static BOOL32 PAINTING_DrawStateJam(HDC32 hdc, UINT32 opcode,
824 DRAWSTATEPROC32 func, LPARAM lp, WPARAM32 wp,
825 LPRECT32 rc, UINT32 dtflags,
826 BOOL32 unicode, BOOL32 _32bit)
828 HDC32 memdc;
829 HBITMAP32 hbmsave;
830 BOOL32 retval;
831 INT32 cx = rc->right - rc->left;
832 INT32 cy = rc->bottom - rc->top;
834 switch(opcode)
836 case DST_TEXT:
837 case DST_PREFIXTEXT:
838 if(unicode)
839 return DrawText32W(hdc, (LPWSTR)lp, (INT32)wp, rc, dtflags);
840 else if(_32bit)
841 return DrawText32A(hdc, (LPSTR)lp, (INT32)wp, rc, dtflags);
842 else
843 return DrawText32A(hdc, (LPSTR)PTR_SEG_TO_LIN(lp), (INT32)wp, rc, dtflags);
845 case DST_ICON:
846 return DrawIcon32(hdc, rc->left, rc->top, (HICON32)lp);
848 case DST_BITMAP:
849 memdc = CreateCompatibleDC32(hdc);
850 if(!memdc) return FALSE;
851 hbmsave = (HBITMAP32)SelectObject32(memdc, (HBITMAP32)lp);
852 if(!hbmsave)
854 DeleteDC32(memdc);
855 return FALSE;
857 retval = BitBlt32(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
858 SelectObject32(memdc, hbmsave);
859 DeleteDC32(memdc);
860 return retval;
862 case DST_COMPLEX:
863 if(func)
864 if(_32bit)
865 return func(hdc, lp, wp, cx, cy);
866 else
867 return (BOOL32)((DRAWSTATEPROC16)func)((HDC16)hdc, (LPARAM)lp, (WPARAM16)wp, (INT16)cx, (INT16)cy);
868 else
869 return FALSE;
871 return FALSE;
874 /**********************************************************************
875 * PAINTING_DrawState32()
877 static BOOL32 PAINTING_DrawState32(HDC32 hdc, HBRUSH32 hbr,
878 DRAWSTATEPROC32 func, LPARAM lp, WPARAM32 wp,
879 INT32 x, INT32 y, INT32 cx, INT32 cy,
880 UINT32 flags, BOOL32 unicode, BOOL32 _32bit)
882 HBITMAP32 hbm, hbmsave;
883 HFONT32 hfsave;
884 HBRUSH32 hbsave;
885 HDC32 memdc;
886 RECT32 rc;
887 UINT32 dtflags = DT_NOCLIP;
888 COLORREF fg, bg;
889 UINT32 opcode = flags & 0xf;
890 INT32 len = wp;
891 BOOL32 retval, tmp;
893 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
895 if(unicode)
896 len = lstrlen32W((LPWSTR)lp);
897 else if(_32bit)
898 len = lstrlen32A((LPSTR)lp);
899 else
900 len = lstrlen32A((LPSTR)PTR_SEG_TO_LIN(lp));
903 /* Find out what size the image has if not given by caller */
904 if(!cx || !cy)
906 SIZE32 s;
907 CURSORICONINFO *ici;
908 BITMAPOBJ *bmp;
910 switch(opcode)
912 case DST_TEXT:
913 case DST_PREFIXTEXT:
914 if(unicode)
915 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
916 else if(_32bit)
917 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
918 else
919 retval = GetTextExtentPoint32A(hdc, PTR_SEG_TO_LIN(lp), len, &s);
920 if(!retval) return FALSE;
921 break;
923 case DST_ICON:
924 ici = (CURSORICONINFO *)GlobalLock16((HGLOBAL16)lp);
925 if(!ici) return FALSE;
926 s.cx = ici->nWidth;
927 s.cy = ici->nHeight;
928 GlobalUnlock16((HGLOBAL16)lp);
929 break;
931 case DST_BITMAP:
932 bmp = (BITMAPOBJ *)GDI_GetObjPtr((HBITMAP16)lp, BITMAP_MAGIC);
933 if(!bmp) return FALSE;
934 s.cx = bmp->bitmap.bmWidth;
935 s.cy = bmp->bitmap.bmHeight;
936 break;
938 case DST_COMPLEX: /* cx and cy must be set in this mode */
939 return FALSE;
942 if(!cx) cx = s.cx;
943 if(!cy) cy = s.cy;
946 rc.left = x;
947 rc.top = y;
948 rc.right = x + cx;
949 rc.bottom = y + cy;
951 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
952 dtflags |= DT_RIGHT;
953 if(opcode == DST_TEXT)
954 dtflags |= DT_NOPREFIX;
956 /* For DSS_NORMAL we just jam in the image and return */
957 if((flags & 0x7ff0) == DSS_NORMAL)
959 return PAINTING_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
962 /* For all other states we need to convert the image to B/W in a local bitmap */
963 /* before it is displayed */
964 fg = SetTextColor32(hdc, RGB(0, 0, 0));
965 bg = SetBkColor32(hdc, RGB(255, 255, 255));
966 hbm = (HBITMAP32)NULL; hbmsave = (HBITMAP32)NULL;
967 memdc = (HDC32)NULL; hbsave = (HBRUSH32)NULL;
968 retval = FALSE; /* assume failure */
970 /* From here on we must use "goto cleanup" when something goes wrong */
971 hbm = CreateBitmap32(cx, cy, 1, 1, NULL);
972 if(!hbm) goto cleanup;
973 memdc = CreateCompatibleDC32(hdc);
974 if(!memdc) goto cleanup;
975 hbmsave = (HBITMAP32)SelectObject32(memdc, hbm);
976 if(!hbmsave) goto cleanup;
977 rc.left = rc.top = 0;
978 rc.right = cx;
979 rc.bottom = cy;
980 if(!FillRect32(memdc, &rc, (HBRUSH32)GetStockObject32(WHITE_BRUSH))) goto cleanup;
981 SetBkColor32(memdc, RGB(255, 255, 255));
982 SetTextColor32(memdc, RGB(0, 0, 0));
983 hfsave = (HFONT32)SelectObject32(memdc, GetCurrentObject(hdc, OBJ_FONT));
984 if(!hfsave && (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)) goto cleanup;
985 tmp = PAINTING_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
986 if(hfsave) SelectObject32(memdc, hfsave);
987 if(!tmp) goto cleanup;
989 /* These states cause the image to be dithered */
990 if(flags & (DSS_UNION|DSS_DISABLED))
992 hbsave = (HBRUSH32)SelectObject32(memdc, CACHE_GetPattern55AABrush());
993 if(!hbsave) goto cleanup;
994 tmp = PatBlt32(memdc, 0, 0, cx, cy, 0x00FA0089);
995 if(hbsave) SelectObject32(memdc, hbsave);
996 if(!tmp) goto cleanup;
999 hbsave = (HBRUSH32)SelectObject32(hdc, hbr ? hbr : GetStockObject32(WHITE_BRUSH));
1000 if(!hbsave) goto cleanup;
1002 if(!BitBlt32(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1004 /* DSS_DEFAULT makes the image boldface */
1005 if(flags & DSS_DEFAULT)
1007 if(!BitBlt32(hdc, x+1, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1010 retval = TRUE; /* We succeeded */
1012 cleanup:
1013 SetTextColor32(hdc, fg);
1014 SetBkColor32(hdc, bg);
1016 if(hbsave) SelectObject32(hdc, hbsave);
1017 if(hbmsave) SelectObject32(memdc, hbmsave);
1018 if(hbm) DeleteObject32(hbm);
1019 if(memdc) DeleteDC32(memdc);
1021 return retval;
1024 /**********************************************************************
1025 * DrawState32A() (USER32.162)
1027 BOOL32 WINAPI DrawState32A(HDC32 hdc, HBRUSH32 hbr,
1028 DRAWSTATEPROC32 func, LPARAM ldata, WPARAM32 wdata,
1029 INT32 x, INT32 y, INT32 cx, INT32 cy, UINT32 flags)
1031 return PAINTING_DrawState32(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE, TRUE);
1034 /**********************************************************************
1035 * DrawState32W() (USER32.163)
1037 BOOL32 WINAPI DrawState32W(HDC32 hdc, HBRUSH32 hbr,
1038 DRAWSTATEPROC32 func, LPARAM ldata, WPARAM32 wdata,
1039 INT32 x, INT32 y, INT32 cx, INT32 cy, UINT32 flags)
1041 return PAINTING_DrawState32(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE, TRUE);
1044 /**********************************************************************
1045 * DrawState16() (USER.449)
1047 BOOL16 WINAPI DrawState16(HDC16 hdc, HBRUSH16 hbr,
1048 DRAWSTATEPROC16 func, LPARAM ldata, WPARAM16 wdata,
1049 INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags)
1051 return PAINTING_DrawState32(hdc, hbr, (DRAWSTATEPROC32)func, ldata, wdata, x, y, cx, cy, flags, FALSE, FALSE);
1055 /******************************************************************************
1056 * PolyBezier16 [GDI.502]
1058 BOOL16 WINAPI PolyBezier16( HDC16 hDc, const POINT16* lppt, INT16 cPoints )
1060 int i;
1061 BOOL16 ret;
1062 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
1063 cPoints*sizeof(POINT32) );
1064 if(!pt32) return FALSE;
1065 for (i=cPoints;i--;) CONV_POINT16TO32(&(lppt[i]),&(pt32[i]));
1066 ret= PolyBezier32(hDc, pt32, cPoints);
1067 HeapFree( GetProcessHeap(), 0, pt32 );
1068 return ret;
1071 /******************************************************************************
1072 * PolyBezierTo16 [GDI.503]
1074 BOOL16 WINAPI PolyBezierTo16( HDC16 hDc, const POINT16* lppt, INT16 cPoints )
1076 int i;
1077 BOOL16 ret;
1078 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
1079 cPoints*sizeof(POINT32) );
1080 if(!pt32) return FALSE;
1081 for (i=cPoints;i--;) CONV_POINT16TO32(&(lppt[i]),&(pt32[i]));
1082 ret= PolyBezierTo32(hDc, pt32, cPoints);
1083 HeapFree( GetProcessHeap(), 0, pt32 );
1084 return ret;
1087 /******************************************************************************
1088 * PolyBezier32 [GDI32.268]
1089 * Draws one or more Bezier curves
1091 * PARAMS
1092 * hDc [I] Handle to device context
1093 * lppt [I] Pointer to endpoints and control points
1094 * cPoints [I] Count of endpoints and control points
1096 * RETURNS STD
1098 BOOL32 WINAPI PolyBezier32( HDC32 hdc, const POINT32* lppt, DWORD cPoints )
1100 DC * dc = DC_GetDCPtr( hdc );
1101 if(!dc) return FALSE;
1102 if(dc && PATH_IsPathOpen(dc->w.path))
1103 FIXME(gdi, "PATH_PolyBezier is not implemented!\n");
1104 /* if(!PATH_PolyBezier(hdc, x, y))
1105 return FALSE; */
1106 return dc->funcs->pPolyBezier&&
1107 dc->funcs->pPolyBezier(dc, lppt[0], lppt+1, cPoints-1);
1110 /******************************************************************************
1111 * PolyBezierTo32 [GDI32.269]
1112 * Draws one or more Bezier curves
1114 * PARAMS
1115 * hDc [I] Handle to device context
1116 * lppt [I] Pointer to endpoints and control points
1117 * cPoints [I] Count of endpoints and control points
1119 * RETURNS STD
1121 BOOL32 WINAPI PolyBezierTo32( HDC32 hdc, const POINT32* lppt, DWORD cPoints )
1123 DC * dc = DC_GetDCPtr( hdc );
1124 POINT32 pt;
1125 BOOL32 ret;
1126 if(!dc) return FALSE;
1127 pt.x=dc->w.CursPosX;
1128 pt.y=dc->w.CursPosY;
1129 if(dc && PATH_IsPathOpen(dc->w.path))
1130 FIXME(gdi, "PATH_PolyBezierTo is not implemented!\n");
1131 /* if(!PATH_PolyBezier(hdc, x, y))
1132 return FALSE; */
1133 ret= dc->funcs->pPolyBezier &&
1134 dc->funcs->pPolyBezier(dc, pt, lppt, cPoints);
1135 if( dc->funcs->pMoveToEx)
1136 dc->funcs->pMoveToEx(dc,lppt[cPoints].x,lppt[cPoints].y,&pt);
1137 return ret;