Stubs for Get/SetProcessDefaultLayout.
[wine.git] / windows / painting.c
blob5a65275cec886db1aee95addf7785177317a95ef
1 /*
2 * Window painting functions
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1999 Alex Korobka
6 */
8 #include "region.h"
9 #include "win.h"
10 #include "queue.h"
11 #include "dce.h"
12 #include "heap.h"
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 /***********************************************************************
31 * WIN_HaveToDelayNCPAINT
33 * Currently, in the Wine painting mechanism, the WM_NCPAINT message
34 * is generated as soon as a region intersecting the non-client area
35 * of a window is invalidated.
37 * This technique will work fine for all windows whose parents
38 * have the WS_CLIPCHILDREN style. When the parents have that style,
39 * they are not going to override the contents of their children.
40 * However, when the parent doesn't have that style, Windows relies
41 * on a "painter's algorithm" to display the contents of the windows.
42 * That is, windows are painted from back to front. This includes the
43 * non-client area.
45 * This method looks at the current state of a window to determine
46 * if the sending of the WM_NCPAINT message should be delayed until
47 * the BeginPaint call.
49 * PARAMS:
50 * wndPtr - A Locked window pointer to the window we're
51 * examining.
52 * uncFlags - This is the flag passed to the WIN_UpdateNCRgn
53 * function. This is a shortcut for the cases when
54 * we already know when to avoid scanning all the
55 * parents of a window. If you already know that this
56 * window's NCPAINT should be delayed, set the
57 * UNC_DELAY_NCPAINT flag for this parameter.
59 * This shortcut behavior is implemented in the
60 * RDW_Paint() method.
63 static BOOL WIN_HaveToDelayNCPAINT(
64 WND* wndPtr,
65 UINT uncFlags)
67 WND* parentWnd = NULL;
70 * Test the shortcut first. (duh)
72 if (uncFlags & UNC_DELAY_NCPAINT)
73 return TRUE;
76 * The UNC_IN_BEGINPAINT flag is set in the BeginPaint
77 * method only. This is another shortcut to avoid going
78 * up the parent's chain of the window to finally
79 * figure-out that none of them has an invalid region.
81 if (uncFlags & UNC_IN_BEGINPAINT)
82 return FALSE;
85 * Scan all the parents of this window to find a window
86 * that doesn't have the WS_CLIPCHILDREN style and that
87 * has an invalid region.
89 parentWnd = WIN_LockWndPtr(wndPtr->parent);
91 while (parentWnd!=NULL)
93 if ( ((parentWnd->dwStyle & WS_CLIPCHILDREN) == 0) &&
94 (parentWnd->hrgnUpdate != 0) )
96 WIN_ReleaseWndPtr(parentWnd);
97 return TRUE;
100 WIN_UpdateWndPtr(&parentWnd, parentWnd->parent);
103 WIN_ReleaseWndPtr(parentWnd);
105 return FALSE;
108 /***********************************************************************
109 * WIN_UpdateNCRgn
111 * Things to do:
112 * Send WM_NCPAINT if required (when nonclient is invalid or UNC_ENTIRE flag is set)
113 * Crop hrgnUpdate to a client rect, especially if it 1.
114 * If UNC_REGION is set return update region for the client rect.
116 * NOTE: UNC_REGION is mainly for the RDW_Paint() chunk that sends WM_ERASEBKGND message.
117 * The trick is that when the returned region handle may be different from hRgn.
118 * In this case the old hRgn must be considered gone. BUT, if the returned value
119 * is 1 then the hRgn is preserved and RDW_Paint() will have to get
120 * a DC without extra clipping region.
122 HRGN WIN_UpdateNCRgn(WND* wnd, HRGN hRgn, UINT uncFlags )
124 RECT r;
125 HRGN hClip = 0;
126 HRGN hrgnRet = 0;
128 TRACE_(nonclient)("hwnd %04x [%04x] hrgn %04x, unc %04x, ncf %i\n",
129 wnd->hwndSelf, wnd->hrgnUpdate, hRgn, uncFlags, wnd->flags & WIN_NEEDS_NCPAINT);
131 /* desktop window doesn't have a nonclient area */
132 if(wnd == WIN_GetDesktop())
134 wnd->flags &= ~WIN_NEEDS_NCPAINT;
135 if( wnd->hrgnUpdate > 1 )
136 hrgnRet = REGION_CropRgn( hRgn, wnd->hrgnUpdate, NULL, NULL );
137 else
139 hrgnRet = wnd->hrgnUpdate;
141 WIN_ReleaseDesktop();
142 return hrgnRet;
144 WIN_ReleaseDesktop();
146 if ((wnd->hwndSelf == GetForegroundWindow()) &&
147 !(wnd->flags & WIN_NCACTIVATED) )
149 wnd->flags |= WIN_NCACTIVATED;
150 uncFlags |= UNC_ENTIRE;
154 * If the window's non-client area needs to be painted,
156 if ( ( wnd->flags & WIN_NEEDS_NCPAINT ) &&
157 !WIN_HaveToDelayNCPAINT(wnd, uncFlags) )
159 RECT r2, r3;
161 wnd->flags &= ~WIN_NEEDS_NCPAINT;
162 GETCLIENTRECTW( wnd, r );
164 TRACE_(nonclient)( "\tclient box (%i,%i-%i,%i), hrgnUpdate %04x\n",
165 r.left, r.top, r.right, r.bottom, wnd->hrgnUpdate );
166 if( wnd->hrgnUpdate > 1 )
168 /* Check if update rgn overlaps with nonclient area */
170 GetRgnBox( wnd->hrgnUpdate, &r2 );
171 UnionRect( &r3, &r2, &r );
172 if( r3.left != r.left || r3.top != r.top ||
173 r3.right != r.right || r3.bottom != r.bottom ) /* it does */
175 /* crop hrgnUpdate, save old one in hClip - the only
176 * case that places a valid region handle in hClip */
178 hClip = wnd->hrgnUpdate;
179 wnd->hrgnUpdate = REGION_CropRgn( hRgn, hClip, &r, NULL );
180 if( uncFlags & UNC_REGION ) hrgnRet = hClip;
183 if( uncFlags & UNC_CHECK )
185 GetRgnBox( wnd->hrgnUpdate, &r3 );
186 if( IsRectEmpty( &r3 ) )
188 /* delete the update region since all invalid
189 * parts were in the nonclient area */
191 DeleteObject( wnd->hrgnUpdate );
192 wnd->hrgnUpdate = 0;
193 if(!(wnd->flags & WIN_INTERNAL_PAINT))
194 QUEUE_DecPaintCount( wnd->hmemTaskQ );
196 wnd->flags &= ~WIN_NEEDS_ERASEBKGND;
200 if(!hClip && wnd->hrgnUpdate ) goto copyrgn;
202 else
203 if( wnd->hrgnUpdate == 1 )/* entire window */
205 if( uncFlags & UNC_UPDATE ) wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
206 if( uncFlags & UNC_REGION ) hrgnRet = 1;
207 uncFlags |= UNC_ENTIRE;
210 else /* no WM_NCPAINT unless forced */
212 if( wnd->hrgnUpdate > 1 )
214 copyrgn:
215 if( uncFlags & UNC_REGION )
216 hrgnRet = REGION_CropRgn( hRgn, wnd->hrgnUpdate, NULL, NULL );
218 else
219 if( wnd->hrgnUpdate == 1 && (uncFlags & UNC_UPDATE) )
221 GETCLIENTRECTW( wnd, r );
222 wnd->hrgnUpdate = CreateRectRgnIndirect( &r );
223 if( uncFlags & UNC_REGION ) hrgnRet = 1;
227 if(!hClip && (uncFlags & UNC_ENTIRE) )
229 /* still don't do anything if there is no nonclient area */
230 hClip = (memcmp( &wnd->rectWindow, &wnd->rectClient, sizeof(RECT) ) != 0);
233 if( hClip ) /* NOTE: WM_NCPAINT allows wParam to be 1 */
235 if ( hClip == hrgnRet && hrgnRet > 1 ) {
236 hClip = CreateRectRgn( 0, 0, 0, 0 );
237 CombineRgn( hClip, hrgnRet, 0, RGN_COPY );
240 SendMessageA( wnd->hwndSelf, WM_NCPAINT, hClip, 0L );
241 if( (hClip > 1) && (hClip != hRgn) && (hClip != hrgnRet) )
242 DeleteObject( hClip );
244 * Since all Window locks are suspended while processing the WM_NCPAINT
245 * we want to make sure the window still exists before continuing.
247 if (!IsWindow(wnd->hwndSelf))
249 DeleteObject(hrgnRet);
250 hrgnRet=0;
254 TRACE_(nonclient)("returning %04x (hClip = %04x, hrgnUpdate = %04x)\n", hrgnRet, hClip, wnd->hrgnUpdate );
256 return hrgnRet;
260 /***********************************************************************
261 * BeginPaint16 (USER.39)
263 HDC16 WINAPI BeginPaint16( HWND16 hwnd, LPPAINTSTRUCT16 lps )
265 BOOL bIcon;
266 HRGN hrgnUpdate;
267 RECT16 clipRect, clientRect;
268 WND *wndPtr = WIN_FindWndPtr( hwnd );
269 if (!wndPtr) return 0;
271 bIcon = (wndPtr->dwStyle & WS_MINIMIZE && GetClassWord(wndPtr->hwndSelf, GCW_HICON));
273 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
275 /* send WM_NCPAINT and make sure hrgnUpdate is a valid rgn handle */
276 WIN_UpdateNCRgn( wndPtr, 0, UNC_UPDATE | UNC_IN_BEGINPAINT);
279 * Make sure the window is still a window. All window locks are suspended
280 * when the WM_NCPAINT is sent.
282 if (!IsWindow(wndPtr->hwndSelf))
284 WIN_ReleaseWndPtr(wndPtr);
285 return 0;
288 if( ((hrgnUpdate = wndPtr->hrgnUpdate) != 0) || (wndPtr->flags & WIN_INTERNAL_PAINT))
289 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
291 wndPtr->hrgnUpdate = 0;
292 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
294 HideCaret( hwnd );
296 TRACE_(win)("hrgnUpdate = %04x, \n", hrgnUpdate);
298 if (GetClassWord16(wndPtr->hwndSelf, GCW_STYLE) & CS_PARENTDC)
300 /* Don't clip the output to the update region for CS_PARENTDC window */
301 if( hrgnUpdate )
302 DeleteObject(hrgnUpdate);
303 lps->hdc = GetDCEx16( hwnd, 0, DCX_WINDOWPAINT | DCX_USESTYLE |
304 (bIcon ? DCX_WINDOW : 0) );
306 else
308 if( hrgnUpdate ) /* convert to client coordinates */
309 OffsetRgn( hrgnUpdate, wndPtr->rectWindow.left - wndPtr->rectClient.left,
310 wndPtr->rectWindow.top - wndPtr->rectClient.top );
311 lps->hdc = GetDCEx16(hwnd, hrgnUpdate, DCX_INTERSECTRGN |
312 DCX_WINDOWPAINT | DCX_USESTYLE | (bIcon ? DCX_WINDOW : 0) );
313 /* ReleaseDC() in EndPaint() will delete the region */
316 TRACE_(win)("hdc = %04x\n", lps->hdc);
318 if (!lps->hdc)
320 WARN_(win)("GetDCEx() failed in BeginPaint(), hwnd=%04x\n", hwnd);
321 WIN_ReleaseWndPtr(wndPtr);
322 return 0;
325 /* It is possible that the clip box is bigger than the window itself,
326 if CS_PARENTDC flag is set. Windows never return a paint rect bigger
327 than the window itself, so we need to intersect the cliprect with
328 the window */
330 GetClipBox16( lps->hdc, &clipRect );
331 GetClientRect16( hwnd, &clientRect );
333 /* The rect obtained by GetClipBox is in logical, so make the client in logical to*/
334 DPtoLP16(lps->hdc, (LPPOINT16) &clientRect, 2);
336 IntersectRect16(&lps->rcPaint, &clientRect, &clipRect);
338 TRACE_(win)("box = (%i,%i - %i,%i)\n", lps->rcPaint.left, lps->rcPaint.top,
339 lps->rcPaint.right, lps->rcPaint.bottom );
341 if (wndPtr->flags & WIN_NEEDS_ERASEBKGND)
343 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
344 lps->fErase = !SendMessage16(hwnd, (bIcon) ? WM_ICONERASEBKGND
345 : WM_ERASEBKGND,
346 (WPARAM16)lps->hdc, 0 );
348 else lps->fErase = TRUE;
350 WIN_ReleaseWndPtr(wndPtr);
351 return lps->hdc;
355 /***********************************************************************
356 * BeginPaint32 (USER32.10)
358 HDC WINAPI BeginPaint( HWND hwnd, PAINTSTRUCT *lps )
360 PAINTSTRUCT16 ps;
362 BeginPaint16( hwnd, &ps );
363 lps->hdc = (HDC)ps.hdc;
364 lps->fErase = ps.fErase;
365 lps->rcPaint.top = ps.rcPaint.top;
366 lps->rcPaint.left = ps.rcPaint.left;
367 lps->rcPaint.right = ps.rcPaint.right;
368 lps->rcPaint.bottom = ps.rcPaint.bottom;
369 lps->fRestore = ps.fRestore;
370 lps->fIncUpdate = ps.fIncUpdate;
371 return lps->hdc;
375 /***********************************************************************
376 * EndPaint16 (USER.40)
378 BOOL16 WINAPI EndPaint16( HWND16 hwnd, const PAINTSTRUCT16* lps )
380 ReleaseDC16( hwnd, lps->hdc );
381 ShowCaret( hwnd );
382 return TRUE;
386 /***********************************************************************
387 * EndPaint32 (USER32.176)
389 BOOL WINAPI EndPaint( HWND hwnd, const PAINTSTRUCT *lps )
391 ReleaseDC( hwnd, lps->hdc );
392 ShowCaret( hwnd );
393 return TRUE;
397 /***********************************************************************
398 * FillWindow (USER.324)
400 void WINAPI FillWindow16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc, HBRUSH16 hbrush )
402 RECT16 rect;
403 GetClientRect16( hwnd, &rect );
404 DPtoLP16( hdc, (LPPOINT16)&rect, 2 );
405 PaintRect16( hwndParent, hwnd, hdc, hbrush, &rect );
409 /***********************************************************************
410 * PAINT_GetControlBrush
412 static HBRUSH16 PAINT_GetControlBrush( HWND hParent, HWND hWnd, HDC16 hDC, UINT16 ctlType )
414 HBRUSH16 bkgBrush = (HBRUSH16)SendMessageA( hParent, WM_CTLCOLORMSGBOX + ctlType,
415 (WPARAM)hDC, (LPARAM)hWnd );
416 if( !IsGDIObject16(bkgBrush) )
417 bkgBrush = DEFWND_ControlColor( hDC, ctlType );
418 return bkgBrush;
422 /***********************************************************************
423 * PaintRect (USER.325)
425 void WINAPI PaintRect16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc,
426 HBRUSH16 hbrush, const RECT16 *rect)
428 if( hbrush <= CTLCOLOR_MAX )
430 if( hwndParent )
431 hbrush = PAINT_GetControlBrush( hwndParent, hwnd, hdc, (UINT16)hbrush );
432 else
433 return;
435 if( hbrush )
436 FillRect16( hdc, rect, hbrush );
440 /***********************************************************************
441 * GetControlBrush (USER.326)
443 HBRUSH16 WINAPI GetControlBrush16( HWND16 hwnd, HDC16 hdc, UINT16 ctlType )
445 WND* wndPtr = WIN_FindWndPtr( hwnd );
446 HBRUSH16 retvalue;
448 if((ctlType <= CTLCOLOR_MAX) && wndPtr )
450 WND* parent;
451 if( wndPtr->dwStyle & WS_POPUP ) parent = WIN_LockWndPtr(wndPtr->owner);
452 else parent = WIN_LockWndPtr(wndPtr->parent);
453 if( !parent ) parent = wndPtr;
454 retvalue = (HBRUSH16)PAINT_GetControlBrush( parent->hwndSelf, hwnd, hdc, ctlType );
455 WIN_ReleaseWndPtr(parent);
456 goto END;
458 retvalue = (HBRUSH16)0;
459 END:
460 WIN_ReleaseWndPtr(wndPtr);
461 return retvalue;
465 /***********************************************************************
466 * RDW_ValidateParent [RDW_UpdateRgns() helper]
468 * Validate the portions of parent that are covered by a validated child
469 * wndPtr = child
471 void RDW_ValidateParent(WND *wndChild)
473 WND *wndParent = WIN_LockWndPtr(wndChild->parent);
474 WND *wndDesktop = WIN_GetDesktop();
476 if ((wndParent) && (wndParent != wndDesktop) && !(wndParent->dwStyle & WS_CLIPCHILDREN))
478 HRGN hrg;
479 if (wndChild->hrgnUpdate == 1 )
481 RECT r;
483 r.left = 0;
484 r.top = 0;
485 r.right = wndChild->rectWindow.right - wndChild->rectWindow.left;
486 r.bottom = wndChild->rectWindow.bottom - wndChild->rectWindow.top;
488 hrg = CreateRectRgnIndirect( &r );
490 else
491 hrg = wndChild->hrgnUpdate;
492 if (wndParent->hrgnUpdate != 0)
494 POINT ptOffset;
495 RECT rect, rectParent;
496 if( wndParent->hrgnUpdate == 1 )
498 RECT r;
500 r.left = 0;
501 r.top = 0;
502 r.right = wndParent->rectWindow.right - wndParent->rectWindow.left;
503 r.bottom = wndParent->rectWindow.bottom - wndParent->rectWindow.top;
505 wndParent->hrgnUpdate = CreateRectRgnIndirect( &r );
507 /* we must offset the child region by the offset of the child rect in the parent */
508 GetWindowRect(wndParent->hwndSelf, &rectParent);
509 GetWindowRect(wndChild->hwndSelf, &rect);
510 ptOffset.x = rect.left - rectParent.left;
511 ptOffset.y = rect.top - rectParent.top;
512 OffsetRgn( hrg, ptOffset.x, ptOffset.y );
513 CombineRgn( wndParent->hrgnUpdate, wndParent->hrgnUpdate, hrg, RGN_DIFF );
514 OffsetRgn( hrg, -ptOffset.x, -ptOffset.y );
516 if (hrg != wndChild->hrgnUpdate) DeleteObject( hrg );
518 WIN_ReleaseWndPtr(wndParent);
519 WIN_ReleaseDesktop();
522 /***********************************************************************
523 * RDW_UpdateRgns [RedrawWindow() helper]
525 * Walks the window tree and adds/removes parts of the hRgn to/from update
526 * regions of windows that overlap it. Also, manages internal paint flags.
528 * NOTE: Walks the window tree so the caller must lock it.
529 * MUST preserve hRgn (can modify but then has to restore).
531 static void RDW_UpdateRgns( WND* wndPtr, HRGN hRgn, UINT flags, BOOL firstRecursLevel )
534 * Called only when one of the following is set:
535 * (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT)
538 BOOL bHadOne = wndPtr->hrgnUpdate && hRgn;
539 BOOL bChildren = ( wndPtr->child && !(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE)
540 && ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) );
541 RECT r;
543 r.left = 0;
544 r.top = 0;
545 r.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
546 r.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
548 TRACE_(win)("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", wndPtr->hwndSelf, wndPtr->hrgnUpdate, hRgn, flags );
550 if( flags & RDW_INVALIDATE )
552 if( hRgn > 1 )
554 switch( wndPtr->hrgnUpdate )
556 default:
557 CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_OR );
558 /* fall through */
559 case 0:
560 wndPtr->hrgnUpdate = REGION_CropRgn( wndPtr->hrgnUpdate,
561 wndPtr->hrgnUpdate ? wndPtr->hrgnUpdate : hRgn,
562 &r, NULL );
563 if( !bHadOne )
565 GetRgnBox( wndPtr->hrgnUpdate, &r );
566 if( IsRectEmpty( &r ) )
568 DeleteObject( wndPtr->hrgnUpdate );
569 wndPtr->hrgnUpdate = 0;
570 goto OUT;
573 break;
574 case 1: /* already an entire window */
575 break;
578 else if( hRgn == 1 )
580 if( wndPtr->hrgnUpdate > 1 )
581 DeleteObject( wndPtr->hrgnUpdate );
582 wndPtr->hrgnUpdate = 1;
584 else
585 hRgn = wndPtr->hrgnUpdate; /* this is a trick that depends on code in PAINT_RedrawWindow() */
587 if( !bHadOne && !(wndPtr->flags & WIN_INTERNAL_PAINT) )
588 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
590 if (flags & RDW_FRAME) wndPtr->flags |= WIN_NEEDS_NCPAINT;
591 if (flags & RDW_ERASE) wndPtr->flags |= WIN_NEEDS_ERASEBKGND;
592 flags |= RDW_FRAME;
594 else if( flags & RDW_VALIDATE )
596 if( wndPtr->hrgnUpdate )
598 if( hRgn > 1 )
600 if( wndPtr->hrgnUpdate == 1 )
601 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r );
603 if( CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_DIFF )
604 == NULLREGION )
605 goto EMPTY;
607 else /* validate everything */
609 if( wndPtr->hrgnUpdate > 1 )
611 EMPTY:
612 DeleteObject( wndPtr->hrgnUpdate );
614 wndPtr->hrgnUpdate = 0;
617 if( !wndPtr->hrgnUpdate )
619 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
620 if( !(wndPtr->flags & WIN_INTERNAL_PAINT) )
621 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
625 if (flags & RDW_NOFRAME) wndPtr->flags &= ~WIN_NEEDS_NCPAINT;
626 if (flags & RDW_NOERASE) wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
630 if ((firstRecursLevel) && (wndPtr->hrgnUpdate != 0) && (flags & RDW_UPDATENOW))
631 RDW_ValidateParent(wndPtr); /* validate parent covered by region */
633 /* in/validate child windows that intersect with the region if it
634 * is a valid handle. */
636 if( flags & (RDW_INVALIDATE | RDW_VALIDATE) )
638 if( hRgn > 1 && bChildren )
640 WND* wnd = wndPtr->child;
641 POINT ptTotal, prevOrigin = {0,0};
642 POINT ptClient;
644 ptClient.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
645 ptClient.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
647 for( ptTotal.x = ptTotal.y = 0; wnd; wnd = wnd->next )
649 if( wnd->dwStyle & WS_VISIBLE )
651 POINT ptOffset;
653 r.left = wnd->rectWindow.left + ptClient.x;
654 r.right = wnd->rectWindow.right + ptClient.x;
655 r.top = wnd->rectWindow.top + ptClient.y;
656 r.bottom = wnd->rectWindow.bottom + ptClient.y;
658 ptOffset.x = r.left - prevOrigin.x;
659 ptOffset.y = r.top - prevOrigin.y;
660 OffsetRect( &r, -ptTotal.x, -ptTotal.y );
662 if( RectInRegion( hRgn, &r ) )
664 OffsetRgn( hRgn, -ptOffset.x, -ptOffset.y );
665 RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
666 prevOrigin.x = r.left + ptTotal.x;
667 prevOrigin.y = r.top + ptTotal.y;
668 ptTotal.x += ptOffset.x;
669 ptTotal.y += ptOffset.y;
673 OffsetRgn( hRgn, ptTotal.x, ptTotal.y );
674 bChildren = 0;
678 /* handle hRgn == 1 (alias for entire window) and/or internal paint recursion */
680 if( bChildren )
682 WND* wnd;
683 for( wnd = wndPtr->child; wnd; wnd = wnd->next )
684 if( wnd->dwStyle & WS_VISIBLE )
685 RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
688 OUT:
690 /* Set/clear internal paint flag */
692 if (flags & RDW_INTERNALPAINT)
694 if ( !wndPtr->hrgnUpdate && !(wndPtr->flags & WIN_INTERNAL_PAINT))
695 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
696 wndPtr->flags |= WIN_INTERNAL_PAINT;
698 else if (flags & RDW_NOINTERNALPAINT)
700 if ( !wndPtr->hrgnUpdate && (wndPtr->flags & WIN_INTERNAL_PAINT))
701 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
702 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
706 /***********************************************************************
707 * RDW_Paint [RedrawWindow() helper]
709 * Walks the window tree and paints/erases windows that have
710 * nonzero update regions according to redraw flags. hrgn is a scratch
711 * region passed down during recursion. Must not be 1.
714 static HRGN RDW_Paint( WND* wndPtr, HRGN hrgn, UINT flags, UINT ex )
716 /* NOTE: wndPtr is locked by caller.
718 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
719 * SendMessage() calls. This is a comment inside DefWindowProc() source
720 * from 16-bit SDK:
722 * This message avoids lots of inter-app message traffic
723 * by switching to the other task and continuing the
724 * recursion there.
726 * wParam = flags
727 * LOWORD(lParam) = hrgnClip
728 * HIWORD(lParam) = hwndSkip (not used; always NULL)
731 HDC hDC;
732 HWND hWnd = wndPtr->hwndSelf;
733 BOOL bIcon = ((wndPtr->dwStyle & WS_MINIMIZE) && GetClassWord(wndPtr->hwndSelf, GCW_HICON));
735 /* Erase/update the window itself ... */
737 TRACE_(win)("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", hWnd, wndPtr->hrgnUpdate, hrgn, flags );
740 * Check if this window should delay it's processing of WM_NCPAINT.
741 * See WIN_HaveToDelayNCPAINT for a description of the mechanism
743 if ((ex & RDW_EX_DELAY_NCPAINT) || WIN_HaveToDelayNCPAINT(wndPtr, 0) )
744 ex |= RDW_EX_DELAY_NCPAINT;
746 if (flags & RDW_UPDATENOW)
748 if (wndPtr->hrgnUpdate) /* wm_painticon wparam is 1 */
749 SendMessage16( hWnd, (bIcon) ? WM_PAINTICON : WM_PAINT, bIcon, 0 );
751 else if ((flags & RDW_ERASENOW) || (ex & RDW_EX_TOPFRAME))
753 UINT dcx = DCX_INTERSECTRGN | DCX_USESTYLE | DCX_KEEPCLIPRGN | DCX_WINDOWPAINT | DCX_CACHE;
754 HRGN hrgnRet;
756 hrgnRet = WIN_UpdateNCRgn(wndPtr,
757 hrgn,
758 UNC_REGION | UNC_CHECK |
759 ((ex & RDW_EX_TOPFRAME) ? UNC_ENTIRE : 0) |
760 ((ex & RDW_EX_DELAY_NCPAINT) ? UNC_DELAY_NCPAINT : 0) );
762 if( hrgnRet )
764 if( hrgnRet > 1 ) hrgn = hrgnRet; else hrgnRet = 0; /* entire client */
765 if( wndPtr->flags & WIN_NEEDS_ERASEBKGND )
767 if( bIcon ) dcx |= DCX_WINDOW;
768 else
769 if( hrgnRet )
770 OffsetRgn( hrgnRet, wndPtr->rectWindow.left - wndPtr->rectClient.left,
771 wndPtr->rectWindow.top - wndPtr->rectClient.top);
772 else
773 dcx &= ~DCX_INTERSECTRGN;
774 if (( hDC = GetDCEx( hWnd, hrgnRet, dcx )) )
776 if (SendMessage16( hWnd, (bIcon) ? WM_ICONERASEBKGND
777 : WM_ERASEBKGND, (WPARAM16)hDC, 0 ))
778 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
779 ReleaseDC( hWnd, hDC );
785 if( !IsWindow(hWnd) ) return hrgn;
786 ex &= ~RDW_EX_TOPFRAME;
788 /* ... and its child windows */
790 if( wndPtr->child && !(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE)
791 && ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) )
793 WND** list, **ppWnd;
795 if( (list = WIN_BuildWinArray( wndPtr, 0, NULL )) )
797 wndPtr = NULL;
798 for (ppWnd = list; *ppWnd; ppWnd++)
800 WIN_UpdateWndPtr(&wndPtr,*ppWnd);
801 if (!IsWindow(wndPtr->hwndSelf)) continue;
802 if ( (wndPtr->dwStyle & WS_VISIBLE) &&
803 (wndPtr->hrgnUpdate || (wndPtr->flags & WIN_INTERNAL_PAINT)) )
804 hrgn = RDW_Paint( wndPtr, hrgn, flags, ex );
806 WIN_ReleaseWndPtr(wndPtr);
807 WIN_ReleaseWinArray(list);
811 return hrgn;
814 /***********************************************************************
815 * PAINT_RedrawWindow
818 BOOL PAINT_RedrawWindow( HWND hwnd, const RECT *rectUpdate,
819 HRGN hrgnUpdate, UINT flags, UINT ex )
821 HRGN hRgn = 0;
822 RECT r, r2;
823 POINT pt;
824 WND* wndPtr;
826 if (!hwnd) hwnd = GetDesktopWindow();
827 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
829 /* check if the window or its parents are visible/not minimized */
831 if (!WIN_IsWindowDrawable( wndPtr, !(flags & RDW_FRAME) ) )
833 WIN_ReleaseWndPtr(wndPtr);
834 return TRUE;
837 if (TRACE_ON(win))
839 if( hrgnUpdate )
841 GetRgnBox( hrgnUpdate, &r );
842 TRACE_(win)( "%04x (%04x) NULL %04x box (%i,%i-%i,%i) flags=%04x, exflags=%04x\n",
843 hwnd, wndPtr->hrgnUpdate, hrgnUpdate, r.left, r.top, r.right, r.bottom, flags, ex);
845 else
847 if( rectUpdate )
848 r = *rectUpdate;
849 else
850 SetRectEmpty( &r );
851 TRACE_(win)( "%04x (%04x) %s %d,%d-%d,%d %04x flags=%04x, exflags=%04x\n",
852 hwnd, wndPtr->hrgnUpdate, rectUpdate ? "rect" : "NULL", r.left,
853 r.top, r.right, r.bottom, hrgnUpdate, flags, ex );
857 /* prepare an update region in window coordinates */
859 if( flags & RDW_FRAME )
860 r = wndPtr->rectWindow;
861 else
862 r = wndPtr->rectClient;
864 if( ex & RDW_EX_XYWINDOW )
866 pt.x = pt.y = 0;
867 OffsetRect( &r, -wndPtr->rectWindow.left, -wndPtr->rectWindow.top );
869 else
871 pt.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
872 pt.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
873 OffsetRect( &r, -wndPtr->rectClient.left, -wndPtr->rectClient.top );
876 if (flags & RDW_INVALIDATE) /* ------------------------- Invalidate */
878 /* If the window doesn't have hrgnUpdate we leave hRgn zero
879 * and put a new region straight into wndPtr->hrgnUpdate
880 * so that RDW_UpdateRgns() won't have to do any extra work.
883 if( hrgnUpdate )
885 if( wndPtr->hrgnUpdate )
886 hRgn = REGION_CropRgn( 0, hrgnUpdate, NULL, &pt );
887 else
888 wndPtr->hrgnUpdate = REGION_CropRgn( 0, hrgnUpdate, &r, &pt );
890 else if( rectUpdate )
892 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
893 OffsetRect( &r2, pt.x, pt.y );
895 rect2i:
896 if( wndPtr->hrgnUpdate == 0 )
897 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r2 );
898 else
899 hRgn = CreateRectRgnIndirect( &r2 );
901 else /* entire window or client depending on RDW_FRAME */
903 if( flags & RDW_FRAME )
905 if( wndPtr->hrgnUpdate )
906 DeleteObject( wndPtr->hrgnUpdate );
907 wndPtr->hrgnUpdate = 1;
909 else
911 GETCLIENTRECTW( wndPtr, r2 );
912 goto rect2i;
916 else if (flags & RDW_VALIDATE) /* ------------------------- Validate */
918 /* In this we cannot leave with zero hRgn */
919 if( hrgnUpdate )
921 hRgn = REGION_CropRgn( hRgn, hrgnUpdate, &r, &pt );
922 GetRgnBox( hRgn, &r2 );
923 if( IsRectEmpty( &r2 ) ) goto END;
925 else if( rectUpdate )
927 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
928 OffsetRect( &r2, pt.x, pt.y );
929 rect2v:
930 hRgn = CreateRectRgnIndirect( &r2 );
932 else /* entire window or client depending on RDW_FRAME */
934 if( flags & RDW_FRAME )
935 hRgn = 1;
936 else
938 GETCLIENTRECTW( wndPtr, r2 );
939 goto rect2v;
944 /* At this point hRgn is either an update region in window coordinates or 1 or 0 */
946 RDW_UpdateRgns( wndPtr, hRgn, flags, TRUE );
948 /* Erase/update windows, from now on hRgn is a scratch region */
950 hRgn = RDW_Paint( wndPtr, (hRgn == 1) ? 0 : hRgn, flags, ex );
952 END:
953 if( hRgn > 1 && (hRgn != hrgnUpdate) )
954 DeleteObject(hRgn );
955 WIN_ReleaseWndPtr(wndPtr);
956 return TRUE;
960 /***********************************************************************
961 * RedrawWindow32 (USER32.426)
963 BOOL WINAPI RedrawWindow( HWND hwnd, const RECT *rectUpdate,
964 HRGN hrgnUpdate, UINT flags )
966 return PAINT_RedrawWindow( hwnd, rectUpdate, hrgnUpdate, flags, 0 );
970 /***********************************************************************
971 * RedrawWindow16 (USER.290)
973 BOOL16 WINAPI RedrawWindow16( HWND16 hwnd, const RECT16 *rectUpdate,
974 HRGN16 hrgnUpdate, UINT16 flags )
976 if (rectUpdate)
978 RECT r;
979 CONV_RECT16TO32( rectUpdate, &r );
980 return (BOOL16)RedrawWindow( (HWND)hwnd, &r, hrgnUpdate, flags );
982 return (BOOL16)PAINT_RedrawWindow( (HWND)hwnd, NULL,
983 (HRGN)hrgnUpdate, flags, 0 );
987 /***********************************************************************
988 * UpdateWindow16 (USER.124)
990 void WINAPI UpdateWindow16( HWND16 hwnd )
992 PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
995 /***********************************************************************
996 * UpdateWindow32 (USER32.567)
998 void WINAPI UpdateWindow( HWND hwnd )
1000 PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
1003 /***********************************************************************
1004 * InvalidateRgn16 (USER.126)
1006 void WINAPI InvalidateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
1008 PAINT_RedrawWindow((HWND)hwnd, NULL, (HRGN)hrgn,
1009 RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
1013 /***********************************************************************
1014 * InvalidateRgn32 (USER32.329)
1016 BOOL WINAPI InvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
1018 return PAINT_RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
1022 /***********************************************************************
1023 * InvalidateRect16 (USER.125)
1025 void WINAPI InvalidateRect16( HWND16 hwnd, const RECT16 *rect, BOOL16 erase )
1027 RedrawWindow16( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
1031 /***********************************************************************
1032 * InvalidateRect32 (USER32.328)
1034 BOOL WINAPI InvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
1036 return PAINT_RedrawWindow( hwnd, rect, 0,
1037 RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
1041 /***********************************************************************
1042 * ValidateRgn16 (USER.128)
1044 void WINAPI ValidateRgn16( HWND16 hwnd, HRGN16 hrgn )
1046 PAINT_RedrawWindow( (HWND)hwnd, NULL, (HRGN)hrgn,
1047 RDW_VALIDATE | RDW_NOCHILDREN, 0 );
1051 /***********************************************************************
1052 * ValidateRgn32 (USER32.572)
1054 void WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
1056 PAINT_RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
1060 /***********************************************************************
1061 * ValidateRect16 (USER.127)
1063 void WINAPI ValidateRect16( HWND16 hwnd, const RECT16 *rect )
1065 RedrawWindow16( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
1069 /***********************************************************************
1070 * ValidateRect32 (USER32.571)
1072 void WINAPI ValidateRect( HWND hwnd, const RECT *rect )
1074 PAINT_RedrawWindow( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
1078 /***********************************************************************
1079 * GetUpdateRect16 (USER.190)
1081 BOOL16 WINAPI GetUpdateRect16( HWND16 hwnd, LPRECT16 rect, BOOL16 erase )
1083 RECT r;
1084 BOOL16 ret;
1086 if (!rect) return GetUpdateRect( hwnd, NULL, erase );
1087 ret = GetUpdateRect( hwnd, &r, erase );
1088 CONV_RECT32TO16( &r, rect );
1089 return ret;
1093 /***********************************************************************
1094 * GetUpdateRect32 (USER32.297)
1096 BOOL WINAPI GetUpdateRect( HWND hwnd, LPRECT rect, BOOL erase )
1098 BOOL retvalue;
1099 WND * wndPtr = WIN_FindWndPtr( hwnd );
1100 if (!wndPtr) return FALSE;
1102 if (rect)
1104 if (wndPtr->hrgnUpdate > 1)
1106 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
1107 if (GetUpdateRgn( hwnd, hrgn, erase ) == ERROR)
1109 retvalue = FALSE;
1110 goto END;
1112 GetRgnBox( hrgn, rect );
1113 DeleteObject( hrgn );
1114 if (GetClassLongA(wndPtr->hwndSelf, GCL_STYLE) & CS_OWNDC)
1116 if (GetMapMode(wndPtr->dce->hDC) != MM_TEXT)
1118 DPtoLP (wndPtr->dce->hDC, (LPPOINT)rect, 2);
1122 else
1123 if( wndPtr->hrgnUpdate == 1 )
1125 GetClientRect( hwnd, rect );
1126 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_ERASENOW | RDW_NOCHILDREN );
1128 else
1129 SetRectEmpty( rect );
1131 retvalue = (wndPtr->hrgnUpdate >= 1);
1132 END:
1133 WIN_ReleaseWndPtr(wndPtr);
1134 return retvalue;
1138 /***********************************************************************
1139 * GetUpdateRgn16 (USER.237)
1141 INT16 WINAPI GetUpdateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
1143 return GetUpdateRgn( hwnd, hrgn, erase );
1147 /***********************************************************************
1148 * GetUpdateRgn (USER32.298)
1150 INT WINAPI GetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
1152 INT retval;
1153 WND * wndPtr = WIN_FindWndPtr( hwnd );
1154 if (!wndPtr) return ERROR;
1156 if (wndPtr->hrgnUpdate == 0)
1158 SetRectRgn( hrgn, 0, 0, 0, 0 );
1159 retval = NULLREGION;
1160 goto END;
1162 else
1163 if (wndPtr->hrgnUpdate == 1)
1165 SetRectRgn( hrgn, 0, 0, wndPtr->rectClient.right - wndPtr->rectClient.left,
1166 wndPtr->rectClient.bottom - wndPtr->rectClient.top );
1167 retval = SIMPLEREGION;
1169 else
1171 retval = CombineRgn( hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY );
1172 OffsetRgn( hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
1173 wndPtr->rectWindow.top - wndPtr->rectClient.top );
1175 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW | RDW_NOCHILDREN );
1176 END:
1177 WIN_ReleaseWndPtr(wndPtr);
1178 return retval;
1182 /***********************************************************************
1183 * ExcludeUpdateRgn16 (USER.238)
1185 INT16 WINAPI ExcludeUpdateRgn16( HDC16 hdc, HWND16 hwnd )
1187 return ExcludeUpdateRgn( hdc, hwnd );
1191 /***********************************************************************
1192 * ExcludeUpdateRgn32 (USER32.195)
1194 INT WINAPI ExcludeUpdateRgn( HDC hdc, HWND hwnd )
1196 RECT rect;
1197 WND * wndPtr;
1199 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return ERROR;
1201 if (wndPtr->hrgnUpdate)
1203 INT ret;
1204 HRGN hrgn = CreateRectRgn(wndPtr->rectWindow.left - wndPtr->rectClient.left,
1205 wndPtr->rectWindow.top - wndPtr->rectClient.top,
1206 wndPtr->rectWindow.right - wndPtr->rectClient.left,
1207 wndPtr->rectWindow.bottom - wndPtr->rectClient.top);
1208 if( wndPtr->hrgnUpdate > 1 )
1210 CombineRgn(hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY);
1211 OffsetRgn(hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
1212 wndPtr->rectWindow.top - wndPtr->rectClient.top );
1215 /* do ugly coordinate translations in dce.c */
1217 ret = DCE_ExcludeRgn( hdc, wndPtr, hrgn );
1218 DeleteObject( hrgn );
1219 WIN_ReleaseWndPtr(wndPtr);
1220 return ret;
1222 WIN_ReleaseWndPtr(wndPtr);
1223 return GetClipBox( hdc, &rect );