Release 980104
[wine/multimedia.git] / graphics / painting.c
blobcec3d9ce3e5414e375a29fb71aee75cca78e28a9
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 <X11/Xlib.h>
11 #include <X11/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 "stddebug.h"
28 #include "debug.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 return dc && dc->funcs->pArc &&
121 dc->funcs->pArc(dc,left,top,right,bottom,xstart,ystart,xend,yend);
125 /***********************************************************************
126 * Pie16 (GDI.26)
128 BOOL16 WINAPI Pie16( HDC16 hdc, INT16 left, INT16 top,
129 INT16 right, INT16 bottom, INT16 xstart, INT16 ystart,
130 INT16 xend, INT16 yend )
132 return Pie32( (HDC32)hdc, (INT32)left, (INT32)top, (INT32)right,
133 (INT32)bottom, (INT32)xstart, (INT32)ystart, (INT32)xend,
134 (INT32)yend );
138 /***********************************************************************
139 * Pie32 (GDI32.262)
141 BOOL32 WINAPI Pie32( HDC32 hdc, INT32 left, INT32 top,
142 INT32 right, INT32 bottom, INT32 xstart, INT32 ystart,
143 INT32 xend, INT32 yend )
145 DC * dc = DC_GetDCPtr( hdc );
147 return dc && dc->funcs->pPie &&
148 dc->funcs->pPie(dc,left,top,right,bottom,xstart,ystart,xend,yend);
152 /***********************************************************************
153 * Chord16 (GDI.348)
155 BOOL16 WINAPI Chord16( HDC16 hdc, INT16 left, INT16 top,
156 INT16 right, INT16 bottom, INT16 xstart, INT16 ystart,
157 INT16 xend, INT16 yend )
159 return Chord32( hdc, left, top, right, bottom, xstart, ystart, xend, yend );
163 /***********************************************************************
164 * Chord32 (GDI32.14)
166 BOOL32 WINAPI Chord32( HDC32 hdc, INT32 left, INT32 top,
167 INT32 right, INT32 bottom, INT32 xstart, INT32 ystart,
168 INT32 xend, INT32 yend )
170 DC * dc = DC_GetDCPtr( hdc );
172 return dc && dc->funcs->pChord &&
173 dc->funcs->pChord(dc,left,top,right,bottom,xstart,ystart,xend,yend);
177 /***********************************************************************
178 * Ellipse16 (GDI.24)
180 BOOL16 WINAPI Ellipse16( HDC16 hdc, INT16 left, INT16 top,
181 INT16 right, INT16 bottom )
183 return Ellipse32( hdc, left, top, right, bottom );
187 /***********************************************************************
188 * Ellipse32 (GDI32.75)
190 BOOL32 WINAPI Ellipse32( HDC32 hdc, INT32 left, INT32 top,
191 INT32 right, INT32 bottom )
193 DC * dc = DC_GetDCPtr( hdc );
195 return dc && dc->funcs->pEllipse &&
196 dc->funcs->pEllipse(dc,left,top,right,bottom);
200 /***********************************************************************
201 * Rectangle16 (GDI.27)
203 BOOL16 WINAPI Rectangle16( HDC16 hdc, INT16 left, INT16 top,
204 INT16 right, INT16 bottom )
206 return Rectangle32( hdc, left, top, right, bottom );
210 /***********************************************************************
211 * Rectangle32 (GDI32.283)
213 BOOL32 WINAPI Rectangle32( HDC32 hdc, INT32 left, INT32 top,
214 INT32 right, INT32 bottom )
216 DC * dc = DC_GetDCPtr( hdc );
218 return dc && dc->funcs->pRectangle &&
219 dc->funcs->pRectangle(dc,left,top,right,bottom);
223 /***********************************************************************
224 * RoundRect16 (GDI.28)
226 BOOL16 WINAPI RoundRect16( HDC16 hdc, INT16 left, INT16 top, INT16 right,
227 INT16 bottom, INT16 ell_width, INT16 ell_height )
229 return RoundRect32( hdc, left, top, right, bottom, ell_width, ell_height );
233 /***********************************************************************
234 * RoundRect32 (GDI32.291)
236 BOOL32 WINAPI RoundRect32( HDC32 hdc, INT32 left, INT32 top, INT32 right,
237 INT32 bottom, INT32 ell_width, INT32 ell_height )
239 DC * dc = DC_GetDCPtr( hdc );
241 return dc && dc->funcs->pRoundRect &&
242 dc->funcs->pRoundRect(dc,left,top,right,bottom,ell_width,ell_height);
246 /***********************************************************************
247 * FillRect16 (USER.81)
249 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
251 HBRUSH16 prevBrush;
253 /* coordinates are logical so we cannot fast-check 'rect',
254 * it will be done later in the PatBlt().
257 if (!(prevBrush = SelectObject16( hdc, hbrush ))) return 0;
258 PatBlt32( hdc, rect->left, rect->top,
259 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
260 SelectObject16( hdc, prevBrush );
261 return 1;
265 /***********************************************************************
266 * FillRect32 (USER32.196)
268 INT32 WINAPI FillRect32( HDC32 hdc, const RECT32 *rect, HBRUSH32 hbrush )
270 HBRUSH32 prevBrush;
272 if (!(prevBrush = SelectObject32( hdc, hbrush ))) return 0;
273 PatBlt32( hdc, rect->left, rect->top,
274 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
275 SelectObject32( hdc, prevBrush );
276 return 1;
280 /***********************************************************************
281 * InvertRect16 (USER.82)
283 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
285 PatBlt32( hdc, rect->left, rect->top,
286 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
290 /***********************************************************************
291 * InvertRect32 (USER32.329)
293 void WINAPI InvertRect32( HDC32 hdc, const RECT32 *rect )
295 PatBlt32( hdc, rect->left, rect->top,
296 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
300 /***********************************************************************
301 * FrameRect16 (USER.83)
303 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
305 HBRUSH16 prevBrush;
306 int left, top, right, bottom;
308 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
309 if (!dc) return FALSE;
311 left = XLPTODP( dc, rect->left );
312 top = YLPTODP( dc, rect->top );
313 right = XLPTODP( dc, rect->right );
314 bottom = YLPTODP( dc, rect->bottom );
316 if ( (right <= left) || (bottom <= top) ) return 0;
317 if (!(prevBrush = SelectObject16( hdc, hbrush ))) return 0;
319 if (DC_SetupGCForBrush( dc ))
321 PatBlt32( hdc, rect->left, rect->top, 1,
322 rect->bottom - rect->top, PATCOPY );
323 PatBlt32( hdc, rect->right - 1, rect->top, 1,
324 rect->bottom - rect->top, PATCOPY );
325 PatBlt32( hdc, rect->left, rect->top,
326 rect->right - rect->left, 1, PATCOPY );
327 PatBlt32( hdc, rect->left, rect->bottom - 1,
328 rect->right - rect->left, 1, PATCOPY );
330 SelectObject16( hdc, prevBrush );
331 return 1;
335 /***********************************************************************
336 * FrameRect32 (USER32.202)
338 INT32 WINAPI FrameRect32( HDC32 hdc, const RECT32 *rect, HBRUSH32 hbrush )
340 RECT16 rect16;
341 CONV_RECT32TO16( rect, &rect16 );
342 return FrameRect16( (HDC16)hdc, &rect16, (HBRUSH16)hbrush );
346 /***********************************************************************
347 * SetPixel16 (GDI.31)
349 COLORREF WINAPI SetPixel16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
351 return SetPixel32( hdc, x, y, color );
355 /***********************************************************************
356 * SetPixel32 (GDI32.327)
358 COLORREF WINAPI SetPixel32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
360 DC * dc = DC_GetDCPtr( hdc );
362 if (!dc || !dc->funcs->pSetPixel) return 0;
363 return dc->funcs->pSetPixel(dc,x,y,color);
366 /***********************************************************************
367 * SetPixel32 (GDI32.329)
369 BOOL32 WINAPI SetPixelV32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
371 DC * dc = DC_GetDCPtr( hdc );
373 if (!dc || !dc->funcs->pSetPixel) return FALSE;
374 dc->funcs->pSetPixel(dc,x,y,color);
375 return TRUE;
378 /***********************************************************************
379 * GetPixel16 (GDI.83)
381 COLORREF WINAPI GetPixel16( HDC16 hdc, INT16 x, INT16 y )
383 return GetPixel32( hdc, x, y );
387 /***********************************************************************
388 * GetPixel32 (GDI32.211)
390 COLORREF WINAPI GetPixel32( HDC32 hdc, INT32 x, INT32 y )
392 DC * dc = DC_GetDCPtr( hdc );
394 if (!dc) return 0;
395 #ifdef SOLITAIRE_SPEED_HACK
396 return 0;
397 #endif
399 /* FIXME: should this be in the graphics driver? */
400 if (!PtVisible32( hdc, x, y )) return 0;
401 if (!dc || !dc->funcs->pGetPixel) return 0;
402 return dc->funcs->pGetPixel(dc,x,y);
406 /***********************************************************************
407 * PaintRgn16 (GDI.43)
409 BOOL16 WINAPI PaintRgn16( HDC16 hdc, HRGN16 hrgn )
411 return PaintRgn32( hdc, hrgn );
415 /***********************************************************************
416 * PaintRgn32 (GDI32.259)
418 BOOL32 WINAPI PaintRgn32( HDC32 hdc, HRGN32 hrgn )
420 DC * dc = DC_GetDCPtr( hdc );
422 return dc && dc->funcs->pPaintRgn &&
423 dc->funcs->pPaintRgn(dc,hrgn);
427 /***********************************************************************
428 * FillRgn16 (GDI.40)
430 BOOL16 WINAPI FillRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush )
432 return FillRgn32( hdc, hrgn, hbrush );
436 /***********************************************************************
437 * FillRgn32 (GDI32.101)
439 BOOL32 WINAPI FillRgn32( HDC32 hdc, HRGN32 hrgn, HBRUSH32 hbrush )
441 BOOL32 retval;
442 HBRUSH32 prevBrush = SelectObject32( hdc, hbrush );
443 if (!prevBrush) return FALSE;
444 retval = PaintRgn32( hdc, hrgn );
445 SelectObject32( hdc, prevBrush );
446 return retval;
450 /***********************************************************************
451 * FrameRgn16 (GDI.41)
453 BOOL16 WINAPI FrameRgn16( HDC16 hdc, HRGN16 hrgn, HBRUSH16 hbrush,
454 INT16 nWidth, INT16 nHeight )
456 return FrameRgn32( hdc, hrgn, hbrush, nWidth, nHeight );
460 /***********************************************************************
461 * FrameRgn32 (GDI32.105)
463 BOOL32 WINAPI FrameRgn32( HDC32 hdc, HRGN32 hrgn, HBRUSH32 hbrush,
464 INT32 nWidth, INT32 nHeight )
466 HRGN32 tmp = CreateRectRgn32( 0, 0, 0, 0 );
467 if(!REGION_FrameRgn( tmp, hrgn, nWidth, nHeight )) return FALSE;
468 FillRgn32( hdc, tmp, hbrush );
469 DeleteObject32( tmp );
470 return TRUE;
474 /***********************************************************************
475 * InvertRgn16 (GDI.42)
477 BOOL16 WINAPI InvertRgn16( HDC16 hdc, HRGN16 hrgn )
479 return InvertRgn32( hdc, hrgn );
483 /***********************************************************************
484 * InvertRgn32 (GDI32.246)
486 BOOL32 WINAPI InvertRgn32( HDC32 hdc, HRGN32 hrgn )
488 HBRUSH32 prevBrush = SelectObject32( hdc, GetStockObject32(BLACK_BRUSH) );
489 INT32 prevROP = SetROP232( hdc, R2_NOT );
490 BOOL32 retval = PaintRgn32( hdc, hrgn );
491 SelectObject32( hdc, prevBrush );
492 SetROP232( hdc, prevROP );
493 return retval;
497 /***********************************************************************
498 * DrawFocusRect16 (USER.466)
500 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
502 RECT32 rect32;
503 CONV_RECT16TO32( rc, &rect32 );
504 DrawFocusRect32( hdc, &rect32 );
508 /***********************************************************************
509 * DrawFocusRect32 (USER32.155)
511 * FIXME: PatBlt(PATINVERT) with background brush.
513 void WINAPI DrawFocusRect32( HDC32 hdc, const RECT32* rc )
515 HPEN32 hOldPen, hnewPen;
516 INT32 oldDrawMode, oldBkMode;
517 INT32 left, top, right, bottom;
519 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
520 if (!dc) return;
522 left = XLPTODP( dc, rc->left );
523 top = YLPTODP( dc, rc->top );
524 right = XLPTODP( dc, rc->right );
525 bottom = YLPTODP( dc, rc->bottom );
527 hnewPen = CreatePen32(PS_DOT, 1, GetSysColor32(COLOR_WINDOWTEXT) );
528 hOldPen = SelectObject32( hdc, hnewPen );
529 oldDrawMode = SetROP232(hdc, R2_XORPEN);
530 oldBkMode = SetBkMode32(hdc, TRANSPARENT);
532 /* Hack: make sure the XORPEN operation has an effect */
533 dc->u.x.pen.pixel = (1 << screenDepth) - 1;
535 if (DC_SetupGCForPen( dc ))
536 XDrawRectangle( display, dc->u.x.drawable, dc->u.x.gc,
537 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
538 right-left-1, bottom-top-1 );
540 SetBkMode32(hdc, oldBkMode);
541 SetROP232(hdc, oldDrawMode);
542 SelectObject32(hdc, hOldPen);
543 DeleteObject32(hnewPen);
547 /**********************************************************************
548 * Polyline16 (GDI.37)
550 BOOL16 WINAPI Polyline16( HDC16 hdc, LPPOINT16 pt, INT16 count )
552 register int i;
553 BOOL16 ret;
554 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
555 count*sizeof(POINT32) );
557 if (!pt32) return FALSE;
558 for (i=count;i--;) CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
559 ret = Polyline32(hdc,pt32,count);
560 HeapFree( GetProcessHeap(), 0, pt32 );
561 return ret;
565 /**********************************************************************
566 * Polyline32 (GDI32.276)
568 BOOL32 WINAPI Polyline32( HDC32 hdc, const LPPOINT32 pt, INT32 count )
570 DC * dc = DC_GetDCPtr( hdc );
572 return dc && dc->funcs->pPolyline &&
573 dc->funcs->pPolyline(dc,pt,count);
577 /**********************************************************************
578 * Polygon16 (GDI.36)
580 BOOL16 WINAPI Polygon16( HDC16 hdc, LPPOINT16 pt, INT16 count )
582 register int i;
583 BOOL32 ret;
584 LPPOINT32 pt32 = (LPPOINT32)HeapAlloc( GetProcessHeap(), 0,
585 count*sizeof(POINT32) );
587 if (!pt32) return FALSE;
588 for (i=count;i--;) CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
589 ret = Polygon32(hdc,pt32,count);
590 HeapFree( GetProcessHeap(), 0, pt32 );
591 return ret;
595 /**********************************************************************
596 * Polygon32 (GDI32.275)
598 BOOL32 WINAPI Polygon32( HDC32 hdc, LPPOINT32 pt, INT32 count )
600 DC * dc = DC_GetDCPtr( hdc );
602 return dc && dc->funcs->pPolygon &&
603 dc->funcs->pPolygon(dc,pt,count);
607 /**********************************************************************
608 * PolyPolygon16 (GDI.450)
610 BOOL16 WINAPI PolyPolygon16( HDC16 hdc, LPPOINT16 pt, LPINT16 counts,
611 UINT16 polygons )
613 int i,nrpts;
614 LPPOINT32 pt32;
615 LPINT32 counts32;
616 BOOL16 ret;
618 nrpts=0;
619 for (i=polygons;i--;)
620 nrpts+=counts[i];
621 pt32 = (LPPOINT32)HEAP_xalloc( GetProcessHeap(), 0, sizeof(POINT32)*nrpts);
622 for (i=nrpts;i--;)
623 CONV_POINT16TO32(&(pt[i]),&(pt32[i]));
624 counts32 = (LPINT32)HEAP_xalloc( GetProcessHeap(), 0,
625 polygons*sizeof(INT32) );
626 for (i=polygons;i--;) counts32[i]=counts[i];
628 ret = PolyPolygon32(hdc,pt32,counts32,polygons);
629 HeapFree( GetProcessHeap(), 0, counts32 );
630 HeapFree( GetProcessHeap(), 0, pt32 );
631 return ret;
634 /**********************************************************************
635 * PolyPolygon32 (GDI.450)
637 BOOL32 WINAPI PolyPolygon32( HDC32 hdc, LPPOINT32 pt, LPINT32 counts,
638 UINT32 polygons )
640 DC * dc = DC_GetDCPtr( hdc );
642 return dc && dc->funcs->pPolyPolygon &&
643 dc->funcs->pPolyPolygon(dc,pt,counts,polygons);
646 /**********************************************************************
647 * ExtFloodFill16 (GDI.372)
649 BOOL16 WINAPI ExtFloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color,
650 UINT16 fillType )
652 return ExtFloodFill32( hdc, x, y, color, fillType );
656 /**********************************************************************
657 * ExtFloodFill32 (GDI32.96)
659 BOOL32 WINAPI ExtFloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color,
660 UINT32 fillType )
662 DC *dc = DC_GetDCPtr( hdc );
664 return dc && dc->funcs->pExtFloodFill &&
665 dc->funcs->pExtFloodFill(dc,x,y,color,fillType);
669 /**********************************************************************
670 * FloodFill16 (GDI.25)
672 BOOL16 WINAPI FloodFill16( HDC16 hdc, INT16 x, INT16 y, COLORREF color )
674 return ExtFloodFill32( hdc, x, y, color, FLOODFILLBORDER );
678 /**********************************************************************
679 * FloodFill32 (GDI32.104)
681 BOOL32 WINAPI FloodFill32( HDC32 hdc, INT32 x, INT32 y, COLORREF color )
683 return ExtFloodFill32( hdc, x, y, color, FLOODFILLBORDER );
687 /**********************************************************************
688 * DrawAnimatedRects32 (USER32.153)
690 BOOL32 WINAPI DrawAnimatedRects32( HWND32 hwnd, int idAni,
691 const LPRECT32 lprcFrom,
692 const LPRECT32 lprcTo )
694 fprintf( stdnimp,"DrawAnimatedRects32(%x,%d,%p,%p), empty stub!\n",
695 hwnd, idAni, lprcFrom, lprcTo );
696 return TRUE;
700 /**********************************************************************
701 * PAINTING_DrawStateJam
703 * Jams in the requested type in the dc
705 static BOOL32 PAINTING_DrawStateJam(HDC32 hdc, UINT32 opcode,
706 DRAWSTATEPROC32 func, LPARAM lp, WPARAM32 wp,
707 LPRECT32 rc, UINT32 dtflags,
708 BOOL32 unicode, BOOL32 _32bit)
710 HDC32 memdc;
711 HBITMAP32 hbmsave;
712 BOOL32 retval;
713 INT32 cx = rc->right - rc->left;
714 INT32 cy = rc->bottom - rc->top;
716 switch(opcode)
718 case DST_TEXT:
719 case DST_PREFIXTEXT:
720 if(unicode)
721 return DrawText32W(hdc, (LPWSTR)lp, (INT32)wp, rc, dtflags);
722 else if(_32bit)
723 return DrawText32A(hdc, (LPSTR)lp, (INT32)wp, rc, dtflags);
724 else
725 return DrawText32A(hdc, (LPSTR)PTR_SEG_TO_LIN(lp), (INT32)wp, rc, dtflags);
727 case DST_ICON:
728 return DrawIcon32(hdc, rc->left, rc->top, (HICON32)lp);
730 case DST_BITMAP:
731 memdc = CreateCompatibleDC32(hdc);
732 if(!memdc) return FALSE;
733 hbmsave = (HBITMAP32)SelectObject32(memdc, (HBITMAP32)lp);
734 if(!hbmsave)
736 DeleteDC32(memdc);
737 return FALSE;
739 retval = BitBlt32(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
740 SelectObject32(memdc, hbmsave);
741 DeleteDC32(memdc);
742 return retval;
744 case DST_COMPLEX:
745 if(func)
746 if(_32bit)
747 return func(hdc, lp, wp, cx, cy);
748 else
749 return (BOOL32)((DRAWSTATEPROC16)func)((HDC16)hdc, (LPARAM)lp, (WPARAM16)wp, (INT16)cx, (INT16)cy);
750 else
751 return FALSE;
753 return FALSE;
756 /**********************************************************************
757 * PAINTING_DrawState32()
759 static BOOL32 PAINTING_DrawState32(HDC32 hdc, HBRUSH32 hbr,
760 DRAWSTATEPROC32 func, LPARAM lp, WPARAM32 wp,
761 INT32 x, INT32 y, INT32 cx, INT32 cy,
762 UINT32 flags, BOOL32 unicode, BOOL32 _32bit)
764 HBITMAP32 hbm, hbmsave;
765 HFONT32 hfsave;
766 HBRUSH32 hbsave;
767 HDC32 memdc;
768 RECT32 rc;
769 UINT32 dtflags = DT_NOCLIP;
770 COLORREF fg, bg;
771 UINT32 opcode = flags & 0xf;
772 INT32 len = wp;
773 BOOL32 retval, tmp;
775 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
777 if(unicode)
778 len = lstrlen32W((LPWSTR)lp);
779 else if(_32bit)
780 len = lstrlen32A((LPSTR)lp);
781 else
782 len = lstrlen32A((LPSTR)PTR_SEG_TO_LIN(lp));
785 /* Find out what size the image has if not given by caller */
786 if(!cx || !cy)
788 SIZE32 s;
789 CURSORICONINFO *ici;
790 BITMAPOBJ *bmp;
792 switch(opcode)
794 case DST_TEXT:
795 case DST_PREFIXTEXT:
796 if(unicode)
797 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
798 else if(_32bit)
799 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
800 else
801 retval = GetTextExtentPoint32A(hdc, PTR_SEG_TO_LIN(lp), len, &s);
802 if(!retval) return FALSE;
803 break;
805 case DST_ICON:
806 ici = (CURSORICONINFO *)GlobalLock16((HGLOBAL16)lp);
807 if(!ici) return FALSE;
808 s.cx = ici->nWidth;
809 s.cy = ici->nHeight;
810 GlobalUnlock16((HGLOBAL16)lp);
811 break;
813 case DST_BITMAP:
814 bmp = (BITMAPOBJ *)GDI_GetObjPtr((HBITMAP16)lp, BITMAP_MAGIC);
815 if(!bmp) return FALSE;
816 s.cx = bmp->bitmap.bmWidth;
817 s.cy = bmp->bitmap.bmHeight;
818 break;
820 case DST_COMPLEX: /* cx and cy must be set in this mode */
821 return FALSE;
824 if(!cx) cx = s.cx;
825 if(!cy) cy = s.cy;
828 rc.left = x;
829 rc.top = y;
830 rc.right = x + cx;
831 rc.bottom = y + cy;
833 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
834 dtflags |= DT_RIGHT;
835 if(opcode == DST_TEXT)
836 dtflags |= DT_NOPREFIX;
838 /* For DSS_NORMAL we just jam in the image and return */
839 if((flags & 0x7ff0) == DSS_NORMAL)
841 return PAINTING_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
844 /* For all other states we need to convert the image to B/W in a local bitmap */
845 /* before it is displayed */
846 fg = SetTextColor32(hdc, RGB(0, 0, 0));
847 bg = SetBkColor32(hdc, RGB(255, 255, 255));
848 hbm = NULL; hbmsave = NULL; memdc = NULL; memdc = NULL; hbsave = NULL;
849 retval = FALSE; /* assume failure */
851 /* From here on we must use "goto cleanup" when something goes wrong */
852 hbm = CreateBitmap32(cx, cy, 1, 1, NULL);
853 if(!hbm) goto cleanup;
854 memdc = CreateCompatibleDC32(hdc);
855 if(!memdc) goto cleanup;
856 hbmsave = (HBITMAP32)SelectObject32(memdc, hbm);
857 if(!hbmsave) goto cleanup;
858 rc.left = rc.top = 0;
859 rc.right = cx;
860 rc.bottom = cy;
861 if(!FillRect32(memdc, &rc, (HBRUSH32)GetStockObject32(WHITE_BRUSH))) goto cleanup;
862 SetBkColor32(memdc, RGB(255, 255, 255));
863 SetTextColor32(memdc, RGB(0, 0, 0));
864 hfsave = (HFONT32)SelectObject32(memdc, GetCurrentObject(hdc, OBJ_FONT));
865 if(!hfsave && (opcode == DST_TEXT || opcode == DST_PREFIXTEXT)) goto cleanup;
866 tmp = PAINTING_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
867 if(hfsave) SelectObject32(memdc, hfsave);
868 if(!tmp) goto cleanup;
870 /* These states cause the image to be dithered */
871 if(flags & (DSS_UNION|DSS_DISABLED))
873 hbsave = (HBRUSH32)SelectObject32(memdc, CACHE_GetPattern55AABrush());
874 if(!hbsave) goto cleanup;
875 tmp = PatBlt32(memdc, 0, 0, cx, cy, 0x00FA0089);
876 if(hbsave) SelectObject32(memdc, hbsave);
877 if(!tmp) goto cleanup;
880 hbsave = (HBRUSH32)SelectObject32(hdc, hbr ? hbr : GetStockObject32(WHITE_BRUSH));
881 if(!hbsave) goto cleanup;
883 if(!BitBlt32(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
885 /* DSS_DEFAULT makes the image boldface */
886 if(flags & DSS_DEFAULT)
888 if(!BitBlt32(hdc, x+1, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
891 retval = TRUE; /* We succeeded */
893 cleanup:
894 SetTextColor32(hdc, fg);
895 SetBkColor32(hdc, bg);
897 if(hbsave) SelectObject32(hdc, hbsave);
898 if(hbmsave) SelectObject32(memdc, hbmsave);
899 if(hbm) DeleteObject32(hbm);
900 if(memdc) DeleteDC32(memdc);
902 return retval;
905 /**********************************************************************
906 * DrawState32A() (USER32.162)
908 BOOL32 WINAPI DrawState32A(HDC32 hdc, HBRUSH32 hbr,
909 DRAWSTATEPROC32 func, LPARAM ldata, WPARAM32 wdata,
910 INT32 x, INT32 y, INT32 cx, INT32 cy, UINT32 flags)
912 return PAINTING_DrawState32(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE, TRUE);
915 /**********************************************************************
916 * DrawState32W() (USER32.163)
918 BOOL32 WINAPI DrawState32W(HDC32 hdc, HBRUSH32 hbr,
919 DRAWSTATEPROC32 func, LPARAM ldata, WPARAM32 wdata,
920 INT32 x, INT32 y, INT32 cx, INT32 cy, UINT32 flags)
922 return PAINTING_DrawState32(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE, TRUE);
925 /**********************************************************************
926 * DrawState16() (USER.449)
928 BOOL16 WINAPI DrawState16(HDC16 hdc, HBRUSH16 hbr,
929 DRAWSTATEPROC16 func, LPARAM ldata, WPARAM16 wdata,
930 INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags)
932 return PAINTING_DrawState32(hdc, hbr, (DRAWSTATEPROC32)func, ldata, wdata, x, y, cx, cy, flags, FALSE, FALSE);