Don't send ODA_ENTIRE for empty listboxes (LISTBOX_Paint).
[wine/multimedia.git] / graphics / painting.c
blob423853fc50b2a38e15094fa0473da8b7509ab3f2
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 "region.h"
25 #include "path.h"
26 #include "debug.h"
27 #include "winerror.h"
28 #include "x11drv.h"
30 /***********************************************************************
31 * LineTo16 (GDI.19)
33 BOOL16 WINAPI LineTo16( HDC16 hdc, INT16 x, INT16 y )
35 return LineTo32( hdc, x, y );
39 /***********************************************************************
40 * LineTo32 (GDI32.249)
42 BOOL32 WINAPI LineTo32( HDC32 hdc, INT32 x, INT32 y )
44 DC * dc = DC_GetDCPtr( hdc );
46 if(dc && PATH_IsPathOpen(dc->w.path))
47 if(!PATH_LineTo(hdc, x, y))
48 return FALSE;
50 return dc && dc->funcs->pLineTo &&
51 dc->funcs->pLineTo(dc,x,y);
55 /***********************************************************************
56 * MoveTo (GDI.20)
58 DWORD WINAPI MoveTo( HDC16 hdc, INT16 x, INT16 y )
60 POINT16 pt;
62 if (!MoveToEx16(hdc,x,y,&pt))
63 return 0;
64 return MAKELONG(pt.x,pt.y);
68 /***********************************************************************
69 * MoveToEx16 (GDI.483)
71 BOOL16 WINAPI MoveToEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
73 POINT32 pt32;
75 if (!MoveToEx32( (HDC32)hdc, (INT32)x, (INT32)y, &pt32 )) return FALSE;
76 if (pt) CONV_POINT32TO16( &pt32, pt );
77 return TRUE;
82 /***********************************************************************
83 * MoveToEx32 (GDI32.254)
85 BOOL32 WINAPI MoveToEx32( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 pt )
87 DC * dc = DC_GetDCPtr( hdc );
89 if(dc && PATH_IsPathOpen(dc->w.path))
90 if(!PATH_MoveTo(hdc))
91 return FALSE;
93 return dc && dc->funcs->pMoveToEx &&
94 dc->funcs->pMoveToEx(dc,x,y,pt);
98 /***********************************************************************
99 * Arc16 (GDI.23)
101 BOOL16 WINAPI Arc16( HDC16 hdc, INT16 left, INT16 top, INT16 right,
102 INT16 bottom, INT16 xstart, INT16 ystart,
103 INT16 xend, INT16 yend )
105 return Arc32( (HDC32)hdc, (INT32)left, (INT32)top, (INT32)right,
106 (INT32)bottom, (INT32)xstart, (INT32)ystart, (INT32)xend,
107 (INT32)yend );
111 /***********************************************************************
112 * Arc32 (GDI32.7)
114 BOOL32 WINAPI Arc32( HDC32 hdc, INT32 left, INT32 top, INT32 right,
115 INT32 bottom, INT32 xstart, INT32 ystart,
116 INT32 xend, INT32 yend )
118 DC * dc = DC_GetDCPtr( hdc );
120 if(dc && PATH_IsPathOpen(dc->w.path))
121 if(!PATH_Arc(hdc, left, top, right, bottom, xstart, ystart, xend,
122 yend))
123 return FALSE;
125 return dc && dc->funcs->pArc &&
126 dc->funcs->pArc(dc,left,top,right,bottom,xstart,ystart,xend,yend);
129 /***********************************************************************
130 * ArcTo32 (GDI32.8)
132 BOOL32 WINAPI ArcTo32( HDC32 hdc,
133 INT32 left, INT32 top,
134 INT32 right, INT32 bottom,
135 INT32 xstart, INT32 ystart,
136 INT32 xend, INT32 yend )
138 BOOL32 result;
141 * According to the documentation, a line is drawn from the current
142 * position to the starting point of the arc.
144 LineTo32(hdc, xstart, ystart);
147 * Then the arc is drawn.
149 result = Arc32(hdc,
150 left, top,
151 right, bottom,
152 xstart, ystart,
153 xend, yend);
156 * If no error occured, the current position is moved to the ending
157 * point of the arc.
159 if (result)
161 MoveToEx32(hdc, xend, yend, NULL);
164 return result;
167 /***********************************************************************
168 * Pie16 (GDI.26)
170 BOOL16 WINAPI Pie16( HDC16 hdc, INT16 left, INT16 top,
171 INT16 right, INT16 bottom, INT16 xstart, INT16 ystart,
172 INT16 xend, INT16 yend )
174 return Pie32( (HDC32)hdc, (INT32)left, (INT32)top, (INT32)right,
175 (INT32)bottom, (INT32)xstart, (INT32)ystart, (INT32)xend,
176 (INT32)yend );
180 /***********************************************************************
181 * Pie32 (GDI32.262)
183 BOOL32 WINAPI Pie32( HDC32 hdc, INT32 left, INT32 top,
184 INT32 right, INT32 bottom, INT32 xstart, INT32 ystart,
185 INT32 xend, INT32 yend )
187 DC * dc = DC_GetDCPtr( hdc );
189 return dc && dc->funcs->pPie &&
190 dc->funcs->pPie(dc,left,top,right,bottom,xstart,ystart,xend,yend);
194 /***********************************************************************
195 * Chord16 (GDI.348)
197 BOOL16 WINAPI Chord16( HDC16 hdc, INT16 left, INT16 top,
198 INT16 right, INT16 bottom, INT16 xstart, INT16 ystart,
199 INT16 xend, INT16 yend )
201 return Chord32( hdc, left, top, right, bottom, xstart, ystart, xend, yend );
205 /***********************************************************************
206 * Chord32 (GDI32.14)
208 BOOL32 WINAPI Chord32( HDC32 hdc, INT32 left, INT32 top,
209 INT32 right, INT32 bottom, INT32 xstart, INT32 ystart,
210 INT32 xend, INT32 yend )
212 DC * dc = DC_GetDCPtr( hdc );
214 return dc && dc->funcs->pChord &&
215 dc->funcs->pChord(dc,left,top,right,bottom,xstart,ystart,xend,yend);
219 /***********************************************************************
220 * Ellipse16 (GDI.24)
222 BOOL16 WINAPI Ellipse16( HDC16 hdc, INT16 left, INT16 top,
223 INT16 right, INT16 bottom )
225 return Ellipse32( hdc, left, top, right, bottom );
229 /***********************************************************************
230 * Ellipse32 (GDI32.75)
232 BOOL32 WINAPI Ellipse32( HDC32 hdc, INT32 left, INT32 top,
233 INT32 right, INT32 bottom )
235 DC * dc = DC_GetDCPtr( hdc );
237 return dc && dc->funcs->pEllipse &&
238 dc->funcs->pEllipse(dc,left,top,right,bottom);
242 /***********************************************************************
243 * Rectangle16 (GDI.27)
245 BOOL16 WINAPI Rectangle16( HDC16 hdc, INT16 left, INT16 top,
246 INT16 right, INT16 bottom )
248 return Rectangle32( hdc, left, top, right, bottom );
252 /***********************************************************************
253 * Rectangle32 (GDI32.283)
255 BOOL32 WINAPI Rectangle32( HDC32 hdc, INT32 left, INT32 top,
256 INT32 right, INT32 bottom )
258 DC * dc = DC_GetDCPtr( hdc );
260 if(dc && PATH_IsPathOpen(dc->w.path))
261 if(!PATH_Rectangle(hdc, left, top, right, bottom))
262 return FALSE;
264 return dc && dc->funcs->pRectangle &&
265 dc->funcs->pRectangle(dc,left,top,right,bottom);
269 /***********************************************************************
270 * RoundRect16 (GDI.28)
272 BOOL16 WINAPI RoundRect16( HDC16 hdc, INT16 left, INT16 top, INT16 right,
273 INT16 bottom, INT16 ell_width, INT16 ell_height )
275 return RoundRect32( hdc, left, top, right, bottom, ell_width, ell_height );
279 /***********************************************************************
280 * RoundRect32 (GDI32.291)
282 BOOL32 WINAPI RoundRect32( HDC32 hdc, INT32 left, INT32 top, INT32 right,
283 INT32 bottom, INT32 ell_width, INT32 ell_height )
286 if(ell_width == 0 || ell_height == 0) /* Just an optimization */
287 return Rectangle32(hdc, left, top, right, bottom);
289 else {
290 DC * dc = DC_GetDCPtr( hdc );
292 return dc && dc->funcs->pRoundRect &&
293 dc->funcs->pRoundRect(dc,left,top,right,bottom,ell_width,ell_height);
298 /***********************************************************************
299 * FillRect16 (USER.81)
301 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
303 HBRUSH16 prevBrush;
305 /* coordinates are logical so we cannot fast-check 'rect',
306 * it will be done later in the PatBlt().
309 if (!(prevBrush = SelectObject16( hdc, hbrush ))) return 0;
310 PatBlt32( hdc, rect->left, rect->top,
311 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
312 SelectObject16( hdc, prevBrush );
313 return 1;
317 /***********************************************************************
318 * FillRect32 (USER32.197)
320 INT32 WINAPI FillRect32( HDC32 hdc, const RECT32 *rect, HBRUSH32 hbrush )
322 HBRUSH32 prevBrush;
324 if (!(prevBrush = SelectObject32( hdc, hbrush ))) return 0;
325 PatBlt32( hdc, rect->left, rect->top,
326 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
327 SelectObject32( hdc, prevBrush );
328 return 1;
332 /***********************************************************************
333 * InvertRect16 (USER.82)
335 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
337 PatBlt32( hdc, rect->left, rect->top,
338 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
342 /***********************************************************************
343 * InvertRect32 (USER32.330)
345 void WINAPI InvertRect32( HDC32 hdc, const RECT32 *rect )
347 PatBlt32( hdc, rect->left, rect->top,
348 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
352 /***********************************************************************
353 * FrameRect16 (USER.83)
355 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
357 HBRUSH16 prevBrush;
358 int left, top, right, bottom;
360 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
361 if (!dc) return FALSE;
363 left = XLPTODP( dc, rect->left );
364 top = YLPTODP( dc, rect->top );
365 right = XLPTODP( dc, rect->right );
366 bottom = YLPTODP( dc, rect->bottom );
368 if ( (right <= left) || (bottom <= top) ) return 0;
369 if (!(prevBrush = SelectObject16( hdc, hbrush ))) return 0;
371 PatBlt32( hdc, rect->left, rect->top, 1,
372 rect->bottom - rect->top, PATCOPY );
373 PatBlt32( hdc, rect->right - 1, rect->top, 1,
374 rect->bottom - rect->top, PATCOPY );
375 PatBlt32( hdc, rect->left, rect->top,
376 rect->right - rect->left, 1, PATCOPY );
377 PatBlt32( hdc, rect->left, rect->bottom - 1,
378 rect->right - rect->left, 1, PATCOPY );
380 SelectObject16( hdc, prevBrush );
381 return 1;
385 /***********************************************************************
386 * FrameRect32 (USER32.203)
388 INT32 WINAPI FrameRect32( HDC32 hdc, const RECT32 *rect, HBRUSH32 hbrush )
390 RECT16 rect16;
391 CONV_RECT32TO16( rect, &rect16 );
392 return FrameRect16( (HDC16)hdc, &rect16, (HBRUSH16)hbrush );
396 /***********************************************************************
397 * SetPixel16 (GDI.31)
399 COLORREF WINAPI SetPixel16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
401 return SetPixel32( hdc, x, y, color );
405 /***********************************************************************
406 * SetPixel32 (GDI32.327)
408 COLORREF WINAPI SetPixel32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
410 DC * dc = DC_GetDCPtr( hdc );
412 if (!dc || !dc->funcs->pSetPixel) return 0;
413 return dc->funcs->pSetPixel(dc,x,y,color);
416 /***********************************************************************
417 * SetPixelV32 (GDI32.329)
419 BOOL32 WINAPI SetPixelV32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
421 DC * dc = DC_GetDCPtr( hdc );
423 if (!dc || !dc->funcs->pSetPixel) return FALSE;
424 dc->funcs->pSetPixel(dc,x,y,color);
425 return TRUE;
428 /***********************************************************************
429 * GetPixel16 (GDI.83)
431 COLORREF WINAPI GetPixel16( HDC16 hdc, INT16 x, INT16 y )
433 return GetPixel32( hdc, x, y );
437 /***********************************************************************
438 * GetPixel32 (GDI32.211)
440 COLORREF WINAPI GetPixel32( HDC32 hdc, INT32 x, INT32 y )
442 DC * dc = DC_GetDCPtr( hdc );
444 if (!dc) return 0;
445 #ifdef SOLITAIRE_SPEED_HACK
446 return 0;
447 #endif
449 /* FIXME: should this be in the graphics driver? */
450 if (!PtVisible32( hdc, x, y )) return 0;
451 if (!dc || !dc->funcs->pGetPixel) return 0;
452 return dc->funcs->pGetPixel(dc,x,y);
456 /******************************************************************************
457 * ChoosePixelFormat [GDI32.13]
458 * Matches a pixel format to given format
460 * PARAMS
461 * hdc [I] Device context to search for best pixel match
462 * ppfd [I] Pixel format for which a match is sought
464 * RETURNS
465 * Success: Pixel format index closest to given format
466 * Failure: 0
468 INT32 WINAPI ChoosePixelFormat( HDC32 hdc, const PIXELFORMATDESCRIPTOR* ppfd )
470 FIXME(gdi, "(%d,%p): stub\n",hdc,ppfd);
471 return 1;
475 /******************************************************************************
476 * SetPixelFormat [GDI32.328]
477 * Sets pixel format of device context
479 * PARAMS
480 * hdc [I] Device context to search for best pixel match
481 * iPixelFormat [I] Pixel format index
482 * ppfd [I] Pixel format for which a match is sought
484 * RETURNS STD
486 BOOL32 WINAPI SetPixelFormat( HDC32 hdc, int iPixelFormat,
487 const PIXELFORMATDESCRIPTOR* ppfd)
489 FIXME(gdi, "(%d,%d,%p): stub\n",hdc,iPixelFormat,ppfd);
490 return TRUE;
494 /******************************************************************************
495 * GetPixelFormat [GDI32.212]
496 * Gets index of pixel format of DC
498 * PARAMETERS
499 * hdc [I] Device context whose pixel format index is sought
501 * RETURNS
502 * Success: Currently selected pixel format
503 * Failure: 0
505 int WINAPI GetPixelFormat( HDC32 hdc )
507 FIXME(gdi, "(%d): stub\n",hdc);
508 return 1;
512 /******************************************************************************
513 * DescribePixelFormat [GDI32.71]
514 * Gets info about pixel format from DC
516 * PARAMS
517 * hdc [I] Device context
518 * iPixelFormat [I] Pixel format selector
519 * nBytes [I] Size of buffer
520 * ppfd [O] Pointer to structure to receive pixel format data
522 * RETURNS
523 * Success: Maximum pixel format index of the device context
524 * Failure: 0
526 int WINAPI DescribePixelFormat( HDC32 hdc, int iPixelFormat, UINT32 nBytes,
527 LPPIXELFORMATDESCRIPTOR ppfd )
529 FIXME(gdi, "(%d,%d,%d,%p): stub\n",hdc,iPixelFormat,nBytes,ppfd);
530 ppfd->nSize = nBytes;
531 ppfd->nVersion = 1;
532 return 3;
536 /******************************************************************************
537 * SwapBuffers [GDI32.354]
538 * Exchanges front and back buffers of window
540 * PARAMS
541 * hdc [I] Device context whose buffers get swapped
543 * RETURNS STD
545 BOOL32 WINAPI SwapBuffers( HDC32 hdc )
547 FIXME(gdi, "(%d): stub\n",hdc);
548 return TRUE;
552 /***********************************************************************
553 * PaintRgn16 (GDI.43)
555 BOOL16 WINAPI PaintRgn16( HDC16 hdc, HRGN16 hrgn )
557 return PaintRgn32( hdc, hrgn );
561 /***********************************************************************
562 * PaintRgn32 (GDI32.259)
564 BOOL32 WINAPI PaintRgn32( HDC32 hdc, HRGN32 hrgn )
566 DC * dc = DC_GetDCPtr( hdc );
568 return dc && dc->funcs->pPaintRgn &&
569 dc->funcs->pPaintRgn(dc,hrgn);
573 /***********************************************************************
574 * FillRgn16 (GDI.40)
576 BOOL16 WINAPI FillRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush )
578 return FillRgn32( hdc, hrgn, hbrush );
582 /***********************************************************************
583 * FillRgn32 (GDI32.101)
585 BOOL32 WINAPI FillRgn32( HDC32 hdc, HRGN32 hrgn, HBRUSH32 hbrush )
587 BOOL32 retval;
588 HBRUSH32 prevBrush = SelectObject32( hdc, hbrush );
589 if (!prevBrush) return FALSE;
590 retval = PaintRgn32( hdc, hrgn );
591 SelectObject32( hdc, prevBrush );
592 return retval;
596 /***********************************************************************
597 * FrameRgn16 (GDI.41)
599 BOOL16 WINAPI FrameRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush,
600 INT16 nWidth, INT16 nHeight )
602 return FrameRgn32( hdc, hrgn, hbrush, nWidth, nHeight );
606 /***********************************************************************
607 * FrameRgn32 (GDI32.105)
609 BOOL32 WINAPI FrameRgn32( HDC32 hdc, HRGN32 hrgn, HBRUSH32 hbrush,
610 INT32 nWidth, INT32 nHeight )
612 HRGN32 tmp = CreateRectRgn32( 0, 0, 0, 0 );
613 if(!REGION_FrameRgn( tmp, hrgn, nWidth, nHeight )) return FALSE;
614 FillRgn32( hdc, tmp, hbrush );
615 DeleteObject32( tmp );
616 return TRUE;
620 /***********************************************************************
621 * InvertRgn16 (GDI.42)
623 BOOL16 WINAPI InvertRgn16( HDC16 hdc, HRGN16 hrgn )
625 return InvertRgn32( hdc, hrgn );
629 /***********************************************************************
630 * InvertRgn32 (GDI32.246)
632 BOOL32 WINAPI InvertRgn32( HDC32 hdc, HRGN32 hrgn )
634 HBRUSH32 prevBrush = SelectObject32( hdc, GetStockObject32(BLACK_BRUSH) );
635 INT32 prevROP = SetROP232( hdc, R2_NOT );
636 BOOL32 retval = PaintRgn32( hdc, hrgn );
637 SelectObject32( hdc, prevBrush );
638 SetROP232( hdc, prevROP );
639 return retval;
643 /***********************************************************************
644 * DrawFocusRect16 (USER.466)
646 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
648 RECT32 rect32;
649 CONV_RECT16TO32( rc, &rect32 );
650 DrawFocusRect32( hdc, &rect32 );
654 /***********************************************************************
655 * DrawFocusRect32 (USER32.156)
657 * FIXME: PatBlt(PATINVERT) with background brush.
659 void WINAPI DrawFocusRect32( HDC32 hdc, const RECT32* rc )
661 HPEN32 hOldPen, hnewPen;
662 INT32 oldDrawMode, oldBkMode;
663 INT32 left, top, right, bottom;
664 X11DRV_PDEVICE *physDev;
666 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
667 if (!dc) return;
668 physDev = (X11DRV_PDEVICE *)dc->physDev;
670 left = XLPTODP( dc, rc->left );
671 top = YLPTODP( dc, rc->top );
672 right = XLPTODP( dc, rc->right );
673 bottom = YLPTODP( dc, rc->bottom );
675 if(left == right || top == bottom)
676 return;
678 hnewPen = CreatePen32(PS_DOT, 1, GetSysColor32(COLOR_WINDOWTEXT) );
679 hOldPen = SelectObject32( hdc, hnewPen );
680 oldDrawMode = SetROP232(hdc, R2_XORPEN);
681 oldBkMode = SetBkMode32(hdc, TRANSPARENT);
683 /* Hack: make sure the XORPEN operation has an effect */
684 physDev->pen.pixel = (1 << screenDepth) - 1;
686 if (X11DRV_SetupGCForPen( dc ))
687 TSXDrawRectangle( display, physDev->drawable, physDev->gc,
688 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
689 right-left-1, bottom-top-1 );
691 SetBkMode32(hdc, oldBkMode);
692 SetROP232(hdc, oldDrawMode);
693 SelectObject32(hdc, hOldPen);
694 DeleteObject32(hnewPen);
698 /**********************************************************************
699 * Polyline16 (GDI.37)
701 BOOL16 WINAPI Polyline16( HDC16 hdc, const POINT16* pt, INT16 count )
703 register int i;
704 BOOL16 ret;
705 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
706 count*sizeof(POINT32) );
708 if (!pt32) return FALSE;
709 for (i=count;i--;) CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
710 ret = Polyline32(hdc,pt32,count);
711 HeapFree( GetProcessHeap(), 0, pt32 );
712 return ret;
716 /**********************************************************************
717 * Polyline32 (GDI32.276)
719 BOOL32 WINAPI Polyline32( HDC32 hdc, const POINT32* pt, INT32 count )
721 DC * dc = DC_GetDCPtr( hdc );
723 return dc && dc->funcs->pPolyline &&
724 dc->funcs->pPolyline(dc,pt,count);
727 /**********************************************************************
728 * PolylineTo32 (GDI32.277)
730 BOOL32 WINAPI PolylineTo32( HDC32 hdc, const POINT32* pt, DWORD cCount )
732 POINT32 *pts = HeapAlloc( GetProcessHeap(), 0,
733 sizeof(POINT32) * (cCount + 1) );
734 if(!pts) return FALSE;
736 /* Get the current point */
737 MoveToEx32( hdc, 0, 0, pts);
739 /* Add in the other points */
740 memcpy( pts + 1, pt, sizeof(POINT32) * cCount );
742 /* Draw the lines */
743 Polyline32( hdc, pts, cCount + 1 );
745 /* Move to last point */
746 MoveToEx32( hdc, (pts + cCount)->x, (pts + cCount)->y, NULL );
748 HeapFree( GetProcessHeap(), 0, pts );
749 return TRUE;
752 /**********************************************************************
753 * Polygon16 (GDI.36)
755 BOOL16 WINAPI Polygon16( HDC16 hdc, const POINT16* pt, INT16 count )
757 register int i;
758 BOOL32 ret;
759 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
760 count*sizeof(POINT32) );
762 if (!pt32) return FALSE;
763 for (i=count;i--;) CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
764 ret = Polygon32(hdc,pt32,count);
765 HeapFree( GetProcessHeap(), 0, pt32 );
766 return ret;
770 /**********************************************************************
771 * Polygon32 (GDI32.275)
773 BOOL32 WINAPI Polygon32( HDC32 hdc, const POINT32* pt, INT32 count )
775 DC * dc = DC_GetDCPtr( hdc );
777 return dc && dc->funcs->pPolygon &&
778 dc->funcs->pPolygon(dc,pt,count);
782 /**********************************************************************
783 * PolyPolygon16 (GDI.450)
785 BOOL16 WINAPI PolyPolygon16( HDC16 hdc, const POINT16* pt, const INT16* counts,
786 UINT16 polygons )
788 int i,nrpts;
789 LPPOINT32 pt32;
790 LPINT32 counts32;
791 BOOL16 ret;
793 nrpts=0;
794 for (i=polygons;i--;)
795 nrpts+=counts[i];
796 pt32 = (LPPOINT32)HEAP_xalloc( GetProcessHeap(), 0, sizeof(POINT32)*nrpts);
797 for (i=nrpts;i--;)
798 CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
799 counts32 = (LPINT32)HEAP_xalloc( GetProcessHeap(), 0,
800 polygons*sizeof(INT32) );
801 for (i=polygons;i--;) counts32[i]=counts[i];
803 ret = PolyPolygon32(hdc,pt32,counts32,polygons);
804 HeapFree( GetProcessHeap(), 0, counts32 );
805 HeapFree( GetProcessHeap(), 0, pt32 );
806 return ret;
809 /**********************************************************************
810 * PolyPolygon32 (GDI.450)
812 BOOL32 WINAPI PolyPolygon32( HDC32 hdc, const POINT32* pt, const INT32* counts,
813 UINT32 polygons )
815 DC * dc = DC_GetDCPtr( hdc );
817 return dc && dc->funcs->pPolyPolygon &&
818 dc->funcs->pPolyPolygon(dc,pt,counts,polygons);
821 /**********************************************************************
822 * PolyPolyline32 (GDI32.272)
824 BOOL32 WINAPI PolyPolyline32( HDC32 hdc, const POINT32* pt, const DWORD* counts,
825 DWORD polylines )
827 DC * dc = DC_GetDCPtr( hdc );
829 return dc && dc->funcs->pPolyPolyline &&
830 dc->funcs->pPolyPolyline(dc,pt,counts,polylines);
833 /**********************************************************************
834 * ExtFloodFill16 (GDI.372)
836 BOOL16 WINAPI ExtFloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color,
837 UINT16 fillType )
839 return ExtFloodFill32( hdc, x, y, color, fillType );
843 /**********************************************************************
844 * ExtFloodFill32 (GDI32.96)
846 BOOL32 WINAPI ExtFloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color,
847 UINT32 fillType )
849 DC *dc = DC_GetDCPtr( hdc );
851 return dc && dc->funcs->pExtFloodFill &&
852 dc->funcs->pExtFloodFill(dc,x,y,color,fillType);
856 /**********************************************************************
857 * FloodFill16 (GDI.25)
859 BOOL16 WINAPI FloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
861 return ExtFloodFill32( hdc, x, y, color, FLOODFILLBORDER );
865 /**********************************************************************
866 * FloodFill32 (GDI32.104)
868 BOOL32 WINAPI FloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
870 return ExtFloodFill32( hdc, x, y, color, FLOODFILLBORDER );
874 /**********************************************************************
875 * DrawAnimatedRects32 (USER32.153)
877 BOOL32 WINAPI DrawAnimatedRects32( HWND32 hwnd, int idAni,
878 const RECT32* lprcFrom,
879 const RECT32* lprcTo )
881 FIXME(gdi,"(0x%x,%d,%p,%p): stub\n",hwnd,idAni,lprcFrom,lprcTo);
882 return TRUE;
886 /**********************************************************************
887 * PAINTING_DrawStateJam
889 * Jams in the requested type in the dc
891 static BOOL32 PAINTING_DrawStateJam(HDC32 hdc, UINT32 opcode,
892 DRAWSTATEPROC32 func, LPARAM lp, WPARAM32 wp,
893 LPRECT32 rc, UINT32 dtflags,
894 BOOL32 unicode, BOOL32 _32bit)
896 HDC32 memdc;
897 HBITMAP32 hbmsave;
898 BOOL32 retval;
899 INT32 cx = rc->right - rc->left;
900 INT32 cy = rc->bottom - rc->top;
902 switch(opcode)
904 case DST_TEXT:
905 case DST_PREFIXTEXT:
906 if(unicode)
907 return DrawText32W(hdc, (LPWSTR)lp, (INT32)wp, rc, dtflags);
908 else if(_32bit)
909 return DrawText32A(hdc, (LPSTR)lp, (INT32)wp, rc, dtflags);
910 else
911 return DrawText32A(hdc, (LPSTR)PTR_SEG_TO_LIN(lp), (INT32)wp, rc, dtflags);
913 case DST_ICON:
914 return DrawIcon32(hdc, rc->left, rc->top, (HICON32)lp);
916 case DST_BITMAP:
917 memdc = CreateCompatibleDC32(hdc);
918 if(!memdc) return FALSE;
919 hbmsave = (HBITMAP32)SelectObject32(memdc, (HBITMAP32)lp);
920 if(!hbmsave)
922 DeleteDC32(memdc);
923 return FALSE;
925 retval = BitBlt32(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
926 SelectObject32(memdc, hbmsave);
927 DeleteDC32(memdc);
928 return retval;
930 case DST_COMPLEX:
931 if(func)
932 if(_32bit)
933 return func(hdc, lp, wp, cx, cy);
934 else
935 return (BOOL32)((DRAWSTATEPROC16)func)((HDC16)hdc, (LPARAM)lp, (WPARAM16)wp, (INT16)cx, (INT16)cy);
936 else
937 return FALSE;
939 return FALSE;
942 /**********************************************************************
943 * PAINTING_DrawState32()
945 static BOOL32 PAINTING_DrawState32(HDC32 hdc, HBRUSH32 hbr,
946 DRAWSTATEPROC32 func, LPARAM lp, WPARAM32 wp,
947 INT32 x, INT32 y, INT32 cx, INT32 cy,
948 UINT32 flags, BOOL32 unicode, BOOL32 _32bit)
950 HBITMAP32 hbm, hbmsave;
951 HFONT32 hfsave;
952 HBRUSH32 hbsave;
953 HDC32 memdc;
954 RECT32 rc;
955 UINT32 dtflags = DT_NOCLIP;
956 COLORREF fg, bg;
957 UINT32 opcode = flags & 0xf;
958 INT32 len = wp;
959 BOOL32 retval, tmp;
961 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
963 if(unicode)
964 len = lstrlen32W((LPWSTR)lp);
965 else if(_32bit)
966 len = lstrlen32A((LPSTR)lp);
967 else
968 len = lstrlen32A((LPSTR)PTR_SEG_TO_LIN(lp));
971 /* Find out what size the image has if not given by caller */
972 if(!cx || !cy)
974 SIZE32 s;
975 CURSORICONINFO *ici;
976 BITMAPOBJ *bmp;
978 switch(opcode)
980 case DST_TEXT:
981 case DST_PREFIXTEXT:
982 if(unicode)
983 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
984 else if(_32bit)
985 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
986 else
987 retval = GetTextExtentPoint32A(hdc, PTR_SEG_TO_LIN(lp), len, &s);
988 if(!retval) return FALSE;
989 break;
991 case DST_ICON:
992 ici = (CURSORICONINFO *)GlobalLock16((HGLOBAL16)lp);
993 if(!ici) return FALSE;
994 s.cx = ici->nWidth;
995 s.cy = ici->nHeight;
996 GlobalUnlock16((HGLOBAL16)lp);
997 break;
999 case DST_BITMAP:
1000 bmp = (BITMAPOBJ *)GDI_GetObjPtr((HBITMAP16)lp, BITMAP_MAGIC);
1001 if(!bmp) return FALSE;
1002 s.cx = bmp->bitmap.bmWidth;
1003 s.cy = bmp->bitmap.bmHeight;
1004 break;
1006 case DST_COMPLEX: /* cx and cy must be set in this mode */
1007 return FALSE;
1010 if(!cx) cx = s.cx;
1011 if(!cy) cy = s.cy;
1014 rc.left = x;
1015 rc.top = y;
1016 rc.right = x + cx;
1017 rc.bottom = y + cy;
1019 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
1020 dtflags |= DT_RIGHT;
1021 if(opcode == DST_TEXT)
1022 dtflags |= DT_NOPREFIX;
1024 /* For DSS_NORMAL we just jam in the image and return */
1025 if((flags & 0x7ff0) == DSS_NORMAL)
1027 return PAINTING_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
1030 /* For all other states we need to convert the image to B/W in a local bitmap */
1031 /* before it is displayed */
1032 fg = SetTextColor32(hdc, RGB(0, 0, 0));
1033 bg = SetBkColor32(hdc, RGB(255, 255, 255));
1034 hbm = (HBITMAP32)NULL; hbmsave = (HBITMAP32)NULL;
1035 memdc = (HDC32)NULL; hbsave = (HBRUSH32)NULL;
1036 retval = FALSE; /* assume failure */
1038 /* From here on we must use "goto cleanup" when something goes wrong */
1039 hbm = CreateBitmap32(cx, cy, 1, 1, NULL);
1040 if(!hbm) goto cleanup;
1041 memdc = CreateCompatibleDC32(hdc);
1042 if(!memdc) goto cleanup;
1043 hbmsave = (HBITMAP32)SelectObject32(memdc, hbm);
1044 if(!hbmsave) goto cleanup;
1045 rc.left = rc.top = 0;
1046 rc.right = cx;
1047 rc.bottom = cy;
1048 if(!FillRect32(memdc, &rc, (HBRUSH32)GetStockObject32(WHITE_BRUSH))) goto cleanup;
1049 SetBkColor32(memdc, RGB(255, 255, 255));
1050 SetTextColor32(memdc, RGB(0, 0, 0));
1051 hfsave = (HFONT32)SelectObject32(memdc, GetCurrentObject(hdc, OBJ_FONT));
1052 if(!hfsave && (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)) goto cleanup;
1053 tmp = PAINTING_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
1054 if(hfsave) SelectObject32(memdc, hfsave);
1055 if(!tmp) goto cleanup;
1057 /* These states cause the image to be dithered */
1058 if(flags & (DSS_UNION|DSS_DISABLED))
1060 hbsave = (HBRUSH32)SelectObject32(memdc, CACHE_GetPattern55AABrush());
1061 if(!hbsave) goto cleanup;
1062 tmp = PatBlt32(memdc, 0, 0, cx, cy, 0x00FA0089);
1063 if(hbsave) SelectObject32(memdc, hbsave);
1064 if(!tmp) goto cleanup;
1067 hbsave = (HBRUSH32)SelectObject32(hdc, hbr ? hbr : GetStockObject32(WHITE_BRUSH));
1068 if(!hbsave) goto cleanup;
1070 if(!BitBlt32(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1072 /* DSS_DEFAULT makes the image boldface */
1073 if(flags & DSS_DEFAULT)
1075 if(!BitBlt32(hdc, x+1, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1078 retval = TRUE; /* We succeeded */
1080 cleanup:
1081 SetTextColor32(hdc, fg);
1082 SetBkColor32(hdc, bg);
1084 if(hbsave) SelectObject32(hdc, hbsave);
1085 if(hbmsave) SelectObject32(memdc, hbmsave);
1086 if(hbm) DeleteObject32(hbm);
1087 if(memdc) DeleteDC32(memdc);
1089 return retval;
1092 /**********************************************************************
1093 * DrawState32A() (USER32.162)
1095 BOOL32 WINAPI DrawState32A(HDC32 hdc, HBRUSH32 hbr,
1096 DRAWSTATEPROC32 func, LPARAM ldata, WPARAM32 wdata,
1097 INT32 x, INT32 y, INT32 cx, INT32 cy, UINT32 flags)
1099 return PAINTING_DrawState32(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE, TRUE);
1102 /**********************************************************************
1103 * DrawState32W() (USER32.163)
1105 BOOL32 WINAPI DrawState32W(HDC32 hdc, HBRUSH32 hbr,
1106 DRAWSTATEPROC32 func, LPARAM ldata, WPARAM32 wdata,
1107 INT32 x, INT32 y, INT32 cx, INT32 cy, UINT32 flags)
1109 return PAINTING_DrawState32(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE, TRUE);
1112 /**********************************************************************
1113 * DrawState16() (USER.449)
1115 BOOL16 WINAPI DrawState16(HDC16 hdc, HBRUSH16 hbr,
1116 DRAWSTATEPROC16 func, LPARAM ldata, WPARAM16 wdata,
1117 INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags)
1119 return PAINTING_DrawState32(hdc, hbr, (DRAWSTATEPROC32)func, ldata, wdata, x, y, cx, cy, flags, FALSE, FALSE);
1123 /******************************************************************************
1124 * PolyBezier16 [GDI.502]
1126 BOOL16 WINAPI PolyBezier16( HDC16 hDc, const POINT16* lppt, INT16 cPoints )
1128 int i;
1129 BOOL16 ret;
1130 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
1131 cPoints*sizeof(POINT32) );
1132 if(!pt32) return FALSE;
1133 for (i=cPoints;i--;) CONV_POINT16TO32(&(lppt[i]),&(pt32[i]));
1134 ret= PolyBezier32(hDc, pt32, cPoints);
1135 HeapFree( GetProcessHeap(), 0, pt32 );
1136 return ret;
1139 /******************************************************************************
1140 * PolyBezierTo16 [GDI.503]
1142 BOOL16 WINAPI PolyBezierTo16( HDC16 hDc, const POINT16* lppt, INT16 cPoints )
1144 int i;
1145 BOOL16 ret;
1146 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
1147 cPoints*sizeof(POINT32) );
1148 if(!pt32) return FALSE;
1149 for (i=cPoints;i--;) CONV_POINT16TO32(&(lppt[i]),&(pt32[i]));
1150 ret= PolyBezierTo32(hDc, pt32, cPoints);
1151 HeapFree( GetProcessHeap(), 0, pt32 );
1152 return ret;
1155 /******************************************************************************
1156 * PolyBezier32 [GDI32.268]
1157 * Draws one or more Bezier curves
1159 * PARAMS
1160 * hDc [I] Handle to device context
1161 * lppt [I] Pointer to endpoints and control points
1162 * cPoints [I] Count of endpoints and control points
1164 * RETURNS STD
1166 BOOL32 WINAPI PolyBezier32( HDC32 hdc, const POINT32* lppt, DWORD cPoints )
1168 DC * dc = DC_GetDCPtr( hdc );
1169 if(!dc) return FALSE;
1170 if(dc && PATH_IsPathOpen(dc->w.path))
1171 FIXME(gdi, "PATH_PolyBezier is not implemented!\n");
1172 /* if(!PATH_PolyBezier(hdc, x, y))
1173 return FALSE; */
1174 return dc->funcs->pPolyBezier&&
1175 dc->funcs->pPolyBezier(dc, lppt[0], lppt+1, cPoints-1);
1178 /******************************************************************************
1179 * PolyBezierTo32 [GDI32.269]
1180 * Draws one or more Bezier curves
1182 * PARAMS
1183 * hDc [I] Handle to device context
1184 * lppt [I] Pointer to endpoints and control points
1185 * cPoints [I] Count of endpoints and control points
1187 * RETURNS STD
1189 BOOL32 WINAPI PolyBezierTo32( HDC32 hdc, const POINT32* lppt, DWORD cPoints )
1191 DC * dc = DC_GetDCPtr( hdc );
1192 POINT32 pt;
1193 BOOL32 ret;
1194 if(!dc) return FALSE;
1195 pt.x=dc->w.CursPosX;
1196 pt.y=dc->w.CursPosY;
1197 if(dc && PATH_IsPathOpen(dc->w.path))
1198 FIXME(gdi, "PATH_PolyBezierTo is not implemented!\n");
1199 /* if(!PATH_PolyBezier(hdc, x, y))
1200 return FALSE; */
1201 ret= dc->funcs->pPolyBezier &&
1202 dc->funcs->pPolyBezier(dc, pt, lppt, cPoints);
1203 if( dc->funcs->pMoveToEx)
1204 dc->funcs->pMoveToEx(dc,lppt[cPoints].x,lppt[cPoints].y,&pt);
1205 return ret;
1208 /***************************************************************
1209 * AngleArc32 (GDI32.5)
1212 BOOL32 WINAPI AngleArc32(HDC32 hdc, INT32 x, INT32 y, DWORD dwRadius,
1213 FLOAT eStartAngle, FLOAT eSweepAngle)
1215 FIXME(gdi,"AngleArc, stub\n");
1216 return 0;
1219 /***************************************************************
1220 * PolyDraw (GDI32.270)
1223 BOOL32 WINAPI PolyDraw(HDC32 hdc, const POINT32 *lppt, const BYTE *lpbTypes,
1224 DWORD cCount)
1226 FIXME(gdi,"PolyDraw, stub\n");
1227 return 0;