2 * Window painting functions
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
11 #include "wine/winuser16.h"
12 #include "wine/unicode.h"
19 #include "debugtools.h"
21 DEFAULT_DEBUG_CHANNEL(win);
22 DECLARE_DEBUG_CHANNEL(nonclient);
24 /* client rect in window coordinates */
26 #define GETCLIENTRECTW( wnd, r ) (r).left = (wnd)->rectClient.left - (wnd)->rectWindow.left; \
27 (r).top = (wnd)->rectClient.top - (wnd)->rectWindow.top; \
28 (r).right = (wnd)->rectClient.right - (wnd)->rectWindow.left; \
29 (r).bottom = (wnd)->rectClient.bottom - (wnd)->rectWindow.top
31 /* PAINT_RedrawWindow() control flags */
32 #define RDW_EX_DELAY_NCPAINT 0x0020
34 /* WIN_UpdateNCRgn() flags */
35 #define UNC_CHECK 0x0001
36 #define UNC_ENTIRE 0x0002
37 #define UNC_REGION 0x0004
38 #define UNC_UPDATE 0x0008
39 #define UNC_DELAY_NCPAINT 0x0010
40 #define UNC_IN_BEGINPAINT 0x0020
43 #define COLOR_MAX COLOR_GRADIENTINACTIVECAPTION
45 /* Last CTLCOLOR id */
46 #define CTLCOLOR_MAX CTLCOLOR_STATIC
49 /***********************************************************************
50 * WIN_HaveToDelayNCPAINT
52 * Currently, in the Wine painting mechanism, the WM_NCPAINT message
53 * is generated as soon as a region intersecting the non-client area
54 * of a window is invalidated.
56 * This technique will work fine for all windows whose parents
57 * have the WS_CLIPCHILDREN style. When the parents have that style,
58 * they are not going to override the contents of their children.
59 * However, when the parent doesn't have that style, Windows relies
60 * on a "painter's algorithm" to display the contents of the windows.
61 * That is, windows are painted from back to front. This includes the
64 * This method looks at the current state of a window to determine
65 * if the sending of the WM_NCPAINT message should be delayed until
66 * the BeginPaint call.
69 * wndPtr - A Locked window pointer to the window we're
71 * uncFlags - This is the flag passed to the WIN_UpdateNCRgn
72 * function. This is a shortcut for the cases when
73 * we already know when to avoid scanning all the
74 * parents of a window. If you already know that this
75 * window's NCPAINT should be delayed, set the
76 * UNC_DELAY_NCPAINT flag for this parameter.
78 * This shortcut behavior is implemented in the
82 static BOOL WIN_HaveToDelayNCPAINT(
86 WND* parentWnd = NULL;
89 * Test the shortcut first. (duh)
91 if (uncFlags & UNC_DELAY_NCPAINT)
95 * The UNC_IN_BEGINPAINT flag is set in the BeginPaint
96 * method only. This is another shortcut to avoid going
97 * up the parent's chain of the window to finally
98 * figure-out that none of them has an invalid region.
100 if (uncFlags & UNC_IN_BEGINPAINT)
104 * Scan all the parents of this window to find a window
105 * that doesn't have the WS_CLIPCHILDREN style and that
106 * has an invalid region.
108 parentWnd = WIN_LockWndPtr(wndPtr->parent);
110 while (parentWnd!=NULL)
112 if ( ((parentWnd->dwStyle & WS_CLIPCHILDREN) == 0) &&
113 (parentWnd->hrgnUpdate != 0) )
115 WIN_ReleaseWndPtr(parentWnd);
119 WIN_UpdateWndPtr(&parentWnd, parentWnd->parent);
122 WIN_ReleaseWndPtr(parentWnd);
127 /***********************************************************************
131 * Send WM_NCPAINT if required (when nonclient is invalid or UNC_ENTIRE flag is set)
132 * Crop hrgnUpdate to a client rect, especially if it 1.
133 * If UNC_REGION is set return update region for the client rect.
135 * NOTE: UNC_REGION is mainly for the RDW_Paint() chunk that sends WM_ERASEBKGND message.
136 * The trick is that when the returned region handle may be different from hRgn.
137 * In this case the old hRgn must be considered gone. BUT, if the returned value
138 * is 1 then the hRgn is preserved and RDW_Paint() will have to get
139 * a DC without extra clipping region.
141 static HRGN WIN_UpdateNCRgn(WND* wnd, HRGN hRgn, UINT uncFlags )
147 TRACE_(nonclient)("hwnd %04x [%04x] hrgn %04x, unc %04x, ncf %i\n",
148 wnd->hwndSelf, wnd->hrgnUpdate, hRgn, uncFlags, wnd->flags & WIN_NEEDS_NCPAINT);
150 /* desktop window doesn't have a nonclient area */
151 if(wnd == WIN_GetDesktop())
153 wnd->flags &= ~WIN_NEEDS_NCPAINT;
154 if( wnd->hrgnUpdate > 1 )
155 hrgnRet = REGION_CropRgn( hRgn, wnd->hrgnUpdate, NULL, NULL );
158 hrgnRet = wnd->hrgnUpdate;
160 WIN_ReleaseDesktop();
163 WIN_ReleaseDesktop();
165 if ((wnd->hwndSelf == GetForegroundWindow()) &&
166 !(wnd->flags & WIN_NCACTIVATED) )
168 wnd->flags |= WIN_NCACTIVATED;
169 uncFlags |= UNC_ENTIRE;
173 * If the window's non-client area needs to be painted,
175 if ( ( wnd->flags & WIN_NEEDS_NCPAINT ) &&
176 !WIN_HaveToDelayNCPAINT(wnd, uncFlags) )
180 wnd->flags &= ~WIN_NEEDS_NCPAINT;
181 GETCLIENTRECTW( wnd, r );
183 TRACE_(nonclient)( "\tclient box (%i,%i-%i,%i), hrgnUpdate %04x\n",
184 r.left, r.top, r.right, r.bottom, wnd->hrgnUpdate );
185 if( wnd->hrgnUpdate > 1 )
187 /* Check if update rgn overlaps with nonclient area */
189 GetRgnBox( wnd->hrgnUpdate, &r2 );
190 UnionRect( &r3, &r2, &r );
191 if( r3.left != r.left || r3.top != r.top ||
192 r3.right != r.right || r3.bottom != r.bottom ) /* it does */
194 /* crop hrgnUpdate, save old one in hClip - the only
195 * case that places a valid region handle in hClip */
197 hClip = wnd->hrgnUpdate;
198 wnd->hrgnUpdate = REGION_CropRgn( hRgn, hClip, &r, NULL );
199 if( uncFlags & UNC_REGION ) hrgnRet = hClip;
202 if( uncFlags & UNC_CHECK )
204 GetRgnBox( wnd->hrgnUpdate, &r3 );
205 if( IsRectEmpty( &r3 ) )
207 /* delete the update region since all invalid
208 * parts were in the nonclient area */
210 DeleteObject( wnd->hrgnUpdate );
212 if(!(wnd->flags & WIN_INTERNAL_PAINT))
213 QUEUE_DecPaintCount( wnd->hmemTaskQ );
215 wnd->flags &= ~WIN_NEEDS_ERASEBKGND;
219 if(!hClip && wnd->hrgnUpdate ) goto copyrgn;
222 if( wnd->hrgnUpdate == 1 )/* entire window */
224 if( uncFlags & UNC_UPDATE ) wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
225 if( uncFlags & UNC_REGION ) hrgnRet = 1;
226 uncFlags |= UNC_ENTIRE;
229 else /* no WM_NCPAINT unless forced */
231 if( wnd->hrgnUpdate > 1 )
234 if( uncFlags & UNC_REGION )
235 hrgnRet = REGION_CropRgn( hRgn, wnd->hrgnUpdate, NULL, NULL );
238 if( wnd->hrgnUpdate == 1 && (uncFlags & UNC_UPDATE) )
240 GETCLIENTRECTW( wnd, r );
241 wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
242 if( uncFlags & UNC_REGION ) hrgnRet = 1;
246 if(!hClip && (uncFlags & UNC_ENTIRE) )
248 /* still don't do anything if there is no nonclient area */
249 hClip = (memcmp( &wnd->rectWindow, &wnd->rectClient, sizeof(RECT) ) != 0);
252 if( hClip ) /* NOTE: WM_NCPAINT allows wParam to be 1 */
254 if ( hClip == hrgnRet && hrgnRet > 1 ) {
255 hClip = CreateRectRgn( 0, 0, 0, 0 );
256 CombineRgn( hClip, hrgnRet, 0, RGN_COPY );
259 SendMessageA( wnd->hwndSelf, WM_NCPAINT, hClip, 0L );
260 if( (hClip > 1) && (hClip != hRgn) && (hClip != hrgnRet) )
261 DeleteObject( hClip );
263 * Since all Window locks are suspended while processing the WM_NCPAINT
264 * we want to make sure the window still exists before continuing.
266 if (!IsWindow(wnd->hwndSelf))
268 DeleteObject(hrgnRet);
273 TRACE_(nonclient)("returning %04x (hClip = %04x, hrgnUpdate = %04x)\n", hrgnRet, hClip, wnd->hrgnUpdate );
279 /***********************************************************************
280 * BeginPaint (USER.39)
282 HDC16 WINAPI BeginPaint16( HWND16 hwnd, LPPAINTSTRUCT16 lps )
286 BeginPaint( hwnd, &ps );
288 lps->fErase = ps.fErase;
289 lps->rcPaint.top = ps.rcPaint.top;
290 lps->rcPaint.left = ps.rcPaint.left;
291 lps->rcPaint.right = ps.rcPaint.right;
292 lps->rcPaint.bottom = ps.rcPaint.bottom;
293 lps->fRestore = ps.fRestore;
294 lps->fIncUpdate = ps.fIncUpdate;
299 /***********************************************************************
300 * BeginPaint (USER32.@)
302 HDC WINAPI BeginPaint( HWND hwnd, PAINTSTRUCT *lps )
306 RECT clipRect, clientRect;
307 WND *wndPtr = WIN_FindWndPtr( hwnd );
308 if (!wndPtr) return 0;
310 bIcon = (wndPtr->dwStyle & WS_MINIMIZE && GetClassWord(wndPtr->hwndSelf, GCW_HICON));
312 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
314 /* send WM_NCPAINT and make sure hrgnUpdate is a valid rgn handle */
315 WIN_UpdateNCRgn( wndPtr, 0, UNC_UPDATE | UNC_IN_BEGINPAINT);
318 * Make sure the window is still a window. All window locks are suspended
319 * when the WM_NCPAINT is sent.
321 if (!IsWindow(wndPtr->hwndSelf))
323 WIN_ReleaseWndPtr(wndPtr);
327 if( ((hrgnUpdate = wndPtr->hrgnUpdate) != 0) || (wndPtr->flags & WIN_INTERNAL_PAINT))
328 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
330 wndPtr->hrgnUpdate = 0;
331 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
335 TRACE("hrgnUpdate = %04x, \n", hrgnUpdate);
337 if (GetClassLongA(wndPtr->hwndSelf, GCL_STYLE) & CS_PARENTDC)
339 /* Don't clip the output to the update region for CS_PARENTDC window */
341 DeleteObject(hrgnUpdate);
342 lps->hdc = GetDCEx( hwnd, 0, DCX_WINDOWPAINT | DCX_USESTYLE |
343 (bIcon ? DCX_WINDOW : 0) );
347 if( hrgnUpdate ) /* convert to client coordinates */
348 OffsetRgn( hrgnUpdate, wndPtr->rectWindow.left - wndPtr->rectClient.left,
349 wndPtr->rectWindow.top - wndPtr->rectClient.top );
350 lps->hdc = GetDCEx(hwnd, hrgnUpdate, DCX_INTERSECTRGN |
351 DCX_WINDOWPAINT | DCX_USESTYLE | (bIcon ? DCX_WINDOW : 0) );
352 /* ReleaseDC() in EndPaint() will delete the region */
355 TRACE("hdc = %04x\n", lps->hdc);
359 WARN("GetDCEx() failed in BeginPaint(), hwnd=%04x\n", hwnd);
360 WIN_ReleaseWndPtr(wndPtr);
364 /* It is possible that the clip box is bigger than the window itself,
365 if CS_PARENTDC flag is set. Windows never return a paint rect bigger
366 than the window itself, so we need to intersect the cliprect with
369 GetClientRect( hwnd, &clientRect );
371 GetClipBox( lps->hdc, &clipRect );
372 LPtoDP(lps->hdc, (LPPOINT)&clipRect, 2); /* GetClipBox returns LP */
374 IntersectRect(&lps->rcPaint, &clientRect, &clipRect);
375 DPtoLP(lps->hdc, (LPPOINT)&lps->rcPaint, 2); /* we must return LP */
377 TRACE("box = (%i,%i - %i,%i)\n", lps->rcPaint.left, lps->rcPaint.top,
378 lps->rcPaint.right, lps->rcPaint.bottom );
380 if (wndPtr->flags & WIN_NEEDS_ERASEBKGND)
382 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
383 lps->fErase = !SendMessageA(hwnd, (bIcon) ? WM_ICONERASEBKGND : WM_ERASEBKGND,
384 (WPARAM16)lps->hdc, 0 );
386 else lps->fErase = TRUE;
388 WIN_ReleaseWndPtr(wndPtr);
393 /***********************************************************************
396 BOOL16 WINAPI EndPaint16( HWND16 hwnd, const PAINTSTRUCT16* lps )
398 ReleaseDC16( hwnd, lps->hdc );
404 /***********************************************************************
405 * EndPaint (USER32.@)
407 BOOL WINAPI EndPaint( HWND hwnd, const PAINTSTRUCT *lps )
409 ReleaseDC( hwnd, lps->hdc );
415 /***********************************************************************
416 * FillWindow (USER.324)
418 void WINAPI FillWindow16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc, HBRUSH16 hbrush )
422 GetClientRect( hwnd, &rect );
423 DPtoLP( hdc, (LPPOINT)&rect, 2 );
424 CONV_RECT32TO16( &rect, &rc16 );
425 PaintRect16( hwndParent, hwnd, hdc, hbrush, &rc16 );
429 /***********************************************************************
430 * PAINT_GetControlBrush
432 static HBRUSH16 PAINT_GetControlBrush( HWND hParent, HWND hWnd, HDC16 hDC, UINT16 ctlType )
434 HBRUSH16 bkgBrush = (HBRUSH16)SendMessageA( hParent, WM_CTLCOLORMSGBOX + ctlType,
435 (WPARAM)hDC, (LPARAM)hWnd );
436 if( !IsGDIObject16(bkgBrush) )
437 bkgBrush = DEFWND_ControlColor( hDC, ctlType );
442 /***********************************************************************
443 * PaintRect (USER.325)
445 void WINAPI PaintRect16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc,
446 HBRUSH16 hbrush, const RECT16 *rect)
448 if( hbrush <= CTLCOLOR_MAX )
451 hbrush = PAINT_GetControlBrush( hwndParent, hwnd, hdc, (UINT16)hbrush );
456 FillRect16( hdc, rect, hbrush );
460 /***********************************************************************
461 * GetControlBrush (USER.326)
463 HBRUSH16 WINAPI GetControlBrush16( HWND16 hwnd, HDC16 hdc, UINT16 ctlType )
465 WND* wndPtr = WIN_FindWndPtr( hwnd );
468 if((ctlType <= CTLCOLOR_MAX) && wndPtr )
471 if( wndPtr->dwStyle & WS_POPUP ) parent = WIN_LockWndPtr(wndPtr->owner);
472 else parent = WIN_LockWndPtr(wndPtr->parent);
473 if( !parent ) parent = wndPtr;
474 retvalue = (HBRUSH16)PAINT_GetControlBrush( parent->hwndSelf, hwnd, hdc, ctlType );
475 WIN_ReleaseWndPtr(parent);
478 retvalue = (HBRUSH16)0;
480 WIN_ReleaseWndPtr(wndPtr);
485 /***********************************************************************
486 * RDW_ValidateParent [RDW_UpdateRgns() helper]
488 * Validate the portions of parents that are covered by a validated child
491 static void RDW_ValidateParent(WND *wndChild)
493 WND *wndParent = WIN_LockWndPtr(wndChild->parent);
494 WND *wndDesktop = WIN_GetDesktop();
497 if (wndChild->hrgnUpdate == 1 ) {
501 r.right = wndChild->rectWindow.right - wndChild->rectWindow.left;
502 r.bottom = wndChild->rectWindow.bottom - wndChild->rectWindow.top;
503 hrg = CreateRectRgnIndirect( &r );
505 hrg = wndChild->hrgnUpdate;
507 while ((wndParent) && (wndParent != wndDesktop) ) {
508 if (!(wndParent->dwStyle & WS_CLIPCHILDREN))
510 if (wndParent->hrgnUpdate != 0)
513 RECT rect, rectParent;
514 if( wndParent->hrgnUpdate == 1 )
520 r.right = wndParent->rectWindow.right - wndParent->rectWindow.left;
521 r.bottom = wndParent->rectWindow.bottom - wndParent->rectWindow.top;
523 wndParent->hrgnUpdate = CreateRectRgnIndirect( &r );
525 /* we must offset the child region by the offset of the child rect in the parent */
526 GetWindowRect(wndParent->hwndSelf, &rectParent);
527 GetWindowRect(wndChild->hwndSelf, &rect);
528 ptOffset.x = rect.left - rectParent.left;
529 ptOffset.y = rect.top - rectParent.top;
530 OffsetRgn( hrg, ptOffset.x, ptOffset.y );
531 CombineRgn( wndParent->hrgnUpdate, wndParent->hrgnUpdate, hrg, RGN_DIFF );
532 OffsetRgn( hrg, -ptOffset.x, -ptOffset.y );
535 WIN_UpdateWndPtr(&wndParent, wndParent->parent);
537 if (hrg != wndChild->hrgnUpdate) DeleteObject( hrg );
538 WIN_ReleaseWndPtr(wndParent);
539 WIN_ReleaseDesktop();
542 /***********************************************************************
543 * RDW_UpdateRgns [RedrawWindow() helper]
545 * Walks the window tree and adds/removes parts of the hRgn to/from update
546 * regions of windows that overlap it. Also, manages internal paint flags.
548 * NOTE: Walks the window tree so the caller must lock it.
549 * MUST preserve hRgn (can modify but then has to restore).
551 static void RDW_UpdateRgns( WND* wndPtr, HRGN hRgn, UINT flags, BOOL firstRecursLevel )
554 * Called only when one of the following is set:
555 * (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT)
558 BOOL bHadOne = wndPtr->hrgnUpdate && hRgn;
559 BOOL bChildren = ( wndPtr->child && !(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE)
560 && ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) );
565 r.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
566 r.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
568 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", wndPtr->hwndSelf, wndPtr->hrgnUpdate, hRgn, flags );
570 if( flags & RDW_INVALIDATE )
574 switch( wndPtr->hrgnUpdate )
577 CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_OR );
580 wndPtr->hrgnUpdate = REGION_CropRgn( wndPtr->hrgnUpdate,
581 wndPtr->hrgnUpdate ? wndPtr->hrgnUpdate : hRgn,
585 GetRgnBox( wndPtr->hrgnUpdate, &r );
586 if( IsRectEmpty( &r ) )
588 DeleteObject( wndPtr->hrgnUpdate );
589 wndPtr->hrgnUpdate = 0;
594 case 1: /* already an entire window */
600 if( wndPtr->hrgnUpdate > 1 )
601 DeleteObject( wndPtr->hrgnUpdate );
602 wndPtr->hrgnUpdate = 1;
605 hRgn = wndPtr->hrgnUpdate; /* this is a trick that depends on code in PAINT_RedrawWindow() */
607 if( !bHadOne && !(wndPtr->flags & WIN_INTERNAL_PAINT) )
608 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
610 if (flags & RDW_FRAME) wndPtr->flags |= WIN_NEEDS_NCPAINT;
611 if (flags & RDW_ERASE) wndPtr->flags |= WIN_NEEDS_ERASEBKGND;
614 else if( flags & RDW_VALIDATE )
616 if( wndPtr->hrgnUpdate )
620 if( wndPtr->hrgnUpdate == 1 )
621 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r );
623 if( CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_DIFF )
626 DeleteObject( wndPtr->hrgnUpdate );
627 wndPtr->hrgnUpdate = 0;
630 else /* validate everything */
632 if( wndPtr->hrgnUpdate > 1 ) DeleteObject( wndPtr->hrgnUpdate );
633 wndPtr->hrgnUpdate = 0;
636 if( !wndPtr->hrgnUpdate )
638 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
639 if( !(wndPtr->flags & WIN_INTERNAL_PAINT) )
640 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
644 if (flags & RDW_NOFRAME) wndPtr->flags &= ~WIN_NEEDS_NCPAINT;
645 if (flags & RDW_NOERASE) wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
649 if ((firstRecursLevel) && (wndPtr->hrgnUpdate != 0) && (flags & RDW_UPDATENOW))
650 RDW_ValidateParent(wndPtr); /* validate parent covered by region */
652 /* in/validate child windows that intersect with the region if it
653 * is a valid handle. */
655 if( flags & (RDW_INVALIDATE | RDW_VALIDATE) )
657 if( hRgn > 1 && bChildren )
659 WND* wnd = wndPtr->child;
660 POINT ptTotal, prevOrigin = {0,0};
663 ptClient.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
664 ptClient.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
666 for( ptTotal.x = ptTotal.y = 0; wnd; wnd = wnd->next )
668 if( wnd->dwStyle & WS_VISIBLE )
672 r.left = wnd->rectWindow.left + ptClient.x;
673 r.right = wnd->rectWindow.right + ptClient.x;
674 r.top = wnd->rectWindow.top + ptClient.y;
675 r.bottom = wnd->rectWindow.bottom + ptClient.y;
677 ptOffset.x = r.left - prevOrigin.x;
678 ptOffset.y = r.top - prevOrigin.y;
679 OffsetRect( &r, -ptTotal.x, -ptTotal.y );
681 if( RectInRegion( hRgn, &r ) )
683 OffsetRgn( hRgn, -ptOffset.x, -ptOffset.y );
684 RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
685 prevOrigin.x = r.left + ptTotal.x;
686 prevOrigin.y = r.top + ptTotal.y;
687 ptTotal.x += ptOffset.x;
688 ptTotal.y += ptOffset.y;
692 OffsetRgn( hRgn, ptTotal.x, ptTotal.y );
697 /* handle hRgn == 1 (alias for entire window) and/or internal paint recursion */
702 for( wnd = wndPtr->child; wnd; wnd = wnd->next )
703 if( wnd->dwStyle & WS_VISIBLE )
704 RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
709 /* Set/clear internal paint flag */
711 if (flags & RDW_INTERNALPAINT)
713 if ( !wndPtr->hrgnUpdate && !(wndPtr->flags & WIN_INTERNAL_PAINT))
714 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
715 wndPtr->flags |= WIN_INTERNAL_PAINT;
717 else if (flags & RDW_NOINTERNALPAINT)
719 if ( !wndPtr->hrgnUpdate && (wndPtr->flags & WIN_INTERNAL_PAINT))
720 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
721 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
725 /***********************************************************************
726 * RDW_Paint [RedrawWindow() helper]
728 * Walks the window tree and paints/erases windows that have
729 * nonzero update regions according to redraw flags. hrgn is a scratch
730 * region passed down during recursion. Must not be 1.
733 static HRGN RDW_Paint( WND* wndPtr, HRGN hrgn, UINT flags, UINT ex )
735 /* NOTE: wndPtr is locked by caller.
737 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
738 * SendMessage() calls. This is a comment inside DefWindowProc() source
741 * This message avoids lots of inter-app message traffic
742 * by switching to the other task and continuing the
746 * LOWORD(lParam) = hrgnClip
747 * HIWORD(lParam) = hwndSkip (not used; always NULL)
751 HWND hWnd = wndPtr->hwndSelf;
752 BOOL bIcon = ((wndPtr->dwStyle & WS_MINIMIZE) && GetClassWord(wndPtr->hwndSelf, GCW_HICON));
754 /* Erase/update the window itself ... */
756 TRACE("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", hWnd, wndPtr->hrgnUpdate, hrgn, flags );
759 * Check if this window should delay it's processing of WM_NCPAINT.
760 * See WIN_HaveToDelayNCPAINT for a description of the mechanism
762 if ((ex & RDW_EX_DELAY_NCPAINT) || WIN_HaveToDelayNCPAINT(wndPtr, 0) )
763 ex |= RDW_EX_DELAY_NCPAINT;
765 if (flags & RDW_UPDATENOW)
767 if (wndPtr->hrgnUpdate) /* wm_painticon wparam is 1 */
768 SendMessage16( hWnd, (bIcon) ? WM_PAINTICON : WM_PAINT, bIcon, 0 );
770 else if (flags & RDW_ERASENOW)
772 UINT dcx = DCX_INTERSECTRGN | DCX_USESTYLE | DCX_KEEPCLIPRGN | DCX_WINDOWPAINT | DCX_CACHE;
775 hrgnRet = WIN_UpdateNCRgn(wndPtr,
777 UNC_REGION | UNC_CHECK |
778 ((ex & RDW_EX_DELAY_NCPAINT) ? UNC_DELAY_NCPAINT : 0) );
782 if( hrgnRet > 1 ) hrgn = hrgnRet; else hrgnRet = 0; /* entire client */
783 if( wndPtr->flags & WIN_NEEDS_ERASEBKGND )
785 if( bIcon ) dcx |= DCX_WINDOW;
788 OffsetRgn( hrgnRet, wndPtr->rectWindow.left - wndPtr->rectClient.left,
789 wndPtr->rectWindow.top - wndPtr->rectClient.top);
791 dcx &= ~DCX_INTERSECTRGN;
792 if (( hDC = GetDCEx( hWnd, hrgnRet, dcx )) )
794 if (SendMessage16( hWnd, (bIcon) ? WM_ICONERASEBKGND
795 : WM_ERASEBKGND, (WPARAM16)hDC, 0 ))
796 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
797 ReleaseDC( hWnd, hDC );
803 if( !IsWindow(hWnd) ) return hrgn;
805 /* ... and its child windows */
807 if( wndPtr->child && !(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE)
808 && ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) )
812 if( (list = WIN_BuildWinArray( wndPtr, 0, NULL )) )
815 for (ppWnd = list; *ppWnd; ppWnd++)
817 WIN_UpdateWndPtr(&wndPtr,*ppWnd);
818 if (!IsWindow(wndPtr->hwndSelf)) continue;
819 if ( (wndPtr->dwStyle & WS_VISIBLE) &&
820 (wndPtr->hrgnUpdate || (wndPtr->flags & WIN_INTERNAL_PAINT)) )
821 hrgn = RDW_Paint( wndPtr, hrgn, flags, ex );
823 WIN_ReleaseWndPtr(wndPtr);
824 WIN_ReleaseWinArray(list);
832 /***********************************************************************
833 * RedrawWindow (USER32.@)
835 BOOL WINAPI RedrawWindow( HWND hwnd, const RECT *rectUpdate,
836 HRGN hrgnUpdate, UINT flags )
843 if (!hwnd) hwnd = GetDesktopWindow();
844 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
846 /* check if the window or its parents are visible/not minimized */
848 if (!WIN_IsWindowDrawable( wndPtr, !(flags & RDW_FRAME) ) )
850 WIN_ReleaseWndPtr(wndPtr);
858 GetRgnBox( hrgnUpdate, &r );
859 TRACE( "%04x (%04x) NULL %04x box (%i,%i-%i,%i) flags=%04x\n",
860 hwnd, wndPtr->hrgnUpdate, hrgnUpdate, r.left, r.top, r.right, r.bottom, flags );
868 TRACE( "%04x (%04x) %s %d,%d-%d,%d %04x flags=%04x\n",
869 hwnd, wndPtr->hrgnUpdate, rectUpdate ? "rect" : "NULL", r.left,
870 r.top, r.right, r.bottom, hrgnUpdate, flags );
874 /* prepare an update region in window coordinates */
876 if( flags & RDW_FRAME )
877 r = wndPtr->rectWindow;
879 r = wndPtr->rectClient;
881 pt.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
882 pt.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
883 OffsetRect( &r, -wndPtr->rectClient.left, -wndPtr->rectClient.top );
885 if (flags & RDW_INVALIDATE) /* ------------------------- Invalidate */
887 /* If the window doesn't have hrgnUpdate we leave hRgn zero
888 * and put a new region straight into wndPtr->hrgnUpdate
889 * so that RDW_UpdateRgns() won't have to do any extra work.
894 if( wndPtr->hrgnUpdate )
895 hRgn = REGION_CropRgn( 0, hrgnUpdate, NULL, &pt );
897 wndPtr->hrgnUpdate = REGION_CropRgn( 0, hrgnUpdate, &r, &pt );
899 else if( rectUpdate )
901 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
902 OffsetRect( &r2, pt.x, pt.y );
905 if( wndPtr->hrgnUpdate == 0 )
906 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r2 );
908 hRgn = CreateRectRgnIndirect( &r2 );
910 else /* entire window or client depending on RDW_FRAME */
912 if( flags & RDW_FRAME )
914 if( wndPtr->hrgnUpdate )
915 DeleteObject( wndPtr->hrgnUpdate );
916 wndPtr->hrgnUpdate = 1;
920 GETCLIENTRECTW( wndPtr, r2 );
925 else if (flags & RDW_VALIDATE) /* ------------------------- Validate */
927 /* In this we cannot leave with zero hRgn */
930 hRgn = REGION_CropRgn( hRgn, hrgnUpdate, &r, &pt );
931 GetRgnBox( hRgn, &r2 );
932 if( IsRectEmpty( &r2 ) ) goto END;
934 else if( rectUpdate )
936 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
937 OffsetRect( &r2, pt.x, pt.y );
938 hRgn = CreateRectRgnIndirect( &r2 );
940 else /* entire window or client depending on RDW_FRAME */
942 if( flags & RDW_FRAME )
946 GETCLIENTRECTW( wndPtr, r2 );
947 hRgn = CreateRectRgnIndirect( &r2 );
952 /* At this point hRgn is either an update region in window coordinates or 1 or 0 */
954 RDW_UpdateRgns( wndPtr, hRgn, flags, TRUE );
956 /* Erase/update windows, from now on hRgn is a scratch region */
958 hRgn = RDW_Paint( wndPtr, (hRgn == 1) ? 0 : hRgn, flags, 0 );
961 if( hRgn > 1 && (hRgn != hrgnUpdate) )
963 WIN_ReleaseWndPtr(wndPtr);
968 /***********************************************************************
969 * RedrawWindow (USER.290)
971 BOOL16 WINAPI RedrawWindow16( HWND16 hwnd, const RECT16 *rectUpdate,
972 HRGN16 hrgnUpdate, UINT16 flags )
977 CONV_RECT16TO32( rectUpdate, &r );
978 return (BOOL16)RedrawWindow( (HWND)hwnd, &r, hrgnUpdate, flags );
980 return RedrawWindow( hwnd, NULL, hrgnUpdate, flags );
984 /***********************************************************************
985 * UpdateWindow (USER.124)
987 void WINAPI UpdateWindow16( HWND16 hwnd )
989 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
992 /***********************************************************************
993 * UpdateWindow (USER32.@)
995 void WINAPI UpdateWindow( HWND hwnd )
997 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1000 /***********************************************************************
1001 * InvalidateRgn (USER.126)
1003 void WINAPI InvalidateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
1005 RedrawWindow((HWND)hwnd, NULL, (HRGN)hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
1009 /***********************************************************************
1010 * InvalidateRgn (USER32.@)
1012 BOOL WINAPI InvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
1014 return RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
1018 /***********************************************************************
1019 * InvalidateRect (USER.125)
1021 void WINAPI InvalidateRect16( HWND16 hwnd, const RECT16 *rect, BOOL16 erase )
1023 RedrawWindow16( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
1027 /***********************************************************************
1028 * InvalidateRect (USER32.@)
1030 BOOL WINAPI InvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
1032 return RedrawWindow( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
1036 /***********************************************************************
1037 * ValidateRgn (USER.128)
1039 void WINAPI ValidateRgn16( HWND16 hwnd, HRGN16 hrgn )
1041 RedrawWindow( (HWND)hwnd, NULL, (HRGN)hrgn, RDW_VALIDATE | RDW_NOCHILDREN );
1045 /***********************************************************************
1046 * ValidateRgn (USER32.@)
1048 void WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
1050 RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOCHILDREN );
1054 /***********************************************************************
1055 * ValidateRect (USER.127)
1057 void WINAPI ValidateRect16( HWND16 hwnd, const RECT16 *rect )
1059 RedrawWindow16( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
1063 /***********************************************************************
1064 * ValidateRect (USER32.@)
1066 void WINAPI ValidateRect( HWND hwnd, const RECT *rect )
1068 RedrawWindow( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
1072 /***********************************************************************
1073 * GetUpdateRect (USER.190)
1075 BOOL16 WINAPI GetUpdateRect16( HWND16 hwnd, LPRECT16 rect, BOOL16 erase )
1080 if (!rect) return GetUpdateRect( hwnd, NULL, erase );
1081 ret = GetUpdateRect( hwnd, &r, erase );
1082 CONV_RECT32TO16( &r, rect );
1087 /***********************************************************************
1088 * GetUpdateRect (USER32.@)
1090 BOOL WINAPI GetUpdateRect( HWND hwnd, LPRECT rect, BOOL erase )
1093 WND * wndPtr = WIN_FindWndPtr( hwnd );
1094 if (!wndPtr) return FALSE;
1098 if (wndPtr->hrgnUpdate > 1)
1100 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
1101 if (GetUpdateRgn( hwnd, hrgn, erase ) == ERROR)
1106 GetRgnBox( hrgn, rect );
1107 DeleteObject( hrgn );
1108 if (GetClassLongA(wndPtr->hwndSelf, GCL_STYLE) & CS_OWNDC)
1110 if (GetMapMode(wndPtr->dce->hDC) != MM_TEXT)
1112 DPtoLP (wndPtr->dce->hDC, (LPPOINT)rect, 2);
1117 if( wndPtr->hrgnUpdate == 1 )
1119 GetClientRect( hwnd, rect );
1120 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_ERASENOW | RDW_NOCHILDREN );
1123 SetRectEmpty( rect );
1125 retvalue = (wndPtr->hrgnUpdate >= 1);
1127 WIN_ReleaseWndPtr(wndPtr);
1132 /***********************************************************************
1133 * GetUpdateRgn (USER.237)
1135 INT16 WINAPI GetUpdateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
1137 return GetUpdateRgn( hwnd, hrgn, erase );
1141 /***********************************************************************
1142 * GetUpdateRgn (USER32.@)
1144 INT WINAPI GetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
1147 WND * wndPtr = WIN_FindWndPtr( hwnd );
1148 if (!wndPtr) return ERROR;
1150 if (wndPtr->hrgnUpdate == 0)
1152 SetRectRgn( hrgn, 0, 0, 0, 0 );
1153 retval = NULLREGION;
1157 if (wndPtr->hrgnUpdate == 1)
1159 SetRectRgn( hrgn, 0, 0, wndPtr->rectClient.right - wndPtr->rectClient.left,
1160 wndPtr->rectClient.bottom - wndPtr->rectClient.top );
1161 retval = SIMPLEREGION;
1165 retval = CombineRgn( hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY );
1166 OffsetRgn( hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
1167 wndPtr->rectWindow.top - wndPtr->rectClient.top );
1169 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW | RDW_NOCHILDREN );
1171 WIN_ReleaseWndPtr(wndPtr);
1176 /***********************************************************************
1177 * ExcludeUpdateRgn (USER.238)
1179 INT16 WINAPI ExcludeUpdateRgn16( HDC16 hdc, HWND16 hwnd )
1181 return ExcludeUpdateRgn( hdc, hwnd );
1185 /***********************************************************************
1186 * ExcludeUpdateRgn (USER32.@)
1188 INT WINAPI ExcludeUpdateRgn( HDC hdc, HWND hwnd )
1193 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return ERROR;
1195 if (wndPtr->hrgnUpdate)
1198 HRGN hrgn = CreateRectRgn(wndPtr->rectWindow.left - wndPtr->rectClient.left,
1199 wndPtr->rectWindow.top - wndPtr->rectClient.top,
1200 wndPtr->rectWindow.right - wndPtr->rectClient.left,
1201 wndPtr->rectWindow.bottom - wndPtr->rectClient.top);
1202 if( wndPtr->hrgnUpdate > 1 )
1204 CombineRgn(hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY);
1205 OffsetRgn(hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
1206 wndPtr->rectWindow.top - wndPtr->rectClient.top );
1209 /* do ugly coordinate translations in dce.c */
1211 ret = DCE_ExcludeRgn( hdc, wndPtr, hrgn );
1212 DeleteObject( hrgn );
1213 WIN_ReleaseWndPtr(wndPtr);
1216 WIN_ReleaseWndPtr(wndPtr);
1217 return GetClipBox( hdc, &rect );
1222 /***********************************************************************
1223 * FillRect (USER.81)
1225 * The Win16 variant doesn't support special color brushes like
1226 * the Win32 one, despite the fact that Win16, as well as Win32,
1227 * supports special background brushes for a window class.
1229 INT16 WINAPI FillRect16( HDC16 hdc, const RECT16 *rect, HBRUSH16 hbrush )
1233 /* coordinates are logical so we cannot fast-check 'rect',
1234 * it will be done later in the PatBlt().
1237 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1238 PatBlt( hdc, rect->left, rect->top,
1239 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
1240 SelectObject( hdc, prevBrush );
1245 /***********************************************************************
1246 * FillRect (USER32.@)
1248 INT WINAPI FillRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1252 if (hbrush <= (HBRUSH) (COLOR_MAX + 1)) {
1253 hbrush = GetSysColorBrush( (INT) hbrush - 1 );
1256 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1257 PatBlt( hdc, rect->left, rect->top,
1258 rect->right - rect->left, rect->bottom - rect->top, PATCOPY );
1259 SelectObject( hdc, prevBrush );
1264 /***********************************************************************
1265 * InvertRect (USER.82)
1267 void WINAPI InvertRect16( HDC16 hdc, const RECT16 *rect )
1269 PatBlt( hdc, rect->left, rect->top,
1270 rect->right - rect->left, rect->bottom - rect->top, DSTINVERT );
1274 /***********************************************************************
1275 * InvertRect (USER32.@)
1277 BOOL WINAPI InvertRect( HDC hdc, const RECT *rect )
1279 return PatBlt( hdc, rect->left, rect->top,
1280 rect->right - rect->left, rect->bottom - rect->top,
1285 /***********************************************************************
1286 * FrameRect (USER32.@)
1288 INT WINAPI FrameRect( HDC hdc, const RECT *rect, HBRUSH hbrush )
1293 if ( (r.right <= r.left) || (r.bottom <= r.top) ) return 0;
1294 if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0;
1296 PatBlt( hdc, r.left, r.top, 1,
1297 r.bottom - r.top, PATCOPY );
1298 PatBlt( hdc, r.right - 1, r.top, 1,
1299 r.bottom - r.top, PATCOPY );
1300 PatBlt( hdc, r.left, r.top,
1301 r.right - r.left, 1, PATCOPY );
1302 PatBlt( hdc, r.left, r.bottom - 1,
1303 r.right - r.left, 1, PATCOPY );
1305 SelectObject( hdc, prevBrush );
1310 /***********************************************************************
1311 * FrameRect (USER.83)
1313 INT16 WINAPI FrameRect16( HDC16 hdc, const RECT16 *rect16, HBRUSH16 hbrush )
1316 CONV_RECT16TO32( rect16, &rect );
1317 return FrameRect( hdc, &rect, hbrush );
1321 /***********************************************************************
1322 * DrawFocusRect (USER.466)
1324 void WINAPI DrawFocusRect16( HDC16 hdc, const RECT16* rc )
1327 CONV_RECT16TO32( rc, &rect32 );
1328 DrawFocusRect( hdc, &rect32 );
1332 /***********************************************************************
1333 * DrawFocusRect (USER32.@)
1335 * FIXME: PatBlt(PATINVERT) with background brush.
1337 BOOL WINAPI DrawFocusRect( HDC hdc, const RECT* rc )
1340 HPEN hOldPen, hNewPen;
1341 INT oldDrawMode, oldBkMode;
1343 hOldBrush = SelectObject(hdc, GetStockObject(NULL_BRUSH));
1344 hNewPen = CreatePen(PS_ALTERNATE, 1, GetSysColor(COLOR_WINDOWTEXT));
1345 hOldPen = SelectObject(hdc, hNewPen);
1346 oldDrawMode = SetROP2(hdc, R2_XORPEN);
1347 oldBkMode = SetBkMode(hdc, TRANSPARENT);
1349 Rectangle(hdc, rc->left, rc->top, rc->right, rc->bottom);
1351 SetBkMode(hdc, oldBkMode);
1352 SetROP2(hdc, oldDrawMode);
1353 SelectObject(hdc, hOldPen);
1354 DeleteObject(hNewPen);
1355 SelectObject(hdc, hOldBrush);
1360 /**********************************************************************
1361 * DrawAnimatedRects (USER.448)
1363 BOOL16 WINAPI DrawAnimatedRects16( HWND16 hwnd, INT16 idAni,
1364 const RECT16* lprcFrom,
1365 const RECT16* lprcTo )
1367 RECT rcFrom32, rcTo32;
1369 rcFrom32.left = (INT)lprcFrom->left;
1370 rcFrom32.top = (INT)lprcFrom->top;
1371 rcFrom32.right = (INT)lprcFrom->right;
1372 rcFrom32.bottom = (INT)lprcFrom->bottom;
1374 rcTo32.left = (INT)lprcTo->left;
1375 rcTo32.top = (INT)lprcTo->top;
1376 rcTo32.right = (INT)lprcTo->right;
1377 rcTo32.bottom = (INT)lprcTo->bottom;
1379 return DrawAnimatedRects((HWND)hwnd, (INT)idAni, &rcFrom32, &rcTo32);
1383 /**********************************************************************
1384 * DrawAnimatedRects (USER32.@)
1386 BOOL WINAPI DrawAnimatedRects( HWND hwnd, INT idAni,
1387 const RECT* lprcFrom,
1388 const RECT* lprcTo )
1390 FIXME_(win)("(0x%x,%d,%p,%p): stub\n",hwnd,idAni,lprcFrom,lprcTo);
1395 /**********************************************************************
1396 * PAINTING_DrawStateJam
1398 * Jams in the requested type in the dc
1400 static BOOL PAINTING_DrawStateJam(HDC hdc, UINT opcode,
1401 DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1402 LPRECT rc, UINT dtflags,
1403 BOOL unicode, BOOL _32bit)
1408 INT cx = rc->right - rc->left;
1409 INT cy = rc->bottom - rc->top;
1414 case DST_PREFIXTEXT:
1416 return DrawTextW(hdc, (LPWSTR)lp, (INT)wp, rc, dtflags);
1418 return DrawTextA(hdc, (LPSTR)lp, (INT)wp, rc, dtflags);
1420 return DrawTextA(hdc, MapSL(lp), (INT)wp, rc, dtflags);
1423 return DrawIcon(hdc, rc->left, rc->top, (HICON)lp);
1426 memdc = CreateCompatibleDC(hdc);
1427 if(!memdc) return FALSE;
1428 hbmsave = (HBITMAP)SelectObject(memdc, (HBITMAP)lp);
1434 retval = BitBlt(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
1435 SelectObject(memdc, hbmsave);
1442 /* DRAWSTATEPROC assumes that it draws at the center of coordinates */
1444 OffsetViewportOrgEx(hdc, rc->left, rc->top, NULL);
1446 bRet = func(hdc, lp, wp, cx, cy);
1448 bRet = (BOOL)((DRAWSTATEPROC16)func)((HDC16)hdc, (LPARAM)lp, (WPARAM16)wp, (INT16)cx, (INT16)cy);
1449 /* Restore origin */
1450 OffsetViewportOrgEx(hdc, -rc->left, -rc->top, NULL);
1458 /**********************************************************************
1459 * PAINTING_DrawState()
1461 static BOOL PAINTING_DrawState(HDC hdc, HBRUSH hbr,
1462 DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
1463 INT x, INT y, INT cx, INT cy,
1464 UINT flags, BOOL unicode, BOOL _32bit)
1466 HBITMAP hbm, hbmsave;
1468 HBRUSH hbsave, hbrtmp = 0;
1471 UINT dtflags = DT_NOCLIP;
1473 UINT opcode = flags & 0xf;
1477 if((opcode == DST_TEXT || opcode == DST_PREFIXTEXT) && !len) /* The string is '\0' terminated */
1480 len = strlenW((LPWSTR)lp);
1482 len = strlen((LPSTR)lp);
1484 len = strlen(MapSL(lp));
1487 /* Find out what size the image has if not given by caller */
1491 CURSORICONINFO *ici;
1497 case DST_PREFIXTEXT:
1499 retval = GetTextExtentPoint32W(hdc, (LPWSTR)lp, len, &s);
1501 retval = GetTextExtentPoint32A(hdc, (LPSTR)lp, len, &s);
1503 retval = GetTextExtentPoint32A(hdc, MapSL(lp), len, &s);
1504 if(!retval) return FALSE;
1508 ici = (CURSORICONINFO *)GlobalLock16((HGLOBAL16)lp);
1509 if(!ici) return FALSE;
1511 s.cy = ici->nHeight;
1512 GlobalUnlock16((HGLOBAL16)lp);
1516 if(!GetObjectA((HBITMAP)lp, sizeof(bm), &bm))
1522 case DST_COMPLEX: /* cx and cy must be set in this mode */
1535 if(flags & DSS_RIGHT) /* This one is not documented in the win32.hlp file */
1536 dtflags |= DT_RIGHT;
1537 if(opcode == DST_TEXT)
1538 dtflags |= DT_NOPREFIX;
1540 /* For DSS_NORMAL we just jam in the image and return */
1541 if((flags & 0x7ff0) == DSS_NORMAL)
1543 return PAINTING_DrawStateJam(hdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
1546 /* For all other states we need to convert the image to B/W in a local bitmap */
1547 /* before it is displayed */
1548 fg = SetTextColor(hdc, RGB(0, 0, 0));
1549 bg = SetBkColor(hdc, RGB(255, 255, 255));
1550 hbm = (HBITMAP)NULL; hbmsave = (HBITMAP)NULL;
1551 memdc = (HDC)NULL; hbsave = (HBRUSH)NULL;
1552 retval = FALSE; /* assume failure */
1554 /* From here on we must use "goto cleanup" when something goes wrong */
1555 hbm = CreateBitmap(cx, cy, 1, 1, NULL);
1556 if(!hbm) goto cleanup;
1557 memdc = CreateCompatibleDC(hdc);
1558 if(!memdc) goto cleanup;
1559 hbmsave = (HBITMAP)SelectObject(memdc, hbm);
1560 if(!hbmsave) goto cleanup;
1561 rc.left = rc.top = 0;
1564 if(!FillRect(memdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH))) goto cleanup;
1565 SetBkColor(memdc, RGB(255, 255, 255));
1566 SetTextColor(memdc, RGB(0, 0, 0));
1567 hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT));
1569 /* DST_COMPLEX may draw text as well,
1570 * so we must be sure that correct font is selected
1572 if(!hfsave && (opcode <= DST_PREFIXTEXT)) goto cleanup;
1573 tmp = PAINTING_DrawStateJam(memdc, opcode, func, lp, len, &rc, dtflags, unicode, _32bit);
1574 if(hfsave) SelectObject(memdc, hfsave);
1575 if(!tmp) goto cleanup;
1577 /* This state cause the image to be dithered */
1578 if(flags & DSS_UNION)
1580 hbsave = (HBRUSH)SelectObject(memdc, CACHE_GetPattern55AABrush());
1581 if(!hbsave) goto cleanup;
1582 tmp = PatBlt(memdc, 0, 0, cx, cy, 0x00FA0089);
1583 SelectObject(memdc, hbsave);
1584 if(!tmp) goto cleanup;
1587 if (flags & DSS_DISABLED)
1588 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT));
1589 else if (flags & DSS_DEFAULT)
1590 hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1592 /* Draw light or dark shadow */
1593 if (flags & (DSS_DISABLED|DSS_DEFAULT))
1595 if(!hbrtmp) goto cleanup;
1596 hbsave = (HBRUSH)SelectObject(hdc, hbrtmp);
1597 if(!hbsave) goto cleanup;
1598 if(!BitBlt(hdc, x+1, y+1, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1599 SelectObject(hdc, hbsave);
1600 DeleteObject(hbrtmp);
1604 if (flags & DSS_DISABLED)
1606 hbr = hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
1607 if(!hbrtmp) goto cleanup;
1611 hbr = (HBRUSH)GetStockObject(BLACK_BRUSH);
1614 hbsave = (HBRUSH)SelectObject(hdc, hbr);
1616 if(!BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00B8074A)) goto cleanup;
1618 retval = TRUE; /* We succeeded */
1621 SetTextColor(hdc, fg);
1622 SetBkColor(hdc, bg);
1624 if(hbsave) SelectObject(hdc, hbsave);
1625 if(hbmsave) SelectObject(memdc, hbmsave);
1626 if(hbrtmp) DeleteObject(hbrtmp);
1627 if(hbm) DeleteObject(hbm);
1628 if(memdc) DeleteDC(memdc);
1633 /**********************************************************************
1634 * DrawStateA (USER32.@)
1636 BOOL WINAPI DrawStateA(HDC hdc, HBRUSH hbr,
1637 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1638 INT x, INT y, INT cx, INT cy, UINT flags)
1640 return PAINTING_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, FALSE, TRUE);
1643 /**********************************************************************
1644 * DrawStateW (USER32.@)
1646 BOOL WINAPI DrawStateW(HDC hdc, HBRUSH hbr,
1647 DRAWSTATEPROC func, LPARAM ldata, WPARAM wdata,
1648 INT x, INT y, INT cx, INT cy, UINT flags)
1650 return PAINTING_DrawState(hdc, hbr, func, ldata, wdata, x, y, cx, cy, flags, TRUE, TRUE);
1653 /**********************************************************************
1654 * DrawState (USER.449)
1656 BOOL16 WINAPI DrawState16(HDC16 hdc, HBRUSH16 hbr,
1657 DRAWSTATEPROC16 func, LPARAM ldata, WPARAM16 wdata,
1658 INT16 x, INT16 y, INT16 cx, INT16 cy, UINT16 flags)
1660 return PAINTING_DrawState(hdc, hbr, (DRAWSTATEPROC)func, ldata, wdata, x, y, cx, cy, flags, FALSE, FALSE);
1664 /***********************************************************************
1665 * SelectPalette (USER.282)
1667 HPALETTE16 WINAPI SelectPalette16( HDC16 hDC, HPALETTE16 hPal,
1668 BOOL16 bForceBackground )
1670 WORD wBkgPalette = 1;
1672 if (!bForceBackground && (hPal != GetStockObject(DEFAULT_PALETTE)))
1674 HWND hwnd = WindowFromDC( hDC );
1677 HWND hForeground = GetForegroundWindow();
1678 /* set primary palette if it's related to current active */
1679 if (hForeground == hwnd || IsChild(hForeground,hwnd)) wBkgPalette = 0;
1682 return GDISelectPalette16( hDC, hPal, wBkgPalette);
1686 /***********************************************************************
1687 * RealizePalette (USER.283)
1689 UINT16 WINAPI RealizePalette16( HDC16 hDC )
1691 UINT16 realized = GDIRealizePalette16( hDC );
1693 /* do not send anything if no colors were changed */
1694 if (realized && IsDCCurrentPalette16( hDC ))
1696 /* send palette change notification */
1697 HWND hWnd = WindowFromDC( hDC );
1698 if (hWnd) SendMessageA( HWND_BROADCAST, WM_PALETTECHANGED, hWnd, 0L);
1704 /***********************************************************************
1705 * UserRealizePalette (USER32.@)
1707 UINT WINAPI UserRealizePalette( HDC hDC )
1709 return RealizePalette16( hDC );