Release 990523.
[wine/multimedia.git] / windows / painting.c
blob4b68727eb7a919c6c46e66f0ff109909e8f99cc4
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_UpdateNCRgn
33 * Things to do:
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 )
46 RECT r;
47 HRGN hClip = 0;
48 HRGN hrgnRet = 0;
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 );
59 else
61 hrgnRet = wnd->hrgnUpdate;
63 WIN_ReleaseDesktop();
64 return hrgnRet;
66 WIN_ReleaseDesktop();
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 )
77 RECT r2, r3;
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 );
110 wnd->hrgnUpdate = 0;
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;
120 else
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 )
132 copyrgn:
133 if( uncFlags & UNC_REGION )
134 hrgnRet = REGION_CropRgn( hRgn, wnd->hrgnUpdate, NULL, NULL );
136 else
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 );
157 TRACE_(nonclient)("returning %04x (hClip = %04x, hrgnUpdate = %04x)\n", hrgnRet, hClip, wnd->hrgnUpdate );
159 return hrgnRet;
163 /***********************************************************************
164 * BeginPaint16 (USER.39)
166 HDC16 WINAPI BeginPaint16( HWND16 hwnd, LPPAINTSTRUCT16 lps )
168 BOOL bIcon;
169 HRGN hrgnUpdate;
170 WND *wndPtr = WIN_FindWndPtr( hwnd );
171 if (!wndPtr) return 0;
173 bIcon = (wndPtr->dwStyle & WS_MINIMIZE && wndPtr->class->hIcon);
175 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
177 /* send WM_NCPAINT and make sure hrgnUpdate is a valid rgn handle */
178 WIN_UpdateNCRgn( wndPtr, 0, UNC_UPDATE );
180 if( ((hrgnUpdate = wndPtr->hrgnUpdate) != 0) || (wndPtr->flags & WIN_INTERNAL_PAINT))
181 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
183 wndPtr->hrgnUpdate = 0;
184 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
186 HideCaret( hwnd );
188 TRACE_(win)("hrgnUpdate = %04x, \n", hrgnUpdate);
190 if (wndPtr->class->style & CS_PARENTDC)
192 /* Don't clip the output to the update region for CS_PARENTDC window */
193 if( hrgnUpdate )
194 DeleteObject(hrgnUpdate);
195 lps->hdc = GetDCEx16( hwnd, 0, DCX_WINDOWPAINT | DCX_USESTYLE |
196 (bIcon ? DCX_WINDOW : 0) );
198 else
200 if( hrgnUpdate ) /* convert to client coordinates */
201 OffsetRgn( hrgnUpdate, wndPtr->rectWindow.left - wndPtr->rectClient.left,
202 wndPtr->rectWindow.top - wndPtr->rectClient.top );
203 lps->hdc = GetDCEx16(hwnd, hrgnUpdate, DCX_INTERSECTRGN |
204 DCX_WINDOWPAINT | DCX_USESTYLE | (bIcon ? DCX_WINDOW : 0) );
205 /* ReleaseDC() in EndPaint() will delete the region */
208 TRACE_(win)("hdc = %04x\n", lps->hdc);
210 if (!lps->hdc)
212 WARN_(win)("GetDCEx() failed in BeginPaint(), hwnd=%04x\n", hwnd);
213 WIN_ReleaseWndPtr(wndPtr);
214 return 0;
217 GetClipBox16( lps->hdc, &lps->rcPaint );
219 TRACE_(win)("box = (%i,%i - %i,%i)\n", lps->rcPaint.left, lps->rcPaint.top,
220 lps->rcPaint.right, lps->rcPaint.bottom );
222 if (wndPtr->flags & WIN_NEEDS_ERASEBKGND)
224 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
225 lps->fErase = !SendMessage16(hwnd, (bIcon) ? WM_ICONERASEBKGND
226 : WM_ERASEBKGND,
227 (WPARAM16)lps->hdc, 0 );
229 else lps->fErase = TRUE;
231 WIN_ReleaseWndPtr(wndPtr);
232 return lps->hdc;
236 /***********************************************************************
237 * BeginPaint32 (USER32.10)
239 HDC WINAPI BeginPaint( HWND hwnd, PAINTSTRUCT *lps )
241 PAINTSTRUCT16 ps;
243 BeginPaint16( hwnd, &ps );
244 lps->hdc = (HDC)ps.hdc;
245 lps->fErase = ps.fErase;
246 lps->rcPaint.top = ps.rcPaint.top;
247 lps->rcPaint.left = ps.rcPaint.left;
248 lps->rcPaint.right = ps.rcPaint.right;
249 lps->rcPaint.bottom = ps.rcPaint.bottom;
250 lps->fRestore = ps.fRestore;
251 lps->fIncUpdate = ps.fIncUpdate;
252 return lps->hdc;
256 /***********************************************************************
257 * EndPaint16 (USER.40)
259 BOOL16 WINAPI EndPaint16( HWND16 hwnd, const PAINTSTRUCT16* lps )
261 ReleaseDC16( hwnd, lps->hdc );
262 ShowCaret( hwnd );
263 return TRUE;
267 /***********************************************************************
268 * EndPaint32 (USER32.176)
270 BOOL WINAPI EndPaint( HWND hwnd, const PAINTSTRUCT *lps )
272 ReleaseDC( hwnd, lps->hdc );
273 ShowCaret( hwnd );
274 return TRUE;
278 /***********************************************************************
279 * FillWindow (USER.324)
281 void WINAPI FillWindow16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc, HBRUSH16 hbrush )
283 RECT16 rect;
284 GetClientRect16( hwnd, &rect );
285 DPtoLP16( hdc, (LPPOINT16)&rect, 2 );
286 PaintRect16( hwndParent, hwnd, hdc, hbrush, &rect );
290 /***********************************************************************
291 * PAINT_GetControlBrush
293 static HBRUSH16 PAINT_GetControlBrush( HWND hParent, HWND hWnd, HDC16 hDC, UINT16 ctlType )
295 HBRUSH16 bkgBrush = (HBRUSH16)SendMessageA( hParent, WM_CTLCOLORMSGBOX + ctlType,
296 (WPARAM)hDC, (LPARAM)hWnd );
297 if( !IsGDIObject16(bkgBrush) )
298 bkgBrush = DEFWND_ControlColor( hDC, ctlType );
299 return bkgBrush;
303 /***********************************************************************
304 * PaintRect (USER.325)
306 void WINAPI PaintRect16( HWND16 hwndParent, HWND16 hwnd, HDC16 hdc,
307 HBRUSH16 hbrush, const RECT16 *rect)
309 if( hbrush <= CTLCOLOR_MAX )
311 if( hwndParent )
312 hbrush = PAINT_GetControlBrush( hwndParent, hwnd, hdc, (UINT16)hbrush );
313 else
314 return;
316 if( hbrush )
317 FillRect16( hdc, rect, hbrush );
321 /***********************************************************************
322 * GetControlBrush (USER.326)
324 HBRUSH16 WINAPI GetControlBrush16( HWND16 hwnd, HDC16 hdc, UINT16 ctlType )
326 WND* wndPtr = WIN_FindWndPtr( hwnd );
327 HBRUSH16 retvalue;
329 if((ctlType <= CTLCOLOR_MAX) && wndPtr )
331 WND* parent;
332 if( wndPtr->dwStyle & WS_POPUP ) parent = WIN_LockWndPtr(wndPtr->owner);
333 else parent = WIN_LockWndPtr(wndPtr->parent);
334 if( !parent ) parent = wndPtr;
335 retvalue = (HBRUSH16)PAINT_GetControlBrush( parent->hwndSelf, hwnd, hdc, ctlType );
336 WIN_ReleaseWndPtr(parent);
337 goto END;
339 retvalue = (HBRUSH16)0;
340 END:
341 WIN_ReleaseWndPtr(wndPtr);
342 return retvalue;
345 int i;
347 /***********************************************************************
348 * RDW_UpdateRgns [RedrawWindow() helper]
350 * Walks the window tree and adds/removes parts of the hRgn to/from update
351 * regions of windows that overlap it. Also, manages internal paint flags.
353 * NOTE: Walks the window tree so the caller must lock it.
354 * MUST preserve hRgn (can modify but then has to restore).
356 static void RDW_UpdateRgns( WND* wndPtr, HRGN hRgn, UINT flags )
359 * Called only when one of the following is set:
360 * (RDW_INVALIDATE | RDW_VALIDATE | RDW_INTERNALPAINT | RDW_NOINTERNALPAINT)
363 BOOL bHadOne = wndPtr->hrgnUpdate && hRgn;
364 RECT r = {0, 0, wndPtr->rectWindow.right - wndPtr->rectWindow.left,
365 wndPtr->rectWindow.bottom - wndPtr->rectWindow.top };
366 BOOL bChildren = ( wndPtr->child && !(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE)
367 && ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) );
369 TRACE_(win)("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", wndPtr->hwndSelf, wndPtr->hrgnUpdate, hRgn, flags );
371 if( flags & RDW_INVALIDATE )
373 if( hRgn > 1 )
375 switch( wndPtr->hrgnUpdate )
377 default:
378 CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_OR );
379 /* fall through */
380 case 0:
381 wndPtr->hrgnUpdate = REGION_CropRgn( wndPtr->hrgnUpdate,
382 wndPtr->hrgnUpdate ? wndPtr->hrgnUpdate : hRgn,
383 &r, NULL );
384 if( !bHadOne )
386 GetRgnBox( wndPtr->hrgnUpdate, &r );
387 if( IsRectEmpty( &r ) )
389 DeleteObject( wndPtr->hrgnUpdate );
390 wndPtr->hrgnUpdate = 0;
391 goto OUT;
394 break;
396 case 1: /* already an entire window */
399 else if( hRgn == 1 )
401 if( wndPtr->hrgnUpdate > 1 )
402 DeleteObject( wndPtr->hrgnUpdate );
403 wndPtr->hrgnUpdate = 1;
405 else
406 hRgn = wndPtr->hrgnUpdate; /* this is a trick that depends on code in PAINT_RedrawWindow() */
408 if( !bHadOne && !(wndPtr->flags & WIN_INTERNAL_PAINT) )
409 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
411 if (flags & RDW_FRAME) wndPtr->flags |= WIN_NEEDS_NCPAINT;
412 if (flags & RDW_ERASE) wndPtr->flags |= WIN_NEEDS_ERASEBKGND;
413 flags |= RDW_FRAME;
415 else if( flags & RDW_VALIDATE )
417 if( wndPtr->hrgnUpdate )
419 if( hRgn > 1 )
421 if( wndPtr->hrgnUpdate == 1 )
422 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r );
424 if( CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, hRgn, RGN_DIFF )
425 == NULLREGION )
426 goto EMPTY;
428 else /* validate everything */
430 if( wndPtr->hrgnUpdate > 1 )
432 EMPTY:
433 DeleteObject( wndPtr->hrgnUpdate );
435 wndPtr->hrgnUpdate = 0;
438 if( !wndPtr->hrgnUpdate )
440 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
441 if( !(wndPtr->flags & WIN_INTERNAL_PAINT) )
442 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
446 if (flags & RDW_NOFRAME) wndPtr->flags &= ~WIN_NEEDS_NCPAINT;
447 if (flags & RDW_NOERASE) wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
450 /* in/validate child windows that intersect with the region if it
451 * is a valid handle. */
453 if( flags & (RDW_INVALIDATE | RDW_VALIDATE) )
455 if( hRgn > 1 && bChildren )
457 WND* wnd = wndPtr->child;
458 POINT ptClient = { wndPtr->rectClient.left - wndPtr->rectWindow.left,
459 wndPtr->rectClient.top - wndPtr->rectWindow.top };
460 POINT ptTotal, prevOrigin = {0,0};
462 for( ptTotal.x = ptTotal.y = 0; wnd; wnd = wnd->next )
464 if( wnd->dwStyle & WS_VISIBLE )
466 POINT ptOffset;
468 r.left = wnd->rectWindow.left + ptClient.x;
469 r.right = wnd->rectWindow.right + ptClient.x;
470 r.top = wnd->rectWindow.top + ptClient.y;
471 r.bottom = wnd->rectWindow.bottom + ptClient.y;
473 ptOffset.x = r.left - prevOrigin.x;
474 ptOffset.y = r.top - prevOrigin.y;
475 OffsetRect( &r, -ptTotal.x, -ptTotal.y );
477 if( RectInRegion( hRgn, &r ) )
479 OffsetRgn( hRgn, -ptOffset.x, -ptOffset.y );
480 RDW_UpdateRgns( wnd, hRgn, flags );
481 prevOrigin.x = r.left + ptTotal.x;
482 prevOrigin.y = r.top + ptTotal.y;
483 ptTotal.x += ptOffset.x;
484 ptTotal.y += ptOffset.y;
488 OffsetRgn( hRgn, ptTotal.x, ptTotal.y );
489 bChildren = 0;
493 /* handle hRgn == 1 (alias for entire window) and/or internal paint recursion */
495 if( bChildren )
497 WND* wnd;
498 for( wnd = wndPtr->child; wnd; wnd = wnd->next )
499 if( wnd->dwStyle & WS_VISIBLE )
500 RDW_UpdateRgns( wnd, hRgn, flags );
503 OUT:
505 /* Set/clear internal paint flag */
507 if (flags & RDW_INTERNALPAINT)
509 if ( !wndPtr->hrgnUpdate && !(wndPtr->flags & WIN_INTERNAL_PAINT))
510 QUEUE_IncPaintCount( wndPtr->hmemTaskQ );
511 wndPtr->flags |= WIN_INTERNAL_PAINT;
513 else if (flags & RDW_NOINTERNALPAINT)
515 if ( !wndPtr->hrgnUpdate && (wndPtr->flags & WIN_INTERNAL_PAINT))
516 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
517 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
521 /***********************************************************************
522 * RDW_Paint [RedrawWindow() helper]
524 * Walks the window tree and paints/erases windows that have
525 * nonzero update regions according to redraw flags. hrgn is a scratch
526 * region passed down during recursion. Must not be 1.
529 static HRGN RDW_Paint( WND* wndPtr, HRGN hrgn, UINT flags, UINT ex )
531 /* NOTE: wndPtr is locked by caller.
533 * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask
534 * SendMessage() calls. This is a comment inside DefWindowProc() source
535 * from 16-bit SDK:
537 * This message avoids lots of inter-app message traffic
538 * by switching to the other task and continuing the
539 * recursion there.
541 * wParam = flags
542 * LOWORD(lParam) = hrgnClip
543 * HIWORD(lParam) = hwndSkip (not used; always NULL)
546 HDC hDC;
547 HWND hWnd = wndPtr->hwndSelf;
548 BOOL bIcon = ((wndPtr->dwStyle & WS_MINIMIZE) && wndPtr->class->hIcon);
550 /* Erase/update the window itself ... */
552 TRACE_(win)("\thwnd %04x [%04x] -> hrgn [%04x], flags [%04x]\n", hWnd, wndPtr->hrgnUpdate, hrgn, flags );
554 if (flags & RDW_UPDATENOW)
556 if (wndPtr->hrgnUpdate) /* wm_painticon wparam is 1 */
557 SendMessage16( hWnd, (bIcon) ? WM_PAINTICON : WM_PAINT, bIcon, 0 );
559 else if ((flags & RDW_ERASENOW) || (ex & RDW_EX_TOPFRAME))
561 UINT dcx = DCX_INTERSECTRGN | DCX_USESTYLE | DCX_KEEPCLIPRGN | DCX_WINDOWPAINT;
562 HRGN hrgnRet = WIN_UpdateNCRgn( wndPtr, hrgn, UNC_REGION | UNC_CHECK |
563 ((ex & RDW_EX_TOPFRAME) ? UNC_ENTIRE : 0) );
564 if( hrgnRet )
566 if( hrgnRet > 1 ) hrgn = hrgnRet; else hrgnRet = 0; /* entire client */
567 if( wndPtr->flags & WIN_NEEDS_ERASEBKGND )
569 if( bIcon ) dcx |= DCX_WINDOW;
570 else
571 if( hrgnRet )
572 OffsetRgn( hrgnRet, wndPtr->rectWindow.left - wndPtr->rectClient.left,
573 wndPtr->rectWindow.top - wndPtr->rectClient.top);
574 else
575 dcx &= ~DCX_INTERSECTRGN;
576 if (( hDC = GetDCEx( hWnd, hrgnRet, dcx )) )
578 if (SendMessage16( hWnd, (bIcon) ? WM_ICONERASEBKGND
579 : WM_ERASEBKGND, (WPARAM16)hDC, 0 ))
580 wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND;
581 ReleaseDC( hWnd, hDC );
587 if( !IsWindow(hWnd) ) return hrgn;
588 ex &= ~RDW_EX_TOPFRAME;
590 /* ... and its child windows */
592 if( wndPtr->child && !(flags & RDW_NOCHILDREN) && !(wndPtr->dwStyle & WS_MINIMIZE)
593 && ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) )
595 WND** list, **ppWnd;
597 if( (list = WIN_BuildWinArray( wndPtr, 0, NULL )) )
599 wndPtr = NULL;
600 for (ppWnd = list; *ppWnd; ppWnd++)
602 WIN_UpdateWndPtr(&wndPtr,*ppWnd);
603 if (!IsWindow(wndPtr->hwndSelf)) continue;
604 if ( (wndPtr->dwStyle & WS_VISIBLE) &&
605 (wndPtr->hrgnUpdate || (wndPtr->flags & WIN_INTERNAL_PAINT)) )
606 hrgn = RDW_Paint( wndPtr, hrgn, flags, ex );
608 WIN_ReleaseWndPtr(wndPtr);
609 WIN_ReleaseWinArray(list);
613 return hrgn;
616 /***********************************************************************
617 * PAINT_RedrawWindow
620 BOOL PAINT_RedrawWindow( HWND hwnd, const RECT *rectUpdate,
621 HRGN hrgnUpdate, UINT flags, UINT ex )
623 HRGN hRgn = 0;
624 RECT r, r2;
625 POINT pt;
626 WND* wndPtr;
628 if (!hwnd) hwnd = GetDesktopWindow();
629 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
631 /* check if the window or its parents are visible/not minimized */
633 if (!WIN_IsWindowDrawable( wndPtr, !(flags & RDW_FRAME) ) )
635 WIN_ReleaseWndPtr(wndPtr);
636 return TRUE;
639 if (TRACE_ON(win))
641 if( hrgnUpdate )
643 GetRgnBox( hrgnUpdate, &r );
644 TRACE_(win)( "%04x (%04x) NULL %04x box (%i,%i-%i,%i) flags=%04x, exflags=%04x\n",
645 hwnd, wndPtr->hrgnUpdate, hrgnUpdate, r.left, r.top, r.right, r.bottom, flags, ex);
647 else
649 if( rectUpdate )
650 r = *rectUpdate;
651 else
652 SetRectEmpty( &r );
653 TRACE_(win)( "%04x (%04x) %s %d,%d-%d,%d %04x flags=%04x, exflags=%04x\n",
654 hwnd, wndPtr->hrgnUpdate, rectUpdate ? "rect" : "NULL", r.left,
655 r.top, r.right, r.bottom, hrgnUpdate, flags, ex );
659 /* prepare an update region in window coordinates */
661 if( flags & RDW_FRAME )
662 r = wndPtr->rectWindow;
663 else
664 r = wndPtr->rectClient;
666 if( ex & RDW_EX_XYWINDOW )
668 pt.x = pt.y = 0;
669 OffsetRect( &r, -wndPtr->rectWindow.left, -wndPtr->rectWindow.top );
671 else
673 pt.x = wndPtr->rectClient.left - wndPtr->rectWindow.left;
674 pt.y = wndPtr->rectClient.top - wndPtr->rectWindow.top;
675 OffsetRect( &r, -wndPtr->rectClient.left, -wndPtr->rectClient.top );
678 if (flags & RDW_INVALIDATE) /* ------------------------- Invalidate */
680 /* If the window doesn't have hrgnUpdate we leave hRgn zero
681 * and put a new region straight into wndPtr->hrgnUpdate
682 * so that RDW_UpdateRgns() won't have to do any extra work.
685 if( hrgnUpdate )
687 if( wndPtr->hrgnUpdate )
688 hRgn = REGION_CropRgn( 0, hrgnUpdate, NULL, &pt );
689 else
690 wndPtr->hrgnUpdate = REGION_CropRgn( 0, hrgnUpdate, &r, &pt );
692 else if( rectUpdate )
694 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
695 OffsetRect( &r2, pt.x, pt.y );
697 rect2i:
698 if( wndPtr->hrgnUpdate == 0 )
699 wndPtr->hrgnUpdate = CreateRectRgnIndirect( &r2 );
700 else
701 hRgn = CreateRectRgnIndirect( &r2 );
703 else /* entire window or client depending on RDW_FRAME */
705 if( flags & RDW_FRAME )
707 if( wndPtr->hrgnUpdate )
708 DeleteObject( wndPtr->hrgnUpdate );
709 wndPtr->hrgnUpdate = 1;
711 else
713 GETCLIENTRECTW( wndPtr, r2 );
714 goto rect2i;
718 else if (flags & RDW_VALIDATE) /* ------------------------- Validate */
720 /* In this we cannot leave with zero hRgn */
721 if( hrgnUpdate )
723 hRgn = REGION_CropRgn( hRgn, hrgnUpdate, &r, &pt );
724 GetRgnBox( hRgn, &r2 );
725 if( IsRectEmpty( &r2 ) ) goto END;
727 else if( rectUpdate )
729 if( !IntersectRect( &r2, &r, rectUpdate ) ) goto END;
730 OffsetRect( &r2, pt.x, pt.y );
731 rect2v:
732 hRgn = CreateRectRgnIndirect( &r2 );
734 else /* entire window or client depending on RDW_FRAME */
736 if( flags & RDW_FRAME )
737 hRgn = 1;
738 else
740 GETCLIENTRECTW( wndPtr, r2 );
741 goto rect2v;
746 /* At this point hRgn is either an update region in window coordinates or 1 or 0 */
748 RDW_UpdateRgns( wndPtr, hRgn, flags );
750 /* Erase/update windows, from now on hRgn is a scratch region */
752 hRgn = RDW_Paint( wndPtr, (hRgn == 1) ? 0 : hRgn, flags, ex );
754 END:
755 if( hRgn > 1 && (hRgn != hrgnUpdate) )
756 DeleteObject(hRgn );
757 WIN_ReleaseWndPtr(wndPtr);
758 return TRUE;
762 /***********************************************************************
763 * RedrawWindow32 (USER32.426)
765 BOOL WINAPI RedrawWindow( HWND hwnd, const RECT *rectUpdate,
766 HRGN hrgnUpdate, UINT flags )
768 return PAINT_RedrawWindow( hwnd, rectUpdate, hrgnUpdate, flags, 0 );
772 /***********************************************************************
773 * RedrawWindow16 (USER.290)
775 BOOL16 WINAPI RedrawWindow16( HWND16 hwnd, const RECT16 *rectUpdate,
776 HRGN16 hrgnUpdate, UINT16 flags )
778 if (rectUpdate)
780 RECT r;
781 CONV_RECT16TO32( rectUpdate, &r );
782 return (BOOL16)RedrawWindow( (HWND)hwnd, &r, hrgnUpdate, flags );
784 return (BOOL16)PAINT_RedrawWindow( (HWND)hwnd, NULL,
785 (HRGN)hrgnUpdate, flags, 0 );
789 /***********************************************************************
790 * UpdateWindow16 (USER.124)
792 void WINAPI UpdateWindow16( HWND16 hwnd )
794 PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
797 /***********************************************************************
798 * UpdateWindow32 (USER32.567)
800 void WINAPI UpdateWindow( HWND hwnd )
802 PAINT_RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_NOCHILDREN, 0 );
805 /***********************************************************************
806 * InvalidateRgn16 (USER.126)
808 void WINAPI InvalidateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
810 PAINT_RedrawWindow((HWND)hwnd, NULL, (HRGN)hrgn,
811 RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
815 /***********************************************************************
816 * InvalidateRgn32 (USER32.329)
818 BOOL WINAPI InvalidateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
820 return PAINT_RedrawWindow(hwnd, NULL, hrgn, RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
824 /***********************************************************************
825 * InvalidateRect16 (USER.125)
827 void WINAPI InvalidateRect16( HWND16 hwnd, const RECT16 *rect, BOOL16 erase )
829 RedrawWindow16( hwnd, rect, 0, RDW_INVALIDATE | (erase ? RDW_ERASE : 0) );
833 /***********************************************************************
834 * InvalidateRect32 (USER32.328)
836 BOOL WINAPI InvalidateRect( HWND hwnd, const RECT *rect, BOOL erase )
838 return PAINT_RedrawWindow( hwnd, rect, 0,
839 RDW_INVALIDATE | (erase ? RDW_ERASE : 0), 0 );
843 /***********************************************************************
844 * ValidateRgn16 (USER.128)
846 void WINAPI ValidateRgn16( HWND16 hwnd, HRGN16 hrgn )
848 PAINT_RedrawWindow( (HWND)hwnd, NULL, (HRGN)hrgn,
849 RDW_VALIDATE | RDW_NOCHILDREN, 0 );
853 /***********************************************************************
854 * ValidateRgn32 (USER32.572)
856 void WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
858 PAINT_RedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
862 /***********************************************************************
863 * ValidateRect16 (USER.127)
865 void WINAPI ValidateRect16( HWND16 hwnd, const RECT16 *rect )
867 RedrawWindow16( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN );
871 /***********************************************************************
872 * ValidateRect32 (USER32.571)
874 void WINAPI ValidateRect( HWND hwnd, const RECT *rect )
876 PAINT_RedrawWindow( hwnd, rect, 0, RDW_VALIDATE | RDW_NOCHILDREN, 0 );
880 /***********************************************************************
881 * GetUpdateRect16 (USER.190)
883 BOOL16 WINAPI GetUpdateRect16( HWND16 hwnd, LPRECT16 rect, BOOL16 erase )
885 RECT r;
886 BOOL16 ret;
888 if (!rect) return GetUpdateRect( hwnd, NULL, erase );
889 ret = GetUpdateRect( hwnd, &r, erase );
890 CONV_RECT32TO16( &r, rect );
891 return ret;
895 /***********************************************************************
896 * GetUpdateRect32 (USER32.297)
898 BOOL WINAPI GetUpdateRect( HWND hwnd, LPRECT rect, BOOL erase )
900 BOOL retvalue;
901 WND * wndPtr = WIN_FindWndPtr( hwnd );
902 if (!wndPtr) return FALSE;
904 if (rect)
906 if (wndPtr->hrgnUpdate > 1)
908 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
909 if (GetUpdateRgn( hwnd, hrgn, erase ) == ERROR)
911 retvalue = FALSE;
912 goto END;
914 GetRgnBox( hrgn, rect );
915 DeleteObject( hrgn );
916 if (wndPtr->class->style & CS_OWNDC)
918 if (GetMapMode(wndPtr->dce->hDC) != MM_TEXT)
920 DPtoLP (wndPtr->dce->hDC, (LPPOINT)rect, 2);
924 else
925 if( wndPtr->hrgnUpdate == 1 )
927 GetClientRect( hwnd, rect );
928 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_ERASENOW | RDW_NOCHILDREN );
930 else
931 SetRectEmpty( rect );
933 retvalue = (wndPtr->hrgnUpdate >= 1);
934 END:
935 WIN_ReleaseWndPtr(wndPtr);
936 return retvalue;
940 /***********************************************************************
941 * GetUpdateRgn16 (USER.237)
943 INT16 WINAPI GetUpdateRgn16( HWND16 hwnd, HRGN16 hrgn, BOOL16 erase )
945 return GetUpdateRgn( hwnd, hrgn, erase );
949 /***********************************************************************
950 * GetUpdateRgn (USER32.298)
952 INT WINAPI GetUpdateRgn( HWND hwnd, HRGN hrgn, BOOL erase )
954 INT retval;
955 WND * wndPtr = WIN_FindWndPtr( hwnd );
956 if (!wndPtr) return ERROR;
958 if (wndPtr->hrgnUpdate == 0)
960 SetRectRgn( hrgn, 0, 0, 0, 0 );
961 retval = NULLREGION;
962 goto END;
964 else
965 if (wndPtr->hrgnUpdate == 1)
967 SetRectRgn( hrgn, 0, 0, wndPtr->rectClient.right - wndPtr->rectClient.left,
968 wndPtr->rectClient.bottom - wndPtr->rectClient.top );
969 retval = SIMPLEREGION;
971 else
973 retval = CombineRgn( hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY );
974 OffsetRgn( hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
975 wndPtr->rectWindow.top - wndPtr->rectClient.top );
977 if (erase) RedrawWindow( hwnd, NULL, 0, RDW_ERASENOW | RDW_NOCHILDREN );
978 END:
979 WIN_ReleaseWndPtr(wndPtr);
980 return retval;
984 /***********************************************************************
985 * ExcludeUpdateRgn16 (USER.238)
987 INT16 WINAPI ExcludeUpdateRgn16( HDC16 hdc, HWND16 hwnd )
989 return ExcludeUpdateRgn( hdc, hwnd );
993 /***********************************************************************
994 * ExcludeUpdateRgn32 (USER32.195)
996 INT WINAPI ExcludeUpdateRgn( HDC hdc, HWND hwnd )
998 RECT rect;
999 WND * wndPtr;
1001 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return ERROR;
1003 if (wndPtr->hrgnUpdate)
1005 INT ret;
1006 HRGN hrgn = CreateRectRgn(wndPtr->rectWindow.left - wndPtr->rectClient.left,
1007 wndPtr->rectWindow.top - wndPtr->rectClient.top,
1008 wndPtr->rectWindow.right - wndPtr->rectClient.left,
1009 wndPtr->rectWindow.bottom - wndPtr->rectClient.top);
1010 if( wndPtr->hrgnUpdate > 1 )
1012 CombineRgn(hrgn, wndPtr->hrgnUpdate, 0, RGN_COPY);
1013 OffsetRgn(hrgn, wndPtr->rectWindow.left - wndPtr->rectClient.left,
1014 wndPtr->rectWindow.top - wndPtr->rectClient.top );
1017 /* do ugly coordinate translations in dce.c */
1019 ret = DCE_ExcludeRgn( hdc, wndPtr, hrgn );
1020 DeleteObject( hrgn );
1021 WIN_ReleaseWndPtr(wndPtr);
1022 return ret;
1024 WIN_ReleaseWndPtr(wndPtr);
1025 return GetClipBox( hdc, &rect );