2 * Misc. graphics operations
4 * Copyright 1993, 1994 Alexandre Julliard
5 * Copyright 1997 Bertho A. Stultiens
12 #include <X11/Intrinsic.h>
30 /***********************************************************************
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))
50 return dc && dc->funcs->pLineTo &&
51 dc->funcs->pLineTo(dc,x,y);
55 /***********************************************************************
58 DWORD WINAPI MoveTo( HDC16 hdc, INT16 x, INT16 y )
62 if (!MoveToEx16(hdc,x,y,&pt))
64 return MAKELONG(pt.x,pt.y);
68 /***********************************************************************
69 * MoveToEx16 (GDI.483)
71 BOOL16 WINAPI MoveToEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
75 if (!MoveToEx32( (HDC32)hdc, (INT32)x, (INT32)y, &pt32 )) return FALSE;
76 if (pt) CONV_POINT32TO16( &pt32, pt );
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))
93 return dc && dc->funcs->pMoveToEx &&
94 dc->funcs->pMoveToEx(dc,x,y,pt);
98 /***********************************************************************
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,
111 /***********************************************************************
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,
125 return dc && dc->funcs->pArc &&
126 dc->funcs->pArc(dc,left,top,right,bottom,xstart,ystart,xend,yend);
129 /***********************************************************************
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 )
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.
156 * If no error occured, the current position is moved to the ending
161 MoveToEx32(hdc, xend, yend, NULL);
167 /***********************************************************************
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,
180 /***********************************************************************
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 /***********************************************************************
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 /***********************************************************************
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 /***********************************************************************
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))
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);
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 )
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 );
317 /***********************************************************************
318 * FillRect32 (USER32.197)
320 INT32 WINAPI FillRect32( HDC32 hdc, const RECT32 *rect, HBRUSH32 hbrush )
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 );
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 )
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 );
385 /***********************************************************************
386 * FrameRect32 (USER32.203)
388 INT32 WINAPI FrameRect32( HDC32 hdc, const RECT32 *rect, HBRUSH32 hbrush )
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);
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 );
445 #ifdef SOLITAIRE_SPEED_HACK
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
461 * hdc [I] Device context to search for best pixel match
462 * ppfd [I] Pixel format for which a match is sought
465 * Success: Pixel format index closest to given format
468 INT32 WINAPI ChoosePixelFormat( HDC32 hdc, const PIXELFORMATDESCRIPTOR* ppfd )
470 FIXME(gdi, "(%d,%p): stub\n",hdc,ppfd);
475 /******************************************************************************
476 * SetPixelFormat [GDI32.328]
477 * Sets pixel format of device context
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
486 BOOL32 WINAPI SetPixelFormat( HDC32 hdc, int iPixelFormat,
487 const PIXELFORMATDESCRIPTOR* ppfd)
489 FIXME(gdi, "(%d,%d,%p): stub\n",hdc,iPixelFormat,ppfd);
494 /******************************************************************************
495 * GetPixelFormat [GDI32.212]
496 * Gets index of pixel format of DC
499 * hdc [I] Device context whose pixel format index is sought
502 * Success: Currently selected pixel format
505 int WINAPI GetPixelFormat( HDC32 hdc )
507 FIXME(gdi, "(%d): stub\n",hdc);
512 /******************************************************************************
513 * DescribePixelFormat [GDI32.71]
514 * Gets info about pixel format from DC
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
523 * Success: Maximum pixel format index of the device context
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;
536 /******************************************************************************
537 * SwapBuffers [GDI32.354]
538 * Exchanges front and back buffers of window
541 * hdc [I] Device context whose buffers get swapped
545 BOOL32 WINAPI SwapBuffers( HDC32 hdc )
547 FIXME(gdi, "(%d): stub\n",hdc);
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 /***********************************************************************
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 )
588 HBRUSH32 prevBrush = SelectObject32( hdc, hbrush );
589 if (!prevBrush) return FALSE;
590 retval = PaintRgn32( hdc, hrgn );
591 SelectObject32( hdc, prevBrush );
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 );
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 );
643 /***********************************************************************
644 * DrawFocusRect16 (USER.466)
646 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
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 );
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)
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 )
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 );
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);
728 /**********************************************************************
731 BOOL16 WINAPI Polygon16( HDC16 hdc, const POINT16* pt, INT16 count )
735 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
736 count*sizeof(POINT32) );
738 if (!pt32) return FALSE;
739 for (i=count;i--;) CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
740 ret = Polygon32(hdc,pt32,count);
741 HeapFree( GetProcessHeap(), 0, pt32 );
746 /**********************************************************************
747 * Polygon32 (GDI32.275)
749 BOOL32 WINAPI Polygon32( HDC32 hdc, const POINT32* pt, INT32 count )
751 DC * dc = DC_GetDCPtr( hdc );
753 return dc && dc->funcs->pPolygon &&
754 dc->funcs->pPolygon(dc,pt,count);
758 /**********************************************************************
759 * PolyPolygon16 (GDI.450)
761 BOOL16 WINAPI PolyPolygon16( HDC16 hdc, const POINT16* pt, const INT16* counts,
770 for (i=polygons;i--;)
772 pt32 = (LPPOINT32)HEAP_xalloc( GetProcessHeap(), 0, sizeof(POINT32)*nrpts);
774 CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
775 counts32 = (LPINT32)HEAP_xalloc( GetProcessHeap(), 0,
776 polygons*sizeof(INT32) );
777 for (i=polygons;i--;) counts32[i]=counts[i];
779 ret = PolyPolygon32(hdc,pt32,counts32,polygons);
780 HeapFree( GetProcessHeap(), 0, counts32 );
781 HeapFree( GetProcessHeap(), 0, pt32 );
785 /**********************************************************************
786 * PolyPolygon32 (GDI.450)
788 BOOL32 WINAPI PolyPolygon32( HDC32 hdc, const POINT32* pt, const INT32* counts,
791 DC * dc = DC_GetDCPtr( hdc );
793 return dc && dc->funcs->pPolyPolygon &&
794 dc->funcs->pPolyPolygon(dc,pt,counts,polygons);
797 /**********************************************************************
798 * PolyPolyline32 (GDI32.272)
800 BOOL32 WINAPI PolyPolyline32( HDC32 hdc, const POINT32* pt, const DWORD* counts,
803 DC * dc = DC_GetDCPtr( hdc );
805 return dc && dc->funcs->pPolyPolyline &&
806 dc->funcs->pPolyPolyline(dc,pt,counts,polylines);
809 /**********************************************************************
810 * ExtFloodFill16 (GDI.372)
812 BOOL16 WINAPI ExtFloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color,
815 return ExtFloodFill32( hdc, x, y, color, fillType );
819 /**********************************************************************
820 * ExtFloodFill32 (GDI32.96)
822 BOOL32 WINAPI ExtFloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color,
825 DC *dc = DC_GetDCPtr( hdc );
827 return dc && dc->funcs->pExtFloodFill &&
828 dc->funcs->pExtFloodFill(dc,x,y,color,fillType);
832 /**********************************************************************
833 * FloodFill16 (GDI.25)
835 BOOL16 WINAPI FloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
837 return ExtFloodFill32( hdc, x, y, color, FLOODFILLBORDER );
841 /**********************************************************************
842 * FloodFill32 (GDI32.104)
844 BOOL32 WINAPI FloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
846 return ExtFloodFill32( hdc, x, y, color, FLOODFILLBORDER );
850 /**********************************************************************
851 * DrawAnimatedRects32 (USER32.153)
853 BOOL32 WINAPI DrawAnimatedRects32( HWND32 hwnd, int idAni,
854 const RECT32* lprcFrom,
855 const RECT32* lprcTo )
857 FIXME(gdi,"(0x%x,%d,%p,%p): stub\n",hwnd,idAni,lprcFrom,lprcTo);
862 /**********************************************************************
863 * PAINTING_DrawStateJam
865 * Jams in the requested type in the dc
867 static BOOL32 PAINTING_DrawStateJam(HDC32 hdc, UINT32 opcode,
868 DRAWSTATEPROC32 func, LPARAM lp, WPARAM32 wp,
869 LPRECT32 rc, UINT32 dtflags,
870 BOOL32 unicode, BOOL32 _32bit)
875 INT32 cx = rc->right - rc->left;
876 INT32 cy = rc->bottom - rc->top;
883 return DrawText32W(hdc, (LPWSTR)lp, (INT32)wp, rc, dtflags);
885 return DrawText32A(hdc, (LPSTR)lp, (INT32)wp, rc, dtflags);
887 return DrawText32A(hdc, (LPSTR)PTR_SEG_TO_LIN(lp), (INT32)wp, rc, dtflags);
890 return DrawIcon32(hdc, rc->left, rc->top, (HICON32)lp);
893 memdc = CreateCompatibleDC32(hdc);
894 if(!memdc) return FALSE;
895 hbmsave = (HBITMAP32)SelectObject32(memdc, (HBITMAP32)lp);
901 retval = BitBlt32(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
902 SelectObject32(memdc, hbmsave);
909 return func(hdc, lp, wp, cx, cy);
911 return (BOOL32)((DRAWSTATEPROC16)func)((HDC16)hdc, (LPARAM)lp, (WPARAM16)wp, (INT16)cx, (INT16)cy);
918 /**********************************************************************
919 * PAINTING_DrawState32()
921 static BOOL32 PAINTING_DrawState32(HDC32 hdc, HBRUSH32 hbr,
922 DRAWSTATEPROC32 func, LPARAM lp, WPARAM32 wp,
923 INT32 x, INT32 y, INT32 cx, INT32 cy,
924 UINT32 flags, BOOL32 unicode, BOOL32 _32bit)
926 HBITMAP32 hbm, hbmsave;
931 UINT32 dtflags = DT_NOCLIP;
933 UINT32 opcode = flags & 0xf;
937 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
940 len = lstrlen32W((LPWSTR)lp);
942 len = lstrlen32A((LPSTR)lp);
944 len = lstrlen32A((LPSTR)PTR_SEG_TO_LIN(lp));
947 /* Find out what size the image has if not given by caller */
959 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
961 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
963 retval = GetTextExtentPoint32A(hdc, PTR_SEG_TO_LIN(lp), len, &s);
964 if(!retval) return FALSE;
968 ici = (CURSORICONINFO *)GlobalLock16((HGLOBAL16)lp);
969 if(!ici) return FALSE;
972 GlobalUnlock16((HGLOBAL16)lp);
976 bmp = (BITMAPOBJ *)GDI_GetObjPtr((HBITMAP16)lp, BITMAP_MAGIC);
977 if(!bmp) return FALSE;
978 s.cx = bmp->bitmap.bmWidth;
979 s.cy = bmp->bitmap.bmHeight;
982 case DST_COMPLEX: /* cx and cy must be set in this mode */
995 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
997 if(opcode == DST_TEXT)
998 dtflags |= DT_NOPREFIX;
1000 /* For DSS_NORMAL we just jam in the image and return */
1001 if((flags & 0x7ff0) == DSS_NORMAL)
1003 return PAINTING_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
1006 /* For all other states we need to convert the image to B/W in a local bitmap */
1007 /* before it is displayed */
1008 fg = SetTextColor32(hdc, RGB(0, 0, 0));
1009 bg = SetBkColor32(hdc, RGB(255, 255, 255));
1010 hbm = (HBITMAP32)NULL; hbmsave = (HBITMAP32)NULL;
1011 memdc = (HDC32)NULL; hbsave = (HBRUSH32)NULL;
1012 retval = FALSE; /* assume failure */
1014 /* From here on we must use "goto cleanup" when something goes wrong */
1015 hbm = CreateBitmap32(cx, cy, 1, 1, NULL);
1016 if(!hbm) goto cleanup;
1017 memdc = CreateCompatibleDC32(hdc);
1018 if(!memdc) goto cleanup;
1019 hbmsave = (HBITMAP32)SelectObject32(memdc, hbm);
1020 if(!hbmsave) goto cleanup;
1021 rc.left = rc.top = 0;
1024 if(!FillRect32(memdc, &rc, (HBRUSH32)GetStockObject32(WHITE_BRUSH))) goto cleanup;
1025 SetBkColor32(memdc, RGB(255, 255, 255));
1026 SetTextColor32(memdc, RGB(0, 0, 0));
1027 hfsave = (HFONT32)SelectObject32(memdc, GetCurrentObject(hdc, OBJ_FONT));
1028 if(!hfsave && (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)) goto cleanup;
1029 tmp = PAINTING_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
1030 if(hfsave) SelectObject32(memdc, hfsave);
1031 if(!tmp) goto cleanup;
1033 /* These states cause the image to be dithered */
1034 if(flags & (DSS_UNION|DSS_DISABLED))
1036 hbsave = (HBRUSH32)SelectObject32(memdc, CACHE_GetPattern55AABrush());
1037 if(!hbsave) goto cleanup;
1038 tmp = PatBlt32(memdc, 0, 0, cx, cy, 0x00FA0089);
1039 if(hbsave) SelectObject32(memdc, hbsave);
1040 if(!tmp) goto cleanup;
1043 hbsave = (HBRUSH32)SelectObject32(hdc, hbr ? hbr : GetStockObject32(WHITE_BRUSH));
1044 if(!hbsave) goto cleanup;
1046 if(!BitBlt32(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1048 /* DSS_DEFAULT makes the image boldface */
1049 if(flags & DSS_DEFAULT)
1051 if(!BitBlt32(hdc, x+1, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1054 retval = TRUE; /* We succeeded */
1057 SetTextColor32(hdc, fg);
1058 SetBkColor32(hdc, bg);
1060 if(hbsave) SelectObject32(hdc, hbsave);
1061 if(hbmsave) SelectObject32(memdc, hbmsave);
1062 if(hbm) DeleteObject32(hbm);
1063 if(memdc) DeleteDC32(memdc);
1068 /**********************************************************************
1069 * DrawState32A() (USER32.162)
1071 BOOL32 WINAPI DrawState32A(HDC32 hdc, HBRUSH32 hbr,
1072 DRAWSTATEPROC32 func, LPARAM ldata, WPARAM32 wdata,
1073 INT32 x, INT32 y, INT32 cx, INT32 cy, UINT32 flags)
1075 return PAINTING_DrawState32(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE, TRUE);
1078 /**********************************************************************
1079 * DrawState32W() (USER32.163)
1081 BOOL32 WINAPI DrawState32W(HDC32 hdc, HBRUSH32 hbr,
1082 DRAWSTATEPROC32 func, LPARAM ldata, WPARAM32 wdata,
1083 INT32 x, INT32 y, INT32 cx, INT32 cy, UINT32 flags)
1085 return PAINTING_DrawState32(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE, TRUE);
1088 /**********************************************************************
1089 * DrawState16() (USER.449)
1091 BOOL16 WINAPI DrawState16(HDC16 hdc, HBRUSH16 hbr,
1092 DRAWSTATEPROC16 func, LPARAM ldata, WPARAM16 wdata,
1093 INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags)
1095 return PAINTING_DrawState32(hdc, hbr, (DRAWSTATEPROC32)func, ldata, wdata, x, y, cx, cy, flags, FALSE, FALSE);
1099 /******************************************************************************
1100 * PolyBezier16 [GDI.502]
1102 BOOL16 WINAPI PolyBezier16( HDC16 hDc, const POINT16* lppt, INT16 cPoints )
1106 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
1107 cPoints*sizeof(POINT32) );
1108 if(!pt32) return FALSE;
1109 for (i=cPoints;i--;) CONV_POINT16TO32(&(lppt[i]),&(pt32[i]));
1110 ret= PolyBezier32(hDc, pt32, cPoints);
1111 HeapFree( GetProcessHeap(), 0, pt32 );
1115 /******************************************************************************
1116 * PolyBezierTo16 [GDI.503]
1118 BOOL16 WINAPI PolyBezierTo16( HDC16 hDc, const POINT16* lppt, INT16 cPoints )
1122 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
1123 cPoints*sizeof(POINT32) );
1124 if(!pt32) return FALSE;
1125 for (i=cPoints;i--;) CONV_POINT16TO32(&(lppt[i]),&(pt32[i]));
1126 ret= PolyBezierTo32(hDc, pt32, cPoints);
1127 HeapFree( GetProcessHeap(), 0, pt32 );
1131 /******************************************************************************
1132 * PolyBezier32 [GDI32.268]
1133 * Draws one or more Bezier curves
1136 * hDc [I] Handle to device context
1137 * lppt [I] Pointer to endpoints and control points
1138 * cPoints [I] Count of endpoints and control points
1142 BOOL32 WINAPI PolyBezier32( HDC32 hdc, const POINT32* lppt, DWORD cPoints )
1144 DC * dc = DC_GetDCPtr( hdc );
1145 if(!dc) return FALSE;
1146 if(dc && PATH_IsPathOpen(dc->w.path))
1147 FIXME(gdi, "PATH_PolyBezier is not implemented!\n");
1148 /* if(!PATH_PolyBezier(hdc, x, y))
1150 return dc->funcs->pPolyBezier&&
1151 dc->funcs->pPolyBezier(dc, lppt[0], lppt+1, cPoints-1);
1154 /******************************************************************************
1155 * PolyBezierTo32 [GDI32.269]
1156 * Draws one or more Bezier curves
1159 * hDc [I] Handle to device context
1160 * lppt [I] Pointer to endpoints and control points
1161 * cPoints [I] Count of endpoints and control points
1165 BOOL32 WINAPI PolyBezierTo32( HDC32 hdc, const POINT32* lppt, DWORD cPoints )
1167 DC * dc = DC_GetDCPtr( hdc );
1170 if(!dc) return FALSE;
1171 pt.x=dc->w.CursPosX;
1172 pt.y=dc->w.CursPosY;
1173 if(dc && PATH_IsPathOpen(dc->w.path))
1174 FIXME(gdi, "PATH_PolyBezierTo is not implemented!\n");
1175 /* if(!PATH_PolyBezier(hdc, x, y))
1177 ret= dc->funcs->pPolyBezier &&
1178 dc->funcs->pPolyBezier(dc, pt, lppt, cPoints);
1179 if( dc->funcs->pMoveToEx)
1180 dc->funcs->pMoveToEx(dc,lppt[cPoints].x,lppt[cPoints].y,&pt);
1185 /*************************************************************************
1186 * StartDoc32W [GDI32.348]
1190 StartDoc32W(HDC32 hdc ,const DOCINFO32W* doc) {
1191 FIXME(gdi,"stub\n");
1192 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1193 return 0; /* failure*/
1196 /******************************************************************************
1197 * PolylineTo32 [GDI32.277]
1199 BOOL32 WINAPI PolylineTo32(HDC32 hdc, const POINT32 *lppt, DWORD cCount)
1201 FIXME(gdi, "(%d,%p,%ld): stub\n", hdc, lppt, cCount);
1205 /******************************************************************************
1206 * AbortDoc32 [GDI32.0]
1208 INT32 WINAPI AbortDoc32(HDC32 hdc)
1210 FIXME(gdi, "(%d): stub\n", hdc);