2 * Window painting functions
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
13 #include "debugtools.h"
14 #include "wine/winuser16.h"
16 DECLARE_DEBUG_CHANNEL(nonclient)
17 DECLARE_DEBUG_CHANNEL(win)
19 /* client rect in window coordinates */
21 #define GETCLIENTRECTW( wnd, r ) (r).left = (wnd)->rectClient.left - (wnd)->rectWindow.left; \
22 (r).top = (wnd)->rectClient.top - (wnd)->rectWindow.top; \
23 (r).right = (wnd)->rectClient.right - (wnd)->rectWindow.left; \
24 (r).bottom = (wnd)->rectClient.bottom - (wnd)->rectWindow.top
26 /* Last CTLCOLOR id */
27 #define CTLCOLOR_MAX CTLCOLOR_STATIC
30 /***********************************************************************
34 * Send WM_NCPAINT if required (when nonclient is invalid or UNC_ENTIRE flag is set)
35 * Crop hrgnUpdate to a client rect, especially if it 1.
36 * If UNC_REGION is set return update region for the client rect.
38 * NOTE: UNC_REGION is mainly for the RDW_Paint() chunk that sends WM_ERASEBKGND message.
39 * The trick is that when the returned region handle may be different from hRgn.
40 * In this case the old hRgn must be considered gone. BUT, if the returned value
41 * is 1 then the hRgn is preserved and RDW_Paint() will have to get
42 * a DC without extra clipping region.
44 HRGN WIN_UpdateNCRgn(WND* wnd, HRGN hRgn, UINT uncFlags )
50 TRACE_(nonclient)("hwnd %04x [%04x] hrgn %04x, unc %04x, ncf %i\n",
51 wnd->hwndSelf, wnd->hrgnUpdate, hRgn, uncFlags, wnd->flags & WIN_NEEDS_NCPAINT);
53 /* desktop window doesn't have a nonclient area */
54 if(wnd == WIN_GetDesktop())
56 wnd->flags &= ~WIN_NEEDS_NCPAINT;
57 if( wnd->hrgnUpdate > 1 )
58 hrgnRet = REGION_CropRgn( hRgn, wnd->hrgnUpdate, NULL, NULL );
61 hrgnRet = wnd->hrgnUpdate;
68 if ((wnd->hwndSelf == GetForegroundWindow()) &&
69 !(wnd->flags & WIN_NCACTIVATED) )
71 wnd->flags |= WIN_NCACTIVATED;
72 uncFlags |= UNC_ENTIRE;
75 if( wnd->flags & WIN_NEEDS_NCPAINT )
79 wnd->flags &= ~WIN_NEEDS_NCPAINT;
80 GETCLIENTRECTW( wnd, r );
82 TRACE_(nonclient)( "\tclient box (%i,%i-%i,%i), hrgnUpdate %04x\n",
83 r.left, r.top, r.right, r.bottom, wnd->hrgnUpdate );
84 if( wnd->hrgnUpdate > 1 )
86 /* Check if update rgn overlaps with nonclient area */
88 GetRgnBox( wnd->hrgnUpdate, &r2 );
89 UnionRect( &r3, &r2, &r );
90 if( r3.left != r.left || r3.top != r.top ||
91 r3.right != r.right || r3.bottom != r.bottom ) /* it does */
93 /* crop hrgnUpdate, save old one in hClip - the only
94 * case that places a valid region handle in hClip */
96 hClip = wnd->hrgnUpdate;
97 wnd->hrgnUpdate = REGION_CropRgn( hRgn, hClip, &r, NULL );
98 if( uncFlags & UNC_REGION ) hrgnRet = hClip;
101 if( uncFlags & UNC_CHECK )
103 GetRgnBox( wnd->hrgnUpdate, &r3 );
104 if( IsRectEmpty( &r3 ) )
106 /* delete the update region since all invalid
107 * parts were in the nonclient area */
109 DeleteObject( wnd->hrgnUpdate );
111 if(!(wnd->flags & WIN_INTERNAL_PAINT))
112 QUEUE_DecPaintCount( wnd->hmemTaskQ );
114 wnd->flags &= ~WIN_NEEDS_ERASEBKGND;
118 if(!hClip && wnd->hrgnUpdate ) goto copyrgn;
121 if( wnd->hrgnUpdate == 1 )/* entire window */
123 if( uncFlags & UNC_UPDATE ) wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
124 if( uncFlags & UNC_REGION ) hrgnRet = 1;
125 uncFlags |= UNC_ENTIRE;
128 else /* no WM_NCPAINT unless forced */
130 if( wnd->hrgnUpdate > 1 )
133 if( uncFlags & UNC_REGION )
134 hrgnRet = REGION_CropRgn( hRgn, wnd->hrgnUpdate, NULL, NULL );
137 if( wnd->hrgnUpdate == 1 && (uncFlags & UNC_UPDATE) )
139 GETCLIENTRECTW( wnd, r );
140 wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
141 if( uncFlags & UNC_REGION ) hrgnRet = 1;
145 if(!hClip && (uncFlags & UNC_ENTIRE) )
147 /* still don't do anything if there is no nonclient area */
148 hClip = (memcmp( &wnd->rectWindow, &wnd->rectClient, sizeof(RECT) ) != 0);
151 if( hClip ) /* NOTE: WM_NCPAINT allows wParam to be 1 */
153 SendMessageA( wnd->hwndSelf, WM_NCPAINT, hClip, 0L );
154 if( (hClip > 1)&& (hClip != hRgn) && (hClip != hrgnRet) ) DeleteObject( hClip );
156 * Since all Window locks are suspended while processing the WM_NCPAINT
157 * we want to make sure the window still exists before continuing.
159 if (!IsWindow(wnd->hwndSelf))
161 DeleteObject(hrgnRet);
166 TRACE_(nonclient)("returning %04x (hClip = %04x, hrgnUpdate = %04x)\n", hrgnRet, hClip, wnd->hrgnUpdate );
172 /***********************************************************************
173 * BeginPaint16 (USER.39)
175 HDC16 WINAPI BeginPaint16( HWND16 hwnd, LPPAINTSTRUCT16 lps )
179 WND *wndPtr = WIN_FindWndPtr( hwnd );
180 if (!wndPtr) return 0;
182 bIcon = (wndPtr->dwStyle & WS_MINIMIZE && GetClassWord(wndPtr->hwndSelf, GCW_HICON));
184 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
186 /* send WM_NCPAINT and make sure hrgnUpdate is a valid rgn handle */
187 WIN_UpdateNCRgn( wndPtr, 0, UNC_UPDATE );
190 * Make sure the window is still a window. All window locks are suspended
191 * when the WM_NCPAINT is sent.
193 if (!IsWindow(wndPtr->hwndSelf))
195 WIN_ReleaseWndPtr(wndPtr);
199 if( ((hrgnUpdate = wndPtr->hrgnUpdate) != 0) || (wndPtr->flags & WIN_INTERNAL_PAINT))
200 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
202 wndPtr->hrgnUpdate = 0;
203 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
207 TRACE_(win)("hrgnUpdate = %04x, \n", hrgnUpdate);
209 if (GetClassWord16(wndPtr->hwndSelf, GCW_STYLE) & CS_PARENTDC)
211 /* Don't clip the output to the update region for CS_PARENTDC window */
213 DeleteObject(hrgnUpdate);
214 lps->hdc = GetDCEx16( hwnd, 0, DCX_WINDOWPAINT | DCX_USESTYLE |
215 (bIcon ? DCX_WINDOW : 0) );
219 if( hrgnUpdate ) /* convert to client coordinates */
220 OffsetRgn( hrgnUpdate, wndPtr->rectWindow.left - wndPtr->rectClient.left,
221 wndPtr->rectWindow.top - wndPtr->rectClient.top );
222 lps->hdc = GetDCEx16(hwnd, hrgnUpdate, DCX_INTERSECTRGN |
223 DCX_WINDOWPAINT | DCX_USESTYLE | (bIcon ? DCX_WINDOW : 0) );
224 /* ReleaseDC() in EndPaint() will delete the region */
227 TRACE_(win)("hdc = %04x\n", lps->hdc);
231 WARN_(win)("GetDCEx() failed in BeginPaint(), hwnd=%04x\n", hwnd);
232 WIN_ReleaseWndPtr(wndPtr);
236 GetClipBox16( lps->hdc, &lps->rcPaint );
238 TRACE_(win)("box = (%i,%i - %i,%i)\n", lps->rcPaint.left, lps->rcPaint.top,
239 lps->rcPaint.right, lps->rcPaint.bottom );
241 if (wndPtr->flags & WIN_NEEDS_ERASEBKGND)
243 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
244 lps->fErase = !SendMessage16(hwnd, (bIcon) ? WM_ICONERASEBKGND
246 (WPARAM16)lps->hdc, 0 );
248 else lps->fErase = TRUE;
250 WIN_ReleaseWndPtr(wndPtr);
255 /***********************************************************************
256 * BeginPaint32 (USER32.10)
258 HDC WINAPI BeginPaint( HWND hwnd, PAINTSTRUCT *lps )
262 BeginPaint16( hwnd, &ps );
263 lps->hdc = (HDC)ps.hdc;
264 lps->fErase = ps.fErase;
265 lps->rcPaint.top = ps.rcPaint.top;
266 lps->rcPaint.left = ps.rcPaint.left;
267 lps->rcPaint.right = ps.rcPaint.right;
268 lps->rcPaint.bottom = ps.rcPaint.bottom;
269 lps->fRestore = ps.fRestore;
270 lps->fIncUpdate = ps.fIncUpdate;
275 /***********************************************************************
276 * EndPaint16 (USER.40)
278 BOOL16 WINAPI EndPaint16( HWND16 hwnd, const PAINTSTRUCT16* lps )
280 ReleaseDC16( hwnd, lps->hdc );
286 /***********************************************************************
287 * EndPaint32 (USER32.176)
289 BOOL WINAPI EndPaint( HWND hwnd, const PAINTSTRUCT *lps )
291 ReleaseDC( hwnd, lps->hdc );
297 /***********************************************************************
298 * FillWindow (USER.324)
300 void WINAPI FillWindow16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc, HBRUSH16 hbrush )
303 GetClientRect16( hwnd, &rect );
304 DPtoLP16( hdc, (LPPOINT16)&rect, 2 );
305 PaintRect16( hwndParent, hwnd, hdc, hbrush, &rect );
309 /***********************************************************************
310 * PAINT_GetControlBrush
312 static HBRUSH16 PAINT_GetControlBrush( HWND hParent, HWND hWnd, HDC16 hDC, UINT16 ctlType )
314 HBRUSH16 bkgBrush = (HBRUSH16)SendMessageA( hParent, WM_CTLCOLORMSGBOX + ctlType,
315 (WPARAM)hDC, (LPARAM)hWnd );
316 if( !IsGDIObject16(bkgBrush) )
317 bkgBrush = DEFWND_ControlColor( hDC, ctlType );
322 /***********************************************************************
323 * PaintRect (USER.325)
325 void WINAPI PaintRect16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc,
326 HBRUSH16 hbrush, const RECT16 *rect)
328 if( hbrush <= CTLCOLOR_MAX )
331 hbrush = PAINT_GetControlBrush( hwndParent, hwnd, hdc, (UINT16)hbrush );
336 FillRect16( hdc, rect, hbrush );
340 /***********************************************************************
341 * GetControlBrush (USER.326)
343 HBRUSH16 WINAPI GetControlBrush16( HWND16 hwnd, HDC16 hdc, UINT16 ctlType )
345 WND* wndPtr = WIN_FindWndPtr( hwnd );
348 if((ctlType <= CTLCOLOR_MAX) && wndPtr )
351 if( wndPtr->dwStyle & WS_POPUP ) parent = WIN_LockWndPtr(wndPtr->owner);
352 else parent = WIN_LockWndPtr(wndPtr->parent);
353 if( !parent ) parent = wndPtr;
354 retvalue = (HBRUSH16)PAINT_GetControlBrush( parent->hwndSelf, hwnd, hdc, ctlType );
355 WIN_ReleaseWndPtr(parent);
358 retvalue = (HBRUSH16)0;
360 WIN_ReleaseWndPtr(wndPtr);
366 /***********************************************************************
367 * RDW_UpdateRgns [RedrawWindow() helper]
369 * Walks the window tree and adds/removes parts of the hRgn to/from update
370 * regions of windows that overlap it. Also, manages internal paint flags.
372 * NOTE: Walks the window tree so the caller must lock it.
373 * MUST preserve hRgn (can modify but then has to restore).
375 static void RDW_UpdateRgns( WND* wndPtr, HRGN hRgn, UINT flags )
378 * Called only when one of the following is set:
379 * (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT)
382 BOOL bHadOne = wndPtr->hrgnUpdate && hRgn;
383 RECT r = {0, 0, wndPtr->rectWindow.right - wndPtr->rectWindow.left,
384 wndPtr->rectWindow.bottom - wndPtr->rectWindow.top };
385 BOOL bChildren = ( wndPtr->child && !(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE)
386 && ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) );
388 TRACE_(win)("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", wndPtr->hwndSelf, wndPtr->hrgnUpdate, hRgn, flags );
390 if( flags & RDW_INVALIDATE )
394 switch( wndPtr->hrgnUpdate )
397 CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_OR );
400 wndPtr->hrgnUpdate = REGION_CropRgn( wndPtr->hrgnUpdate,
401 wndPtr->hrgnUpdate ? wndPtr->hrgnUpdate : hRgn,
405 GetRgnBox( wndPtr->hrgnUpdate, &r );
406 if( IsRectEmpty( &r ) )
408 DeleteObject( wndPtr->hrgnUpdate );
409 wndPtr->hrgnUpdate = 0;
415 case 1: /* already an entire window */
420 if( wndPtr->hrgnUpdate > 1 )
421 DeleteObject( wndPtr->hrgnUpdate );
422 wndPtr->hrgnUpdate = 1;
425 hRgn = wndPtr->hrgnUpdate; /* this is a trick that depends on code in PAINT_RedrawWindow() */
427 if( !bHadOne && !(wndPtr->flags & WIN_INTERNAL_PAINT) )
428 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
430 if (flags & RDW_FRAME) wndPtr->flags |= WIN_NEEDS_NCPAINT;
431 if (flags & RDW_ERASE) wndPtr->flags |= WIN_NEEDS_ERASEBKGND;
434 else if( flags & RDW_VALIDATE )
436 if( wndPtr->hrgnUpdate )
440 if( wndPtr->hrgnUpdate == 1 )
441 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r );
443 if( CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_DIFF )
447 else /* validate everything */
449 if( wndPtr->hrgnUpdate > 1 )
452 DeleteObject( wndPtr->hrgnUpdate );
454 wndPtr->hrgnUpdate = 0;
457 if( !wndPtr->hrgnUpdate )
459 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
460 if( !(wndPtr->flags & WIN_INTERNAL_PAINT) )
461 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
465 if (flags & RDW_NOFRAME) wndPtr->flags &= ~WIN_NEEDS_NCPAINT;
466 if (flags & RDW_NOERASE) wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
469 /* in/validate child windows that intersect with the region if it
470 * is a valid handle. */
472 if( flags & (RDW_INVALIDATE | RDW_VALIDATE) )
474 if( hRgn > 1 && bChildren )
476 WND* wnd = wndPtr->child;
477 POINT ptClient = { wndPtr->rectClient.left - wndPtr->rectWindow.left,
478 wndPtr->rectClient.top - wndPtr->rectWindow.top };
479 POINT ptTotal, prevOrigin = {0,0};
481 for( ptTotal.x = ptTotal.y = 0; wnd; wnd = wnd->next )
483 if( wnd->dwStyle & WS_VISIBLE )
487 r.left = wnd->rectWindow.left + ptClient.x;
488 r.right = wnd->rectWindow.right + ptClient.x;
489 r.top = wnd->rectWindow.top + ptClient.y;
490 r.bottom = wnd->rectWindow.bottom + ptClient.y;
492 ptOffset.x = r.left - prevOrigin.x;
493 ptOffset.y = r.top - prevOrigin.y;
494 OffsetRect( &r, -ptTotal.x, -ptTotal.y );
496 if( RectInRegion( hRgn, &r ) )
498 OffsetRgn( hRgn, -ptOffset.x, -ptOffset.y );
499 RDW_UpdateRgns( wnd, hRgn, flags );
500 prevOrigin.x = r.left + ptTotal.x;
501 prevOrigin.y = r.top + ptTotal.y;
502 ptTotal.x += ptOffset.x;
503 ptTotal.y += ptOffset.y;
507 OffsetRgn( hRgn, ptTotal.x, ptTotal.y );
512 /* handle hRgn == 1 (alias for entire window) and/or internal paint recursion */
517 for( wnd = wndPtr->child; wnd; wnd = wnd->next )
518 if( wnd->dwStyle & WS_VISIBLE )
519 RDW_UpdateRgns( wnd, hRgn, flags );
524 /* Set/clear internal paint flag */
526 if (flags & RDW_INTERNALPAINT)
528 if ( !wndPtr->hrgnUpdate && !(wndPtr->flags & WIN_INTERNAL_PAINT))
529 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
530 wndPtr->flags |= WIN_INTERNAL_PAINT;
532 else if (flags & RDW_NOINTERNALPAINT)
534 if ( !wndPtr->hrgnUpdate && (wndPtr->flags & WIN_INTERNAL_PAINT))
535 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
536 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
540 /***********************************************************************
541 * RDW_Paint [RedrawWindow() helper]
543 * Walks the window tree and paints/erases windows that have
544 * nonzero update regions according to redraw flags. hrgn is a scratch
545 * region passed down during recursion. Must not be 1.
548 static HRGN RDW_Paint( WND* wndPtr, HRGN hrgn, UINT flags, UINT ex )
550 /* NOTE: wndPtr is locked by caller.
552 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
553 * SendMessage() calls. This is a comment inside DefWindowProc() source
556 * This message avoids lots of inter-app message traffic
557 * by switching to the other task and continuing the
561 * LOWORD(lParam) = hrgnClip
562 * HIWORD(lParam) = hwndSkip (not used; always NULL)
566 HWND hWnd = wndPtr->hwndSelf;
567 BOOL bIcon = ((wndPtr->dwStyle & WS_MINIMIZE) && GetClassWord(wndPtr->hwndSelf, GCW_HICON));
569 /* Erase/update the window itself ... */
571 TRACE_(win)("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", hWnd, wndPtr->hrgnUpdate, hrgn, flags );
573 if (flags & RDW_UPDATENOW)
575 if (wndPtr->hrgnUpdate) /* wm_painticon wparam is 1 */
576 SendMessage16( hWnd, (bIcon) ? WM_PAINTICON : WM_PAINT, bIcon, 0 );
578 else if ((flags & RDW_ERASENOW) || (ex & RDW_EX_TOPFRAME))
580 UINT dcx = DCX_INTERSECTRGN | DCX_USESTYLE | DCX_KEEPCLIPRGN | DCX_WINDOWPAINT | DCX_CACHE;
581 HRGN hrgnRet = WIN_UpdateNCRgn( wndPtr, hrgn, UNC_REGION | UNC_CHECK |
582 ((ex & RDW_EX_TOPFRAME) ? UNC_ENTIRE : 0) );
585 if( hrgnRet > 1 ) hrgn = hrgnRet; else hrgnRet = 0; /* entire client */
586 if( wndPtr->flags & WIN_NEEDS_ERASEBKGND )
588 if( bIcon ) dcx |= DCX_WINDOW;
591 OffsetRgn( hrgnRet, wndPtr->rectWindow.left - wndPtr->rectClient.left,
592 wndPtr->rectWindow.top - wndPtr->rectClient.top);
594 dcx &= ~DCX_INTERSECTRGN;
595 if (( hDC = GetDCEx( hWnd, hrgnRet, dcx )) )
597 if (SendMessage16( hWnd, (bIcon) ? WM_ICONERASEBKGND
598 : WM_ERASEBKGND, (WPARAM16)hDC, 0 ))
599 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
600 ReleaseDC( hWnd, hDC );
606 if( !IsWindow(hWnd) ) return hrgn;
607 ex &= ~RDW_EX_TOPFRAME;
609 /* ... and its child windows */
611 if( wndPtr->child && !(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE)
612 && ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) )
616 if( (list = WIN_BuildWinArray( wndPtr, 0, NULL )) )
619 for (ppWnd = list; *ppWnd; ppWnd++)
621 WIN_UpdateWndPtr(&wndPtr,*ppWnd);
622 if (!IsWindow(wndPtr->hwndSelf)) continue;
623 if ( (wndPtr->dwStyle & WS_VISIBLE) &&
624 (wndPtr->hrgnUpdate || (wndPtr->flags & WIN_INTERNAL_PAINT)) )
625 hrgn = RDW_Paint( wndPtr, hrgn, flags, ex );
627 WIN_ReleaseWndPtr(wndPtr);
628 WIN_ReleaseWinArray(list);
635 /***********************************************************************
639 BOOL PAINT_RedrawWindow( HWND hwnd, const RECT *rectUpdate,
640 HRGN hrgnUpdate, UINT flags, UINT ex )
647 if (!hwnd) hwnd = GetDesktopWindow();
648 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
650 /* check if the window or its parents are visible/not minimized */
652 if (!WIN_IsWindowDrawable( wndPtr, !(flags & RDW_FRAME) ) )
654 WIN_ReleaseWndPtr(wndPtr);
662 GetRgnBox( hrgnUpdate, &r );
663 TRACE_(win)( "%04x (%04x) NULL %04x box (%i,%i-%i,%i) flags=%04x, exflags=%04x\n",
664 hwnd, wndPtr->hrgnUpdate, hrgnUpdate, r.left, r.top, r.right, r.bottom, flags, ex);
672 TRACE_(win)( "%04x (%04x) %s %d,%d-%d,%d %04x flags=%04x, exflags=%04x\n",
673 hwnd, wndPtr->hrgnUpdate, rectUpdate ? "rect" : "NULL", r.left,
674 r.top, r.right, r.bottom, hrgnUpdate, flags, ex );
678 /* prepare an update region in window coordinates */
680 if( flags & RDW_FRAME )
681 r = wndPtr->rectWindow;
683 r = wndPtr->rectClient;
685 if( ex & RDW_EX_XYWINDOW )
688 OffsetRect( &r, -wndPtr->rectWindow.left, -wndPtr->rectWindow.top );
692 pt.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
693 pt.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
694 OffsetRect( &r, -wndPtr->rectClient.left, -wndPtr->rectClient.top );
697 if (flags & RDW_INVALIDATE) /* ------------------------- Invalidate */
699 /* If the window doesn't have hrgnUpdate we leave hRgn zero
700 * and put a new region straight into wndPtr->hrgnUpdate
701 * so that RDW_UpdateRgns() won't have to do any extra work.
706 if( wndPtr->hrgnUpdate )
707 hRgn = REGION_CropRgn( 0, hrgnUpdate, NULL, &pt );
709 wndPtr->hrgnUpdate = REGION_CropRgn( 0, hrgnUpdate, &r, &pt );
711 else if( rectUpdate )
713 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
714 OffsetRect( &r2, pt.x, pt.y );
717 if( wndPtr->hrgnUpdate == 0 )
718 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r2 );
720 hRgn = CreateRectRgnIndirect( &r2 );
722 else /* entire window or client depending on RDW_FRAME */
724 if( flags & RDW_FRAME )
726 if( wndPtr->hrgnUpdate )
727 DeleteObject( wndPtr->hrgnUpdate );
728 wndPtr->hrgnUpdate = 1;
732 GETCLIENTRECTW( wndPtr, r2 );
737 else if (flags & RDW_VALIDATE) /* ------------------------- Validate */
739 /* In this we cannot leave with zero hRgn */
742 hRgn = REGION_CropRgn( hRgn, hrgnUpdate, &r, &pt );
743 GetRgnBox( hRgn, &r2 );
744 if( IsRectEmpty( &r2 ) ) goto END;
746 else if( rectUpdate )
748 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
749 OffsetRect( &r2, pt.x, pt.y );
751 hRgn = CreateRectRgnIndirect( &r2 );
753 else /* entire window or client depending on RDW_FRAME */
755 if( flags & RDW_FRAME )
759 GETCLIENTRECTW( wndPtr, r2 );
765 /* At this point hRgn is either an update region in window coordinates or 1 or 0 */
767 RDW_UpdateRgns( wndPtr, hRgn, flags );
769 /* Erase/update windows, from now on hRgn is a scratch region */
771 hRgn = RDW_Paint( wndPtr, (hRgn == 1) ? 0 : hRgn, flags, ex );
774 if( hRgn > 1 && (hRgn != hrgnUpdate) )
776 WIN_ReleaseWndPtr(wndPtr);
781 /***********************************************************************
782 * RedrawWindow32 (USER32.426)
784 BOOL WINAPI RedrawWindow( HWND hwnd, const RECT *rectUpdate,
785 HRGN hrgnUpdate, UINT flags )
787 return PAINT_RedrawWindow( hwnd, rectUpdate, hrgnUpdate, flags, 0 );
791 /***********************************************************************
792 * RedrawWindow16 (USER.290)
794 BOOL16 WINAPI RedrawWindow16( HWND16 hwnd, const RECT16 *rectUpdate,
795 HRGN16 hrgnUpdate, UINT16 flags )
800 CONV_RECT16TO32( rectUpdate, &r );
801 return (BOOL16)RedrawWindow( (HWND)hwnd, &r, hrgnUpdate, flags );
803 return (BOOL16)PAINT_RedrawWindow( (HWND)hwnd, NULL,
804 (HRGN)hrgnUpdate, flags, 0 );
808 /***********************************************************************
809 * UpdateWindow16 (USER.124)
811 void WINAPI UpdateWindow16( HWND16 hwnd )
813 PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
816 /***********************************************************************
817 * UpdateWindow32 (USER32.567)
819 void WINAPI UpdateWindow( HWND hwnd )
821 PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
824 /***********************************************************************
825 * InvalidateRgn16 (USER.126)
827 void WINAPI InvalidateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
829 PAINT_RedrawWindow((HWND)hwnd, NULL, (HRGN)hrgn,
830 RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
834 /***********************************************************************
835 * InvalidateRgn32 (USER32.329)
837 BOOL WINAPI InvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
839 return PAINT_RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
843 /***********************************************************************
844 * InvalidateRect16 (USER.125)
846 void WINAPI InvalidateRect16( HWND16 hwnd, const RECT16 *rect, BOOL16 erase )
848 RedrawWindow16( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
852 /***********************************************************************
853 * InvalidateRect32 (USER32.328)
855 BOOL WINAPI InvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
857 return PAINT_RedrawWindow( hwnd, rect, 0,
858 RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
862 /***********************************************************************
863 * ValidateRgn16 (USER.128)
865 void WINAPI ValidateRgn16( HWND16 hwnd, HRGN16 hrgn )
867 PAINT_RedrawWindow( (HWND)hwnd, NULL, (HRGN)hrgn,
868 RDW_VALIDATE | RDW_NOCHILDREN, 0 );
872 /***********************************************************************
873 * ValidateRgn32 (USER32.572)
875 void WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
877 PAINT_RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
881 /***********************************************************************
882 * ValidateRect16 (USER.127)
884 void WINAPI ValidateRect16( HWND16 hwnd, const RECT16 *rect )
886 RedrawWindow16( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
890 /***********************************************************************
891 * ValidateRect32 (USER32.571)
893 void WINAPI ValidateRect( HWND hwnd, const RECT *rect )
895 PAINT_RedrawWindow( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
899 /***********************************************************************
900 * GetUpdateRect16 (USER.190)
902 BOOL16 WINAPI GetUpdateRect16( HWND16 hwnd, LPRECT16 rect, BOOL16 erase )
907 if (!rect) return GetUpdateRect( hwnd, NULL, erase );
908 ret = GetUpdateRect( hwnd, &r, erase );
909 CONV_RECT32TO16( &r, rect );
914 /***********************************************************************
915 * GetUpdateRect32 (USER32.297)
917 BOOL WINAPI GetUpdateRect( HWND hwnd, LPRECT rect, BOOL erase )
920 WND * wndPtr = WIN_FindWndPtr( hwnd );
921 if (!wndPtr) return FALSE;
925 if (wndPtr->hrgnUpdate > 1)
927 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
928 if (GetUpdateRgn( hwnd, hrgn, erase ) == ERROR)
933 GetRgnBox( hrgn, rect );
934 DeleteObject( hrgn );
935 if (GetClassLongA(wndPtr->hwndSelf, GCL_STYLE) & CS_OWNDC)
937 if (GetMapMode(wndPtr->dce->hDC) != MM_TEXT)
939 DPtoLP (wndPtr->dce->hDC, (LPPOINT)rect, 2);
944 if( wndPtr->hrgnUpdate == 1 )
946 GetClientRect( hwnd, rect );
947 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_ERASENOW | RDW_NOCHILDREN );
950 SetRectEmpty( rect );
952 retvalue = (wndPtr->hrgnUpdate >= 1);
954 WIN_ReleaseWndPtr(wndPtr);
959 /***********************************************************************
960 * GetUpdateRgn16 (USER.237)
962 INT16 WINAPI GetUpdateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
964 return GetUpdateRgn( hwnd, hrgn, erase );
968 /***********************************************************************
969 * GetUpdateRgn (USER32.298)
971 INT WINAPI GetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
974 WND * wndPtr = WIN_FindWndPtr( hwnd );
975 if (!wndPtr) return ERROR;
977 if (wndPtr->hrgnUpdate == 0)
979 SetRectRgn( hrgn, 0, 0, 0, 0 );
984 if (wndPtr->hrgnUpdate == 1)
986 SetRectRgn( hrgn, 0, 0, wndPtr->rectClient.right - wndPtr->rectClient.left,
987 wndPtr->rectClient.bottom - wndPtr->rectClient.top );
988 retval = SIMPLEREGION;
992 retval = CombineRgn( hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY );
993 OffsetRgn( hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
994 wndPtr->rectWindow.top - wndPtr->rectClient.top );
996 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW | RDW_NOCHILDREN );
998 WIN_ReleaseWndPtr(wndPtr);
1003 /***********************************************************************
1004 * ExcludeUpdateRgn16 (USER.238)
1006 INT16 WINAPI ExcludeUpdateRgn16( HDC16 hdc, HWND16 hwnd )
1008 return ExcludeUpdateRgn( hdc, hwnd );
1012 /***********************************************************************
1013 * ExcludeUpdateRgn32 (USER32.195)
1015 INT WINAPI ExcludeUpdateRgn( HDC hdc, HWND hwnd )
1020 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return ERROR;
1022 if (wndPtr->hrgnUpdate)
1025 HRGN hrgn = CreateRectRgn(wndPtr->rectWindow.left - wndPtr->rectClient.left,
1026 wndPtr->rectWindow.top - wndPtr->rectClient.top,
1027 wndPtr->rectWindow.right - wndPtr->rectClient.left,
1028 wndPtr->rectWindow.bottom - wndPtr->rectClient.top);
1029 if( wndPtr->hrgnUpdate > 1 )
1031 CombineRgn(hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY);
1032 OffsetRgn(hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
1033 wndPtr->rectWindow.top - wndPtr->rectClient.top );
1036 /* do ugly coordinate translations in dce.c */
1038 ret = DCE_ExcludeRgn( hdc, wndPtr, hrgn );
1039 DeleteObject( hrgn );
1040 WIN_ReleaseWndPtr(wndPtr);
1043 WIN_ReleaseWndPtr(wndPtr);
1044 return GetClipBox( hdc, &rect );