Implemented SHCreateShellFolderViewEx.
[wine/hacks.git] / windows / painting.c
blobff559d754e08a2c337b2e73a768790cbae7eb404
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 WND *wndPtr = WIN_FindWndPtr( hwnd );
268 if (!wndPtr) return 0;
270 bIcon = (wndPtr->dwStyle & WS_MINIMIZE && GetClassWord(wndPtr->hwndSelf, GCW_HICON));
272 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
274 /* send WM_NCPAINT and make sure hrgnUpdate is a valid rgn handle */
275 WIN_UpdateNCRgn( wndPtr, 0, UNC_UPDATE | UNC_IN_BEGINPAINT);
278 * Make sure the window is still a window. All window locks are suspended
279 * when the WM_NCPAINT is sent.
281 if (!IsWindow(wndPtr->hwndSelf))
283 WIN_ReleaseWndPtr(wndPtr);
284 return 0;
287 if( ((hrgnUpdate = wndPtr->hrgnUpdate) != 0) || (wndPtr->flags & WIN_INTERNAL_PAINT))
288 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
290 wndPtr->hrgnUpdate = 0;
291 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
293 HideCaret( hwnd );
295 TRACE_(win)("hrgnUpdate = %04x, \n", hrgnUpdate);
297 if (GetClassWord16(wndPtr->hwndSelf, GCW_STYLE) & CS_PARENTDC)
299 /* Don't clip the output to the update region for CS_PARENTDC window */
300 if( hrgnUpdate )
301 DeleteObject(hrgnUpdate);
302 lps->hdc = GetDCEx16( hwnd, 0, DCX_WINDOWPAINT | DCX_USESTYLE |
303 (bIcon ? DCX_WINDOW : 0) );
305 else
307 if( hrgnUpdate ) /* convert to client coordinates */
308 OffsetRgn( hrgnUpdate, wndPtr->rectWindow.left - wndPtr->rectClient.left,
309 wndPtr->rectWindow.top - wndPtr->rectClient.top );
310 lps->hdc = GetDCEx16(hwnd, hrgnUpdate, DCX_INTERSECTRGN |
311 DCX_WINDOWPAINT | DCX_USESTYLE | (bIcon ? DCX_WINDOW : 0) );
312 /* ReleaseDC() in EndPaint() will delete the region */
315 TRACE_(win)("hdc = %04x\n", lps->hdc);
317 if (!lps->hdc)
319 WARN_(win)("GetDCEx() failed in BeginPaint(), hwnd=%04x\n", hwnd);
320 WIN_ReleaseWndPtr(wndPtr);
321 return 0;
324 GetClipBox16( lps->hdc, &lps->rcPaint );
326 TRACE_(win)("box = (%i,%i - %i,%i)\n", lps->rcPaint.left, lps->rcPaint.top,
327 lps->rcPaint.right, lps->rcPaint.bottom );
329 if (wndPtr->flags & WIN_NEEDS_ERASEBKGND)
331 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
332 lps->fErase = !SendMessage16(hwnd, (bIcon) ? WM_ICONERASEBKGND
333 : WM_ERASEBKGND,
334 (WPARAM16)lps->hdc, 0 );
336 else lps->fErase = TRUE;
338 WIN_ReleaseWndPtr(wndPtr);
339 return lps->hdc;
343 /***********************************************************************
344 * BeginPaint32 (USER32.10)
346 HDC WINAPI BeginPaint( HWND hwnd, PAINTSTRUCT *lps )
348 PAINTSTRUCT16 ps;
350 BeginPaint16( hwnd, &ps );
351 lps->hdc = (HDC)ps.hdc;
352 lps->fErase = ps.fErase;
353 lps->rcPaint.top = ps.rcPaint.top;
354 lps->rcPaint.left = ps.rcPaint.left;
355 lps->rcPaint.right = ps.rcPaint.right;
356 lps->rcPaint.bottom = ps.rcPaint.bottom;
357 lps->fRestore = ps.fRestore;
358 lps->fIncUpdate = ps.fIncUpdate;
359 return lps->hdc;
363 /***********************************************************************
364 * EndPaint16 (USER.40)
366 BOOL16 WINAPI EndPaint16( HWND16 hwnd, const PAINTSTRUCT16* lps )
368 ReleaseDC16( hwnd, lps->hdc );
369 ShowCaret( hwnd );
370 return TRUE;
374 /***********************************************************************
375 * EndPaint32 (USER32.176)
377 BOOL WINAPI EndPaint( HWND hwnd, const PAINTSTRUCT *lps )
379 ReleaseDC( hwnd, lps->hdc );
380 ShowCaret( hwnd );
381 return TRUE;
385 /***********************************************************************
386 * FillWindow (USER.324)
388 void WINAPI FillWindow16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc, HBRUSH16 hbrush )
390 RECT16 rect;
391 GetClientRect16( hwnd, &rect );
392 DPtoLP16( hdc, (LPPOINT16)&rect, 2 );
393 PaintRect16( hwndParent, hwnd, hdc, hbrush, &rect );
397 /***********************************************************************
398 * PAINT_GetControlBrush
400 static HBRUSH16 PAINT_GetControlBrush( HWND hParent, HWND hWnd, HDC16 hDC, UINT16 ctlType )
402 HBRUSH16 bkgBrush = (HBRUSH16)SendMessageA( hParent, WM_CTLCOLORMSGBOX + ctlType,
403 (WPARAM)hDC, (LPARAM)hWnd );
404 if( !IsGDIObject16(bkgBrush) )
405 bkgBrush = DEFWND_ControlColor( hDC, ctlType );
406 return bkgBrush;
410 /***********************************************************************
411 * PaintRect (USER.325)
413 void WINAPI PaintRect16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc,
414 HBRUSH16 hbrush, const RECT16 *rect)
416 if( hbrush <= CTLCOLOR_MAX )
418 if( hwndParent )
419 hbrush = PAINT_GetControlBrush( hwndParent, hwnd, hdc, (UINT16)hbrush );
420 else
421 return;
423 if( hbrush )
424 FillRect16( hdc, rect, hbrush );
428 /***********************************************************************
429 * GetControlBrush (USER.326)
431 HBRUSH16 WINAPI GetControlBrush16( HWND16 hwnd, HDC16 hdc, UINT16 ctlType )
433 WND* wndPtr = WIN_FindWndPtr( hwnd );
434 HBRUSH16 retvalue;
436 if((ctlType <= CTLCOLOR_MAX) && wndPtr )
438 WND* parent;
439 if( wndPtr->dwStyle & WS_POPUP ) parent = WIN_LockWndPtr(wndPtr->owner);
440 else parent = WIN_LockWndPtr(wndPtr->parent);
441 if( !parent ) parent = wndPtr;
442 retvalue = (HBRUSH16)PAINT_GetControlBrush( parent->hwndSelf, hwnd, hdc, ctlType );
443 WIN_ReleaseWndPtr(parent);
444 goto END;
446 retvalue = (HBRUSH16)0;
447 END:
448 WIN_ReleaseWndPtr(wndPtr);
449 return retvalue;
453 /***********************************************************************
454 * RDW_ValidateParent [RDW_UpdateRgns() helper]
456 * Validate the portions of parent that are covered by a validated child
457 * wndPtr = child
459 void RDW_ValidateParent(WND *wndChild)
461 WND *wndParent = WIN_LockWndPtr(wndChild->parent);
462 WND *wndDesktop = WIN_GetDesktop();
464 if ((wndParent) && (wndParent != wndDesktop) && !(wndParent->dwStyle & WS_CLIPCHILDREN))
466 HRGN hrg;
467 if (wndChild->hrgnUpdate == 1 )
469 RECT r = {0, 0, wndChild->rectWindow.right - wndChild->rectWindow.left,
470 wndChild->rectWindow.bottom - wndChild->rectWindow.top };
471 hrg = CreateRectRgnIndirect( &r );
473 else
474 hrg = wndChild->hrgnUpdate;
475 if (wndParent->hrgnUpdate != 0)
477 POINT ptOffset;
478 RECT rect, rectParent;
479 if( wndParent->hrgnUpdate == 1 )
481 RECT r = {0, 0, wndParent->rectWindow.right - wndParent->rectWindow.left,
482 wndParent->rectWindow.bottom - wndParent->rectWindow.top };
483 wndParent->hrgnUpdate = CreateRectRgnIndirect( &r );
485 /* we must offset the child region by the offset of the child rect in the parent */
486 GetWindowRect(wndParent->hwndSelf, &rectParent);
487 GetWindowRect(wndChild->hwndSelf, &rect);
488 ptOffset.x = rect.left - rectParent.left;
489 ptOffset.y = rect.top - rectParent.top;
490 OffsetRgn( hrg, ptOffset.x, ptOffset.y );
491 CombineRgn( wndParent->hrgnUpdate, wndParent->hrgnUpdate, hrg, RGN_DIFF );
492 OffsetRgn( hrg, -ptOffset.x, -ptOffset.y );
494 if (hrg != wndChild->hrgnUpdate) DeleteObject( hrg );
496 WIN_ReleaseWndPtr(wndParent);
497 WIN_ReleaseDesktop();
500 /***********************************************************************
501 * RDW_UpdateRgns [RedrawWindow() helper]
503 * Walks the window tree and adds/removes parts of the hRgn to/from update
504 * regions of windows that overlap it. Also, manages internal paint flags.
506 * NOTE: Walks the window tree so the caller must lock it.
507 * MUST preserve hRgn (can modify but then has to restore).
509 static void RDW_UpdateRgns( WND* wndPtr, HRGN hRgn, UINT flags, BOOL firstRecursLevel )
512 * Called only when one of the following is set:
513 * (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT)
516 BOOL bHadOne = wndPtr->hrgnUpdate && hRgn;
517 BOOL bChildren = ( wndPtr->child && !(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE)
518 && ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) );
519 RECT r;
521 r.left = 0;
522 r.top = 0;
523 r.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
524 r.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
526 TRACE_(win)("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", wndPtr->hwndSelf, wndPtr->hrgnUpdate, hRgn, flags );
528 if( flags & RDW_INVALIDATE )
530 if( hRgn > 1 )
532 switch( wndPtr->hrgnUpdate )
534 default:
535 CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_OR );
536 /* fall through */
537 case 0:
538 wndPtr->hrgnUpdate = REGION_CropRgn( wndPtr->hrgnUpdate,
539 wndPtr->hrgnUpdate ? wndPtr->hrgnUpdate : hRgn,
540 &r, NULL );
541 if( !bHadOne )
543 GetRgnBox( wndPtr->hrgnUpdate, &r );
544 if( IsRectEmpty( &r ) )
546 DeleteObject( wndPtr->hrgnUpdate );
547 wndPtr->hrgnUpdate = 0;
548 goto OUT;
551 break;
552 case 1: /* already an entire window */
553 break;
556 else if( hRgn == 1 )
558 if( wndPtr->hrgnUpdate > 1 )
559 DeleteObject( wndPtr->hrgnUpdate );
560 wndPtr->hrgnUpdate = 1;
562 else
563 hRgn = wndPtr->hrgnUpdate; /* this is a trick that depends on code in PAINT_RedrawWindow() */
565 if( !bHadOne && !(wndPtr->flags & WIN_INTERNAL_PAINT) )
566 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
568 if (flags & RDW_FRAME) wndPtr->flags |= WIN_NEEDS_NCPAINT;
569 if (flags & RDW_ERASE) wndPtr->flags |= WIN_NEEDS_ERASEBKGND;
570 flags |= RDW_FRAME;
572 else if( flags & RDW_VALIDATE )
574 if( wndPtr->hrgnUpdate )
576 if( hRgn > 1 )
578 if( wndPtr->hrgnUpdate == 1 )
579 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r );
581 if( CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_DIFF )
582 == NULLREGION )
583 goto EMPTY;
585 else /* validate everything */
587 if( wndPtr->hrgnUpdate > 1 )
589 EMPTY:
590 DeleteObject( wndPtr->hrgnUpdate );
592 wndPtr->hrgnUpdate = 0;
595 if( !wndPtr->hrgnUpdate )
597 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
598 if( !(wndPtr->flags & WIN_INTERNAL_PAINT) )
599 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
603 if (flags & RDW_NOFRAME) wndPtr->flags &= ~WIN_NEEDS_NCPAINT;
604 if (flags & RDW_NOERASE) wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
608 if ((firstRecursLevel) && (wndPtr->hrgnUpdate != 0) && (flags & RDW_UPDATENOW))
609 RDW_ValidateParent(wndPtr); /* validate parent covered by region */
611 /* in/validate child windows that intersect with the region if it
612 * is a valid handle. */
614 if( flags & (RDW_INVALIDATE | RDW_VALIDATE) )
616 if( hRgn > 1 && bChildren )
618 WND* wnd = wndPtr->child;
619 POINT ptTotal, prevOrigin = {0,0};
620 POINT ptClient;
622 ptClient.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
623 ptClient.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
625 for( ptTotal.x = ptTotal.y = 0; wnd; wnd = wnd->next )
627 if( wnd->dwStyle & WS_VISIBLE )
629 POINT ptOffset;
631 r.left = wnd->rectWindow.left + ptClient.x;
632 r.right = wnd->rectWindow.right + ptClient.x;
633 r.top = wnd->rectWindow.top + ptClient.y;
634 r.bottom = wnd->rectWindow.bottom + ptClient.y;
636 ptOffset.x = r.left - prevOrigin.x;
637 ptOffset.y = r.top - prevOrigin.y;
638 OffsetRect( &r, -ptTotal.x, -ptTotal.y );
640 if( RectInRegion( hRgn, &r ) )
642 OffsetRgn( hRgn, -ptOffset.x, -ptOffset.y );
643 RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
644 prevOrigin.x = r.left + ptTotal.x;
645 prevOrigin.y = r.top + ptTotal.y;
646 ptTotal.x += ptOffset.x;
647 ptTotal.y += ptOffset.y;
651 OffsetRgn( hRgn, ptTotal.x, ptTotal.y );
652 bChildren = 0;
656 /* handle hRgn == 1 (alias for entire window) and/or internal paint recursion */
658 if( bChildren )
660 WND* wnd;
661 for( wnd = wndPtr->child; wnd; wnd = wnd->next )
662 if( wnd->dwStyle & WS_VISIBLE )
663 RDW_UpdateRgns( wnd, hRgn, flags, FALSE );
666 OUT:
668 /* Set/clear internal paint flag */
670 if (flags & RDW_INTERNALPAINT)
672 if ( !wndPtr->hrgnUpdate && !(wndPtr->flags & WIN_INTERNAL_PAINT))
673 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
674 wndPtr->flags |= WIN_INTERNAL_PAINT;
676 else if (flags & RDW_NOINTERNALPAINT)
678 if ( !wndPtr->hrgnUpdate && (wndPtr->flags & WIN_INTERNAL_PAINT))
679 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
680 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
684 /***********************************************************************
685 * RDW_Paint [RedrawWindow() helper]
687 * Walks the window tree and paints/erases windows that have
688 * nonzero update regions according to redraw flags. hrgn is a scratch
689 * region passed down during recursion. Must not be 1.
692 static HRGN RDW_Paint( WND* wndPtr, HRGN hrgn, UINT flags, UINT ex )
694 /* NOTE: wndPtr is locked by caller.
696 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
697 * SendMessage() calls. This is a comment inside DefWindowProc() source
698 * from 16-bit SDK:
700 * This message avoids lots of inter-app message traffic
701 * by switching to the other task and continuing the
702 * recursion there.
704 * wParam = flags
705 * LOWORD(lParam) = hrgnClip
706 * HIWORD(lParam) = hwndSkip (not used; always NULL)
709 HDC hDC;
710 HWND hWnd = wndPtr->hwndSelf;
711 BOOL bIcon = ((wndPtr->dwStyle & WS_MINIMIZE) && GetClassWord(wndPtr->hwndSelf, GCW_HICON));
713 /* Erase/update the window itself ... */
715 TRACE_(win)("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", hWnd, wndPtr->hrgnUpdate, hrgn, flags );
718 * Check if this window should delay it's processing of WM_NCPAINT.
719 * See WIN_HaveToDelayNCPAINT for a description of the mechanism
721 if ((ex & RDW_EX_DELAY_NCPAINT) || WIN_HaveToDelayNCPAINT(wndPtr, 0) )
722 ex |= RDW_EX_DELAY_NCPAINT;
724 if (flags & RDW_UPDATENOW)
726 if (wndPtr->hrgnUpdate) /* wm_painticon wparam is 1 */
727 SendMessage16( hWnd, (bIcon) ? WM_PAINTICON : WM_PAINT, bIcon, 0 );
729 else if ((flags & RDW_ERASENOW) || (ex & RDW_EX_TOPFRAME))
731 UINT dcx = DCX_INTERSECTRGN | DCX_USESTYLE | DCX_KEEPCLIPRGN | DCX_WINDOWPAINT | DCX_CACHE;
732 HRGN hrgnRet;
734 hrgnRet = WIN_UpdateNCRgn(wndPtr,
735 hrgn,
736 UNC_REGION | UNC_CHECK |
737 ((ex & RDW_EX_TOPFRAME) ? UNC_ENTIRE : 0) |
738 ((ex & RDW_EX_DELAY_NCPAINT) ? UNC_DELAY_NCPAINT : 0) );
740 if( hrgnRet )
742 if( hrgnRet > 1 ) hrgn = hrgnRet; else hrgnRet = 0; /* entire client */
743 if( wndPtr->flags & WIN_NEEDS_ERASEBKGND )
745 if( bIcon ) dcx |= DCX_WINDOW;
746 else
747 if( hrgnRet )
748 OffsetRgn( hrgnRet, wndPtr->rectWindow.left - wndPtr->rectClient.left,
749 wndPtr->rectWindow.top - wndPtr->rectClient.top);
750 else
751 dcx &= ~DCX_INTERSECTRGN;
752 if (( hDC = GetDCEx( hWnd, hrgnRet, dcx )) )
754 if (SendMessage16( hWnd, (bIcon) ? WM_ICONERASEBKGND
755 : WM_ERASEBKGND, (WPARAM16)hDC, 0 ))
756 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
757 ReleaseDC( hWnd, hDC );
763 if( !IsWindow(hWnd) ) return hrgn;
764 ex &= ~RDW_EX_TOPFRAME;
766 /* ... and its child windows */
768 if( wndPtr->child && !(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE)
769 && ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) )
771 WND** list, **ppWnd;
773 if( (list = WIN_BuildWinArray( wndPtr, 0, NULL )) )
775 wndPtr = NULL;
776 for (ppWnd = list; *ppWnd; ppWnd++)
778 WIN_UpdateWndPtr(&wndPtr,*ppWnd);
779 if (!IsWindow(wndPtr->hwndSelf)) continue;
780 if ( (wndPtr->dwStyle & WS_VISIBLE) &&
781 (wndPtr->hrgnUpdate || (wndPtr->flags & WIN_INTERNAL_PAINT)) )
782 hrgn = RDW_Paint( wndPtr, hrgn, flags, ex );
784 WIN_ReleaseWndPtr(wndPtr);
785 WIN_ReleaseWinArray(list);
789 return hrgn;
792 /***********************************************************************
793 * PAINT_RedrawWindow
796 BOOL PAINT_RedrawWindow( HWND hwnd, const RECT *rectUpdate,
797 HRGN hrgnUpdate, UINT flags, UINT ex )
799 HRGN hRgn = 0;
800 RECT r, r2;
801 POINT pt;
802 WND* wndPtr;
804 if (!hwnd) hwnd = GetDesktopWindow();
805 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
807 /* check if the window or its parents are visible/not minimized */
809 if (!WIN_IsWindowDrawable( wndPtr, !(flags & RDW_FRAME) ) )
811 WIN_ReleaseWndPtr(wndPtr);
812 return TRUE;
815 if (TRACE_ON(win))
817 if( hrgnUpdate )
819 GetRgnBox( hrgnUpdate, &r );
820 TRACE_(win)( "%04x (%04x) NULL %04x box (%i,%i-%i,%i) flags=%04x, exflags=%04x\n",
821 hwnd, wndPtr->hrgnUpdate, hrgnUpdate, r.left, r.top, r.right, r.bottom, flags, ex);
823 else
825 if( rectUpdate )
826 r = *rectUpdate;
827 else
828 SetRectEmpty( &r );
829 TRACE_(win)( "%04x (%04x) %s %d,%d-%d,%d %04x flags=%04x, exflags=%04x\n",
830 hwnd, wndPtr->hrgnUpdate, rectUpdate ? "rect" : "NULL", r.left,
831 r.top, r.right, r.bottom, hrgnUpdate, flags, ex );
835 /* prepare an update region in window coordinates */
837 if( flags & RDW_FRAME )
838 r = wndPtr->rectWindow;
839 else
840 r = wndPtr->rectClient;
842 if( ex & RDW_EX_XYWINDOW )
844 pt.x = pt.y = 0;
845 OffsetRect( &r, -wndPtr->rectWindow.left, -wndPtr->rectWindow.top );
847 else
849 pt.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
850 pt.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
851 OffsetRect( &r, -wndPtr->rectClient.left, -wndPtr->rectClient.top );
854 if (flags & RDW_INVALIDATE) /* ------------------------- Invalidate */
856 /* If the window doesn't have hrgnUpdate we leave hRgn zero
857 * and put a new region straight into wndPtr->hrgnUpdate
858 * so that RDW_UpdateRgns() won't have to do any extra work.
861 if( hrgnUpdate )
863 if( wndPtr->hrgnUpdate )
864 hRgn = REGION_CropRgn( 0, hrgnUpdate, NULL, &pt );
865 else
866 wndPtr->hrgnUpdate = REGION_CropRgn( 0, hrgnUpdate, &r, &pt );
868 else if( rectUpdate )
870 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
871 OffsetRect( &r2, pt.x, pt.y );
873 rect2i:
874 if( wndPtr->hrgnUpdate == 0 )
875 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r2 );
876 else
877 hRgn = CreateRectRgnIndirect( &r2 );
879 else /* entire window or client depending on RDW_FRAME */
881 if( flags & RDW_FRAME )
883 if( wndPtr->hrgnUpdate )
884 DeleteObject( wndPtr->hrgnUpdate );
885 wndPtr->hrgnUpdate = 1;
887 else
889 GETCLIENTRECTW( wndPtr, r2 );
890 goto rect2i;
894 else if (flags & RDW_VALIDATE) /* ------------------------- Validate */
896 /* In this we cannot leave with zero hRgn */
897 if( hrgnUpdate )
899 hRgn = REGION_CropRgn( hRgn, hrgnUpdate, &r, &pt );
900 GetRgnBox( hRgn, &r2 );
901 if( IsRectEmpty( &r2 ) ) goto END;
903 else if( rectUpdate )
905 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
906 OffsetRect( &r2, pt.x, pt.y );
907 rect2v:
908 hRgn = CreateRectRgnIndirect( &r2 );
910 else /* entire window or client depending on RDW_FRAME */
912 if( flags & RDW_FRAME )
913 hRgn = 1;
914 else
916 GETCLIENTRECTW( wndPtr, r2 );
917 goto rect2v;
922 /* At this point hRgn is either an update region in window coordinates or 1 or 0 */
924 RDW_UpdateRgns( wndPtr, hRgn, flags, TRUE );
926 /* Erase/update windows, from now on hRgn is a scratch region */
928 hRgn = RDW_Paint( wndPtr, (hRgn == 1) ? 0 : hRgn, flags, ex );
930 END:
931 if( hRgn > 1 && (hRgn != hrgnUpdate) )
932 DeleteObject(hRgn );
933 WIN_ReleaseWndPtr(wndPtr);
934 return TRUE;
938 /***********************************************************************
939 * RedrawWindow32 (USER32.426)
941 BOOL WINAPI RedrawWindow( HWND hwnd, const RECT *rectUpdate,
942 HRGN hrgnUpdate, UINT flags )
944 return PAINT_RedrawWindow( hwnd, rectUpdate, hrgnUpdate, flags, 0 );
948 /***********************************************************************
949 * RedrawWindow16 (USER.290)
951 BOOL16 WINAPI RedrawWindow16( HWND16 hwnd, const RECT16 *rectUpdate,
952 HRGN16 hrgnUpdate, UINT16 flags )
954 if (rectUpdate)
956 RECT r;
957 CONV_RECT16TO32( rectUpdate, &r );
958 return (BOOL16)RedrawWindow( (HWND)hwnd, &r, hrgnUpdate, flags );
960 return (BOOL16)PAINT_RedrawWindow( (HWND)hwnd, NULL,
961 (HRGN)hrgnUpdate, flags, 0 );
965 /***********************************************************************
966 * UpdateWindow16 (USER.124)
968 void WINAPI UpdateWindow16( HWND16 hwnd )
970 PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
973 /***********************************************************************
974 * UpdateWindow32 (USER32.567)
976 void WINAPI UpdateWindow( HWND hwnd )
978 PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
981 /***********************************************************************
982 * InvalidateRgn16 (USER.126)
984 void WINAPI InvalidateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
986 PAINT_RedrawWindow((HWND)hwnd, NULL, (HRGN)hrgn,
987 RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
991 /***********************************************************************
992 * InvalidateRgn32 (USER32.329)
994 BOOL WINAPI InvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
996 return PAINT_RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
1000 /***********************************************************************
1001 * InvalidateRect16 (USER.125)
1003 void WINAPI InvalidateRect16( HWND16 hwnd, const RECT16 *rect, BOOL16 erase )
1005 RedrawWindow16( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
1009 /***********************************************************************
1010 * InvalidateRect32 (USER32.328)
1012 BOOL WINAPI InvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
1014 return PAINT_RedrawWindow( hwnd, rect, 0,
1015 RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
1019 /***********************************************************************
1020 * ValidateRgn16 (USER.128)
1022 void WINAPI ValidateRgn16( HWND16 hwnd, HRGN16 hrgn )
1024 PAINT_RedrawWindow( (HWND)hwnd, NULL, (HRGN)hrgn,
1025 RDW_VALIDATE | RDW_NOCHILDREN, 0 );
1029 /***********************************************************************
1030 * ValidateRgn32 (USER32.572)
1032 void WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
1034 PAINT_RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
1038 /***********************************************************************
1039 * ValidateRect16 (USER.127)
1041 void WINAPI ValidateRect16( HWND16 hwnd, const RECT16 *rect )
1043 RedrawWindow16( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
1047 /***********************************************************************
1048 * ValidateRect32 (USER32.571)
1050 void WINAPI ValidateRect( HWND hwnd, const RECT *rect )
1052 PAINT_RedrawWindow( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
1056 /***********************************************************************
1057 * GetUpdateRect16 (USER.190)
1059 BOOL16 WINAPI GetUpdateRect16( HWND16 hwnd, LPRECT16 rect, BOOL16 erase )
1061 RECT r;
1062 BOOL16 ret;
1064 if (!rect) return GetUpdateRect( hwnd, NULL, erase );
1065 ret = GetUpdateRect( hwnd, &r, erase );
1066 CONV_RECT32TO16( &r, rect );
1067 return ret;
1071 /***********************************************************************
1072 * GetUpdateRect32 (USER32.297)
1074 BOOL WINAPI GetUpdateRect( HWND hwnd, LPRECT rect, BOOL erase )
1076 BOOL retvalue;
1077 WND * wndPtr = WIN_FindWndPtr( hwnd );
1078 if (!wndPtr) return FALSE;
1080 if (rect)
1082 if (wndPtr->hrgnUpdate > 1)
1084 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
1085 if (GetUpdateRgn( hwnd, hrgn, erase ) == ERROR)
1087 retvalue = FALSE;
1088 goto END;
1090 GetRgnBox( hrgn, rect );
1091 DeleteObject( hrgn );
1092 if (GetClassLongA(wndPtr->hwndSelf, GCL_STYLE) & CS_OWNDC)
1094 if (GetMapMode(wndPtr->dce->hDC) != MM_TEXT)
1096 DPtoLP (wndPtr->dce->hDC, (LPPOINT)rect, 2);
1100 else
1101 if( wndPtr->hrgnUpdate == 1 )
1103 GetClientRect( hwnd, rect );
1104 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_ERASENOW | RDW_NOCHILDREN );
1106 else
1107 SetRectEmpty( rect );
1109 retvalue = (wndPtr->hrgnUpdate >= 1);
1110 END:
1111 WIN_ReleaseWndPtr(wndPtr);
1112 return retvalue;
1116 /***********************************************************************
1117 * GetUpdateRgn16 (USER.237)
1119 INT16 WINAPI GetUpdateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
1121 return GetUpdateRgn( hwnd, hrgn, erase );
1125 /***********************************************************************
1126 * GetUpdateRgn (USER32.298)
1128 INT WINAPI GetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
1130 INT retval;
1131 WND * wndPtr = WIN_FindWndPtr( hwnd );
1132 if (!wndPtr) return ERROR;
1134 if (wndPtr->hrgnUpdate == 0)
1136 SetRectRgn( hrgn, 0, 0, 0, 0 );
1137 retval = NULLREGION;
1138 goto END;
1140 else
1141 if (wndPtr->hrgnUpdate == 1)
1143 SetRectRgn( hrgn, 0, 0, wndPtr->rectClient.right - wndPtr->rectClient.left,
1144 wndPtr->rectClient.bottom - wndPtr->rectClient.top );
1145 retval = SIMPLEREGION;
1147 else
1149 retval = CombineRgn( hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY );
1150 OffsetRgn( hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
1151 wndPtr->rectWindow.top - wndPtr->rectClient.top );
1153 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW | RDW_NOCHILDREN );
1154 END:
1155 WIN_ReleaseWndPtr(wndPtr);
1156 return retval;
1160 /***********************************************************************
1161 * ExcludeUpdateRgn16 (USER.238)
1163 INT16 WINAPI ExcludeUpdateRgn16( HDC16 hdc, HWND16 hwnd )
1165 return ExcludeUpdateRgn( hdc, hwnd );
1169 /***********************************************************************
1170 * ExcludeUpdateRgn32 (USER32.195)
1172 INT WINAPI ExcludeUpdateRgn( HDC hdc, HWND hwnd )
1174 RECT rect;
1175 WND * wndPtr;
1177 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return ERROR;
1179 if (wndPtr->hrgnUpdate)
1181 INT ret;
1182 HRGN hrgn = CreateRectRgn(wndPtr->rectWindow.left - wndPtr->rectClient.left,
1183 wndPtr->rectWindow.top - wndPtr->rectClient.top,
1184 wndPtr->rectWindow.right - wndPtr->rectClient.left,
1185 wndPtr->rectWindow.bottom - wndPtr->rectClient.top);
1186 if( wndPtr->hrgnUpdate > 1 )
1188 CombineRgn(hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY);
1189 OffsetRgn(hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
1190 wndPtr->rectWindow.top - wndPtr->rectClient.top );
1193 /* do ugly coordinate translations in dce.c */
1195 ret = DCE_ExcludeRgn( hdc, wndPtr, hrgn );
1196 DeleteObject( hrgn );
1197 WIN_ReleaseWndPtr(wndPtr);
1198 return ret;
1200 WIN_ReleaseWndPtr(wndPtr);
1201 return GetClipBox( hdc, &rect );